cxgb4_main.c 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 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 <linux/uaccess.h>
  65. #include <linux/crash_dump.h>
  66. #include <net/udp_tunnel.h>
  67. #include "cxgb4.h"
  68. #include "cxgb4_filter.h"
  69. #include "t4_regs.h"
  70. #include "t4_values.h"
  71. #include "t4_msg.h"
  72. #include "t4fw_api.h"
  73. #include "t4fw_version.h"
  74. #include "cxgb4_dcb.h"
  75. #include "srq.h"
  76. #include "cxgb4_debugfs.h"
  77. #include "clip_tbl.h"
  78. #include "l2t.h"
  79. #include "smt.h"
  80. #include "sched.h"
  81. #include "cxgb4_tc_u32.h"
  82. #include "cxgb4_tc_flower.h"
  83. #include "cxgb4_ptp.h"
  84. #include "cxgb4_cudbg.h"
  85. char cxgb4_driver_name[] = KBUILD_MODNAME;
  86. #ifdef DRV_VERSION
  87. #undef DRV_VERSION
  88. #endif
  89. #define DRV_VERSION "2.0.0-ko"
  90. const char cxgb4_driver_version[] = DRV_VERSION;
  91. #define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
  92. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  93. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  94. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  95. /* Macros needed to support the PCI Device ID Table ...
  96. */
  97. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
  98. static const struct pci_device_id cxgb4_pci_tbl[] = {
  99. #define CXGB4_UNIFIED_PF 0x4
  100. #define CH_PCI_DEVICE_ID_FUNCTION CXGB4_UNIFIED_PF
  101. /* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
  102. * called for both.
  103. */
  104. #define CH_PCI_DEVICE_ID_FUNCTION2 0x0
  105. #define CH_PCI_ID_TABLE_ENTRY(devid) \
  106. {PCI_VDEVICE(CHELSIO, (devid)), CXGB4_UNIFIED_PF}
  107. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
  108. { 0, } \
  109. }
  110. #include "t4_pci_id_tbl.h"
  111. #define FW4_FNAME "cxgb4/t4fw.bin"
  112. #define FW5_FNAME "cxgb4/t5fw.bin"
  113. #define FW6_FNAME "cxgb4/t6fw.bin"
  114. #define FW4_CFNAME "cxgb4/t4-config.txt"
  115. #define FW5_CFNAME "cxgb4/t5-config.txt"
  116. #define FW6_CFNAME "cxgb4/t6-config.txt"
  117. #define PHY_AQ1202_FIRMWARE "cxgb4/aq1202_fw.cld"
  118. #define PHY_BCM84834_FIRMWARE "cxgb4/bcm8483.bin"
  119. #define PHY_AQ1202_DEVICEID 0x4409
  120. #define PHY_BCM84834_DEVICEID 0x4486
  121. MODULE_DESCRIPTION(DRV_DESC);
  122. MODULE_AUTHOR("Chelsio Communications");
  123. MODULE_LICENSE("Dual BSD/GPL");
  124. MODULE_VERSION(DRV_VERSION);
  125. MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
  126. MODULE_FIRMWARE(FW4_FNAME);
  127. MODULE_FIRMWARE(FW5_FNAME);
  128. MODULE_FIRMWARE(FW6_FNAME);
  129. /*
  130. * The driver uses the best interrupt scheme available on a platform in the
  131. * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
  132. * of these schemes the driver may consider as follows:
  133. *
  134. * msi = 2: choose from among all three options
  135. * msi = 1: only consider MSI and INTx interrupts
  136. * msi = 0: force INTx interrupts
  137. */
  138. static int msi = 2;
  139. module_param(msi, int, 0644);
  140. MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
  141. /*
  142. * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
  143. * offset by 2 bytes in order to have the IP headers line up on 4-byte
  144. * boundaries. This is a requirement for many architectures which will throw
  145. * a machine check fault if an attempt is made to access one of the 4-byte IP
  146. * header fields on a non-4-byte boundary. And it's a major performance issue
  147. * even on some architectures which allow it like some implementations of the
  148. * x86 ISA. However, some architectures don't mind this and for some very
  149. * edge-case performance sensitive applications (like forwarding large volumes
  150. * of small packets), setting this DMA offset to 0 will decrease the number of
  151. * PCI-E Bus transfers enough to measurably affect performance.
  152. */
  153. static int rx_dma_offset = 2;
  154. /* TX Queue select used to determine what algorithm to use for selecting TX
  155. * queue. Select between the kernel provided function (select_queue=0) or user
  156. * cxgb_select_queue function (select_queue=1)
  157. *
  158. * Default: select_queue=0
  159. */
  160. static int select_queue;
  161. module_param(select_queue, int, 0644);
  162. MODULE_PARM_DESC(select_queue,
  163. "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
  164. static struct dentry *cxgb4_debugfs_root;
  165. LIST_HEAD(adapter_list);
  166. DEFINE_MUTEX(uld_mutex);
  167. static void link_report(struct net_device *dev)
  168. {
  169. if (!netif_carrier_ok(dev))
  170. netdev_info(dev, "link down\n");
  171. else {
  172. static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
  173. const char *s;
  174. const struct port_info *p = netdev_priv(dev);
  175. switch (p->link_cfg.speed) {
  176. case 100:
  177. s = "100Mbps";
  178. break;
  179. case 1000:
  180. s = "1Gbps";
  181. break;
  182. case 10000:
  183. s = "10Gbps";
  184. break;
  185. case 25000:
  186. s = "25Gbps";
  187. break;
  188. case 40000:
  189. s = "40Gbps";
  190. break;
  191. case 50000:
  192. s = "50Gbps";
  193. break;
  194. case 100000:
  195. s = "100Gbps";
  196. break;
  197. default:
  198. pr_info("%s: unsupported speed: %d\n",
  199. dev->name, p->link_cfg.speed);
  200. return;
  201. }
  202. netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
  203. fc[p->link_cfg.fc]);
  204. }
  205. }
  206. #ifdef CONFIG_CHELSIO_T4_DCB
  207. /* Set up/tear down Data Center Bridging Priority mapping for a net device. */
  208. static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
  209. {
  210. struct port_info *pi = netdev_priv(dev);
  211. struct adapter *adap = pi->adapter;
  212. struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
  213. int i;
  214. /* We use a simple mapping of Port TX Queue Index to DCB
  215. * Priority when we're enabling DCB.
  216. */
  217. for (i = 0; i < pi->nqsets; i++, txq++) {
  218. u32 name, value;
  219. int err;
  220. name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  221. FW_PARAMS_PARAM_X_V(
  222. FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
  223. FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
  224. value = enable ? i : 0xffffffff;
  225. /* Since we can be called while atomic (from "interrupt
  226. * level") we need to issue the Set Parameters Commannd
  227. * without sleeping (timeout < 0).
  228. */
  229. err = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
  230. &name, &value,
  231. -FW_CMD_MAX_TIMEOUT);
  232. if (err)
  233. dev_err(adap->pdev_dev,
  234. "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
  235. enable ? "set" : "unset", pi->port_id, i, -err);
  236. else
  237. txq->dcb_prio = enable ? value : 0;
  238. }
  239. }
  240. int cxgb4_dcb_enabled(const struct net_device *dev)
  241. {
  242. struct port_info *pi = netdev_priv(dev);
  243. if (!pi->dcb.enabled)
  244. return 0;
  245. return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
  246. (pi->dcb.state == CXGB4_DCB_STATE_HOST));
  247. }
  248. #endif /* CONFIG_CHELSIO_T4_DCB */
  249. void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
  250. {
  251. struct net_device *dev = adapter->port[port_id];
  252. /* Skip changes from disabled ports. */
  253. if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
  254. if (link_stat)
  255. netif_carrier_on(dev);
  256. else {
  257. #ifdef CONFIG_CHELSIO_T4_DCB
  258. if (cxgb4_dcb_enabled(dev)) {
  259. cxgb4_dcb_reset(dev);
  260. dcb_tx_queue_prio_enable(dev, false);
  261. }
  262. #endif /* CONFIG_CHELSIO_T4_DCB */
  263. netif_carrier_off(dev);
  264. }
  265. link_report(dev);
  266. }
  267. }
  268. void t4_os_portmod_changed(struct adapter *adap, int port_id)
  269. {
  270. static const char *mod_str[] = {
  271. NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
  272. };
  273. struct net_device *dev = adap->port[port_id];
  274. struct port_info *pi = netdev_priv(dev);
  275. if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
  276. netdev_info(dev, "port module unplugged\n");
  277. else if (pi->mod_type < ARRAY_SIZE(mod_str))
  278. netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
  279. else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  280. netdev_info(dev, "%s: unsupported port module inserted\n",
  281. dev->name);
  282. else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  283. netdev_info(dev, "%s: unknown port module inserted\n",
  284. dev->name);
  285. else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
  286. netdev_info(dev, "%s: transceiver module error\n", dev->name);
  287. else
  288. netdev_info(dev, "%s: unknown module type %d inserted\n",
  289. dev->name, pi->mod_type);
  290. /* If the interface is running, then we'll need any "sticky" Link
  291. * Parameters redone with a new Transceiver Module.
  292. */
  293. pi->link_cfg.redo_l1cfg = netif_running(dev);
  294. }
  295. int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
  296. module_param(dbfifo_int_thresh, int, 0644);
  297. MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
  298. /*
  299. * usecs to sleep while draining the dbfifo
  300. */
  301. static int dbfifo_drain_delay = 1000;
  302. module_param(dbfifo_drain_delay, int, 0644);
  303. MODULE_PARM_DESC(dbfifo_drain_delay,
  304. "usecs to sleep while draining the dbfifo");
  305. static inline int cxgb4_set_addr_hash(struct port_info *pi)
  306. {
  307. struct adapter *adap = pi->adapter;
  308. u64 vec = 0;
  309. bool ucast = false;
  310. struct hash_mac_addr *entry;
  311. /* Calculate the hash vector for the updated list and program it */
  312. list_for_each_entry(entry, &adap->mac_hlist, list) {
  313. ucast |= is_unicast_ether_addr(entry->addr);
  314. vec |= (1ULL << hash_mac_addr(entry->addr));
  315. }
  316. return t4_set_addr_hash(adap, adap->mbox, pi->viid, ucast,
  317. vec, false);
  318. }
  319. static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
  320. {
  321. struct port_info *pi = netdev_priv(netdev);
  322. struct adapter *adap = pi->adapter;
  323. int ret;
  324. u64 mhash = 0;
  325. u64 uhash = 0;
  326. bool free = false;
  327. bool ucast = is_unicast_ether_addr(mac_addr);
  328. const u8 *maclist[1] = {mac_addr};
  329. struct hash_mac_addr *new_entry;
  330. ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
  331. NULL, ucast ? &uhash : &mhash, false);
  332. if (ret < 0)
  333. goto out;
  334. /* if hash != 0, then add the addr to hash addr list
  335. * so on the end we will calculate the hash for the
  336. * list and program it
  337. */
  338. if (uhash || mhash) {
  339. new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
  340. if (!new_entry)
  341. return -ENOMEM;
  342. ether_addr_copy(new_entry->addr, mac_addr);
  343. list_add_tail(&new_entry->list, &adap->mac_hlist);
  344. ret = cxgb4_set_addr_hash(pi);
  345. }
  346. out:
  347. return ret < 0 ? ret : 0;
  348. }
  349. static int cxgb4_mac_unsync(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. const u8 *maclist[1] = {mac_addr};
  355. struct hash_mac_addr *entry, *tmp;
  356. /* If the MAC address to be removed is in the hash addr
  357. * list, delete it from the list and update hash vector
  358. */
  359. list_for_each_entry_safe(entry, tmp, &adap->mac_hlist, list) {
  360. if (ether_addr_equal(entry->addr, mac_addr)) {
  361. list_del(&entry->list);
  362. kfree(entry);
  363. return cxgb4_set_addr_hash(pi);
  364. }
  365. }
  366. ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
  367. return ret < 0 ? -EINVAL : 0;
  368. }
  369. /*
  370. * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
  371. * If @mtu is -1 it is left unchanged.
  372. */
  373. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  374. {
  375. struct port_info *pi = netdev_priv(dev);
  376. struct adapter *adapter = pi->adapter;
  377. __dev_uc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  378. __dev_mc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  379. return t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu,
  380. (dev->flags & IFF_PROMISC) ? 1 : 0,
  381. (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
  382. sleep_ok);
  383. }
  384. /**
  385. * link_start - enable a port
  386. * @dev: the port to enable
  387. *
  388. * Performs the MAC and PHY actions needed to enable a port.
  389. */
  390. static int link_start(struct net_device *dev)
  391. {
  392. int ret;
  393. struct port_info *pi = netdev_priv(dev);
  394. unsigned int mb = pi->adapter->pf;
  395. /*
  396. * We do not set address filters and promiscuity here, the stack does
  397. * that step explicitly.
  398. */
  399. ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
  400. !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
  401. if (ret == 0) {
  402. ret = t4_change_mac(pi->adapter, mb, pi->viid,
  403. pi->xact_addr_filt, dev->dev_addr, true,
  404. true);
  405. if (ret >= 0) {
  406. pi->xact_addr_filt = ret;
  407. ret = 0;
  408. }
  409. }
  410. if (ret == 0)
  411. ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
  412. &pi->link_cfg);
  413. if (ret == 0) {
  414. local_bh_disable();
  415. ret = t4_enable_pi_params(pi->adapter, mb, pi, true,
  416. true, CXGB4_DCB_ENABLED);
  417. local_bh_enable();
  418. }
  419. return ret;
  420. }
  421. #ifdef CONFIG_CHELSIO_T4_DCB
  422. /* Handle a Data Center Bridging update message from the firmware. */
  423. static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
  424. {
  425. int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
  426. struct net_device *dev = adap->port[adap->chan_map[port]];
  427. int old_dcb_enabled = cxgb4_dcb_enabled(dev);
  428. int new_dcb_enabled;
  429. cxgb4_dcb_handle_fw_update(adap, pcmd);
  430. new_dcb_enabled = cxgb4_dcb_enabled(dev);
  431. /* If the DCB has become enabled or disabled on the port then we're
  432. * going to need to set up/tear down DCB Priority parameters for the
  433. * TX Queues associated with the port.
  434. */
  435. if (new_dcb_enabled != old_dcb_enabled)
  436. dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
  437. }
  438. #endif /* CONFIG_CHELSIO_T4_DCB */
  439. /* Response queue handler for the FW event queue.
  440. */
  441. static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
  442. const struct pkt_gl *gl)
  443. {
  444. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  445. rsp++; /* skip RSS header */
  446. /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
  447. */
  448. if (unlikely(opcode == CPL_FW4_MSG &&
  449. ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
  450. rsp++;
  451. opcode = ((const struct rss_header *)rsp)->opcode;
  452. rsp++;
  453. if (opcode != CPL_SGE_EGR_UPDATE) {
  454. dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
  455. , opcode);
  456. goto out;
  457. }
  458. }
  459. if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
  460. const struct cpl_sge_egr_update *p = (void *)rsp;
  461. unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
  462. struct sge_txq *txq;
  463. txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
  464. txq->restarts++;
  465. if (txq->q_type == CXGB4_TXQ_ETH) {
  466. struct sge_eth_txq *eq;
  467. eq = container_of(txq, struct sge_eth_txq, q);
  468. netif_tx_wake_queue(eq->txq);
  469. } else {
  470. struct sge_uld_txq *oq;
  471. oq = container_of(txq, struct sge_uld_txq, q);
  472. tasklet_schedule(&oq->qresume_tsk);
  473. }
  474. } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
  475. const struct cpl_fw6_msg *p = (void *)rsp;
  476. #ifdef CONFIG_CHELSIO_T4_DCB
  477. const struct fw_port_cmd *pcmd = (const void *)p->data;
  478. unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
  479. unsigned int action =
  480. FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
  481. if (cmd == FW_PORT_CMD &&
  482. (action == FW_PORT_ACTION_GET_PORT_INFO ||
  483. action == FW_PORT_ACTION_GET_PORT_INFO32)) {
  484. int port = FW_PORT_CMD_PORTID_G(
  485. be32_to_cpu(pcmd->op_to_portid));
  486. struct net_device *dev;
  487. int dcbxdis, state_input;
  488. dev = q->adap->port[q->adap->chan_map[port]];
  489. dcbxdis = (action == FW_PORT_ACTION_GET_PORT_INFO
  490. ? !!(pcmd->u.info.dcbxdis_pkd & FW_PORT_CMD_DCBXDIS_F)
  491. : !!(be32_to_cpu(pcmd->u.info32.lstatus32_to_cbllen32)
  492. & FW_PORT_CMD_DCBXDIS32_F));
  493. state_input = (dcbxdis
  494. ? CXGB4_DCB_INPUT_FW_DISABLED
  495. : CXGB4_DCB_INPUT_FW_ENABLED);
  496. cxgb4_dcb_state_fsm(dev, state_input);
  497. }
  498. if (cmd == FW_PORT_CMD &&
  499. action == FW_PORT_ACTION_L2_DCB_CFG)
  500. dcb_rpl(q->adap, pcmd);
  501. else
  502. #endif
  503. if (p->type == 0)
  504. t4_handle_fw_rpl(q->adap, p->data);
  505. } else if (opcode == CPL_L2T_WRITE_RPL) {
  506. const struct cpl_l2t_write_rpl *p = (void *)rsp;
  507. do_l2t_write_rpl(q->adap, p);
  508. } else if (opcode == CPL_SMT_WRITE_RPL) {
  509. const struct cpl_smt_write_rpl *p = (void *)rsp;
  510. do_smt_write_rpl(q->adap, p);
  511. } else if (opcode == CPL_SET_TCB_RPL) {
  512. const struct cpl_set_tcb_rpl *p = (void *)rsp;
  513. filter_rpl(q->adap, p);
  514. } else if (opcode == CPL_ACT_OPEN_RPL) {
  515. const struct cpl_act_open_rpl *p = (void *)rsp;
  516. hash_filter_rpl(q->adap, p);
  517. } else if (opcode == CPL_ABORT_RPL_RSS) {
  518. const struct cpl_abort_rpl_rss *p = (void *)rsp;
  519. hash_del_filter_rpl(q->adap, p);
  520. } else if (opcode == CPL_SRQ_TABLE_RPL) {
  521. const struct cpl_srq_table_rpl *p = (void *)rsp;
  522. do_srq_table_rpl(q->adap, p);
  523. } else
  524. dev_err(q->adap->pdev_dev,
  525. "unexpected CPL %#x on FW event queue\n", opcode);
  526. out:
  527. return 0;
  528. }
  529. static void disable_msi(struct adapter *adapter)
  530. {
  531. if (adapter->flags & USING_MSIX) {
  532. pci_disable_msix(adapter->pdev);
  533. adapter->flags &= ~USING_MSIX;
  534. } else if (adapter->flags & USING_MSI) {
  535. pci_disable_msi(adapter->pdev);
  536. adapter->flags &= ~USING_MSI;
  537. }
  538. }
  539. /*
  540. * Interrupt handler for non-data events used with MSI-X.
  541. */
  542. static irqreturn_t t4_nondata_intr(int irq, void *cookie)
  543. {
  544. struct adapter *adap = cookie;
  545. u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
  546. if (v & PFSW_F) {
  547. adap->swintr = 1;
  548. t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
  549. }
  550. if (adap->flags & MASTER_PF)
  551. t4_slow_intr_handler(adap);
  552. return IRQ_HANDLED;
  553. }
  554. /*
  555. * Name the MSI-X interrupts.
  556. */
  557. static void name_msix_vecs(struct adapter *adap)
  558. {
  559. int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
  560. /* non-data interrupts */
  561. snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
  562. /* FW events */
  563. snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
  564. adap->port[0]->name);
  565. /* Ethernet queues */
  566. for_each_port(adap, j) {
  567. struct net_device *d = adap->port[j];
  568. const struct port_info *pi = netdev_priv(d);
  569. for (i = 0; i < pi->nqsets; i++, msi_idx++)
  570. snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
  571. d->name, i);
  572. }
  573. }
  574. static int request_msix_queue_irqs(struct adapter *adap)
  575. {
  576. struct sge *s = &adap->sge;
  577. int err, ethqidx;
  578. int msi_index = 2;
  579. err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
  580. adap->msix_info[1].desc, &s->fw_evtq);
  581. if (err)
  582. return err;
  583. for_each_ethrxq(s, ethqidx) {
  584. err = request_irq(adap->msix_info[msi_index].vec,
  585. t4_sge_intr_msix, 0,
  586. adap->msix_info[msi_index].desc,
  587. &s->ethrxq[ethqidx].rspq);
  588. if (err)
  589. goto unwind;
  590. msi_index++;
  591. }
  592. return 0;
  593. unwind:
  594. while (--ethqidx >= 0)
  595. free_irq(adap->msix_info[--msi_index].vec,
  596. &s->ethrxq[ethqidx].rspq);
  597. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  598. return err;
  599. }
  600. static void free_msix_queue_irqs(struct adapter *adap)
  601. {
  602. int i, msi_index = 2;
  603. struct sge *s = &adap->sge;
  604. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  605. for_each_ethrxq(s, i)
  606. free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
  607. }
  608. /**
  609. * cxgb4_write_rss - write the RSS table for a given port
  610. * @pi: the port
  611. * @queues: array of queue indices for RSS
  612. *
  613. * Sets up the portion of the HW RSS table for the port's VI to distribute
  614. * packets to the Rx queues in @queues.
  615. * Should never be called before setting up sge eth rx queues
  616. */
  617. int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
  618. {
  619. u16 *rss;
  620. int i, err;
  621. struct adapter *adapter = pi->adapter;
  622. const struct sge_eth_rxq *rxq;
  623. rxq = &adapter->sge.ethrxq[pi->first_qset];
  624. rss = kmalloc_array(pi->rss_size, sizeof(u16), GFP_KERNEL);
  625. if (!rss)
  626. return -ENOMEM;
  627. /* map the queue indices to queue ids */
  628. for (i = 0; i < pi->rss_size; i++, queues++)
  629. rss[i] = rxq[*queues].rspq.abs_id;
  630. err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
  631. pi->rss_size, rss, pi->rss_size);
  632. /* If Tunnel All Lookup isn't specified in the global RSS
  633. * Configuration, then we need to specify a default Ingress
  634. * Queue for any ingress packets which aren't hashed. We'll
  635. * use our first ingress queue ...
  636. */
  637. if (!err)
  638. err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
  639. FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F |
  640. FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F |
  641. FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F |
  642. FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F |
  643. FW_RSS_VI_CONFIG_CMD_UDPEN_F,
  644. rss[0]);
  645. kfree(rss);
  646. return err;
  647. }
  648. /**
  649. * setup_rss - configure RSS
  650. * @adap: the adapter
  651. *
  652. * Sets up RSS for each port.
  653. */
  654. static int setup_rss(struct adapter *adap)
  655. {
  656. int i, j, err;
  657. for_each_port(adap, i) {
  658. const struct port_info *pi = adap2pinfo(adap, i);
  659. /* Fill default values with equal distribution */
  660. for (j = 0; j < pi->rss_size; j++)
  661. pi->rss[j] = j % pi->nqsets;
  662. err = cxgb4_write_rss(pi, pi->rss);
  663. if (err)
  664. return err;
  665. }
  666. return 0;
  667. }
  668. /*
  669. * Return the channel of the ingress queue with the given qid.
  670. */
  671. static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
  672. {
  673. qid -= p->ingr_start;
  674. return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
  675. }
  676. /*
  677. * Wait until all NAPI handlers are descheduled.
  678. */
  679. static void quiesce_rx(struct adapter *adap)
  680. {
  681. int i;
  682. for (i = 0; i < adap->sge.ingr_sz; i++) {
  683. struct sge_rspq *q = adap->sge.ingr_map[i];
  684. if (q && q->handler)
  685. napi_disable(&q->napi);
  686. }
  687. }
  688. /* Disable interrupt and napi handler */
  689. static void disable_interrupts(struct adapter *adap)
  690. {
  691. if (adap->flags & FULL_INIT_DONE) {
  692. t4_intr_disable(adap);
  693. if (adap->flags & USING_MSIX) {
  694. free_msix_queue_irqs(adap);
  695. free_irq(adap->msix_info[0].vec, adap);
  696. } else {
  697. free_irq(adap->pdev->irq, adap);
  698. }
  699. quiesce_rx(adap);
  700. }
  701. }
  702. /*
  703. * Enable NAPI scheduling and interrupt generation for all Rx queues.
  704. */
  705. static void enable_rx(struct adapter *adap)
  706. {
  707. int i;
  708. for (i = 0; i < adap->sge.ingr_sz; i++) {
  709. struct sge_rspq *q = adap->sge.ingr_map[i];
  710. if (!q)
  711. continue;
  712. if (q->handler)
  713. napi_enable(&q->napi);
  714. /* 0-increment GTS to start the timer and enable interrupts */
  715. t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
  716. SEINTARM_V(q->intr_params) |
  717. INGRESSQID_V(q->cntxt_id));
  718. }
  719. }
  720. static int setup_fw_sge_queues(struct adapter *adap)
  721. {
  722. struct sge *s = &adap->sge;
  723. int err = 0;
  724. bitmap_zero(s->starving_fl, s->egr_sz);
  725. bitmap_zero(s->txq_maperr, s->egr_sz);
  726. if (adap->flags & USING_MSIX)
  727. adap->msi_idx = 1; /* vector 0 is for non-queue interrupts */
  728. else {
  729. err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
  730. NULL, NULL, NULL, -1);
  731. if (err)
  732. return err;
  733. adap->msi_idx = -((int)s->intrq.abs_id + 1);
  734. }
  735. err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
  736. adap->msi_idx, NULL, fwevtq_handler, NULL, -1);
  737. return err;
  738. }
  739. /**
  740. * setup_sge_queues - configure SGE Tx/Rx/response queues
  741. * @adap: the adapter
  742. *
  743. * Determines how many sets of SGE queues to use and initializes them.
  744. * We support multiple queue sets per port if we have MSI-X, otherwise
  745. * just one queue set per port.
  746. */
  747. static int setup_sge_queues(struct adapter *adap)
  748. {
  749. int err, i, j;
  750. struct sge *s = &adap->sge;
  751. struct sge_uld_rxq_info *rxq_info = NULL;
  752. unsigned int cmplqid = 0;
  753. if (is_uld(adap))
  754. rxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
  755. for_each_port(adap, i) {
  756. struct net_device *dev = adap->port[i];
  757. struct port_info *pi = netdev_priv(dev);
  758. struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
  759. struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
  760. for (j = 0; j < pi->nqsets; j++, q++) {
  761. if (adap->msi_idx > 0)
  762. adap->msi_idx++;
  763. err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
  764. adap->msi_idx, &q->fl,
  765. t4_ethrx_handler,
  766. NULL,
  767. t4_get_tp_ch_map(adap,
  768. pi->tx_chan));
  769. if (err)
  770. goto freeout;
  771. q->rspq.idx = j;
  772. memset(&q->stats, 0, sizeof(q->stats));
  773. }
  774. for (j = 0; j < pi->nqsets; j++, t++) {
  775. err = t4_sge_alloc_eth_txq(adap, t, dev,
  776. netdev_get_tx_queue(dev, j),
  777. s->fw_evtq.cntxt_id);
  778. if (err)
  779. goto freeout;
  780. }
  781. }
  782. for_each_port(adap, i) {
  783. /* Note that cmplqid below is 0 if we don't
  784. * have RDMA queues, and that's the right value.
  785. */
  786. if (rxq_info)
  787. cmplqid = rxq_info->uldrxq[i].rspq.cntxt_id;
  788. err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
  789. s->fw_evtq.cntxt_id, cmplqid);
  790. if (err)
  791. goto freeout;
  792. }
  793. if (!is_t4(adap->params.chip)) {
  794. err = t4_sge_alloc_eth_txq(adap, &s->ptptxq, adap->port[0],
  795. netdev_get_tx_queue(adap->port[0], 0)
  796. , s->fw_evtq.cntxt_id);
  797. if (err)
  798. goto freeout;
  799. }
  800. t4_write_reg(adap, is_t4(adap->params.chip) ?
  801. MPS_TRC_RSS_CONTROL_A :
  802. MPS_T5_TRC_RSS_CONTROL_A,
  803. RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
  804. QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
  805. return 0;
  806. freeout:
  807. dev_err(adap->pdev_dev, "Can't allocate queues, err=%d\n", -err);
  808. t4_free_sge_resources(adap);
  809. return err;
  810. }
  811. static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
  812. struct net_device *sb_dev,
  813. select_queue_fallback_t fallback)
  814. {
  815. int txq;
  816. #ifdef CONFIG_CHELSIO_T4_DCB
  817. /* If a Data Center Bridging has been successfully negotiated on this
  818. * link then we'll use the skb's priority to map it to a TX Queue.
  819. * The skb's priority is determined via the VLAN Tag Priority Code
  820. * Point field.
  821. */
  822. if (cxgb4_dcb_enabled(dev) && !is_kdump_kernel()) {
  823. u16 vlan_tci;
  824. int err;
  825. err = vlan_get_tag(skb, &vlan_tci);
  826. if (unlikely(err)) {
  827. if (net_ratelimit())
  828. netdev_warn(dev,
  829. "TX Packet without VLAN Tag on DCB Link\n");
  830. txq = 0;
  831. } else {
  832. txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  833. #ifdef CONFIG_CHELSIO_T4_FCOE
  834. if (skb->protocol == htons(ETH_P_FCOE))
  835. txq = skb->priority & 0x7;
  836. #endif /* CONFIG_CHELSIO_T4_FCOE */
  837. }
  838. return txq;
  839. }
  840. #endif /* CONFIG_CHELSIO_T4_DCB */
  841. if (select_queue) {
  842. txq = (skb_rx_queue_recorded(skb)
  843. ? skb_get_rx_queue(skb)
  844. : smp_processor_id());
  845. while (unlikely(txq >= dev->real_num_tx_queues))
  846. txq -= dev->real_num_tx_queues;
  847. return txq;
  848. }
  849. return fallback(dev, skb, NULL) % dev->real_num_tx_queues;
  850. }
  851. static int closest_timer(const struct sge *s, int time)
  852. {
  853. int i, delta, match = 0, min_delta = INT_MAX;
  854. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  855. delta = time - s->timer_val[i];
  856. if (delta < 0)
  857. delta = -delta;
  858. if (delta < min_delta) {
  859. min_delta = delta;
  860. match = i;
  861. }
  862. }
  863. return match;
  864. }
  865. static int closest_thres(const struct sge *s, int thres)
  866. {
  867. int i, delta, match = 0, min_delta = INT_MAX;
  868. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  869. delta = thres - s->counter_val[i];
  870. if (delta < 0)
  871. delta = -delta;
  872. if (delta < min_delta) {
  873. min_delta = delta;
  874. match = i;
  875. }
  876. }
  877. return match;
  878. }
  879. /**
  880. * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
  881. * @q: the Rx queue
  882. * @us: the hold-off time in us, or 0 to disable timer
  883. * @cnt: the hold-off packet count, or 0 to disable counter
  884. *
  885. * Sets an Rx queue's interrupt hold-off time and packet count. At least
  886. * one of the two needs to be enabled for the queue to generate interrupts.
  887. */
  888. int cxgb4_set_rspq_intr_params(struct sge_rspq *q,
  889. unsigned int us, unsigned int cnt)
  890. {
  891. struct adapter *adap = q->adap;
  892. if ((us | cnt) == 0)
  893. cnt = 1;
  894. if (cnt) {
  895. int err;
  896. u32 v, new_idx;
  897. new_idx = closest_thres(&adap->sge, cnt);
  898. if (q->desc && q->pktcnt_idx != new_idx) {
  899. /* the queue has already been created, update it */
  900. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  901. FW_PARAMS_PARAM_X_V(
  902. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  903. FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
  904. err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
  905. &v, &new_idx);
  906. if (err)
  907. return err;
  908. }
  909. q->pktcnt_idx = new_idx;
  910. }
  911. us = us == 0 ? 6 : closest_timer(&adap->sge, us);
  912. q->intr_params = QINTR_TIMER_IDX_V(us) | QINTR_CNT_EN_V(cnt > 0);
  913. return 0;
  914. }
  915. static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
  916. {
  917. const struct port_info *pi = netdev_priv(dev);
  918. netdev_features_t changed = dev->features ^ features;
  919. int err;
  920. if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
  921. return 0;
  922. err = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, -1,
  923. -1, -1, -1,
  924. !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
  925. if (unlikely(err))
  926. dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
  927. return err;
  928. }
  929. static int setup_debugfs(struct adapter *adap)
  930. {
  931. if (IS_ERR_OR_NULL(adap->debugfs_root))
  932. return -1;
  933. #ifdef CONFIG_DEBUG_FS
  934. t4_setup_debugfs(adap);
  935. #endif
  936. return 0;
  937. }
  938. /*
  939. * upper-layer driver support
  940. */
  941. /*
  942. * Allocate an active-open TID and set it to the supplied value.
  943. */
  944. int cxgb4_alloc_atid(struct tid_info *t, void *data)
  945. {
  946. int atid = -1;
  947. spin_lock_bh(&t->atid_lock);
  948. if (t->afree) {
  949. union aopen_entry *p = t->afree;
  950. atid = (p - t->atid_tab) + t->atid_base;
  951. t->afree = p->next;
  952. p->data = data;
  953. t->atids_in_use++;
  954. }
  955. spin_unlock_bh(&t->atid_lock);
  956. return atid;
  957. }
  958. EXPORT_SYMBOL(cxgb4_alloc_atid);
  959. /*
  960. * Release an active-open TID.
  961. */
  962. void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
  963. {
  964. union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
  965. spin_lock_bh(&t->atid_lock);
  966. p->next = t->afree;
  967. t->afree = p;
  968. t->atids_in_use--;
  969. spin_unlock_bh(&t->atid_lock);
  970. }
  971. EXPORT_SYMBOL(cxgb4_free_atid);
  972. /*
  973. * Allocate a server TID and set it to the supplied value.
  974. */
  975. int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
  976. {
  977. int stid;
  978. spin_lock_bh(&t->stid_lock);
  979. if (family == PF_INET) {
  980. stid = find_first_zero_bit(t->stid_bmap, t->nstids);
  981. if (stid < t->nstids)
  982. __set_bit(stid, t->stid_bmap);
  983. else
  984. stid = -1;
  985. } else {
  986. stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 1);
  987. if (stid < 0)
  988. stid = -1;
  989. }
  990. if (stid >= 0) {
  991. t->stid_tab[stid].data = data;
  992. stid += t->stid_base;
  993. /* IPv6 requires max of 520 bits or 16 cells in TCAM
  994. * This is equivalent to 4 TIDs. With CLIP enabled it
  995. * needs 2 TIDs.
  996. */
  997. if (family == PF_INET6) {
  998. t->stids_in_use += 2;
  999. t->v6_stids_in_use += 2;
  1000. } else {
  1001. t->stids_in_use++;
  1002. }
  1003. }
  1004. spin_unlock_bh(&t->stid_lock);
  1005. return stid;
  1006. }
  1007. EXPORT_SYMBOL(cxgb4_alloc_stid);
  1008. /* Allocate a server filter TID and set it to the supplied value.
  1009. */
  1010. int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
  1011. {
  1012. int stid;
  1013. spin_lock_bh(&t->stid_lock);
  1014. if (family == PF_INET) {
  1015. stid = find_next_zero_bit(t->stid_bmap,
  1016. t->nstids + t->nsftids, t->nstids);
  1017. if (stid < (t->nstids + t->nsftids))
  1018. __set_bit(stid, t->stid_bmap);
  1019. else
  1020. stid = -1;
  1021. } else {
  1022. stid = -1;
  1023. }
  1024. if (stid >= 0) {
  1025. t->stid_tab[stid].data = data;
  1026. stid -= t->nstids;
  1027. stid += t->sftid_base;
  1028. t->sftids_in_use++;
  1029. }
  1030. spin_unlock_bh(&t->stid_lock);
  1031. return stid;
  1032. }
  1033. EXPORT_SYMBOL(cxgb4_alloc_sftid);
  1034. /* Release a server TID.
  1035. */
  1036. void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
  1037. {
  1038. /* Is it a server filter TID? */
  1039. if (t->nsftids && (stid >= t->sftid_base)) {
  1040. stid -= t->sftid_base;
  1041. stid += t->nstids;
  1042. } else {
  1043. stid -= t->stid_base;
  1044. }
  1045. spin_lock_bh(&t->stid_lock);
  1046. if (family == PF_INET)
  1047. __clear_bit(stid, t->stid_bmap);
  1048. else
  1049. bitmap_release_region(t->stid_bmap, stid, 1);
  1050. t->stid_tab[stid].data = NULL;
  1051. if (stid < t->nstids) {
  1052. if (family == PF_INET6) {
  1053. t->stids_in_use -= 2;
  1054. t->v6_stids_in_use -= 2;
  1055. } else {
  1056. t->stids_in_use--;
  1057. }
  1058. } else {
  1059. t->sftids_in_use--;
  1060. }
  1061. spin_unlock_bh(&t->stid_lock);
  1062. }
  1063. EXPORT_SYMBOL(cxgb4_free_stid);
  1064. /*
  1065. * Populate a TID_RELEASE WR. Caller must properly size the skb.
  1066. */
  1067. static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
  1068. unsigned int tid)
  1069. {
  1070. struct cpl_tid_release *req;
  1071. set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
  1072. req = __skb_put(skb, sizeof(*req));
  1073. INIT_TP_WR(req, tid);
  1074. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  1075. }
  1076. /*
  1077. * Queue a TID release request and if necessary schedule a work queue to
  1078. * process it.
  1079. */
  1080. static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
  1081. unsigned int tid)
  1082. {
  1083. void **p = &t->tid_tab[tid];
  1084. struct adapter *adap = container_of(t, struct adapter, tids);
  1085. spin_lock_bh(&adap->tid_release_lock);
  1086. *p = adap->tid_release_head;
  1087. /* Low 2 bits encode the Tx channel number */
  1088. adap->tid_release_head = (void **)((uintptr_t)p | chan);
  1089. if (!adap->tid_release_task_busy) {
  1090. adap->tid_release_task_busy = true;
  1091. queue_work(adap->workq, &adap->tid_release_task);
  1092. }
  1093. spin_unlock_bh(&adap->tid_release_lock);
  1094. }
  1095. /*
  1096. * Process the list of pending TID release requests.
  1097. */
  1098. static void process_tid_release_list(struct work_struct *work)
  1099. {
  1100. struct sk_buff *skb;
  1101. struct adapter *adap;
  1102. adap = container_of(work, struct adapter, tid_release_task);
  1103. spin_lock_bh(&adap->tid_release_lock);
  1104. while (adap->tid_release_head) {
  1105. void **p = adap->tid_release_head;
  1106. unsigned int chan = (uintptr_t)p & 3;
  1107. p = (void *)p - chan;
  1108. adap->tid_release_head = *p;
  1109. *p = NULL;
  1110. spin_unlock_bh(&adap->tid_release_lock);
  1111. while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
  1112. GFP_KERNEL)))
  1113. schedule_timeout_uninterruptible(1);
  1114. mk_tid_release(skb, chan, p - adap->tids.tid_tab);
  1115. t4_ofld_send(adap, skb);
  1116. spin_lock_bh(&adap->tid_release_lock);
  1117. }
  1118. adap->tid_release_task_busy = false;
  1119. spin_unlock_bh(&adap->tid_release_lock);
  1120. }
  1121. /*
  1122. * Release a TID and inform HW. If we are unable to allocate the release
  1123. * message we defer to a work queue.
  1124. */
  1125. void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
  1126. unsigned short family)
  1127. {
  1128. struct sk_buff *skb;
  1129. struct adapter *adap = container_of(t, struct adapter, tids);
  1130. WARN_ON(tid >= t->ntids);
  1131. if (t->tid_tab[tid]) {
  1132. t->tid_tab[tid] = NULL;
  1133. atomic_dec(&t->conns_in_use);
  1134. if (t->hash_base && (tid >= t->hash_base)) {
  1135. if (family == AF_INET6)
  1136. atomic_sub(2, &t->hash_tids_in_use);
  1137. else
  1138. atomic_dec(&t->hash_tids_in_use);
  1139. } else {
  1140. if (family == AF_INET6)
  1141. atomic_sub(2, &t->tids_in_use);
  1142. else
  1143. atomic_dec(&t->tids_in_use);
  1144. }
  1145. }
  1146. skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
  1147. if (likely(skb)) {
  1148. mk_tid_release(skb, chan, tid);
  1149. t4_ofld_send(adap, skb);
  1150. } else
  1151. cxgb4_queue_tid_release(t, chan, tid);
  1152. }
  1153. EXPORT_SYMBOL(cxgb4_remove_tid);
  1154. /*
  1155. * Allocate and initialize the TID tables. Returns 0 on success.
  1156. */
  1157. static int tid_init(struct tid_info *t)
  1158. {
  1159. struct adapter *adap = container_of(t, struct adapter, tids);
  1160. unsigned int max_ftids = t->nftids + t->nsftids;
  1161. unsigned int natids = t->natids;
  1162. unsigned int stid_bmap_size;
  1163. unsigned int ftid_bmap_size;
  1164. size_t size;
  1165. stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
  1166. ftid_bmap_size = BITS_TO_LONGS(t->nftids);
  1167. size = t->ntids * sizeof(*t->tid_tab) +
  1168. natids * sizeof(*t->atid_tab) +
  1169. t->nstids * sizeof(*t->stid_tab) +
  1170. t->nsftids * sizeof(*t->stid_tab) +
  1171. stid_bmap_size * sizeof(long) +
  1172. max_ftids * sizeof(*t->ftid_tab) +
  1173. ftid_bmap_size * sizeof(long);
  1174. t->tid_tab = kvzalloc(size, GFP_KERNEL);
  1175. if (!t->tid_tab)
  1176. return -ENOMEM;
  1177. t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
  1178. t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
  1179. t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
  1180. t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
  1181. t->ftid_bmap = (unsigned long *)&t->ftid_tab[max_ftids];
  1182. spin_lock_init(&t->stid_lock);
  1183. spin_lock_init(&t->atid_lock);
  1184. spin_lock_init(&t->ftid_lock);
  1185. t->stids_in_use = 0;
  1186. t->v6_stids_in_use = 0;
  1187. t->sftids_in_use = 0;
  1188. t->afree = NULL;
  1189. t->atids_in_use = 0;
  1190. atomic_set(&t->tids_in_use, 0);
  1191. atomic_set(&t->conns_in_use, 0);
  1192. atomic_set(&t->hash_tids_in_use, 0);
  1193. /* Setup the free list for atid_tab and clear the stid bitmap. */
  1194. if (natids) {
  1195. while (--natids)
  1196. t->atid_tab[natids - 1].next = &t->atid_tab[natids];
  1197. t->afree = t->atid_tab;
  1198. }
  1199. if (is_offload(adap)) {
  1200. bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
  1201. /* Reserve stid 0 for T4/T5 adapters */
  1202. if (!t->stid_base &&
  1203. CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1204. __set_bit(0, t->stid_bmap);
  1205. }
  1206. bitmap_zero(t->ftid_bmap, t->nftids);
  1207. return 0;
  1208. }
  1209. /**
  1210. * cxgb4_create_server - create an IP server
  1211. * @dev: the device
  1212. * @stid: the server TID
  1213. * @sip: local IP address to bind server to
  1214. * @sport: the server's TCP port
  1215. * @queue: queue to direct messages from this server to
  1216. *
  1217. * Create an IP server for the given port and address.
  1218. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1219. */
  1220. int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
  1221. __be32 sip, __be16 sport, __be16 vlan,
  1222. unsigned int queue)
  1223. {
  1224. unsigned int chan;
  1225. struct sk_buff *skb;
  1226. struct adapter *adap;
  1227. struct cpl_pass_open_req *req;
  1228. int ret;
  1229. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1230. if (!skb)
  1231. return -ENOMEM;
  1232. adap = netdev2adap(dev);
  1233. req = __skb_put(skb, sizeof(*req));
  1234. INIT_TP_WR(req, 0);
  1235. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
  1236. req->local_port = sport;
  1237. req->peer_port = htons(0);
  1238. req->local_ip = sip;
  1239. req->peer_ip = htonl(0);
  1240. chan = rxq_to_chan(&adap->sge, queue);
  1241. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1242. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1243. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1244. ret = t4_mgmt_tx(adap, skb);
  1245. return net_xmit_eval(ret);
  1246. }
  1247. EXPORT_SYMBOL(cxgb4_create_server);
  1248. /* cxgb4_create_server6 - create an IPv6 server
  1249. * @dev: the device
  1250. * @stid: the server TID
  1251. * @sip: local IPv6 address to bind server to
  1252. * @sport: the server's TCP port
  1253. * @queue: queue to direct messages from this server to
  1254. *
  1255. * Create an IPv6 server for the given port and address.
  1256. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1257. */
  1258. int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
  1259. const struct in6_addr *sip, __be16 sport,
  1260. unsigned int queue)
  1261. {
  1262. unsigned int chan;
  1263. struct sk_buff *skb;
  1264. struct adapter *adap;
  1265. struct cpl_pass_open_req6 *req;
  1266. int ret;
  1267. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1268. if (!skb)
  1269. return -ENOMEM;
  1270. adap = netdev2adap(dev);
  1271. req = __skb_put(skb, sizeof(*req));
  1272. INIT_TP_WR(req, 0);
  1273. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
  1274. req->local_port = sport;
  1275. req->peer_port = htons(0);
  1276. req->local_ip_hi = *(__be64 *)(sip->s6_addr);
  1277. req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
  1278. req->peer_ip_hi = cpu_to_be64(0);
  1279. req->peer_ip_lo = cpu_to_be64(0);
  1280. chan = rxq_to_chan(&adap->sge, queue);
  1281. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1282. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1283. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1284. ret = t4_mgmt_tx(adap, skb);
  1285. return net_xmit_eval(ret);
  1286. }
  1287. EXPORT_SYMBOL(cxgb4_create_server6);
  1288. int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
  1289. unsigned int queue, bool ipv6)
  1290. {
  1291. struct sk_buff *skb;
  1292. struct adapter *adap;
  1293. struct cpl_close_listsvr_req *req;
  1294. int ret;
  1295. adap = netdev2adap(dev);
  1296. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1297. if (!skb)
  1298. return -ENOMEM;
  1299. req = __skb_put(skb, sizeof(*req));
  1300. INIT_TP_WR(req, 0);
  1301. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
  1302. req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
  1303. LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
  1304. ret = t4_mgmt_tx(adap, skb);
  1305. return net_xmit_eval(ret);
  1306. }
  1307. EXPORT_SYMBOL(cxgb4_remove_server);
  1308. /**
  1309. * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
  1310. * @mtus: the HW MTU table
  1311. * @mtu: the target MTU
  1312. * @idx: index of selected entry in the MTU table
  1313. *
  1314. * Returns the index and the value in the HW MTU table that is closest to
  1315. * but does not exceed @mtu, unless @mtu is smaller than any value in the
  1316. * table, in which case that smallest available value is selected.
  1317. */
  1318. unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
  1319. unsigned int *idx)
  1320. {
  1321. unsigned int i = 0;
  1322. while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
  1323. ++i;
  1324. if (idx)
  1325. *idx = i;
  1326. return mtus[i];
  1327. }
  1328. EXPORT_SYMBOL(cxgb4_best_mtu);
  1329. /**
  1330. * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
  1331. * @mtus: the HW MTU table
  1332. * @header_size: Header Size
  1333. * @data_size_max: maximum Data Segment Size
  1334. * @data_size_align: desired Data Segment Size Alignment (2^N)
  1335. * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
  1336. *
  1337. * Similar to cxgb4_best_mtu() but instead of searching the Hardware
  1338. * MTU Table based solely on a Maximum MTU parameter, we break that
  1339. * parameter up into a Header Size and Maximum Data Segment Size, and
  1340. * provide a desired Data Segment Size Alignment. If we find an MTU in
  1341. * the Hardware MTU Table which will result in a Data Segment Size with
  1342. * the requested alignment _and_ that MTU isn't "too far" from the
  1343. * closest MTU, then we'll return that rather than the closest MTU.
  1344. */
  1345. unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
  1346. unsigned short header_size,
  1347. unsigned short data_size_max,
  1348. unsigned short data_size_align,
  1349. unsigned int *mtu_idxp)
  1350. {
  1351. unsigned short max_mtu = header_size + data_size_max;
  1352. unsigned short data_size_align_mask = data_size_align - 1;
  1353. int mtu_idx, aligned_mtu_idx;
  1354. /* Scan the MTU Table till we find an MTU which is larger than our
  1355. * Maximum MTU or we reach the end of the table. Along the way,
  1356. * record the last MTU found, if any, which will result in a Data
  1357. * Segment Length matching the requested alignment.
  1358. */
  1359. for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
  1360. unsigned short data_size = mtus[mtu_idx] - header_size;
  1361. /* If this MTU minus the Header Size would result in a
  1362. * Data Segment Size of the desired alignment, remember it.
  1363. */
  1364. if ((data_size & data_size_align_mask) == 0)
  1365. aligned_mtu_idx = mtu_idx;
  1366. /* If we're not at the end of the Hardware MTU Table and the
  1367. * next element is larger than our Maximum MTU, drop out of
  1368. * the loop.
  1369. */
  1370. if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
  1371. break;
  1372. }
  1373. /* If we fell out of the loop because we ran to the end of the table,
  1374. * then we just have to use the last [largest] entry.
  1375. */
  1376. if (mtu_idx == NMTUS)
  1377. mtu_idx--;
  1378. /* If we found an MTU which resulted in the requested Data Segment
  1379. * Length alignment and that's "not far" from the largest MTU which is
  1380. * less than or equal to the maximum MTU, then use that.
  1381. */
  1382. if (aligned_mtu_idx >= 0 &&
  1383. mtu_idx - aligned_mtu_idx <= 1)
  1384. mtu_idx = aligned_mtu_idx;
  1385. /* If the caller has passed in an MTU Index pointer, pass the
  1386. * MTU Index back. Return the MTU value.
  1387. */
  1388. if (mtu_idxp)
  1389. *mtu_idxp = mtu_idx;
  1390. return mtus[mtu_idx];
  1391. }
  1392. EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
  1393. /**
  1394. * cxgb4_tp_smt_idx - Get the Source Mac Table index for this VI
  1395. * @chip: chip type
  1396. * @viid: VI id of the given port
  1397. *
  1398. * Return the SMT index for this VI.
  1399. */
  1400. unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid)
  1401. {
  1402. /* In T4/T5, SMT contains 256 SMAC entries organized in
  1403. * 128 rows of 2 entries each.
  1404. * In T6, SMT contains 256 SMAC entries in 256 rows.
  1405. * TODO: The below code needs to be updated when we add support
  1406. * for 256 VFs.
  1407. */
  1408. if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5)
  1409. return ((viid & 0x7f) << 1);
  1410. else
  1411. return (viid & 0x7f);
  1412. }
  1413. EXPORT_SYMBOL(cxgb4_tp_smt_idx);
  1414. /**
  1415. * cxgb4_port_chan - get the HW channel of a port
  1416. * @dev: the net device for the port
  1417. *
  1418. * Return the HW Tx channel of the given port.
  1419. */
  1420. unsigned int cxgb4_port_chan(const struct net_device *dev)
  1421. {
  1422. return netdev2pinfo(dev)->tx_chan;
  1423. }
  1424. EXPORT_SYMBOL(cxgb4_port_chan);
  1425. unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
  1426. {
  1427. struct adapter *adap = netdev2adap(dev);
  1428. u32 v1, v2, lp_count, hp_count;
  1429. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1430. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1431. if (is_t4(adap->params.chip)) {
  1432. lp_count = LP_COUNT_G(v1);
  1433. hp_count = HP_COUNT_G(v1);
  1434. } else {
  1435. lp_count = LP_COUNT_T5_G(v1);
  1436. hp_count = HP_COUNT_T5_G(v2);
  1437. }
  1438. return lpfifo ? lp_count : hp_count;
  1439. }
  1440. EXPORT_SYMBOL(cxgb4_dbfifo_count);
  1441. /**
  1442. * cxgb4_port_viid - get the VI id of a port
  1443. * @dev: the net device for the port
  1444. *
  1445. * Return the VI id of the given port.
  1446. */
  1447. unsigned int cxgb4_port_viid(const struct net_device *dev)
  1448. {
  1449. return netdev2pinfo(dev)->viid;
  1450. }
  1451. EXPORT_SYMBOL(cxgb4_port_viid);
  1452. /**
  1453. * cxgb4_port_idx - get the index of a port
  1454. * @dev: the net device for the port
  1455. *
  1456. * Return the index of the given port.
  1457. */
  1458. unsigned int cxgb4_port_idx(const struct net_device *dev)
  1459. {
  1460. return netdev2pinfo(dev)->port_id;
  1461. }
  1462. EXPORT_SYMBOL(cxgb4_port_idx);
  1463. void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
  1464. struct tp_tcp_stats *v6)
  1465. {
  1466. struct adapter *adap = pci_get_drvdata(pdev);
  1467. spin_lock(&adap->stats_lock);
  1468. t4_tp_get_tcp_stats(adap, v4, v6, false);
  1469. spin_unlock(&adap->stats_lock);
  1470. }
  1471. EXPORT_SYMBOL(cxgb4_get_tcp_stats);
  1472. void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
  1473. const unsigned int *pgsz_order)
  1474. {
  1475. struct adapter *adap = netdev2adap(dev);
  1476. t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
  1477. t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
  1478. HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
  1479. HPZ3_V(pgsz_order[3]));
  1480. }
  1481. EXPORT_SYMBOL(cxgb4_iscsi_init);
  1482. int cxgb4_flush_eq_cache(struct net_device *dev)
  1483. {
  1484. struct adapter *adap = netdev2adap(dev);
  1485. return t4_sge_ctxt_flush(adap, adap->mbox, CTXT_EGRESS);
  1486. }
  1487. EXPORT_SYMBOL(cxgb4_flush_eq_cache);
  1488. static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
  1489. {
  1490. u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
  1491. __be64 indices;
  1492. int ret;
  1493. spin_lock(&adap->win0_lock);
  1494. ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
  1495. sizeof(indices), (__be32 *)&indices,
  1496. T4_MEMORY_READ);
  1497. spin_unlock(&adap->win0_lock);
  1498. if (!ret) {
  1499. *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
  1500. *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
  1501. }
  1502. return ret;
  1503. }
  1504. int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
  1505. u16 size)
  1506. {
  1507. struct adapter *adap = netdev2adap(dev);
  1508. u16 hw_pidx, hw_cidx;
  1509. int ret;
  1510. ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
  1511. if (ret)
  1512. goto out;
  1513. if (pidx != hw_pidx) {
  1514. u16 delta;
  1515. u32 val;
  1516. if (pidx >= hw_pidx)
  1517. delta = pidx - hw_pidx;
  1518. else
  1519. delta = size - hw_pidx + pidx;
  1520. if (is_t4(adap->params.chip))
  1521. val = PIDX_V(delta);
  1522. else
  1523. val = PIDX_T5_V(delta);
  1524. wmb();
  1525. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1526. QID_V(qid) | val);
  1527. }
  1528. out:
  1529. return ret;
  1530. }
  1531. EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
  1532. int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
  1533. {
  1534. u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
  1535. u32 edc0_end, edc1_end, mc0_end, mc1_end;
  1536. u32 offset, memtype, memaddr;
  1537. struct adapter *adap;
  1538. u32 hma_size = 0;
  1539. int ret;
  1540. adap = netdev2adap(dev);
  1541. offset = ((stag >> 8) * 32) + adap->vres.stag.start;
  1542. /* Figure out where the offset lands in the Memory Type/Address scheme.
  1543. * This code assumes that the memory is laid out starting at offset 0
  1544. * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
  1545. * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
  1546. * MC0, and some have both MC0 and MC1.
  1547. */
  1548. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  1549. edc0_size = EDRAM0_SIZE_G(size) << 20;
  1550. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  1551. edc1_size = EDRAM1_SIZE_G(size) << 20;
  1552. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  1553. mc0_size = EXT_MEM0_SIZE_G(size) << 20;
  1554. if (t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A) & HMA_MUX_F) {
  1555. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  1556. hma_size = EXT_MEM1_SIZE_G(size) << 20;
  1557. }
  1558. edc0_end = edc0_size;
  1559. edc1_end = edc0_end + edc1_size;
  1560. mc0_end = edc1_end + mc0_size;
  1561. if (offset < edc0_end) {
  1562. memtype = MEM_EDC0;
  1563. memaddr = offset;
  1564. } else if (offset < edc1_end) {
  1565. memtype = MEM_EDC1;
  1566. memaddr = offset - edc0_end;
  1567. } else {
  1568. if (hma_size && (offset < (edc1_end + hma_size))) {
  1569. memtype = MEM_HMA;
  1570. memaddr = offset - edc1_end;
  1571. } else if (offset < mc0_end) {
  1572. memtype = MEM_MC0;
  1573. memaddr = offset - edc1_end;
  1574. } else if (is_t5(adap->params.chip)) {
  1575. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  1576. mc1_size = EXT_MEM1_SIZE_G(size) << 20;
  1577. mc1_end = mc0_end + mc1_size;
  1578. if (offset < mc1_end) {
  1579. memtype = MEM_MC1;
  1580. memaddr = offset - mc0_end;
  1581. } else {
  1582. /* offset beyond the end of any memory */
  1583. goto err;
  1584. }
  1585. } else {
  1586. /* T4/T6 only has a single memory channel */
  1587. goto err;
  1588. }
  1589. }
  1590. spin_lock(&adap->win0_lock);
  1591. ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
  1592. spin_unlock(&adap->win0_lock);
  1593. return ret;
  1594. err:
  1595. dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
  1596. stag, offset);
  1597. return -EINVAL;
  1598. }
  1599. EXPORT_SYMBOL(cxgb4_read_tpte);
  1600. u64 cxgb4_read_sge_timestamp(struct net_device *dev)
  1601. {
  1602. u32 hi, lo;
  1603. struct adapter *adap;
  1604. adap = netdev2adap(dev);
  1605. lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
  1606. hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
  1607. return ((u64)hi << 32) | (u64)lo;
  1608. }
  1609. EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
  1610. int cxgb4_bar2_sge_qregs(struct net_device *dev,
  1611. unsigned int qid,
  1612. enum cxgb4_bar2_qtype qtype,
  1613. int user,
  1614. u64 *pbar2_qoffset,
  1615. unsigned int *pbar2_qid)
  1616. {
  1617. return t4_bar2_sge_qregs(netdev2adap(dev),
  1618. qid,
  1619. (qtype == CXGB4_BAR2_QTYPE_EGRESS
  1620. ? T4_BAR2_QTYPE_EGRESS
  1621. : T4_BAR2_QTYPE_INGRESS),
  1622. user,
  1623. pbar2_qoffset,
  1624. pbar2_qid);
  1625. }
  1626. EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
  1627. static struct pci_driver cxgb4_driver;
  1628. static void check_neigh_update(struct neighbour *neigh)
  1629. {
  1630. const struct device *parent;
  1631. const struct net_device *netdev = neigh->dev;
  1632. if (is_vlan_dev(netdev))
  1633. netdev = vlan_dev_real_dev(netdev);
  1634. parent = netdev->dev.parent;
  1635. if (parent && parent->driver == &cxgb4_driver.driver)
  1636. t4_l2t_update(dev_get_drvdata(parent), neigh);
  1637. }
  1638. static int netevent_cb(struct notifier_block *nb, unsigned long event,
  1639. void *data)
  1640. {
  1641. switch (event) {
  1642. case NETEVENT_NEIGH_UPDATE:
  1643. check_neigh_update(data);
  1644. break;
  1645. case NETEVENT_REDIRECT:
  1646. default:
  1647. break;
  1648. }
  1649. return 0;
  1650. }
  1651. static bool netevent_registered;
  1652. static struct notifier_block cxgb4_netevent_nb = {
  1653. .notifier_call = netevent_cb
  1654. };
  1655. static void drain_db_fifo(struct adapter *adap, int usecs)
  1656. {
  1657. u32 v1, v2, lp_count, hp_count;
  1658. do {
  1659. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1660. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1661. if (is_t4(adap->params.chip)) {
  1662. lp_count = LP_COUNT_G(v1);
  1663. hp_count = HP_COUNT_G(v1);
  1664. } else {
  1665. lp_count = LP_COUNT_T5_G(v1);
  1666. hp_count = HP_COUNT_T5_G(v2);
  1667. }
  1668. if (lp_count == 0 && hp_count == 0)
  1669. break;
  1670. set_current_state(TASK_UNINTERRUPTIBLE);
  1671. schedule_timeout(usecs_to_jiffies(usecs));
  1672. } while (1);
  1673. }
  1674. static void disable_txq_db(struct sge_txq *q)
  1675. {
  1676. unsigned long flags;
  1677. spin_lock_irqsave(&q->db_lock, flags);
  1678. q->db_disabled = 1;
  1679. spin_unlock_irqrestore(&q->db_lock, flags);
  1680. }
  1681. static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
  1682. {
  1683. spin_lock_irq(&q->db_lock);
  1684. if (q->db_pidx_inc) {
  1685. /* Make sure that all writes to the TX descriptors
  1686. * are committed before we tell HW about them.
  1687. */
  1688. wmb();
  1689. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1690. QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
  1691. q->db_pidx_inc = 0;
  1692. }
  1693. q->db_disabled = 0;
  1694. spin_unlock_irq(&q->db_lock);
  1695. }
  1696. static void disable_dbs(struct adapter *adap)
  1697. {
  1698. int i;
  1699. for_each_ethrxq(&adap->sge, i)
  1700. disable_txq_db(&adap->sge.ethtxq[i].q);
  1701. if (is_offload(adap)) {
  1702. struct sge_uld_txq_info *txq_info =
  1703. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1704. if (txq_info) {
  1705. for_each_ofldtxq(&adap->sge, i) {
  1706. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1707. disable_txq_db(&txq->q);
  1708. }
  1709. }
  1710. }
  1711. for_each_port(adap, i)
  1712. disable_txq_db(&adap->sge.ctrlq[i].q);
  1713. }
  1714. static void enable_dbs(struct adapter *adap)
  1715. {
  1716. int i;
  1717. for_each_ethrxq(&adap->sge, i)
  1718. enable_txq_db(adap, &adap->sge.ethtxq[i].q);
  1719. if (is_offload(adap)) {
  1720. struct sge_uld_txq_info *txq_info =
  1721. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1722. if (txq_info) {
  1723. for_each_ofldtxq(&adap->sge, i) {
  1724. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1725. enable_txq_db(adap, &txq->q);
  1726. }
  1727. }
  1728. }
  1729. for_each_port(adap, i)
  1730. enable_txq_db(adap, &adap->sge.ctrlq[i].q);
  1731. }
  1732. static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
  1733. {
  1734. enum cxgb4_uld type = CXGB4_ULD_RDMA;
  1735. if (adap->uld && adap->uld[type].handle)
  1736. adap->uld[type].control(adap->uld[type].handle, cmd);
  1737. }
  1738. static void process_db_full(struct work_struct *work)
  1739. {
  1740. struct adapter *adap;
  1741. adap = container_of(work, struct adapter, db_full_task);
  1742. drain_db_fifo(adap, dbfifo_drain_delay);
  1743. enable_dbs(adap);
  1744. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  1745. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1746. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1747. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
  1748. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
  1749. else
  1750. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1751. DBFIFO_LP_INT_F, DBFIFO_LP_INT_F);
  1752. }
  1753. static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
  1754. {
  1755. u16 hw_pidx, hw_cidx;
  1756. int ret;
  1757. spin_lock_irq(&q->db_lock);
  1758. ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
  1759. if (ret)
  1760. goto out;
  1761. if (q->db_pidx != hw_pidx) {
  1762. u16 delta;
  1763. u32 val;
  1764. if (q->db_pidx >= hw_pidx)
  1765. delta = q->db_pidx - hw_pidx;
  1766. else
  1767. delta = q->size - hw_pidx + q->db_pidx;
  1768. if (is_t4(adap->params.chip))
  1769. val = PIDX_V(delta);
  1770. else
  1771. val = PIDX_T5_V(delta);
  1772. wmb();
  1773. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1774. QID_V(q->cntxt_id) | val);
  1775. }
  1776. out:
  1777. q->db_disabled = 0;
  1778. q->db_pidx_inc = 0;
  1779. spin_unlock_irq(&q->db_lock);
  1780. if (ret)
  1781. CH_WARN(adap, "DB drop recovery failed.\n");
  1782. }
  1783. static void recover_all_queues(struct adapter *adap)
  1784. {
  1785. int i;
  1786. for_each_ethrxq(&adap->sge, i)
  1787. sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
  1788. if (is_offload(adap)) {
  1789. struct sge_uld_txq_info *txq_info =
  1790. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1791. if (txq_info) {
  1792. for_each_ofldtxq(&adap->sge, i) {
  1793. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1794. sync_txq_pidx(adap, &txq->q);
  1795. }
  1796. }
  1797. }
  1798. for_each_port(adap, i)
  1799. sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
  1800. }
  1801. static void process_db_drop(struct work_struct *work)
  1802. {
  1803. struct adapter *adap;
  1804. adap = container_of(work, struct adapter, db_drop_task);
  1805. if (is_t4(adap->params.chip)) {
  1806. drain_db_fifo(adap, dbfifo_drain_delay);
  1807. notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
  1808. drain_db_fifo(adap, dbfifo_drain_delay);
  1809. recover_all_queues(adap);
  1810. drain_db_fifo(adap, dbfifo_drain_delay);
  1811. enable_dbs(adap);
  1812. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  1813. } else if (is_t5(adap->params.chip)) {
  1814. u32 dropped_db = t4_read_reg(adap, 0x010ac);
  1815. u16 qid = (dropped_db >> 15) & 0x1ffff;
  1816. u16 pidx_inc = dropped_db & 0x1fff;
  1817. u64 bar2_qoffset;
  1818. unsigned int bar2_qid;
  1819. int ret;
  1820. ret = t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
  1821. 0, &bar2_qoffset, &bar2_qid);
  1822. if (ret)
  1823. dev_err(adap->pdev_dev, "doorbell drop recovery: "
  1824. "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
  1825. else
  1826. writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
  1827. adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
  1828. /* Re-enable BAR2 WC */
  1829. t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
  1830. }
  1831. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1832. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
  1833. }
  1834. void t4_db_full(struct adapter *adap)
  1835. {
  1836. if (is_t4(adap->params.chip)) {
  1837. disable_dbs(adap);
  1838. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  1839. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1840. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
  1841. queue_work(adap->workq, &adap->db_full_task);
  1842. }
  1843. }
  1844. void t4_db_dropped(struct adapter *adap)
  1845. {
  1846. if (is_t4(adap->params.chip)) {
  1847. disable_dbs(adap);
  1848. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  1849. }
  1850. queue_work(adap->workq, &adap->db_drop_task);
  1851. }
  1852. void t4_register_netevent_notifier(void)
  1853. {
  1854. if (!netevent_registered) {
  1855. register_netevent_notifier(&cxgb4_netevent_nb);
  1856. netevent_registered = true;
  1857. }
  1858. }
  1859. static void detach_ulds(struct adapter *adap)
  1860. {
  1861. unsigned int i;
  1862. mutex_lock(&uld_mutex);
  1863. list_del(&adap->list_node);
  1864. for (i = 0; i < CXGB4_ULD_MAX; i++)
  1865. if (adap->uld && adap->uld[i].handle)
  1866. adap->uld[i].state_change(adap->uld[i].handle,
  1867. CXGB4_STATE_DETACH);
  1868. if (netevent_registered && list_empty(&adapter_list)) {
  1869. unregister_netevent_notifier(&cxgb4_netevent_nb);
  1870. netevent_registered = false;
  1871. }
  1872. mutex_unlock(&uld_mutex);
  1873. }
  1874. static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
  1875. {
  1876. unsigned int i;
  1877. mutex_lock(&uld_mutex);
  1878. for (i = 0; i < CXGB4_ULD_MAX; i++)
  1879. if (adap->uld && adap->uld[i].handle)
  1880. adap->uld[i].state_change(adap->uld[i].handle,
  1881. new_state);
  1882. mutex_unlock(&uld_mutex);
  1883. }
  1884. #if IS_ENABLED(CONFIG_IPV6)
  1885. static int cxgb4_inet6addr_handler(struct notifier_block *this,
  1886. unsigned long event, void *data)
  1887. {
  1888. struct inet6_ifaddr *ifa = data;
  1889. struct net_device *event_dev = ifa->idev->dev;
  1890. const struct device *parent = NULL;
  1891. #if IS_ENABLED(CONFIG_BONDING)
  1892. struct adapter *adap;
  1893. #endif
  1894. if (is_vlan_dev(event_dev))
  1895. event_dev = vlan_dev_real_dev(event_dev);
  1896. #if IS_ENABLED(CONFIG_BONDING)
  1897. if (event_dev->flags & IFF_MASTER) {
  1898. list_for_each_entry(adap, &adapter_list, list_node) {
  1899. switch (event) {
  1900. case NETDEV_UP:
  1901. cxgb4_clip_get(adap->port[0],
  1902. (const u32 *)ifa, 1);
  1903. break;
  1904. case NETDEV_DOWN:
  1905. cxgb4_clip_release(adap->port[0],
  1906. (const u32 *)ifa, 1);
  1907. break;
  1908. default:
  1909. break;
  1910. }
  1911. }
  1912. return NOTIFY_OK;
  1913. }
  1914. #endif
  1915. if (event_dev)
  1916. parent = event_dev->dev.parent;
  1917. if (parent && parent->driver == &cxgb4_driver.driver) {
  1918. switch (event) {
  1919. case NETDEV_UP:
  1920. cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
  1921. break;
  1922. case NETDEV_DOWN:
  1923. cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
  1924. break;
  1925. default:
  1926. break;
  1927. }
  1928. }
  1929. return NOTIFY_OK;
  1930. }
  1931. static bool inet6addr_registered;
  1932. static struct notifier_block cxgb4_inet6addr_notifier = {
  1933. .notifier_call = cxgb4_inet6addr_handler
  1934. };
  1935. static void update_clip(const struct adapter *adap)
  1936. {
  1937. int i;
  1938. struct net_device *dev;
  1939. int ret;
  1940. rcu_read_lock();
  1941. for (i = 0; i < MAX_NPORTS; i++) {
  1942. dev = adap->port[i];
  1943. ret = 0;
  1944. if (dev)
  1945. ret = cxgb4_update_root_dev_clip(dev);
  1946. if (ret < 0)
  1947. break;
  1948. }
  1949. rcu_read_unlock();
  1950. }
  1951. #endif /* IS_ENABLED(CONFIG_IPV6) */
  1952. /**
  1953. * cxgb_up - enable the adapter
  1954. * @adap: adapter being enabled
  1955. *
  1956. * Called when the first port is enabled, this function performs the
  1957. * actions necessary to make an adapter operational, such as completing
  1958. * the initialization of HW modules, and enabling interrupts.
  1959. *
  1960. * Must be called with the rtnl lock held.
  1961. */
  1962. static int cxgb_up(struct adapter *adap)
  1963. {
  1964. int err;
  1965. mutex_lock(&uld_mutex);
  1966. err = setup_sge_queues(adap);
  1967. if (err)
  1968. goto rel_lock;
  1969. err = setup_rss(adap);
  1970. if (err)
  1971. goto freeq;
  1972. if (adap->flags & USING_MSIX) {
  1973. name_msix_vecs(adap);
  1974. err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
  1975. adap->msix_info[0].desc, adap);
  1976. if (err)
  1977. goto irq_err;
  1978. err = request_msix_queue_irqs(adap);
  1979. if (err) {
  1980. free_irq(adap->msix_info[0].vec, adap);
  1981. goto irq_err;
  1982. }
  1983. } else {
  1984. err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
  1985. (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
  1986. adap->port[0]->name, adap);
  1987. if (err)
  1988. goto irq_err;
  1989. }
  1990. enable_rx(adap);
  1991. t4_sge_start(adap);
  1992. t4_intr_enable(adap);
  1993. adap->flags |= FULL_INIT_DONE;
  1994. mutex_unlock(&uld_mutex);
  1995. notify_ulds(adap, CXGB4_STATE_UP);
  1996. #if IS_ENABLED(CONFIG_IPV6)
  1997. update_clip(adap);
  1998. #endif
  1999. /* Initialize hash mac addr list*/
  2000. INIT_LIST_HEAD(&adap->mac_hlist);
  2001. return err;
  2002. irq_err:
  2003. dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
  2004. freeq:
  2005. t4_free_sge_resources(adap);
  2006. rel_lock:
  2007. mutex_unlock(&uld_mutex);
  2008. return err;
  2009. }
  2010. static void cxgb_down(struct adapter *adapter)
  2011. {
  2012. cancel_work_sync(&adapter->tid_release_task);
  2013. cancel_work_sync(&adapter->db_full_task);
  2014. cancel_work_sync(&adapter->db_drop_task);
  2015. adapter->tid_release_task_busy = false;
  2016. adapter->tid_release_head = NULL;
  2017. t4_sge_stop(adapter);
  2018. t4_free_sge_resources(adapter);
  2019. adapter->flags &= ~FULL_INIT_DONE;
  2020. }
  2021. /*
  2022. * net_device operations
  2023. */
  2024. static int cxgb_open(struct net_device *dev)
  2025. {
  2026. int err;
  2027. struct port_info *pi = netdev_priv(dev);
  2028. struct adapter *adapter = pi->adapter;
  2029. netif_carrier_off(dev);
  2030. if (!(adapter->flags & FULL_INIT_DONE)) {
  2031. err = cxgb_up(adapter);
  2032. if (err < 0)
  2033. return err;
  2034. }
  2035. /* It's possible that the basic port information could have
  2036. * changed since we first read it.
  2037. */
  2038. err = t4_update_port_info(pi);
  2039. if (err < 0)
  2040. return err;
  2041. err = link_start(dev);
  2042. if (!err)
  2043. netif_tx_start_all_queues(dev);
  2044. return err;
  2045. }
  2046. static int cxgb_close(struct net_device *dev)
  2047. {
  2048. struct port_info *pi = netdev_priv(dev);
  2049. struct adapter *adapter = pi->adapter;
  2050. int ret;
  2051. netif_tx_stop_all_queues(dev);
  2052. netif_carrier_off(dev);
  2053. ret = t4_enable_pi_params(adapter, adapter->pf, pi,
  2054. false, false, false);
  2055. #ifdef CONFIG_CHELSIO_T4_DCB
  2056. cxgb4_dcb_reset(dev);
  2057. dcb_tx_queue_prio_enable(dev, false);
  2058. #endif
  2059. return ret;
  2060. }
  2061. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  2062. __be32 sip, __be16 sport, __be16 vlan,
  2063. unsigned int queue, unsigned char port, unsigned char mask)
  2064. {
  2065. int ret;
  2066. struct filter_entry *f;
  2067. struct adapter *adap;
  2068. int i;
  2069. u8 *val;
  2070. adap = netdev2adap(dev);
  2071. /* Adjust stid to correct filter index */
  2072. stid -= adap->tids.sftid_base;
  2073. stid += adap->tids.nftids;
  2074. /* Check to make sure the filter requested is writable ...
  2075. */
  2076. f = &adap->tids.ftid_tab[stid];
  2077. ret = writable_filter(f);
  2078. if (ret)
  2079. return ret;
  2080. /* Clear out any old resources being used by the filter before
  2081. * we start constructing the new filter.
  2082. */
  2083. if (f->valid)
  2084. clear_filter(adap, f);
  2085. /* Clear out filter specifications */
  2086. memset(&f->fs, 0, sizeof(struct ch_filter_specification));
  2087. f->fs.val.lport = cpu_to_be16(sport);
  2088. f->fs.mask.lport = ~0;
  2089. val = (u8 *)&sip;
  2090. if ((val[0] | val[1] | val[2] | val[3]) != 0) {
  2091. for (i = 0; i < 4; i++) {
  2092. f->fs.val.lip[i] = val[i];
  2093. f->fs.mask.lip[i] = ~0;
  2094. }
  2095. if (adap->params.tp.vlan_pri_map & PORT_F) {
  2096. f->fs.val.iport = port;
  2097. f->fs.mask.iport = mask;
  2098. }
  2099. }
  2100. if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
  2101. f->fs.val.proto = IPPROTO_TCP;
  2102. f->fs.mask.proto = ~0;
  2103. }
  2104. f->fs.dirsteer = 1;
  2105. f->fs.iq = queue;
  2106. /* Mark filter as locked */
  2107. f->locked = 1;
  2108. f->fs.rpttid = 1;
  2109. /* Save the actual tid. We need this to get the corresponding
  2110. * filter entry structure in filter_rpl.
  2111. */
  2112. f->tid = stid + adap->tids.ftid_base;
  2113. ret = set_filter_wr(adap, stid);
  2114. if (ret) {
  2115. clear_filter(adap, f);
  2116. return ret;
  2117. }
  2118. return 0;
  2119. }
  2120. EXPORT_SYMBOL(cxgb4_create_server_filter);
  2121. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  2122. unsigned int queue, bool ipv6)
  2123. {
  2124. struct filter_entry *f;
  2125. struct adapter *adap;
  2126. adap = netdev2adap(dev);
  2127. /* Adjust stid to correct filter index */
  2128. stid -= adap->tids.sftid_base;
  2129. stid += adap->tids.nftids;
  2130. f = &adap->tids.ftid_tab[stid];
  2131. /* Unlock the filter */
  2132. f->locked = 0;
  2133. return delete_filter(adap, stid);
  2134. }
  2135. EXPORT_SYMBOL(cxgb4_remove_server_filter);
  2136. static void cxgb_get_stats(struct net_device *dev,
  2137. struct rtnl_link_stats64 *ns)
  2138. {
  2139. struct port_stats stats;
  2140. struct port_info *p = netdev_priv(dev);
  2141. struct adapter *adapter = p->adapter;
  2142. /* Block retrieving statistics during EEH error
  2143. * recovery. Otherwise, the recovery might fail
  2144. * and the PCI device will be removed permanently
  2145. */
  2146. spin_lock(&adapter->stats_lock);
  2147. if (!netif_device_present(dev)) {
  2148. spin_unlock(&adapter->stats_lock);
  2149. return;
  2150. }
  2151. t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
  2152. &p->stats_base);
  2153. spin_unlock(&adapter->stats_lock);
  2154. ns->tx_bytes = stats.tx_octets;
  2155. ns->tx_packets = stats.tx_frames;
  2156. ns->rx_bytes = stats.rx_octets;
  2157. ns->rx_packets = stats.rx_frames;
  2158. ns->multicast = stats.rx_mcast_frames;
  2159. /* detailed rx_errors */
  2160. ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
  2161. stats.rx_runt;
  2162. ns->rx_over_errors = 0;
  2163. ns->rx_crc_errors = stats.rx_fcs_err;
  2164. ns->rx_frame_errors = stats.rx_symbol_err;
  2165. ns->rx_dropped = stats.rx_ovflow0 + stats.rx_ovflow1 +
  2166. stats.rx_ovflow2 + stats.rx_ovflow3 +
  2167. stats.rx_trunc0 + stats.rx_trunc1 +
  2168. stats.rx_trunc2 + stats.rx_trunc3;
  2169. ns->rx_missed_errors = 0;
  2170. /* detailed tx_errors */
  2171. ns->tx_aborted_errors = 0;
  2172. ns->tx_carrier_errors = 0;
  2173. ns->tx_fifo_errors = 0;
  2174. ns->tx_heartbeat_errors = 0;
  2175. ns->tx_window_errors = 0;
  2176. ns->tx_errors = stats.tx_error_frames;
  2177. ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
  2178. ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
  2179. }
  2180. static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  2181. {
  2182. unsigned int mbox;
  2183. int ret = 0, prtad, devad;
  2184. struct port_info *pi = netdev_priv(dev);
  2185. struct adapter *adapter = pi->adapter;
  2186. struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
  2187. switch (cmd) {
  2188. case SIOCGMIIPHY:
  2189. if (pi->mdio_addr < 0)
  2190. return -EOPNOTSUPP;
  2191. data->phy_id = pi->mdio_addr;
  2192. break;
  2193. case SIOCGMIIREG:
  2194. case SIOCSMIIREG:
  2195. if (mdio_phy_id_is_c45(data->phy_id)) {
  2196. prtad = mdio_phy_id_prtad(data->phy_id);
  2197. devad = mdio_phy_id_devad(data->phy_id);
  2198. } else if (data->phy_id < 32) {
  2199. prtad = data->phy_id;
  2200. devad = 0;
  2201. data->reg_num &= 0x1f;
  2202. } else
  2203. return -EINVAL;
  2204. mbox = pi->adapter->pf;
  2205. if (cmd == SIOCGMIIREG)
  2206. ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
  2207. data->reg_num, &data->val_out);
  2208. else
  2209. ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
  2210. data->reg_num, data->val_in);
  2211. break;
  2212. case SIOCGHWTSTAMP:
  2213. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2214. sizeof(pi->tstamp_config)) ?
  2215. -EFAULT : 0;
  2216. case SIOCSHWTSTAMP:
  2217. if (copy_from_user(&pi->tstamp_config, req->ifr_data,
  2218. sizeof(pi->tstamp_config)))
  2219. return -EFAULT;
  2220. if (!is_t4(adapter->params.chip)) {
  2221. switch (pi->tstamp_config.tx_type) {
  2222. case HWTSTAMP_TX_OFF:
  2223. case HWTSTAMP_TX_ON:
  2224. break;
  2225. default:
  2226. return -ERANGE;
  2227. }
  2228. switch (pi->tstamp_config.rx_filter) {
  2229. case HWTSTAMP_FILTER_NONE:
  2230. pi->rxtstamp = false;
  2231. break;
  2232. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2233. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2234. cxgb4_ptprx_timestamping(pi, pi->port_id,
  2235. PTP_TS_L4);
  2236. break;
  2237. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2238. cxgb4_ptprx_timestamping(pi, pi->port_id,
  2239. PTP_TS_L2_L4);
  2240. break;
  2241. case HWTSTAMP_FILTER_ALL:
  2242. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2243. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2244. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2245. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2246. pi->rxtstamp = true;
  2247. break;
  2248. default:
  2249. pi->tstamp_config.rx_filter =
  2250. HWTSTAMP_FILTER_NONE;
  2251. return -ERANGE;
  2252. }
  2253. if ((pi->tstamp_config.tx_type == HWTSTAMP_TX_OFF) &&
  2254. (pi->tstamp_config.rx_filter ==
  2255. HWTSTAMP_FILTER_NONE)) {
  2256. if (cxgb4_ptp_txtype(adapter, pi->port_id) >= 0)
  2257. pi->ptp_enable = false;
  2258. }
  2259. if (pi->tstamp_config.rx_filter !=
  2260. HWTSTAMP_FILTER_NONE) {
  2261. if (cxgb4_ptp_redirect_rx_packet(adapter,
  2262. pi) >= 0)
  2263. pi->ptp_enable = true;
  2264. }
  2265. } else {
  2266. /* For T4 Adapters */
  2267. switch (pi->tstamp_config.rx_filter) {
  2268. case HWTSTAMP_FILTER_NONE:
  2269. pi->rxtstamp = false;
  2270. break;
  2271. case HWTSTAMP_FILTER_ALL:
  2272. pi->rxtstamp = true;
  2273. break;
  2274. default:
  2275. pi->tstamp_config.rx_filter =
  2276. HWTSTAMP_FILTER_NONE;
  2277. return -ERANGE;
  2278. }
  2279. }
  2280. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2281. sizeof(pi->tstamp_config)) ?
  2282. -EFAULT : 0;
  2283. default:
  2284. return -EOPNOTSUPP;
  2285. }
  2286. return ret;
  2287. }
  2288. static void cxgb_set_rxmode(struct net_device *dev)
  2289. {
  2290. /* unfortunately we can't return errors to the stack */
  2291. set_rxmode(dev, -1, false);
  2292. }
  2293. static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
  2294. {
  2295. int ret;
  2296. struct port_info *pi = netdev_priv(dev);
  2297. ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
  2298. -1, -1, -1, true);
  2299. if (!ret)
  2300. dev->mtu = new_mtu;
  2301. return ret;
  2302. }
  2303. #ifdef CONFIG_PCI_IOV
  2304. static int cxgb4_mgmt_open(struct net_device *dev)
  2305. {
  2306. /* Turn carrier off since we don't have to transmit anything on this
  2307. * interface.
  2308. */
  2309. netif_carrier_off(dev);
  2310. return 0;
  2311. }
  2312. /* Fill MAC address that will be assigned by the FW */
  2313. static void cxgb4_mgmt_fill_vf_station_mac_addr(struct adapter *adap)
  2314. {
  2315. u8 hw_addr[ETH_ALEN], macaddr[ETH_ALEN];
  2316. unsigned int i, vf, nvfs;
  2317. u16 a, b;
  2318. int err;
  2319. u8 *na;
  2320. adap->params.pci.vpd_cap_addr = pci_find_capability(adap->pdev,
  2321. PCI_CAP_ID_VPD);
  2322. err = t4_get_raw_vpd_params(adap, &adap->params.vpd);
  2323. if (err)
  2324. return;
  2325. na = adap->params.vpd.na;
  2326. for (i = 0; i < ETH_ALEN; i++)
  2327. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  2328. hex2val(na[2 * i + 1]));
  2329. a = (hw_addr[0] << 8) | hw_addr[1];
  2330. b = (hw_addr[1] << 8) | hw_addr[2];
  2331. a ^= b;
  2332. a |= 0x0200; /* locally assigned Ethernet MAC address */
  2333. a &= ~0x0100; /* not a multicast Ethernet MAC address */
  2334. macaddr[0] = a >> 8;
  2335. macaddr[1] = a & 0xff;
  2336. for (i = 2; i < 5; i++)
  2337. macaddr[i] = hw_addr[i + 1];
  2338. for (vf = 0, nvfs = pci_sriov_get_totalvfs(adap->pdev);
  2339. vf < nvfs; vf++) {
  2340. macaddr[5] = adap->pf * 16 + vf;
  2341. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, macaddr);
  2342. }
  2343. }
  2344. static int cxgb4_mgmt_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
  2345. {
  2346. struct port_info *pi = netdev_priv(dev);
  2347. struct adapter *adap = pi->adapter;
  2348. int ret;
  2349. /* verify MAC addr is valid */
  2350. if (!is_valid_ether_addr(mac)) {
  2351. dev_err(pi->adapter->pdev_dev,
  2352. "Invalid Ethernet address %pM for VF %d\n",
  2353. mac, vf);
  2354. return -EINVAL;
  2355. }
  2356. dev_info(pi->adapter->pdev_dev,
  2357. "Setting MAC %pM on VF %d\n", mac, vf);
  2358. ret = t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
  2359. if (!ret)
  2360. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, mac);
  2361. return ret;
  2362. }
  2363. static int cxgb4_mgmt_get_vf_config(struct net_device *dev,
  2364. int vf, struct ifla_vf_info *ivi)
  2365. {
  2366. struct port_info *pi = netdev_priv(dev);
  2367. struct adapter *adap = pi->adapter;
  2368. struct vf_info *vfinfo;
  2369. if (vf >= adap->num_vfs)
  2370. return -EINVAL;
  2371. vfinfo = &adap->vfinfo[vf];
  2372. ivi->vf = vf;
  2373. ivi->max_tx_rate = vfinfo->tx_rate;
  2374. ivi->min_tx_rate = 0;
  2375. ether_addr_copy(ivi->mac, vfinfo->vf_mac_addr);
  2376. ivi->vlan = vfinfo->vlan;
  2377. return 0;
  2378. }
  2379. static int cxgb4_mgmt_get_phys_port_id(struct net_device *dev,
  2380. struct netdev_phys_item_id *ppid)
  2381. {
  2382. struct port_info *pi = netdev_priv(dev);
  2383. unsigned int phy_port_id;
  2384. phy_port_id = pi->adapter->adap_idx * 10 + pi->port_id;
  2385. ppid->id_len = sizeof(phy_port_id);
  2386. memcpy(ppid->id, &phy_port_id, ppid->id_len);
  2387. return 0;
  2388. }
  2389. static int cxgb4_mgmt_set_vf_rate(struct net_device *dev, int vf,
  2390. int min_tx_rate, int max_tx_rate)
  2391. {
  2392. struct port_info *pi = netdev_priv(dev);
  2393. struct adapter *adap = pi->adapter;
  2394. unsigned int link_ok, speed, mtu;
  2395. u32 fw_pfvf, fw_class;
  2396. int class_id = vf;
  2397. int ret;
  2398. u16 pktsize;
  2399. if (vf >= adap->num_vfs)
  2400. return -EINVAL;
  2401. if (min_tx_rate) {
  2402. dev_err(adap->pdev_dev,
  2403. "Min tx rate (%d) (> 0) for VF %d is Invalid.\n",
  2404. min_tx_rate, vf);
  2405. return -EINVAL;
  2406. }
  2407. ret = t4_get_link_params(pi, &link_ok, &speed, &mtu);
  2408. if (ret != FW_SUCCESS) {
  2409. dev_err(adap->pdev_dev,
  2410. "Failed to get link information for VF %d\n", vf);
  2411. return -EINVAL;
  2412. }
  2413. if (!link_ok) {
  2414. dev_err(adap->pdev_dev, "Link down for VF %d\n", vf);
  2415. return -EINVAL;
  2416. }
  2417. if (max_tx_rate > speed) {
  2418. dev_err(adap->pdev_dev,
  2419. "Max tx rate %d for VF %d can't be > link-speed %u",
  2420. max_tx_rate, vf, speed);
  2421. return -EINVAL;
  2422. }
  2423. pktsize = mtu;
  2424. /* subtract ethhdr size and 4 bytes crc since, f/w appends it */
  2425. pktsize = pktsize - sizeof(struct ethhdr) - 4;
  2426. /* subtract ipv4 hdr size, tcp hdr size to get typical IPv4 MSS size */
  2427. pktsize = pktsize - sizeof(struct iphdr) - sizeof(struct tcphdr);
  2428. /* configure Traffic Class for rate-limiting */
  2429. ret = t4_sched_params(adap, SCHED_CLASS_TYPE_PACKET,
  2430. SCHED_CLASS_LEVEL_CL_RL,
  2431. SCHED_CLASS_MODE_CLASS,
  2432. SCHED_CLASS_RATEUNIT_BITS,
  2433. SCHED_CLASS_RATEMODE_ABS,
  2434. pi->tx_chan, class_id, 0,
  2435. max_tx_rate * 1000, 0, pktsize);
  2436. if (ret) {
  2437. dev_err(adap->pdev_dev, "Err %d for Traffic Class config\n",
  2438. ret);
  2439. return -EINVAL;
  2440. }
  2441. dev_info(adap->pdev_dev,
  2442. "Class %d with MSS %u configured with rate %u\n",
  2443. class_id, pktsize, max_tx_rate);
  2444. /* bind VF to configured Traffic Class */
  2445. fw_pfvf = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
  2446. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_SCHEDCLASS_ETH));
  2447. fw_class = class_id;
  2448. ret = t4_set_params(adap, adap->mbox, adap->pf, vf + 1, 1, &fw_pfvf,
  2449. &fw_class);
  2450. if (ret) {
  2451. dev_err(adap->pdev_dev,
  2452. "Err %d in binding VF %d to Traffic Class %d\n",
  2453. ret, vf, class_id);
  2454. return -EINVAL;
  2455. }
  2456. dev_info(adap->pdev_dev, "PF %d VF %d is bound to Class %d\n",
  2457. adap->pf, vf, class_id);
  2458. adap->vfinfo[vf].tx_rate = max_tx_rate;
  2459. return 0;
  2460. }
  2461. static int cxgb4_mgmt_set_vf_vlan(struct net_device *dev, int vf,
  2462. u16 vlan, u8 qos, __be16 vlan_proto)
  2463. {
  2464. struct port_info *pi = netdev_priv(dev);
  2465. struct adapter *adap = pi->adapter;
  2466. int ret;
  2467. if (vf >= adap->num_vfs || vlan > 4095 || qos > 7)
  2468. return -EINVAL;
  2469. if (vlan_proto != htons(ETH_P_8021Q) || qos != 0)
  2470. return -EPROTONOSUPPORT;
  2471. ret = t4_set_vlan_acl(adap, adap->mbox, vf + 1, vlan);
  2472. if (!ret) {
  2473. adap->vfinfo[vf].vlan = vlan;
  2474. return 0;
  2475. }
  2476. dev_err(adap->pdev_dev, "Err %d %s VLAN ACL for PF/VF %d/%d\n",
  2477. ret, (vlan ? "setting" : "clearing"), adap->pf, vf);
  2478. return ret;
  2479. }
  2480. #endif /* CONFIG_PCI_IOV */
  2481. static int cxgb_set_mac_addr(struct net_device *dev, void *p)
  2482. {
  2483. int ret;
  2484. struct sockaddr *addr = p;
  2485. struct port_info *pi = netdev_priv(dev);
  2486. if (!is_valid_ether_addr(addr->sa_data))
  2487. return -EADDRNOTAVAIL;
  2488. ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
  2489. pi->xact_addr_filt, addr->sa_data, true, true);
  2490. if (ret < 0)
  2491. return ret;
  2492. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2493. pi->xact_addr_filt = ret;
  2494. return 0;
  2495. }
  2496. #ifdef CONFIG_NET_POLL_CONTROLLER
  2497. static void cxgb_netpoll(struct net_device *dev)
  2498. {
  2499. struct port_info *pi = netdev_priv(dev);
  2500. struct adapter *adap = pi->adapter;
  2501. if (adap->flags & USING_MSIX) {
  2502. int i;
  2503. struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
  2504. for (i = pi->nqsets; i; i--, rx++)
  2505. t4_sge_intr_msix(0, &rx->rspq);
  2506. } else
  2507. t4_intr_handler(adap)(0, adap);
  2508. }
  2509. #endif
  2510. static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
  2511. {
  2512. struct port_info *pi = netdev_priv(dev);
  2513. struct adapter *adap = pi->adapter;
  2514. struct sched_class *e;
  2515. struct ch_sched_params p;
  2516. struct ch_sched_queue qe;
  2517. u32 req_rate;
  2518. int err = 0;
  2519. if (!can_sched(dev))
  2520. return -ENOTSUPP;
  2521. if (index < 0 || index > pi->nqsets - 1)
  2522. return -EINVAL;
  2523. if (!(adap->flags & FULL_INIT_DONE)) {
  2524. dev_err(adap->pdev_dev,
  2525. "Failed to rate limit on queue %d. Link Down?\n",
  2526. index);
  2527. return -EINVAL;
  2528. }
  2529. /* Convert from Mbps to Kbps */
  2530. req_rate = rate * 1000;
  2531. /* Max rate is 100 Gbps */
  2532. if (req_rate > SCHED_MAX_RATE_KBPS) {
  2533. dev_err(adap->pdev_dev,
  2534. "Invalid rate %u Mbps, Max rate is %u Mbps\n",
  2535. rate, SCHED_MAX_RATE_KBPS / 1000);
  2536. return -ERANGE;
  2537. }
  2538. /* First unbind the queue from any existing class */
  2539. memset(&qe, 0, sizeof(qe));
  2540. qe.queue = index;
  2541. qe.class = SCHED_CLS_NONE;
  2542. err = cxgb4_sched_class_unbind(dev, (void *)(&qe), SCHED_QUEUE);
  2543. if (err) {
  2544. dev_err(adap->pdev_dev,
  2545. "Unbinding Queue %d on port %d fail. Err: %d\n",
  2546. index, pi->port_id, err);
  2547. return err;
  2548. }
  2549. /* Queue already unbound */
  2550. if (!req_rate)
  2551. return 0;
  2552. /* Fetch any available unused or matching scheduling class */
  2553. memset(&p, 0, sizeof(p));
  2554. p.type = SCHED_CLASS_TYPE_PACKET;
  2555. p.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
  2556. p.u.params.mode = SCHED_CLASS_MODE_CLASS;
  2557. p.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
  2558. p.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
  2559. p.u.params.channel = pi->tx_chan;
  2560. p.u.params.class = SCHED_CLS_NONE;
  2561. p.u.params.minrate = 0;
  2562. p.u.params.maxrate = req_rate;
  2563. p.u.params.weight = 0;
  2564. p.u.params.pktsize = dev->mtu;
  2565. e = cxgb4_sched_class_alloc(dev, &p);
  2566. if (!e)
  2567. return -ENOMEM;
  2568. /* Bind the queue to a scheduling class */
  2569. memset(&qe, 0, sizeof(qe));
  2570. qe.queue = index;
  2571. qe.class = e->idx;
  2572. err = cxgb4_sched_class_bind(dev, (void *)(&qe), SCHED_QUEUE);
  2573. if (err)
  2574. dev_err(adap->pdev_dev,
  2575. "Queue rate limiting failed. Err: %d\n", err);
  2576. return err;
  2577. }
  2578. static int cxgb_setup_tc_flower(struct net_device *dev,
  2579. struct tc_cls_flower_offload *cls_flower)
  2580. {
  2581. switch (cls_flower->command) {
  2582. case TC_CLSFLOWER_REPLACE:
  2583. return cxgb4_tc_flower_replace(dev, cls_flower);
  2584. case TC_CLSFLOWER_DESTROY:
  2585. return cxgb4_tc_flower_destroy(dev, cls_flower);
  2586. case TC_CLSFLOWER_STATS:
  2587. return cxgb4_tc_flower_stats(dev, cls_flower);
  2588. default:
  2589. return -EOPNOTSUPP;
  2590. }
  2591. }
  2592. static int cxgb_setup_tc_cls_u32(struct net_device *dev,
  2593. struct tc_cls_u32_offload *cls_u32)
  2594. {
  2595. switch (cls_u32->command) {
  2596. case TC_CLSU32_NEW_KNODE:
  2597. case TC_CLSU32_REPLACE_KNODE:
  2598. return cxgb4_config_knode(dev, cls_u32);
  2599. case TC_CLSU32_DELETE_KNODE:
  2600. return cxgb4_delete_knode(dev, cls_u32);
  2601. default:
  2602. return -EOPNOTSUPP;
  2603. }
  2604. }
  2605. static int cxgb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  2606. void *cb_priv)
  2607. {
  2608. struct net_device *dev = cb_priv;
  2609. struct port_info *pi = netdev2pinfo(dev);
  2610. struct adapter *adap = netdev2adap(dev);
  2611. if (!(adap->flags & FULL_INIT_DONE)) {
  2612. dev_err(adap->pdev_dev,
  2613. "Failed to setup tc on port %d. Link Down?\n",
  2614. pi->port_id);
  2615. return -EINVAL;
  2616. }
  2617. if (!tc_cls_can_offload_and_chain0(dev, type_data))
  2618. return -EOPNOTSUPP;
  2619. switch (type) {
  2620. case TC_SETUP_CLSU32:
  2621. return cxgb_setup_tc_cls_u32(dev, type_data);
  2622. case TC_SETUP_CLSFLOWER:
  2623. return cxgb_setup_tc_flower(dev, type_data);
  2624. default:
  2625. return -EOPNOTSUPP;
  2626. }
  2627. }
  2628. static int cxgb_setup_tc_block(struct net_device *dev,
  2629. struct tc_block_offload *f)
  2630. {
  2631. struct port_info *pi = netdev2pinfo(dev);
  2632. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  2633. return -EOPNOTSUPP;
  2634. switch (f->command) {
  2635. case TC_BLOCK_BIND:
  2636. return tcf_block_cb_register(f->block, cxgb_setup_tc_block_cb,
  2637. pi, dev, f->extack);
  2638. case TC_BLOCK_UNBIND:
  2639. tcf_block_cb_unregister(f->block, cxgb_setup_tc_block_cb, pi);
  2640. return 0;
  2641. default:
  2642. return -EOPNOTSUPP;
  2643. }
  2644. }
  2645. static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
  2646. void *type_data)
  2647. {
  2648. switch (type) {
  2649. case TC_SETUP_BLOCK:
  2650. return cxgb_setup_tc_block(dev, type_data);
  2651. default:
  2652. return -EOPNOTSUPP;
  2653. }
  2654. }
  2655. static void cxgb_del_udp_tunnel(struct net_device *netdev,
  2656. struct udp_tunnel_info *ti)
  2657. {
  2658. struct port_info *pi = netdev_priv(netdev);
  2659. struct adapter *adapter = pi->adapter;
  2660. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2661. u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
  2662. int ret = 0, i;
  2663. if (chip_ver < CHELSIO_T6)
  2664. return;
  2665. switch (ti->type) {
  2666. case UDP_TUNNEL_TYPE_VXLAN:
  2667. if (!adapter->vxlan_port_cnt ||
  2668. adapter->vxlan_port != ti->port)
  2669. return; /* Invalid VxLAN destination port */
  2670. adapter->vxlan_port_cnt--;
  2671. if (adapter->vxlan_port_cnt)
  2672. return;
  2673. adapter->vxlan_port = 0;
  2674. t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A, 0);
  2675. break;
  2676. case UDP_TUNNEL_TYPE_GENEVE:
  2677. if (!adapter->geneve_port_cnt ||
  2678. adapter->geneve_port != ti->port)
  2679. return; /* Invalid GENEVE destination port */
  2680. adapter->geneve_port_cnt--;
  2681. if (adapter->geneve_port_cnt)
  2682. return;
  2683. adapter->geneve_port = 0;
  2684. t4_write_reg(adapter, MPS_RX_GENEVE_TYPE_A, 0);
  2685. break;
  2686. default:
  2687. return;
  2688. }
  2689. /* Matchall mac entries can be deleted only after all tunnel ports
  2690. * are brought down or removed.
  2691. */
  2692. if (!adapter->rawf_cnt)
  2693. return;
  2694. for_each_port(adapter, i) {
  2695. pi = adap2pinfo(adapter, i);
  2696. ret = t4_free_raw_mac_filt(adapter, pi->viid,
  2697. match_all_mac, match_all_mac,
  2698. adapter->rawf_start +
  2699. pi->port_id,
  2700. 1, pi->port_id, false);
  2701. if (ret < 0) {
  2702. netdev_info(netdev, "Failed to free mac filter entry, for port %d\n",
  2703. i);
  2704. return;
  2705. }
  2706. atomic_dec(&adapter->mps_encap[adapter->rawf_start +
  2707. pi->port_id].refcnt);
  2708. }
  2709. }
  2710. static void cxgb_add_udp_tunnel(struct net_device *netdev,
  2711. struct udp_tunnel_info *ti)
  2712. {
  2713. struct port_info *pi = netdev_priv(netdev);
  2714. struct adapter *adapter = pi->adapter;
  2715. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2716. u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
  2717. int i, ret;
  2718. if (chip_ver < CHELSIO_T6 || !adapter->rawf_cnt)
  2719. return;
  2720. switch (ti->type) {
  2721. case UDP_TUNNEL_TYPE_VXLAN:
  2722. /* Callback for adding vxlan port can be called with the same
  2723. * port for both IPv4 and IPv6. We should not disable the
  2724. * offloading when the same port for both protocols is added
  2725. * and later one of them is removed.
  2726. */
  2727. if (adapter->vxlan_port_cnt &&
  2728. adapter->vxlan_port == ti->port) {
  2729. adapter->vxlan_port_cnt++;
  2730. return;
  2731. }
  2732. /* We will support only one VxLAN port */
  2733. if (adapter->vxlan_port_cnt) {
  2734. netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
  2735. be16_to_cpu(adapter->vxlan_port),
  2736. be16_to_cpu(ti->port));
  2737. return;
  2738. }
  2739. adapter->vxlan_port = ti->port;
  2740. adapter->vxlan_port_cnt = 1;
  2741. t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A,
  2742. VXLAN_V(be16_to_cpu(ti->port)) | VXLAN_EN_F);
  2743. break;
  2744. case UDP_TUNNEL_TYPE_GENEVE:
  2745. if (adapter->geneve_port_cnt &&
  2746. adapter->geneve_port == ti->port) {
  2747. adapter->geneve_port_cnt++;
  2748. return;
  2749. }
  2750. /* We will support only one GENEVE port */
  2751. if (adapter->geneve_port_cnt) {
  2752. netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
  2753. be16_to_cpu(adapter->geneve_port),
  2754. be16_to_cpu(ti->port));
  2755. return;
  2756. }
  2757. adapter->geneve_port = ti->port;
  2758. adapter->geneve_port_cnt = 1;
  2759. t4_write_reg(adapter, MPS_RX_GENEVE_TYPE_A,
  2760. GENEVE_V(be16_to_cpu(ti->port)) | GENEVE_EN_F);
  2761. break;
  2762. default:
  2763. return;
  2764. }
  2765. /* Create a 'match all' mac filter entry for inner mac,
  2766. * if raw mac interface is supported. Once the linux kernel provides
  2767. * driver entry points for adding/deleting the inner mac addresses,
  2768. * we will remove this 'match all' entry and fallback to adding
  2769. * exact match filters.
  2770. */
  2771. for_each_port(adapter, i) {
  2772. pi = adap2pinfo(adapter, i);
  2773. ret = t4_alloc_raw_mac_filt(adapter, pi->viid,
  2774. match_all_mac,
  2775. match_all_mac,
  2776. adapter->rawf_start +
  2777. pi->port_id,
  2778. 1, pi->port_id, false);
  2779. if (ret < 0) {
  2780. netdev_info(netdev, "Failed to allocate a mac filter entry, not adding port %d\n",
  2781. be16_to_cpu(ti->port));
  2782. cxgb_del_udp_tunnel(netdev, ti);
  2783. return;
  2784. }
  2785. atomic_inc(&adapter->mps_encap[ret].refcnt);
  2786. }
  2787. }
  2788. static netdev_features_t cxgb_features_check(struct sk_buff *skb,
  2789. struct net_device *dev,
  2790. netdev_features_t features)
  2791. {
  2792. struct port_info *pi = netdev_priv(dev);
  2793. struct adapter *adapter = pi->adapter;
  2794. if (CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
  2795. return features;
  2796. /* Check if hw supports offload for this packet */
  2797. if (!skb->encapsulation || cxgb_encap_offload_supported(skb))
  2798. return features;
  2799. /* Offload is not supported for this encapsulated packet */
  2800. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  2801. }
  2802. static netdev_features_t cxgb_fix_features(struct net_device *dev,
  2803. netdev_features_t features)
  2804. {
  2805. /* Disable GRO, if RX_CSUM is disabled */
  2806. if (!(features & NETIF_F_RXCSUM))
  2807. features &= ~NETIF_F_GRO;
  2808. return features;
  2809. }
  2810. static const struct net_device_ops cxgb4_netdev_ops = {
  2811. .ndo_open = cxgb_open,
  2812. .ndo_stop = cxgb_close,
  2813. .ndo_start_xmit = t4_start_xmit,
  2814. .ndo_select_queue = cxgb_select_queue,
  2815. .ndo_get_stats64 = cxgb_get_stats,
  2816. .ndo_set_rx_mode = cxgb_set_rxmode,
  2817. .ndo_set_mac_address = cxgb_set_mac_addr,
  2818. .ndo_set_features = cxgb_set_features,
  2819. .ndo_validate_addr = eth_validate_addr,
  2820. .ndo_do_ioctl = cxgb_ioctl,
  2821. .ndo_change_mtu = cxgb_change_mtu,
  2822. #ifdef CONFIG_NET_POLL_CONTROLLER
  2823. .ndo_poll_controller = cxgb_netpoll,
  2824. #endif
  2825. #ifdef CONFIG_CHELSIO_T4_FCOE
  2826. .ndo_fcoe_enable = cxgb_fcoe_enable,
  2827. .ndo_fcoe_disable = cxgb_fcoe_disable,
  2828. #endif /* CONFIG_CHELSIO_T4_FCOE */
  2829. .ndo_set_tx_maxrate = cxgb_set_tx_maxrate,
  2830. .ndo_setup_tc = cxgb_setup_tc,
  2831. .ndo_udp_tunnel_add = cxgb_add_udp_tunnel,
  2832. .ndo_udp_tunnel_del = cxgb_del_udp_tunnel,
  2833. .ndo_features_check = cxgb_features_check,
  2834. .ndo_fix_features = cxgb_fix_features,
  2835. };
  2836. #ifdef CONFIG_PCI_IOV
  2837. static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
  2838. .ndo_open = cxgb4_mgmt_open,
  2839. .ndo_set_vf_mac = cxgb4_mgmt_set_vf_mac,
  2840. .ndo_get_vf_config = cxgb4_mgmt_get_vf_config,
  2841. .ndo_set_vf_rate = cxgb4_mgmt_set_vf_rate,
  2842. .ndo_get_phys_port_id = cxgb4_mgmt_get_phys_port_id,
  2843. .ndo_set_vf_vlan = cxgb4_mgmt_set_vf_vlan,
  2844. };
  2845. #endif
  2846. static void cxgb4_mgmt_get_drvinfo(struct net_device *dev,
  2847. struct ethtool_drvinfo *info)
  2848. {
  2849. struct adapter *adapter = netdev2adap(dev);
  2850. strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
  2851. strlcpy(info->version, cxgb4_driver_version,
  2852. sizeof(info->version));
  2853. strlcpy(info->bus_info, pci_name(adapter->pdev),
  2854. sizeof(info->bus_info));
  2855. }
  2856. static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
  2857. .get_drvinfo = cxgb4_mgmt_get_drvinfo,
  2858. };
  2859. static void notify_fatal_err(struct work_struct *work)
  2860. {
  2861. struct adapter *adap;
  2862. adap = container_of(work, struct adapter, fatal_err_notify_task);
  2863. notify_ulds(adap, CXGB4_STATE_FATAL_ERROR);
  2864. }
  2865. void t4_fatal_err(struct adapter *adap)
  2866. {
  2867. int port;
  2868. if (pci_channel_offline(adap->pdev))
  2869. return;
  2870. /* Disable the SGE since ULDs are going to free resources that
  2871. * could be exposed to the adapter. RDMA MWs for example...
  2872. */
  2873. t4_shutdown_adapter(adap);
  2874. for_each_port(adap, port) {
  2875. struct net_device *dev = adap->port[port];
  2876. /* If we get here in very early initialization the network
  2877. * devices may not have been set up yet.
  2878. */
  2879. if (!dev)
  2880. continue;
  2881. netif_tx_stop_all_queues(dev);
  2882. netif_carrier_off(dev);
  2883. }
  2884. dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
  2885. queue_work(adap->workq, &adap->fatal_err_notify_task);
  2886. }
  2887. static void setup_memwin(struct adapter *adap)
  2888. {
  2889. u32 nic_win_base = t4_get_util_window(adap);
  2890. t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
  2891. }
  2892. static void setup_memwin_rdma(struct adapter *adap)
  2893. {
  2894. if (adap->vres.ocq.size) {
  2895. u32 start;
  2896. unsigned int sz_kb;
  2897. start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
  2898. start &= PCI_BASE_ADDRESS_MEM_MASK;
  2899. start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
  2900. sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
  2901. t4_write_reg(adap,
  2902. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
  2903. start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
  2904. t4_write_reg(adap,
  2905. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
  2906. adap->vres.ocq.start);
  2907. t4_read_reg(adap,
  2908. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
  2909. }
  2910. }
  2911. /* HMA Definitions */
  2912. /* The maximum number of address that can be send in a single FW cmd */
  2913. #define HMA_MAX_ADDR_IN_CMD 5
  2914. #define HMA_PAGE_SIZE PAGE_SIZE
  2915. #define HMA_MAX_NO_FW_ADDRESS (16 << 10) /* FW supports 16K addresses */
  2916. #define HMA_PAGE_ORDER \
  2917. ((HMA_PAGE_SIZE < HMA_MAX_NO_FW_ADDRESS) ? \
  2918. ilog2(HMA_MAX_NO_FW_ADDRESS / HMA_PAGE_SIZE) : 0)
  2919. /* The minimum and maximum possible HMA sizes that can be specified in the FW
  2920. * configuration(in units of MB).
  2921. */
  2922. #define HMA_MIN_TOTAL_SIZE 1
  2923. #define HMA_MAX_TOTAL_SIZE \
  2924. (((HMA_PAGE_SIZE << HMA_PAGE_ORDER) * \
  2925. HMA_MAX_NO_FW_ADDRESS) >> 20)
  2926. static void adap_free_hma_mem(struct adapter *adapter)
  2927. {
  2928. struct scatterlist *iter;
  2929. struct page *page;
  2930. int i;
  2931. if (!adapter->hma.sgt)
  2932. return;
  2933. if (adapter->hma.flags & HMA_DMA_MAPPED_FLAG) {
  2934. dma_unmap_sg(adapter->pdev_dev, adapter->hma.sgt->sgl,
  2935. adapter->hma.sgt->nents, PCI_DMA_BIDIRECTIONAL);
  2936. adapter->hma.flags &= ~HMA_DMA_MAPPED_FLAG;
  2937. }
  2938. for_each_sg(adapter->hma.sgt->sgl, iter,
  2939. adapter->hma.sgt->orig_nents, i) {
  2940. page = sg_page(iter);
  2941. if (page)
  2942. __free_pages(page, HMA_PAGE_ORDER);
  2943. }
  2944. kfree(adapter->hma.phy_addr);
  2945. sg_free_table(adapter->hma.sgt);
  2946. kfree(adapter->hma.sgt);
  2947. adapter->hma.sgt = NULL;
  2948. }
  2949. static int adap_config_hma(struct adapter *adapter)
  2950. {
  2951. struct scatterlist *sgl, *iter;
  2952. struct sg_table *sgt;
  2953. struct page *newpage;
  2954. unsigned int i, j, k;
  2955. u32 param, hma_size;
  2956. unsigned int ncmds;
  2957. size_t page_size;
  2958. u32 page_order;
  2959. int node, ret;
  2960. /* HMA is supported only for T6+ cards.
  2961. * Avoid initializing HMA in kdump kernels.
  2962. */
  2963. if (is_kdump_kernel() ||
  2964. CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
  2965. return 0;
  2966. /* Get the HMA region size required by fw */
  2967. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  2968. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_HMA_SIZE));
  2969. ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
  2970. 1, &param, &hma_size);
  2971. /* An error means card has its own memory or HMA is not supported by
  2972. * the firmware. Return without any errors.
  2973. */
  2974. if (ret || !hma_size)
  2975. return 0;
  2976. if (hma_size < HMA_MIN_TOTAL_SIZE ||
  2977. hma_size > HMA_MAX_TOTAL_SIZE) {
  2978. dev_err(adapter->pdev_dev,
  2979. "HMA size %uMB beyond bounds(%u-%lu)MB\n",
  2980. hma_size, HMA_MIN_TOTAL_SIZE, HMA_MAX_TOTAL_SIZE);
  2981. return -EINVAL;
  2982. }
  2983. page_size = HMA_PAGE_SIZE;
  2984. page_order = HMA_PAGE_ORDER;
  2985. adapter->hma.sgt = kzalloc(sizeof(*adapter->hma.sgt), GFP_KERNEL);
  2986. if (unlikely(!adapter->hma.sgt)) {
  2987. dev_err(adapter->pdev_dev, "HMA SG table allocation failed\n");
  2988. return -ENOMEM;
  2989. }
  2990. sgt = adapter->hma.sgt;
  2991. /* FW returned value will be in MB's
  2992. */
  2993. sgt->orig_nents = (hma_size << 20) / (page_size << page_order);
  2994. if (sg_alloc_table(sgt, sgt->orig_nents, GFP_KERNEL)) {
  2995. dev_err(adapter->pdev_dev, "HMA SGL allocation failed\n");
  2996. kfree(adapter->hma.sgt);
  2997. adapter->hma.sgt = NULL;
  2998. return -ENOMEM;
  2999. }
  3000. sgl = adapter->hma.sgt->sgl;
  3001. node = dev_to_node(adapter->pdev_dev);
  3002. for_each_sg(sgl, iter, sgt->orig_nents, i) {
  3003. newpage = alloc_pages_node(node, __GFP_NOWARN | GFP_KERNEL |
  3004. __GFP_ZERO, page_order);
  3005. if (!newpage) {
  3006. dev_err(adapter->pdev_dev,
  3007. "Not enough memory for HMA page allocation\n");
  3008. ret = -ENOMEM;
  3009. goto free_hma;
  3010. }
  3011. sg_set_page(iter, newpage, page_size << page_order, 0);
  3012. }
  3013. sgt->nents = dma_map_sg(adapter->pdev_dev, sgl, sgt->orig_nents,
  3014. DMA_BIDIRECTIONAL);
  3015. if (!sgt->nents) {
  3016. dev_err(adapter->pdev_dev,
  3017. "Not enough memory for HMA DMA mapping");
  3018. ret = -ENOMEM;
  3019. goto free_hma;
  3020. }
  3021. adapter->hma.flags |= HMA_DMA_MAPPED_FLAG;
  3022. adapter->hma.phy_addr = kcalloc(sgt->nents, sizeof(dma_addr_t),
  3023. GFP_KERNEL);
  3024. if (unlikely(!adapter->hma.phy_addr))
  3025. goto free_hma;
  3026. for_each_sg(sgl, iter, sgt->nents, i) {
  3027. newpage = sg_page(iter);
  3028. adapter->hma.phy_addr[i] = sg_dma_address(iter);
  3029. }
  3030. ncmds = DIV_ROUND_UP(sgt->nents, HMA_MAX_ADDR_IN_CMD);
  3031. /* Pass on the addresses to firmware */
  3032. for (i = 0, k = 0; i < ncmds; i++, k += HMA_MAX_ADDR_IN_CMD) {
  3033. struct fw_hma_cmd hma_cmd;
  3034. u8 naddr = HMA_MAX_ADDR_IN_CMD;
  3035. u8 soc = 0, eoc = 0;
  3036. u8 hma_mode = 1; /* Presently we support only Page table mode */
  3037. soc = (i == 0) ? 1 : 0;
  3038. eoc = (i == ncmds - 1) ? 1 : 0;
  3039. /* For last cmd, set naddr corresponding to remaining
  3040. * addresses
  3041. */
  3042. if (i == ncmds - 1) {
  3043. naddr = sgt->nents % HMA_MAX_ADDR_IN_CMD;
  3044. naddr = naddr ? naddr : HMA_MAX_ADDR_IN_CMD;
  3045. }
  3046. memset(&hma_cmd, 0, sizeof(hma_cmd));
  3047. hma_cmd.op_pkd = htonl(FW_CMD_OP_V(FW_HMA_CMD) |
  3048. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  3049. hma_cmd.retval_len16 = htonl(FW_LEN16(hma_cmd));
  3050. hma_cmd.mode_to_pcie_params =
  3051. htonl(FW_HMA_CMD_MODE_V(hma_mode) |
  3052. FW_HMA_CMD_SOC_V(soc) | FW_HMA_CMD_EOC_V(eoc));
  3053. /* HMA cmd size specified in MB's */
  3054. hma_cmd.naddr_size =
  3055. htonl(FW_HMA_CMD_SIZE_V(hma_size) |
  3056. FW_HMA_CMD_NADDR_V(naddr));
  3057. /* Total Page size specified in units of 4K */
  3058. hma_cmd.addr_size_pkd =
  3059. htonl(FW_HMA_CMD_ADDR_SIZE_V
  3060. ((page_size << page_order) >> 12));
  3061. /* Fill the 5 addresses */
  3062. for (j = 0; j < naddr; j++) {
  3063. hma_cmd.phy_address[j] =
  3064. cpu_to_be64(adapter->hma.phy_addr[j + k]);
  3065. }
  3066. ret = t4_wr_mbox(adapter, adapter->mbox, &hma_cmd,
  3067. sizeof(hma_cmd), &hma_cmd);
  3068. if (ret) {
  3069. dev_err(adapter->pdev_dev,
  3070. "HMA FW command failed with err %d\n", ret);
  3071. goto free_hma;
  3072. }
  3073. }
  3074. if (!ret)
  3075. dev_info(adapter->pdev_dev,
  3076. "Reserved %uMB host memory for HMA\n", hma_size);
  3077. return ret;
  3078. free_hma:
  3079. adap_free_hma_mem(adapter);
  3080. return ret;
  3081. }
  3082. static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
  3083. {
  3084. u32 v;
  3085. int ret;
  3086. /* Now that we've successfully configured and initialized the adapter
  3087. * can ask the Firmware what resources it has provisioned for us.
  3088. */
  3089. ret = t4_get_pfres(adap);
  3090. if (ret) {
  3091. dev_err(adap->pdev_dev,
  3092. "Unable to retrieve resource provisioning information\n");
  3093. return ret;
  3094. }
  3095. /* get device capabilities */
  3096. memset(c, 0, sizeof(*c));
  3097. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3098. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3099. c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
  3100. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
  3101. if (ret < 0)
  3102. return ret;
  3103. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3104. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  3105. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
  3106. if (ret < 0)
  3107. return ret;
  3108. ret = t4_config_glbl_rss(adap, adap->pf,
  3109. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
  3110. FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
  3111. FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
  3112. if (ret < 0)
  3113. return ret;
  3114. ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
  3115. MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
  3116. FW_CMD_CAP_PF);
  3117. if (ret < 0)
  3118. return ret;
  3119. t4_sge_init(adap);
  3120. /* tweak some settings */
  3121. t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
  3122. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
  3123. t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
  3124. v = t4_read_reg(adap, TP_PIO_DATA_A);
  3125. t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
  3126. /* first 4 Tx modulation queues point to consecutive Tx channels */
  3127. adap->params.tp.tx_modq_map = 0xE4;
  3128. t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
  3129. TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
  3130. /* associate each Tx modulation queue with consecutive Tx channels */
  3131. v = 0x84218421;
  3132. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3133. &v, 1, TP_TX_SCHED_HDR_A);
  3134. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3135. &v, 1, TP_TX_SCHED_FIFO_A);
  3136. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3137. &v, 1, TP_TX_SCHED_PCMD_A);
  3138. #define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
  3139. if (is_offload(adap)) {
  3140. t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
  3141. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3142. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3143. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3144. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  3145. t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
  3146. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3147. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3148. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3149. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  3150. }
  3151. /* get basic stuff going */
  3152. return t4_early_init(adap, adap->pf);
  3153. }
  3154. /*
  3155. * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
  3156. */
  3157. #define MAX_ATIDS 8192U
  3158. /*
  3159. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3160. *
  3161. * If the firmware we're dealing with has Configuration File support, then
  3162. * we use that to perform all configuration
  3163. */
  3164. /*
  3165. * Tweak configuration based on module parameters, etc. Most of these have
  3166. * defaults assigned to them by Firmware Configuration Files (if we're using
  3167. * them) but need to be explicitly set if we're using hard-coded
  3168. * initialization. But even in the case of using Firmware Configuration
  3169. * Files, we'd like to expose the ability to change these via module
  3170. * parameters so these are essentially common tweaks/settings for
  3171. * Configuration Files and hard-coded initialization ...
  3172. */
  3173. static int adap_init0_tweaks(struct adapter *adapter)
  3174. {
  3175. /*
  3176. * Fix up various Host-Dependent Parameters like Page Size, Cache
  3177. * Line Size, etc. The firmware default is for a 4KB Page Size and
  3178. * 64B Cache Line Size ...
  3179. */
  3180. t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
  3181. /*
  3182. * Process module parameters which affect early initialization.
  3183. */
  3184. if (rx_dma_offset != 2 && rx_dma_offset != 0) {
  3185. dev_err(&adapter->pdev->dev,
  3186. "Ignoring illegal rx_dma_offset=%d, using 2\n",
  3187. rx_dma_offset);
  3188. rx_dma_offset = 2;
  3189. }
  3190. t4_set_reg_field(adapter, SGE_CONTROL_A,
  3191. PKTSHIFT_V(PKTSHIFT_M),
  3192. PKTSHIFT_V(rx_dma_offset));
  3193. /*
  3194. * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
  3195. * adds the pseudo header itself.
  3196. */
  3197. t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
  3198. CSUM_HAS_PSEUDO_HDR_F, 0);
  3199. return 0;
  3200. }
  3201. /* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
  3202. * unto themselves and they contain their own firmware to perform their
  3203. * tasks ...
  3204. */
  3205. static int phy_aq1202_version(const u8 *phy_fw_data,
  3206. size_t phy_fw_size)
  3207. {
  3208. int offset;
  3209. /* At offset 0x8 you're looking for the primary image's
  3210. * starting offset which is 3 Bytes wide
  3211. *
  3212. * At offset 0xa of the primary image, you look for the offset
  3213. * of the DRAM segment which is 3 Bytes wide.
  3214. *
  3215. * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
  3216. * wide
  3217. */
  3218. #define be16(__p) (((__p)[0] << 8) | (__p)[1])
  3219. #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
  3220. #define le24(__p) (le16(__p) | ((__p)[2] << 16))
  3221. offset = le24(phy_fw_data + 0x8) << 12;
  3222. offset = le24(phy_fw_data + offset + 0xa);
  3223. return be16(phy_fw_data + offset + 0x27e);
  3224. #undef be16
  3225. #undef le16
  3226. #undef le24
  3227. }
  3228. static struct info_10gbt_phy_fw {
  3229. unsigned int phy_fw_id; /* PCI Device ID */
  3230. char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
  3231. int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
  3232. int phy_flash; /* Has FLASH for PHY Firmware */
  3233. } phy_info_array[] = {
  3234. {
  3235. PHY_AQ1202_DEVICEID,
  3236. PHY_AQ1202_FIRMWARE,
  3237. phy_aq1202_version,
  3238. 1,
  3239. },
  3240. {
  3241. PHY_BCM84834_DEVICEID,
  3242. PHY_BCM84834_FIRMWARE,
  3243. NULL,
  3244. 0,
  3245. },
  3246. { 0, NULL, NULL },
  3247. };
  3248. static struct info_10gbt_phy_fw *find_phy_info(int devid)
  3249. {
  3250. int i;
  3251. for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
  3252. if (phy_info_array[i].phy_fw_id == devid)
  3253. return &phy_info_array[i];
  3254. }
  3255. return NULL;
  3256. }
  3257. /* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
  3258. * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
  3259. * we return a negative error number. If we transfer new firmware we return 1
  3260. * (from t4_load_phy_fw()). If we don't do anything we return 0.
  3261. */
  3262. static int adap_init0_phy(struct adapter *adap)
  3263. {
  3264. const struct firmware *phyf;
  3265. int ret;
  3266. struct info_10gbt_phy_fw *phy_info;
  3267. /* Use the device ID to determine which PHY file to flash.
  3268. */
  3269. phy_info = find_phy_info(adap->pdev->device);
  3270. if (!phy_info) {
  3271. dev_warn(adap->pdev_dev,
  3272. "No PHY Firmware file found for this PHY\n");
  3273. return -EOPNOTSUPP;
  3274. }
  3275. /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
  3276. * use that. The adapter firmware provides us with a memory buffer
  3277. * where we can load a PHY firmware file from the host if we want to
  3278. * override the PHY firmware File in flash.
  3279. */
  3280. ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
  3281. adap->pdev_dev);
  3282. if (ret < 0) {
  3283. /* For adapters without FLASH attached to PHY for their
  3284. * firmware, it's obviously a fatal error if we can't get the
  3285. * firmware to the adapter. For adapters with PHY firmware
  3286. * FLASH storage, it's worth a warning if we can't find the
  3287. * PHY Firmware but we'll neuter the error ...
  3288. */
  3289. dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
  3290. "/lib/firmware/%s, error %d\n",
  3291. phy_info->phy_fw_file, -ret);
  3292. if (phy_info->phy_flash) {
  3293. int cur_phy_fw_ver = 0;
  3294. t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3295. dev_warn(adap->pdev_dev, "continuing with, on-adapter "
  3296. "FLASH copy, version %#x\n", cur_phy_fw_ver);
  3297. ret = 0;
  3298. }
  3299. return ret;
  3300. }
  3301. /* Load PHY Firmware onto adapter.
  3302. */
  3303. ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
  3304. phy_info->phy_fw_version,
  3305. (u8 *)phyf->data, phyf->size);
  3306. if (ret < 0)
  3307. dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
  3308. -ret);
  3309. else if (ret > 0) {
  3310. int new_phy_fw_ver = 0;
  3311. if (phy_info->phy_fw_version)
  3312. new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
  3313. phyf->size);
  3314. dev_info(adap->pdev_dev, "Successfully transferred PHY "
  3315. "Firmware /lib/firmware/%s, version %#x\n",
  3316. phy_info->phy_fw_file, new_phy_fw_ver);
  3317. }
  3318. release_firmware(phyf);
  3319. return ret;
  3320. }
  3321. /*
  3322. * Attempt to initialize the adapter via a Firmware Configuration File.
  3323. */
  3324. static int adap_init0_config(struct adapter *adapter, int reset)
  3325. {
  3326. struct fw_caps_config_cmd caps_cmd;
  3327. const struct firmware *cf;
  3328. unsigned long mtype = 0, maddr = 0;
  3329. u32 finiver, finicsum, cfcsum;
  3330. int ret;
  3331. int config_issued = 0;
  3332. char *fw_config_file, fw_config_file_path[256];
  3333. char *config_name = NULL;
  3334. /*
  3335. * Reset device if necessary.
  3336. */
  3337. if (reset) {
  3338. ret = t4_fw_reset(adapter, adapter->mbox,
  3339. PIORSTMODE_F | PIORST_F);
  3340. if (ret < 0)
  3341. goto bye;
  3342. }
  3343. /* If this is a 10Gb/s-BT adapter make sure the chip-external
  3344. * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
  3345. * to be performed after any global adapter RESET above since some
  3346. * PHYs only have local RAM copies of the PHY firmware.
  3347. */
  3348. if (is_10gbt_device(adapter->pdev->device)) {
  3349. ret = adap_init0_phy(adapter);
  3350. if (ret < 0)
  3351. goto bye;
  3352. }
  3353. /*
  3354. * If we have a T4 configuration file under /lib/firmware/cxgb4/,
  3355. * then use that. Otherwise, use the configuration file stored
  3356. * in the adapter flash ...
  3357. */
  3358. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  3359. case CHELSIO_T4:
  3360. fw_config_file = FW4_CFNAME;
  3361. break;
  3362. case CHELSIO_T5:
  3363. fw_config_file = FW5_CFNAME;
  3364. break;
  3365. case CHELSIO_T6:
  3366. fw_config_file = FW6_CFNAME;
  3367. break;
  3368. default:
  3369. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  3370. adapter->pdev->device);
  3371. ret = -EINVAL;
  3372. goto bye;
  3373. }
  3374. ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
  3375. if (ret < 0) {
  3376. config_name = "On FLASH";
  3377. mtype = FW_MEMTYPE_CF_FLASH;
  3378. maddr = t4_flash_cfg_addr(adapter);
  3379. } else {
  3380. u32 params[7], val[7];
  3381. sprintf(fw_config_file_path,
  3382. "/lib/firmware/%s", fw_config_file);
  3383. config_name = fw_config_file_path;
  3384. if (cf->size >= FLASH_CFG_MAX_SIZE)
  3385. ret = -ENOMEM;
  3386. else {
  3387. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3388. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3389. ret = t4_query_params(adapter, adapter->mbox,
  3390. adapter->pf, 0, 1, params, val);
  3391. if (ret == 0) {
  3392. /*
  3393. * For t4_memory_rw() below addresses and
  3394. * sizes have to be in terms of multiples of 4
  3395. * bytes. So, if the Configuration File isn't
  3396. * a multiple of 4 bytes in length we'll have
  3397. * to write that out separately since we can't
  3398. * guarantee that the bytes following the
  3399. * residual byte in the buffer returned by
  3400. * request_firmware() are zeroed out ...
  3401. */
  3402. size_t resid = cf->size & 0x3;
  3403. size_t size = cf->size & ~0x3;
  3404. __be32 *data = (__be32 *)cf->data;
  3405. mtype = FW_PARAMS_PARAM_Y_G(val[0]);
  3406. maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
  3407. spin_lock(&adapter->win0_lock);
  3408. ret = t4_memory_rw(adapter, 0, mtype, maddr,
  3409. size, data, T4_MEMORY_WRITE);
  3410. if (ret == 0 && resid != 0) {
  3411. union {
  3412. __be32 word;
  3413. char buf[4];
  3414. } last;
  3415. int i;
  3416. last.word = data[size >> 2];
  3417. for (i = resid; i < 4; i++)
  3418. last.buf[i] = 0;
  3419. ret = t4_memory_rw(adapter, 0, mtype,
  3420. maddr + size,
  3421. 4, &last.word,
  3422. T4_MEMORY_WRITE);
  3423. }
  3424. spin_unlock(&adapter->win0_lock);
  3425. }
  3426. }
  3427. release_firmware(cf);
  3428. if (ret)
  3429. goto bye;
  3430. }
  3431. /*
  3432. * Issue a Capability Configuration command to the firmware to get it
  3433. * to parse the Configuration File. We don't use t4_fw_config_file()
  3434. * because we want the ability to modify various features after we've
  3435. * processed the configuration file ...
  3436. */
  3437. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3438. caps_cmd.op_to_write =
  3439. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3440. FW_CMD_REQUEST_F |
  3441. FW_CMD_READ_F);
  3442. caps_cmd.cfvalid_to_len16 =
  3443. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  3444. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  3445. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  3446. FW_LEN16(caps_cmd));
  3447. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3448. &caps_cmd);
  3449. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  3450. * Configuration File in FLASH), our last gasp effort is to use the
  3451. * Firmware Configuration File which is embedded in the firmware. A
  3452. * very few early versions of the firmware didn't have one embedded
  3453. * but we can ignore those.
  3454. */
  3455. if (ret == -ENOENT) {
  3456. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3457. caps_cmd.op_to_write =
  3458. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3459. FW_CMD_REQUEST_F |
  3460. FW_CMD_READ_F);
  3461. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3462. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
  3463. sizeof(caps_cmd), &caps_cmd);
  3464. config_name = "Firmware Default";
  3465. }
  3466. config_issued = 1;
  3467. if (ret < 0)
  3468. goto bye;
  3469. finiver = ntohl(caps_cmd.finiver);
  3470. finicsum = ntohl(caps_cmd.finicsum);
  3471. cfcsum = ntohl(caps_cmd.cfcsum);
  3472. if (finicsum != cfcsum)
  3473. dev_warn(adapter->pdev_dev, "Configuration File checksum "\
  3474. "mismatch: [fini] csum=%#x, computed csum=%#x\n",
  3475. finicsum, cfcsum);
  3476. /*
  3477. * And now tell the firmware to use the configuration we just loaded.
  3478. */
  3479. caps_cmd.op_to_write =
  3480. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3481. FW_CMD_REQUEST_F |
  3482. FW_CMD_WRITE_F);
  3483. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3484. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3485. NULL);
  3486. if (ret < 0)
  3487. goto bye;
  3488. /*
  3489. * Tweak configuration based on system architecture, module
  3490. * parameters, etc.
  3491. */
  3492. ret = adap_init0_tweaks(adapter);
  3493. if (ret < 0)
  3494. goto bye;
  3495. /* We will proceed even if HMA init fails. */
  3496. ret = adap_config_hma(adapter);
  3497. if (ret)
  3498. dev_err(adapter->pdev_dev,
  3499. "HMA configuration failed with error %d\n", ret);
  3500. /*
  3501. * And finally tell the firmware to initialize itself using the
  3502. * parameters from the Configuration File.
  3503. */
  3504. ret = t4_fw_initialize(adapter, adapter->mbox);
  3505. if (ret < 0)
  3506. goto bye;
  3507. /* Emit Firmware Configuration File information and return
  3508. * successfully.
  3509. */
  3510. dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
  3511. "Configuration File \"%s\", version %#x, computed checksum %#x\n",
  3512. config_name, finiver, cfcsum);
  3513. return 0;
  3514. /*
  3515. * Something bad happened. Return the error ... (If the "error"
  3516. * is that there's no Configuration File on the adapter we don't
  3517. * want to issue a warning since this is fairly common.)
  3518. */
  3519. bye:
  3520. if (config_issued && ret != -ENOENT)
  3521. dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
  3522. config_name, -ret);
  3523. return ret;
  3524. }
  3525. static struct fw_info fw_info_array[] = {
  3526. {
  3527. .chip = CHELSIO_T4,
  3528. .fs_name = FW4_CFNAME,
  3529. .fw_mod_name = FW4_FNAME,
  3530. .fw_hdr = {
  3531. .chip = FW_HDR_CHIP_T4,
  3532. .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
  3533. .intfver_nic = FW_INTFVER(T4, NIC),
  3534. .intfver_vnic = FW_INTFVER(T4, VNIC),
  3535. .intfver_ri = FW_INTFVER(T4, RI),
  3536. .intfver_iscsi = FW_INTFVER(T4, ISCSI),
  3537. .intfver_fcoe = FW_INTFVER(T4, FCOE),
  3538. },
  3539. }, {
  3540. .chip = CHELSIO_T5,
  3541. .fs_name = FW5_CFNAME,
  3542. .fw_mod_name = FW5_FNAME,
  3543. .fw_hdr = {
  3544. .chip = FW_HDR_CHIP_T5,
  3545. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  3546. .intfver_nic = FW_INTFVER(T5, NIC),
  3547. .intfver_vnic = FW_INTFVER(T5, VNIC),
  3548. .intfver_ri = FW_INTFVER(T5, RI),
  3549. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  3550. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  3551. },
  3552. }, {
  3553. .chip = CHELSIO_T6,
  3554. .fs_name = FW6_CFNAME,
  3555. .fw_mod_name = FW6_FNAME,
  3556. .fw_hdr = {
  3557. .chip = FW_HDR_CHIP_T6,
  3558. .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
  3559. .intfver_nic = FW_INTFVER(T6, NIC),
  3560. .intfver_vnic = FW_INTFVER(T6, VNIC),
  3561. .intfver_ofld = FW_INTFVER(T6, OFLD),
  3562. .intfver_ri = FW_INTFVER(T6, RI),
  3563. .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
  3564. .intfver_iscsi = FW_INTFVER(T6, ISCSI),
  3565. .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
  3566. .intfver_fcoe = FW_INTFVER(T6, FCOE),
  3567. },
  3568. }
  3569. };
  3570. static struct fw_info *find_fw_info(int chip)
  3571. {
  3572. int i;
  3573. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  3574. if (fw_info_array[i].chip == chip)
  3575. return &fw_info_array[i];
  3576. }
  3577. return NULL;
  3578. }
  3579. /*
  3580. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3581. */
  3582. static int adap_init0(struct adapter *adap)
  3583. {
  3584. int ret;
  3585. u32 v, port_vec;
  3586. enum dev_state state;
  3587. u32 params[7], val[7];
  3588. struct fw_caps_config_cmd caps_cmd;
  3589. int reset = 1;
  3590. /* Grab Firmware Device Log parameters as early as possible so we have
  3591. * access to it for debugging, etc.
  3592. */
  3593. ret = t4_init_devlog_params(adap);
  3594. if (ret < 0)
  3595. return ret;
  3596. /* Contact FW, advertising Master capability */
  3597. ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
  3598. is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
  3599. if (ret < 0) {
  3600. dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
  3601. ret);
  3602. return ret;
  3603. }
  3604. if (ret == adap->mbox)
  3605. adap->flags |= MASTER_PF;
  3606. /*
  3607. * If we're the Master PF Driver and the device is uninitialized,
  3608. * then let's consider upgrading the firmware ... (We always want
  3609. * to check the firmware version number in order to A. get it for
  3610. * later reporting and B. to warn if the currently loaded firmware
  3611. * is excessively mismatched relative to the driver.)
  3612. */
  3613. t4_get_version_info(adap);
  3614. ret = t4_check_fw_version(adap);
  3615. /* If firmware is too old (not supported by driver) force an update. */
  3616. if (ret)
  3617. state = DEV_STATE_UNINIT;
  3618. if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
  3619. struct fw_info *fw_info;
  3620. struct fw_hdr *card_fw;
  3621. const struct firmware *fw;
  3622. const u8 *fw_data = NULL;
  3623. unsigned int fw_size = 0;
  3624. /* This is the firmware whose headers the driver was compiled
  3625. * against
  3626. */
  3627. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
  3628. if (fw_info == NULL) {
  3629. dev_err(adap->pdev_dev,
  3630. "unable to get firmware info for chip %d.\n",
  3631. CHELSIO_CHIP_VERSION(adap->params.chip));
  3632. return -EINVAL;
  3633. }
  3634. /* allocate memory to read the header of the firmware on the
  3635. * card
  3636. */
  3637. card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL);
  3638. if (!card_fw) {
  3639. ret = -ENOMEM;
  3640. goto bye;
  3641. }
  3642. /* Get FW from from /lib/firmware/ */
  3643. ret = request_firmware(&fw, fw_info->fw_mod_name,
  3644. adap->pdev_dev);
  3645. if (ret < 0) {
  3646. dev_err(adap->pdev_dev,
  3647. "unable to load firmware image %s, error %d\n",
  3648. fw_info->fw_mod_name, ret);
  3649. } else {
  3650. fw_data = fw->data;
  3651. fw_size = fw->size;
  3652. }
  3653. /* upgrade FW logic */
  3654. ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
  3655. state, &reset);
  3656. /* Cleaning up */
  3657. release_firmware(fw);
  3658. kvfree(card_fw);
  3659. if (ret < 0)
  3660. goto bye;
  3661. }
  3662. /* If the firmware is initialized already, emit a simply note to that
  3663. * effect. Otherwise, it's time to try initializing the adapter.
  3664. */
  3665. if (state == DEV_STATE_INIT) {
  3666. ret = adap_config_hma(adap);
  3667. if (ret)
  3668. dev_err(adap->pdev_dev,
  3669. "HMA configuration failed with error %d\n",
  3670. ret);
  3671. dev_info(adap->pdev_dev, "Coming up as %s: "\
  3672. "Adapter already initialized\n",
  3673. adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
  3674. } else {
  3675. dev_info(adap->pdev_dev, "Coming up as MASTER: "\
  3676. "Initializing adapter\n");
  3677. /* Find out whether we're dealing with a version of the
  3678. * firmware which has configuration file support.
  3679. */
  3680. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3681. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3682. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3683. params, val);
  3684. /* If the firmware doesn't support Configuration Files,
  3685. * return an error.
  3686. */
  3687. if (ret < 0) {
  3688. dev_err(adap->pdev_dev, "firmware doesn't support "
  3689. "Firmware Configuration Files\n");
  3690. goto bye;
  3691. }
  3692. /* The firmware provides us with a memory buffer where we can
  3693. * load a Configuration File from the host if we want to
  3694. * override the Configuration File in flash.
  3695. */
  3696. ret = adap_init0_config(adap, reset);
  3697. if (ret == -ENOENT) {
  3698. dev_err(adap->pdev_dev, "no Configuration File "
  3699. "present on adapter.\n");
  3700. goto bye;
  3701. }
  3702. if (ret < 0) {
  3703. dev_err(adap->pdev_dev, "could not initialize "
  3704. "adapter, error %d\n", -ret);
  3705. goto bye;
  3706. }
  3707. }
  3708. /* Now that we've successfully configured and initialized the adapter
  3709. * (or found it already initialized), we can ask the Firmware what
  3710. * resources it has provisioned for us.
  3711. */
  3712. ret = t4_get_pfres(adap);
  3713. if (ret) {
  3714. dev_err(adap->pdev_dev,
  3715. "Unable to retrieve resource provisioning information\n");
  3716. goto bye;
  3717. }
  3718. /* Grab VPD parameters. This should be done after we establish a
  3719. * connection to the firmware since some of the VPD parameters
  3720. * (notably the Core Clock frequency) are retrieved via requests to
  3721. * the firmware. On the other hand, we need these fairly early on
  3722. * so we do this right after getting ahold of the firmware.
  3723. *
  3724. * We need to do this after initializing the adapter because someone
  3725. * could have FLASHed a new VPD which won't be read by the firmware
  3726. * until we do the RESET ...
  3727. */
  3728. ret = t4_get_vpd_params(adap, &adap->params.vpd);
  3729. if (ret < 0)
  3730. goto bye;
  3731. /* Find out what ports are available to us. Note that we need to do
  3732. * this before calling adap_init0_no_config() since it needs nports
  3733. * and portvec ...
  3734. */
  3735. v =
  3736. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3737. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  3738. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
  3739. if (ret < 0)
  3740. goto bye;
  3741. adap->params.nports = hweight32(port_vec);
  3742. adap->params.portvec = port_vec;
  3743. /* Give the SGE code a chance to pull in anything that it needs ...
  3744. * Note that this must be called after we retrieve our VPD parameters
  3745. * in order to know how to convert core ticks to seconds, etc.
  3746. */
  3747. ret = t4_sge_init(adap);
  3748. if (ret < 0)
  3749. goto bye;
  3750. if (is_bypass_device(adap->pdev->device))
  3751. adap->params.bypass = 1;
  3752. /*
  3753. * Grab some of our basic fundamental operating parameters.
  3754. */
  3755. #define FW_PARAM_DEV(param) \
  3756. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
  3757. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
  3758. #define FW_PARAM_PFVF(param) \
  3759. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  3760. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
  3761. FW_PARAMS_PARAM_Y_V(0) | \
  3762. FW_PARAMS_PARAM_Z_V(0)
  3763. params[0] = FW_PARAM_PFVF(EQ_START);
  3764. params[1] = FW_PARAM_PFVF(L2T_START);
  3765. params[2] = FW_PARAM_PFVF(L2T_END);
  3766. params[3] = FW_PARAM_PFVF(FILTER_START);
  3767. params[4] = FW_PARAM_PFVF(FILTER_END);
  3768. params[5] = FW_PARAM_PFVF(IQFLINT_START);
  3769. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
  3770. if (ret < 0)
  3771. goto bye;
  3772. adap->sge.egr_start = val[0];
  3773. adap->l2t_start = val[1];
  3774. adap->l2t_end = val[2];
  3775. adap->tids.ftid_base = val[3];
  3776. adap->tids.nftids = val[4] - val[3] + 1;
  3777. adap->sge.ingr_start = val[5];
  3778. if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
  3779. /* Read the raw mps entries. In T6, the last 2 tcam entries
  3780. * are reserved for raw mac addresses (rawf = 2, one per port).
  3781. */
  3782. params[0] = FW_PARAM_PFVF(RAWF_START);
  3783. params[1] = FW_PARAM_PFVF(RAWF_END);
  3784. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3785. params, val);
  3786. if (ret == 0) {
  3787. adap->rawf_start = val[0];
  3788. adap->rawf_cnt = val[1] - val[0] + 1;
  3789. }
  3790. }
  3791. /* qids (ingress/egress) returned from firmware can be anywhere
  3792. * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
  3793. * Hence driver needs to allocate memory for this range to
  3794. * store the queue info. Get the highest IQFLINT/EQ index returned
  3795. * in FW_EQ_*_CMD.alloc command.
  3796. */
  3797. params[0] = FW_PARAM_PFVF(EQ_END);
  3798. params[1] = FW_PARAM_PFVF(IQFLINT_END);
  3799. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3800. if (ret < 0)
  3801. goto bye;
  3802. adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
  3803. adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
  3804. adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
  3805. sizeof(*adap->sge.egr_map), GFP_KERNEL);
  3806. if (!adap->sge.egr_map) {
  3807. ret = -ENOMEM;
  3808. goto bye;
  3809. }
  3810. adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
  3811. sizeof(*adap->sge.ingr_map), GFP_KERNEL);
  3812. if (!adap->sge.ingr_map) {
  3813. ret = -ENOMEM;
  3814. goto bye;
  3815. }
  3816. /* Allocate the memory for the vaious egress queue bitmaps
  3817. * ie starving_fl, txq_maperr and blocked_fl.
  3818. */
  3819. adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3820. sizeof(long), GFP_KERNEL);
  3821. if (!adap->sge.starving_fl) {
  3822. ret = -ENOMEM;
  3823. goto bye;
  3824. }
  3825. adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3826. sizeof(long), GFP_KERNEL);
  3827. if (!adap->sge.txq_maperr) {
  3828. ret = -ENOMEM;
  3829. goto bye;
  3830. }
  3831. #ifdef CONFIG_DEBUG_FS
  3832. adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3833. sizeof(long), GFP_KERNEL);
  3834. if (!adap->sge.blocked_fl) {
  3835. ret = -ENOMEM;
  3836. goto bye;
  3837. }
  3838. #endif
  3839. params[0] = FW_PARAM_PFVF(CLIP_START);
  3840. params[1] = FW_PARAM_PFVF(CLIP_END);
  3841. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3842. if (ret < 0)
  3843. goto bye;
  3844. adap->clipt_start = val[0];
  3845. adap->clipt_end = val[1];
  3846. /* We don't yet have a PARAMs calls to retrieve the number of Traffic
  3847. * Classes supported by the hardware/firmware so we hard code it here
  3848. * for now.
  3849. */
  3850. adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
  3851. /* query params related to active filter region */
  3852. params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
  3853. params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
  3854. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3855. /* If Active filter size is set we enable establishing
  3856. * offload connection through firmware work request
  3857. */
  3858. if ((val[0] != val[1]) && (ret >= 0)) {
  3859. adap->flags |= FW_OFLD_CONN;
  3860. adap->tids.aftid_base = val[0];
  3861. adap->tids.aftid_end = val[1];
  3862. }
  3863. /* If we're running on newer firmware, let it know that we're
  3864. * prepared to deal with encapsulated CPL messages. Older
  3865. * firmware won't understand this and we'll just get
  3866. * unencapsulated messages ...
  3867. */
  3868. params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
  3869. val[0] = 1;
  3870. (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
  3871. /*
  3872. * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
  3873. * capability. Earlier versions of the firmware didn't have the
  3874. * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
  3875. * permission to use ULPTX MEMWRITE DSGL.
  3876. */
  3877. if (is_t4(adap->params.chip)) {
  3878. adap->params.ulptx_memwrite_dsgl = false;
  3879. } else {
  3880. params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
  3881. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3882. 1, params, val);
  3883. adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
  3884. }
  3885. /* See if FW supports FW_RI_FR_NSMR_TPTE_WR work request */
  3886. params[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR);
  3887. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3888. 1, params, val);
  3889. adap->params.fr_nsmr_tpte_wr_support = (ret == 0 && val[0] != 0);
  3890. /* See if FW supports FW_FILTER2 work request */
  3891. if (is_t4(adap->params.chip)) {
  3892. adap->params.filter2_wr_support = 0;
  3893. } else {
  3894. params[0] = FW_PARAM_DEV(FILTER2_WR);
  3895. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3896. 1, params, val);
  3897. adap->params.filter2_wr_support = (ret == 0 && val[0] != 0);
  3898. }
  3899. /*
  3900. * Get device capabilities so we can determine what resources we need
  3901. * to manage.
  3902. */
  3903. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3904. caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3905. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3906. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3907. ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
  3908. &caps_cmd);
  3909. if (ret < 0)
  3910. goto bye;
  3911. if (caps_cmd.ofldcaps ||
  3912. (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER))) {
  3913. /* query offload-related parameters */
  3914. params[0] = FW_PARAM_DEV(NTID);
  3915. params[1] = FW_PARAM_PFVF(SERVER_START);
  3916. params[2] = FW_PARAM_PFVF(SERVER_END);
  3917. params[3] = FW_PARAM_PFVF(TDDP_START);
  3918. params[4] = FW_PARAM_PFVF(TDDP_END);
  3919. params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
  3920. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3921. params, val);
  3922. if (ret < 0)
  3923. goto bye;
  3924. adap->tids.ntids = val[0];
  3925. adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
  3926. adap->tids.stid_base = val[1];
  3927. adap->tids.nstids = val[2] - val[1] + 1;
  3928. /*
  3929. * Setup server filter region. Divide the available filter
  3930. * region into two parts. Regular filters get 1/3rd and server
  3931. * filters get 2/3rd part. This is only enabled if workarond
  3932. * path is enabled.
  3933. * 1. For regular filters.
  3934. * 2. Server filter: This are special filters which are used
  3935. * to redirect SYN packets to offload queue.
  3936. */
  3937. if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
  3938. adap->tids.sftid_base = adap->tids.ftid_base +
  3939. DIV_ROUND_UP(adap->tids.nftids, 3);
  3940. adap->tids.nsftids = adap->tids.nftids -
  3941. DIV_ROUND_UP(adap->tids.nftids, 3);
  3942. adap->tids.nftids = adap->tids.sftid_base -
  3943. adap->tids.ftid_base;
  3944. }
  3945. adap->vres.ddp.start = val[3];
  3946. adap->vres.ddp.size = val[4] - val[3] + 1;
  3947. adap->params.ofldq_wr_cred = val[5];
  3948. if (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER)) {
  3949. ret = init_hash_filter(adap);
  3950. if (ret < 0)
  3951. goto bye;
  3952. } else {
  3953. adap->params.offload = 1;
  3954. adap->num_ofld_uld += 1;
  3955. }
  3956. }
  3957. if (caps_cmd.rdmacaps) {
  3958. params[0] = FW_PARAM_PFVF(STAG_START);
  3959. params[1] = FW_PARAM_PFVF(STAG_END);
  3960. params[2] = FW_PARAM_PFVF(RQ_START);
  3961. params[3] = FW_PARAM_PFVF(RQ_END);
  3962. params[4] = FW_PARAM_PFVF(PBL_START);
  3963. params[5] = FW_PARAM_PFVF(PBL_END);
  3964. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3965. params, val);
  3966. if (ret < 0)
  3967. goto bye;
  3968. adap->vres.stag.start = val[0];
  3969. adap->vres.stag.size = val[1] - val[0] + 1;
  3970. adap->vres.rq.start = val[2];
  3971. adap->vres.rq.size = val[3] - val[2] + 1;
  3972. adap->vres.pbl.start = val[4];
  3973. adap->vres.pbl.size = val[5] - val[4] + 1;
  3974. params[0] = FW_PARAM_PFVF(SRQ_START);
  3975. params[1] = FW_PARAM_PFVF(SRQ_END);
  3976. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3977. params, val);
  3978. if (!ret) {
  3979. adap->vres.srq.start = val[0];
  3980. adap->vres.srq.size = val[1] - val[0] + 1;
  3981. }
  3982. if (adap->vres.srq.size) {
  3983. adap->srq = t4_init_srq(adap->vres.srq.size);
  3984. if (!adap->srq)
  3985. dev_warn(&adap->pdev->dev, "could not allocate SRQ, continuing\n");
  3986. }
  3987. params[0] = FW_PARAM_PFVF(SQRQ_START);
  3988. params[1] = FW_PARAM_PFVF(SQRQ_END);
  3989. params[2] = FW_PARAM_PFVF(CQ_START);
  3990. params[3] = FW_PARAM_PFVF(CQ_END);
  3991. params[4] = FW_PARAM_PFVF(OCQ_START);
  3992. params[5] = FW_PARAM_PFVF(OCQ_END);
  3993. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
  3994. val);
  3995. if (ret < 0)
  3996. goto bye;
  3997. adap->vres.qp.start = val[0];
  3998. adap->vres.qp.size = val[1] - val[0] + 1;
  3999. adap->vres.cq.start = val[2];
  4000. adap->vres.cq.size = val[3] - val[2] + 1;
  4001. adap->vres.ocq.start = val[4];
  4002. adap->vres.ocq.size = val[5] - val[4] + 1;
  4003. params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
  4004. params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
  4005. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
  4006. val);
  4007. if (ret < 0) {
  4008. adap->params.max_ordird_qp = 8;
  4009. adap->params.max_ird_adapter = 32 * adap->tids.ntids;
  4010. ret = 0;
  4011. } else {
  4012. adap->params.max_ordird_qp = val[0];
  4013. adap->params.max_ird_adapter = val[1];
  4014. }
  4015. dev_info(adap->pdev_dev,
  4016. "max_ordird_qp %d max_ird_adapter %d\n",
  4017. adap->params.max_ordird_qp,
  4018. adap->params.max_ird_adapter);
  4019. /* Enable write_with_immediate if FW supports it */
  4020. params[0] = FW_PARAM_DEV(RDMA_WRITE_WITH_IMM);
  4021. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params,
  4022. val);
  4023. adap->params.write_w_imm_support = (ret == 0 && val[0] != 0);
  4024. /* Enable write_cmpl if FW supports it */
  4025. params[0] = FW_PARAM_DEV(RI_WRITE_CMPL_WR);
  4026. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params,
  4027. val);
  4028. adap->params.write_cmpl_support = (ret == 0 && val[0] != 0);
  4029. adap->num_ofld_uld += 2;
  4030. }
  4031. if (caps_cmd.iscsicaps) {
  4032. params[0] = FW_PARAM_PFVF(ISCSI_START);
  4033. params[1] = FW_PARAM_PFVF(ISCSI_END);
  4034. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  4035. params, val);
  4036. if (ret < 0)
  4037. goto bye;
  4038. adap->vres.iscsi.start = val[0];
  4039. adap->vres.iscsi.size = val[1] - val[0] + 1;
  4040. /* LIO target and cxgb4i initiaitor */
  4041. adap->num_ofld_uld += 2;
  4042. }
  4043. if (caps_cmd.cryptocaps) {
  4044. if (ntohs(caps_cmd.cryptocaps) &
  4045. FW_CAPS_CONFIG_CRYPTO_LOOKASIDE) {
  4046. params[0] = FW_PARAM_PFVF(NCRYPTO_LOOKASIDE);
  4047. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  4048. 2, params, val);
  4049. if (ret < 0) {
  4050. if (ret != -EINVAL)
  4051. goto bye;
  4052. } else {
  4053. adap->vres.ncrypto_fc = val[0];
  4054. }
  4055. adap->num_ofld_uld += 1;
  4056. }
  4057. if (ntohs(caps_cmd.cryptocaps) &
  4058. FW_CAPS_CONFIG_TLS_INLINE) {
  4059. params[0] = FW_PARAM_PFVF(TLS_START);
  4060. params[1] = FW_PARAM_PFVF(TLS_END);
  4061. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  4062. 2, params, val);
  4063. if (ret < 0)
  4064. goto bye;
  4065. adap->vres.key.start = val[0];
  4066. adap->vres.key.size = val[1] - val[0] + 1;
  4067. adap->num_uld += 1;
  4068. }
  4069. adap->params.crypto = ntohs(caps_cmd.cryptocaps);
  4070. }
  4071. #undef FW_PARAM_PFVF
  4072. #undef FW_PARAM_DEV
  4073. /* The MTU/MSS Table is initialized by now, so load their values. If
  4074. * we're initializing the adapter, then we'll make any modifications
  4075. * we want to the MTU/MSS Table and also initialize the congestion
  4076. * parameters.
  4077. */
  4078. t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
  4079. if (state != DEV_STATE_INIT) {
  4080. int i;
  4081. /* The default MTU Table contains values 1492 and 1500.
  4082. * However, for TCP, it's better to have two values which are
  4083. * a multiple of 8 +/- 4 bytes apart near this popular MTU.
  4084. * This allows us to have a TCP Data Payload which is a
  4085. * multiple of 8 regardless of what combination of TCP Options
  4086. * are in use (always a multiple of 4 bytes) which is
  4087. * important for performance reasons. For instance, if no
  4088. * options are in use, then we have a 20-byte IP header and a
  4089. * 20-byte TCP header. In this case, a 1500-byte MSS would
  4090. * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
  4091. * which is not a multiple of 8. So using an MSS of 1488 in
  4092. * this case results in a TCP Data Payload of 1448 bytes which
  4093. * is a multiple of 8. On the other hand, if 12-byte TCP Time
  4094. * Stamps have been negotiated, then an MTU of 1500 bytes
  4095. * results in a TCP Data Payload of 1448 bytes which, as
  4096. * above, is a multiple of 8 bytes ...
  4097. */
  4098. for (i = 0; i < NMTUS; i++)
  4099. if (adap->params.mtus[i] == 1492) {
  4100. adap->params.mtus[i] = 1488;
  4101. break;
  4102. }
  4103. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4104. adap->params.b_wnd);
  4105. }
  4106. t4_init_sge_params(adap);
  4107. adap->flags |= FW_OK;
  4108. t4_init_tp_params(adap, true);
  4109. return 0;
  4110. /*
  4111. * Something bad happened. If a command timed out or failed with EIO
  4112. * FW does not operate within its spec or something catastrophic
  4113. * happened to HW/FW, stop issuing commands.
  4114. */
  4115. bye:
  4116. adap_free_hma_mem(adap);
  4117. kfree(adap->sge.egr_map);
  4118. kfree(adap->sge.ingr_map);
  4119. kfree(adap->sge.starving_fl);
  4120. kfree(adap->sge.txq_maperr);
  4121. #ifdef CONFIG_DEBUG_FS
  4122. kfree(adap->sge.blocked_fl);
  4123. #endif
  4124. if (ret != -ETIMEDOUT && ret != -EIO)
  4125. t4_fw_bye(adap, adap->mbox);
  4126. return ret;
  4127. }
  4128. /* EEH callbacks */
  4129. static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
  4130. pci_channel_state_t state)
  4131. {
  4132. int i;
  4133. struct adapter *adap = pci_get_drvdata(pdev);
  4134. if (!adap)
  4135. goto out;
  4136. rtnl_lock();
  4137. adap->flags &= ~FW_OK;
  4138. notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
  4139. spin_lock(&adap->stats_lock);
  4140. for_each_port(adap, i) {
  4141. struct net_device *dev = adap->port[i];
  4142. if (dev) {
  4143. netif_device_detach(dev);
  4144. netif_carrier_off(dev);
  4145. }
  4146. }
  4147. spin_unlock(&adap->stats_lock);
  4148. disable_interrupts(adap);
  4149. if (adap->flags & FULL_INIT_DONE)
  4150. cxgb_down(adap);
  4151. rtnl_unlock();
  4152. if ((adap->flags & DEV_ENABLED)) {
  4153. pci_disable_device(pdev);
  4154. adap->flags &= ~DEV_ENABLED;
  4155. }
  4156. out: return state == pci_channel_io_perm_failure ?
  4157. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  4158. }
  4159. static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
  4160. {
  4161. int i, ret;
  4162. struct fw_caps_config_cmd c;
  4163. struct adapter *adap = pci_get_drvdata(pdev);
  4164. if (!adap) {
  4165. pci_restore_state(pdev);
  4166. pci_save_state(pdev);
  4167. return PCI_ERS_RESULT_RECOVERED;
  4168. }
  4169. if (!(adap->flags & DEV_ENABLED)) {
  4170. if (pci_enable_device(pdev)) {
  4171. dev_err(&pdev->dev, "Cannot reenable PCI "
  4172. "device after reset\n");
  4173. return PCI_ERS_RESULT_DISCONNECT;
  4174. }
  4175. adap->flags |= DEV_ENABLED;
  4176. }
  4177. pci_set_master(pdev);
  4178. pci_restore_state(pdev);
  4179. pci_save_state(pdev);
  4180. pci_cleanup_aer_uncorrect_error_status(pdev);
  4181. if (t4_wait_dev_ready(adap->regs) < 0)
  4182. return PCI_ERS_RESULT_DISCONNECT;
  4183. if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
  4184. return PCI_ERS_RESULT_DISCONNECT;
  4185. adap->flags |= FW_OK;
  4186. if (adap_init1(adap, &c))
  4187. return PCI_ERS_RESULT_DISCONNECT;
  4188. for_each_port(adap, i) {
  4189. struct port_info *p = adap2pinfo(adap, i);
  4190. ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
  4191. NULL, NULL);
  4192. if (ret < 0)
  4193. return PCI_ERS_RESULT_DISCONNECT;
  4194. p->viid = ret;
  4195. p->xact_addr_filt = -1;
  4196. }
  4197. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4198. adap->params.b_wnd);
  4199. setup_memwin(adap);
  4200. if (cxgb_up(adap))
  4201. return PCI_ERS_RESULT_DISCONNECT;
  4202. return PCI_ERS_RESULT_RECOVERED;
  4203. }
  4204. static void eeh_resume(struct pci_dev *pdev)
  4205. {
  4206. int i;
  4207. struct adapter *adap = pci_get_drvdata(pdev);
  4208. if (!adap)
  4209. return;
  4210. rtnl_lock();
  4211. for_each_port(adap, i) {
  4212. struct net_device *dev = adap->port[i];
  4213. if (dev) {
  4214. if (netif_running(dev)) {
  4215. link_start(dev);
  4216. cxgb_set_rxmode(dev);
  4217. }
  4218. netif_device_attach(dev);
  4219. }
  4220. }
  4221. rtnl_unlock();
  4222. }
  4223. static const struct pci_error_handlers cxgb4_eeh = {
  4224. .error_detected = eeh_err_detected,
  4225. .slot_reset = eeh_slot_reset,
  4226. .resume = eeh_resume,
  4227. };
  4228. /* Return true if the Link Configuration supports "High Speeds" (those greater
  4229. * than 1Gb/s).
  4230. */
  4231. static inline bool is_x_10g_port(const struct link_config *lc)
  4232. {
  4233. unsigned int speeds, high_speeds;
  4234. speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
  4235. high_speeds = speeds &
  4236. ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
  4237. return high_speeds != 0;
  4238. }
  4239. /*
  4240. * Perform default configuration of DMA queues depending on the number and type
  4241. * of ports we found and the number of available CPUs. Most settings can be
  4242. * modified by the admin prior to actual use.
  4243. */
  4244. static int cfg_queues(struct adapter *adap)
  4245. {
  4246. struct sge *s = &adap->sge;
  4247. int i, n10g = 0, qidx = 0;
  4248. int niqflint, neq, avail_eth_qsets;
  4249. int max_eth_qsets = 32;
  4250. #ifndef CONFIG_CHELSIO_T4_DCB
  4251. int q10g = 0;
  4252. #endif
  4253. /* Reduce memory usage in kdump environment, disable all offload.
  4254. */
  4255. if (is_kdump_kernel() || (is_uld(adap) && t4_uld_mem_alloc(adap))) {
  4256. adap->params.offload = 0;
  4257. adap->params.crypto = 0;
  4258. }
  4259. /* Calculate the number of Ethernet Queue Sets available based on
  4260. * resources provisioned for us. We always have an Asynchronous
  4261. * Firmware Event Ingress Queue. If we're operating in MSI or Legacy
  4262. * IRQ Pin Interrupt mode, then we'll also have a Forwarded Interrupt
  4263. * Ingress Queue. Meanwhile, we need two Egress Queues for each
  4264. * Queue Set: one for the Free List and one for the Ethernet TX Queue.
  4265. *
  4266. * Note that we should also take into account all of the various
  4267. * Offload Queues. But, in any situation where we're operating in
  4268. * a Resource Constrained Provisioning environment, doing any Offload
  4269. * at all is problematic ...
  4270. */
  4271. niqflint = adap->params.pfres.niqflint - 1;
  4272. if (!(adap->flags & USING_MSIX))
  4273. niqflint--;
  4274. neq = adap->params.pfres.neq / 2;
  4275. avail_eth_qsets = min(niqflint, neq);
  4276. if (avail_eth_qsets > max_eth_qsets)
  4277. avail_eth_qsets = max_eth_qsets;
  4278. if (avail_eth_qsets < adap->params.nports) {
  4279. dev_err(adap->pdev_dev, "avail_eth_qsets=%d < nports=%d\n",
  4280. avail_eth_qsets, adap->params.nports);
  4281. return -ENOMEM;
  4282. }
  4283. /* Count the number of 10Gb/s or better ports */
  4284. for_each_port(adap, i)
  4285. n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
  4286. #ifdef CONFIG_CHELSIO_T4_DCB
  4287. /* For Data Center Bridging support we need to be able to support up
  4288. * to 8 Traffic Priorities; each of which will be assigned to its
  4289. * own TX Queue in order to prevent Head-Of-Line Blocking.
  4290. */
  4291. if (adap->params.nports * 8 > avail_eth_qsets) {
  4292. dev_err(adap->pdev_dev, "DCB avail_eth_qsets=%d < %d!\n",
  4293. avail_eth_qsets, adap->params.nports * 8);
  4294. return -ENOMEM;
  4295. }
  4296. for_each_port(adap, i) {
  4297. struct port_info *pi = adap2pinfo(adap, i);
  4298. pi->first_qset = qidx;
  4299. pi->nqsets = is_kdump_kernel() ? 1 : 8;
  4300. qidx += pi->nqsets;
  4301. }
  4302. #else /* !CONFIG_CHELSIO_T4_DCB */
  4303. /*
  4304. * We default to 1 queue per non-10G port and up to # of cores queues
  4305. * per 10G port.
  4306. */
  4307. if (n10g)
  4308. q10g = (avail_eth_qsets - (adap->params.nports - n10g)) / n10g;
  4309. if (q10g > netif_get_num_default_rss_queues())
  4310. q10g = netif_get_num_default_rss_queues();
  4311. if (is_kdump_kernel())
  4312. q10g = 1;
  4313. for_each_port(adap, i) {
  4314. struct port_info *pi = adap2pinfo(adap, i);
  4315. pi->first_qset = qidx;
  4316. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  4317. qidx += pi->nqsets;
  4318. }
  4319. #endif /* !CONFIG_CHELSIO_T4_DCB */
  4320. s->ethqsets = qidx;
  4321. s->max_ethqsets = qidx; /* MSI-X may lower it later */
  4322. if (is_uld(adap)) {
  4323. /*
  4324. * For offload we use 1 queue/channel if all ports are up to 1G,
  4325. * otherwise we divide all available queues amongst the channels
  4326. * capped by the number of available cores.
  4327. */
  4328. if (n10g) {
  4329. i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
  4330. s->ofldqsets = roundup(i, adap->params.nports);
  4331. } else {
  4332. s->ofldqsets = adap->params.nports;
  4333. }
  4334. }
  4335. for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
  4336. struct sge_eth_rxq *r = &s->ethrxq[i];
  4337. init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
  4338. r->fl.size = 72;
  4339. }
  4340. for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
  4341. s->ethtxq[i].q.size = 1024;
  4342. for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
  4343. s->ctrlq[i].q.size = 512;
  4344. if (!is_t4(adap->params.chip))
  4345. s->ptptxq.q.size = 8;
  4346. init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
  4347. init_rspq(adap, &s->intrq, 0, 1, 512, 64);
  4348. return 0;
  4349. }
  4350. /*
  4351. * Reduce the number of Ethernet queues across all ports to at most n.
  4352. * n provides at least one queue per port.
  4353. */
  4354. static void reduce_ethqs(struct adapter *adap, int n)
  4355. {
  4356. int i;
  4357. struct port_info *pi;
  4358. while (n < adap->sge.ethqsets)
  4359. for_each_port(adap, i) {
  4360. pi = adap2pinfo(adap, i);
  4361. if (pi->nqsets > 1) {
  4362. pi->nqsets--;
  4363. adap->sge.ethqsets--;
  4364. if (adap->sge.ethqsets <= n)
  4365. break;
  4366. }
  4367. }
  4368. n = 0;
  4369. for_each_port(adap, i) {
  4370. pi = adap2pinfo(adap, i);
  4371. pi->first_qset = n;
  4372. n += pi->nqsets;
  4373. }
  4374. }
  4375. static int get_msix_info(struct adapter *adap)
  4376. {
  4377. struct uld_msix_info *msix_info;
  4378. unsigned int max_ingq = 0;
  4379. if (is_offload(adap))
  4380. max_ingq += MAX_OFLD_QSETS * adap->num_ofld_uld;
  4381. if (is_pci_uld(adap))
  4382. max_ingq += MAX_OFLD_QSETS * adap->num_uld;
  4383. if (!max_ingq)
  4384. goto out;
  4385. msix_info = kcalloc(max_ingq, sizeof(*msix_info), GFP_KERNEL);
  4386. if (!msix_info)
  4387. return -ENOMEM;
  4388. adap->msix_bmap_ulds.msix_bmap = kcalloc(BITS_TO_LONGS(max_ingq),
  4389. sizeof(long), GFP_KERNEL);
  4390. if (!adap->msix_bmap_ulds.msix_bmap) {
  4391. kfree(msix_info);
  4392. return -ENOMEM;
  4393. }
  4394. spin_lock_init(&adap->msix_bmap_ulds.lock);
  4395. adap->msix_info_ulds = msix_info;
  4396. out:
  4397. return 0;
  4398. }
  4399. static void free_msix_info(struct adapter *adap)
  4400. {
  4401. if (!(adap->num_uld && adap->num_ofld_uld))
  4402. return;
  4403. kfree(adap->msix_info_ulds);
  4404. kfree(adap->msix_bmap_ulds.msix_bmap);
  4405. }
  4406. /* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
  4407. #define EXTRA_VECS 2
  4408. static int enable_msix(struct adapter *adap)
  4409. {
  4410. int ofld_need = 0, uld_need = 0;
  4411. int i, j, want, need, allocated;
  4412. struct sge *s = &adap->sge;
  4413. unsigned int nchan = adap->params.nports;
  4414. struct msix_entry *entries;
  4415. int max_ingq = MAX_INGQ;
  4416. if (is_pci_uld(adap))
  4417. max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
  4418. if (is_offload(adap))
  4419. max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
  4420. entries = kmalloc_array(max_ingq + 1, sizeof(*entries),
  4421. GFP_KERNEL);
  4422. if (!entries)
  4423. return -ENOMEM;
  4424. /* map for msix */
  4425. if (get_msix_info(adap)) {
  4426. adap->params.offload = 0;
  4427. adap->params.crypto = 0;
  4428. }
  4429. for (i = 0; i < max_ingq + 1; ++i)
  4430. entries[i].entry = i;
  4431. want = s->max_ethqsets + EXTRA_VECS;
  4432. if (is_offload(adap)) {
  4433. want += adap->num_ofld_uld * s->ofldqsets;
  4434. ofld_need = adap->num_ofld_uld * nchan;
  4435. }
  4436. if (is_pci_uld(adap)) {
  4437. want += adap->num_uld * s->ofldqsets;
  4438. uld_need = adap->num_uld * nchan;
  4439. }
  4440. #ifdef CONFIG_CHELSIO_T4_DCB
  4441. /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
  4442. * each port.
  4443. */
  4444. need = 8 * adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  4445. #else
  4446. need = adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  4447. #endif
  4448. allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
  4449. if (allocated < 0) {
  4450. dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
  4451. " not using MSI-X\n");
  4452. kfree(entries);
  4453. return allocated;
  4454. }
  4455. /* Distribute available vectors to the various queue groups.
  4456. * Every group gets its minimum requirement and NIC gets top
  4457. * priority for leftovers.
  4458. */
  4459. i = allocated - EXTRA_VECS - ofld_need - uld_need;
  4460. if (i < s->max_ethqsets) {
  4461. s->max_ethqsets = i;
  4462. if (i < s->ethqsets)
  4463. reduce_ethqs(adap, i);
  4464. }
  4465. if (is_uld(adap)) {
  4466. if (allocated < want)
  4467. s->nqs_per_uld = nchan;
  4468. else
  4469. s->nqs_per_uld = s->ofldqsets;
  4470. }
  4471. for (i = 0; i < (s->max_ethqsets + EXTRA_VECS); ++i)
  4472. adap->msix_info[i].vec = entries[i].vector;
  4473. if (is_uld(adap)) {
  4474. for (j = 0 ; i < allocated; ++i, j++) {
  4475. adap->msix_info_ulds[j].vec = entries[i].vector;
  4476. adap->msix_info_ulds[j].idx = i;
  4477. }
  4478. adap->msix_bmap_ulds.mapsize = j;
  4479. }
  4480. dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
  4481. "nic %d per uld %d\n",
  4482. allocated, s->max_ethqsets, s->nqs_per_uld);
  4483. kfree(entries);
  4484. return 0;
  4485. }
  4486. #undef EXTRA_VECS
  4487. static int init_rss(struct adapter *adap)
  4488. {
  4489. unsigned int i;
  4490. int err;
  4491. err = t4_init_rss_mode(adap, adap->mbox);
  4492. if (err)
  4493. return err;
  4494. for_each_port(adap, i) {
  4495. struct port_info *pi = adap2pinfo(adap, i);
  4496. pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
  4497. if (!pi->rss)
  4498. return -ENOMEM;
  4499. }
  4500. return 0;
  4501. }
  4502. /* Dump basic information about the adapter */
  4503. static void print_adapter_info(struct adapter *adapter)
  4504. {
  4505. /* Hardware/Firmware/etc. Version/Revision IDs */
  4506. t4_dump_version_info(adapter);
  4507. /* Software/Hardware configuration */
  4508. dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
  4509. is_offload(adapter) ? "R" : "",
  4510. ((adapter->flags & USING_MSIX) ? "MSI-X" :
  4511. (adapter->flags & USING_MSI) ? "MSI" : ""),
  4512. is_offload(adapter) ? "Offload" : "non-Offload");
  4513. }
  4514. static void print_port_info(const struct net_device *dev)
  4515. {
  4516. char buf[80];
  4517. char *bufp = buf;
  4518. const struct port_info *pi = netdev_priv(dev);
  4519. const struct adapter *adap = pi->adapter;
  4520. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M)
  4521. bufp += sprintf(bufp, "100M/");
  4522. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G)
  4523. bufp += sprintf(bufp, "1G/");
  4524. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G)
  4525. bufp += sprintf(bufp, "10G/");
  4526. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G)
  4527. bufp += sprintf(bufp, "25G/");
  4528. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G)
  4529. bufp += sprintf(bufp, "40G/");
  4530. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G)
  4531. bufp += sprintf(bufp, "50G/");
  4532. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G)
  4533. bufp += sprintf(bufp, "100G/");
  4534. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_200G)
  4535. bufp += sprintf(bufp, "200G/");
  4536. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_400G)
  4537. bufp += sprintf(bufp, "400G/");
  4538. if (bufp != buf)
  4539. --bufp;
  4540. sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
  4541. netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
  4542. dev->name, adap->params.vpd.id, adap->name, buf);
  4543. }
  4544. /*
  4545. * Free the following resources:
  4546. * - memory used for tables
  4547. * - MSI/MSI-X
  4548. * - net devices
  4549. * - resources FW is holding for us
  4550. */
  4551. static void free_some_resources(struct adapter *adapter)
  4552. {
  4553. unsigned int i;
  4554. kvfree(adapter->mps_encap);
  4555. kvfree(adapter->smt);
  4556. kvfree(adapter->l2t);
  4557. kvfree(adapter->srq);
  4558. t4_cleanup_sched(adapter);
  4559. kvfree(adapter->tids.tid_tab);
  4560. cxgb4_cleanup_tc_flower(adapter);
  4561. cxgb4_cleanup_tc_u32(adapter);
  4562. kfree(adapter->sge.egr_map);
  4563. kfree(adapter->sge.ingr_map);
  4564. kfree(adapter->sge.starving_fl);
  4565. kfree(adapter->sge.txq_maperr);
  4566. #ifdef CONFIG_DEBUG_FS
  4567. kfree(adapter->sge.blocked_fl);
  4568. #endif
  4569. disable_msi(adapter);
  4570. for_each_port(adapter, i)
  4571. if (adapter->port[i]) {
  4572. struct port_info *pi = adap2pinfo(adapter, i);
  4573. if (pi->viid != 0)
  4574. t4_free_vi(adapter, adapter->mbox, adapter->pf,
  4575. 0, pi->viid);
  4576. kfree(adap2pinfo(adapter, i)->rss);
  4577. free_netdev(adapter->port[i]);
  4578. }
  4579. if (adapter->flags & FW_OK)
  4580. t4_fw_bye(adapter, adapter->pf);
  4581. }
  4582. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  4583. #define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
  4584. NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
  4585. #define SEGMENT_SIZE 128
  4586. static int t4_get_chip_type(struct adapter *adap, int ver)
  4587. {
  4588. u32 pl_rev = REV_G(t4_read_reg(adap, PL_REV_A));
  4589. switch (ver) {
  4590. case CHELSIO_T4:
  4591. return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  4592. case CHELSIO_T5:
  4593. return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  4594. case CHELSIO_T6:
  4595. return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  4596. default:
  4597. break;
  4598. }
  4599. return -EINVAL;
  4600. }
  4601. #ifdef CONFIG_PCI_IOV
  4602. static void cxgb4_mgmt_setup(struct net_device *dev)
  4603. {
  4604. dev->type = ARPHRD_NONE;
  4605. dev->mtu = 0;
  4606. dev->hard_header_len = 0;
  4607. dev->addr_len = 0;
  4608. dev->tx_queue_len = 0;
  4609. dev->flags |= IFF_NOARP;
  4610. dev->priv_flags |= IFF_NO_QUEUE;
  4611. /* Initialize the device structure. */
  4612. dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
  4613. dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
  4614. }
  4615. static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
  4616. {
  4617. struct adapter *adap = pci_get_drvdata(pdev);
  4618. int err = 0;
  4619. int current_vfs = pci_num_vf(pdev);
  4620. u32 pcie_fw;
  4621. pcie_fw = readl(adap->regs + PCIE_FW_A);
  4622. /* Check if fw is initialized */
  4623. if (!(pcie_fw & PCIE_FW_INIT_F)) {
  4624. dev_warn(&pdev->dev, "Device not initialized\n");
  4625. return -EOPNOTSUPP;
  4626. }
  4627. /* If any of the VF's is already assigned to Guest OS, then
  4628. * SRIOV for the same cannot be modified
  4629. */
  4630. if (current_vfs && pci_vfs_assigned(pdev)) {
  4631. dev_err(&pdev->dev,
  4632. "Cannot modify SR-IOV while VFs are assigned\n");
  4633. return current_vfs;
  4634. }
  4635. /* Note that the upper-level code ensures that we're never called with
  4636. * a non-zero "num_vfs" when we already have VFs instantiated. But
  4637. * it never hurts to code defensively.
  4638. */
  4639. if (num_vfs != 0 && current_vfs != 0)
  4640. return -EBUSY;
  4641. /* Nothing to do for no change. */
  4642. if (num_vfs == current_vfs)
  4643. return num_vfs;
  4644. /* Disable SRIOV when zero is passed. */
  4645. if (!num_vfs) {
  4646. pci_disable_sriov(pdev);
  4647. /* free VF Management Interface */
  4648. unregister_netdev(adap->port[0]);
  4649. free_netdev(adap->port[0]);
  4650. adap->port[0] = NULL;
  4651. /* free VF resources */
  4652. adap->num_vfs = 0;
  4653. kfree(adap->vfinfo);
  4654. adap->vfinfo = NULL;
  4655. return 0;
  4656. }
  4657. if (!current_vfs) {
  4658. struct fw_pfvf_cmd port_cmd, port_rpl;
  4659. struct net_device *netdev;
  4660. unsigned int pmask, port;
  4661. struct pci_dev *pbridge;
  4662. struct port_info *pi;
  4663. char name[IFNAMSIZ];
  4664. u32 devcap2;
  4665. u16 flags;
  4666. int pos;
  4667. /* If we want to instantiate Virtual Functions, then our
  4668. * parent bridge's PCI-E needs to support Alternative Routing
  4669. * ID (ARI) because our VFs will show up at function offset 8
  4670. * and above.
  4671. */
  4672. pbridge = pdev->bus->self;
  4673. pos = pci_find_capability(pbridge, PCI_CAP_ID_EXP);
  4674. pci_read_config_word(pbridge, pos + PCI_EXP_FLAGS, &flags);
  4675. pci_read_config_dword(pbridge, pos + PCI_EXP_DEVCAP2, &devcap2);
  4676. if ((flags & PCI_EXP_FLAGS_VERS) < 2 ||
  4677. !(devcap2 & PCI_EXP_DEVCAP2_ARI)) {
  4678. /* Our parent bridge does not support ARI so issue a
  4679. * warning and skip instantiating the VFs. They
  4680. * won't be reachable.
  4681. */
  4682. dev_warn(&pdev->dev, "Parent bridge %02x:%02x.%x doesn't support ARI; can't instantiate Virtual Functions\n",
  4683. pbridge->bus->number, PCI_SLOT(pbridge->devfn),
  4684. PCI_FUNC(pbridge->devfn));
  4685. return -ENOTSUPP;
  4686. }
  4687. memset(&port_cmd, 0, sizeof(port_cmd));
  4688. port_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) |
  4689. FW_CMD_REQUEST_F |
  4690. FW_CMD_READ_F |
  4691. FW_PFVF_CMD_PFN_V(adap->pf) |
  4692. FW_PFVF_CMD_VFN_V(0));
  4693. port_cmd.retval_len16 = cpu_to_be32(FW_LEN16(port_cmd));
  4694. err = t4_wr_mbox(adap, adap->mbox, &port_cmd, sizeof(port_cmd),
  4695. &port_rpl);
  4696. if (err)
  4697. return err;
  4698. pmask = FW_PFVF_CMD_PMASK_G(be32_to_cpu(port_rpl.type_to_neq));
  4699. port = ffs(pmask) - 1;
  4700. /* Allocate VF Management Interface. */
  4701. snprintf(name, IFNAMSIZ, "mgmtpf%d,%d", adap->adap_idx,
  4702. adap->pf);
  4703. netdev = alloc_netdev(sizeof(struct port_info),
  4704. name, NET_NAME_UNKNOWN, cxgb4_mgmt_setup);
  4705. if (!netdev)
  4706. return -ENOMEM;
  4707. pi = netdev_priv(netdev);
  4708. pi->adapter = adap;
  4709. pi->lport = port;
  4710. pi->tx_chan = port;
  4711. SET_NETDEV_DEV(netdev, &pdev->dev);
  4712. adap->port[0] = netdev;
  4713. pi->port_id = 0;
  4714. err = register_netdev(adap->port[0]);
  4715. if (err) {
  4716. pr_info("Unable to register VF mgmt netdev %s\n", name);
  4717. free_netdev(adap->port[0]);
  4718. adap->port[0] = NULL;
  4719. return err;
  4720. }
  4721. /* Allocate and set up VF Information. */
  4722. adap->vfinfo = kcalloc(pci_sriov_get_totalvfs(pdev),
  4723. sizeof(struct vf_info), GFP_KERNEL);
  4724. if (!adap->vfinfo) {
  4725. unregister_netdev(adap->port[0]);
  4726. free_netdev(adap->port[0]);
  4727. adap->port[0] = NULL;
  4728. return -ENOMEM;
  4729. }
  4730. cxgb4_mgmt_fill_vf_station_mac_addr(adap);
  4731. }
  4732. /* Instantiate the requested number of VFs. */
  4733. err = pci_enable_sriov(pdev, num_vfs);
  4734. if (err) {
  4735. pr_info("Unable to instantiate %d VFs\n", num_vfs);
  4736. if (!current_vfs) {
  4737. unregister_netdev(adap->port[0]);
  4738. free_netdev(adap->port[0]);
  4739. adap->port[0] = NULL;
  4740. kfree(adap->vfinfo);
  4741. adap->vfinfo = NULL;
  4742. }
  4743. return err;
  4744. }
  4745. adap->num_vfs = num_vfs;
  4746. return num_vfs;
  4747. }
  4748. #endif /* CONFIG_PCI_IOV */
  4749. static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4750. {
  4751. struct net_device *netdev;
  4752. struct adapter *adapter;
  4753. static int adap_idx = 1;
  4754. int s_qpp, qpp, num_seg;
  4755. struct port_info *pi;
  4756. bool highdma = false;
  4757. enum chip_type chip;
  4758. void __iomem *regs;
  4759. int func, chip_ver;
  4760. u16 device_id;
  4761. int i, err;
  4762. u32 whoami;
  4763. printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  4764. err = pci_request_regions(pdev, KBUILD_MODNAME);
  4765. if (err) {
  4766. /* Just info, some other driver may have claimed the device. */
  4767. dev_info(&pdev->dev, "cannot obtain PCI resources\n");
  4768. return err;
  4769. }
  4770. err = pci_enable_device(pdev);
  4771. if (err) {
  4772. dev_err(&pdev->dev, "cannot enable PCI device\n");
  4773. goto out_release_regions;
  4774. }
  4775. regs = pci_ioremap_bar(pdev, 0);
  4776. if (!regs) {
  4777. dev_err(&pdev->dev, "cannot map device registers\n");
  4778. err = -ENOMEM;
  4779. goto out_disable_device;
  4780. }
  4781. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  4782. if (!adapter) {
  4783. err = -ENOMEM;
  4784. goto out_unmap_bar0;
  4785. }
  4786. adapter->regs = regs;
  4787. err = t4_wait_dev_ready(regs);
  4788. if (err < 0)
  4789. goto out_free_adapter;
  4790. /* We control everything through one PF */
  4791. whoami = t4_read_reg(adapter, PL_WHOAMI_A);
  4792. pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
  4793. chip = t4_get_chip_type(adapter, CHELSIO_PCI_ID_VER(device_id));
  4794. if ((int)chip < 0) {
  4795. dev_err(&pdev->dev, "Device %d is not supported\n", device_id);
  4796. err = chip;
  4797. goto out_free_adapter;
  4798. }
  4799. chip_ver = CHELSIO_CHIP_VERSION(chip);
  4800. func = chip_ver <= CHELSIO_T5 ?
  4801. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4802. adapter->pdev = pdev;
  4803. adapter->pdev_dev = &pdev->dev;
  4804. adapter->name = pci_name(pdev);
  4805. adapter->mbox = func;
  4806. adapter->pf = func;
  4807. adapter->params.chip = chip;
  4808. adapter->adap_idx = adap_idx;
  4809. adapter->msg_enable = DFLT_MSG_ENABLE;
  4810. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  4811. (sizeof(struct mbox_cmd) *
  4812. T4_OS_LOG_MBOX_CMDS),
  4813. GFP_KERNEL);
  4814. if (!adapter->mbox_log) {
  4815. err = -ENOMEM;
  4816. goto out_free_adapter;
  4817. }
  4818. spin_lock_init(&adapter->mbox_lock);
  4819. INIT_LIST_HEAD(&adapter->mlist.list);
  4820. adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
  4821. pci_set_drvdata(pdev, adapter);
  4822. if (func != ent->driver_data) {
  4823. pci_disable_device(pdev);
  4824. pci_save_state(pdev); /* to restore SR-IOV later */
  4825. return 0;
  4826. }
  4827. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  4828. highdma = true;
  4829. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4830. if (err) {
  4831. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
  4832. "coherent allocations\n");
  4833. goto out_free_adapter;
  4834. }
  4835. } else {
  4836. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4837. if (err) {
  4838. dev_err(&pdev->dev, "no usable DMA configuration\n");
  4839. goto out_free_adapter;
  4840. }
  4841. }
  4842. pci_enable_pcie_error_reporting(pdev);
  4843. pci_set_master(pdev);
  4844. pci_save_state(pdev);
  4845. adap_idx++;
  4846. adapter->workq = create_singlethread_workqueue("cxgb4");
  4847. if (!adapter->workq) {
  4848. err = -ENOMEM;
  4849. goto out_free_adapter;
  4850. }
  4851. /* PCI device has been enabled */
  4852. adapter->flags |= DEV_ENABLED;
  4853. memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
  4854. /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
  4855. * Ingress Packet Data to Free List Buffers in order to allow for
  4856. * chipset performance optimizations between the Root Complex and
  4857. * Memory Controllers. (Messages to the associated Ingress Queue
  4858. * notifying new Packet Placement in the Free Lists Buffers will be
  4859. * send without the Relaxed Ordering Attribute thus guaranteeing that
  4860. * all preceding PCIe Transaction Layer Packets will be processed
  4861. * first.) But some Root Complexes have various issues with Upstream
  4862. * Transaction Layer Packets with the Relaxed Ordering Attribute set.
  4863. * The PCIe devices which under the Root Complexes will be cleared the
  4864. * Relaxed Ordering bit in the configuration space, So we check our
  4865. * PCIe configuration space to see if it's flagged with advice against
  4866. * using Relaxed Ordering.
  4867. */
  4868. if (!pcie_relaxed_ordering_enabled(pdev))
  4869. adapter->flags |= ROOT_NO_RELAXED_ORDERING;
  4870. spin_lock_init(&adapter->stats_lock);
  4871. spin_lock_init(&adapter->tid_release_lock);
  4872. spin_lock_init(&adapter->win0_lock);
  4873. INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
  4874. INIT_WORK(&adapter->db_full_task, process_db_full);
  4875. INIT_WORK(&adapter->db_drop_task, process_db_drop);
  4876. INIT_WORK(&adapter->fatal_err_notify_task, notify_fatal_err);
  4877. err = t4_prep_adapter(adapter);
  4878. if (err)
  4879. goto out_free_adapter;
  4880. if (is_kdump_kernel()) {
  4881. /* Collect hardware state and append to /proc/vmcore */
  4882. err = cxgb4_cudbg_vmcore_add_dump(adapter);
  4883. if (err) {
  4884. dev_warn(adapter->pdev_dev,
  4885. "Fail collecting vmcore device dump, err: %d. Continuing\n",
  4886. err);
  4887. err = 0;
  4888. }
  4889. }
  4890. if (!is_t4(adapter->params.chip)) {
  4891. s_qpp = (QUEUESPERPAGEPF0_S +
  4892. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
  4893. adapter->pf);
  4894. qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
  4895. SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
  4896. num_seg = PAGE_SIZE / SEGMENT_SIZE;
  4897. /* Each segment size is 128B. Write coalescing is enabled only
  4898. * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
  4899. * queue is less no of segments that can be accommodated in
  4900. * a page size.
  4901. */
  4902. if (qpp > num_seg) {
  4903. dev_err(&pdev->dev,
  4904. "Incorrect number of egress queues per page\n");
  4905. err = -EINVAL;
  4906. goto out_free_adapter;
  4907. }
  4908. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  4909. pci_resource_len(pdev, 2));
  4910. if (!adapter->bar2) {
  4911. dev_err(&pdev->dev, "cannot map device bar2 region\n");
  4912. err = -ENOMEM;
  4913. goto out_free_adapter;
  4914. }
  4915. }
  4916. setup_memwin(adapter);
  4917. err = adap_init0(adapter);
  4918. #ifdef CONFIG_DEBUG_FS
  4919. bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
  4920. #endif
  4921. setup_memwin_rdma(adapter);
  4922. if (err)
  4923. goto out_unmap_bar;
  4924. /* configure SGE_STAT_CFG_A to read WC stats */
  4925. if (!is_t4(adapter->params.chip))
  4926. t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
  4927. (is_t5(adapter->params.chip) ? STATMODE_V(0) :
  4928. T6_STATMODE_V(0)));
  4929. for_each_port(adapter, i) {
  4930. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  4931. MAX_ETH_QSETS);
  4932. if (!netdev) {
  4933. err = -ENOMEM;
  4934. goto out_free_dev;
  4935. }
  4936. SET_NETDEV_DEV(netdev, &pdev->dev);
  4937. adapter->port[i] = netdev;
  4938. pi = netdev_priv(netdev);
  4939. pi->adapter = adapter;
  4940. pi->xact_addr_filt = -1;
  4941. pi->port_id = i;
  4942. netdev->irq = pdev->irq;
  4943. netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
  4944. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  4945. NETIF_F_RXCSUM | NETIF_F_RXHASH |
  4946. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
  4947. NETIF_F_HW_TC;
  4948. if (chip_ver > CHELSIO_T5) {
  4949. netdev->hw_enc_features |= NETIF_F_IP_CSUM |
  4950. NETIF_F_IPV6_CSUM |
  4951. NETIF_F_RXCSUM |
  4952. NETIF_F_GSO_UDP_TUNNEL |
  4953. NETIF_F_TSO | NETIF_F_TSO6;
  4954. netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
  4955. }
  4956. if (highdma)
  4957. netdev->hw_features |= NETIF_F_HIGHDMA;
  4958. netdev->features |= netdev->hw_features;
  4959. netdev->vlan_features = netdev->features & VLAN_FEAT;
  4960. netdev->priv_flags |= IFF_UNICAST_FLT;
  4961. /* MTU range: 81 - 9600 */
  4962. netdev->min_mtu = 81; /* accommodate SACK */
  4963. netdev->max_mtu = MAX_MTU;
  4964. netdev->netdev_ops = &cxgb4_netdev_ops;
  4965. #ifdef CONFIG_CHELSIO_T4_DCB
  4966. netdev->dcbnl_ops = &cxgb4_dcb_ops;
  4967. cxgb4_dcb_state_init(netdev);
  4968. cxgb4_dcb_version_init(netdev);
  4969. #endif
  4970. cxgb4_set_ethtool_ops(netdev);
  4971. }
  4972. cxgb4_init_ethtool_dump(adapter);
  4973. pci_set_drvdata(pdev, adapter);
  4974. if (adapter->flags & FW_OK) {
  4975. err = t4_port_init(adapter, func, func, 0);
  4976. if (err)
  4977. goto out_free_dev;
  4978. } else if (adapter->params.nports == 1) {
  4979. /* If we don't have a connection to the firmware -- possibly
  4980. * because of an error -- grab the raw VPD parameters so we
  4981. * can set the proper MAC Address on the debug network
  4982. * interface that we've created.
  4983. */
  4984. u8 hw_addr[ETH_ALEN];
  4985. u8 *na = adapter->params.vpd.na;
  4986. err = t4_get_raw_vpd_params(adapter, &adapter->params.vpd);
  4987. if (!err) {
  4988. for (i = 0; i < ETH_ALEN; i++)
  4989. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  4990. hex2val(na[2 * i + 1]));
  4991. t4_set_hw_addr(adapter, 0, hw_addr);
  4992. }
  4993. }
  4994. if (!(adapter->flags & FW_OK))
  4995. goto fw_attach_fail;
  4996. /* Configure queues and allocate tables now, they can be needed as
  4997. * soon as the first register_netdev completes.
  4998. */
  4999. err = cfg_queues(adapter);
  5000. if (err)
  5001. goto out_free_dev;
  5002. adapter->smt = t4_init_smt();
  5003. if (!adapter->smt) {
  5004. /* We tolerate a lack of SMT, giving up some functionality */
  5005. dev_warn(&pdev->dev, "could not allocate SMT, continuing\n");
  5006. }
  5007. adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
  5008. if (!adapter->l2t) {
  5009. /* We tolerate a lack of L2T, giving up some functionality */
  5010. dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
  5011. adapter->params.offload = 0;
  5012. }
  5013. adapter->mps_encap = kvcalloc(adapter->params.arch.mps_tcam_size,
  5014. sizeof(struct mps_encap_entry),
  5015. GFP_KERNEL);
  5016. if (!adapter->mps_encap)
  5017. dev_warn(&pdev->dev, "could not allocate MPS Encap entries, continuing\n");
  5018. #if IS_ENABLED(CONFIG_IPV6)
  5019. if (chip_ver <= CHELSIO_T5 &&
  5020. (!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
  5021. /* CLIP functionality is not present in hardware,
  5022. * hence disable all offload features
  5023. */
  5024. dev_warn(&pdev->dev,
  5025. "CLIP not enabled in hardware, continuing\n");
  5026. adapter->params.offload = 0;
  5027. } else {
  5028. adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
  5029. adapter->clipt_end);
  5030. if (!adapter->clipt) {
  5031. /* We tolerate a lack of clip_table, giving up
  5032. * some functionality
  5033. */
  5034. dev_warn(&pdev->dev,
  5035. "could not allocate Clip table, continuing\n");
  5036. adapter->params.offload = 0;
  5037. }
  5038. }
  5039. #endif
  5040. for_each_port(adapter, i) {
  5041. pi = adap2pinfo(adapter, i);
  5042. pi->sched_tbl = t4_init_sched(adapter->params.nsched_cls);
  5043. if (!pi->sched_tbl)
  5044. dev_warn(&pdev->dev,
  5045. "could not activate scheduling on port %d\n",
  5046. i);
  5047. }
  5048. if (tid_init(&adapter->tids) < 0) {
  5049. dev_warn(&pdev->dev, "could not allocate TID table, "
  5050. "continuing\n");
  5051. adapter->params.offload = 0;
  5052. } else {
  5053. adapter->tc_u32 = cxgb4_init_tc_u32(adapter);
  5054. if (!adapter->tc_u32)
  5055. dev_warn(&pdev->dev,
  5056. "could not offload tc u32, continuing\n");
  5057. if (cxgb4_init_tc_flower(adapter))
  5058. dev_warn(&pdev->dev,
  5059. "could not offload tc flower, continuing\n");
  5060. }
  5061. if (is_offload(adapter) || is_hashfilter(adapter)) {
  5062. if (t4_read_reg(adapter, LE_DB_CONFIG_A) & HASHEN_F) {
  5063. u32 hash_base, hash_reg;
  5064. if (chip_ver <= CHELSIO_T5) {
  5065. hash_reg = LE_DB_TID_HASHBASE_A;
  5066. hash_base = t4_read_reg(adapter, hash_reg);
  5067. adapter->tids.hash_base = hash_base / 4;
  5068. } else {
  5069. hash_reg = T6_LE_DB_HASH_TID_BASE_A;
  5070. hash_base = t4_read_reg(adapter, hash_reg);
  5071. adapter->tids.hash_base = hash_base;
  5072. }
  5073. }
  5074. }
  5075. /* See what interrupts we'll be using */
  5076. if (msi > 1 && enable_msix(adapter) == 0)
  5077. adapter->flags |= USING_MSIX;
  5078. else if (msi > 0 && pci_enable_msi(pdev) == 0) {
  5079. adapter->flags |= USING_MSI;
  5080. if (msi > 1)
  5081. free_msix_info(adapter);
  5082. }
  5083. /* check for PCI Express bandwidth capabiltites */
  5084. pcie_print_link_status(pdev);
  5085. err = init_rss(adapter);
  5086. if (err)
  5087. goto out_free_dev;
  5088. err = setup_fw_sge_queues(adapter);
  5089. if (err) {
  5090. dev_err(adapter->pdev_dev,
  5091. "FW sge queue allocation failed, err %d", err);
  5092. goto out_free_dev;
  5093. }
  5094. fw_attach_fail:
  5095. /*
  5096. * The card is now ready to go. If any errors occur during device
  5097. * registration we do not fail the whole card but rather proceed only
  5098. * with the ports we manage to register successfully. However we must
  5099. * register at least one net device.
  5100. */
  5101. for_each_port(adapter, i) {
  5102. pi = adap2pinfo(adapter, i);
  5103. adapter->port[i]->dev_port = pi->lport;
  5104. netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
  5105. netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
  5106. netif_carrier_off(adapter->port[i]);
  5107. err = register_netdev(adapter->port[i]);
  5108. if (err)
  5109. break;
  5110. adapter->chan_map[pi->tx_chan] = i;
  5111. print_port_info(adapter->port[i]);
  5112. }
  5113. if (i == 0) {
  5114. dev_err(&pdev->dev, "could not register any net devices\n");
  5115. goto out_free_dev;
  5116. }
  5117. if (err) {
  5118. dev_warn(&pdev->dev, "only %d net devices registered\n", i);
  5119. err = 0;
  5120. }
  5121. if (cxgb4_debugfs_root) {
  5122. adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
  5123. cxgb4_debugfs_root);
  5124. setup_debugfs(adapter);
  5125. }
  5126. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  5127. pdev->needs_freset = 1;
  5128. if (is_uld(adapter)) {
  5129. mutex_lock(&uld_mutex);
  5130. list_add_tail(&adapter->list_node, &adapter_list);
  5131. mutex_unlock(&uld_mutex);
  5132. }
  5133. if (!is_t4(adapter->params.chip))
  5134. cxgb4_ptp_init(adapter);
  5135. print_adapter_info(adapter);
  5136. return 0;
  5137. out_free_dev:
  5138. t4_free_sge_resources(adapter);
  5139. free_some_resources(adapter);
  5140. if (adapter->flags & USING_MSIX)
  5141. free_msix_info(adapter);
  5142. if (adapter->num_uld || adapter->num_ofld_uld)
  5143. t4_uld_mem_free(adapter);
  5144. out_unmap_bar:
  5145. if (!is_t4(adapter->params.chip))
  5146. iounmap(adapter->bar2);
  5147. out_free_adapter:
  5148. if (adapter->workq)
  5149. destroy_workqueue(adapter->workq);
  5150. kfree(adapter->mbox_log);
  5151. kfree(adapter);
  5152. out_unmap_bar0:
  5153. iounmap(regs);
  5154. out_disable_device:
  5155. pci_disable_pcie_error_reporting(pdev);
  5156. pci_disable_device(pdev);
  5157. out_release_regions:
  5158. pci_release_regions(pdev);
  5159. return err;
  5160. }
  5161. static void remove_one(struct pci_dev *pdev)
  5162. {
  5163. struct adapter *adapter = pci_get_drvdata(pdev);
  5164. if (!adapter) {
  5165. pci_release_regions(pdev);
  5166. return;
  5167. }
  5168. adapter->flags |= SHUTTING_DOWN;
  5169. if (adapter->pf == 4) {
  5170. int i;
  5171. /* Tear down per-adapter Work Queue first since it can contain
  5172. * references to our adapter data structure.
  5173. */
  5174. destroy_workqueue(adapter->workq);
  5175. if (is_uld(adapter)) {
  5176. detach_ulds(adapter);
  5177. t4_uld_clean_up(adapter);
  5178. }
  5179. adap_free_hma_mem(adapter);
  5180. disable_interrupts(adapter);
  5181. for_each_port(adapter, i)
  5182. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5183. unregister_netdev(adapter->port[i]);
  5184. debugfs_remove_recursive(adapter->debugfs_root);
  5185. if (!is_t4(adapter->params.chip))
  5186. cxgb4_ptp_stop(adapter);
  5187. /* If we allocated filters, free up state associated with any
  5188. * valid filters ...
  5189. */
  5190. clear_all_filters(adapter);
  5191. if (adapter->flags & FULL_INIT_DONE)
  5192. cxgb_down(adapter);
  5193. if (adapter->flags & USING_MSIX)
  5194. free_msix_info(adapter);
  5195. if (adapter->num_uld || adapter->num_ofld_uld)
  5196. t4_uld_mem_free(adapter);
  5197. free_some_resources(adapter);
  5198. #if IS_ENABLED(CONFIG_IPV6)
  5199. t4_cleanup_clip_tbl(adapter);
  5200. #endif
  5201. if (!is_t4(adapter->params.chip))
  5202. iounmap(adapter->bar2);
  5203. }
  5204. #ifdef CONFIG_PCI_IOV
  5205. else {
  5206. cxgb4_iov_configure(adapter->pdev, 0);
  5207. }
  5208. #endif
  5209. iounmap(adapter->regs);
  5210. pci_disable_pcie_error_reporting(pdev);
  5211. if ((adapter->flags & DEV_ENABLED)) {
  5212. pci_disable_device(pdev);
  5213. adapter->flags &= ~DEV_ENABLED;
  5214. }
  5215. pci_release_regions(pdev);
  5216. kfree(adapter->mbox_log);
  5217. synchronize_rcu();
  5218. kfree(adapter);
  5219. }
  5220. /* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
  5221. * delivery. This is essentially a stripped down version of the PCI remove()
  5222. * function where we do the minimal amount of work necessary to shutdown any
  5223. * further activity.
  5224. */
  5225. static void shutdown_one(struct pci_dev *pdev)
  5226. {
  5227. struct adapter *adapter = pci_get_drvdata(pdev);
  5228. /* As with remove_one() above (see extended comment), we only want do
  5229. * do cleanup on PCI Devices which went all the way through init_one()
  5230. * ...
  5231. */
  5232. if (!adapter) {
  5233. pci_release_regions(pdev);
  5234. return;
  5235. }
  5236. adapter->flags |= SHUTTING_DOWN;
  5237. if (adapter->pf == 4) {
  5238. int i;
  5239. for_each_port(adapter, i)
  5240. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5241. cxgb_close(adapter->port[i]);
  5242. if (is_uld(adapter)) {
  5243. detach_ulds(adapter);
  5244. t4_uld_clean_up(adapter);
  5245. }
  5246. disable_interrupts(adapter);
  5247. disable_msi(adapter);
  5248. t4_sge_stop(adapter);
  5249. if (adapter->flags & FW_OK)
  5250. t4_fw_bye(adapter, adapter->mbox);
  5251. }
  5252. }
  5253. static struct pci_driver cxgb4_driver = {
  5254. .name = KBUILD_MODNAME,
  5255. .id_table = cxgb4_pci_tbl,
  5256. .probe = init_one,
  5257. .remove = remove_one,
  5258. .shutdown = shutdown_one,
  5259. #ifdef CONFIG_PCI_IOV
  5260. .sriov_configure = cxgb4_iov_configure,
  5261. #endif
  5262. .err_handler = &cxgb4_eeh,
  5263. };
  5264. static int __init cxgb4_init_module(void)
  5265. {
  5266. int ret;
  5267. /* Debugfs support is optional, just warn if this fails */
  5268. cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  5269. if (!cxgb4_debugfs_root)
  5270. pr_warn("could not create debugfs entry, continuing\n");
  5271. ret = pci_register_driver(&cxgb4_driver);
  5272. if (ret < 0)
  5273. goto err_pci;
  5274. #if IS_ENABLED(CONFIG_IPV6)
  5275. if (!inet6addr_registered) {
  5276. ret = register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5277. if (ret)
  5278. pci_unregister_driver(&cxgb4_driver);
  5279. else
  5280. inet6addr_registered = true;
  5281. }
  5282. #endif
  5283. if (ret == 0)
  5284. return ret;
  5285. err_pci:
  5286. debugfs_remove(cxgb4_debugfs_root);
  5287. return ret;
  5288. }
  5289. static void __exit cxgb4_cleanup_module(void)
  5290. {
  5291. #if IS_ENABLED(CONFIG_IPV6)
  5292. if (inet6addr_registered) {
  5293. unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5294. inet6addr_registered = false;
  5295. }
  5296. #endif
  5297. pci_unregister_driver(&cxgb4_driver);
  5298. debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
  5299. }
  5300. module_init(cxgb4_init_module);
  5301. module_exit(cxgb4_cleanup_module);