cxgb4_main.c 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  35. #include <linux/bitmap.h>
  36. #include <linux/crc32.h>
  37. #include <linux/ctype.h>
  38. #include <linux/debugfs.h>
  39. #include <linux/err.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/if.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/init.h>
  45. #include <linux/log2.h>
  46. #include <linux/mdio.h>
  47. #include <linux/module.h>
  48. #include <linux/moduleparam.h>
  49. #include <linux/mutex.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/pci.h>
  52. #include <linux/aer.h>
  53. #include <linux/rtnetlink.h>
  54. #include <linux/sched.h>
  55. #include <linux/seq_file.h>
  56. #include <linux/sockios.h>
  57. #include <linux/vmalloc.h>
  58. #include <linux/workqueue.h>
  59. #include <net/neighbour.h>
  60. #include <net/netevent.h>
  61. #include <net/addrconf.h>
  62. #include <net/bonding.h>
  63. #include <net/addrconf.h>
  64. #include <asm/uaccess.h>
  65. #include <linux/crash_dump.h>
  66. #include "cxgb4.h"
  67. #include "t4_regs.h"
  68. #include "t4_values.h"
  69. #include "t4_msg.h"
  70. #include "t4fw_api.h"
  71. #include "t4fw_version.h"
  72. #include "cxgb4_dcb.h"
  73. #include "cxgb4_debugfs.h"
  74. #include "clip_tbl.h"
  75. #include "l2t.h"
  76. char cxgb4_driver_name[] = KBUILD_MODNAME;
  77. #ifdef DRV_VERSION
  78. #undef DRV_VERSION
  79. #endif
  80. #define DRV_VERSION "2.0.0-ko"
  81. const char cxgb4_driver_version[] = DRV_VERSION;
  82. #define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
  83. /* Host shadow copy of ingress filter entry. This is in host native format
  84. * and doesn't match the ordering or bit order, etc. of the hardware of the
  85. * firmware command. The use of bit-field structure elements is purely to
  86. * remind ourselves of the field size limitations and save memory in the case
  87. * where the filter table is large.
  88. */
  89. struct filter_entry {
  90. /* Administrative fields for filter.
  91. */
  92. u32 valid:1; /* filter allocated and valid */
  93. u32 locked:1; /* filter is administratively locked */
  94. u32 pending:1; /* filter action is pending firmware reply */
  95. u32 smtidx:8; /* Source MAC Table index for smac */
  96. struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
  97. /* The filter itself. Most of this is a straight copy of information
  98. * provided by the extended ioctl(). Some fields are translated to
  99. * internal forms -- for instance the Ingress Queue ID passed in from
  100. * the ioctl() is translated into the Absolute Ingress Queue ID.
  101. */
  102. struct ch_filter_specification fs;
  103. };
  104. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  105. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  106. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  107. /* Macros needed to support the PCI Device ID Table ...
  108. */
  109. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
  110. static const struct pci_device_id cxgb4_pci_tbl[] = {
  111. #define CH_PCI_DEVICE_ID_FUNCTION 0x4
  112. /* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
  113. * called for both.
  114. */
  115. #define CH_PCI_DEVICE_ID_FUNCTION2 0x0
  116. #define CH_PCI_ID_TABLE_ENTRY(devid) \
  117. {PCI_VDEVICE(CHELSIO, (devid)), 4}
  118. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
  119. { 0, } \
  120. }
  121. #include "t4_pci_id_tbl.h"
  122. #define FW4_FNAME "cxgb4/t4fw.bin"
  123. #define FW5_FNAME "cxgb4/t5fw.bin"
  124. #define FW6_FNAME "cxgb4/t6fw.bin"
  125. #define FW4_CFNAME "cxgb4/t4-config.txt"
  126. #define FW5_CFNAME "cxgb4/t5-config.txt"
  127. #define FW6_CFNAME "cxgb4/t6-config.txt"
  128. #define PHY_AQ1202_FIRMWARE "cxgb4/aq1202_fw.cld"
  129. #define PHY_BCM84834_FIRMWARE "cxgb4/bcm8483.bin"
  130. #define PHY_AQ1202_DEVICEID 0x4409
  131. #define PHY_BCM84834_DEVICEID 0x4486
  132. MODULE_DESCRIPTION(DRV_DESC);
  133. MODULE_AUTHOR("Chelsio Communications");
  134. MODULE_LICENSE("Dual BSD/GPL");
  135. MODULE_VERSION(DRV_VERSION);
  136. MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
  137. MODULE_FIRMWARE(FW4_FNAME);
  138. MODULE_FIRMWARE(FW5_FNAME);
  139. MODULE_FIRMWARE(FW6_FNAME);
  140. /*
  141. * Normally we're willing to become the firmware's Master PF but will be happy
  142. * if another PF has already become the Master and initialized the adapter.
  143. * Setting "force_init" will cause this driver to forcibly establish itself as
  144. * the Master PF and initialize the adapter.
  145. */
  146. static uint force_init;
  147. module_param(force_init, uint, 0644);
  148. MODULE_PARM_DESC(force_init, "Forcibly become Master PF and initialize adapter,"
  149. "deprecated parameter");
  150. static int dflt_msg_enable = DFLT_MSG_ENABLE;
  151. module_param(dflt_msg_enable, int, 0644);
  152. MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T4 default message enable bitmap, "
  153. "deprecated parameter");
  154. /*
  155. * The driver uses the best interrupt scheme available on a platform in the
  156. * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
  157. * of these schemes the driver may consider as follows:
  158. *
  159. * msi = 2: choose from among all three options
  160. * msi = 1: only consider MSI and INTx interrupts
  161. * msi = 0: force INTx interrupts
  162. */
  163. static int msi = 2;
  164. module_param(msi, int, 0644);
  165. MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
  166. /*
  167. * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
  168. * offset by 2 bytes in order to have the IP headers line up on 4-byte
  169. * boundaries. This is a requirement for many architectures which will throw
  170. * a machine check fault if an attempt is made to access one of the 4-byte IP
  171. * header fields on a non-4-byte boundary. And it's a major performance issue
  172. * even on some architectures which allow it like some implementations of the
  173. * x86 ISA. However, some architectures don't mind this and for some very
  174. * edge-case performance sensitive applications (like forwarding large volumes
  175. * of small packets), setting this DMA offset to 0 will decrease the number of
  176. * PCI-E Bus transfers enough to measurably affect performance.
  177. */
  178. static int rx_dma_offset = 2;
  179. #ifdef CONFIG_PCI_IOV
  180. /* Configure the number of PCI-E Virtual Function which are to be instantiated
  181. * on SR-IOV Capable Physical Functions.
  182. */
  183. static unsigned int num_vf[NUM_OF_PF_WITH_SRIOV];
  184. module_param_array(num_vf, uint, NULL, 0644);
  185. MODULE_PARM_DESC(num_vf, "number of VFs for each of PFs 0-3, deprecated parameter - please use the pci sysfs interface.");
  186. #endif
  187. /* TX Queue select used to determine what algorithm to use for selecting TX
  188. * queue. Select between the kernel provided function (select_queue=0) or user
  189. * cxgb_select_queue function (select_queue=1)
  190. *
  191. * Default: select_queue=0
  192. */
  193. static int select_queue;
  194. module_param(select_queue, int, 0644);
  195. MODULE_PARM_DESC(select_queue,
  196. "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
  197. static struct dentry *cxgb4_debugfs_root;
  198. static LIST_HEAD(adapter_list);
  199. static DEFINE_MUTEX(uld_mutex);
  200. /* Adapter list to be accessed from atomic context */
  201. static LIST_HEAD(adap_rcu_list);
  202. static DEFINE_SPINLOCK(adap_rcu_lock);
  203. static struct cxgb4_uld_info ulds[CXGB4_ULD_MAX];
  204. static const char *const uld_str[] = { "RDMA", "iSCSI", "iSCSIT" };
  205. static void link_report(struct net_device *dev)
  206. {
  207. if (!netif_carrier_ok(dev))
  208. netdev_info(dev, "link down\n");
  209. else {
  210. static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
  211. const char *s;
  212. const struct port_info *p = netdev_priv(dev);
  213. switch (p->link_cfg.speed) {
  214. case 10000:
  215. s = "10Gbps";
  216. break;
  217. case 1000:
  218. s = "1000Mbps";
  219. break;
  220. case 100:
  221. s = "100Mbps";
  222. break;
  223. case 40000:
  224. s = "40Gbps";
  225. break;
  226. default:
  227. pr_info("%s: unsupported speed: %d\n",
  228. dev->name, p->link_cfg.speed);
  229. return;
  230. }
  231. netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
  232. fc[p->link_cfg.fc]);
  233. }
  234. }
  235. #ifdef CONFIG_CHELSIO_T4_DCB
  236. /* Set up/tear down Data Center Bridging Priority mapping for a net device. */
  237. static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
  238. {
  239. struct port_info *pi = netdev_priv(dev);
  240. struct adapter *adap = pi->adapter;
  241. struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
  242. int i;
  243. /* We use a simple mapping of Port TX Queue Index to DCB
  244. * Priority when we're enabling DCB.
  245. */
  246. for (i = 0; i < pi->nqsets; i++, txq++) {
  247. u32 name, value;
  248. int err;
  249. name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  250. FW_PARAMS_PARAM_X_V(
  251. FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
  252. FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
  253. value = enable ? i : 0xffffffff;
  254. /* Since we can be called while atomic (from "interrupt
  255. * level") we need to issue the Set Parameters Commannd
  256. * without sleeping (timeout < 0).
  257. */
  258. err = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
  259. &name, &value,
  260. -FW_CMD_MAX_TIMEOUT);
  261. if (err)
  262. dev_err(adap->pdev_dev,
  263. "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
  264. enable ? "set" : "unset", pi->port_id, i, -err);
  265. else
  266. txq->dcb_prio = value;
  267. }
  268. }
  269. #endif /* CONFIG_CHELSIO_T4_DCB */
  270. int cxgb4_dcb_enabled(const struct net_device *dev)
  271. {
  272. #ifdef CONFIG_CHELSIO_T4_DCB
  273. struct port_info *pi = netdev_priv(dev);
  274. if (!pi->dcb.enabled)
  275. return 0;
  276. return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
  277. (pi->dcb.state == CXGB4_DCB_STATE_HOST));
  278. #else
  279. return 0;
  280. #endif
  281. }
  282. EXPORT_SYMBOL(cxgb4_dcb_enabled);
  283. void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
  284. {
  285. struct net_device *dev = adapter->port[port_id];
  286. /* Skip changes from disabled ports. */
  287. if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
  288. if (link_stat)
  289. netif_carrier_on(dev);
  290. else {
  291. #ifdef CONFIG_CHELSIO_T4_DCB
  292. if (cxgb4_dcb_enabled(dev)) {
  293. cxgb4_dcb_state_init(dev);
  294. dcb_tx_queue_prio_enable(dev, false);
  295. }
  296. #endif /* CONFIG_CHELSIO_T4_DCB */
  297. netif_carrier_off(dev);
  298. }
  299. link_report(dev);
  300. }
  301. }
  302. void t4_os_portmod_changed(const struct adapter *adap, int port_id)
  303. {
  304. static const char *mod_str[] = {
  305. NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
  306. };
  307. const struct net_device *dev = adap->port[port_id];
  308. const struct port_info *pi = netdev_priv(dev);
  309. if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
  310. netdev_info(dev, "port module unplugged\n");
  311. else if (pi->mod_type < ARRAY_SIZE(mod_str))
  312. netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
  313. else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  314. netdev_info(dev, "%s: unsupported port module inserted\n",
  315. dev->name);
  316. else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  317. netdev_info(dev, "%s: unknown port module inserted\n",
  318. dev->name);
  319. else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
  320. netdev_info(dev, "%s: transceiver module error\n", dev->name);
  321. else
  322. netdev_info(dev, "%s: unknown module type %d inserted\n",
  323. dev->name, pi->mod_type);
  324. }
  325. int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
  326. module_param(dbfifo_int_thresh, int, 0644);
  327. MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
  328. /*
  329. * usecs to sleep while draining the dbfifo
  330. */
  331. static int dbfifo_drain_delay = 1000;
  332. module_param(dbfifo_drain_delay, int, 0644);
  333. MODULE_PARM_DESC(dbfifo_drain_delay,
  334. "usecs to sleep while draining the dbfifo");
  335. static inline int cxgb4_set_addr_hash(struct port_info *pi)
  336. {
  337. struct adapter *adap = pi->adapter;
  338. u64 vec = 0;
  339. bool ucast = false;
  340. struct hash_mac_addr *entry;
  341. /* Calculate the hash vector for the updated list and program it */
  342. list_for_each_entry(entry, &adap->mac_hlist, list) {
  343. ucast |= is_unicast_ether_addr(entry->addr);
  344. vec |= (1ULL << hash_mac_addr(entry->addr));
  345. }
  346. return t4_set_addr_hash(adap, adap->mbox, pi->viid, ucast,
  347. vec, false);
  348. }
  349. static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
  350. {
  351. struct port_info *pi = netdev_priv(netdev);
  352. struct adapter *adap = pi->adapter;
  353. int ret;
  354. u64 mhash = 0;
  355. u64 uhash = 0;
  356. bool free = false;
  357. bool ucast = is_unicast_ether_addr(mac_addr);
  358. const u8 *maclist[1] = {mac_addr};
  359. struct hash_mac_addr *new_entry;
  360. ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
  361. NULL, ucast ? &uhash : &mhash, false);
  362. if (ret < 0)
  363. goto out;
  364. /* if hash != 0, then add the addr to hash addr list
  365. * so on the end we will calculate the hash for the
  366. * list and program it
  367. */
  368. if (uhash || mhash) {
  369. new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
  370. if (!new_entry)
  371. return -ENOMEM;
  372. ether_addr_copy(new_entry->addr, mac_addr);
  373. list_add_tail(&new_entry->list, &adap->mac_hlist);
  374. ret = cxgb4_set_addr_hash(pi);
  375. }
  376. out:
  377. return ret < 0 ? ret : 0;
  378. }
  379. static int cxgb4_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
  380. {
  381. struct port_info *pi = netdev_priv(netdev);
  382. struct adapter *adap = pi->adapter;
  383. int ret;
  384. const u8 *maclist[1] = {mac_addr};
  385. struct hash_mac_addr *entry, *tmp;
  386. /* If the MAC address to be removed is in the hash addr
  387. * list, delete it from the list and update hash vector
  388. */
  389. list_for_each_entry_safe(entry, tmp, &adap->mac_hlist, list) {
  390. if (ether_addr_equal(entry->addr, mac_addr)) {
  391. list_del(&entry->list);
  392. kfree(entry);
  393. return cxgb4_set_addr_hash(pi);
  394. }
  395. }
  396. ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
  397. return ret < 0 ? -EINVAL : 0;
  398. }
  399. /*
  400. * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
  401. * If @mtu is -1 it is left unchanged.
  402. */
  403. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  404. {
  405. struct port_info *pi = netdev_priv(dev);
  406. struct adapter *adapter = pi->adapter;
  407. __dev_uc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  408. __dev_mc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  409. return t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu,
  410. (dev->flags & IFF_PROMISC) ? 1 : 0,
  411. (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
  412. sleep_ok);
  413. }
  414. /**
  415. * link_start - enable a port
  416. * @dev: the port to enable
  417. *
  418. * Performs the MAC and PHY actions needed to enable a port.
  419. */
  420. static int link_start(struct net_device *dev)
  421. {
  422. int ret;
  423. struct port_info *pi = netdev_priv(dev);
  424. unsigned int mb = pi->adapter->pf;
  425. /*
  426. * We do not set address filters and promiscuity here, the stack does
  427. * that step explicitly.
  428. */
  429. ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
  430. !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
  431. if (ret == 0) {
  432. ret = t4_change_mac(pi->adapter, mb, pi->viid,
  433. pi->xact_addr_filt, dev->dev_addr, true,
  434. true);
  435. if (ret >= 0) {
  436. pi->xact_addr_filt = ret;
  437. ret = 0;
  438. }
  439. }
  440. if (ret == 0)
  441. ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
  442. &pi->link_cfg);
  443. if (ret == 0) {
  444. local_bh_disable();
  445. ret = t4_enable_vi_params(pi->adapter, mb, pi->viid, true,
  446. true, CXGB4_DCB_ENABLED);
  447. local_bh_enable();
  448. }
  449. return ret;
  450. }
  451. #ifdef CONFIG_CHELSIO_T4_DCB
  452. /* Handle a Data Center Bridging update message from the firmware. */
  453. static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
  454. {
  455. int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
  456. struct net_device *dev = adap->port[adap->chan_map[port]];
  457. int old_dcb_enabled = cxgb4_dcb_enabled(dev);
  458. int new_dcb_enabled;
  459. cxgb4_dcb_handle_fw_update(adap, pcmd);
  460. new_dcb_enabled = cxgb4_dcb_enabled(dev);
  461. /* If the DCB has become enabled or disabled on the port then we're
  462. * going to need to set up/tear down DCB Priority parameters for the
  463. * TX Queues associated with the port.
  464. */
  465. if (new_dcb_enabled != old_dcb_enabled)
  466. dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
  467. }
  468. #endif /* CONFIG_CHELSIO_T4_DCB */
  469. /* Clear a filter and release any of its resources that we own. This also
  470. * clears the filter's "pending" status.
  471. */
  472. static void clear_filter(struct adapter *adap, struct filter_entry *f)
  473. {
  474. /* If the new or old filter have loopback rewriteing rules then we'll
  475. * need to free any existing Layer Two Table (L2T) entries of the old
  476. * filter rule. The firmware will handle freeing up any Source MAC
  477. * Table (SMT) entries used for rewriting Source MAC Addresses in
  478. * loopback rules.
  479. */
  480. if (f->l2t)
  481. cxgb4_l2t_release(f->l2t);
  482. /* The zeroing of the filter rule below clears the filter valid,
  483. * pending, locked flags, l2t pointer, etc. so it's all we need for
  484. * this operation.
  485. */
  486. memset(f, 0, sizeof(*f));
  487. }
  488. /* Handle a filter write/deletion reply.
  489. */
  490. static void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
  491. {
  492. unsigned int idx = GET_TID(rpl);
  493. unsigned int nidx = idx - adap->tids.ftid_base;
  494. unsigned int ret;
  495. struct filter_entry *f;
  496. if (idx >= adap->tids.ftid_base && nidx <
  497. (adap->tids.nftids + adap->tids.nsftids)) {
  498. idx = nidx;
  499. ret = TCB_COOKIE_G(rpl->cookie);
  500. f = &adap->tids.ftid_tab[idx];
  501. if (ret == FW_FILTER_WR_FLT_DELETED) {
  502. /* Clear the filter when we get confirmation from the
  503. * hardware that the filter has been deleted.
  504. */
  505. clear_filter(adap, f);
  506. } else if (ret == FW_FILTER_WR_SMT_TBL_FULL) {
  507. dev_err(adap->pdev_dev, "filter %u setup failed due to full SMT\n",
  508. idx);
  509. clear_filter(adap, f);
  510. } else if (ret == FW_FILTER_WR_FLT_ADDED) {
  511. f->smtidx = (be64_to_cpu(rpl->oldval) >> 24) & 0xff;
  512. f->pending = 0; /* asynchronous setup completed */
  513. f->valid = 1;
  514. } else {
  515. /* Something went wrong. Issue a warning about the
  516. * problem and clear everything out.
  517. */
  518. dev_err(adap->pdev_dev, "filter %u setup failed with error %u\n",
  519. idx, ret);
  520. clear_filter(adap, f);
  521. }
  522. }
  523. }
  524. /* Response queue handler for the FW event queue.
  525. */
  526. static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
  527. const struct pkt_gl *gl)
  528. {
  529. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  530. rsp++; /* skip RSS header */
  531. /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
  532. */
  533. if (unlikely(opcode == CPL_FW4_MSG &&
  534. ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
  535. rsp++;
  536. opcode = ((const struct rss_header *)rsp)->opcode;
  537. rsp++;
  538. if (opcode != CPL_SGE_EGR_UPDATE) {
  539. dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
  540. , opcode);
  541. goto out;
  542. }
  543. }
  544. if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
  545. const struct cpl_sge_egr_update *p = (void *)rsp;
  546. unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
  547. struct sge_txq *txq;
  548. txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
  549. txq->restarts++;
  550. if ((u8 *)txq < (u8 *)q->adap->sge.ofldtxq) {
  551. struct sge_eth_txq *eq;
  552. eq = container_of(txq, struct sge_eth_txq, q);
  553. netif_tx_wake_queue(eq->txq);
  554. } else {
  555. struct sge_ofld_txq *oq;
  556. oq = container_of(txq, struct sge_ofld_txq, q);
  557. tasklet_schedule(&oq->qresume_tsk);
  558. }
  559. } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
  560. const struct cpl_fw6_msg *p = (void *)rsp;
  561. #ifdef CONFIG_CHELSIO_T4_DCB
  562. const struct fw_port_cmd *pcmd = (const void *)p->data;
  563. unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
  564. unsigned int action =
  565. FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
  566. if (cmd == FW_PORT_CMD &&
  567. action == FW_PORT_ACTION_GET_PORT_INFO) {
  568. int port = FW_PORT_CMD_PORTID_G(
  569. be32_to_cpu(pcmd->op_to_portid));
  570. struct net_device *dev =
  571. q->adap->port[q->adap->chan_map[port]];
  572. int state_input = ((pcmd->u.info.dcbxdis_pkd &
  573. FW_PORT_CMD_DCBXDIS_F)
  574. ? CXGB4_DCB_INPUT_FW_DISABLED
  575. : CXGB4_DCB_INPUT_FW_ENABLED);
  576. cxgb4_dcb_state_fsm(dev, state_input);
  577. }
  578. if (cmd == FW_PORT_CMD &&
  579. action == FW_PORT_ACTION_L2_DCB_CFG)
  580. dcb_rpl(q->adap, pcmd);
  581. else
  582. #endif
  583. if (p->type == 0)
  584. t4_handle_fw_rpl(q->adap, p->data);
  585. } else if (opcode == CPL_L2T_WRITE_RPL) {
  586. const struct cpl_l2t_write_rpl *p = (void *)rsp;
  587. do_l2t_write_rpl(q->adap, p);
  588. } else if (opcode == CPL_SET_TCB_RPL) {
  589. const struct cpl_set_tcb_rpl *p = (void *)rsp;
  590. filter_rpl(q->adap, p);
  591. } else
  592. dev_err(q->adap->pdev_dev,
  593. "unexpected CPL %#x on FW event queue\n", opcode);
  594. out:
  595. return 0;
  596. }
  597. /* Flush the aggregated lro sessions */
  598. static void uldrx_flush_handler(struct sge_rspq *q)
  599. {
  600. if (ulds[q->uld].lro_flush)
  601. ulds[q->uld].lro_flush(&q->lro_mgr);
  602. }
  603. /**
  604. * uldrx_handler - response queue handler for ULD queues
  605. * @q: the response queue that received the packet
  606. * @rsp: the response queue descriptor holding the offload message
  607. * @gl: the gather list of packet fragments
  608. *
  609. * Deliver an ingress offload packet to a ULD. All processing is done by
  610. * the ULD, we just maintain statistics.
  611. */
  612. static int uldrx_handler(struct sge_rspq *q, const __be64 *rsp,
  613. const struct pkt_gl *gl)
  614. {
  615. struct sge_ofld_rxq *rxq = container_of(q, struct sge_ofld_rxq, rspq);
  616. int ret;
  617. /* FW can send CPLs encapsulated in a CPL_FW4_MSG.
  618. */
  619. if (((const struct rss_header *)rsp)->opcode == CPL_FW4_MSG &&
  620. ((const struct cpl_fw4_msg *)(rsp + 1))->type == FW_TYPE_RSSCPL)
  621. rsp += 2;
  622. if (q->flush_handler)
  623. ret = ulds[q->uld].lro_rx_handler(q->adap->uld_handle[q->uld],
  624. rsp, gl, &q->lro_mgr,
  625. &q->napi);
  626. else
  627. ret = ulds[q->uld].rx_handler(q->adap->uld_handle[q->uld],
  628. rsp, gl);
  629. if (ret) {
  630. rxq->stats.nomem++;
  631. return -1;
  632. }
  633. if (gl == NULL)
  634. rxq->stats.imm++;
  635. else if (gl == CXGB4_MSG_AN)
  636. rxq->stats.an++;
  637. else
  638. rxq->stats.pkts++;
  639. return 0;
  640. }
  641. static void disable_msi(struct adapter *adapter)
  642. {
  643. if (adapter->flags & USING_MSIX) {
  644. pci_disable_msix(adapter->pdev);
  645. adapter->flags &= ~USING_MSIX;
  646. } else if (adapter->flags & USING_MSI) {
  647. pci_disable_msi(adapter->pdev);
  648. adapter->flags &= ~USING_MSI;
  649. }
  650. }
  651. /*
  652. * Interrupt handler for non-data events used with MSI-X.
  653. */
  654. static irqreturn_t t4_nondata_intr(int irq, void *cookie)
  655. {
  656. struct adapter *adap = cookie;
  657. u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
  658. if (v & PFSW_F) {
  659. adap->swintr = 1;
  660. t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
  661. }
  662. if (adap->flags & MASTER_PF)
  663. t4_slow_intr_handler(adap);
  664. return IRQ_HANDLED;
  665. }
  666. /*
  667. * Name the MSI-X interrupts.
  668. */
  669. static void name_msix_vecs(struct adapter *adap)
  670. {
  671. int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
  672. /* non-data interrupts */
  673. snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
  674. /* FW events */
  675. snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
  676. adap->port[0]->name);
  677. /* Ethernet queues */
  678. for_each_port(adap, j) {
  679. struct net_device *d = adap->port[j];
  680. const struct port_info *pi = netdev_priv(d);
  681. for (i = 0; i < pi->nqsets; i++, msi_idx++)
  682. snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
  683. d->name, i);
  684. }
  685. /* offload queues */
  686. for_each_iscsirxq(&adap->sge, i)
  687. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-iscsi%d",
  688. adap->port[0]->name, i);
  689. for_each_iscsitrxq(&adap->sge, i)
  690. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-iSCSIT%d",
  691. adap->port[0]->name, i);
  692. for_each_rdmarxq(&adap->sge, i)
  693. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-rdma%d",
  694. adap->port[0]->name, i);
  695. for_each_rdmaciq(&adap->sge, i)
  696. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-rdma-ciq%d",
  697. adap->port[0]->name, i);
  698. }
  699. static int request_msix_queue_irqs(struct adapter *adap)
  700. {
  701. struct sge *s = &adap->sge;
  702. int err, ethqidx, iscsiqidx = 0, rdmaqidx = 0, rdmaciqqidx = 0;
  703. int iscsitqidx = 0;
  704. int msi_index = 2;
  705. err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
  706. adap->msix_info[1].desc, &s->fw_evtq);
  707. if (err)
  708. return err;
  709. for_each_ethrxq(s, ethqidx) {
  710. err = request_irq(adap->msix_info[msi_index].vec,
  711. t4_sge_intr_msix, 0,
  712. adap->msix_info[msi_index].desc,
  713. &s->ethrxq[ethqidx].rspq);
  714. if (err)
  715. goto unwind;
  716. msi_index++;
  717. }
  718. for_each_iscsirxq(s, iscsiqidx) {
  719. err = request_irq(adap->msix_info[msi_index].vec,
  720. t4_sge_intr_msix, 0,
  721. adap->msix_info[msi_index].desc,
  722. &s->iscsirxq[iscsiqidx].rspq);
  723. if (err)
  724. goto unwind;
  725. msi_index++;
  726. }
  727. for_each_iscsitrxq(s, iscsitqidx) {
  728. err = request_irq(adap->msix_info[msi_index].vec,
  729. t4_sge_intr_msix, 0,
  730. adap->msix_info[msi_index].desc,
  731. &s->iscsitrxq[iscsitqidx].rspq);
  732. if (err)
  733. goto unwind;
  734. msi_index++;
  735. }
  736. for_each_rdmarxq(s, rdmaqidx) {
  737. err = request_irq(adap->msix_info[msi_index].vec,
  738. t4_sge_intr_msix, 0,
  739. adap->msix_info[msi_index].desc,
  740. &s->rdmarxq[rdmaqidx].rspq);
  741. if (err)
  742. goto unwind;
  743. msi_index++;
  744. }
  745. for_each_rdmaciq(s, rdmaciqqidx) {
  746. err = request_irq(adap->msix_info[msi_index].vec,
  747. t4_sge_intr_msix, 0,
  748. adap->msix_info[msi_index].desc,
  749. &s->rdmaciq[rdmaciqqidx].rspq);
  750. if (err)
  751. goto unwind;
  752. msi_index++;
  753. }
  754. return 0;
  755. unwind:
  756. while (--rdmaciqqidx >= 0)
  757. free_irq(adap->msix_info[--msi_index].vec,
  758. &s->rdmaciq[rdmaciqqidx].rspq);
  759. while (--rdmaqidx >= 0)
  760. free_irq(adap->msix_info[--msi_index].vec,
  761. &s->rdmarxq[rdmaqidx].rspq);
  762. while (--iscsitqidx >= 0)
  763. free_irq(adap->msix_info[--msi_index].vec,
  764. &s->iscsitrxq[iscsitqidx].rspq);
  765. while (--iscsiqidx >= 0)
  766. free_irq(adap->msix_info[--msi_index].vec,
  767. &s->iscsirxq[iscsiqidx].rspq);
  768. while (--ethqidx >= 0)
  769. free_irq(adap->msix_info[--msi_index].vec,
  770. &s->ethrxq[ethqidx].rspq);
  771. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  772. return err;
  773. }
  774. static void free_msix_queue_irqs(struct adapter *adap)
  775. {
  776. int i, msi_index = 2;
  777. struct sge *s = &adap->sge;
  778. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  779. for_each_ethrxq(s, i)
  780. free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
  781. for_each_iscsirxq(s, i)
  782. free_irq(adap->msix_info[msi_index++].vec,
  783. &s->iscsirxq[i].rspq);
  784. for_each_iscsitrxq(s, i)
  785. free_irq(adap->msix_info[msi_index++].vec,
  786. &s->iscsitrxq[i].rspq);
  787. for_each_rdmarxq(s, i)
  788. free_irq(adap->msix_info[msi_index++].vec, &s->rdmarxq[i].rspq);
  789. for_each_rdmaciq(s, i)
  790. free_irq(adap->msix_info[msi_index++].vec, &s->rdmaciq[i].rspq);
  791. }
  792. /**
  793. * cxgb4_write_rss - write the RSS table for a given port
  794. * @pi: the port
  795. * @queues: array of queue indices for RSS
  796. *
  797. * Sets up the portion of the HW RSS table for the port's VI to distribute
  798. * packets to the Rx queues in @queues.
  799. * Should never be called before setting up sge eth rx queues
  800. */
  801. int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
  802. {
  803. u16 *rss;
  804. int i, err;
  805. struct adapter *adapter = pi->adapter;
  806. const struct sge_eth_rxq *rxq;
  807. rxq = &adapter->sge.ethrxq[pi->first_qset];
  808. rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
  809. if (!rss)
  810. return -ENOMEM;
  811. /* map the queue indices to queue ids */
  812. for (i = 0; i < pi->rss_size; i++, queues++)
  813. rss[i] = rxq[*queues].rspq.abs_id;
  814. err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
  815. pi->rss_size, rss, pi->rss_size);
  816. /* If Tunnel All Lookup isn't specified in the global RSS
  817. * Configuration, then we need to specify a default Ingress
  818. * Queue for any ingress packets which aren't hashed. We'll
  819. * use our first ingress queue ...
  820. */
  821. if (!err)
  822. err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
  823. FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F |
  824. FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F |
  825. FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F |
  826. FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F |
  827. FW_RSS_VI_CONFIG_CMD_UDPEN_F,
  828. rss[0]);
  829. kfree(rss);
  830. return err;
  831. }
  832. /**
  833. * setup_rss - configure RSS
  834. * @adap: the adapter
  835. *
  836. * Sets up RSS for each port.
  837. */
  838. static int setup_rss(struct adapter *adap)
  839. {
  840. int i, j, err;
  841. for_each_port(adap, i) {
  842. const struct port_info *pi = adap2pinfo(adap, i);
  843. /* Fill default values with equal distribution */
  844. for (j = 0; j < pi->rss_size; j++)
  845. pi->rss[j] = j % pi->nqsets;
  846. err = cxgb4_write_rss(pi, pi->rss);
  847. if (err)
  848. return err;
  849. }
  850. return 0;
  851. }
  852. /*
  853. * Return the channel of the ingress queue with the given qid.
  854. */
  855. static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
  856. {
  857. qid -= p->ingr_start;
  858. return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
  859. }
  860. /*
  861. * Wait until all NAPI handlers are descheduled.
  862. */
  863. static void quiesce_rx(struct adapter *adap)
  864. {
  865. int i;
  866. for (i = 0; i < adap->sge.ingr_sz; i++) {
  867. struct sge_rspq *q = adap->sge.ingr_map[i];
  868. if (q && q->handler) {
  869. napi_disable(&q->napi);
  870. local_bh_disable();
  871. while (!cxgb_poll_lock_napi(q))
  872. mdelay(1);
  873. local_bh_enable();
  874. }
  875. }
  876. }
  877. /* Disable interrupt and napi handler */
  878. static void disable_interrupts(struct adapter *adap)
  879. {
  880. if (adap->flags & FULL_INIT_DONE) {
  881. t4_intr_disable(adap);
  882. if (adap->flags & USING_MSIX) {
  883. free_msix_queue_irqs(adap);
  884. free_irq(adap->msix_info[0].vec, adap);
  885. } else {
  886. free_irq(adap->pdev->irq, adap);
  887. }
  888. quiesce_rx(adap);
  889. }
  890. }
  891. /*
  892. * Enable NAPI scheduling and interrupt generation for all Rx queues.
  893. */
  894. static void enable_rx(struct adapter *adap)
  895. {
  896. int i;
  897. for (i = 0; i < adap->sge.ingr_sz; i++) {
  898. struct sge_rspq *q = adap->sge.ingr_map[i];
  899. if (!q)
  900. continue;
  901. if (q->handler) {
  902. cxgb_busy_poll_init_lock(q);
  903. napi_enable(&q->napi);
  904. }
  905. /* 0-increment GTS to start the timer and enable interrupts */
  906. t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
  907. SEINTARM_V(q->intr_params) |
  908. INGRESSQID_V(q->cntxt_id));
  909. }
  910. }
  911. static int alloc_ofld_rxqs(struct adapter *adap, struct sge_ofld_rxq *q,
  912. unsigned int nq, unsigned int per_chan, int msi_idx,
  913. u16 *ids, bool lro)
  914. {
  915. int i, err;
  916. for (i = 0; i < nq; i++, q++) {
  917. if (msi_idx > 0)
  918. msi_idx++;
  919. err = t4_sge_alloc_rxq(adap, &q->rspq, false,
  920. adap->port[i / per_chan],
  921. msi_idx, q->fl.size ? &q->fl : NULL,
  922. uldrx_handler,
  923. lro ? uldrx_flush_handler : NULL,
  924. 0);
  925. if (err)
  926. return err;
  927. memset(&q->stats, 0, sizeof(q->stats));
  928. if (ids)
  929. ids[i] = q->rspq.abs_id;
  930. }
  931. return 0;
  932. }
  933. /**
  934. * setup_sge_queues - configure SGE Tx/Rx/response queues
  935. * @adap: the adapter
  936. *
  937. * Determines how many sets of SGE queues to use and initializes them.
  938. * We support multiple queue sets per port if we have MSI-X, otherwise
  939. * just one queue set per port.
  940. */
  941. static int setup_sge_queues(struct adapter *adap)
  942. {
  943. int err, msi_idx, i, j;
  944. struct sge *s = &adap->sge;
  945. bitmap_zero(s->starving_fl, s->egr_sz);
  946. bitmap_zero(s->txq_maperr, s->egr_sz);
  947. if (adap->flags & USING_MSIX)
  948. msi_idx = 1; /* vector 0 is for non-queue interrupts */
  949. else {
  950. err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
  951. NULL, NULL, NULL, -1);
  952. if (err)
  953. return err;
  954. msi_idx = -((int)s->intrq.abs_id + 1);
  955. }
  956. /* NOTE: If you add/delete any Ingress/Egress Queue allocations in here,
  957. * don't forget to update the following which need to be
  958. * synchronized to and changes here.
  959. *
  960. * 1. The calculations of MAX_INGQ in cxgb4.h.
  961. *
  962. * 2. Update enable_msix/name_msix_vecs/request_msix_queue_irqs
  963. * to accommodate any new/deleted Ingress Queues
  964. * which need MSI-X Vectors.
  965. *
  966. * 3. Update sge_qinfo_show() to include information on the
  967. * new/deleted queues.
  968. */
  969. err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
  970. msi_idx, NULL, fwevtq_handler, NULL, -1);
  971. if (err) {
  972. freeout: t4_free_sge_resources(adap);
  973. return err;
  974. }
  975. for_each_port(adap, i) {
  976. struct net_device *dev = adap->port[i];
  977. struct port_info *pi = netdev_priv(dev);
  978. struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
  979. struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
  980. for (j = 0; j < pi->nqsets; j++, q++) {
  981. if (msi_idx > 0)
  982. msi_idx++;
  983. err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
  984. msi_idx, &q->fl,
  985. t4_ethrx_handler,
  986. NULL,
  987. t4_get_mps_bg_map(adap,
  988. pi->tx_chan));
  989. if (err)
  990. goto freeout;
  991. q->rspq.idx = j;
  992. memset(&q->stats, 0, sizeof(q->stats));
  993. }
  994. for (j = 0; j < pi->nqsets; j++, t++) {
  995. err = t4_sge_alloc_eth_txq(adap, t, dev,
  996. netdev_get_tx_queue(dev, j),
  997. s->fw_evtq.cntxt_id);
  998. if (err)
  999. goto freeout;
  1000. }
  1001. }
  1002. j = s->iscsiqsets / adap->params.nports; /* iscsi queues per channel */
  1003. for_each_iscsirxq(s, i) {
  1004. err = t4_sge_alloc_ofld_txq(adap, &s->ofldtxq[i],
  1005. adap->port[i / j],
  1006. s->fw_evtq.cntxt_id);
  1007. if (err)
  1008. goto freeout;
  1009. }
  1010. #define ALLOC_OFLD_RXQS(firstq, nq, per_chan, ids, lro) do { \
  1011. err = alloc_ofld_rxqs(adap, firstq, nq, per_chan, msi_idx, ids, lro); \
  1012. if (err) \
  1013. goto freeout; \
  1014. if (msi_idx > 0) \
  1015. msi_idx += nq; \
  1016. } while (0)
  1017. ALLOC_OFLD_RXQS(s->iscsirxq, s->iscsiqsets, j, s->iscsi_rxq, false);
  1018. ALLOC_OFLD_RXQS(s->iscsitrxq, s->niscsitq, j, s->iscsit_rxq, true);
  1019. ALLOC_OFLD_RXQS(s->rdmarxq, s->rdmaqs, 1, s->rdma_rxq, false);
  1020. j = s->rdmaciqs / adap->params.nports; /* rdmaq queues per channel */
  1021. ALLOC_OFLD_RXQS(s->rdmaciq, s->rdmaciqs, j, s->rdma_ciq, false);
  1022. #undef ALLOC_OFLD_RXQS
  1023. for_each_port(adap, i) {
  1024. /*
  1025. * Note that ->rdmarxq[i].rspq.cntxt_id below is 0 if we don't
  1026. * have RDMA queues, and that's the right value.
  1027. */
  1028. err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
  1029. s->fw_evtq.cntxt_id,
  1030. s->rdmarxq[i].rspq.cntxt_id);
  1031. if (err)
  1032. goto freeout;
  1033. }
  1034. t4_write_reg(adap, is_t4(adap->params.chip) ?
  1035. MPS_TRC_RSS_CONTROL_A :
  1036. MPS_T5_TRC_RSS_CONTROL_A,
  1037. RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
  1038. QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
  1039. return 0;
  1040. }
  1041. /*
  1042. * Allocate a chunk of memory using kmalloc or, if that fails, vmalloc.
  1043. * The allocated memory is cleared.
  1044. */
  1045. void *t4_alloc_mem(size_t size)
  1046. {
  1047. void *p = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
  1048. if (!p)
  1049. p = vzalloc(size);
  1050. return p;
  1051. }
  1052. /*
  1053. * Free memory allocated through alloc_mem().
  1054. */
  1055. void t4_free_mem(void *addr)
  1056. {
  1057. kvfree(addr);
  1058. }
  1059. /* Send a Work Request to write the filter at a specified index. We construct
  1060. * a Firmware Filter Work Request to have the work done and put the indicated
  1061. * filter into "pending" mode which will prevent any further actions against
  1062. * it till we get a reply from the firmware on the completion status of the
  1063. * request.
  1064. */
  1065. static int set_filter_wr(struct adapter *adapter, int fidx)
  1066. {
  1067. struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
  1068. struct sk_buff *skb;
  1069. struct fw_filter_wr *fwr;
  1070. unsigned int ftid;
  1071. skb = alloc_skb(sizeof(*fwr), GFP_KERNEL);
  1072. if (!skb)
  1073. return -ENOMEM;
  1074. /* If the new filter requires loopback Destination MAC and/or VLAN
  1075. * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
  1076. * the filter.
  1077. */
  1078. if (f->fs.newdmac || f->fs.newvlan) {
  1079. /* allocate L2T entry for new filter */
  1080. f->l2t = t4_l2t_alloc_switching(adapter, f->fs.vlan,
  1081. f->fs.eport, f->fs.dmac);
  1082. if (f->l2t == NULL) {
  1083. kfree_skb(skb);
  1084. return -ENOMEM;
  1085. }
  1086. }
  1087. ftid = adapter->tids.ftid_base + fidx;
  1088. fwr = (struct fw_filter_wr *)__skb_put(skb, sizeof(*fwr));
  1089. memset(fwr, 0, sizeof(*fwr));
  1090. /* It would be nice to put most of the following in t4_hw.c but most
  1091. * of the work is translating the cxgbtool ch_filter_specification
  1092. * into the Work Request and the definition of that structure is
  1093. * currently in cxgbtool.h which isn't appropriate to pull into the
  1094. * common code. We may eventually try to come up with a more neutral
  1095. * filter specification structure but for now it's easiest to simply
  1096. * put this fairly direct code in line ...
  1097. */
  1098. fwr->op_pkd = htonl(FW_WR_OP_V(FW_FILTER_WR));
  1099. fwr->len16_pkd = htonl(FW_WR_LEN16_V(sizeof(*fwr)/16));
  1100. fwr->tid_to_iq =
  1101. htonl(FW_FILTER_WR_TID_V(ftid) |
  1102. FW_FILTER_WR_RQTYPE_V(f->fs.type) |
  1103. FW_FILTER_WR_NOREPLY_V(0) |
  1104. FW_FILTER_WR_IQ_V(f->fs.iq));
  1105. fwr->del_filter_to_l2tix =
  1106. htonl(FW_FILTER_WR_RPTTID_V(f->fs.rpttid) |
  1107. FW_FILTER_WR_DROP_V(f->fs.action == FILTER_DROP) |
  1108. FW_FILTER_WR_DIRSTEER_V(f->fs.dirsteer) |
  1109. FW_FILTER_WR_MASKHASH_V(f->fs.maskhash) |
  1110. FW_FILTER_WR_DIRSTEERHASH_V(f->fs.dirsteerhash) |
  1111. FW_FILTER_WR_LPBK_V(f->fs.action == FILTER_SWITCH) |
  1112. FW_FILTER_WR_DMAC_V(f->fs.newdmac) |
  1113. FW_FILTER_WR_SMAC_V(f->fs.newsmac) |
  1114. FW_FILTER_WR_INSVLAN_V(f->fs.newvlan == VLAN_INSERT ||
  1115. f->fs.newvlan == VLAN_REWRITE) |
  1116. FW_FILTER_WR_RMVLAN_V(f->fs.newvlan == VLAN_REMOVE ||
  1117. f->fs.newvlan == VLAN_REWRITE) |
  1118. FW_FILTER_WR_HITCNTS_V(f->fs.hitcnts) |
  1119. FW_FILTER_WR_TXCHAN_V(f->fs.eport) |
  1120. FW_FILTER_WR_PRIO_V(f->fs.prio) |
  1121. FW_FILTER_WR_L2TIX_V(f->l2t ? f->l2t->idx : 0));
  1122. fwr->ethtype = htons(f->fs.val.ethtype);
  1123. fwr->ethtypem = htons(f->fs.mask.ethtype);
  1124. fwr->frag_to_ovlan_vldm =
  1125. (FW_FILTER_WR_FRAG_V(f->fs.val.frag) |
  1126. FW_FILTER_WR_FRAGM_V(f->fs.mask.frag) |
  1127. FW_FILTER_WR_IVLAN_VLD_V(f->fs.val.ivlan_vld) |
  1128. FW_FILTER_WR_OVLAN_VLD_V(f->fs.val.ovlan_vld) |
  1129. FW_FILTER_WR_IVLAN_VLDM_V(f->fs.mask.ivlan_vld) |
  1130. FW_FILTER_WR_OVLAN_VLDM_V(f->fs.mask.ovlan_vld));
  1131. fwr->smac_sel = 0;
  1132. fwr->rx_chan_rx_rpl_iq =
  1133. htons(FW_FILTER_WR_RX_CHAN_V(0) |
  1134. FW_FILTER_WR_RX_RPL_IQ_V(adapter->sge.fw_evtq.abs_id));
  1135. fwr->maci_to_matchtypem =
  1136. htonl(FW_FILTER_WR_MACI_V(f->fs.val.macidx) |
  1137. FW_FILTER_WR_MACIM_V(f->fs.mask.macidx) |
  1138. FW_FILTER_WR_FCOE_V(f->fs.val.fcoe) |
  1139. FW_FILTER_WR_FCOEM_V(f->fs.mask.fcoe) |
  1140. FW_FILTER_WR_PORT_V(f->fs.val.iport) |
  1141. FW_FILTER_WR_PORTM_V(f->fs.mask.iport) |
  1142. FW_FILTER_WR_MATCHTYPE_V(f->fs.val.matchtype) |
  1143. FW_FILTER_WR_MATCHTYPEM_V(f->fs.mask.matchtype));
  1144. fwr->ptcl = f->fs.val.proto;
  1145. fwr->ptclm = f->fs.mask.proto;
  1146. fwr->ttyp = f->fs.val.tos;
  1147. fwr->ttypm = f->fs.mask.tos;
  1148. fwr->ivlan = htons(f->fs.val.ivlan);
  1149. fwr->ivlanm = htons(f->fs.mask.ivlan);
  1150. fwr->ovlan = htons(f->fs.val.ovlan);
  1151. fwr->ovlanm = htons(f->fs.mask.ovlan);
  1152. memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip));
  1153. memcpy(fwr->lipm, f->fs.mask.lip, sizeof(fwr->lipm));
  1154. memcpy(fwr->fip, f->fs.val.fip, sizeof(fwr->fip));
  1155. memcpy(fwr->fipm, f->fs.mask.fip, sizeof(fwr->fipm));
  1156. fwr->lp = htons(f->fs.val.lport);
  1157. fwr->lpm = htons(f->fs.mask.lport);
  1158. fwr->fp = htons(f->fs.val.fport);
  1159. fwr->fpm = htons(f->fs.mask.fport);
  1160. if (f->fs.newsmac)
  1161. memcpy(fwr->sma, f->fs.smac, sizeof(fwr->sma));
  1162. /* Mark the filter as "pending" and ship off the Filter Work Request.
  1163. * When we get the Work Request Reply we'll clear the pending status.
  1164. */
  1165. f->pending = 1;
  1166. set_wr_txq(skb, CPL_PRIORITY_CONTROL, f->fs.val.iport & 0x3);
  1167. t4_ofld_send(adapter, skb);
  1168. return 0;
  1169. }
  1170. /* Delete the filter at a specified index.
  1171. */
  1172. static int del_filter_wr(struct adapter *adapter, int fidx)
  1173. {
  1174. struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
  1175. struct sk_buff *skb;
  1176. struct fw_filter_wr *fwr;
  1177. unsigned int len, ftid;
  1178. len = sizeof(*fwr);
  1179. ftid = adapter->tids.ftid_base + fidx;
  1180. skb = alloc_skb(len, GFP_KERNEL);
  1181. if (!skb)
  1182. return -ENOMEM;
  1183. fwr = (struct fw_filter_wr *)__skb_put(skb, len);
  1184. t4_mk_filtdelwr(ftid, fwr, adapter->sge.fw_evtq.abs_id);
  1185. /* Mark the filter as "pending" and ship off the Filter Work Request.
  1186. * When we get the Work Request Reply we'll clear the pending status.
  1187. */
  1188. f->pending = 1;
  1189. t4_mgmt_tx(adapter, skb);
  1190. return 0;
  1191. }
  1192. static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
  1193. void *accel_priv, select_queue_fallback_t fallback)
  1194. {
  1195. int txq;
  1196. #ifdef CONFIG_CHELSIO_T4_DCB
  1197. /* If a Data Center Bridging has been successfully negotiated on this
  1198. * link then we'll use the skb's priority to map it to a TX Queue.
  1199. * The skb's priority is determined via the VLAN Tag Priority Code
  1200. * Point field.
  1201. */
  1202. if (cxgb4_dcb_enabled(dev)) {
  1203. u16 vlan_tci;
  1204. int err;
  1205. err = vlan_get_tag(skb, &vlan_tci);
  1206. if (unlikely(err)) {
  1207. if (net_ratelimit())
  1208. netdev_warn(dev,
  1209. "TX Packet without VLAN Tag on DCB Link\n");
  1210. txq = 0;
  1211. } else {
  1212. txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  1213. #ifdef CONFIG_CHELSIO_T4_FCOE
  1214. if (skb->protocol == htons(ETH_P_FCOE))
  1215. txq = skb->priority & 0x7;
  1216. #endif /* CONFIG_CHELSIO_T4_FCOE */
  1217. }
  1218. return txq;
  1219. }
  1220. #endif /* CONFIG_CHELSIO_T4_DCB */
  1221. if (select_queue) {
  1222. txq = (skb_rx_queue_recorded(skb)
  1223. ? skb_get_rx_queue(skb)
  1224. : smp_processor_id());
  1225. while (unlikely(txq >= dev->real_num_tx_queues))
  1226. txq -= dev->real_num_tx_queues;
  1227. return txq;
  1228. }
  1229. return fallback(dev, skb) % dev->real_num_tx_queues;
  1230. }
  1231. static int closest_timer(const struct sge *s, int time)
  1232. {
  1233. int i, delta, match = 0, min_delta = INT_MAX;
  1234. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  1235. delta = time - s->timer_val[i];
  1236. if (delta < 0)
  1237. delta = -delta;
  1238. if (delta < min_delta) {
  1239. min_delta = delta;
  1240. match = i;
  1241. }
  1242. }
  1243. return match;
  1244. }
  1245. static int closest_thres(const struct sge *s, int thres)
  1246. {
  1247. int i, delta, match = 0, min_delta = INT_MAX;
  1248. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  1249. delta = thres - s->counter_val[i];
  1250. if (delta < 0)
  1251. delta = -delta;
  1252. if (delta < min_delta) {
  1253. min_delta = delta;
  1254. match = i;
  1255. }
  1256. }
  1257. return match;
  1258. }
  1259. /**
  1260. * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
  1261. * @q: the Rx queue
  1262. * @us: the hold-off time in us, or 0 to disable timer
  1263. * @cnt: the hold-off packet count, or 0 to disable counter
  1264. *
  1265. * Sets an Rx queue's interrupt hold-off time and packet count. At least
  1266. * one of the two needs to be enabled for the queue to generate interrupts.
  1267. */
  1268. int cxgb4_set_rspq_intr_params(struct sge_rspq *q,
  1269. unsigned int us, unsigned int cnt)
  1270. {
  1271. struct adapter *adap = q->adap;
  1272. if ((us | cnt) == 0)
  1273. cnt = 1;
  1274. if (cnt) {
  1275. int err;
  1276. u32 v, new_idx;
  1277. new_idx = closest_thres(&adap->sge, cnt);
  1278. if (q->desc && q->pktcnt_idx != new_idx) {
  1279. /* the queue has already been created, update it */
  1280. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  1281. FW_PARAMS_PARAM_X_V(
  1282. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  1283. FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
  1284. err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
  1285. &v, &new_idx);
  1286. if (err)
  1287. return err;
  1288. }
  1289. q->pktcnt_idx = new_idx;
  1290. }
  1291. us = us == 0 ? 6 : closest_timer(&adap->sge, us);
  1292. q->intr_params = QINTR_TIMER_IDX_V(us) | QINTR_CNT_EN_V(cnt > 0);
  1293. return 0;
  1294. }
  1295. static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
  1296. {
  1297. const struct port_info *pi = netdev_priv(dev);
  1298. netdev_features_t changed = dev->features ^ features;
  1299. int err;
  1300. if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
  1301. return 0;
  1302. err = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, -1,
  1303. -1, -1, -1,
  1304. !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
  1305. if (unlikely(err))
  1306. dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
  1307. return err;
  1308. }
  1309. static int setup_debugfs(struct adapter *adap)
  1310. {
  1311. if (IS_ERR_OR_NULL(adap->debugfs_root))
  1312. return -1;
  1313. #ifdef CONFIG_DEBUG_FS
  1314. t4_setup_debugfs(adap);
  1315. #endif
  1316. return 0;
  1317. }
  1318. /*
  1319. * upper-layer driver support
  1320. */
  1321. /*
  1322. * Allocate an active-open TID and set it to the supplied value.
  1323. */
  1324. int cxgb4_alloc_atid(struct tid_info *t, void *data)
  1325. {
  1326. int atid = -1;
  1327. spin_lock_bh(&t->atid_lock);
  1328. if (t->afree) {
  1329. union aopen_entry *p = t->afree;
  1330. atid = (p - t->atid_tab) + t->atid_base;
  1331. t->afree = p->next;
  1332. p->data = data;
  1333. t->atids_in_use++;
  1334. }
  1335. spin_unlock_bh(&t->atid_lock);
  1336. return atid;
  1337. }
  1338. EXPORT_SYMBOL(cxgb4_alloc_atid);
  1339. /*
  1340. * Release an active-open TID.
  1341. */
  1342. void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
  1343. {
  1344. union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
  1345. spin_lock_bh(&t->atid_lock);
  1346. p->next = t->afree;
  1347. t->afree = p;
  1348. t->atids_in_use--;
  1349. spin_unlock_bh(&t->atid_lock);
  1350. }
  1351. EXPORT_SYMBOL(cxgb4_free_atid);
  1352. /*
  1353. * Allocate a server TID and set it to the supplied value.
  1354. */
  1355. int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
  1356. {
  1357. int stid;
  1358. spin_lock_bh(&t->stid_lock);
  1359. if (family == PF_INET) {
  1360. stid = find_first_zero_bit(t->stid_bmap, t->nstids);
  1361. if (stid < t->nstids)
  1362. __set_bit(stid, t->stid_bmap);
  1363. else
  1364. stid = -1;
  1365. } else {
  1366. stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 1);
  1367. if (stid < 0)
  1368. stid = -1;
  1369. }
  1370. if (stid >= 0) {
  1371. t->stid_tab[stid].data = data;
  1372. stid += t->stid_base;
  1373. /* IPv6 requires max of 520 bits or 16 cells in TCAM
  1374. * This is equivalent to 4 TIDs. With CLIP enabled it
  1375. * needs 2 TIDs.
  1376. */
  1377. if (family == PF_INET)
  1378. t->stids_in_use++;
  1379. else
  1380. t->stids_in_use += 2;
  1381. }
  1382. spin_unlock_bh(&t->stid_lock);
  1383. return stid;
  1384. }
  1385. EXPORT_SYMBOL(cxgb4_alloc_stid);
  1386. /* Allocate a server filter TID and set it to the supplied value.
  1387. */
  1388. int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
  1389. {
  1390. int stid;
  1391. spin_lock_bh(&t->stid_lock);
  1392. if (family == PF_INET) {
  1393. stid = find_next_zero_bit(t->stid_bmap,
  1394. t->nstids + t->nsftids, t->nstids);
  1395. if (stid < (t->nstids + t->nsftids))
  1396. __set_bit(stid, t->stid_bmap);
  1397. else
  1398. stid = -1;
  1399. } else {
  1400. stid = -1;
  1401. }
  1402. if (stid >= 0) {
  1403. t->stid_tab[stid].data = data;
  1404. stid -= t->nstids;
  1405. stid += t->sftid_base;
  1406. t->sftids_in_use++;
  1407. }
  1408. spin_unlock_bh(&t->stid_lock);
  1409. return stid;
  1410. }
  1411. EXPORT_SYMBOL(cxgb4_alloc_sftid);
  1412. /* Release a server TID.
  1413. */
  1414. void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
  1415. {
  1416. /* Is it a server filter TID? */
  1417. if (t->nsftids && (stid >= t->sftid_base)) {
  1418. stid -= t->sftid_base;
  1419. stid += t->nstids;
  1420. } else {
  1421. stid -= t->stid_base;
  1422. }
  1423. spin_lock_bh(&t->stid_lock);
  1424. if (family == PF_INET)
  1425. __clear_bit(stid, t->stid_bmap);
  1426. else
  1427. bitmap_release_region(t->stid_bmap, stid, 1);
  1428. t->stid_tab[stid].data = NULL;
  1429. if (stid < t->nstids) {
  1430. if (family == PF_INET)
  1431. t->stids_in_use--;
  1432. else
  1433. t->stids_in_use -= 2;
  1434. } else {
  1435. t->sftids_in_use--;
  1436. }
  1437. spin_unlock_bh(&t->stid_lock);
  1438. }
  1439. EXPORT_SYMBOL(cxgb4_free_stid);
  1440. /*
  1441. * Populate a TID_RELEASE WR. Caller must properly size the skb.
  1442. */
  1443. static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
  1444. unsigned int tid)
  1445. {
  1446. struct cpl_tid_release *req;
  1447. set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
  1448. req = (struct cpl_tid_release *)__skb_put(skb, sizeof(*req));
  1449. INIT_TP_WR(req, tid);
  1450. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  1451. }
  1452. /*
  1453. * Queue a TID release request and if necessary schedule a work queue to
  1454. * process it.
  1455. */
  1456. static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
  1457. unsigned int tid)
  1458. {
  1459. void **p = &t->tid_tab[tid];
  1460. struct adapter *adap = container_of(t, struct adapter, tids);
  1461. spin_lock_bh(&adap->tid_release_lock);
  1462. *p = adap->tid_release_head;
  1463. /* Low 2 bits encode the Tx channel number */
  1464. adap->tid_release_head = (void **)((uintptr_t)p | chan);
  1465. if (!adap->tid_release_task_busy) {
  1466. adap->tid_release_task_busy = true;
  1467. queue_work(adap->workq, &adap->tid_release_task);
  1468. }
  1469. spin_unlock_bh(&adap->tid_release_lock);
  1470. }
  1471. /*
  1472. * Process the list of pending TID release requests.
  1473. */
  1474. static void process_tid_release_list(struct work_struct *work)
  1475. {
  1476. struct sk_buff *skb;
  1477. struct adapter *adap;
  1478. adap = container_of(work, struct adapter, tid_release_task);
  1479. spin_lock_bh(&adap->tid_release_lock);
  1480. while (adap->tid_release_head) {
  1481. void **p = adap->tid_release_head;
  1482. unsigned int chan = (uintptr_t)p & 3;
  1483. p = (void *)p - chan;
  1484. adap->tid_release_head = *p;
  1485. *p = NULL;
  1486. spin_unlock_bh(&adap->tid_release_lock);
  1487. while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
  1488. GFP_KERNEL)))
  1489. schedule_timeout_uninterruptible(1);
  1490. mk_tid_release(skb, chan, p - adap->tids.tid_tab);
  1491. t4_ofld_send(adap, skb);
  1492. spin_lock_bh(&adap->tid_release_lock);
  1493. }
  1494. adap->tid_release_task_busy = false;
  1495. spin_unlock_bh(&adap->tid_release_lock);
  1496. }
  1497. /*
  1498. * Release a TID and inform HW. If we are unable to allocate the release
  1499. * message we defer to a work queue.
  1500. */
  1501. void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid)
  1502. {
  1503. struct sk_buff *skb;
  1504. struct adapter *adap = container_of(t, struct adapter, tids);
  1505. WARN_ON(tid >= t->ntids);
  1506. if (t->tid_tab[tid]) {
  1507. t->tid_tab[tid] = NULL;
  1508. if (t->hash_base && (tid >= t->hash_base))
  1509. atomic_dec(&t->hash_tids_in_use);
  1510. else
  1511. atomic_dec(&t->tids_in_use);
  1512. }
  1513. skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
  1514. if (likely(skb)) {
  1515. mk_tid_release(skb, chan, tid);
  1516. t4_ofld_send(adap, skb);
  1517. } else
  1518. cxgb4_queue_tid_release(t, chan, tid);
  1519. }
  1520. EXPORT_SYMBOL(cxgb4_remove_tid);
  1521. /*
  1522. * Allocate and initialize the TID tables. Returns 0 on success.
  1523. */
  1524. static int tid_init(struct tid_info *t)
  1525. {
  1526. size_t size;
  1527. unsigned int stid_bmap_size;
  1528. unsigned int natids = t->natids;
  1529. struct adapter *adap = container_of(t, struct adapter, tids);
  1530. stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
  1531. size = t->ntids * sizeof(*t->tid_tab) +
  1532. natids * sizeof(*t->atid_tab) +
  1533. t->nstids * sizeof(*t->stid_tab) +
  1534. t->nsftids * sizeof(*t->stid_tab) +
  1535. stid_bmap_size * sizeof(long) +
  1536. t->nftids * sizeof(*t->ftid_tab) +
  1537. t->nsftids * sizeof(*t->ftid_tab);
  1538. t->tid_tab = t4_alloc_mem(size);
  1539. if (!t->tid_tab)
  1540. return -ENOMEM;
  1541. t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
  1542. t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
  1543. t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
  1544. t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
  1545. spin_lock_init(&t->stid_lock);
  1546. spin_lock_init(&t->atid_lock);
  1547. t->stids_in_use = 0;
  1548. t->sftids_in_use = 0;
  1549. t->afree = NULL;
  1550. t->atids_in_use = 0;
  1551. atomic_set(&t->tids_in_use, 0);
  1552. atomic_set(&t->hash_tids_in_use, 0);
  1553. /* Setup the free list for atid_tab and clear the stid bitmap. */
  1554. if (natids) {
  1555. while (--natids)
  1556. t->atid_tab[natids - 1].next = &t->atid_tab[natids];
  1557. t->afree = t->atid_tab;
  1558. }
  1559. bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
  1560. /* Reserve stid 0 for T4/T5 adapters */
  1561. if (!t->stid_base &&
  1562. (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5))
  1563. __set_bit(0, t->stid_bmap);
  1564. return 0;
  1565. }
  1566. /**
  1567. * cxgb4_create_server - create an IP server
  1568. * @dev: the device
  1569. * @stid: the server TID
  1570. * @sip: local IP address to bind server to
  1571. * @sport: the server's TCP port
  1572. * @queue: queue to direct messages from this server to
  1573. *
  1574. * Create an IP server for the given port and address.
  1575. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1576. */
  1577. int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
  1578. __be32 sip, __be16 sport, __be16 vlan,
  1579. unsigned int queue)
  1580. {
  1581. unsigned int chan;
  1582. struct sk_buff *skb;
  1583. struct adapter *adap;
  1584. struct cpl_pass_open_req *req;
  1585. int ret;
  1586. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1587. if (!skb)
  1588. return -ENOMEM;
  1589. adap = netdev2adap(dev);
  1590. req = (struct cpl_pass_open_req *)__skb_put(skb, sizeof(*req));
  1591. INIT_TP_WR(req, 0);
  1592. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
  1593. req->local_port = sport;
  1594. req->peer_port = htons(0);
  1595. req->local_ip = sip;
  1596. req->peer_ip = htonl(0);
  1597. chan = rxq_to_chan(&adap->sge, queue);
  1598. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1599. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1600. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1601. ret = t4_mgmt_tx(adap, skb);
  1602. return net_xmit_eval(ret);
  1603. }
  1604. EXPORT_SYMBOL(cxgb4_create_server);
  1605. /* cxgb4_create_server6 - create an IPv6 server
  1606. * @dev: the device
  1607. * @stid: the server TID
  1608. * @sip: local IPv6 address to bind server to
  1609. * @sport: the server's TCP port
  1610. * @queue: queue to direct messages from this server to
  1611. *
  1612. * Create an IPv6 server for the given port and address.
  1613. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1614. */
  1615. int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
  1616. const struct in6_addr *sip, __be16 sport,
  1617. unsigned int queue)
  1618. {
  1619. unsigned int chan;
  1620. struct sk_buff *skb;
  1621. struct adapter *adap;
  1622. struct cpl_pass_open_req6 *req;
  1623. int ret;
  1624. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1625. if (!skb)
  1626. return -ENOMEM;
  1627. adap = netdev2adap(dev);
  1628. req = (struct cpl_pass_open_req6 *)__skb_put(skb, sizeof(*req));
  1629. INIT_TP_WR(req, 0);
  1630. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
  1631. req->local_port = sport;
  1632. req->peer_port = htons(0);
  1633. req->local_ip_hi = *(__be64 *)(sip->s6_addr);
  1634. req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
  1635. req->peer_ip_hi = cpu_to_be64(0);
  1636. req->peer_ip_lo = cpu_to_be64(0);
  1637. chan = rxq_to_chan(&adap->sge, queue);
  1638. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1639. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1640. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1641. ret = t4_mgmt_tx(adap, skb);
  1642. return net_xmit_eval(ret);
  1643. }
  1644. EXPORT_SYMBOL(cxgb4_create_server6);
  1645. int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
  1646. unsigned int queue, bool ipv6)
  1647. {
  1648. struct sk_buff *skb;
  1649. struct adapter *adap;
  1650. struct cpl_close_listsvr_req *req;
  1651. int ret;
  1652. adap = netdev2adap(dev);
  1653. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1654. if (!skb)
  1655. return -ENOMEM;
  1656. req = (struct cpl_close_listsvr_req *)__skb_put(skb, sizeof(*req));
  1657. INIT_TP_WR(req, 0);
  1658. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
  1659. req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
  1660. LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
  1661. ret = t4_mgmt_tx(adap, skb);
  1662. return net_xmit_eval(ret);
  1663. }
  1664. EXPORT_SYMBOL(cxgb4_remove_server);
  1665. /**
  1666. * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
  1667. * @mtus: the HW MTU table
  1668. * @mtu: the target MTU
  1669. * @idx: index of selected entry in the MTU table
  1670. *
  1671. * Returns the index and the value in the HW MTU table that is closest to
  1672. * but does not exceed @mtu, unless @mtu is smaller than any value in the
  1673. * table, in which case that smallest available value is selected.
  1674. */
  1675. unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
  1676. unsigned int *idx)
  1677. {
  1678. unsigned int i = 0;
  1679. while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
  1680. ++i;
  1681. if (idx)
  1682. *idx = i;
  1683. return mtus[i];
  1684. }
  1685. EXPORT_SYMBOL(cxgb4_best_mtu);
  1686. /**
  1687. * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
  1688. * @mtus: the HW MTU table
  1689. * @header_size: Header Size
  1690. * @data_size_max: maximum Data Segment Size
  1691. * @data_size_align: desired Data Segment Size Alignment (2^N)
  1692. * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
  1693. *
  1694. * Similar to cxgb4_best_mtu() but instead of searching the Hardware
  1695. * MTU Table based solely on a Maximum MTU parameter, we break that
  1696. * parameter up into a Header Size and Maximum Data Segment Size, and
  1697. * provide a desired Data Segment Size Alignment. If we find an MTU in
  1698. * the Hardware MTU Table which will result in a Data Segment Size with
  1699. * the requested alignment _and_ that MTU isn't "too far" from the
  1700. * closest MTU, then we'll return that rather than the closest MTU.
  1701. */
  1702. unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
  1703. unsigned short header_size,
  1704. unsigned short data_size_max,
  1705. unsigned short data_size_align,
  1706. unsigned int *mtu_idxp)
  1707. {
  1708. unsigned short max_mtu = header_size + data_size_max;
  1709. unsigned short data_size_align_mask = data_size_align - 1;
  1710. int mtu_idx, aligned_mtu_idx;
  1711. /* Scan the MTU Table till we find an MTU which is larger than our
  1712. * Maximum MTU or we reach the end of the table. Along the way,
  1713. * record the last MTU found, if any, which will result in a Data
  1714. * Segment Length matching the requested alignment.
  1715. */
  1716. for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
  1717. unsigned short data_size = mtus[mtu_idx] - header_size;
  1718. /* If this MTU minus the Header Size would result in a
  1719. * Data Segment Size of the desired alignment, remember it.
  1720. */
  1721. if ((data_size & data_size_align_mask) == 0)
  1722. aligned_mtu_idx = mtu_idx;
  1723. /* If we're not at the end of the Hardware MTU Table and the
  1724. * next element is larger than our Maximum MTU, drop out of
  1725. * the loop.
  1726. */
  1727. if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
  1728. break;
  1729. }
  1730. /* If we fell out of the loop because we ran to the end of the table,
  1731. * then we just have to use the last [largest] entry.
  1732. */
  1733. if (mtu_idx == NMTUS)
  1734. mtu_idx--;
  1735. /* If we found an MTU which resulted in the requested Data Segment
  1736. * Length alignment and that's "not far" from the largest MTU which is
  1737. * less than or equal to the maximum MTU, then use that.
  1738. */
  1739. if (aligned_mtu_idx >= 0 &&
  1740. mtu_idx - aligned_mtu_idx <= 1)
  1741. mtu_idx = aligned_mtu_idx;
  1742. /* If the caller has passed in an MTU Index pointer, pass the
  1743. * MTU Index back. Return the MTU value.
  1744. */
  1745. if (mtu_idxp)
  1746. *mtu_idxp = mtu_idx;
  1747. return mtus[mtu_idx];
  1748. }
  1749. EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
  1750. /**
  1751. * cxgb4_tp_smt_idx - Get the Source Mac Table index for this VI
  1752. * @chip: chip type
  1753. * @viid: VI id of the given port
  1754. *
  1755. * Return the SMT index for this VI.
  1756. */
  1757. unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid)
  1758. {
  1759. /* In T4/T5, SMT contains 256 SMAC entries organized in
  1760. * 128 rows of 2 entries each.
  1761. * In T6, SMT contains 256 SMAC entries in 256 rows.
  1762. * TODO: The below code needs to be updated when we add support
  1763. * for 256 VFs.
  1764. */
  1765. if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5)
  1766. return ((viid & 0x7f) << 1);
  1767. else
  1768. return (viid & 0x7f);
  1769. }
  1770. EXPORT_SYMBOL(cxgb4_tp_smt_idx);
  1771. /**
  1772. * cxgb4_port_chan - get the HW channel of a port
  1773. * @dev: the net device for the port
  1774. *
  1775. * Return the HW Tx channel of the given port.
  1776. */
  1777. unsigned int cxgb4_port_chan(const struct net_device *dev)
  1778. {
  1779. return netdev2pinfo(dev)->tx_chan;
  1780. }
  1781. EXPORT_SYMBOL(cxgb4_port_chan);
  1782. unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
  1783. {
  1784. struct adapter *adap = netdev2adap(dev);
  1785. u32 v1, v2, lp_count, hp_count;
  1786. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1787. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1788. if (is_t4(adap->params.chip)) {
  1789. lp_count = LP_COUNT_G(v1);
  1790. hp_count = HP_COUNT_G(v1);
  1791. } else {
  1792. lp_count = LP_COUNT_T5_G(v1);
  1793. hp_count = HP_COUNT_T5_G(v2);
  1794. }
  1795. return lpfifo ? lp_count : hp_count;
  1796. }
  1797. EXPORT_SYMBOL(cxgb4_dbfifo_count);
  1798. /**
  1799. * cxgb4_port_viid - get the VI id of a port
  1800. * @dev: the net device for the port
  1801. *
  1802. * Return the VI id of the given port.
  1803. */
  1804. unsigned int cxgb4_port_viid(const struct net_device *dev)
  1805. {
  1806. return netdev2pinfo(dev)->viid;
  1807. }
  1808. EXPORT_SYMBOL(cxgb4_port_viid);
  1809. /**
  1810. * cxgb4_port_idx - get the index of a port
  1811. * @dev: the net device for the port
  1812. *
  1813. * Return the index of the given port.
  1814. */
  1815. unsigned int cxgb4_port_idx(const struct net_device *dev)
  1816. {
  1817. return netdev2pinfo(dev)->port_id;
  1818. }
  1819. EXPORT_SYMBOL(cxgb4_port_idx);
  1820. void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
  1821. struct tp_tcp_stats *v6)
  1822. {
  1823. struct adapter *adap = pci_get_drvdata(pdev);
  1824. spin_lock(&adap->stats_lock);
  1825. t4_tp_get_tcp_stats(adap, v4, v6);
  1826. spin_unlock(&adap->stats_lock);
  1827. }
  1828. EXPORT_SYMBOL(cxgb4_get_tcp_stats);
  1829. void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
  1830. const unsigned int *pgsz_order)
  1831. {
  1832. struct adapter *adap = netdev2adap(dev);
  1833. t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
  1834. t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
  1835. HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
  1836. HPZ3_V(pgsz_order[3]));
  1837. }
  1838. EXPORT_SYMBOL(cxgb4_iscsi_init);
  1839. int cxgb4_flush_eq_cache(struct net_device *dev)
  1840. {
  1841. struct adapter *adap = netdev2adap(dev);
  1842. return t4_sge_ctxt_flush(adap, adap->mbox);
  1843. }
  1844. EXPORT_SYMBOL(cxgb4_flush_eq_cache);
  1845. static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
  1846. {
  1847. u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
  1848. __be64 indices;
  1849. int ret;
  1850. spin_lock(&adap->win0_lock);
  1851. ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
  1852. sizeof(indices), (__be32 *)&indices,
  1853. T4_MEMORY_READ);
  1854. spin_unlock(&adap->win0_lock);
  1855. if (!ret) {
  1856. *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
  1857. *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
  1858. }
  1859. return ret;
  1860. }
  1861. int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
  1862. u16 size)
  1863. {
  1864. struct adapter *adap = netdev2adap(dev);
  1865. u16 hw_pidx, hw_cidx;
  1866. int ret;
  1867. ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
  1868. if (ret)
  1869. goto out;
  1870. if (pidx != hw_pidx) {
  1871. u16 delta;
  1872. u32 val;
  1873. if (pidx >= hw_pidx)
  1874. delta = pidx - hw_pidx;
  1875. else
  1876. delta = size - hw_pidx + pidx;
  1877. if (is_t4(adap->params.chip))
  1878. val = PIDX_V(delta);
  1879. else
  1880. val = PIDX_T5_V(delta);
  1881. wmb();
  1882. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1883. QID_V(qid) | val);
  1884. }
  1885. out:
  1886. return ret;
  1887. }
  1888. EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
  1889. int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
  1890. {
  1891. struct adapter *adap;
  1892. u32 offset, memtype, memaddr;
  1893. u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
  1894. u32 edc0_end, edc1_end, mc0_end, mc1_end;
  1895. int ret;
  1896. adap = netdev2adap(dev);
  1897. offset = ((stag >> 8) * 32) + adap->vres.stag.start;
  1898. /* Figure out where the offset lands in the Memory Type/Address scheme.
  1899. * This code assumes that the memory is laid out starting at offset 0
  1900. * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
  1901. * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
  1902. * MC0, and some have both MC0 and MC1.
  1903. */
  1904. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  1905. edc0_size = EDRAM0_SIZE_G(size) << 20;
  1906. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  1907. edc1_size = EDRAM1_SIZE_G(size) << 20;
  1908. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  1909. mc0_size = EXT_MEM0_SIZE_G(size) << 20;
  1910. edc0_end = edc0_size;
  1911. edc1_end = edc0_end + edc1_size;
  1912. mc0_end = edc1_end + mc0_size;
  1913. if (offset < edc0_end) {
  1914. memtype = MEM_EDC0;
  1915. memaddr = offset;
  1916. } else if (offset < edc1_end) {
  1917. memtype = MEM_EDC1;
  1918. memaddr = offset - edc0_end;
  1919. } else {
  1920. if (offset < mc0_end) {
  1921. memtype = MEM_MC0;
  1922. memaddr = offset - edc1_end;
  1923. } else if (is_t5(adap->params.chip)) {
  1924. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  1925. mc1_size = EXT_MEM1_SIZE_G(size) << 20;
  1926. mc1_end = mc0_end + mc1_size;
  1927. if (offset < mc1_end) {
  1928. memtype = MEM_MC1;
  1929. memaddr = offset - mc0_end;
  1930. } else {
  1931. /* offset beyond the end of any memory */
  1932. goto err;
  1933. }
  1934. } else {
  1935. /* T4/T6 only has a single memory channel */
  1936. goto err;
  1937. }
  1938. }
  1939. spin_lock(&adap->win0_lock);
  1940. ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
  1941. spin_unlock(&adap->win0_lock);
  1942. return ret;
  1943. err:
  1944. dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
  1945. stag, offset);
  1946. return -EINVAL;
  1947. }
  1948. EXPORT_SYMBOL(cxgb4_read_tpte);
  1949. u64 cxgb4_read_sge_timestamp(struct net_device *dev)
  1950. {
  1951. u32 hi, lo;
  1952. struct adapter *adap;
  1953. adap = netdev2adap(dev);
  1954. lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
  1955. hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
  1956. return ((u64)hi << 32) | (u64)lo;
  1957. }
  1958. EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
  1959. int cxgb4_bar2_sge_qregs(struct net_device *dev,
  1960. unsigned int qid,
  1961. enum cxgb4_bar2_qtype qtype,
  1962. int user,
  1963. u64 *pbar2_qoffset,
  1964. unsigned int *pbar2_qid)
  1965. {
  1966. return t4_bar2_sge_qregs(netdev2adap(dev),
  1967. qid,
  1968. (qtype == CXGB4_BAR2_QTYPE_EGRESS
  1969. ? T4_BAR2_QTYPE_EGRESS
  1970. : T4_BAR2_QTYPE_INGRESS),
  1971. user,
  1972. pbar2_qoffset,
  1973. pbar2_qid);
  1974. }
  1975. EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
  1976. static struct pci_driver cxgb4_driver;
  1977. static void check_neigh_update(struct neighbour *neigh)
  1978. {
  1979. const struct device *parent;
  1980. const struct net_device *netdev = neigh->dev;
  1981. if (netdev->priv_flags & IFF_802_1Q_VLAN)
  1982. netdev = vlan_dev_real_dev(netdev);
  1983. parent = netdev->dev.parent;
  1984. if (parent && parent->driver == &cxgb4_driver.driver)
  1985. t4_l2t_update(dev_get_drvdata(parent), neigh);
  1986. }
  1987. static int netevent_cb(struct notifier_block *nb, unsigned long event,
  1988. void *data)
  1989. {
  1990. switch (event) {
  1991. case NETEVENT_NEIGH_UPDATE:
  1992. check_neigh_update(data);
  1993. break;
  1994. case NETEVENT_REDIRECT:
  1995. default:
  1996. break;
  1997. }
  1998. return 0;
  1999. }
  2000. static bool netevent_registered;
  2001. static struct notifier_block cxgb4_netevent_nb = {
  2002. .notifier_call = netevent_cb
  2003. };
  2004. static void drain_db_fifo(struct adapter *adap, int usecs)
  2005. {
  2006. u32 v1, v2, lp_count, hp_count;
  2007. do {
  2008. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  2009. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  2010. if (is_t4(adap->params.chip)) {
  2011. lp_count = LP_COUNT_G(v1);
  2012. hp_count = HP_COUNT_G(v1);
  2013. } else {
  2014. lp_count = LP_COUNT_T5_G(v1);
  2015. hp_count = HP_COUNT_T5_G(v2);
  2016. }
  2017. if (lp_count == 0 && hp_count == 0)
  2018. break;
  2019. set_current_state(TASK_UNINTERRUPTIBLE);
  2020. schedule_timeout(usecs_to_jiffies(usecs));
  2021. } while (1);
  2022. }
  2023. static void disable_txq_db(struct sge_txq *q)
  2024. {
  2025. unsigned long flags;
  2026. spin_lock_irqsave(&q->db_lock, flags);
  2027. q->db_disabled = 1;
  2028. spin_unlock_irqrestore(&q->db_lock, flags);
  2029. }
  2030. static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
  2031. {
  2032. spin_lock_irq(&q->db_lock);
  2033. if (q->db_pidx_inc) {
  2034. /* Make sure that all writes to the TX descriptors
  2035. * are committed before we tell HW about them.
  2036. */
  2037. wmb();
  2038. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  2039. QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
  2040. q->db_pidx_inc = 0;
  2041. }
  2042. q->db_disabled = 0;
  2043. spin_unlock_irq(&q->db_lock);
  2044. }
  2045. static void disable_dbs(struct adapter *adap)
  2046. {
  2047. int i;
  2048. for_each_ethrxq(&adap->sge, i)
  2049. disable_txq_db(&adap->sge.ethtxq[i].q);
  2050. for_each_iscsirxq(&adap->sge, i)
  2051. disable_txq_db(&adap->sge.ofldtxq[i].q);
  2052. for_each_port(adap, i)
  2053. disable_txq_db(&adap->sge.ctrlq[i].q);
  2054. }
  2055. static void enable_dbs(struct adapter *adap)
  2056. {
  2057. int i;
  2058. for_each_ethrxq(&adap->sge, i)
  2059. enable_txq_db(adap, &adap->sge.ethtxq[i].q);
  2060. for_each_iscsirxq(&adap->sge, i)
  2061. enable_txq_db(adap, &adap->sge.ofldtxq[i].q);
  2062. for_each_port(adap, i)
  2063. enable_txq_db(adap, &adap->sge.ctrlq[i].q);
  2064. }
  2065. static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
  2066. {
  2067. if (adap->uld_handle[CXGB4_ULD_RDMA])
  2068. ulds[CXGB4_ULD_RDMA].control(adap->uld_handle[CXGB4_ULD_RDMA],
  2069. cmd);
  2070. }
  2071. static void process_db_full(struct work_struct *work)
  2072. {
  2073. struct adapter *adap;
  2074. adap = container_of(work, struct adapter, db_full_task);
  2075. drain_db_fifo(adap, dbfifo_drain_delay);
  2076. enable_dbs(adap);
  2077. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  2078. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  2079. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  2080. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
  2081. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
  2082. else
  2083. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  2084. DBFIFO_LP_INT_F, DBFIFO_LP_INT_F);
  2085. }
  2086. static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
  2087. {
  2088. u16 hw_pidx, hw_cidx;
  2089. int ret;
  2090. spin_lock_irq(&q->db_lock);
  2091. ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
  2092. if (ret)
  2093. goto out;
  2094. if (q->db_pidx != hw_pidx) {
  2095. u16 delta;
  2096. u32 val;
  2097. if (q->db_pidx >= hw_pidx)
  2098. delta = q->db_pidx - hw_pidx;
  2099. else
  2100. delta = q->size - hw_pidx + q->db_pidx;
  2101. if (is_t4(adap->params.chip))
  2102. val = PIDX_V(delta);
  2103. else
  2104. val = PIDX_T5_V(delta);
  2105. wmb();
  2106. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  2107. QID_V(q->cntxt_id) | val);
  2108. }
  2109. out:
  2110. q->db_disabled = 0;
  2111. q->db_pidx_inc = 0;
  2112. spin_unlock_irq(&q->db_lock);
  2113. if (ret)
  2114. CH_WARN(adap, "DB drop recovery failed.\n");
  2115. }
  2116. static void recover_all_queues(struct adapter *adap)
  2117. {
  2118. int i;
  2119. for_each_ethrxq(&adap->sge, i)
  2120. sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
  2121. for_each_iscsirxq(&adap->sge, i)
  2122. sync_txq_pidx(adap, &adap->sge.ofldtxq[i].q);
  2123. for_each_port(adap, i)
  2124. sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
  2125. }
  2126. static void process_db_drop(struct work_struct *work)
  2127. {
  2128. struct adapter *adap;
  2129. adap = container_of(work, struct adapter, db_drop_task);
  2130. if (is_t4(adap->params.chip)) {
  2131. drain_db_fifo(adap, dbfifo_drain_delay);
  2132. notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
  2133. drain_db_fifo(adap, dbfifo_drain_delay);
  2134. recover_all_queues(adap);
  2135. drain_db_fifo(adap, dbfifo_drain_delay);
  2136. enable_dbs(adap);
  2137. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  2138. } else if (is_t5(adap->params.chip)) {
  2139. u32 dropped_db = t4_read_reg(adap, 0x010ac);
  2140. u16 qid = (dropped_db >> 15) & 0x1ffff;
  2141. u16 pidx_inc = dropped_db & 0x1fff;
  2142. u64 bar2_qoffset;
  2143. unsigned int bar2_qid;
  2144. int ret;
  2145. ret = t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
  2146. 0, &bar2_qoffset, &bar2_qid);
  2147. if (ret)
  2148. dev_err(adap->pdev_dev, "doorbell drop recovery: "
  2149. "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
  2150. else
  2151. writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
  2152. adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
  2153. /* Re-enable BAR2 WC */
  2154. t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
  2155. }
  2156. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  2157. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
  2158. }
  2159. void t4_db_full(struct adapter *adap)
  2160. {
  2161. if (is_t4(adap->params.chip)) {
  2162. disable_dbs(adap);
  2163. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  2164. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  2165. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
  2166. queue_work(adap->workq, &adap->db_full_task);
  2167. }
  2168. }
  2169. void t4_db_dropped(struct adapter *adap)
  2170. {
  2171. if (is_t4(adap->params.chip)) {
  2172. disable_dbs(adap);
  2173. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  2174. }
  2175. queue_work(adap->workq, &adap->db_drop_task);
  2176. }
  2177. static void uld_attach(struct adapter *adap, unsigned int uld)
  2178. {
  2179. void *handle;
  2180. struct cxgb4_lld_info lli;
  2181. unsigned short i;
  2182. lli.pdev = adap->pdev;
  2183. lli.pf = adap->pf;
  2184. lli.l2t = adap->l2t;
  2185. lli.tids = &adap->tids;
  2186. lli.ports = adap->port;
  2187. lli.vr = &adap->vres;
  2188. lli.mtus = adap->params.mtus;
  2189. if (uld == CXGB4_ULD_RDMA) {
  2190. lli.rxq_ids = adap->sge.rdma_rxq;
  2191. lli.ciq_ids = adap->sge.rdma_ciq;
  2192. lli.nrxq = adap->sge.rdmaqs;
  2193. lli.nciq = adap->sge.rdmaciqs;
  2194. } else if (uld == CXGB4_ULD_ISCSI) {
  2195. lli.rxq_ids = adap->sge.iscsi_rxq;
  2196. lli.nrxq = adap->sge.iscsiqsets;
  2197. } else if (uld == CXGB4_ULD_ISCSIT) {
  2198. lli.rxq_ids = adap->sge.iscsit_rxq;
  2199. lli.nrxq = adap->sge.niscsitq;
  2200. }
  2201. lli.ntxq = adap->sge.iscsiqsets;
  2202. lli.nchan = adap->params.nports;
  2203. lli.nports = adap->params.nports;
  2204. lli.wr_cred = adap->params.ofldq_wr_cred;
  2205. lli.adapter_type = adap->params.chip;
  2206. lli.iscsi_iolen = MAXRXDATA_G(t4_read_reg(adap, TP_PARA_REG2_A));
  2207. lli.iscsi_tagmask = t4_read_reg(adap, ULP_RX_ISCSI_TAGMASK_A);
  2208. lli.iscsi_pgsz_order = t4_read_reg(adap, ULP_RX_ISCSI_PSZ_A);
  2209. lli.iscsi_llimit = t4_read_reg(adap, ULP_RX_ISCSI_LLIMIT_A);
  2210. lli.iscsi_ppm = &adap->iscsi_ppm;
  2211. lli.cclk_ps = 1000000000 / adap->params.vpd.cclk;
  2212. lli.udb_density = 1 << adap->params.sge.eq_qpp;
  2213. lli.ucq_density = 1 << adap->params.sge.iq_qpp;
  2214. lli.filt_mode = adap->params.tp.vlan_pri_map;
  2215. /* MODQ_REQ_MAP sets queues 0-3 to chan 0-3 */
  2216. for (i = 0; i < NCHAN; i++)
  2217. lli.tx_modq[i] = i;
  2218. lli.gts_reg = adap->regs + MYPF_REG(SGE_PF_GTS_A);
  2219. lli.db_reg = adap->regs + MYPF_REG(SGE_PF_KDOORBELL_A);
  2220. lli.fw_vers = adap->params.fw_vers;
  2221. lli.dbfifo_int_thresh = dbfifo_int_thresh;
  2222. lli.sge_ingpadboundary = adap->sge.fl_align;
  2223. lli.sge_egrstatuspagesize = adap->sge.stat_len;
  2224. lli.sge_pktshift = adap->sge.pktshift;
  2225. lli.enable_fw_ofld_conn = adap->flags & FW_OFLD_CONN;
  2226. lli.max_ordird_qp = adap->params.max_ordird_qp;
  2227. lli.max_ird_adapter = adap->params.max_ird_adapter;
  2228. lli.ulptx_memwrite_dsgl = adap->params.ulptx_memwrite_dsgl;
  2229. lli.nodeid = dev_to_node(adap->pdev_dev);
  2230. handle = ulds[uld].add(&lli);
  2231. if (IS_ERR(handle)) {
  2232. dev_warn(adap->pdev_dev,
  2233. "could not attach to the %s driver, error %ld\n",
  2234. uld_str[uld], PTR_ERR(handle));
  2235. return;
  2236. }
  2237. adap->uld_handle[uld] = handle;
  2238. if (!netevent_registered) {
  2239. register_netevent_notifier(&cxgb4_netevent_nb);
  2240. netevent_registered = true;
  2241. }
  2242. if (adap->flags & FULL_INIT_DONE)
  2243. ulds[uld].state_change(handle, CXGB4_STATE_UP);
  2244. }
  2245. static void attach_ulds(struct adapter *adap)
  2246. {
  2247. unsigned int i;
  2248. spin_lock(&adap_rcu_lock);
  2249. list_add_tail_rcu(&adap->rcu_node, &adap_rcu_list);
  2250. spin_unlock(&adap_rcu_lock);
  2251. mutex_lock(&uld_mutex);
  2252. list_add_tail(&adap->list_node, &adapter_list);
  2253. for (i = 0; i < CXGB4_ULD_MAX; i++)
  2254. if (ulds[i].add)
  2255. uld_attach(adap, i);
  2256. mutex_unlock(&uld_mutex);
  2257. }
  2258. static void detach_ulds(struct adapter *adap)
  2259. {
  2260. unsigned int i;
  2261. mutex_lock(&uld_mutex);
  2262. list_del(&adap->list_node);
  2263. for (i = 0; i < CXGB4_ULD_MAX; i++)
  2264. if (adap->uld_handle[i]) {
  2265. ulds[i].state_change(adap->uld_handle[i],
  2266. CXGB4_STATE_DETACH);
  2267. adap->uld_handle[i] = NULL;
  2268. }
  2269. if (netevent_registered && list_empty(&adapter_list)) {
  2270. unregister_netevent_notifier(&cxgb4_netevent_nb);
  2271. netevent_registered = false;
  2272. }
  2273. mutex_unlock(&uld_mutex);
  2274. spin_lock(&adap_rcu_lock);
  2275. list_del_rcu(&adap->rcu_node);
  2276. spin_unlock(&adap_rcu_lock);
  2277. }
  2278. static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
  2279. {
  2280. unsigned int i;
  2281. mutex_lock(&uld_mutex);
  2282. for (i = 0; i < CXGB4_ULD_MAX; i++)
  2283. if (adap->uld_handle[i])
  2284. ulds[i].state_change(adap->uld_handle[i], new_state);
  2285. mutex_unlock(&uld_mutex);
  2286. }
  2287. /**
  2288. * cxgb4_register_uld - register an upper-layer driver
  2289. * @type: the ULD type
  2290. * @p: the ULD methods
  2291. *
  2292. * Registers an upper-layer driver with this driver and notifies the ULD
  2293. * about any presently available devices that support its type. Returns
  2294. * %-EBUSY if a ULD of the same type is already registered.
  2295. */
  2296. int cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p)
  2297. {
  2298. int ret = 0;
  2299. struct adapter *adap;
  2300. if (type >= CXGB4_ULD_MAX)
  2301. return -EINVAL;
  2302. mutex_lock(&uld_mutex);
  2303. if (ulds[type].add) {
  2304. ret = -EBUSY;
  2305. goto out;
  2306. }
  2307. ulds[type] = *p;
  2308. list_for_each_entry(adap, &adapter_list, list_node)
  2309. uld_attach(adap, type);
  2310. out: mutex_unlock(&uld_mutex);
  2311. return ret;
  2312. }
  2313. EXPORT_SYMBOL(cxgb4_register_uld);
  2314. /**
  2315. * cxgb4_unregister_uld - unregister an upper-layer driver
  2316. * @type: the ULD type
  2317. *
  2318. * Unregisters an existing upper-layer driver.
  2319. */
  2320. int cxgb4_unregister_uld(enum cxgb4_uld type)
  2321. {
  2322. struct adapter *adap;
  2323. if (type >= CXGB4_ULD_MAX)
  2324. return -EINVAL;
  2325. mutex_lock(&uld_mutex);
  2326. list_for_each_entry(adap, &adapter_list, list_node)
  2327. adap->uld_handle[type] = NULL;
  2328. ulds[type].add = NULL;
  2329. mutex_unlock(&uld_mutex);
  2330. return 0;
  2331. }
  2332. EXPORT_SYMBOL(cxgb4_unregister_uld);
  2333. #if IS_ENABLED(CONFIG_IPV6)
  2334. static int cxgb4_inet6addr_handler(struct notifier_block *this,
  2335. unsigned long event, void *data)
  2336. {
  2337. struct inet6_ifaddr *ifa = data;
  2338. struct net_device *event_dev = ifa->idev->dev;
  2339. const struct device *parent = NULL;
  2340. #if IS_ENABLED(CONFIG_BONDING)
  2341. struct adapter *adap;
  2342. #endif
  2343. if (event_dev->priv_flags & IFF_802_1Q_VLAN)
  2344. event_dev = vlan_dev_real_dev(event_dev);
  2345. #if IS_ENABLED(CONFIG_BONDING)
  2346. if (event_dev->flags & IFF_MASTER) {
  2347. list_for_each_entry(adap, &adapter_list, list_node) {
  2348. switch (event) {
  2349. case NETDEV_UP:
  2350. cxgb4_clip_get(adap->port[0],
  2351. (const u32 *)ifa, 1);
  2352. break;
  2353. case NETDEV_DOWN:
  2354. cxgb4_clip_release(adap->port[0],
  2355. (const u32 *)ifa, 1);
  2356. break;
  2357. default:
  2358. break;
  2359. }
  2360. }
  2361. return NOTIFY_OK;
  2362. }
  2363. #endif
  2364. if (event_dev)
  2365. parent = event_dev->dev.parent;
  2366. if (parent && parent->driver == &cxgb4_driver.driver) {
  2367. switch (event) {
  2368. case NETDEV_UP:
  2369. cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
  2370. break;
  2371. case NETDEV_DOWN:
  2372. cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
  2373. break;
  2374. default:
  2375. break;
  2376. }
  2377. }
  2378. return NOTIFY_OK;
  2379. }
  2380. static bool inet6addr_registered;
  2381. static struct notifier_block cxgb4_inet6addr_notifier = {
  2382. .notifier_call = cxgb4_inet6addr_handler
  2383. };
  2384. static void update_clip(const struct adapter *adap)
  2385. {
  2386. int i;
  2387. struct net_device *dev;
  2388. int ret;
  2389. rcu_read_lock();
  2390. for (i = 0; i < MAX_NPORTS; i++) {
  2391. dev = adap->port[i];
  2392. ret = 0;
  2393. if (dev)
  2394. ret = cxgb4_update_root_dev_clip(dev);
  2395. if (ret < 0)
  2396. break;
  2397. }
  2398. rcu_read_unlock();
  2399. }
  2400. #endif /* IS_ENABLED(CONFIG_IPV6) */
  2401. /**
  2402. * cxgb_up - enable the adapter
  2403. * @adap: adapter being enabled
  2404. *
  2405. * Called when the first port is enabled, this function performs the
  2406. * actions necessary to make an adapter operational, such as completing
  2407. * the initialization of HW modules, and enabling interrupts.
  2408. *
  2409. * Must be called with the rtnl lock held.
  2410. */
  2411. static int cxgb_up(struct adapter *adap)
  2412. {
  2413. int err;
  2414. err = setup_sge_queues(adap);
  2415. if (err)
  2416. goto out;
  2417. err = setup_rss(adap);
  2418. if (err)
  2419. goto freeq;
  2420. if (adap->flags & USING_MSIX) {
  2421. name_msix_vecs(adap);
  2422. err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
  2423. adap->msix_info[0].desc, adap);
  2424. if (err)
  2425. goto irq_err;
  2426. err = request_msix_queue_irqs(adap);
  2427. if (err) {
  2428. free_irq(adap->msix_info[0].vec, adap);
  2429. goto irq_err;
  2430. }
  2431. } else {
  2432. err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
  2433. (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
  2434. adap->port[0]->name, adap);
  2435. if (err)
  2436. goto irq_err;
  2437. }
  2438. enable_rx(adap);
  2439. t4_sge_start(adap);
  2440. t4_intr_enable(adap);
  2441. adap->flags |= FULL_INIT_DONE;
  2442. notify_ulds(adap, CXGB4_STATE_UP);
  2443. #if IS_ENABLED(CONFIG_IPV6)
  2444. update_clip(adap);
  2445. #endif
  2446. /* Initialize hash mac addr list*/
  2447. INIT_LIST_HEAD(&adap->mac_hlist);
  2448. out:
  2449. return err;
  2450. irq_err:
  2451. dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
  2452. freeq:
  2453. t4_free_sge_resources(adap);
  2454. goto out;
  2455. }
  2456. static void cxgb_down(struct adapter *adapter)
  2457. {
  2458. cancel_work_sync(&adapter->tid_release_task);
  2459. cancel_work_sync(&adapter->db_full_task);
  2460. cancel_work_sync(&adapter->db_drop_task);
  2461. adapter->tid_release_task_busy = false;
  2462. adapter->tid_release_head = NULL;
  2463. t4_sge_stop(adapter);
  2464. t4_free_sge_resources(adapter);
  2465. adapter->flags &= ~FULL_INIT_DONE;
  2466. }
  2467. /*
  2468. * net_device operations
  2469. */
  2470. static int cxgb_open(struct net_device *dev)
  2471. {
  2472. int err;
  2473. struct port_info *pi = netdev_priv(dev);
  2474. struct adapter *adapter = pi->adapter;
  2475. netif_carrier_off(dev);
  2476. if (!(adapter->flags & FULL_INIT_DONE)) {
  2477. err = cxgb_up(adapter);
  2478. if (err < 0)
  2479. return err;
  2480. }
  2481. err = link_start(dev);
  2482. if (!err)
  2483. netif_tx_start_all_queues(dev);
  2484. return err;
  2485. }
  2486. static int cxgb_close(struct net_device *dev)
  2487. {
  2488. struct port_info *pi = netdev_priv(dev);
  2489. struct adapter *adapter = pi->adapter;
  2490. netif_tx_stop_all_queues(dev);
  2491. netif_carrier_off(dev);
  2492. return t4_enable_vi(adapter, adapter->pf, pi->viid, false, false);
  2493. }
  2494. /* Return an error number if the indicated filter isn't writable ...
  2495. */
  2496. static int writable_filter(struct filter_entry *f)
  2497. {
  2498. if (f->locked)
  2499. return -EPERM;
  2500. if (f->pending)
  2501. return -EBUSY;
  2502. return 0;
  2503. }
  2504. /* Delete the filter at the specified index (if valid). The checks for all
  2505. * the common problems with doing this like the filter being locked, currently
  2506. * pending in another operation, etc.
  2507. */
  2508. static int delete_filter(struct adapter *adapter, unsigned int fidx)
  2509. {
  2510. struct filter_entry *f;
  2511. int ret;
  2512. if (fidx >= adapter->tids.nftids + adapter->tids.nsftids)
  2513. return -EINVAL;
  2514. f = &adapter->tids.ftid_tab[fidx];
  2515. ret = writable_filter(f);
  2516. if (ret)
  2517. return ret;
  2518. if (f->valid)
  2519. return del_filter_wr(adapter, fidx);
  2520. return 0;
  2521. }
  2522. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  2523. __be32 sip, __be16 sport, __be16 vlan,
  2524. unsigned int queue, unsigned char port, unsigned char mask)
  2525. {
  2526. int ret;
  2527. struct filter_entry *f;
  2528. struct adapter *adap;
  2529. int i;
  2530. u8 *val;
  2531. adap = netdev2adap(dev);
  2532. /* Adjust stid to correct filter index */
  2533. stid -= adap->tids.sftid_base;
  2534. stid += adap->tids.nftids;
  2535. /* Check to make sure the filter requested is writable ...
  2536. */
  2537. f = &adap->tids.ftid_tab[stid];
  2538. ret = writable_filter(f);
  2539. if (ret)
  2540. return ret;
  2541. /* Clear out any old resources being used by the filter before
  2542. * we start constructing the new filter.
  2543. */
  2544. if (f->valid)
  2545. clear_filter(adap, f);
  2546. /* Clear out filter specifications */
  2547. memset(&f->fs, 0, sizeof(struct ch_filter_specification));
  2548. f->fs.val.lport = cpu_to_be16(sport);
  2549. f->fs.mask.lport = ~0;
  2550. val = (u8 *)&sip;
  2551. if ((val[0] | val[1] | val[2] | val[3]) != 0) {
  2552. for (i = 0; i < 4; i++) {
  2553. f->fs.val.lip[i] = val[i];
  2554. f->fs.mask.lip[i] = ~0;
  2555. }
  2556. if (adap->params.tp.vlan_pri_map & PORT_F) {
  2557. f->fs.val.iport = port;
  2558. f->fs.mask.iport = mask;
  2559. }
  2560. }
  2561. if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
  2562. f->fs.val.proto = IPPROTO_TCP;
  2563. f->fs.mask.proto = ~0;
  2564. }
  2565. f->fs.dirsteer = 1;
  2566. f->fs.iq = queue;
  2567. /* Mark filter as locked */
  2568. f->locked = 1;
  2569. f->fs.rpttid = 1;
  2570. ret = set_filter_wr(adap, stid);
  2571. if (ret) {
  2572. clear_filter(adap, f);
  2573. return ret;
  2574. }
  2575. return 0;
  2576. }
  2577. EXPORT_SYMBOL(cxgb4_create_server_filter);
  2578. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  2579. unsigned int queue, bool ipv6)
  2580. {
  2581. int ret;
  2582. struct filter_entry *f;
  2583. struct adapter *adap;
  2584. adap = netdev2adap(dev);
  2585. /* Adjust stid to correct filter index */
  2586. stid -= adap->tids.sftid_base;
  2587. stid += adap->tids.nftids;
  2588. f = &adap->tids.ftid_tab[stid];
  2589. /* Unlock the filter */
  2590. f->locked = 0;
  2591. ret = delete_filter(adap, stid);
  2592. if (ret)
  2593. return ret;
  2594. return 0;
  2595. }
  2596. EXPORT_SYMBOL(cxgb4_remove_server_filter);
  2597. static struct rtnl_link_stats64 *cxgb_get_stats(struct net_device *dev,
  2598. struct rtnl_link_stats64 *ns)
  2599. {
  2600. struct port_stats stats;
  2601. struct port_info *p = netdev_priv(dev);
  2602. struct adapter *adapter = p->adapter;
  2603. /* Block retrieving statistics during EEH error
  2604. * recovery. Otherwise, the recovery might fail
  2605. * and the PCI device will be removed permanently
  2606. */
  2607. spin_lock(&adapter->stats_lock);
  2608. if (!netif_device_present(dev)) {
  2609. spin_unlock(&adapter->stats_lock);
  2610. return ns;
  2611. }
  2612. t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
  2613. &p->stats_base);
  2614. spin_unlock(&adapter->stats_lock);
  2615. ns->tx_bytes = stats.tx_octets;
  2616. ns->tx_packets = stats.tx_frames;
  2617. ns->rx_bytes = stats.rx_octets;
  2618. ns->rx_packets = stats.rx_frames;
  2619. ns->multicast = stats.rx_mcast_frames;
  2620. /* detailed rx_errors */
  2621. ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
  2622. stats.rx_runt;
  2623. ns->rx_over_errors = 0;
  2624. ns->rx_crc_errors = stats.rx_fcs_err;
  2625. ns->rx_frame_errors = stats.rx_symbol_err;
  2626. ns->rx_fifo_errors = stats.rx_ovflow0 + stats.rx_ovflow1 +
  2627. stats.rx_ovflow2 + stats.rx_ovflow3 +
  2628. stats.rx_trunc0 + stats.rx_trunc1 +
  2629. stats.rx_trunc2 + stats.rx_trunc3;
  2630. ns->rx_missed_errors = 0;
  2631. /* detailed tx_errors */
  2632. ns->tx_aborted_errors = 0;
  2633. ns->tx_carrier_errors = 0;
  2634. ns->tx_fifo_errors = 0;
  2635. ns->tx_heartbeat_errors = 0;
  2636. ns->tx_window_errors = 0;
  2637. ns->tx_errors = stats.tx_error_frames;
  2638. ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
  2639. ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
  2640. return ns;
  2641. }
  2642. static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  2643. {
  2644. unsigned int mbox;
  2645. int ret = 0, prtad, devad;
  2646. struct port_info *pi = netdev_priv(dev);
  2647. struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
  2648. switch (cmd) {
  2649. case SIOCGMIIPHY:
  2650. if (pi->mdio_addr < 0)
  2651. return -EOPNOTSUPP;
  2652. data->phy_id = pi->mdio_addr;
  2653. break;
  2654. case SIOCGMIIREG:
  2655. case SIOCSMIIREG:
  2656. if (mdio_phy_id_is_c45(data->phy_id)) {
  2657. prtad = mdio_phy_id_prtad(data->phy_id);
  2658. devad = mdio_phy_id_devad(data->phy_id);
  2659. } else if (data->phy_id < 32) {
  2660. prtad = data->phy_id;
  2661. devad = 0;
  2662. data->reg_num &= 0x1f;
  2663. } else
  2664. return -EINVAL;
  2665. mbox = pi->adapter->pf;
  2666. if (cmd == SIOCGMIIREG)
  2667. ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
  2668. data->reg_num, &data->val_out);
  2669. else
  2670. ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
  2671. data->reg_num, data->val_in);
  2672. break;
  2673. case SIOCGHWTSTAMP:
  2674. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2675. sizeof(pi->tstamp_config)) ?
  2676. -EFAULT : 0;
  2677. case SIOCSHWTSTAMP:
  2678. if (copy_from_user(&pi->tstamp_config, req->ifr_data,
  2679. sizeof(pi->tstamp_config)))
  2680. return -EFAULT;
  2681. switch (pi->tstamp_config.rx_filter) {
  2682. case HWTSTAMP_FILTER_NONE:
  2683. pi->rxtstamp = false;
  2684. break;
  2685. case HWTSTAMP_FILTER_ALL:
  2686. pi->rxtstamp = true;
  2687. break;
  2688. default:
  2689. pi->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
  2690. return -ERANGE;
  2691. }
  2692. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2693. sizeof(pi->tstamp_config)) ?
  2694. -EFAULT : 0;
  2695. default:
  2696. return -EOPNOTSUPP;
  2697. }
  2698. return ret;
  2699. }
  2700. static void cxgb_set_rxmode(struct net_device *dev)
  2701. {
  2702. /* unfortunately we can't return errors to the stack */
  2703. set_rxmode(dev, -1, false);
  2704. }
  2705. static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
  2706. {
  2707. int ret;
  2708. struct port_info *pi = netdev_priv(dev);
  2709. if (new_mtu < 81 || new_mtu > MAX_MTU) /* accommodate SACK */
  2710. return -EINVAL;
  2711. ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
  2712. -1, -1, -1, true);
  2713. if (!ret)
  2714. dev->mtu = new_mtu;
  2715. return ret;
  2716. }
  2717. static int cxgb_set_mac_addr(struct net_device *dev, void *p)
  2718. {
  2719. int ret;
  2720. struct sockaddr *addr = p;
  2721. struct port_info *pi = netdev_priv(dev);
  2722. if (!is_valid_ether_addr(addr->sa_data))
  2723. return -EADDRNOTAVAIL;
  2724. ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
  2725. pi->xact_addr_filt, addr->sa_data, true, true);
  2726. if (ret < 0)
  2727. return ret;
  2728. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2729. pi->xact_addr_filt = ret;
  2730. return 0;
  2731. }
  2732. #ifdef CONFIG_NET_POLL_CONTROLLER
  2733. static void cxgb_netpoll(struct net_device *dev)
  2734. {
  2735. struct port_info *pi = netdev_priv(dev);
  2736. struct adapter *adap = pi->adapter;
  2737. if (adap->flags & USING_MSIX) {
  2738. int i;
  2739. struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
  2740. for (i = pi->nqsets; i; i--, rx++)
  2741. t4_sge_intr_msix(0, &rx->rspq);
  2742. } else
  2743. t4_intr_handler(adap)(0, adap);
  2744. }
  2745. #endif
  2746. static const struct net_device_ops cxgb4_netdev_ops = {
  2747. .ndo_open = cxgb_open,
  2748. .ndo_stop = cxgb_close,
  2749. .ndo_start_xmit = t4_eth_xmit,
  2750. .ndo_select_queue = cxgb_select_queue,
  2751. .ndo_get_stats64 = cxgb_get_stats,
  2752. .ndo_set_rx_mode = cxgb_set_rxmode,
  2753. .ndo_set_mac_address = cxgb_set_mac_addr,
  2754. .ndo_set_features = cxgb_set_features,
  2755. .ndo_validate_addr = eth_validate_addr,
  2756. .ndo_do_ioctl = cxgb_ioctl,
  2757. .ndo_change_mtu = cxgb_change_mtu,
  2758. #ifdef CONFIG_NET_POLL_CONTROLLER
  2759. .ndo_poll_controller = cxgb_netpoll,
  2760. #endif
  2761. #ifdef CONFIG_CHELSIO_T4_FCOE
  2762. .ndo_fcoe_enable = cxgb_fcoe_enable,
  2763. .ndo_fcoe_disable = cxgb_fcoe_disable,
  2764. #endif /* CONFIG_CHELSIO_T4_FCOE */
  2765. #ifdef CONFIG_NET_RX_BUSY_POLL
  2766. .ndo_busy_poll = cxgb_busy_poll,
  2767. #endif
  2768. };
  2769. void t4_fatal_err(struct adapter *adap)
  2770. {
  2771. t4_set_reg_field(adap, SGE_CONTROL_A, GLOBALENABLE_F, 0);
  2772. t4_intr_disable(adap);
  2773. dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
  2774. }
  2775. static void setup_memwin(struct adapter *adap)
  2776. {
  2777. u32 nic_win_base = t4_get_util_window(adap);
  2778. t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
  2779. }
  2780. static void setup_memwin_rdma(struct adapter *adap)
  2781. {
  2782. if (adap->vres.ocq.size) {
  2783. u32 start;
  2784. unsigned int sz_kb;
  2785. start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
  2786. start &= PCI_BASE_ADDRESS_MEM_MASK;
  2787. start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
  2788. sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
  2789. t4_write_reg(adap,
  2790. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
  2791. start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
  2792. t4_write_reg(adap,
  2793. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
  2794. adap->vres.ocq.start);
  2795. t4_read_reg(adap,
  2796. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
  2797. }
  2798. }
  2799. static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
  2800. {
  2801. u32 v;
  2802. int ret;
  2803. /* get device capabilities */
  2804. memset(c, 0, sizeof(*c));
  2805. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2806. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  2807. c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
  2808. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
  2809. if (ret < 0)
  2810. return ret;
  2811. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2812. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  2813. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
  2814. if (ret < 0)
  2815. return ret;
  2816. ret = t4_config_glbl_rss(adap, adap->pf,
  2817. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
  2818. FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
  2819. FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
  2820. if (ret < 0)
  2821. return ret;
  2822. ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
  2823. MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
  2824. FW_CMD_CAP_PF);
  2825. if (ret < 0)
  2826. return ret;
  2827. t4_sge_init(adap);
  2828. /* tweak some settings */
  2829. t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
  2830. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
  2831. t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
  2832. v = t4_read_reg(adap, TP_PIO_DATA_A);
  2833. t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
  2834. /* first 4 Tx modulation queues point to consecutive Tx channels */
  2835. adap->params.tp.tx_modq_map = 0xE4;
  2836. t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
  2837. TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
  2838. /* associate each Tx modulation queue with consecutive Tx channels */
  2839. v = 0x84218421;
  2840. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2841. &v, 1, TP_TX_SCHED_HDR_A);
  2842. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2843. &v, 1, TP_TX_SCHED_FIFO_A);
  2844. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2845. &v, 1, TP_TX_SCHED_PCMD_A);
  2846. #define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
  2847. if (is_offload(adap)) {
  2848. t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
  2849. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2850. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2851. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2852. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  2853. t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
  2854. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2855. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2856. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2857. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  2858. }
  2859. /* get basic stuff going */
  2860. return t4_early_init(adap, adap->pf);
  2861. }
  2862. /*
  2863. * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
  2864. */
  2865. #define MAX_ATIDS 8192U
  2866. /*
  2867. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  2868. *
  2869. * If the firmware we're dealing with has Configuration File support, then
  2870. * we use that to perform all configuration
  2871. */
  2872. /*
  2873. * Tweak configuration based on module parameters, etc. Most of these have
  2874. * defaults assigned to them by Firmware Configuration Files (if we're using
  2875. * them) but need to be explicitly set if we're using hard-coded
  2876. * initialization. But even in the case of using Firmware Configuration
  2877. * Files, we'd like to expose the ability to change these via module
  2878. * parameters so these are essentially common tweaks/settings for
  2879. * Configuration Files and hard-coded initialization ...
  2880. */
  2881. static int adap_init0_tweaks(struct adapter *adapter)
  2882. {
  2883. /*
  2884. * Fix up various Host-Dependent Parameters like Page Size, Cache
  2885. * Line Size, etc. The firmware default is for a 4KB Page Size and
  2886. * 64B Cache Line Size ...
  2887. */
  2888. t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
  2889. /*
  2890. * Process module parameters which affect early initialization.
  2891. */
  2892. if (rx_dma_offset != 2 && rx_dma_offset != 0) {
  2893. dev_err(&adapter->pdev->dev,
  2894. "Ignoring illegal rx_dma_offset=%d, using 2\n",
  2895. rx_dma_offset);
  2896. rx_dma_offset = 2;
  2897. }
  2898. t4_set_reg_field(adapter, SGE_CONTROL_A,
  2899. PKTSHIFT_V(PKTSHIFT_M),
  2900. PKTSHIFT_V(rx_dma_offset));
  2901. /*
  2902. * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
  2903. * adds the pseudo header itself.
  2904. */
  2905. t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
  2906. CSUM_HAS_PSEUDO_HDR_F, 0);
  2907. return 0;
  2908. }
  2909. /* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
  2910. * unto themselves and they contain their own firmware to perform their
  2911. * tasks ...
  2912. */
  2913. static int phy_aq1202_version(const u8 *phy_fw_data,
  2914. size_t phy_fw_size)
  2915. {
  2916. int offset;
  2917. /* At offset 0x8 you're looking for the primary image's
  2918. * starting offset which is 3 Bytes wide
  2919. *
  2920. * At offset 0xa of the primary image, you look for the offset
  2921. * of the DRAM segment which is 3 Bytes wide.
  2922. *
  2923. * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
  2924. * wide
  2925. */
  2926. #define be16(__p) (((__p)[0] << 8) | (__p)[1])
  2927. #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
  2928. #define le24(__p) (le16(__p) | ((__p)[2] << 16))
  2929. offset = le24(phy_fw_data + 0x8) << 12;
  2930. offset = le24(phy_fw_data + offset + 0xa);
  2931. return be16(phy_fw_data + offset + 0x27e);
  2932. #undef be16
  2933. #undef le16
  2934. #undef le24
  2935. }
  2936. static struct info_10gbt_phy_fw {
  2937. unsigned int phy_fw_id; /* PCI Device ID */
  2938. char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
  2939. int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
  2940. int phy_flash; /* Has FLASH for PHY Firmware */
  2941. } phy_info_array[] = {
  2942. {
  2943. PHY_AQ1202_DEVICEID,
  2944. PHY_AQ1202_FIRMWARE,
  2945. phy_aq1202_version,
  2946. 1,
  2947. },
  2948. {
  2949. PHY_BCM84834_DEVICEID,
  2950. PHY_BCM84834_FIRMWARE,
  2951. NULL,
  2952. 0,
  2953. },
  2954. { 0, NULL, NULL },
  2955. };
  2956. static struct info_10gbt_phy_fw *find_phy_info(int devid)
  2957. {
  2958. int i;
  2959. for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
  2960. if (phy_info_array[i].phy_fw_id == devid)
  2961. return &phy_info_array[i];
  2962. }
  2963. return NULL;
  2964. }
  2965. /* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
  2966. * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
  2967. * we return a negative error number. If we transfer new firmware we return 1
  2968. * (from t4_load_phy_fw()). If we don't do anything we return 0.
  2969. */
  2970. static int adap_init0_phy(struct adapter *adap)
  2971. {
  2972. const struct firmware *phyf;
  2973. int ret;
  2974. struct info_10gbt_phy_fw *phy_info;
  2975. /* Use the device ID to determine which PHY file to flash.
  2976. */
  2977. phy_info = find_phy_info(adap->pdev->device);
  2978. if (!phy_info) {
  2979. dev_warn(adap->pdev_dev,
  2980. "No PHY Firmware file found for this PHY\n");
  2981. return -EOPNOTSUPP;
  2982. }
  2983. /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
  2984. * use that. The adapter firmware provides us with a memory buffer
  2985. * where we can load a PHY firmware file from the host if we want to
  2986. * override the PHY firmware File in flash.
  2987. */
  2988. ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
  2989. adap->pdev_dev);
  2990. if (ret < 0) {
  2991. /* For adapters without FLASH attached to PHY for their
  2992. * firmware, it's obviously a fatal error if we can't get the
  2993. * firmware to the adapter. For adapters with PHY firmware
  2994. * FLASH storage, it's worth a warning if we can't find the
  2995. * PHY Firmware but we'll neuter the error ...
  2996. */
  2997. dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
  2998. "/lib/firmware/%s, error %d\n",
  2999. phy_info->phy_fw_file, -ret);
  3000. if (phy_info->phy_flash) {
  3001. int cur_phy_fw_ver = 0;
  3002. t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3003. dev_warn(adap->pdev_dev, "continuing with, on-adapter "
  3004. "FLASH copy, version %#x\n", cur_phy_fw_ver);
  3005. ret = 0;
  3006. }
  3007. return ret;
  3008. }
  3009. /* Load PHY Firmware onto adapter.
  3010. */
  3011. ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
  3012. phy_info->phy_fw_version,
  3013. (u8 *)phyf->data, phyf->size);
  3014. if (ret < 0)
  3015. dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
  3016. -ret);
  3017. else if (ret > 0) {
  3018. int new_phy_fw_ver = 0;
  3019. if (phy_info->phy_fw_version)
  3020. new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
  3021. phyf->size);
  3022. dev_info(adap->pdev_dev, "Successfully transferred PHY "
  3023. "Firmware /lib/firmware/%s, version %#x\n",
  3024. phy_info->phy_fw_file, new_phy_fw_ver);
  3025. }
  3026. release_firmware(phyf);
  3027. return ret;
  3028. }
  3029. /*
  3030. * Attempt to initialize the adapter via a Firmware Configuration File.
  3031. */
  3032. static int adap_init0_config(struct adapter *adapter, int reset)
  3033. {
  3034. struct fw_caps_config_cmd caps_cmd;
  3035. const struct firmware *cf;
  3036. unsigned long mtype = 0, maddr = 0;
  3037. u32 finiver, finicsum, cfcsum;
  3038. int ret;
  3039. int config_issued = 0;
  3040. char *fw_config_file, fw_config_file_path[256];
  3041. char *config_name = NULL;
  3042. /*
  3043. * Reset device if necessary.
  3044. */
  3045. if (reset) {
  3046. ret = t4_fw_reset(adapter, adapter->mbox,
  3047. PIORSTMODE_F | PIORST_F);
  3048. if (ret < 0)
  3049. goto bye;
  3050. }
  3051. /* If this is a 10Gb/s-BT adapter make sure the chip-external
  3052. * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
  3053. * to be performed after any global adapter RESET above since some
  3054. * PHYs only have local RAM copies of the PHY firmware.
  3055. */
  3056. if (is_10gbt_device(adapter->pdev->device)) {
  3057. ret = adap_init0_phy(adapter);
  3058. if (ret < 0)
  3059. goto bye;
  3060. }
  3061. /*
  3062. * If we have a T4 configuration file under /lib/firmware/cxgb4/,
  3063. * then use that. Otherwise, use the configuration file stored
  3064. * in the adapter flash ...
  3065. */
  3066. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  3067. case CHELSIO_T4:
  3068. fw_config_file = FW4_CFNAME;
  3069. break;
  3070. case CHELSIO_T5:
  3071. fw_config_file = FW5_CFNAME;
  3072. break;
  3073. case CHELSIO_T6:
  3074. fw_config_file = FW6_CFNAME;
  3075. break;
  3076. default:
  3077. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  3078. adapter->pdev->device);
  3079. ret = -EINVAL;
  3080. goto bye;
  3081. }
  3082. ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
  3083. if (ret < 0) {
  3084. config_name = "On FLASH";
  3085. mtype = FW_MEMTYPE_CF_FLASH;
  3086. maddr = t4_flash_cfg_addr(adapter);
  3087. } else {
  3088. u32 params[7], val[7];
  3089. sprintf(fw_config_file_path,
  3090. "/lib/firmware/%s", fw_config_file);
  3091. config_name = fw_config_file_path;
  3092. if (cf->size >= FLASH_CFG_MAX_SIZE)
  3093. ret = -ENOMEM;
  3094. else {
  3095. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3096. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3097. ret = t4_query_params(adapter, adapter->mbox,
  3098. adapter->pf, 0, 1, params, val);
  3099. if (ret == 0) {
  3100. /*
  3101. * For t4_memory_rw() below addresses and
  3102. * sizes have to be in terms of multiples of 4
  3103. * bytes. So, if the Configuration File isn't
  3104. * a multiple of 4 bytes in length we'll have
  3105. * to write that out separately since we can't
  3106. * guarantee that the bytes following the
  3107. * residual byte in the buffer returned by
  3108. * request_firmware() are zeroed out ...
  3109. */
  3110. size_t resid = cf->size & 0x3;
  3111. size_t size = cf->size & ~0x3;
  3112. __be32 *data = (__be32 *)cf->data;
  3113. mtype = FW_PARAMS_PARAM_Y_G(val[0]);
  3114. maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
  3115. spin_lock(&adapter->win0_lock);
  3116. ret = t4_memory_rw(adapter, 0, mtype, maddr,
  3117. size, data, T4_MEMORY_WRITE);
  3118. if (ret == 0 && resid != 0) {
  3119. union {
  3120. __be32 word;
  3121. char buf[4];
  3122. } last;
  3123. int i;
  3124. last.word = data[size >> 2];
  3125. for (i = resid; i < 4; i++)
  3126. last.buf[i] = 0;
  3127. ret = t4_memory_rw(adapter, 0, mtype,
  3128. maddr + size,
  3129. 4, &last.word,
  3130. T4_MEMORY_WRITE);
  3131. }
  3132. spin_unlock(&adapter->win0_lock);
  3133. }
  3134. }
  3135. release_firmware(cf);
  3136. if (ret)
  3137. goto bye;
  3138. }
  3139. /*
  3140. * Issue a Capability Configuration command to the firmware to get it
  3141. * to parse the Configuration File. We don't use t4_fw_config_file()
  3142. * because we want the ability to modify various features after we've
  3143. * processed the configuration file ...
  3144. */
  3145. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3146. caps_cmd.op_to_write =
  3147. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3148. FW_CMD_REQUEST_F |
  3149. FW_CMD_READ_F);
  3150. caps_cmd.cfvalid_to_len16 =
  3151. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  3152. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  3153. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  3154. FW_LEN16(caps_cmd));
  3155. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3156. &caps_cmd);
  3157. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  3158. * Configuration File in FLASH), our last gasp effort is to use the
  3159. * Firmware Configuration File which is embedded in the firmware. A
  3160. * very few early versions of the firmware didn't have one embedded
  3161. * but we can ignore those.
  3162. */
  3163. if (ret == -ENOENT) {
  3164. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3165. caps_cmd.op_to_write =
  3166. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3167. FW_CMD_REQUEST_F |
  3168. FW_CMD_READ_F);
  3169. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3170. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
  3171. sizeof(caps_cmd), &caps_cmd);
  3172. config_name = "Firmware Default";
  3173. }
  3174. config_issued = 1;
  3175. if (ret < 0)
  3176. goto bye;
  3177. finiver = ntohl(caps_cmd.finiver);
  3178. finicsum = ntohl(caps_cmd.finicsum);
  3179. cfcsum = ntohl(caps_cmd.cfcsum);
  3180. if (finicsum != cfcsum)
  3181. dev_warn(adapter->pdev_dev, "Configuration File checksum "\
  3182. "mismatch: [fini] csum=%#x, computed csum=%#x\n",
  3183. finicsum, cfcsum);
  3184. /*
  3185. * And now tell the firmware to use the configuration we just loaded.
  3186. */
  3187. caps_cmd.op_to_write =
  3188. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3189. FW_CMD_REQUEST_F |
  3190. FW_CMD_WRITE_F);
  3191. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3192. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3193. NULL);
  3194. if (ret < 0)
  3195. goto bye;
  3196. /*
  3197. * Tweak configuration based on system architecture, module
  3198. * parameters, etc.
  3199. */
  3200. ret = adap_init0_tweaks(adapter);
  3201. if (ret < 0)
  3202. goto bye;
  3203. /*
  3204. * And finally tell the firmware to initialize itself using the
  3205. * parameters from the Configuration File.
  3206. */
  3207. ret = t4_fw_initialize(adapter, adapter->mbox);
  3208. if (ret < 0)
  3209. goto bye;
  3210. /* Emit Firmware Configuration File information and return
  3211. * successfully.
  3212. */
  3213. dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
  3214. "Configuration File \"%s\", version %#x, computed checksum %#x\n",
  3215. config_name, finiver, cfcsum);
  3216. return 0;
  3217. /*
  3218. * Something bad happened. Return the error ... (If the "error"
  3219. * is that there's no Configuration File on the adapter we don't
  3220. * want to issue a warning since this is fairly common.)
  3221. */
  3222. bye:
  3223. if (config_issued && ret != -ENOENT)
  3224. dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
  3225. config_name, -ret);
  3226. return ret;
  3227. }
  3228. static struct fw_info fw_info_array[] = {
  3229. {
  3230. .chip = CHELSIO_T4,
  3231. .fs_name = FW4_CFNAME,
  3232. .fw_mod_name = FW4_FNAME,
  3233. .fw_hdr = {
  3234. .chip = FW_HDR_CHIP_T4,
  3235. .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
  3236. .intfver_nic = FW_INTFVER(T4, NIC),
  3237. .intfver_vnic = FW_INTFVER(T4, VNIC),
  3238. .intfver_ri = FW_INTFVER(T4, RI),
  3239. .intfver_iscsi = FW_INTFVER(T4, ISCSI),
  3240. .intfver_fcoe = FW_INTFVER(T4, FCOE),
  3241. },
  3242. }, {
  3243. .chip = CHELSIO_T5,
  3244. .fs_name = FW5_CFNAME,
  3245. .fw_mod_name = FW5_FNAME,
  3246. .fw_hdr = {
  3247. .chip = FW_HDR_CHIP_T5,
  3248. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  3249. .intfver_nic = FW_INTFVER(T5, NIC),
  3250. .intfver_vnic = FW_INTFVER(T5, VNIC),
  3251. .intfver_ri = FW_INTFVER(T5, RI),
  3252. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  3253. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  3254. },
  3255. }, {
  3256. .chip = CHELSIO_T6,
  3257. .fs_name = FW6_CFNAME,
  3258. .fw_mod_name = FW6_FNAME,
  3259. .fw_hdr = {
  3260. .chip = FW_HDR_CHIP_T6,
  3261. .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
  3262. .intfver_nic = FW_INTFVER(T6, NIC),
  3263. .intfver_vnic = FW_INTFVER(T6, VNIC),
  3264. .intfver_ofld = FW_INTFVER(T6, OFLD),
  3265. .intfver_ri = FW_INTFVER(T6, RI),
  3266. .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
  3267. .intfver_iscsi = FW_INTFVER(T6, ISCSI),
  3268. .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
  3269. .intfver_fcoe = FW_INTFVER(T6, FCOE),
  3270. },
  3271. }
  3272. };
  3273. static struct fw_info *find_fw_info(int chip)
  3274. {
  3275. int i;
  3276. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  3277. if (fw_info_array[i].chip == chip)
  3278. return &fw_info_array[i];
  3279. }
  3280. return NULL;
  3281. }
  3282. /*
  3283. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3284. */
  3285. static int adap_init0(struct adapter *adap)
  3286. {
  3287. int ret;
  3288. u32 v, port_vec;
  3289. enum dev_state state;
  3290. u32 params[7], val[7];
  3291. struct fw_caps_config_cmd caps_cmd;
  3292. int reset = 1;
  3293. /* Grab Firmware Device Log parameters as early as possible so we have
  3294. * access to it for debugging, etc.
  3295. */
  3296. ret = t4_init_devlog_params(adap);
  3297. if (ret < 0)
  3298. return ret;
  3299. /* Contact FW, advertising Master capability */
  3300. ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
  3301. is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
  3302. if (ret < 0) {
  3303. dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
  3304. ret);
  3305. return ret;
  3306. }
  3307. if (ret == adap->mbox)
  3308. adap->flags |= MASTER_PF;
  3309. /*
  3310. * If we're the Master PF Driver and the device is uninitialized,
  3311. * then let's consider upgrading the firmware ... (We always want
  3312. * to check the firmware version number in order to A. get it for
  3313. * later reporting and B. to warn if the currently loaded firmware
  3314. * is excessively mismatched relative to the driver.)
  3315. */
  3316. t4_get_fw_version(adap, &adap->params.fw_vers);
  3317. t4_get_bs_version(adap, &adap->params.bs_vers);
  3318. t4_get_tp_version(adap, &adap->params.tp_vers);
  3319. t4_get_exprom_version(adap, &adap->params.er_vers);
  3320. ret = t4_check_fw_version(adap);
  3321. /* If firmware is too old (not supported by driver) force an update. */
  3322. if (ret)
  3323. state = DEV_STATE_UNINIT;
  3324. if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
  3325. struct fw_info *fw_info;
  3326. struct fw_hdr *card_fw;
  3327. const struct firmware *fw;
  3328. const u8 *fw_data = NULL;
  3329. unsigned int fw_size = 0;
  3330. /* This is the firmware whose headers the driver was compiled
  3331. * against
  3332. */
  3333. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
  3334. if (fw_info == NULL) {
  3335. dev_err(adap->pdev_dev,
  3336. "unable to get firmware info for chip %d.\n",
  3337. CHELSIO_CHIP_VERSION(adap->params.chip));
  3338. return -EINVAL;
  3339. }
  3340. /* allocate memory to read the header of the firmware on the
  3341. * card
  3342. */
  3343. card_fw = t4_alloc_mem(sizeof(*card_fw));
  3344. /* Get FW from from /lib/firmware/ */
  3345. ret = request_firmware(&fw, fw_info->fw_mod_name,
  3346. adap->pdev_dev);
  3347. if (ret < 0) {
  3348. dev_err(adap->pdev_dev,
  3349. "unable to load firmware image %s, error %d\n",
  3350. fw_info->fw_mod_name, ret);
  3351. } else {
  3352. fw_data = fw->data;
  3353. fw_size = fw->size;
  3354. }
  3355. /* upgrade FW logic */
  3356. ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
  3357. state, &reset);
  3358. /* Cleaning up */
  3359. release_firmware(fw);
  3360. t4_free_mem(card_fw);
  3361. if (ret < 0)
  3362. goto bye;
  3363. }
  3364. /*
  3365. * Grab VPD parameters. This should be done after we establish a
  3366. * connection to the firmware since some of the VPD parameters
  3367. * (notably the Core Clock frequency) are retrieved via requests to
  3368. * the firmware. On the other hand, we need these fairly early on
  3369. * so we do this right after getting ahold of the firmware.
  3370. */
  3371. ret = t4_get_vpd_params(adap, &adap->params.vpd);
  3372. if (ret < 0)
  3373. goto bye;
  3374. /*
  3375. * Find out what ports are available to us. Note that we need to do
  3376. * this before calling adap_init0_no_config() since it needs nports
  3377. * and portvec ...
  3378. */
  3379. v =
  3380. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3381. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  3382. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
  3383. if (ret < 0)
  3384. goto bye;
  3385. adap->params.nports = hweight32(port_vec);
  3386. adap->params.portvec = port_vec;
  3387. /* If the firmware is initialized already, emit a simply note to that
  3388. * effect. Otherwise, it's time to try initializing the adapter.
  3389. */
  3390. if (state == DEV_STATE_INIT) {
  3391. dev_info(adap->pdev_dev, "Coming up as %s: "\
  3392. "Adapter already initialized\n",
  3393. adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
  3394. } else {
  3395. dev_info(adap->pdev_dev, "Coming up as MASTER: "\
  3396. "Initializing adapter\n");
  3397. /* Find out whether we're dealing with a version of the
  3398. * firmware which has configuration file support.
  3399. */
  3400. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3401. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3402. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3403. params, val);
  3404. /* If the firmware doesn't support Configuration Files,
  3405. * return an error.
  3406. */
  3407. if (ret < 0) {
  3408. dev_err(adap->pdev_dev, "firmware doesn't support "
  3409. "Firmware Configuration Files\n");
  3410. goto bye;
  3411. }
  3412. /* The firmware provides us with a memory buffer where we can
  3413. * load a Configuration File from the host if we want to
  3414. * override the Configuration File in flash.
  3415. */
  3416. ret = adap_init0_config(adap, reset);
  3417. if (ret == -ENOENT) {
  3418. dev_err(adap->pdev_dev, "no Configuration File "
  3419. "present on adapter.\n");
  3420. goto bye;
  3421. }
  3422. if (ret < 0) {
  3423. dev_err(adap->pdev_dev, "could not initialize "
  3424. "adapter, error %d\n", -ret);
  3425. goto bye;
  3426. }
  3427. }
  3428. /* Give the SGE code a chance to pull in anything that it needs ...
  3429. * Note that this must be called after we retrieve our VPD parameters
  3430. * in order to know how to convert core ticks to seconds, etc.
  3431. */
  3432. ret = t4_sge_init(adap);
  3433. if (ret < 0)
  3434. goto bye;
  3435. if (is_bypass_device(adap->pdev->device))
  3436. adap->params.bypass = 1;
  3437. /*
  3438. * Grab some of our basic fundamental operating parameters.
  3439. */
  3440. #define FW_PARAM_DEV(param) \
  3441. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
  3442. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
  3443. #define FW_PARAM_PFVF(param) \
  3444. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  3445. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
  3446. FW_PARAMS_PARAM_Y_V(0) | \
  3447. FW_PARAMS_PARAM_Z_V(0)
  3448. params[0] = FW_PARAM_PFVF(EQ_START);
  3449. params[1] = FW_PARAM_PFVF(L2T_START);
  3450. params[2] = FW_PARAM_PFVF(L2T_END);
  3451. params[3] = FW_PARAM_PFVF(FILTER_START);
  3452. params[4] = FW_PARAM_PFVF(FILTER_END);
  3453. params[5] = FW_PARAM_PFVF(IQFLINT_START);
  3454. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
  3455. if (ret < 0)
  3456. goto bye;
  3457. adap->sge.egr_start = val[0];
  3458. adap->l2t_start = val[1];
  3459. adap->l2t_end = val[2];
  3460. adap->tids.ftid_base = val[3];
  3461. adap->tids.nftids = val[4] - val[3] + 1;
  3462. adap->sge.ingr_start = val[5];
  3463. /* qids (ingress/egress) returned from firmware can be anywhere
  3464. * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
  3465. * Hence driver needs to allocate memory for this range to
  3466. * store the queue info. Get the highest IQFLINT/EQ index returned
  3467. * in FW_EQ_*_CMD.alloc command.
  3468. */
  3469. params[0] = FW_PARAM_PFVF(EQ_END);
  3470. params[1] = FW_PARAM_PFVF(IQFLINT_END);
  3471. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3472. if (ret < 0)
  3473. goto bye;
  3474. adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
  3475. adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
  3476. adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
  3477. sizeof(*adap->sge.egr_map), GFP_KERNEL);
  3478. if (!adap->sge.egr_map) {
  3479. ret = -ENOMEM;
  3480. goto bye;
  3481. }
  3482. adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
  3483. sizeof(*adap->sge.ingr_map), GFP_KERNEL);
  3484. if (!adap->sge.ingr_map) {
  3485. ret = -ENOMEM;
  3486. goto bye;
  3487. }
  3488. /* Allocate the memory for the vaious egress queue bitmaps
  3489. * ie starving_fl, txq_maperr and blocked_fl.
  3490. */
  3491. adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3492. sizeof(long), GFP_KERNEL);
  3493. if (!adap->sge.starving_fl) {
  3494. ret = -ENOMEM;
  3495. goto bye;
  3496. }
  3497. adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3498. sizeof(long), GFP_KERNEL);
  3499. if (!adap->sge.txq_maperr) {
  3500. ret = -ENOMEM;
  3501. goto bye;
  3502. }
  3503. #ifdef CONFIG_DEBUG_FS
  3504. adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3505. sizeof(long), GFP_KERNEL);
  3506. if (!adap->sge.blocked_fl) {
  3507. ret = -ENOMEM;
  3508. goto bye;
  3509. }
  3510. #endif
  3511. params[0] = FW_PARAM_PFVF(CLIP_START);
  3512. params[1] = FW_PARAM_PFVF(CLIP_END);
  3513. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3514. if (ret < 0)
  3515. goto bye;
  3516. adap->clipt_start = val[0];
  3517. adap->clipt_end = val[1];
  3518. /* query params related to active filter region */
  3519. params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
  3520. params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
  3521. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3522. /* If Active filter size is set we enable establishing
  3523. * offload connection through firmware work request
  3524. */
  3525. if ((val[0] != val[1]) && (ret >= 0)) {
  3526. adap->flags |= FW_OFLD_CONN;
  3527. adap->tids.aftid_base = val[0];
  3528. adap->tids.aftid_end = val[1];
  3529. }
  3530. /* If we're running on newer firmware, let it know that we're
  3531. * prepared to deal with encapsulated CPL messages. Older
  3532. * firmware won't understand this and we'll just get
  3533. * unencapsulated messages ...
  3534. */
  3535. params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
  3536. val[0] = 1;
  3537. (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
  3538. /*
  3539. * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
  3540. * capability. Earlier versions of the firmware didn't have the
  3541. * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
  3542. * permission to use ULPTX MEMWRITE DSGL.
  3543. */
  3544. if (is_t4(adap->params.chip)) {
  3545. adap->params.ulptx_memwrite_dsgl = false;
  3546. } else {
  3547. params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
  3548. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3549. 1, params, val);
  3550. adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
  3551. }
  3552. /*
  3553. * Get device capabilities so we can determine what resources we need
  3554. * to manage.
  3555. */
  3556. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3557. caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3558. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3559. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3560. ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
  3561. &caps_cmd);
  3562. if (ret < 0)
  3563. goto bye;
  3564. if (caps_cmd.ofldcaps) {
  3565. /* query offload-related parameters */
  3566. params[0] = FW_PARAM_DEV(NTID);
  3567. params[1] = FW_PARAM_PFVF(SERVER_START);
  3568. params[2] = FW_PARAM_PFVF(SERVER_END);
  3569. params[3] = FW_PARAM_PFVF(TDDP_START);
  3570. params[4] = FW_PARAM_PFVF(TDDP_END);
  3571. params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
  3572. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3573. params, val);
  3574. if (ret < 0)
  3575. goto bye;
  3576. adap->tids.ntids = val[0];
  3577. adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
  3578. adap->tids.stid_base = val[1];
  3579. adap->tids.nstids = val[2] - val[1] + 1;
  3580. /*
  3581. * Setup server filter region. Divide the available filter
  3582. * region into two parts. Regular filters get 1/3rd and server
  3583. * filters get 2/3rd part. This is only enabled if workarond
  3584. * path is enabled.
  3585. * 1. For regular filters.
  3586. * 2. Server filter: This are special filters which are used
  3587. * to redirect SYN packets to offload queue.
  3588. */
  3589. if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
  3590. adap->tids.sftid_base = adap->tids.ftid_base +
  3591. DIV_ROUND_UP(adap->tids.nftids, 3);
  3592. adap->tids.nsftids = adap->tids.nftids -
  3593. DIV_ROUND_UP(adap->tids.nftids, 3);
  3594. adap->tids.nftids = adap->tids.sftid_base -
  3595. adap->tids.ftid_base;
  3596. }
  3597. adap->vres.ddp.start = val[3];
  3598. adap->vres.ddp.size = val[4] - val[3] + 1;
  3599. adap->params.ofldq_wr_cred = val[5];
  3600. adap->params.offload = 1;
  3601. }
  3602. if (caps_cmd.rdmacaps) {
  3603. params[0] = FW_PARAM_PFVF(STAG_START);
  3604. params[1] = FW_PARAM_PFVF(STAG_END);
  3605. params[2] = FW_PARAM_PFVF(RQ_START);
  3606. params[3] = FW_PARAM_PFVF(RQ_END);
  3607. params[4] = FW_PARAM_PFVF(PBL_START);
  3608. params[5] = FW_PARAM_PFVF(PBL_END);
  3609. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3610. params, val);
  3611. if (ret < 0)
  3612. goto bye;
  3613. adap->vres.stag.start = val[0];
  3614. adap->vres.stag.size = val[1] - val[0] + 1;
  3615. adap->vres.rq.start = val[2];
  3616. adap->vres.rq.size = val[3] - val[2] + 1;
  3617. adap->vres.pbl.start = val[4];
  3618. adap->vres.pbl.size = val[5] - val[4] + 1;
  3619. params[0] = FW_PARAM_PFVF(SQRQ_START);
  3620. params[1] = FW_PARAM_PFVF(SQRQ_END);
  3621. params[2] = FW_PARAM_PFVF(CQ_START);
  3622. params[3] = FW_PARAM_PFVF(CQ_END);
  3623. params[4] = FW_PARAM_PFVF(OCQ_START);
  3624. params[5] = FW_PARAM_PFVF(OCQ_END);
  3625. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
  3626. val);
  3627. if (ret < 0)
  3628. goto bye;
  3629. adap->vres.qp.start = val[0];
  3630. adap->vres.qp.size = val[1] - val[0] + 1;
  3631. adap->vres.cq.start = val[2];
  3632. adap->vres.cq.size = val[3] - val[2] + 1;
  3633. adap->vres.ocq.start = val[4];
  3634. adap->vres.ocq.size = val[5] - val[4] + 1;
  3635. params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
  3636. params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
  3637. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
  3638. val);
  3639. if (ret < 0) {
  3640. adap->params.max_ordird_qp = 8;
  3641. adap->params.max_ird_adapter = 32 * adap->tids.ntids;
  3642. ret = 0;
  3643. } else {
  3644. adap->params.max_ordird_qp = val[0];
  3645. adap->params.max_ird_adapter = val[1];
  3646. }
  3647. dev_info(adap->pdev_dev,
  3648. "max_ordird_qp %d max_ird_adapter %d\n",
  3649. adap->params.max_ordird_qp,
  3650. adap->params.max_ird_adapter);
  3651. }
  3652. if (caps_cmd.iscsicaps) {
  3653. params[0] = FW_PARAM_PFVF(ISCSI_START);
  3654. params[1] = FW_PARAM_PFVF(ISCSI_END);
  3655. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3656. params, val);
  3657. if (ret < 0)
  3658. goto bye;
  3659. adap->vres.iscsi.start = val[0];
  3660. adap->vres.iscsi.size = val[1] - val[0] + 1;
  3661. }
  3662. #undef FW_PARAM_PFVF
  3663. #undef FW_PARAM_DEV
  3664. /* The MTU/MSS Table is initialized by now, so load their values. If
  3665. * we're initializing the adapter, then we'll make any modifications
  3666. * we want to the MTU/MSS Table and also initialize the congestion
  3667. * parameters.
  3668. */
  3669. t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
  3670. if (state != DEV_STATE_INIT) {
  3671. int i;
  3672. /* The default MTU Table contains values 1492 and 1500.
  3673. * However, for TCP, it's better to have two values which are
  3674. * a multiple of 8 +/- 4 bytes apart near this popular MTU.
  3675. * This allows us to have a TCP Data Payload which is a
  3676. * multiple of 8 regardless of what combination of TCP Options
  3677. * are in use (always a multiple of 4 bytes) which is
  3678. * important for performance reasons. For instance, if no
  3679. * options are in use, then we have a 20-byte IP header and a
  3680. * 20-byte TCP header. In this case, a 1500-byte MSS would
  3681. * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
  3682. * which is not a multiple of 8. So using an MSS of 1488 in
  3683. * this case results in a TCP Data Payload of 1448 bytes which
  3684. * is a multiple of 8. On the other hand, if 12-byte TCP Time
  3685. * Stamps have been negotiated, then an MTU of 1500 bytes
  3686. * results in a TCP Data Payload of 1448 bytes which, as
  3687. * above, is a multiple of 8 bytes ...
  3688. */
  3689. for (i = 0; i < NMTUS; i++)
  3690. if (adap->params.mtus[i] == 1492) {
  3691. adap->params.mtus[i] = 1488;
  3692. break;
  3693. }
  3694. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  3695. adap->params.b_wnd);
  3696. }
  3697. t4_init_sge_params(adap);
  3698. adap->flags |= FW_OK;
  3699. t4_init_tp_params(adap);
  3700. return 0;
  3701. /*
  3702. * Something bad happened. If a command timed out or failed with EIO
  3703. * FW does not operate within its spec or something catastrophic
  3704. * happened to HW/FW, stop issuing commands.
  3705. */
  3706. bye:
  3707. kfree(adap->sge.egr_map);
  3708. kfree(adap->sge.ingr_map);
  3709. kfree(adap->sge.starving_fl);
  3710. kfree(adap->sge.txq_maperr);
  3711. #ifdef CONFIG_DEBUG_FS
  3712. kfree(adap->sge.blocked_fl);
  3713. #endif
  3714. if (ret != -ETIMEDOUT && ret != -EIO)
  3715. t4_fw_bye(adap, adap->mbox);
  3716. return ret;
  3717. }
  3718. /* EEH callbacks */
  3719. static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
  3720. pci_channel_state_t state)
  3721. {
  3722. int i;
  3723. struct adapter *adap = pci_get_drvdata(pdev);
  3724. if (!adap)
  3725. goto out;
  3726. rtnl_lock();
  3727. adap->flags &= ~FW_OK;
  3728. notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
  3729. spin_lock(&adap->stats_lock);
  3730. for_each_port(adap, i) {
  3731. struct net_device *dev = adap->port[i];
  3732. netif_device_detach(dev);
  3733. netif_carrier_off(dev);
  3734. }
  3735. spin_unlock(&adap->stats_lock);
  3736. disable_interrupts(adap);
  3737. if (adap->flags & FULL_INIT_DONE)
  3738. cxgb_down(adap);
  3739. rtnl_unlock();
  3740. if ((adap->flags & DEV_ENABLED)) {
  3741. pci_disable_device(pdev);
  3742. adap->flags &= ~DEV_ENABLED;
  3743. }
  3744. out: return state == pci_channel_io_perm_failure ?
  3745. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  3746. }
  3747. static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
  3748. {
  3749. int i, ret;
  3750. struct fw_caps_config_cmd c;
  3751. struct adapter *adap = pci_get_drvdata(pdev);
  3752. if (!adap) {
  3753. pci_restore_state(pdev);
  3754. pci_save_state(pdev);
  3755. return PCI_ERS_RESULT_RECOVERED;
  3756. }
  3757. if (!(adap->flags & DEV_ENABLED)) {
  3758. if (pci_enable_device(pdev)) {
  3759. dev_err(&pdev->dev, "Cannot reenable PCI "
  3760. "device after reset\n");
  3761. return PCI_ERS_RESULT_DISCONNECT;
  3762. }
  3763. adap->flags |= DEV_ENABLED;
  3764. }
  3765. pci_set_master(pdev);
  3766. pci_restore_state(pdev);
  3767. pci_save_state(pdev);
  3768. pci_cleanup_aer_uncorrect_error_status(pdev);
  3769. if (t4_wait_dev_ready(adap->regs) < 0)
  3770. return PCI_ERS_RESULT_DISCONNECT;
  3771. if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
  3772. return PCI_ERS_RESULT_DISCONNECT;
  3773. adap->flags |= FW_OK;
  3774. if (adap_init1(adap, &c))
  3775. return PCI_ERS_RESULT_DISCONNECT;
  3776. for_each_port(adap, i) {
  3777. struct port_info *p = adap2pinfo(adap, i);
  3778. ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
  3779. NULL, NULL);
  3780. if (ret < 0)
  3781. return PCI_ERS_RESULT_DISCONNECT;
  3782. p->viid = ret;
  3783. p->xact_addr_filt = -1;
  3784. }
  3785. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  3786. adap->params.b_wnd);
  3787. setup_memwin(adap);
  3788. if (cxgb_up(adap))
  3789. return PCI_ERS_RESULT_DISCONNECT;
  3790. return PCI_ERS_RESULT_RECOVERED;
  3791. }
  3792. static void eeh_resume(struct pci_dev *pdev)
  3793. {
  3794. int i;
  3795. struct adapter *adap = pci_get_drvdata(pdev);
  3796. if (!adap)
  3797. return;
  3798. rtnl_lock();
  3799. for_each_port(adap, i) {
  3800. struct net_device *dev = adap->port[i];
  3801. if (netif_running(dev)) {
  3802. link_start(dev);
  3803. cxgb_set_rxmode(dev);
  3804. }
  3805. netif_device_attach(dev);
  3806. }
  3807. rtnl_unlock();
  3808. }
  3809. static const struct pci_error_handlers cxgb4_eeh = {
  3810. .error_detected = eeh_err_detected,
  3811. .slot_reset = eeh_slot_reset,
  3812. .resume = eeh_resume,
  3813. };
  3814. static inline bool is_x_10g_port(const struct link_config *lc)
  3815. {
  3816. return (lc->supported & FW_PORT_CAP_SPEED_10G) != 0 ||
  3817. (lc->supported & FW_PORT_CAP_SPEED_40G) != 0;
  3818. }
  3819. static inline void init_rspq(struct adapter *adap, struct sge_rspq *q,
  3820. unsigned int us, unsigned int cnt,
  3821. unsigned int size, unsigned int iqe_size)
  3822. {
  3823. q->adap = adap;
  3824. cxgb4_set_rspq_intr_params(q, us, cnt);
  3825. q->iqe_len = iqe_size;
  3826. q->size = size;
  3827. }
  3828. /*
  3829. * Perform default configuration of DMA queues depending on the number and type
  3830. * of ports we found and the number of available CPUs. Most settings can be
  3831. * modified by the admin prior to actual use.
  3832. */
  3833. static void cfg_queues(struct adapter *adap)
  3834. {
  3835. struct sge *s = &adap->sge;
  3836. int i, n10g = 0, qidx = 0;
  3837. #ifndef CONFIG_CHELSIO_T4_DCB
  3838. int q10g = 0;
  3839. #endif
  3840. int ciq_size;
  3841. /* Reduce memory usage in kdump environment, disable all offload.
  3842. */
  3843. if (is_kdump_kernel())
  3844. adap->params.offload = 0;
  3845. for_each_port(adap, i)
  3846. n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
  3847. #ifdef CONFIG_CHELSIO_T4_DCB
  3848. /* For Data Center Bridging support we need to be able to support up
  3849. * to 8 Traffic Priorities; each of which will be assigned to its
  3850. * own TX Queue in order to prevent Head-Of-Line Blocking.
  3851. */
  3852. if (adap->params.nports * 8 > MAX_ETH_QSETS) {
  3853. dev_err(adap->pdev_dev, "MAX_ETH_QSETS=%d < %d!\n",
  3854. MAX_ETH_QSETS, adap->params.nports * 8);
  3855. BUG_ON(1);
  3856. }
  3857. for_each_port(adap, i) {
  3858. struct port_info *pi = adap2pinfo(adap, i);
  3859. pi->first_qset = qidx;
  3860. pi->nqsets = 8;
  3861. qidx += pi->nqsets;
  3862. }
  3863. #else /* !CONFIG_CHELSIO_T4_DCB */
  3864. /*
  3865. * We default to 1 queue per non-10G port and up to # of cores queues
  3866. * per 10G port.
  3867. */
  3868. if (n10g)
  3869. q10g = (MAX_ETH_QSETS - (adap->params.nports - n10g)) / n10g;
  3870. if (q10g > netif_get_num_default_rss_queues())
  3871. q10g = netif_get_num_default_rss_queues();
  3872. for_each_port(adap, i) {
  3873. struct port_info *pi = adap2pinfo(adap, i);
  3874. pi->first_qset = qidx;
  3875. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  3876. qidx += pi->nqsets;
  3877. }
  3878. #endif /* !CONFIG_CHELSIO_T4_DCB */
  3879. s->ethqsets = qidx;
  3880. s->max_ethqsets = qidx; /* MSI-X may lower it later */
  3881. if (is_offload(adap)) {
  3882. /*
  3883. * For offload we use 1 queue/channel if all ports are up to 1G,
  3884. * otherwise we divide all available queues amongst the channels
  3885. * capped by the number of available cores.
  3886. */
  3887. if (n10g) {
  3888. i = min_t(int, ARRAY_SIZE(s->iscsirxq),
  3889. num_online_cpus());
  3890. s->iscsiqsets = roundup(i, adap->params.nports);
  3891. } else
  3892. s->iscsiqsets = adap->params.nports;
  3893. /* For RDMA one Rx queue per channel suffices */
  3894. s->rdmaqs = adap->params.nports;
  3895. /* Try and allow at least 1 CIQ per cpu rounding down
  3896. * to the number of ports, with a minimum of 1 per port.
  3897. * A 2 port card in a 6 cpu system: 6 CIQs, 3 / port.
  3898. * A 4 port card in a 6 cpu system: 4 CIQs, 1 / port.
  3899. * A 4 port card in a 2 cpu system: 4 CIQs, 1 / port.
  3900. */
  3901. s->rdmaciqs = min_t(int, MAX_RDMA_CIQS, num_online_cpus());
  3902. s->rdmaciqs = (s->rdmaciqs / adap->params.nports) *
  3903. adap->params.nports;
  3904. s->rdmaciqs = max_t(int, s->rdmaciqs, adap->params.nports);
  3905. if (!is_t4(adap->params.chip))
  3906. s->niscsitq = s->iscsiqsets;
  3907. }
  3908. for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
  3909. struct sge_eth_rxq *r = &s->ethrxq[i];
  3910. init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
  3911. r->fl.size = 72;
  3912. }
  3913. for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
  3914. s->ethtxq[i].q.size = 1024;
  3915. for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
  3916. s->ctrlq[i].q.size = 512;
  3917. for (i = 0; i < ARRAY_SIZE(s->ofldtxq); i++)
  3918. s->ofldtxq[i].q.size = 1024;
  3919. for (i = 0; i < ARRAY_SIZE(s->iscsirxq); i++) {
  3920. struct sge_ofld_rxq *r = &s->iscsirxq[i];
  3921. init_rspq(adap, &r->rspq, 5, 1, 1024, 64);
  3922. r->rspq.uld = CXGB4_ULD_ISCSI;
  3923. r->fl.size = 72;
  3924. }
  3925. if (!is_t4(adap->params.chip)) {
  3926. for (i = 0; i < ARRAY_SIZE(s->iscsitrxq); i++) {
  3927. struct sge_ofld_rxq *r = &s->iscsitrxq[i];
  3928. init_rspq(adap, &r->rspq, 5, 1, 1024, 64);
  3929. r->rspq.uld = CXGB4_ULD_ISCSIT;
  3930. r->fl.size = 72;
  3931. }
  3932. }
  3933. for (i = 0; i < ARRAY_SIZE(s->rdmarxq); i++) {
  3934. struct sge_ofld_rxq *r = &s->rdmarxq[i];
  3935. init_rspq(adap, &r->rspq, 5, 1, 511, 64);
  3936. r->rspq.uld = CXGB4_ULD_RDMA;
  3937. r->fl.size = 72;
  3938. }
  3939. ciq_size = 64 + adap->vres.cq.size + adap->tids.nftids;
  3940. if (ciq_size > SGE_MAX_IQ_SIZE) {
  3941. CH_WARN(adap, "CIQ size too small for available IQs\n");
  3942. ciq_size = SGE_MAX_IQ_SIZE;
  3943. }
  3944. for (i = 0; i < ARRAY_SIZE(s->rdmaciq); i++) {
  3945. struct sge_ofld_rxq *r = &s->rdmaciq[i];
  3946. init_rspq(adap, &r->rspq, 5, 1, ciq_size, 64);
  3947. r->rspq.uld = CXGB4_ULD_RDMA;
  3948. }
  3949. init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
  3950. init_rspq(adap, &s->intrq, 0, 1, 2 * MAX_INGQ, 64);
  3951. }
  3952. /*
  3953. * Reduce the number of Ethernet queues across all ports to at most n.
  3954. * n provides at least one queue per port.
  3955. */
  3956. static void reduce_ethqs(struct adapter *adap, int n)
  3957. {
  3958. int i;
  3959. struct port_info *pi;
  3960. while (n < adap->sge.ethqsets)
  3961. for_each_port(adap, i) {
  3962. pi = adap2pinfo(adap, i);
  3963. if (pi->nqsets > 1) {
  3964. pi->nqsets--;
  3965. adap->sge.ethqsets--;
  3966. if (adap->sge.ethqsets <= n)
  3967. break;
  3968. }
  3969. }
  3970. n = 0;
  3971. for_each_port(adap, i) {
  3972. pi = adap2pinfo(adap, i);
  3973. pi->first_qset = n;
  3974. n += pi->nqsets;
  3975. }
  3976. }
  3977. /* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
  3978. #define EXTRA_VECS 2
  3979. static int enable_msix(struct adapter *adap)
  3980. {
  3981. int ofld_need = 0;
  3982. int i, want, need, allocated;
  3983. struct sge *s = &adap->sge;
  3984. unsigned int nchan = adap->params.nports;
  3985. struct msix_entry *entries;
  3986. entries = kmalloc(sizeof(*entries) * (MAX_INGQ + 1),
  3987. GFP_KERNEL);
  3988. if (!entries)
  3989. return -ENOMEM;
  3990. for (i = 0; i < MAX_INGQ + 1; ++i)
  3991. entries[i].entry = i;
  3992. want = s->max_ethqsets + EXTRA_VECS;
  3993. if (is_offload(adap)) {
  3994. want += s->rdmaqs + s->rdmaciqs + s->iscsiqsets +
  3995. s->niscsitq;
  3996. /* need nchan for each possible ULD */
  3997. if (is_t4(adap->params.chip))
  3998. ofld_need = 3 * nchan;
  3999. else
  4000. ofld_need = 4 * nchan;
  4001. }
  4002. #ifdef CONFIG_CHELSIO_T4_DCB
  4003. /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
  4004. * each port.
  4005. */
  4006. need = 8 * adap->params.nports + EXTRA_VECS + ofld_need;
  4007. #else
  4008. need = adap->params.nports + EXTRA_VECS + ofld_need;
  4009. #endif
  4010. allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
  4011. if (allocated < 0) {
  4012. dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
  4013. " not using MSI-X\n");
  4014. kfree(entries);
  4015. return allocated;
  4016. }
  4017. /* Distribute available vectors to the various queue groups.
  4018. * Every group gets its minimum requirement and NIC gets top
  4019. * priority for leftovers.
  4020. */
  4021. i = allocated - EXTRA_VECS - ofld_need;
  4022. if (i < s->max_ethqsets) {
  4023. s->max_ethqsets = i;
  4024. if (i < s->ethqsets)
  4025. reduce_ethqs(adap, i);
  4026. }
  4027. if (is_offload(adap)) {
  4028. if (allocated < want) {
  4029. s->rdmaqs = nchan;
  4030. s->rdmaciqs = nchan;
  4031. if (!is_t4(adap->params.chip))
  4032. s->niscsitq = nchan;
  4033. }
  4034. /* leftovers go to OFLD */
  4035. i = allocated - EXTRA_VECS - s->max_ethqsets -
  4036. s->rdmaqs - s->rdmaciqs - s->niscsitq;
  4037. s->iscsiqsets = (i / nchan) * nchan; /* round down */
  4038. }
  4039. for (i = 0; i < allocated; ++i)
  4040. adap->msix_info[i].vec = entries[i].vector;
  4041. dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
  4042. "nic %d iscsi %d rdma cpl %d rdma ciq %d\n",
  4043. allocated, s->max_ethqsets, s->iscsiqsets, s->rdmaqs,
  4044. s->rdmaciqs);
  4045. kfree(entries);
  4046. return 0;
  4047. }
  4048. #undef EXTRA_VECS
  4049. static int init_rss(struct adapter *adap)
  4050. {
  4051. unsigned int i;
  4052. int err;
  4053. err = t4_init_rss_mode(adap, adap->mbox);
  4054. if (err)
  4055. return err;
  4056. for_each_port(adap, i) {
  4057. struct port_info *pi = adap2pinfo(adap, i);
  4058. pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
  4059. if (!pi->rss)
  4060. return -ENOMEM;
  4061. }
  4062. return 0;
  4063. }
  4064. static int cxgb4_get_pcie_dev_link_caps(struct adapter *adap,
  4065. enum pci_bus_speed *speed,
  4066. enum pcie_link_width *width)
  4067. {
  4068. u32 lnkcap1, lnkcap2;
  4069. int err1, err2;
  4070. #define PCIE_MLW_CAP_SHIFT 4 /* start of MLW mask in link capabilities */
  4071. *speed = PCI_SPEED_UNKNOWN;
  4072. *width = PCIE_LNK_WIDTH_UNKNOWN;
  4073. err1 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP,
  4074. &lnkcap1);
  4075. err2 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP2,
  4076. &lnkcap2);
  4077. if (!err2 && lnkcap2) { /* PCIe r3.0-compliant */
  4078. if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
  4079. *speed = PCIE_SPEED_8_0GT;
  4080. else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
  4081. *speed = PCIE_SPEED_5_0GT;
  4082. else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
  4083. *speed = PCIE_SPEED_2_5GT;
  4084. }
  4085. if (!err1) {
  4086. *width = (lnkcap1 & PCI_EXP_LNKCAP_MLW) >> PCIE_MLW_CAP_SHIFT;
  4087. if (!lnkcap2) { /* pre-r3.0 */
  4088. if (lnkcap1 & PCI_EXP_LNKCAP_SLS_5_0GB)
  4089. *speed = PCIE_SPEED_5_0GT;
  4090. else if (lnkcap1 & PCI_EXP_LNKCAP_SLS_2_5GB)
  4091. *speed = PCIE_SPEED_2_5GT;
  4092. }
  4093. }
  4094. if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN)
  4095. return err1 ? err1 : err2 ? err2 : -EINVAL;
  4096. return 0;
  4097. }
  4098. static void cxgb4_check_pcie_caps(struct adapter *adap)
  4099. {
  4100. enum pcie_link_width width, width_cap;
  4101. enum pci_bus_speed speed, speed_cap;
  4102. #define PCIE_SPEED_STR(speed) \
  4103. (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : \
  4104. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : \
  4105. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : \
  4106. "Unknown")
  4107. if (cxgb4_get_pcie_dev_link_caps(adap, &speed_cap, &width_cap)) {
  4108. dev_warn(adap->pdev_dev,
  4109. "Unable to determine PCIe device BW capabilities\n");
  4110. return;
  4111. }
  4112. if (pcie_get_minimum_link(adap->pdev, &speed, &width) ||
  4113. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
  4114. dev_warn(adap->pdev_dev,
  4115. "Unable to determine PCI Express bandwidth.\n");
  4116. return;
  4117. }
  4118. dev_info(adap->pdev_dev, "PCIe link speed is %s, device supports %s\n",
  4119. PCIE_SPEED_STR(speed), PCIE_SPEED_STR(speed_cap));
  4120. dev_info(adap->pdev_dev, "PCIe link width is x%d, device supports x%d\n",
  4121. width, width_cap);
  4122. if (speed < speed_cap || width < width_cap)
  4123. dev_info(adap->pdev_dev,
  4124. "A slot with more lanes and/or higher speed is "
  4125. "suggested for optimal performance.\n");
  4126. }
  4127. /* Dump basic information about the adapter */
  4128. static void print_adapter_info(struct adapter *adapter)
  4129. {
  4130. /* Device information */
  4131. dev_info(adapter->pdev_dev, "Chelsio %s rev %d\n",
  4132. adapter->params.vpd.id,
  4133. CHELSIO_CHIP_RELEASE(adapter->params.chip));
  4134. dev_info(adapter->pdev_dev, "S/N: %s, P/N: %s\n",
  4135. adapter->params.vpd.sn, adapter->params.vpd.pn);
  4136. /* Firmware Version */
  4137. if (!adapter->params.fw_vers)
  4138. dev_warn(adapter->pdev_dev, "No firmware loaded\n");
  4139. else
  4140. dev_info(adapter->pdev_dev, "Firmware version: %u.%u.%u.%u\n",
  4141. FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
  4142. FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
  4143. FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
  4144. FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers));
  4145. /* Bootstrap Firmware Version. (Some adapters don't have Bootstrap
  4146. * Firmware, so dev_info() is more appropriate here.)
  4147. */
  4148. if (!adapter->params.bs_vers)
  4149. dev_info(adapter->pdev_dev, "No bootstrap loaded\n");
  4150. else
  4151. dev_info(adapter->pdev_dev, "Bootstrap version: %u.%u.%u.%u\n",
  4152. FW_HDR_FW_VER_MAJOR_G(adapter->params.bs_vers),
  4153. FW_HDR_FW_VER_MINOR_G(adapter->params.bs_vers),
  4154. FW_HDR_FW_VER_MICRO_G(adapter->params.bs_vers),
  4155. FW_HDR_FW_VER_BUILD_G(adapter->params.bs_vers));
  4156. /* TP Microcode Version */
  4157. if (!adapter->params.tp_vers)
  4158. dev_warn(adapter->pdev_dev, "No TP Microcode loaded\n");
  4159. else
  4160. dev_info(adapter->pdev_dev,
  4161. "TP Microcode version: %u.%u.%u.%u\n",
  4162. FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
  4163. FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
  4164. FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
  4165. FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
  4166. /* Expansion ROM version */
  4167. if (!adapter->params.er_vers)
  4168. dev_info(adapter->pdev_dev, "No Expansion ROM loaded\n");
  4169. else
  4170. dev_info(adapter->pdev_dev,
  4171. "Expansion ROM version: %u.%u.%u.%u\n",
  4172. FW_HDR_FW_VER_MAJOR_G(adapter->params.er_vers),
  4173. FW_HDR_FW_VER_MINOR_G(adapter->params.er_vers),
  4174. FW_HDR_FW_VER_MICRO_G(adapter->params.er_vers),
  4175. FW_HDR_FW_VER_BUILD_G(adapter->params.er_vers));
  4176. /* Software/Hardware configuration */
  4177. dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
  4178. is_offload(adapter) ? "R" : "",
  4179. ((adapter->flags & USING_MSIX) ? "MSI-X" :
  4180. (adapter->flags & USING_MSI) ? "MSI" : ""),
  4181. is_offload(adapter) ? "Offload" : "non-Offload");
  4182. }
  4183. static void print_port_info(const struct net_device *dev)
  4184. {
  4185. char buf[80];
  4186. char *bufp = buf;
  4187. const char *spd = "";
  4188. const struct port_info *pi = netdev_priv(dev);
  4189. const struct adapter *adap = pi->adapter;
  4190. if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_2_5GB)
  4191. spd = " 2.5 GT/s";
  4192. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_5_0GB)
  4193. spd = " 5 GT/s";
  4194. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_8_0GB)
  4195. spd = " 8 GT/s";
  4196. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100M)
  4197. bufp += sprintf(bufp, "100/");
  4198. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
  4199. bufp += sprintf(bufp, "1000/");
  4200. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
  4201. bufp += sprintf(bufp, "10G/");
  4202. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
  4203. bufp += sprintf(bufp, "40G/");
  4204. if (bufp != buf)
  4205. --bufp;
  4206. sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
  4207. netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
  4208. dev->name, adap->params.vpd.id, adap->name, buf);
  4209. }
  4210. static void enable_pcie_relaxed_ordering(struct pci_dev *dev)
  4211. {
  4212. pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
  4213. }
  4214. /*
  4215. * Free the following resources:
  4216. * - memory used for tables
  4217. * - MSI/MSI-X
  4218. * - net devices
  4219. * - resources FW is holding for us
  4220. */
  4221. static void free_some_resources(struct adapter *adapter)
  4222. {
  4223. unsigned int i;
  4224. t4_free_mem(adapter->l2t);
  4225. t4_free_mem(adapter->tids.tid_tab);
  4226. kfree(adapter->sge.egr_map);
  4227. kfree(adapter->sge.ingr_map);
  4228. kfree(adapter->sge.starving_fl);
  4229. kfree(adapter->sge.txq_maperr);
  4230. #ifdef CONFIG_DEBUG_FS
  4231. kfree(adapter->sge.blocked_fl);
  4232. #endif
  4233. disable_msi(adapter);
  4234. for_each_port(adapter, i)
  4235. if (adapter->port[i]) {
  4236. struct port_info *pi = adap2pinfo(adapter, i);
  4237. if (pi->viid != 0)
  4238. t4_free_vi(adapter, adapter->mbox, adapter->pf,
  4239. 0, pi->viid);
  4240. kfree(adap2pinfo(adapter, i)->rss);
  4241. free_netdev(adapter->port[i]);
  4242. }
  4243. if (adapter->flags & FW_OK)
  4244. t4_fw_bye(adapter, adapter->pf);
  4245. }
  4246. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  4247. #define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
  4248. NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
  4249. #define SEGMENT_SIZE 128
  4250. static int get_chip_type(struct pci_dev *pdev, u32 pl_rev)
  4251. {
  4252. u16 device_id;
  4253. /* Retrieve adapter's device ID */
  4254. pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
  4255. switch (device_id >> 12) {
  4256. case CHELSIO_T4:
  4257. return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  4258. case CHELSIO_T5:
  4259. return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  4260. case CHELSIO_T6:
  4261. return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  4262. default:
  4263. dev_err(&pdev->dev, "Device %d is not supported\n",
  4264. device_id);
  4265. }
  4266. return -EINVAL;
  4267. }
  4268. #ifdef CONFIG_PCI_IOV
  4269. static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
  4270. {
  4271. int err = 0;
  4272. int current_vfs = pci_num_vf(pdev);
  4273. u32 pcie_fw;
  4274. void __iomem *regs;
  4275. regs = pci_ioremap_bar(pdev, 0);
  4276. if (!regs) {
  4277. dev_err(&pdev->dev, "cannot map device registers\n");
  4278. return -ENOMEM;
  4279. }
  4280. pcie_fw = readl(regs + PCIE_FW_A);
  4281. iounmap(regs);
  4282. /* Check if cxgb4 is the MASTER and fw is initialized */
  4283. if (!(pcie_fw & PCIE_FW_INIT_F) ||
  4284. !(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
  4285. PCIE_FW_MASTER_G(pcie_fw) != 4) {
  4286. dev_warn(&pdev->dev,
  4287. "cxgb4 driver needs to be MASTER to support SRIOV\n");
  4288. return -EOPNOTSUPP;
  4289. }
  4290. /* If any of the VF's is already assigned to Guest OS, then
  4291. * SRIOV for the same cannot be modified
  4292. */
  4293. if (current_vfs && pci_vfs_assigned(pdev)) {
  4294. dev_err(&pdev->dev,
  4295. "Cannot modify SR-IOV while VFs are assigned\n");
  4296. num_vfs = current_vfs;
  4297. return num_vfs;
  4298. }
  4299. /* Disable SRIOV when zero is passed.
  4300. * One needs to disable SRIOV before modifying it, else
  4301. * stack throws the below warning:
  4302. * " 'n' VFs already enabled. Disable before enabling 'm' VFs."
  4303. */
  4304. if (!num_vfs) {
  4305. pci_disable_sriov(pdev);
  4306. return num_vfs;
  4307. }
  4308. if (num_vfs != current_vfs) {
  4309. err = pci_enable_sriov(pdev, num_vfs);
  4310. if (err)
  4311. return err;
  4312. }
  4313. return num_vfs;
  4314. }
  4315. #endif
  4316. static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4317. {
  4318. int func, i, err, s_qpp, qpp, num_seg;
  4319. struct port_info *pi;
  4320. bool highdma = false;
  4321. struct adapter *adapter = NULL;
  4322. void __iomem *regs;
  4323. u32 whoami, pl_rev;
  4324. enum chip_type chip;
  4325. printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  4326. err = pci_request_regions(pdev, KBUILD_MODNAME);
  4327. if (err) {
  4328. /* Just info, some other driver may have claimed the device. */
  4329. dev_info(&pdev->dev, "cannot obtain PCI resources\n");
  4330. return err;
  4331. }
  4332. err = pci_enable_device(pdev);
  4333. if (err) {
  4334. dev_err(&pdev->dev, "cannot enable PCI device\n");
  4335. goto out_release_regions;
  4336. }
  4337. regs = pci_ioremap_bar(pdev, 0);
  4338. if (!regs) {
  4339. dev_err(&pdev->dev, "cannot map device registers\n");
  4340. err = -ENOMEM;
  4341. goto out_disable_device;
  4342. }
  4343. err = t4_wait_dev_ready(regs);
  4344. if (err < 0)
  4345. goto out_unmap_bar0;
  4346. /* We control everything through one PF */
  4347. whoami = readl(regs + PL_WHOAMI_A);
  4348. pl_rev = REV_G(readl(regs + PL_REV_A));
  4349. chip = get_chip_type(pdev, pl_rev);
  4350. func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
  4351. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4352. if (func != ent->driver_data) {
  4353. iounmap(regs);
  4354. pci_disable_device(pdev);
  4355. pci_save_state(pdev); /* to restore SR-IOV later */
  4356. goto sriov;
  4357. }
  4358. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  4359. highdma = true;
  4360. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4361. if (err) {
  4362. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
  4363. "coherent allocations\n");
  4364. goto out_unmap_bar0;
  4365. }
  4366. } else {
  4367. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4368. if (err) {
  4369. dev_err(&pdev->dev, "no usable DMA configuration\n");
  4370. goto out_unmap_bar0;
  4371. }
  4372. }
  4373. pci_enable_pcie_error_reporting(pdev);
  4374. enable_pcie_relaxed_ordering(pdev);
  4375. pci_set_master(pdev);
  4376. pci_save_state(pdev);
  4377. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  4378. if (!adapter) {
  4379. err = -ENOMEM;
  4380. goto out_unmap_bar0;
  4381. }
  4382. adapter->workq = create_singlethread_workqueue("cxgb4");
  4383. if (!adapter->workq) {
  4384. err = -ENOMEM;
  4385. goto out_free_adapter;
  4386. }
  4387. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  4388. (sizeof(struct mbox_cmd) *
  4389. T4_OS_LOG_MBOX_CMDS),
  4390. GFP_KERNEL);
  4391. if (!adapter->mbox_log) {
  4392. err = -ENOMEM;
  4393. goto out_free_adapter;
  4394. }
  4395. adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
  4396. /* PCI device has been enabled */
  4397. adapter->flags |= DEV_ENABLED;
  4398. adapter->regs = regs;
  4399. adapter->pdev = pdev;
  4400. adapter->pdev_dev = &pdev->dev;
  4401. adapter->name = pci_name(pdev);
  4402. adapter->mbox = func;
  4403. adapter->pf = func;
  4404. adapter->msg_enable = dflt_msg_enable;
  4405. memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
  4406. spin_lock_init(&adapter->stats_lock);
  4407. spin_lock_init(&adapter->tid_release_lock);
  4408. spin_lock_init(&adapter->win0_lock);
  4409. INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
  4410. INIT_WORK(&adapter->db_full_task, process_db_full);
  4411. INIT_WORK(&adapter->db_drop_task, process_db_drop);
  4412. err = t4_prep_adapter(adapter);
  4413. if (err)
  4414. goto out_free_adapter;
  4415. if (!is_t4(adapter->params.chip)) {
  4416. s_qpp = (QUEUESPERPAGEPF0_S +
  4417. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
  4418. adapter->pf);
  4419. qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
  4420. SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
  4421. num_seg = PAGE_SIZE / SEGMENT_SIZE;
  4422. /* Each segment size is 128B. Write coalescing is enabled only
  4423. * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
  4424. * queue is less no of segments that can be accommodated in
  4425. * a page size.
  4426. */
  4427. if (qpp > num_seg) {
  4428. dev_err(&pdev->dev,
  4429. "Incorrect number of egress queues per page\n");
  4430. err = -EINVAL;
  4431. goto out_free_adapter;
  4432. }
  4433. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  4434. pci_resource_len(pdev, 2));
  4435. if (!adapter->bar2) {
  4436. dev_err(&pdev->dev, "cannot map device bar2 region\n");
  4437. err = -ENOMEM;
  4438. goto out_free_adapter;
  4439. }
  4440. }
  4441. setup_memwin(adapter);
  4442. err = adap_init0(adapter);
  4443. #ifdef CONFIG_DEBUG_FS
  4444. bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
  4445. #endif
  4446. setup_memwin_rdma(adapter);
  4447. if (err)
  4448. goto out_unmap_bar;
  4449. /* configure SGE_STAT_CFG_A to read WC stats */
  4450. if (!is_t4(adapter->params.chip))
  4451. t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
  4452. (is_t5(adapter->params.chip) ? STATMODE_V(0) :
  4453. T6_STATMODE_V(0)));
  4454. for_each_port(adapter, i) {
  4455. struct net_device *netdev;
  4456. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  4457. MAX_ETH_QSETS);
  4458. if (!netdev) {
  4459. err = -ENOMEM;
  4460. goto out_free_dev;
  4461. }
  4462. SET_NETDEV_DEV(netdev, &pdev->dev);
  4463. adapter->port[i] = netdev;
  4464. pi = netdev_priv(netdev);
  4465. pi->adapter = adapter;
  4466. pi->xact_addr_filt = -1;
  4467. pi->port_id = i;
  4468. netdev->irq = pdev->irq;
  4469. netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
  4470. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  4471. NETIF_F_RXCSUM | NETIF_F_RXHASH |
  4472. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
  4473. if (highdma)
  4474. netdev->hw_features |= NETIF_F_HIGHDMA;
  4475. netdev->features |= netdev->hw_features;
  4476. netdev->vlan_features = netdev->features & VLAN_FEAT;
  4477. netdev->priv_flags |= IFF_UNICAST_FLT;
  4478. netdev->netdev_ops = &cxgb4_netdev_ops;
  4479. #ifdef CONFIG_CHELSIO_T4_DCB
  4480. netdev->dcbnl_ops = &cxgb4_dcb_ops;
  4481. cxgb4_dcb_state_init(netdev);
  4482. #endif
  4483. cxgb4_set_ethtool_ops(netdev);
  4484. }
  4485. pci_set_drvdata(pdev, adapter);
  4486. if (adapter->flags & FW_OK) {
  4487. err = t4_port_init(adapter, func, func, 0);
  4488. if (err)
  4489. goto out_free_dev;
  4490. } else if (adapter->params.nports == 1) {
  4491. /* If we don't have a connection to the firmware -- possibly
  4492. * because of an error -- grab the raw VPD parameters so we
  4493. * can set the proper MAC Address on the debug network
  4494. * interface that we've created.
  4495. */
  4496. u8 hw_addr[ETH_ALEN];
  4497. u8 *na = adapter->params.vpd.na;
  4498. err = t4_get_raw_vpd_params(adapter, &adapter->params.vpd);
  4499. if (!err) {
  4500. for (i = 0; i < ETH_ALEN; i++)
  4501. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  4502. hex2val(na[2 * i + 1]));
  4503. t4_set_hw_addr(adapter, 0, hw_addr);
  4504. }
  4505. }
  4506. /* Configure queues and allocate tables now, they can be needed as
  4507. * soon as the first register_netdev completes.
  4508. */
  4509. cfg_queues(adapter);
  4510. adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
  4511. if (!adapter->l2t) {
  4512. /* We tolerate a lack of L2T, giving up some functionality */
  4513. dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
  4514. adapter->params.offload = 0;
  4515. }
  4516. #if IS_ENABLED(CONFIG_IPV6)
  4517. if ((CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) &&
  4518. (!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
  4519. /* CLIP functionality is not present in hardware,
  4520. * hence disable all offload features
  4521. */
  4522. dev_warn(&pdev->dev,
  4523. "CLIP not enabled in hardware, continuing\n");
  4524. adapter->params.offload = 0;
  4525. } else {
  4526. adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
  4527. adapter->clipt_end);
  4528. if (!adapter->clipt) {
  4529. /* We tolerate a lack of clip_table, giving up
  4530. * some functionality
  4531. */
  4532. dev_warn(&pdev->dev,
  4533. "could not allocate Clip table, continuing\n");
  4534. adapter->params.offload = 0;
  4535. }
  4536. }
  4537. #endif
  4538. if (is_offload(adapter) && tid_init(&adapter->tids) < 0) {
  4539. dev_warn(&pdev->dev, "could not allocate TID table, "
  4540. "continuing\n");
  4541. adapter->params.offload = 0;
  4542. }
  4543. if (is_offload(adapter)) {
  4544. if (t4_read_reg(adapter, LE_DB_CONFIG_A) & HASHEN_F) {
  4545. u32 hash_base, hash_reg;
  4546. if (chip <= CHELSIO_T5) {
  4547. hash_reg = LE_DB_TID_HASHBASE_A;
  4548. hash_base = t4_read_reg(adapter, hash_reg);
  4549. adapter->tids.hash_base = hash_base / 4;
  4550. } else {
  4551. hash_reg = T6_LE_DB_HASH_TID_BASE_A;
  4552. hash_base = t4_read_reg(adapter, hash_reg);
  4553. adapter->tids.hash_base = hash_base;
  4554. }
  4555. }
  4556. }
  4557. /* See what interrupts we'll be using */
  4558. if (msi > 1 && enable_msix(adapter) == 0)
  4559. adapter->flags |= USING_MSIX;
  4560. else if (msi > 0 && pci_enable_msi(pdev) == 0)
  4561. adapter->flags |= USING_MSI;
  4562. /* check for PCI Express bandwidth capabiltites */
  4563. cxgb4_check_pcie_caps(adapter);
  4564. err = init_rss(adapter);
  4565. if (err)
  4566. goto out_free_dev;
  4567. /*
  4568. * The card is now ready to go. If any errors occur during device
  4569. * registration we do not fail the whole card but rather proceed only
  4570. * with the ports we manage to register successfully. However we must
  4571. * register at least one net device.
  4572. */
  4573. for_each_port(adapter, i) {
  4574. pi = adap2pinfo(adapter, i);
  4575. netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
  4576. netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
  4577. err = register_netdev(adapter->port[i]);
  4578. if (err)
  4579. break;
  4580. adapter->chan_map[pi->tx_chan] = i;
  4581. print_port_info(adapter->port[i]);
  4582. }
  4583. if (i == 0) {
  4584. dev_err(&pdev->dev, "could not register any net devices\n");
  4585. goto out_free_dev;
  4586. }
  4587. if (err) {
  4588. dev_warn(&pdev->dev, "only %d net devices registered\n", i);
  4589. err = 0;
  4590. }
  4591. if (cxgb4_debugfs_root) {
  4592. adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
  4593. cxgb4_debugfs_root);
  4594. setup_debugfs(adapter);
  4595. }
  4596. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  4597. pdev->needs_freset = 1;
  4598. if (is_offload(adapter))
  4599. attach_ulds(adapter);
  4600. print_adapter_info(adapter);
  4601. sriov:
  4602. #ifdef CONFIG_PCI_IOV
  4603. if (func < ARRAY_SIZE(num_vf) && num_vf[func] > 0) {
  4604. dev_warn(&pdev->dev,
  4605. "Enabling SR-IOV VFs using the num_vf module "
  4606. "parameter is deprecated - please use the pci sysfs "
  4607. "interface instead.\n");
  4608. if (pci_enable_sriov(pdev, num_vf[func]) == 0)
  4609. dev_info(&pdev->dev,
  4610. "instantiated %u virtual functions\n",
  4611. num_vf[func]);
  4612. }
  4613. #endif
  4614. return 0;
  4615. out_free_dev:
  4616. free_some_resources(adapter);
  4617. out_unmap_bar:
  4618. if (!is_t4(adapter->params.chip))
  4619. iounmap(adapter->bar2);
  4620. out_free_adapter:
  4621. if (adapter->workq)
  4622. destroy_workqueue(adapter->workq);
  4623. kfree(adapter->mbox_log);
  4624. kfree(adapter);
  4625. out_unmap_bar0:
  4626. iounmap(regs);
  4627. out_disable_device:
  4628. pci_disable_pcie_error_reporting(pdev);
  4629. pci_disable_device(pdev);
  4630. out_release_regions:
  4631. pci_release_regions(pdev);
  4632. return err;
  4633. }
  4634. static void remove_one(struct pci_dev *pdev)
  4635. {
  4636. struct adapter *adapter = pci_get_drvdata(pdev);
  4637. #ifdef CONFIG_PCI_IOV
  4638. pci_disable_sriov(pdev);
  4639. #endif
  4640. if (adapter) {
  4641. int i;
  4642. /* Tear down per-adapter Work Queue first since it can contain
  4643. * references to our adapter data structure.
  4644. */
  4645. destroy_workqueue(adapter->workq);
  4646. if (is_offload(adapter))
  4647. detach_ulds(adapter);
  4648. disable_interrupts(adapter);
  4649. for_each_port(adapter, i)
  4650. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  4651. unregister_netdev(adapter->port[i]);
  4652. debugfs_remove_recursive(adapter->debugfs_root);
  4653. /* If we allocated filters, free up state associated with any
  4654. * valid filters ...
  4655. */
  4656. if (adapter->tids.ftid_tab) {
  4657. struct filter_entry *f = &adapter->tids.ftid_tab[0];
  4658. for (i = 0; i < (adapter->tids.nftids +
  4659. adapter->tids.nsftids); i++, f++)
  4660. if (f->valid)
  4661. clear_filter(adapter, f);
  4662. }
  4663. if (adapter->flags & FULL_INIT_DONE)
  4664. cxgb_down(adapter);
  4665. free_some_resources(adapter);
  4666. #if IS_ENABLED(CONFIG_IPV6)
  4667. t4_cleanup_clip_tbl(adapter);
  4668. #endif
  4669. iounmap(adapter->regs);
  4670. if (!is_t4(adapter->params.chip))
  4671. iounmap(adapter->bar2);
  4672. pci_disable_pcie_error_reporting(pdev);
  4673. if ((adapter->flags & DEV_ENABLED)) {
  4674. pci_disable_device(pdev);
  4675. adapter->flags &= ~DEV_ENABLED;
  4676. }
  4677. pci_release_regions(pdev);
  4678. kfree(adapter->mbox_log);
  4679. synchronize_rcu();
  4680. kfree(adapter);
  4681. } else
  4682. pci_release_regions(pdev);
  4683. }
  4684. static struct pci_driver cxgb4_driver = {
  4685. .name = KBUILD_MODNAME,
  4686. .id_table = cxgb4_pci_tbl,
  4687. .probe = init_one,
  4688. .remove = remove_one,
  4689. .shutdown = remove_one,
  4690. #ifdef CONFIG_PCI_IOV
  4691. .sriov_configure = cxgb4_iov_configure,
  4692. #endif
  4693. .err_handler = &cxgb4_eeh,
  4694. };
  4695. static int __init cxgb4_init_module(void)
  4696. {
  4697. int ret;
  4698. /* Debugfs support is optional, just warn if this fails */
  4699. cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  4700. if (!cxgb4_debugfs_root)
  4701. pr_warn("could not create debugfs entry, continuing\n");
  4702. ret = pci_register_driver(&cxgb4_driver);
  4703. if (ret < 0)
  4704. debugfs_remove(cxgb4_debugfs_root);
  4705. #if IS_ENABLED(CONFIG_IPV6)
  4706. if (!inet6addr_registered) {
  4707. register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  4708. inet6addr_registered = true;
  4709. }
  4710. #endif
  4711. return ret;
  4712. }
  4713. static void __exit cxgb4_cleanup_module(void)
  4714. {
  4715. #if IS_ENABLED(CONFIG_IPV6)
  4716. if (inet6addr_registered) {
  4717. unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  4718. inet6addr_registered = false;
  4719. }
  4720. #endif
  4721. pci_unregister_driver(&cxgb4_driver);
  4722. debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
  4723. }
  4724. module_init(cxgb4_init_module);
  4725. module_exit(cxgb4_cleanup_module);