cxgb4_main.c 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056
  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. return err;
  2000. irq_err:
  2001. dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
  2002. freeq:
  2003. t4_free_sge_resources(adap);
  2004. rel_lock:
  2005. mutex_unlock(&uld_mutex);
  2006. return err;
  2007. }
  2008. static void cxgb_down(struct adapter *adapter)
  2009. {
  2010. cancel_work_sync(&adapter->tid_release_task);
  2011. cancel_work_sync(&adapter->db_full_task);
  2012. cancel_work_sync(&adapter->db_drop_task);
  2013. adapter->tid_release_task_busy = false;
  2014. adapter->tid_release_head = NULL;
  2015. t4_sge_stop(adapter);
  2016. t4_free_sge_resources(adapter);
  2017. adapter->flags &= ~FULL_INIT_DONE;
  2018. }
  2019. /*
  2020. * net_device operations
  2021. */
  2022. static int cxgb_open(struct net_device *dev)
  2023. {
  2024. int err;
  2025. struct port_info *pi = netdev_priv(dev);
  2026. struct adapter *adapter = pi->adapter;
  2027. netif_carrier_off(dev);
  2028. if (!(adapter->flags & FULL_INIT_DONE)) {
  2029. err = cxgb_up(adapter);
  2030. if (err < 0)
  2031. return err;
  2032. }
  2033. /* It's possible that the basic port information could have
  2034. * changed since we first read it.
  2035. */
  2036. err = t4_update_port_info(pi);
  2037. if (err < 0)
  2038. return err;
  2039. err = link_start(dev);
  2040. if (!err)
  2041. netif_tx_start_all_queues(dev);
  2042. return err;
  2043. }
  2044. static int cxgb_close(struct net_device *dev)
  2045. {
  2046. struct port_info *pi = netdev_priv(dev);
  2047. struct adapter *adapter = pi->adapter;
  2048. int ret;
  2049. netif_tx_stop_all_queues(dev);
  2050. netif_carrier_off(dev);
  2051. ret = t4_enable_pi_params(adapter, adapter->pf, pi,
  2052. false, false, false);
  2053. #ifdef CONFIG_CHELSIO_T4_DCB
  2054. cxgb4_dcb_reset(dev);
  2055. dcb_tx_queue_prio_enable(dev, false);
  2056. #endif
  2057. return ret;
  2058. }
  2059. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  2060. __be32 sip, __be16 sport, __be16 vlan,
  2061. unsigned int queue, unsigned char port, unsigned char mask)
  2062. {
  2063. int ret;
  2064. struct filter_entry *f;
  2065. struct adapter *adap;
  2066. int i;
  2067. u8 *val;
  2068. adap = netdev2adap(dev);
  2069. /* Adjust stid to correct filter index */
  2070. stid -= adap->tids.sftid_base;
  2071. stid += adap->tids.nftids;
  2072. /* Check to make sure the filter requested is writable ...
  2073. */
  2074. f = &adap->tids.ftid_tab[stid];
  2075. ret = writable_filter(f);
  2076. if (ret)
  2077. return ret;
  2078. /* Clear out any old resources being used by the filter before
  2079. * we start constructing the new filter.
  2080. */
  2081. if (f->valid)
  2082. clear_filter(adap, f);
  2083. /* Clear out filter specifications */
  2084. memset(&f->fs, 0, sizeof(struct ch_filter_specification));
  2085. f->fs.val.lport = cpu_to_be16(sport);
  2086. f->fs.mask.lport = ~0;
  2087. val = (u8 *)&sip;
  2088. if ((val[0] | val[1] | val[2] | val[3]) != 0) {
  2089. for (i = 0; i < 4; i++) {
  2090. f->fs.val.lip[i] = val[i];
  2091. f->fs.mask.lip[i] = ~0;
  2092. }
  2093. if (adap->params.tp.vlan_pri_map & PORT_F) {
  2094. f->fs.val.iport = port;
  2095. f->fs.mask.iport = mask;
  2096. }
  2097. }
  2098. if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
  2099. f->fs.val.proto = IPPROTO_TCP;
  2100. f->fs.mask.proto = ~0;
  2101. }
  2102. f->fs.dirsteer = 1;
  2103. f->fs.iq = queue;
  2104. /* Mark filter as locked */
  2105. f->locked = 1;
  2106. f->fs.rpttid = 1;
  2107. /* Save the actual tid. We need this to get the corresponding
  2108. * filter entry structure in filter_rpl.
  2109. */
  2110. f->tid = stid + adap->tids.ftid_base;
  2111. ret = set_filter_wr(adap, stid);
  2112. if (ret) {
  2113. clear_filter(adap, f);
  2114. return ret;
  2115. }
  2116. return 0;
  2117. }
  2118. EXPORT_SYMBOL(cxgb4_create_server_filter);
  2119. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  2120. unsigned int queue, bool ipv6)
  2121. {
  2122. struct filter_entry *f;
  2123. struct adapter *adap;
  2124. adap = netdev2adap(dev);
  2125. /* Adjust stid to correct filter index */
  2126. stid -= adap->tids.sftid_base;
  2127. stid += adap->tids.nftids;
  2128. f = &adap->tids.ftid_tab[stid];
  2129. /* Unlock the filter */
  2130. f->locked = 0;
  2131. return delete_filter(adap, stid);
  2132. }
  2133. EXPORT_SYMBOL(cxgb4_remove_server_filter);
  2134. static void cxgb_get_stats(struct net_device *dev,
  2135. struct rtnl_link_stats64 *ns)
  2136. {
  2137. struct port_stats stats;
  2138. struct port_info *p = netdev_priv(dev);
  2139. struct adapter *adapter = p->adapter;
  2140. /* Block retrieving statistics during EEH error
  2141. * recovery. Otherwise, the recovery might fail
  2142. * and the PCI device will be removed permanently
  2143. */
  2144. spin_lock(&adapter->stats_lock);
  2145. if (!netif_device_present(dev)) {
  2146. spin_unlock(&adapter->stats_lock);
  2147. return;
  2148. }
  2149. t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
  2150. &p->stats_base);
  2151. spin_unlock(&adapter->stats_lock);
  2152. ns->tx_bytes = stats.tx_octets;
  2153. ns->tx_packets = stats.tx_frames;
  2154. ns->rx_bytes = stats.rx_octets;
  2155. ns->rx_packets = stats.rx_frames;
  2156. ns->multicast = stats.rx_mcast_frames;
  2157. /* detailed rx_errors */
  2158. ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
  2159. stats.rx_runt;
  2160. ns->rx_over_errors = 0;
  2161. ns->rx_crc_errors = stats.rx_fcs_err;
  2162. ns->rx_frame_errors = stats.rx_symbol_err;
  2163. ns->rx_dropped = stats.rx_ovflow0 + stats.rx_ovflow1 +
  2164. stats.rx_ovflow2 + stats.rx_ovflow3 +
  2165. stats.rx_trunc0 + stats.rx_trunc1 +
  2166. stats.rx_trunc2 + stats.rx_trunc3;
  2167. ns->rx_missed_errors = 0;
  2168. /* detailed tx_errors */
  2169. ns->tx_aborted_errors = 0;
  2170. ns->tx_carrier_errors = 0;
  2171. ns->tx_fifo_errors = 0;
  2172. ns->tx_heartbeat_errors = 0;
  2173. ns->tx_window_errors = 0;
  2174. ns->tx_errors = stats.tx_error_frames;
  2175. ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
  2176. ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
  2177. }
  2178. static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  2179. {
  2180. unsigned int mbox;
  2181. int ret = 0, prtad, devad;
  2182. struct port_info *pi = netdev_priv(dev);
  2183. struct adapter *adapter = pi->adapter;
  2184. struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
  2185. switch (cmd) {
  2186. case SIOCGMIIPHY:
  2187. if (pi->mdio_addr < 0)
  2188. return -EOPNOTSUPP;
  2189. data->phy_id = pi->mdio_addr;
  2190. break;
  2191. case SIOCGMIIREG:
  2192. case SIOCSMIIREG:
  2193. if (mdio_phy_id_is_c45(data->phy_id)) {
  2194. prtad = mdio_phy_id_prtad(data->phy_id);
  2195. devad = mdio_phy_id_devad(data->phy_id);
  2196. } else if (data->phy_id < 32) {
  2197. prtad = data->phy_id;
  2198. devad = 0;
  2199. data->reg_num &= 0x1f;
  2200. } else
  2201. return -EINVAL;
  2202. mbox = pi->adapter->pf;
  2203. if (cmd == SIOCGMIIREG)
  2204. ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
  2205. data->reg_num, &data->val_out);
  2206. else
  2207. ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
  2208. data->reg_num, data->val_in);
  2209. break;
  2210. case SIOCGHWTSTAMP:
  2211. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2212. sizeof(pi->tstamp_config)) ?
  2213. -EFAULT : 0;
  2214. case SIOCSHWTSTAMP:
  2215. if (copy_from_user(&pi->tstamp_config, req->ifr_data,
  2216. sizeof(pi->tstamp_config)))
  2217. return -EFAULT;
  2218. if (!is_t4(adapter->params.chip)) {
  2219. switch (pi->tstamp_config.tx_type) {
  2220. case HWTSTAMP_TX_OFF:
  2221. case HWTSTAMP_TX_ON:
  2222. break;
  2223. default:
  2224. return -ERANGE;
  2225. }
  2226. switch (pi->tstamp_config.rx_filter) {
  2227. case HWTSTAMP_FILTER_NONE:
  2228. pi->rxtstamp = false;
  2229. break;
  2230. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2231. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2232. cxgb4_ptprx_timestamping(pi, pi->port_id,
  2233. PTP_TS_L4);
  2234. break;
  2235. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2236. cxgb4_ptprx_timestamping(pi, pi->port_id,
  2237. PTP_TS_L2_L4);
  2238. break;
  2239. case HWTSTAMP_FILTER_ALL:
  2240. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2241. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2242. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2243. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2244. pi->rxtstamp = true;
  2245. break;
  2246. default:
  2247. pi->tstamp_config.rx_filter =
  2248. HWTSTAMP_FILTER_NONE;
  2249. return -ERANGE;
  2250. }
  2251. if ((pi->tstamp_config.tx_type == HWTSTAMP_TX_OFF) &&
  2252. (pi->tstamp_config.rx_filter ==
  2253. HWTSTAMP_FILTER_NONE)) {
  2254. if (cxgb4_ptp_txtype(adapter, pi->port_id) >= 0)
  2255. pi->ptp_enable = false;
  2256. }
  2257. if (pi->tstamp_config.rx_filter !=
  2258. HWTSTAMP_FILTER_NONE) {
  2259. if (cxgb4_ptp_redirect_rx_packet(adapter,
  2260. pi) >= 0)
  2261. pi->ptp_enable = true;
  2262. }
  2263. } else {
  2264. /* For T4 Adapters */
  2265. switch (pi->tstamp_config.rx_filter) {
  2266. case HWTSTAMP_FILTER_NONE:
  2267. pi->rxtstamp = false;
  2268. break;
  2269. case HWTSTAMP_FILTER_ALL:
  2270. pi->rxtstamp = true;
  2271. break;
  2272. default:
  2273. pi->tstamp_config.rx_filter =
  2274. HWTSTAMP_FILTER_NONE;
  2275. return -ERANGE;
  2276. }
  2277. }
  2278. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2279. sizeof(pi->tstamp_config)) ?
  2280. -EFAULT : 0;
  2281. default:
  2282. return -EOPNOTSUPP;
  2283. }
  2284. return ret;
  2285. }
  2286. static void cxgb_set_rxmode(struct net_device *dev)
  2287. {
  2288. /* unfortunately we can't return errors to the stack */
  2289. set_rxmode(dev, -1, false);
  2290. }
  2291. static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
  2292. {
  2293. int ret;
  2294. struct port_info *pi = netdev_priv(dev);
  2295. ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
  2296. -1, -1, -1, true);
  2297. if (!ret)
  2298. dev->mtu = new_mtu;
  2299. return ret;
  2300. }
  2301. #ifdef CONFIG_PCI_IOV
  2302. static int cxgb4_mgmt_open(struct net_device *dev)
  2303. {
  2304. /* Turn carrier off since we don't have to transmit anything on this
  2305. * interface.
  2306. */
  2307. netif_carrier_off(dev);
  2308. return 0;
  2309. }
  2310. /* Fill MAC address that will be assigned by the FW */
  2311. static void cxgb4_mgmt_fill_vf_station_mac_addr(struct adapter *adap)
  2312. {
  2313. u8 hw_addr[ETH_ALEN], macaddr[ETH_ALEN];
  2314. unsigned int i, vf, nvfs;
  2315. u16 a, b;
  2316. int err;
  2317. u8 *na;
  2318. adap->params.pci.vpd_cap_addr = pci_find_capability(adap->pdev,
  2319. PCI_CAP_ID_VPD);
  2320. err = t4_get_raw_vpd_params(adap, &adap->params.vpd);
  2321. if (err)
  2322. return;
  2323. na = adap->params.vpd.na;
  2324. for (i = 0; i < ETH_ALEN; i++)
  2325. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  2326. hex2val(na[2 * i + 1]));
  2327. a = (hw_addr[0] << 8) | hw_addr[1];
  2328. b = (hw_addr[1] << 8) | hw_addr[2];
  2329. a ^= b;
  2330. a |= 0x0200; /* locally assigned Ethernet MAC address */
  2331. a &= ~0x0100; /* not a multicast Ethernet MAC address */
  2332. macaddr[0] = a >> 8;
  2333. macaddr[1] = a & 0xff;
  2334. for (i = 2; i < 5; i++)
  2335. macaddr[i] = hw_addr[i + 1];
  2336. for (vf = 0, nvfs = pci_sriov_get_totalvfs(adap->pdev);
  2337. vf < nvfs; vf++) {
  2338. macaddr[5] = adap->pf * 16 + vf;
  2339. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, macaddr);
  2340. }
  2341. }
  2342. static int cxgb4_mgmt_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
  2343. {
  2344. struct port_info *pi = netdev_priv(dev);
  2345. struct adapter *adap = pi->adapter;
  2346. int ret;
  2347. /* verify MAC addr is valid */
  2348. if (!is_valid_ether_addr(mac)) {
  2349. dev_err(pi->adapter->pdev_dev,
  2350. "Invalid Ethernet address %pM for VF %d\n",
  2351. mac, vf);
  2352. return -EINVAL;
  2353. }
  2354. dev_info(pi->adapter->pdev_dev,
  2355. "Setting MAC %pM on VF %d\n", mac, vf);
  2356. ret = t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
  2357. if (!ret)
  2358. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, mac);
  2359. return ret;
  2360. }
  2361. static int cxgb4_mgmt_get_vf_config(struct net_device *dev,
  2362. int vf, struct ifla_vf_info *ivi)
  2363. {
  2364. struct port_info *pi = netdev_priv(dev);
  2365. struct adapter *adap = pi->adapter;
  2366. struct vf_info *vfinfo;
  2367. if (vf >= adap->num_vfs)
  2368. return -EINVAL;
  2369. vfinfo = &adap->vfinfo[vf];
  2370. ivi->vf = vf;
  2371. ivi->max_tx_rate = vfinfo->tx_rate;
  2372. ivi->min_tx_rate = 0;
  2373. ether_addr_copy(ivi->mac, vfinfo->vf_mac_addr);
  2374. ivi->vlan = vfinfo->vlan;
  2375. return 0;
  2376. }
  2377. static int cxgb4_mgmt_get_phys_port_id(struct net_device *dev,
  2378. struct netdev_phys_item_id *ppid)
  2379. {
  2380. struct port_info *pi = netdev_priv(dev);
  2381. unsigned int phy_port_id;
  2382. phy_port_id = pi->adapter->adap_idx * 10 + pi->port_id;
  2383. ppid->id_len = sizeof(phy_port_id);
  2384. memcpy(ppid->id, &phy_port_id, ppid->id_len);
  2385. return 0;
  2386. }
  2387. static int cxgb4_mgmt_set_vf_rate(struct net_device *dev, int vf,
  2388. int min_tx_rate, int max_tx_rate)
  2389. {
  2390. struct port_info *pi = netdev_priv(dev);
  2391. struct adapter *adap = pi->adapter;
  2392. unsigned int link_ok, speed, mtu;
  2393. u32 fw_pfvf, fw_class;
  2394. int class_id = vf;
  2395. int ret;
  2396. u16 pktsize;
  2397. if (vf >= adap->num_vfs)
  2398. return -EINVAL;
  2399. if (min_tx_rate) {
  2400. dev_err(adap->pdev_dev,
  2401. "Min tx rate (%d) (> 0) for VF %d is Invalid.\n",
  2402. min_tx_rate, vf);
  2403. return -EINVAL;
  2404. }
  2405. ret = t4_get_link_params(pi, &link_ok, &speed, &mtu);
  2406. if (ret != FW_SUCCESS) {
  2407. dev_err(adap->pdev_dev,
  2408. "Failed to get link information for VF %d\n", vf);
  2409. return -EINVAL;
  2410. }
  2411. if (!link_ok) {
  2412. dev_err(adap->pdev_dev, "Link down for VF %d\n", vf);
  2413. return -EINVAL;
  2414. }
  2415. if (max_tx_rate > speed) {
  2416. dev_err(adap->pdev_dev,
  2417. "Max tx rate %d for VF %d can't be > link-speed %u",
  2418. max_tx_rate, vf, speed);
  2419. return -EINVAL;
  2420. }
  2421. pktsize = mtu;
  2422. /* subtract ethhdr size and 4 bytes crc since, f/w appends it */
  2423. pktsize = pktsize - sizeof(struct ethhdr) - 4;
  2424. /* subtract ipv4 hdr size, tcp hdr size to get typical IPv4 MSS size */
  2425. pktsize = pktsize - sizeof(struct iphdr) - sizeof(struct tcphdr);
  2426. /* configure Traffic Class for rate-limiting */
  2427. ret = t4_sched_params(adap, SCHED_CLASS_TYPE_PACKET,
  2428. SCHED_CLASS_LEVEL_CL_RL,
  2429. SCHED_CLASS_MODE_CLASS,
  2430. SCHED_CLASS_RATEUNIT_BITS,
  2431. SCHED_CLASS_RATEMODE_ABS,
  2432. pi->tx_chan, class_id, 0,
  2433. max_tx_rate * 1000, 0, pktsize);
  2434. if (ret) {
  2435. dev_err(adap->pdev_dev, "Err %d for Traffic Class config\n",
  2436. ret);
  2437. return -EINVAL;
  2438. }
  2439. dev_info(adap->pdev_dev,
  2440. "Class %d with MSS %u configured with rate %u\n",
  2441. class_id, pktsize, max_tx_rate);
  2442. /* bind VF to configured Traffic Class */
  2443. fw_pfvf = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
  2444. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_SCHEDCLASS_ETH));
  2445. fw_class = class_id;
  2446. ret = t4_set_params(adap, adap->mbox, adap->pf, vf + 1, 1, &fw_pfvf,
  2447. &fw_class);
  2448. if (ret) {
  2449. dev_err(adap->pdev_dev,
  2450. "Err %d in binding VF %d to Traffic Class %d\n",
  2451. ret, vf, class_id);
  2452. return -EINVAL;
  2453. }
  2454. dev_info(adap->pdev_dev, "PF %d VF %d is bound to Class %d\n",
  2455. adap->pf, vf, class_id);
  2456. adap->vfinfo[vf].tx_rate = max_tx_rate;
  2457. return 0;
  2458. }
  2459. static int cxgb4_mgmt_set_vf_vlan(struct net_device *dev, int vf,
  2460. u16 vlan, u8 qos, __be16 vlan_proto)
  2461. {
  2462. struct port_info *pi = netdev_priv(dev);
  2463. struct adapter *adap = pi->adapter;
  2464. int ret;
  2465. if (vf >= adap->num_vfs || vlan > 4095 || qos > 7)
  2466. return -EINVAL;
  2467. if (vlan_proto != htons(ETH_P_8021Q) || qos != 0)
  2468. return -EPROTONOSUPPORT;
  2469. ret = t4_set_vlan_acl(adap, adap->mbox, vf + 1, vlan);
  2470. if (!ret) {
  2471. adap->vfinfo[vf].vlan = vlan;
  2472. return 0;
  2473. }
  2474. dev_err(adap->pdev_dev, "Err %d %s VLAN ACL for PF/VF %d/%d\n",
  2475. ret, (vlan ? "setting" : "clearing"), adap->pf, vf);
  2476. return ret;
  2477. }
  2478. #endif /* CONFIG_PCI_IOV */
  2479. static int cxgb_set_mac_addr(struct net_device *dev, void *p)
  2480. {
  2481. int ret;
  2482. struct sockaddr *addr = p;
  2483. struct port_info *pi = netdev_priv(dev);
  2484. if (!is_valid_ether_addr(addr->sa_data))
  2485. return -EADDRNOTAVAIL;
  2486. ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
  2487. pi->xact_addr_filt, addr->sa_data, true, true);
  2488. if (ret < 0)
  2489. return ret;
  2490. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2491. pi->xact_addr_filt = ret;
  2492. return 0;
  2493. }
  2494. #ifdef CONFIG_NET_POLL_CONTROLLER
  2495. static void cxgb_netpoll(struct net_device *dev)
  2496. {
  2497. struct port_info *pi = netdev_priv(dev);
  2498. struct adapter *adap = pi->adapter;
  2499. if (adap->flags & USING_MSIX) {
  2500. int i;
  2501. struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
  2502. for (i = pi->nqsets; i; i--, rx++)
  2503. t4_sge_intr_msix(0, &rx->rspq);
  2504. } else
  2505. t4_intr_handler(adap)(0, adap);
  2506. }
  2507. #endif
  2508. static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
  2509. {
  2510. struct port_info *pi = netdev_priv(dev);
  2511. struct adapter *adap = pi->adapter;
  2512. struct sched_class *e;
  2513. struct ch_sched_params p;
  2514. struct ch_sched_queue qe;
  2515. u32 req_rate;
  2516. int err = 0;
  2517. if (!can_sched(dev))
  2518. return -ENOTSUPP;
  2519. if (index < 0 || index > pi->nqsets - 1)
  2520. return -EINVAL;
  2521. if (!(adap->flags & FULL_INIT_DONE)) {
  2522. dev_err(adap->pdev_dev,
  2523. "Failed to rate limit on queue %d. Link Down?\n",
  2524. index);
  2525. return -EINVAL;
  2526. }
  2527. /* Convert from Mbps to Kbps */
  2528. req_rate = rate * 1000;
  2529. /* Max rate is 100 Gbps */
  2530. if (req_rate > SCHED_MAX_RATE_KBPS) {
  2531. dev_err(adap->pdev_dev,
  2532. "Invalid rate %u Mbps, Max rate is %u Mbps\n",
  2533. rate, SCHED_MAX_RATE_KBPS / 1000);
  2534. return -ERANGE;
  2535. }
  2536. /* First unbind the queue from any existing class */
  2537. memset(&qe, 0, sizeof(qe));
  2538. qe.queue = index;
  2539. qe.class = SCHED_CLS_NONE;
  2540. err = cxgb4_sched_class_unbind(dev, (void *)(&qe), SCHED_QUEUE);
  2541. if (err) {
  2542. dev_err(adap->pdev_dev,
  2543. "Unbinding Queue %d on port %d fail. Err: %d\n",
  2544. index, pi->port_id, err);
  2545. return err;
  2546. }
  2547. /* Queue already unbound */
  2548. if (!req_rate)
  2549. return 0;
  2550. /* Fetch any available unused or matching scheduling class */
  2551. memset(&p, 0, sizeof(p));
  2552. p.type = SCHED_CLASS_TYPE_PACKET;
  2553. p.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
  2554. p.u.params.mode = SCHED_CLASS_MODE_CLASS;
  2555. p.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
  2556. p.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
  2557. p.u.params.channel = pi->tx_chan;
  2558. p.u.params.class = SCHED_CLS_NONE;
  2559. p.u.params.minrate = 0;
  2560. p.u.params.maxrate = req_rate;
  2561. p.u.params.weight = 0;
  2562. p.u.params.pktsize = dev->mtu;
  2563. e = cxgb4_sched_class_alloc(dev, &p);
  2564. if (!e)
  2565. return -ENOMEM;
  2566. /* Bind the queue to a scheduling class */
  2567. memset(&qe, 0, sizeof(qe));
  2568. qe.queue = index;
  2569. qe.class = e->idx;
  2570. err = cxgb4_sched_class_bind(dev, (void *)(&qe), SCHED_QUEUE);
  2571. if (err)
  2572. dev_err(adap->pdev_dev,
  2573. "Queue rate limiting failed. Err: %d\n", err);
  2574. return err;
  2575. }
  2576. static int cxgb_setup_tc_flower(struct net_device *dev,
  2577. struct tc_cls_flower_offload *cls_flower)
  2578. {
  2579. switch (cls_flower->command) {
  2580. case TC_CLSFLOWER_REPLACE:
  2581. return cxgb4_tc_flower_replace(dev, cls_flower);
  2582. case TC_CLSFLOWER_DESTROY:
  2583. return cxgb4_tc_flower_destroy(dev, cls_flower);
  2584. case TC_CLSFLOWER_STATS:
  2585. return cxgb4_tc_flower_stats(dev, cls_flower);
  2586. default:
  2587. return -EOPNOTSUPP;
  2588. }
  2589. }
  2590. static int cxgb_setup_tc_cls_u32(struct net_device *dev,
  2591. struct tc_cls_u32_offload *cls_u32)
  2592. {
  2593. switch (cls_u32->command) {
  2594. case TC_CLSU32_NEW_KNODE:
  2595. case TC_CLSU32_REPLACE_KNODE:
  2596. return cxgb4_config_knode(dev, cls_u32);
  2597. case TC_CLSU32_DELETE_KNODE:
  2598. return cxgb4_delete_knode(dev, cls_u32);
  2599. default:
  2600. return -EOPNOTSUPP;
  2601. }
  2602. }
  2603. static int cxgb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  2604. void *cb_priv)
  2605. {
  2606. struct net_device *dev = cb_priv;
  2607. struct port_info *pi = netdev2pinfo(dev);
  2608. struct adapter *adap = netdev2adap(dev);
  2609. if (!(adap->flags & FULL_INIT_DONE)) {
  2610. dev_err(adap->pdev_dev,
  2611. "Failed to setup tc on port %d. Link Down?\n",
  2612. pi->port_id);
  2613. return -EINVAL;
  2614. }
  2615. if (!tc_cls_can_offload_and_chain0(dev, type_data))
  2616. return -EOPNOTSUPP;
  2617. switch (type) {
  2618. case TC_SETUP_CLSU32:
  2619. return cxgb_setup_tc_cls_u32(dev, type_data);
  2620. case TC_SETUP_CLSFLOWER:
  2621. return cxgb_setup_tc_flower(dev, type_data);
  2622. default:
  2623. return -EOPNOTSUPP;
  2624. }
  2625. }
  2626. static int cxgb_setup_tc_block(struct net_device *dev,
  2627. struct tc_block_offload *f)
  2628. {
  2629. struct port_info *pi = netdev2pinfo(dev);
  2630. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  2631. return -EOPNOTSUPP;
  2632. switch (f->command) {
  2633. case TC_BLOCK_BIND:
  2634. return tcf_block_cb_register(f->block, cxgb_setup_tc_block_cb,
  2635. pi, dev, f->extack);
  2636. case TC_BLOCK_UNBIND:
  2637. tcf_block_cb_unregister(f->block, cxgb_setup_tc_block_cb, pi);
  2638. return 0;
  2639. default:
  2640. return -EOPNOTSUPP;
  2641. }
  2642. }
  2643. static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
  2644. void *type_data)
  2645. {
  2646. switch (type) {
  2647. case TC_SETUP_BLOCK:
  2648. return cxgb_setup_tc_block(dev, type_data);
  2649. default:
  2650. return -EOPNOTSUPP;
  2651. }
  2652. }
  2653. static void cxgb_del_udp_tunnel(struct net_device *netdev,
  2654. struct udp_tunnel_info *ti)
  2655. {
  2656. struct port_info *pi = netdev_priv(netdev);
  2657. struct adapter *adapter = pi->adapter;
  2658. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2659. u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
  2660. int ret = 0, i;
  2661. if (chip_ver < CHELSIO_T6)
  2662. return;
  2663. switch (ti->type) {
  2664. case UDP_TUNNEL_TYPE_VXLAN:
  2665. if (!adapter->vxlan_port_cnt ||
  2666. adapter->vxlan_port != ti->port)
  2667. return; /* Invalid VxLAN destination port */
  2668. adapter->vxlan_port_cnt--;
  2669. if (adapter->vxlan_port_cnt)
  2670. return;
  2671. adapter->vxlan_port = 0;
  2672. t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A, 0);
  2673. break;
  2674. case UDP_TUNNEL_TYPE_GENEVE:
  2675. if (!adapter->geneve_port_cnt ||
  2676. adapter->geneve_port != ti->port)
  2677. return; /* Invalid GENEVE destination port */
  2678. adapter->geneve_port_cnt--;
  2679. if (adapter->geneve_port_cnt)
  2680. return;
  2681. adapter->geneve_port = 0;
  2682. t4_write_reg(adapter, MPS_RX_GENEVE_TYPE_A, 0);
  2683. break;
  2684. default:
  2685. return;
  2686. }
  2687. /* Matchall mac entries can be deleted only after all tunnel ports
  2688. * are brought down or removed.
  2689. */
  2690. if (!adapter->rawf_cnt)
  2691. return;
  2692. for_each_port(adapter, i) {
  2693. pi = adap2pinfo(adapter, i);
  2694. ret = t4_free_raw_mac_filt(adapter, pi->viid,
  2695. match_all_mac, match_all_mac,
  2696. adapter->rawf_start +
  2697. pi->port_id,
  2698. 1, pi->port_id, false);
  2699. if (ret < 0) {
  2700. netdev_info(netdev, "Failed to free mac filter entry, for port %d\n",
  2701. i);
  2702. return;
  2703. }
  2704. atomic_dec(&adapter->mps_encap[adapter->rawf_start +
  2705. pi->port_id].refcnt);
  2706. }
  2707. }
  2708. static void cxgb_add_udp_tunnel(struct net_device *netdev,
  2709. struct udp_tunnel_info *ti)
  2710. {
  2711. struct port_info *pi = netdev_priv(netdev);
  2712. struct adapter *adapter = pi->adapter;
  2713. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2714. u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
  2715. int i, ret;
  2716. if (chip_ver < CHELSIO_T6 || !adapter->rawf_cnt)
  2717. return;
  2718. switch (ti->type) {
  2719. case UDP_TUNNEL_TYPE_VXLAN:
  2720. /* Callback for adding vxlan port can be called with the same
  2721. * port for both IPv4 and IPv6. We should not disable the
  2722. * offloading when the same port for both protocols is added
  2723. * and later one of them is removed.
  2724. */
  2725. if (adapter->vxlan_port_cnt &&
  2726. adapter->vxlan_port == ti->port) {
  2727. adapter->vxlan_port_cnt++;
  2728. return;
  2729. }
  2730. /* We will support only one VxLAN port */
  2731. if (adapter->vxlan_port_cnt) {
  2732. netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
  2733. be16_to_cpu(adapter->vxlan_port),
  2734. be16_to_cpu(ti->port));
  2735. return;
  2736. }
  2737. adapter->vxlan_port = ti->port;
  2738. adapter->vxlan_port_cnt = 1;
  2739. t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A,
  2740. VXLAN_V(be16_to_cpu(ti->port)) | VXLAN_EN_F);
  2741. break;
  2742. case UDP_TUNNEL_TYPE_GENEVE:
  2743. if (adapter->geneve_port_cnt &&
  2744. adapter->geneve_port == ti->port) {
  2745. adapter->geneve_port_cnt++;
  2746. return;
  2747. }
  2748. /* We will support only one GENEVE port */
  2749. if (adapter->geneve_port_cnt) {
  2750. netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
  2751. be16_to_cpu(adapter->geneve_port),
  2752. be16_to_cpu(ti->port));
  2753. return;
  2754. }
  2755. adapter->geneve_port = ti->port;
  2756. adapter->geneve_port_cnt = 1;
  2757. t4_write_reg(adapter, MPS_RX_GENEVE_TYPE_A,
  2758. GENEVE_V(be16_to_cpu(ti->port)) | GENEVE_EN_F);
  2759. break;
  2760. default:
  2761. return;
  2762. }
  2763. /* Create a 'match all' mac filter entry for inner mac,
  2764. * if raw mac interface is supported. Once the linux kernel provides
  2765. * driver entry points for adding/deleting the inner mac addresses,
  2766. * we will remove this 'match all' entry and fallback to adding
  2767. * exact match filters.
  2768. */
  2769. for_each_port(adapter, i) {
  2770. pi = adap2pinfo(adapter, i);
  2771. ret = t4_alloc_raw_mac_filt(adapter, pi->viid,
  2772. match_all_mac,
  2773. match_all_mac,
  2774. adapter->rawf_start +
  2775. pi->port_id,
  2776. 1, pi->port_id, false);
  2777. if (ret < 0) {
  2778. netdev_info(netdev, "Failed to allocate a mac filter entry, not adding port %d\n",
  2779. be16_to_cpu(ti->port));
  2780. cxgb_del_udp_tunnel(netdev, ti);
  2781. return;
  2782. }
  2783. atomic_inc(&adapter->mps_encap[ret].refcnt);
  2784. }
  2785. }
  2786. static netdev_features_t cxgb_features_check(struct sk_buff *skb,
  2787. struct net_device *dev,
  2788. netdev_features_t features)
  2789. {
  2790. struct port_info *pi = netdev_priv(dev);
  2791. struct adapter *adapter = pi->adapter;
  2792. if (CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
  2793. return features;
  2794. /* Check if hw supports offload for this packet */
  2795. if (!skb->encapsulation || cxgb_encap_offload_supported(skb))
  2796. return features;
  2797. /* Offload is not supported for this encapsulated packet */
  2798. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  2799. }
  2800. static netdev_features_t cxgb_fix_features(struct net_device *dev,
  2801. netdev_features_t features)
  2802. {
  2803. /* Disable GRO, if RX_CSUM is disabled */
  2804. if (!(features & NETIF_F_RXCSUM))
  2805. features &= ~NETIF_F_GRO;
  2806. return features;
  2807. }
  2808. static const struct net_device_ops cxgb4_netdev_ops = {
  2809. .ndo_open = cxgb_open,
  2810. .ndo_stop = cxgb_close,
  2811. .ndo_start_xmit = t4_start_xmit,
  2812. .ndo_select_queue = cxgb_select_queue,
  2813. .ndo_get_stats64 = cxgb_get_stats,
  2814. .ndo_set_rx_mode = cxgb_set_rxmode,
  2815. .ndo_set_mac_address = cxgb_set_mac_addr,
  2816. .ndo_set_features = cxgb_set_features,
  2817. .ndo_validate_addr = eth_validate_addr,
  2818. .ndo_do_ioctl = cxgb_ioctl,
  2819. .ndo_change_mtu = cxgb_change_mtu,
  2820. #ifdef CONFIG_NET_POLL_CONTROLLER
  2821. .ndo_poll_controller = cxgb_netpoll,
  2822. #endif
  2823. #ifdef CONFIG_CHELSIO_T4_FCOE
  2824. .ndo_fcoe_enable = cxgb_fcoe_enable,
  2825. .ndo_fcoe_disable = cxgb_fcoe_disable,
  2826. #endif /* CONFIG_CHELSIO_T4_FCOE */
  2827. .ndo_set_tx_maxrate = cxgb_set_tx_maxrate,
  2828. .ndo_setup_tc = cxgb_setup_tc,
  2829. .ndo_udp_tunnel_add = cxgb_add_udp_tunnel,
  2830. .ndo_udp_tunnel_del = cxgb_del_udp_tunnel,
  2831. .ndo_features_check = cxgb_features_check,
  2832. .ndo_fix_features = cxgb_fix_features,
  2833. };
  2834. #ifdef CONFIG_PCI_IOV
  2835. static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
  2836. .ndo_open = cxgb4_mgmt_open,
  2837. .ndo_set_vf_mac = cxgb4_mgmt_set_vf_mac,
  2838. .ndo_get_vf_config = cxgb4_mgmt_get_vf_config,
  2839. .ndo_set_vf_rate = cxgb4_mgmt_set_vf_rate,
  2840. .ndo_get_phys_port_id = cxgb4_mgmt_get_phys_port_id,
  2841. .ndo_set_vf_vlan = cxgb4_mgmt_set_vf_vlan,
  2842. };
  2843. #endif
  2844. static void cxgb4_mgmt_get_drvinfo(struct net_device *dev,
  2845. struct ethtool_drvinfo *info)
  2846. {
  2847. struct adapter *adapter = netdev2adap(dev);
  2848. strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
  2849. strlcpy(info->version, cxgb4_driver_version,
  2850. sizeof(info->version));
  2851. strlcpy(info->bus_info, pci_name(adapter->pdev),
  2852. sizeof(info->bus_info));
  2853. }
  2854. static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
  2855. .get_drvinfo = cxgb4_mgmt_get_drvinfo,
  2856. };
  2857. static void notify_fatal_err(struct work_struct *work)
  2858. {
  2859. struct adapter *adap;
  2860. adap = container_of(work, struct adapter, fatal_err_notify_task);
  2861. notify_ulds(adap, CXGB4_STATE_FATAL_ERROR);
  2862. }
  2863. void t4_fatal_err(struct adapter *adap)
  2864. {
  2865. int port;
  2866. if (pci_channel_offline(adap->pdev))
  2867. return;
  2868. /* Disable the SGE since ULDs are going to free resources that
  2869. * could be exposed to the adapter. RDMA MWs for example...
  2870. */
  2871. t4_shutdown_adapter(adap);
  2872. for_each_port(adap, port) {
  2873. struct net_device *dev = adap->port[port];
  2874. /* If we get here in very early initialization the network
  2875. * devices may not have been set up yet.
  2876. */
  2877. if (!dev)
  2878. continue;
  2879. netif_tx_stop_all_queues(dev);
  2880. netif_carrier_off(dev);
  2881. }
  2882. dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
  2883. queue_work(adap->workq, &adap->fatal_err_notify_task);
  2884. }
  2885. static void setup_memwin(struct adapter *adap)
  2886. {
  2887. u32 nic_win_base = t4_get_util_window(adap);
  2888. t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
  2889. }
  2890. static void setup_memwin_rdma(struct adapter *adap)
  2891. {
  2892. if (adap->vres.ocq.size) {
  2893. u32 start;
  2894. unsigned int sz_kb;
  2895. start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
  2896. start &= PCI_BASE_ADDRESS_MEM_MASK;
  2897. start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
  2898. sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
  2899. t4_write_reg(adap,
  2900. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
  2901. start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
  2902. t4_write_reg(adap,
  2903. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
  2904. adap->vres.ocq.start);
  2905. t4_read_reg(adap,
  2906. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
  2907. }
  2908. }
  2909. /* HMA Definitions */
  2910. /* The maximum number of address that can be send in a single FW cmd */
  2911. #define HMA_MAX_ADDR_IN_CMD 5
  2912. #define HMA_PAGE_SIZE PAGE_SIZE
  2913. #define HMA_MAX_NO_FW_ADDRESS (16 << 10) /* FW supports 16K addresses */
  2914. #define HMA_PAGE_ORDER \
  2915. ((HMA_PAGE_SIZE < HMA_MAX_NO_FW_ADDRESS) ? \
  2916. ilog2(HMA_MAX_NO_FW_ADDRESS / HMA_PAGE_SIZE) : 0)
  2917. /* The minimum and maximum possible HMA sizes that can be specified in the FW
  2918. * configuration(in units of MB).
  2919. */
  2920. #define HMA_MIN_TOTAL_SIZE 1
  2921. #define HMA_MAX_TOTAL_SIZE \
  2922. (((HMA_PAGE_SIZE << HMA_PAGE_ORDER) * \
  2923. HMA_MAX_NO_FW_ADDRESS) >> 20)
  2924. static void adap_free_hma_mem(struct adapter *adapter)
  2925. {
  2926. struct scatterlist *iter;
  2927. struct page *page;
  2928. int i;
  2929. if (!adapter->hma.sgt)
  2930. return;
  2931. if (adapter->hma.flags & HMA_DMA_MAPPED_FLAG) {
  2932. dma_unmap_sg(adapter->pdev_dev, adapter->hma.sgt->sgl,
  2933. adapter->hma.sgt->nents, PCI_DMA_BIDIRECTIONAL);
  2934. adapter->hma.flags &= ~HMA_DMA_MAPPED_FLAG;
  2935. }
  2936. for_each_sg(adapter->hma.sgt->sgl, iter,
  2937. adapter->hma.sgt->orig_nents, i) {
  2938. page = sg_page(iter);
  2939. if (page)
  2940. __free_pages(page, HMA_PAGE_ORDER);
  2941. }
  2942. kfree(adapter->hma.phy_addr);
  2943. sg_free_table(adapter->hma.sgt);
  2944. kfree(adapter->hma.sgt);
  2945. adapter->hma.sgt = NULL;
  2946. }
  2947. static int adap_config_hma(struct adapter *adapter)
  2948. {
  2949. struct scatterlist *sgl, *iter;
  2950. struct sg_table *sgt;
  2951. struct page *newpage;
  2952. unsigned int i, j, k;
  2953. u32 param, hma_size;
  2954. unsigned int ncmds;
  2955. size_t page_size;
  2956. u32 page_order;
  2957. int node, ret;
  2958. /* HMA is supported only for T6+ cards.
  2959. * Avoid initializing HMA in kdump kernels.
  2960. */
  2961. if (is_kdump_kernel() ||
  2962. CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
  2963. return 0;
  2964. /* Get the HMA region size required by fw */
  2965. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  2966. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_HMA_SIZE));
  2967. ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
  2968. 1, &param, &hma_size);
  2969. /* An error means card has its own memory or HMA is not supported by
  2970. * the firmware. Return without any errors.
  2971. */
  2972. if (ret || !hma_size)
  2973. return 0;
  2974. if (hma_size < HMA_MIN_TOTAL_SIZE ||
  2975. hma_size > HMA_MAX_TOTAL_SIZE) {
  2976. dev_err(adapter->pdev_dev,
  2977. "HMA size %uMB beyond bounds(%u-%lu)MB\n",
  2978. hma_size, HMA_MIN_TOTAL_SIZE, HMA_MAX_TOTAL_SIZE);
  2979. return -EINVAL;
  2980. }
  2981. page_size = HMA_PAGE_SIZE;
  2982. page_order = HMA_PAGE_ORDER;
  2983. adapter->hma.sgt = kzalloc(sizeof(*adapter->hma.sgt), GFP_KERNEL);
  2984. if (unlikely(!adapter->hma.sgt)) {
  2985. dev_err(adapter->pdev_dev, "HMA SG table allocation failed\n");
  2986. return -ENOMEM;
  2987. }
  2988. sgt = adapter->hma.sgt;
  2989. /* FW returned value will be in MB's
  2990. */
  2991. sgt->orig_nents = (hma_size << 20) / (page_size << page_order);
  2992. if (sg_alloc_table(sgt, sgt->orig_nents, GFP_KERNEL)) {
  2993. dev_err(adapter->pdev_dev, "HMA SGL allocation failed\n");
  2994. kfree(adapter->hma.sgt);
  2995. adapter->hma.sgt = NULL;
  2996. return -ENOMEM;
  2997. }
  2998. sgl = adapter->hma.sgt->sgl;
  2999. node = dev_to_node(adapter->pdev_dev);
  3000. for_each_sg(sgl, iter, sgt->orig_nents, i) {
  3001. newpage = alloc_pages_node(node, __GFP_NOWARN | GFP_KERNEL |
  3002. __GFP_ZERO, page_order);
  3003. if (!newpage) {
  3004. dev_err(adapter->pdev_dev,
  3005. "Not enough memory for HMA page allocation\n");
  3006. ret = -ENOMEM;
  3007. goto free_hma;
  3008. }
  3009. sg_set_page(iter, newpage, page_size << page_order, 0);
  3010. }
  3011. sgt->nents = dma_map_sg(adapter->pdev_dev, sgl, sgt->orig_nents,
  3012. DMA_BIDIRECTIONAL);
  3013. if (!sgt->nents) {
  3014. dev_err(adapter->pdev_dev,
  3015. "Not enough memory for HMA DMA mapping");
  3016. ret = -ENOMEM;
  3017. goto free_hma;
  3018. }
  3019. adapter->hma.flags |= HMA_DMA_MAPPED_FLAG;
  3020. adapter->hma.phy_addr = kcalloc(sgt->nents, sizeof(dma_addr_t),
  3021. GFP_KERNEL);
  3022. if (unlikely(!adapter->hma.phy_addr))
  3023. goto free_hma;
  3024. for_each_sg(sgl, iter, sgt->nents, i) {
  3025. newpage = sg_page(iter);
  3026. adapter->hma.phy_addr[i] = sg_dma_address(iter);
  3027. }
  3028. ncmds = DIV_ROUND_UP(sgt->nents, HMA_MAX_ADDR_IN_CMD);
  3029. /* Pass on the addresses to firmware */
  3030. for (i = 0, k = 0; i < ncmds; i++, k += HMA_MAX_ADDR_IN_CMD) {
  3031. struct fw_hma_cmd hma_cmd;
  3032. u8 naddr = HMA_MAX_ADDR_IN_CMD;
  3033. u8 soc = 0, eoc = 0;
  3034. u8 hma_mode = 1; /* Presently we support only Page table mode */
  3035. soc = (i == 0) ? 1 : 0;
  3036. eoc = (i == ncmds - 1) ? 1 : 0;
  3037. /* For last cmd, set naddr corresponding to remaining
  3038. * addresses
  3039. */
  3040. if (i == ncmds - 1) {
  3041. naddr = sgt->nents % HMA_MAX_ADDR_IN_CMD;
  3042. naddr = naddr ? naddr : HMA_MAX_ADDR_IN_CMD;
  3043. }
  3044. memset(&hma_cmd, 0, sizeof(hma_cmd));
  3045. hma_cmd.op_pkd = htonl(FW_CMD_OP_V(FW_HMA_CMD) |
  3046. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  3047. hma_cmd.retval_len16 = htonl(FW_LEN16(hma_cmd));
  3048. hma_cmd.mode_to_pcie_params =
  3049. htonl(FW_HMA_CMD_MODE_V(hma_mode) |
  3050. FW_HMA_CMD_SOC_V(soc) | FW_HMA_CMD_EOC_V(eoc));
  3051. /* HMA cmd size specified in MB's */
  3052. hma_cmd.naddr_size =
  3053. htonl(FW_HMA_CMD_SIZE_V(hma_size) |
  3054. FW_HMA_CMD_NADDR_V(naddr));
  3055. /* Total Page size specified in units of 4K */
  3056. hma_cmd.addr_size_pkd =
  3057. htonl(FW_HMA_CMD_ADDR_SIZE_V
  3058. ((page_size << page_order) >> 12));
  3059. /* Fill the 5 addresses */
  3060. for (j = 0; j < naddr; j++) {
  3061. hma_cmd.phy_address[j] =
  3062. cpu_to_be64(adapter->hma.phy_addr[j + k]);
  3063. }
  3064. ret = t4_wr_mbox(adapter, adapter->mbox, &hma_cmd,
  3065. sizeof(hma_cmd), &hma_cmd);
  3066. if (ret) {
  3067. dev_err(adapter->pdev_dev,
  3068. "HMA FW command failed with err %d\n", ret);
  3069. goto free_hma;
  3070. }
  3071. }
  3072. if (!ret)
  3073. dev_info(adapter->pdev_dev,
  3074. "Reserved %uMB host memory for HMA\n", hma_size);
  3075. return ret;
  3076. free_hma:
  3077. adap_free_hma_mem(adapter);
  3078. return ret;
  3079. }
  3080. static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
  3081. {
  3082. u32 v;
  3083. int ret;
  3084. /* Now that we've successfully configured and initialized the adapter
  3085. * can ask the Firmware what resources it has provisioned for us.
  3086. */
  3087. ret = t4_get_pfres(adap);
  3088. if (ret) {
  3089. dev_err(adap->pdev_dev,
  3090. "Unable to retrieve resource provisioning information\n");
  3091. return ret;
  3092. }
  3093. /* get device capabilities */
  3094. memset(c, 0, sizeof(*c));
  3095. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3096. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3097. c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
  3098. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
  3099. if (ret < 0)
  3100. return ret;
  3101. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3102. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  3103. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
  3104. if (ret < 0)
  3105. return ret;
  3106. ret = t4_config_glbl_rss(adap, adap->pf,
  3107. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
  3108. FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
  3109. FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
  3110. if (ret < 0)
  3111. return ret;
  3112. ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
  3113. MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
  3114. FW_CMD_CAP_PF);
  3115. if (ret < 0)
  3116. return ret;
  3117. t4_sge_init(adap);
  3118. /* tweak some settings */
  3119. t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
  3120. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
  3121. t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
  3122. v = t4_read_reg(adap, TP_PIO_DATA_A);
  3123. t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
  3124. /* first 4 Tx modulation queues point to consecutive Tx channels */
  3125. adap->params.tp.tx_modq_map = 0xE4;
  3126. t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
  3127. TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
  3128. /* associate each Tx modulation queue with consecutive Tx channels */
  3129. v = 0x84218421;
  3130. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3131. &v, 1, TP_TX_SCHED_HDR_A);
  3132. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3133. &v, 1, TP_TX_SCHED_FIFO_A);
  3134. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3135. &v, 1, TP_TX_SCHED_PCMD_A);
  3136. #define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
  3137. if (is_offload(adap)) {
  3138. t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
  3139. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3140. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3141. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3142. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  3143. t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
  3144. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3145. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3146. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3147. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  3148. }
  3149. /* get basic stuff going */
  3150. return t4_early_init(adap, adap->pf);
  3151. }
  3152. /*
  3153. * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
  3154. */
  3155. #define MAX_ATIDS 8192U
  3156. /*
  3157. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3158. *
  3159. * If the firmware we're dealing with has Configuration File support, then
  3160. * we use that to perform all configuration
  3161. */
  3162. /*
  3163. * Tweak configuration based on module parameters, etc. Most of these have
  3164. * defaults assigned to them by Firmware Configuration Files (if we're using
  3165. * them) but need to be explicitly set if we're using hard-coded
  3166. * initialization. But even in the case of using Firmware Configuration
  3167. * Files, we'd like to expose the ability to change these via module
  3168. * parameters so these are essentially common tweaks/settings for
  3169. * Configuration Files and hard-coded initialization ...
  3170. */
  3171. static int adap_init0_tweaks(struct adapter *adapter)
  3172. {
  3173. /*
  3174. * Fix up various Host-Dependent Parameters like Page Size, Cache
  3175. * Line Size, etc. The firmware default is for a 4KB Page Size and
  3176. * 64B Cache Line Size ...
  3177. */
  3178. t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
  3179. /*
  3180. * Process module parameters which affect early initialization.
  3181. */
  3182. if (rx_dma_offset != 2 && rx_dma_offset != 0) {
  3183. dev_err(&adapter->pdev->dev,
  3184. "Ignoring illegal rx_dma_offset=%d, using 2\n",
  3185. rx_dma_offset);
  3186. rx_dma_offset = 2;
  3187. }
  3188. t4_set_reg_field(adapter, SGE_CONTROL_A,
  3189. PKTSHIFT_V(PKTSHIFT_M),
  3190. PKTSHIFT_V(rx_dma_offset));
  3191. /*
  3192. * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
  3193. * adds the pseudo header itself.
  3194. */
  3195. t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
  3196. CSUM_HAS_PSEUDO_HDR_F, 0);
  3197. return 0;
  3198. }
  3199. /* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
  3200. * unto themselves and they contain their own firmware to perform their
  3201. * tasks ...
  3202. */
  3203. static int phy_aq1202_version(const u8 *phy_fw_data,
  3204. size_t phy_fw_size)
  3205. {
  3206. int offset;
  3207. /* At offset 0x8 you're looking for the primary image's
  3208. * starting offset which is 3 Bytes wide
  3209. *
  3210. * At offset 0xa of the primary image, you look for the offset
  3211. * of the DRAM segment which is 3 Bytes wide.
  3212. *
  3213. * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
  3214. * wide
  3215. */
  3216. #define be16(__p) (((__p)[0] << 8) | (__p)[1])
  3217. #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
  3218. #define le24(__p) (le16(__p) | ((__p)[2] << 16))
  3219. offset = le24(phy_fw_data + 0x8) << 12;
  3220. offset = le24(phy_fw_data + offset + 0xa);
  3221. return be16(phy_fw_data + offset + 0x27e);
  3222. #undef be16
  3223. #undef le16
  3224. #undef le24
  3225. }
  3226. static struct info_10gbt_phy_fw {
  3227. unsigned int phy_fw_id; /* PCI Device ID */
  3228. char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
  3229. int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
  3230. int phy_flash; /* Has FLASH for PHY Firmware */
  3231. } phy_info_array[] = {
  3232. {
  3233. PHY_AQ1202_DEVICEID,
  3234. PHY_AQ1202_FIRMWARE,
  3235. phy_aq1202_version,
  3236. 1,
  3237. },
  3238. {
  3239. PHY_BCM84834_DEVICEID,
  3240. PHY_BCM84834_FIRMWARE,
  3241. NULL,
  3242. 0,
  3243. },
  3244. { 0, NULL, NULL },
  3245. };
  3246. static struct info_10gbt_phy_fw *find_phy_info(int devid)
  3247. {
  3248. int i;
  3249. for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
  3250. if (phy_info_array[i].phy_fw_id == devid)
  3251. return &phy_info_array[i];
  3252. }
  3253. return NULL;
  3254. }
  3255. /* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
  3256. * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
  3257. * we return a negative error number. If we transfer new firmware we return 1
  3258. * (from t4_load_phy_fw()). If we don't do anything we return 0.
  3259. */
  3260. static int adap_init0_phy(struct adapter *adap)
  3261. {
  3262. const struct firmware *phyf;
  3263. int ret;
  3264. struct info_10gbt_phy_fw *phy_info;
  3265. /* Use the device ID to determine which PHY file to flash.
  3266. */
  3267. phy_info = find_phy_info(adap->pdev->device);
  3268. if (!phy_info) {
  3269. dev_warn(adap->pdev_dev,
  3270. "No PHY Firmware file found for this PHY\n");
  3271. return -EOPNOTSUPP;
  3272. }
  3273. /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
  3274. * use that. The adapter firmware provides us with a memory buffer
  3275. * where we can load a PHY firmware file from the host if we want to
  3276. * override the PHY firmware File in flash.
  3277. */
  3278. ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
  3279. adap->pdev_dev);
  3280. if (ret < 0) {
  3281. /* For adapters without FLASH attached to PHY for their
  3282. * firmware, it's obviously a fatal error if we can't get the
  3283. * firmware to the adapter. For adapters with PHY firmware
  3284. * FLASH storage, it's worth a warning if we can't find the
  3285. * PHY Firmware but we'll neuter the error ...
  3286. */
  3287. dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
  3288. "/lib/firmware/%s, error %d\n",
  3289. phy_info->phy_fw_file, -ret);
  3290. if (phy_info->phy_flash) {
  3291. int cur_phy_fw_ver = 0;
  3292. t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3293. dev_warn(adap->pdev_dev, "continuing with, on-adapter "
  3294. "FLASH copy, version %#x\n", cur_phy_fw_ver);
  3295. ret = 0;
  3296. }
  3297. return ret;
  3298. }
  3299. /* Load PHY Firmware onto adapter.
  3300. */
  3301. ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
  3302. phy_info->phy_fw_version,
  3303. (u8 *)phyf->data, phyf->size);
  3304. if (ret < 0)
  3305. dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
  3306. -ret);
  3307. else if (ret > 0) {
  3308. int new_phy_fw_ver = 0;
  3309. if (phy_info->phy_fw_version)
  3310. new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
  3311. phyf->size);
  3312. dev_info(adap->pdev_dev, "Successfully transferred PHY "
  3313. "Firmware /lib/firmware/%s, version %#x\n",
  3314. phy_info->phy_fw_file, new_phy_fw_ver);
  3315. }
  3316. release_firmware(phyf);
  3317. return ret;
  3318. }
  3319. /*
  3320. * Attempt to initialize the adapter via a Firmware Configuration File.
  3321. */
  3322. static int adap_init0_config(struct adapter *adapter, int reset)
  3323. {
  3324. struct fw_caps_config_cmd caps_cmd;
  3325. const struct firmware *cf;
  3326. unsigned long mtype = 0, maddr = 0;
  3327. u32 finiver, finicsum, cfcsum;
  3328. int ret;
  3329. int config_issued = 0;
  3330. char *fw_config_file, fw_config_file_path[256];
  3331. char *config_name = NULL;
  3332. /*
  3333. * Reset device if necessary.
  3334. */
  3335. if (reset) {
  3336. ret = t4_fw_reset(adapter, adapter->mbox,
  3337. PIORSTMODE_F | PIORST_F);
  3338. if (ret < 0)
  3339. goto bye;
  3340. }
  3341. /* If this is a 10Gb/s-BT adapter make sure the chip-external
  3342. * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
  3343. * to be performed after any global adapter RESET above since some
  3344. * PHYs only have local RAM copies of the PHY firmware.
  3345. */
  3346. if (is_10gbt_device(adapter->pdev->device)) {
  3347. ret = adap_init0_phy(adapter);
  3348. if (ret < 0)
  3349. goto bye;
  3350. }
  3351. /*
  3352. * If we have a T4 configuration file under /lib/firmware/cxgb4/,
  3353. * then use that. Otherwise, use the configuration file stored
  3354. * in the adapter flash ...
  3355. */
  3356. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  3357. case CHELSIO_T4:
  3358. fw_config_file = FW4_CFNAME;
  3359. break;
  3360. case CHELSIO_T5:
  3361. fw_config_file = FW5_CFNAME;
  3362. break;
  3363. case CHELSIO_T6:
  3364. fw_config_file = FW6_CFNAME;
  3365. break;
  3366. default:
  3367. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  3368. adapter->pdev->device);
  3369. ret = -EINVAL;
  3370. goto bye;
  3371. }
  3372. ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
  3373. if (ret < 0) {
  3374. config_name = "On FLASH";
  3375. mtype = FW_MEMTYPE_CF_FLASH;
  3376. maddr = t4_flash_cfg_addr(adapter);
  3377. } else {
  3378. u32 params[7], val[7];
  3379. sprintf(fw_config_file_path,
  3380. "/lib/firmware/%s", fw_config_file);
  3381. config_name = fw_config_file_path;
  3382. if (cf->size >= FLASH_CFG_MAX_SIZE)
  3383. ret = -ENOMEM;
  3384. else {
  3385. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3386. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3387. ret = t4_query_params(adapter, adapter->mbox,
  3388. adapter->pf, 0, 1, params, val);
  3389. if (ret == 0) {
  3390. /*
  3391. * For t4_memory_rw() below addresses and
  3392. * sizes have to be in terms of multiples of 4
  3393. * bytes. So, if the Configuration File isn't
  3394. * a multiple of 4 bytes in length we'll have
  3395. * to write that out separately since we can't
  3396. * guarantee that the bytes following the
  3397. * residual byte in the buffer returned by
  3398. * request_firmware() are zeroed out ...
  3399. */
  3400. size_t resid = cf->size & 0x3;
  3401. size_t size = cf->size & ~0x3;
  3402. __be32 *data = (__be32 *)cf->data;
  3403. mtype = FW_PARAMS_PARAM_Y_G(val[0]);
  3404. maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
  3405. spin_lock(&adapter->win0_lock);
  3406. ret = t4_memory_rw(adapter, 0, mtype, maddr,
  3407. size, data, T4_MEMORY_WRITE);
  3408. if (ret == 0 && resid != 0) {
  3409. union {
  3410. __be32 word;
  3411. char buf[4];
  3412. } last;
  3413. int i;
  3414. last.word = data[size >> 2];
  3415. for (i = resid; i < 4; i++)
  3416. last.buf[i] = 0;
  3417. ret = t4_memory_rw(adapter, 0, mtype,
  3418. maddr + size,
  3419. 4, &last.word,
  3420. T4_MEMORY_WRITE);
  3421. }
  3422. spin_unlock(&adapter->win0_lock);
  3423. }
  3424. }
  3425. release_firmware(cf);
  3426. if (ret)
  3427. goto bye;
  3428. }
  3429. /*
  3430. * Issue a Capability Configuration command to the firmware to get it
  3431. * to parse the Configuration File. We don't use t4_fw_config_file()
  3432. * because we want the ability to modify various features after we've
  3433. * processed the configuration file ...
  3434. */
  3435. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3436. caps_cmd.op_to_write =
  3437. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3438. FW_CMD_REQUEST_F |
  3439. FW_CMD_READ_F);
  3440. caps_cmd.cfvalid_to_len16 =
  3441. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  3442. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  3443. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  3444. FW_LEN16(caps_cmd));
  3445. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3446. &caps_cmd);
  3447. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  3448. * Configuration File in FLASH), our last gasp effort is to use the
  3449. * Firmware Configuration File which is embedded in the firmware. A
  3450. * very few early versions of the firmware didn't have one embedded
  3451. * but we can ignore those.
  3452. */
  3453. if (ret == -ENOENT) {
  3454. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3455. caps_cmd.op_to_write =
  3456. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3457. FW_CMD_REQUEST_F |
  3458. FW_CMD_READ_F);
  3459. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3460. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
  3461. sizeof(caps_cmd), &caps_cmd);
  3462. config_name = "Firmware Default";
  3463. }
  3464. config_issued = 1;
  3465. if (ret < 0)
  3466. goto bye;
  3467. finiver = ntohl(caps_cmd.finiver);
  3468. finicsum = ntohl(caps_cmd.finicsum);
  3469. cfcsum = ntohl(caps_cmd.cfcsum);
  3470. if (finicsum != cfcsum)
  3471. dev_warn(adapter->pdev_dev, "Configuration File checksum "\
  3472. "mismatch: [fini] csum=%#x, computed csum=%#x\n",
  3473. finicsum, cfcsum);
  3474. /*
  3475. * And now tell the firmware to use the configuration we just loaded.
  3476. */
  3477. caps_cmd.op_to_write =
  3478. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3479. FW_CMD_REQUEST_F |
  3480. FW_CMD_WRITE_F);
  3481. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3482. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3483. NULL);
  3484. if (ret < 0)
  3485. goto bye;
  3486. /*
  3487. * Tweak configuration based on system architecture, module
  3488. * parameters, etc.
  3489. */
  3490. ret = adap_init0_tweaks(adapter);
  3491. if (ret < 0)
  3492. goto bye;
  3493. /* We will proceed even if HMA init fails. */
  3494. ret = adap_config_hma(adapter);
  3495. if (ret)
  3496. dev_err(adapter->pdev_dev,
  3497. "HMA configuration failed with error %d\n", ret);
  3498. /*
  3499. * And finally tell the firmware to initialize itself using the
  3500. * parameters from the Configuration File.
  3501. */
  3502. ret = t4_fw_initialize(adapter, adapter->mbox);
  3503. if (ret < 0)
  3504. goto bye;
  3505. /* Emit Firmware Configuration File information and return
  3506. * successfully.
  3507. */
  3508. dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
  3509. "Configuration File \"%s\", version %#x, computed checksum %#x\n",
  3510. config_name, finiver, cfcsum);
  3511. return 0;
  3512. /*
  3513. * Something bad happened. Return the error ... (If the "error"
  3514. * is that there's no Configuration File on the adapter we don't
  3515. * want to issue a warning since this is fairly common.)
  3516. */
  3517. bye:
  3518. if (config_issued && ret != -ENOENT)
  3519. dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
  3520. config_name, -ret);
  3521. return ret;
  3522. }
  3523. static struct fw_info fw_info_array[] = {
  3524. {
  3525. .chip = CHELSIO_T4,
  3526. .fs_name = FW4_CFNAME,
  3527. .fw_mod_name = FW4_FNAME,
  3528. .fw_hdr = {
  3529. .chip = FW_HDR_CHIP_T4,
  3530. .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
  3531. .intfver_nic = FW_INTFVER(T4, NIC),
  3532. .intfver_vnic = FW_INTFVER(T4, VNIC),
  3533. .intfver_ri = FW_INTFVER(T4, RI),
  3534. .intfver_iscsi = FW_INTFVER(T4, ISCSI),
  3535. .intfver_fcoe = FW_INTFVER(T4, FCOE),
  3536. },
  3537. }, {
  3538. .chip = CHELSIO_T5,
  3539. .fs_name = FW5_CFNAME,
  3540. .fw_mod_name = FW5_FNAME,
  3541. .fw_hdr = {
  3542. .chip = FW_HDR_CHIP_T5,
  3543. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  3544. .intfver_nic = FW_INTFVER(T5, NIC),
  3545. .intfver_vnic = FW_INTFVER(T5, VNIC),
  3546. .intfver_ri = FW_INTFVER(T5, RI),
  3547. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  3548. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  3549. },
  3550. }, {
  3551. .chip = CHELSIO_T6,
  3552. .fs_name = FW6_CFNAME,
  3553. .fw_mod_name = FW6_FNAME,
  3554. .fw_hdr = {
  3555. .chip = FW_HDR_CHIP_T6,
  3556. .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
  3557. .intfver_nic = FW_INTFVER(T6, NIC),
  3558. .intfver_vnic = FW_INTFVER(T6, VNIC),
  3559. .intfver_ofld = FW_INTFVER(T6, OFLD),
  3560. .intfver_ri = FW_INTFVER(T6, RI),
  3561. .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
  3562. .intfver_iscsi = FW_INTFVER(T6, ISCSI),
  3563. .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
  3564. .intfver_fcoe = FW_INTFVER(T6, FCOE),
  3565. },
  3566. }
  3567. };
  3568. static struct fw_info *find_fw_info(int chip)
  3569. {
  3570. int i;
  3571. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  3572. if (fw_info_array[i].chip == chip)
  3573. return &fw_info_array[i];
  3574. }
  3575. return NULL;
  3576. }
  3577. /*
  3578. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3579. */
  3580. static int adap_init0(struct adapter *adap)
  3581. {
  3582. int ret;
  3583. u32 v, port_vec;
  3584. enum dev_state state;
  3585. u32 params[7], val[7];
  3586. struct fw_caps_config_cmd caps_cmd;
  3587. int reset = 1;
  3588. /* Grab Firmware Device Log parameters as early as possible so we have
  3589. * access to it for debugging, etc.
  3590. */
  3591. ret = t4_init_devlog_params(adap);
  3592. if (ret < 0)
  3593. return ret;
  3594. /* Contact FW, advertising Master capability */
  3595. ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
  3596. is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
  3597. if (ret < 0) {
  3598. dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
  3599. ret);
  3600. return ret;
  3601. }
  3602. if (ret == adap->mbox)
  3603. adap->flags |= MASTER_PF;
  3604. /*
  3605. * If we're the Master PF Driver and the device is uninitialized,
  3606. * then let's consider upgrading the firmware ... (We always want
  3607. * to check the firmware version number in order to A. get it for
  3608. * later reporting and B. to warn if the currently loaded firmware
  3609. * is excessively mismatched relative to the driver.)
  3610. */
  3611. t4_get_version_info(adap);
  3612. ret = t4_check_fw_version(adap);
  3613. /* If firmware is too old (not supported by driver) force an update. */
  3614. if (ret)
  3615. state = DEV_STATE_UNINIT;
  3616. if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
  3617. struct fw_info *fw_info;
  3618. struct fw_hdr *card_fw;
  3619. const struct firmware *fw;
  3620. const u8 *fw_data = NULL;
  3621. unsigned int fw_size = 0;
  3622. /* This is the firmware whose headers the driver was compiled
  3623. * against
  3624. */
  3625. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
  3626. if (fw_info == NULL) {
  3627. dev_err(adap->pdev_dev,
  3628. "unable to get firmware info for chip %d.\n",
  3629. CHELSIO_CHIP_VERSION(adap->params.chip));
  3630. return -EINVAL;
  3631. }
  3632. /* allocate memory to read the header of the firmware on the
  3633. * card
  3634. */
  3635. card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL);
  3636. if (!card_fw) {
  3637. ret = -ENOMEM;
  3638. goto bye;
  3639. }
  3640. /* Get FW from from /lib/firmware/ */
  3641. ret = request_firmware(&fw, fw_info->fw_mod_name,
  3642. adap->pdev_dev);
  3643. if (ret < 0) {
  3644. dev_err(adap->pdev_dev,
  3645. "unable to load firmware image %s, error %d\n",
  3646. fw_info->fw_mod_name, ret);
  3647. } else {
  3648. fw_data = fw->data;
  3649. fw_size = fw->size;
  3650. }
  3651. /* upgrade FW logic */
  3652. ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
  3653. state, &reset);
  3654. /* Cleaning up */
  3655. release_firmware(fw);
  3656. kvfree(card_fw);
  3657. if (ret < 0)
  3658. goto bye;
  3659. }
  3660. /* If the firmware is initialized already, emit a simply note to that
  3661. * effect. Otherwise, it's time to try initializing the adapter.
  3662. */
  3663. if (state == DEV_STATE_INIT) {
  3664. ret = adap_config_hma(adap);
  3665. if (ret)
  3666. dev_err(adap->pdev_dev,
  3667. "HMA configuration failed with error %d\n",
  3668. ret);
  3669. dev_info(adap->pdev_dev, "Coming up as %s: "\
  3670. "Adapter already initialized\n",
  3671. adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
  3672. } else {
  3673. dev_info(adap->pdev_dev, "Coming up as MASTER: "\
  3674. "Initializing adapter\n");
  3675. /* Find out whether we're dealing with a version of the
  3676. * firmware which has configuration file support.
  3677. */
  3678. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3679. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3680. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3681. params, val);
  3682. /* If the firmware doesn't support Configuration Files,
  3683. * return an error.
  3684. */
  3685. if (ret < 0) {
  3686. dev_err(adap->pdev_dev, "firmware doesn't support "
  3687. "Firmware Configuration Files\n");
  3688. goto bye;
  3689. }
  3690. /* The firmware provides us with a memory buffer where we can
  3691. * load a Configuration File from the host if we want to
  3692. * override the Configuration File in flash.
  3693. */
  3694. ret = adap_init0_config(adap, reset);
  3695. if (ret == -ENOENT) {
  3696. dev_err(adap->pdev_dev, "no Configuration File "
  3697. "present on adapter.\n");
  3698. goto bye;
  3699. }
  3700. if (ret < 0) {
  3701. dev_err(adap->pdev_dev, "could not initialize "
  3702. "adapter, error %d\n", -ret);
  3703. goto bye;
  3704. }
  3705. }
  3706. /* Now that we've successfully configured and initialized the adapter
  3707. * (or found it already initialized), we can ask the Firmware what
  3708. * resources it has provisioned for us.
  3709. */
  3710. ret = t4_get_pfres(adap);
  3711. if (ret) {
  3712. dev_err(adap->pdev_dev,
  3713. "Unable to retrieve resource provisioning information\n");
  3714. goto bye;
  3715. }
  3716. /* Grab VPD parameters. This should be done after we establish a
  3717. * connection to the firmware since some of the VPD parameters
  3718. * (notably the Core Clock frequency) are retrieved via requests to
  3719. * the firmware. On the other hand, we need these fairly early on
  3720. * so we do this right after getting ahold of the firmware.
  3721. *
  3722. * We need to do this after initializing the adapter because someone
  3723. * could have FLASHed a new VPD which won't be read by the firmware
  3724. * until we do the RESET ...
  3725. */
  3726. ret = t4_get_vpd_params(adap, &adap->params.vpd);
  3727. if (ret < 0)
  3728. goto bye;
  3729. /* Find out what ports are available to us. Note that we need to do
  3730. * this before calling adap_init0_no_config() since it needs nports
  3731. * and portvec ...
  3732. */
  3733. v =
  3734. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3735. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  3736. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
  3737. if (ret < 0)
  3738. goto bye;
  3739. adap->params.nports = hweight32(port_vec);
  3740. adap->params.portvec = port_vec;
  3741. /* Give the SGE code a chance to pull in anything that it needs ...
  3742. * Note that this must be called after we retrieve our VPD parameters
  3743. * in order to know how to convert core ticks to seconds, etc.
  3744. */
  3745. ret = t4_sge_init(adap);
  3746. if (ret < 0)
  3747. goto bye;
  3748. if (is_bypass_device(adap->pdev->device))
  3749. adap->params.bypass = 1;
  3750. /*
  3751. * Grab some of our basic fundamental operating parameters.
  3752. */
  3753. #define FW_PARAM_DEV(param) \
  3754. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
  3755. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
  3756. #define FW_PARAM_PFVF(param) \
  3757. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  3758. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
  3759. FW_PARAMS_PARAM_Y_V(0) | \
  3760. FW_PARAMS_PARAM_Z_V(0)
  3761. params[0] = FW_PARAM_PFVF(EQ_START);
  3762. params[1] = FW_PARAM_PFVF(L2T_START);
  3763. params[2] = FW_PARAM_PFVF(L2T_END);
  3764. params[3] = FW_PARAM_PFVF(FILTER_START);
  3765. params[4] = FW_PARAM_PFVF(FILTER_END);
  3766. params[5] = FW_PARAM_PFVF(IQFLINT_START);
  3767. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
  3768. if (ret < 0)
  3769. goto bye;
  3770. adap->sge.egr_start = val[0];
  3771. adap->l2t_start = val[1];
  3772. adap->l2t_end = val[2];
  3773. adap->tids.ftid_base = val[3];
  3774. adap->tids.nftids = val[4] - val[3] + 1;
  3775. adap->sge.ingr_start = val[5];
  3776. if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
  3777. /* Read the raw mps entries. In T6, the last 2 tcam entries
  3778. * are reserved for raw mac addresses (rawf = 2, one per port).
  3779. */
  3780. params[0] = FW_PARAM_PFVF(RAWF_START);
  3781. params[1] = FW_PARAM_PFVF(RAWF_END);
  3782. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3783. params, val);
  3784. if (ret == 0) {
  3785. adap->rawf_start = val[0];
  3786. adap->rawf_cnt = val[1] - val[0] + 1;
  3787. }
  3788. }
  3789. /* qids (ingress/egress) returned from firmware can be anywhere
  3790. * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
  3791. * Hence driver needs to allocate memory for this range to
  3792. * store the queue info. Get the highest IQFLINT/EQ index returned
  3793. * in FW_EQ_*_CMD.alloc command.
  3794. */
  3795. params[0] = FW_PARAM_PFVF(EQ_END);
  3796. params[1] = FW_PARAM_PFVF(IQFLINT_END);
  3797. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3798. if (ret < 0)
  3799. goto bye;
  3800. adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
  3801. adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
  3802. adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
  3803. sizeof(*adap->sge.egr_map), GFP_KERNEL);
  3804. if (!adap->sge.egr_map) {
  3805. ret = -ENOMEM;
  3806. goto bye;
  3807. }
  3808. adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
  3809. sizeof(*adap->sge.ingr_map), GFP_KERNEL);
  3810. if (!adap->sge.ingr_map) {
  3811. ret = -ENOMEM;
  3812. goto bye;
  3813. }
  3814. /* Allocate the memory for the vaious egress queue bitmaps
  3815. * ie starving_fl, txq_maperr and blocked_fl.
  3816. */
  3817. adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3818. sizeof(long), GFP_KERNEL);
  3819. if (!adap->sge.starving_fl) {
  3820. ret = -ENOMEM;
  3821. goto bye;
  3822. }
  3823. adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3824. sizeof(long), GFP_KERNEL);
  3825. if (!adap->sge.txq_maperr) {
  3826. ret = -ENOMEM;
  3827. goto bye;
  3828. }
  3829. #ifdef CONFIG_DEBUG_FS
  3830. adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3831. sizeof(long), GFP_KERNEL);
  3832. if (!adap->sge.blocked_fl) {
  3833. ret = -ENOMEM;
  3834. goto bye;
  3835. }
  3836. #endif
  3837. params[0] = FW_PARAM_PFVF(CLIP_START);
  3838. params[1] = FW_PARAM_PFVF(CLIP_END);
  3839. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3840. if (ret < 0)
  3841. goto bye;
  3842. adap->clipt_start = val[0];
  3843. adap->clipt_end = val[1];
  3844. /* We don't yet have a PARAMs calls to retrieve the number of Traffic
  3845. * Classes supported by the hardware/firmware so we hard code it here
  3846. * for now.
  3847. */
  3848. adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
  3849. /* query params related to active filter region */
  3850. params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
  3851. params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
  3852. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3853. /* If Active filter size is set we enable establishing
  3854. * offload connection through firmware work request
  3855. */
  3856. if ((val[0] != val[1]) && (ret >= 0)) {
  3857. adap->flags |= FW_OFLD_CONN;
  3858. adap->tids.aftid_base = val[0];
  3859. adap->tids.aftid_end = val[1];
  3860. }
  3861. /* If we're running on newer firmware, let it know that we're
  3862. * prepared to deal with encapsulated CPL messages. Older
  3863. * firmware won't understand this and we'll just get
  3864. * unencapsulated messages ...
  3865. */
  3866. params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
  3867. val[0] = 1;
  3868. (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
  3869. /*
  3870. * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
  3871. * capability. Earlier versions of the firmware didn't have the
  3872. * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
  3873. * permission to use ULPTX MEMWRITE DSGL.
  3874. */
  3875. if (is_t4(adap->params.chip)) {
  3876. adap->params.ulptx_memwrite_dsgl = false;
  3877. } else {
  3878. params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
  3879. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3880. 1, params, val);
  3881. adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
  3882. }
  3883. /* See if FW supports FW_RI_FR_NSMR_TPTE_WR work request */
  3884. params[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR);
  3885. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3886. 1, params, val);
  3887. adap->params.fr_nsmr_tpte_wr_support = (ret == 0 && val[0] != 0);
  3888. /* See if FW supports FW_FILTER2 work request */
  3889. if (is_t4(adap->params.chip)) {
  3890. adap->params.filter2_wr_support = 0;
  3891. } else {
  3892. params[0] = FW_PARAM_DEV(FILTER2_WR);
  3893. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3894. 1, params, val);
  3895. adap->params.filter2_wr_support = (ret == 0 && val[0] != 0);
  3896. }
  3897. /*
  3898. * Get device capabilities so we can determine what resources we need
  3899. * to manage.
  3900. */
  3901. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3902. caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3903. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3904. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3905. ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
  3906. &caps_cmd);
  3907. if (ret < 0)
  3908. goto bye;
  3909. if (caps_cmd.ofldcaps ||
  3910. (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER))) {
  3911. /* query offload-related parameters */
  3912. params[0] = FW_PARAM_DEV(NTID);
  3913. params[1] = FW_PARAM_PFVF(SERVER_START);
  3914. params[2] = FW_PARAM_PFVF(SERVER_END);
  3915. params[3] = FW_PARAM_PFVF(TDDP_START);
  3916. params[4] = FW_PARAM_PFVF(TDDP_END);
  3917. params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
  3918. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3919. params, val);
  3920. if (ret < 0)
  3921. goto bye;
  3922. adap->tids.ntids = val[0];
  3923. adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
  3924. adap->tids.stid_base = val[1];
  3925. adap->tids.nstids = val[2] - val[1] + 1;
  3926. /*
  3927. * Setup server filter region. Divide the available filter
  3928. * region into two parts. Regular filters get 1/3rd and server
  3929. * filters get 2/3rd part. This is only enabled if workarond
  3930. * path is enabled.
  3931. * 1. For regular filters.
  3932. * 2. Server filter: This are special filters which are used
  3933. * to redirect SYN packets to offload queue.
  3934. */
  3935. if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
  3936. adap->tids.sftid_base = adap->tids.ftid_base +
  3937. DIV_ROUND_UP(adap->tids.nftids, 3);
  3938. adap->tids.nsftids = adap->tids.nftids -
  3939. DIV_ROUND_UP(adap->tids.nftids, 3);
  3940. adap->tids.nftids = adap->tids.sftid_base -
  3941. adap->tids.ftid_base;
  3942. }
  3943. adap->vres.ddp.start = val[3];
  3944. adap->vres.ddp.size = val[4] - val[3] + 1;
  3945. adap->params.ofldq_wr_cred = val[5];
  3946. if (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER)) {
  3947. ret = init_hash_filter(adap);
  3948. if (ret < 0)
  3949. goto bye;
  3950. } else {
  3951. adap->params.offload = 1;
  3952. adap->num_ofld_uld += 1;
  3953. }
  3954. }
  3955. if (caps_cmd.rdmacaps) {
  3956. params[0] = FW_PARAM_PFVF(STAG_START);
  3957. params[1] = FW_PARAM_PFVF(STAG_END);
  3958. params[2] = FW_PARAM_PFVF(RQ_START);
  3959. params[3] = FW_PARAM_PFVF(RQ_END);
  3960. params[4] = FW_PARAM_PFVF(PBL_START);
  3961. params[5] = FW_PARAM_PFVF(PBL_END);
  3962. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3963. params, val);
  3964. if (ret < 0)
  3965. goto bye;
  3966. adap->vres.stag.start = val[0];
  3967. adap->vres.stag.size = val[1] - val[0] + 1;
  3968. adap->vres.rq.start = val[2];
  3969. adap->vres.rq.size = val[3] - val[2] + 1;
  3970. adap->vres.pbl.start = val[4];
  3971. adap->vres.pbl.size = val[5] - val[4] + 1;
  3972. params[0] = FW_PARAM_PFVF(SRQ_START);
  3973. params[1] = FW_PARAM_PFVF(SRQ_END);
  3974. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3975. params, val);
  3976. if (!ret) {
  3977. adap->vres.srq.start = val[0];
  3978. adap->vres.srq.size = val[1] - val[0] + 1;
  3979. }
  3980. if (adap->vres.srq.size) {
  3981. adap->srq = t4_init_srq(adap->vres.srq.size);
  3982. if (!adap->srq)
  3983. dev_warn(&adap->pdev->dev, "could not allocate SRQ, continuing\n");
  3984. }
  3985. params[0] = FW_PARAM_PFVF(SQRQ_START);
  3986. params[1] = FW_PARAM_PFVF(SQRQ_END);
  3987. params[2] = FW_PARAM_PFVF(CQ_START);
  3988. params[3] = FW_PARAM_PFVF(CQ_END);
  3989. params[4] = FW_PARAM_PFVF(OCQ_START);
  3990. params[5] = FW_PARAM_PFVF(OCQ_END);
  3991. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
  3992. val);
  3993. if (ret < 0)
  3994. goto bye;
  3995. adap->vres.qp.start = val[0];
  3996. adap->vres.qp.size = val[1] - val[0] + 1;
  3997. adap->vres.cq.start = val[2];
  3998. adap->vres.cq.size = val[3] - val[2] + 1;
  3999. adap->vres.ocq.start = val[4];
  4000. adap->vres.ocq.size = val[5] - val[4] + 1;
  4001. params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
  4002. params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
  4003. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
  4004. val);
  4005. if (ret < 0) {
  4006. adap->params.max_ordird_qp = 8;
  4007. adap->params.max_ird_adapter = 32 * adap->tids.ntids;
  4008. ret = 0;
  4009. } else {
  4010. adap->params.max_ordird_qp = val[0];
  4011. adap->params.max_ird_adapter = val[1];
  4012. }
  4013. dev_info(adap->pdev_dev,
  4014. "max_ordird_qp %d max_ird_adapter %d\n",
  4015. adap->params.max_ordird_qp,
  4016. adap->params.max_ird_adapter);
  4017. /* Enable write_with_immediate if FW supports it */
  4018. params[0] = FW_PARAM_DEV(RDMA_WRITE_WITH_IMM);
  4019. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params,
  4020. val);
  4021. adap->params.write_w_imm_support = (ret == 0 && val[0] != 0);
  4022. /* Enable write_cmpl if FW supports it */
  4023. params[0] = FW_PARAM_DEV(RI_WRITE_CMPL_WR);
  4024. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params,
  4025. val);
  4026. adap->params.write_cmpl_support = (ret == 0 && val[0] != 0);
  4027. adap->num_ofld_uld += 2;
  4028. }
  4029. if (caps_cmd.iscsicaps) {
  4030. params[0] = FW_PARAM_PFVF(ISCSI_START);
  4031. params[1] = FW_PARAM_PFVF(ISCSI_END);
  4032. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  4033. params, val);
  4034. if (ret < 0)
  4035. goto bye;
  4036. adap->vres.iscsi.start = val[0];
  4037. adap->vres.iscsi.size = val[1] - val[0] + 1;
  4038. /* LIO target and cxgb4i initiaitor */
  4039. adap->num_ofld_uld += 2;
  4040. }
  4041. if (caps_cmd.cryptocaps) {
  4042. if (ntohs(caps_cmd.cryptocaps) &
  4043. FW_CAPS_CONFIG_CRYPTO_LOOKASIDE) {
  4044. params[0] = FW_PARAM_PFVF(NCRYPTO_LOOKASIDE);
  4045. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  4046. 2, params, val);
  4047. if (ret < 0) {
  4048. if (ret != -EINVAL)
  4049. goto bye;
  4050. } else {
  4051. adap->vres.ncrypto_fc = val[0];
  4052. }
  4053. adap->num_ofld_uld += 1;
  4054. }
  4055. if (ntohs(caps_cmd.cryptocaps) &
  4056. FW_CAPS_CONFIG_TLS_INLINE) {
  4057. params[0] = FW_PARAM_PFVF(TLS_START);
  4058. params[1] = FW_PARAM_PFVF(TLS_END);
  4059. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  4060. 2, params, val);
  4061. if (ret < 0)
  4062. goto bye;
  4063. adap->vres.key.start = val[0];
  4064. adap->vres.key.size = val[1] - val[0] + 1;
  4065. adap->num_uld += 1;
  4066. }
  4067. adap->params.crypto = ntohs(caps_cmd.cryptocaps);
  4068. }
  4069. #undef FW_PARAM_PFVF
  4070. #undef FW_PARAM_DEV
  4071. /* The MTU/MSS Table is initialized by now, so load their values. If
  4072. * we're initializing the adapter, then we'll make any modifications
  4073. * we want to the MTU/MSS Table and also initialize the congestion
  4074. * parameters.
  4075. */
  4076. t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
  4077. if (state != DEV_STATE_INIT) {
  4078. int i;
  4079. /* The default MTU Table contains values 1492 and 1500.
  4080. * However, for TCP, it's better to have two values which are
  4081. * a multiple of 8 +/- 4 bytes apart near this popular MTU.
  4082. * This allows us to have a TCP Data Payload which is a
  4083. * multiple of 8 regardless of what combination of TCP Options
  4084. * are in use (always a multiple of 4 bytes) which is
  4085. * important for performance reasons. For instance, if no
  4086. * options are in use, then we have a 20-byte IP header and a
  4087. * 20-byte TCP header. In this case, a 1500-byte MSS would
  4088. * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
  4089. * which is not a multiple of 8. So using an MSS of 1488 in
  4090. * this case results in a TCP Data Payload of 1448 bytes which
  4091. * is a multiple of 8. On the other hand, if 12-byte TCP Time
  4092. * Stamps have been negotiated, then an MTU of 1500 bytes
  4093. * results in a TCP Data Payload of 1448 bytes which, as
  4094. * above, is a multiple of 8 bytes ...
  4095. */
  4096. for (i = 0; i < NMTUS; i++)
  4097. if (adap->params.mtus[i] == 1492) {
  4098. adap->params.mtus[i] = 1488;
  4099. break;
  4100. }
  4101. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4102. adap->params.b_wnd);
  4103. }
  4104. t4_init_sge_params(adap);
  4105. adap->flags |= FW_OK;
  4106. t4_init_tp_params(adap, true);
  4107. return 0;
  4108. /*
  4109. * Something bad happened. If a command timed out or failed with EIO
  4110. * FW does not operate within its spec or something catastrophic
  4111. * happened to HW/FW, stop issuing commands.
  4112. */
  4113. bye:
  4114. adap_free_hma_mem(adap);
  4115. kfree(adap->sge.egr_map);
  4116. kfree(adap->sge.ingr_map);
  4117. kfree(adap->sge.starving_fl);
  4118. kfree(adap->sge.txq_maperr);
  4119. #ifdef CONFIG_DEBUG_FS
  4120. kfree(adap->sge.blocked_fl);
  4121. #endif
  4122. if (ret != -ETIMEDOUT && ret != -EIO)
  4123. t4_fw_bye(adap, adap->mbox);
  4124. return ret;
  4125. }
  4126. /* EEH callbacks */
  4127. static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
  4128. pci_channel_state_t state)
  4129. {
  4130. int i;
  4131. struct adapter *adap = pci_get_drvdata(pdev);
  4132. if (!adap)
  4133. goto out;
  4134. rtnl_lock();
  4135. adap->flags &= ~FW_OK;
  4136. notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
  4137. spin_lock(&adap->stats_lock);
  4138. for_each_port(adap, i) {
  4139. struct net_device *dev = adap->port[i];
  4140. if (dev) {
  4141. netif_device_detach(dev);
  4142. netif_carrier_off(dev);
  4143. }
  4144. }
  4145. spin_unlock(&adap->stats_lock);
  4146. disable_interrupts(adap);
  4147. if (adap->flags & FULL_INIT_DONE)
  4148. cxgb_down(adap);
  4149. rtnl_unlock();
  4150. if ((adap->flags & DEV_ENABLED)) {
  4151. pci_disable_device(pdev);
  4152. adap->flags &= ~DEV_ENABLED;
  4153. }
  4154. out: return state == pci_channel_io_perm_failure ?
  4155. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  4156. }
  4157. static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
  4158. {
  4159. int i, ret;
  4160. struct fw_caps_config_cmd c;
  4161. struct adapter *adap = pci_get_drvdata(pdev);
  4162. if (!adap) {
  4163. pci_restore_state(pdev);
  4164. pci_save_state(pdev);
  4165. return PCI_ERS_RESULT_RECOVERED;
  4166. }
  4167. if (!(adap->flags & DEV_ENABLED)) {
  4168. if (pci_enable_device(pdev)) {
  4169. dev_err(&pdev->dev, "Cannot reenable PCI "
  4170. "device after reset\n");
  4171. return PCI_ERS_RESULT_DISCONNECT;
  4172. }
  4173. adap->flags |= DEV_ENABLED;
  4174. }
  4175. pci_set_master(pdev);
  4176. pci_restore_state(pdev);
  4177. pci_save_state(pdev);
  4178. pci_cleanup_aer_uncorrect_error_status(pdev);
  4179. if (t4_wait_dev_ready(adap->regs) < 0)
  4180. return PCI_ERS_RESULT_DISCONNECT;
  4181. if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
  4182. return PCI_ERS_RESULT_DISCONNECT;
  4183. adap->flags |= FW_OK;
  4184. if (adap_init1(adap, &c))
  4185. return PCI_ERS_RESULT_DISCONNECT;
  4186. for_each_port(adap, i) {
  4187. struct port_info *p = adap2pinfo(adap, i);
  4188. ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
  4189. NULL, NULL);
  4190. if (ret < 0)
  4191. return PCI_ERS_RESULT_DISCONNECT;
  4192. p->viid = ret;
  4193. p->xact_addr_filt = -1;
  4194. }
  4195. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4196. adap->params.b_wnd);
  4197. setup_memwin(adap);
  4198. if (cxgb_up(adap))
  4199. return PCI_ERS_RESULT_DISCONNECT;
  4200. return PCI_ERS_RESULT_RECOVERED;
  4201. }
  4202. static void eeh_resume(struct pci_dev *pdev)
  4203. {
  4204. int i;
  4205. struct adapter *adap = pci_get_drvdata(pdev);
  4206. if (!adap)
  4207. return;
  4208. rtnl_lock();
  4209. for_each_port(adap, i) {
  4210. struct net_device *dev = adap->port[i];
  4211. if (dev) {
  4212. if (netif_running(dev)) {
  4213. link_start(dev);
  4214. cxgb_set_rxmode(dev);
  4215. }
  4216. netif_device_attach(dev);
  4217. }
  4218. }
  4219. rtnl_unlock();
  4220. }
  4221. static const struct pci_error_handlers cxgb4_eeh = {
  4222. .error_detected = eeh_err_detected,
  4223. .slot_reset = eeh_slot_reset,
  4224. .resume = eeh_resume,
  4225. };
  4226. /* Return true if the Link Configuration supports "High Speeds" (those greater
  4227. * than 1Gb/s).
  4228. */
  4229. static inline bool is_x_10g_port(const struct link_config *lc)
  4230. {
  4231. unsigned int speeds, high_speeds;
  4232. speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
  4233. high_speeds = speeds &
  4234. ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
  4235. return high_speeds != 0;
  4236. }
  4237. /*
  4238. * Perform default configuration of DMA queues depending on the number and type
  4239. * of ports we found and the number of available CPUs. Most settings can be
  4240. * modified by the admin prior to actual use.
  4241. */
  4242. static int cfg_queues(struct adapter *adap)
  4243. {
  4244. struct sge *s = &adap->sge;
  4245. int i, n10g = 0, qidx = 0;
  4246. int niqflint, neq, avail_eth_qsets;
  4247. int max_eth_qsets = 32;
  4248. #ifndef CONFIG_CHELSIO_T4_DCB
  4249. int q10g = 0;
  4250. #endif
  4251. /* Reduce memory usage in kdump environment, disable all offload.
  4252. */
  4253. if (is_kdump_kernel() || (is_uld(adap) && t4_uld_mem_alloc(adap))) {
  4254. adap->params.offload = 0;
  4255. adap->params.crypto = 0;
  4256. }
  4257. /* Calculate the number of Ethernet Queue Sets available based on
  4258. * resources provisioned for us. We always have an Asynchronous
  4259. * Firmware Event Ingress Queue. If we're operating in MSI or Legacy
  4260. * IRQ Pin Interrupt mode, then we'll also have a Forwarded Interrupt
  4261. * Ingress Queue. Meanwhile, we need two Egress Queues for each
  4262. * Queue Set: one for the Free List and one for the Ethernet TX Queue.
  4263. *
  4264. * Note that we should also take into account all of the various
  4265. * Offload Queues. But, in any situation where we're operating in
  4266. * a Resource Constrained Provisioning environment, doing any Offload
  4267. * at all is problematic ...
  4268. */
  4269. niqflint = adap->params.pfres.niqflint - 1;
  4270. if (!(adap->flags & USING_MSIX))
  4271. niqflint--;
  4272. neq = adap->params.pfres.neq / 2;
  4273. avail_eth_qsets = min(niqflint, neq);
  4274. if (avail_eth_qsets > max_eth_qsets)
  4275. avail_eth_qsets = max_eth_qsets;
  4276. if (avail_eth_qsets < adap->params.nports) {
  4277. dev_err(adap->pdev_dev, "avail_eth_qsets=%d < nports=%d\n",
  4278. avail_eth_qsets, adap->params.nports);
  4279. return -ENOMEM;
  4280. }
  4281. /* Count the number of 10Gb/s or better ports */
  4282. for_each_port(adap, i)
  4283. n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
  4284. #ifdef CONFIG_CHELSIO_T4_DCB
  4285. /* For Data Center Bridging support we need to be able to support up
  4286. * to 8 Traffic Priorities; each of which will be assigned to its
  4287. * own TX Queue in order to prevent Head-Of-Line Blocking.
  4288. */
  4289. if (adap->params.nports * 8 > avail_eth_qsets) {
  4290. dev_err(adap->pdev_dev, "DCB avail_eth_qsets=%d < %d!\n",
  4291. avail_eth_qsets, adap->params.nports * 8);
  4292. return -ENOMEM;
  4293. }
  4294. for_each_port(adap, i) {
  4295. struct port_info *pi = adap2pinfo(adap, i);
  4296. pi->first_qset = qidx;
  4297. pi->nqsets = is_kdump_kernel() ? 1 : 8;
  4298. qidx += pi->nqsets;
  4299. }
  4300. #else /* !CONFIG_CHELSIO_T4_DCB */
  4301. /*
  4302. * We default to 1 queue per non-10G port and up to # of cores queues
  4303. * per 10G port.
  4304. */
  4305. if (n10g)
  4306. q10g = (avail_eth_qsets - (adap->params.nports - n10g)) / n10g;
  4307. if (q10g > netif_get_num_default_rss_queues())
  4308. q10g = netif_get_num_default_rss_queues();
  4309. if (is_kdump_kernel())
  4310. q10g = 1;
  4311. for_each_port(adap, i) {
  4312. struct port_info *pi = adap2pinfo(adap, i);
  4313. pi->first_qset = qidx;
  4314. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  4315. qidx += pi->nqsets;
  4316. }
  4317. #endif /* !CONFIG_CHELSIO_T4_DCB */
  4318. s->ethqsets = qidx;
  4319. s->max_ethqsets = qidx; /* MSI-X may lower it later */
  4320. if (is_uld(adap)) {
  4321. /*
  4322. * For offload we use 1 queue/channel if all ports are up to 1G,
  4323. * otherwise we divide all available queues amongst the channels
  4324. * capped by the number of available cores.
  4325. */
  4326. if (n10g) {
  4327. i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
  4328. s->ofldqsets = roundup(i, adap->params.nports);
  4329. } else {
  4330. s->ofldqsets = adap->params.nports;
  4331. }
  4332. }
  4333. for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
  4334. struct sge_eth_rxq *r = &s->ethrxq[i];
  4335. init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
  4336. r->fl.size = 72;
  4337. }
  4338. for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
  4339. s->ethtxq[i].q.size = 1024;
  4340. for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
  4341. s->ctrlq[i].q.size = 512;
  4342. if (!is_t4(adap->params.chip))
  4343. s->ptptxq.q.size = 8;
  4344. init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
  4345. init_rspq(adap, &s->intrq, 0, 1, 512, 64);
  4346. return 0;
  4347. }
  4348. /*
  4349. * Reduce the number of Ethernet queues across all ports to at most n.
  4350. * n provides at least one queue per port.
  4351. */
  4352. static void reduce_ethqs(struct adapter *adap, int n)
  4353. {
  4354. int i;
  4355. struct port_info *pi;
  4356. while (n < adap->sge.ethqsets)
  4357. for_each_port(adap, i) {
  4358. pi = adap2pinfo(adap, i);
  4359. if (pi->nqsets > 1) {
  4360. pi->nqsets--;
  4361. adap->sge.ethqsets--;
  4362. if (adap->sge.ethqsets <= n)
  4363. break;
  4364. }
  4365. }
  4366. n = 0;
  4367. for_each_port(adap, i) {
  4368. pi = adap2pinfo(adap, i);
  4369. pi->first_qset = n;
  4370. n += pi->nqsets;
  4371. }
  4372. }
  4373. static int get_msix_info(struct adapter *adap)
  4374. {
  4375. struct uld_msix_info *msix_info;
  4376. unsigned int max_ingq = 0;
  4377. if (is_offload(adap))
  4378. max_ingq += MAX_OFLD_QSETS * adap->num_ofld_uld;
  4379. if (is_pci_uld(adap))
  4380. max_ingq += MAX_OFLD_QSETS * adap->num_uld;
  4381. if (!max_ingq)
  4382. goto out;
  4383. msix_info = kcalloc(max_ingq, sizeof(*msix_info), GFP_KERNEL);
  4384. if (!msix_info)
  4385. return -ENOMEM;
  4386. adap->msix_bmap_ulds.msix_bmap = kcalloc(BITS_TO_LONGS(max_ingq),
  4387. sizeof(long), GFP_KERNEL);
  4388. if (!adap->msix_bmap_ulds.msix_bmap) {
  4389. kfree(msix_info);
  4390. return -ENOMEM;
  4391. }
  4392. spin_lock_init(&adap->msix_bmap_ulds.lock);
  4393. adap->msix_info_ulds = msix_info;
  4394. out:
  4395. return 0;
  4396. }
  4397. static void free_msix_info(struct adapter *adap)
  4398. {
  4399. if (!(adap->num_uld && adap->num_ofld_uld))
  4400. return;
  4401. kfree(adap->msix_info_ulds);
  4402. kfree(adap->msix_bmap_ulds.msix_bmap);
  4403. }
  4404. /* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
  4405. #define EXTRA_VECS 2
  4406. static int enable_msix(struct adapter *adap)
  4407. {
  4408. int ofld_need = 0, uld_need = 0;
  4409. int i, j, want, need, allocated;
  4410. struct sge *s = &adap->sge;
  4411. unsigned int nchan = adap->params.nports;
  4412. struct msix_entry *entries;
  4413. int max_ingq = MAX_INGQ;
  4414. if (is_pci_uld(adap))
  4415. max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
  4416. if (is_offload(adap))
  4417. max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
  4418. entries = kmalloc_array(max_ingq + 1, sizeof(*entries),
  4419. GFP_KERNEL);
  4420. if (!entries)
  4421. return -ENOMEM;
  4422. /* map for msix */
  4423. if (get_msix_info(adap)) {
  4424. adap->params.offload = 0;
  4425. adap->params.crypto = 0;
  4426. }
  4427. for (i = 0; i < max_ingq + 1; ++i)
  4428. entries[i].entry = i;
  4429. want = s->max_ethqsets + EXTRA_VECS;
  4430. if (is_offload(adap)) {
  4431. want += adap->num_ofld_uld * s->ofldqsets;
  4432. ofld_need = adap->num_ofld_uld * nchan;
  4433. }
  4434. if (is_pci_uld(adap)) {
  4435. want += adap->num_uld * s->ofldqsets;
  4436. uld_need = adap->num_uld * nchan;
  4437. }
  4438. #ifdef CONFIG_CHELSIO_T4_DCB
  4439. /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
  4440. * each port.
  4441. */
  4442. need = 8 * adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  4443. #else
  4444. need = adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  4445. #endif
  4446. allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
  4447. if (allocated < 0) {
  4448. dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
  4449. " not using MSI-X\n");
  4450. kfree(entries);
  4451. return allocated;
  4452. }
  4453. /* Distribute available vectors to the various queue groups.
  4454. * Every group gets its minimum requirement and NIC gets top
  4455. * priority for leftovers.
  4456. */
  4457. i = allocated - EXTRA_VECS - ofld_need - uld_need;
  4458. if (i < s->max_ethqsets) {
  4459. s->max_ethqsets = i;
  4460. if (i < s->ethqsets)
  4461. reduce_ethqs(adap, i);
  4462. }
  4463. if (is_uld(adap)) {
  4464. if (allocated < want)
  4465. s->nqs_per_uld = nchan;
  4466. else
  4467. s->nqs_per_uld = s->ofldqsets;
  4468. }
  4469. for (i = 0; i < (s->max_ethqsets + EXTRA_VECS); ++i)
  4470. adap->msix_info[i].vec = entries[i].vector;
  4471. if (is_uld(adap)) {
  4472. for (j = 0 ; i < allocated; ++i, j++) {
  4473. adap->msix_info_ulds[j].vec = entries[i].vector;
  4474. adap->msix_info_ulds[j].idx = i;
  4475. }
  4476. adap->msix_bmap_ulds.mapsize = j;
  4477. }
  4478. dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
  4479. "nic %d per uld %d\n",
  4480. allocated, s->max_ethqsets, s->nqs_per_uld);
  4481. kfree(entries);
  4482. return 0;
  4483. }
  4484. #undef EXTRA_VECS
  4485. static int init_rss(struct adapter *adap)
  4486. {
  4487. unsigned int i;
  4488. int err;
  4489. err = t4_init_rss_mode(adap, adap->mbox);
  4490. if (err)
  4491. return err;
  4492. for_each_port(adap, i) {
  4493. struct port_info *pi = adap2pinfo(adap, i);
  4494. pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
  4495. if (!pi->rss)
  4496. return -ENOMEM;
  4497. }
  4498. return 0;
  4499. }
  4500. /* Dump basic information about the adapter */
  4501. static void print_adapter_info(struct adapter *adapter)
  4502. {
  4503. /* Hardware/Firmware/etc. Version/Revision IDs */
  4504. t4_dump_version_info(adapter);
  4505. /* Software/Hardware configuration */
  4506. dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
  4507. is_offload(adapter) ? "R" : "",
  4508. ((adapter->flags & USING_MSIX) ? "MSI-X" :
  4509. (adapter->flags & USING_MSI) ? "MSI" : ""),
  4510. is_offload(adapter) ? "Offload" : "non-Offload");
  4511. }
  4512. static void print_port_info(const struct net_device *dev)
  4513. {
  4514. char buf[80];
  4515. char *bufp = buf;
  4516. const struct port_info *pi = netdev_priv(dev);
  4517. const struct adapter *adap = pi->adapter;
  4518. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M)
  4519. bufp += sprintf(bufp, "100M/");
  4520. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G)
  4521. bufp += sprintf(bufp, "1G/");
  4522. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G)
  4523. bufp += sprintf(bufp, "10G/");
  4524. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G)
  4525. bufp += sprintf(bufp, "25G/");
  4526. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G)
  4527. bufp += sprintf(bufp, "40G/");
  4528. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G)
  4529. bufp += sprintf(bufp, "50G/");
  4530. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G)
  4531. bufp += sprintf(bufp, "100G/");
  4532. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_200G)
  4533. bufp += sprintf(bufp, "200G/");
  4534. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_400G)
  4535. bufp += sprintf(bufp, "400G/");
  4536. if (bufp != buf)
  4537. --bufp;
  4538. sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
  4539. netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
  4540. dev->name, adap->params.vpd.id, adap->name, buf);
  4541. }
  4542. /*
  4543. * Free the following resources:
  4544. * - memory used for tables
  4545. * - MSI/MSI-X
  4546. * - net devices
  4547. * - resources FW is holding for us
  4548. */
  4549. static void free_some_resources(struct adapter *adapter)
  4550. {
  4551. unsigned int i;
  4552. kvfree(adapter->mps_encap);
  4553. kvfree(adapter->smt);
  4554. kvfree(adapter->l2t);
  4555. kvfree(adapter->srq);
  4556. t4_cleanup_sched(adapter);
  4557. kvfree(adapter->tids.tid_tab);
  4558. cxgb4_cleanup_tc_flower(adapter);
  4559. cxgb4_cleanup_tc_u32(adapter);
  4560. kfree(adapter->sge.egr_map);
  4561. kfree(adapter->sge.ingr_map);
  4562. kfree(adapter->sge.starving_fl);
  4563. kfree(adapter->sge.txq_maperr);
  4564. #ifdef CONFIG_DEBUG_FS
  4565. kfree(adapter->sge.blocked_fl);
  4566. #endif
  4567. disable_msi(adapter);
  4568. for_each_port(adapter, i)
  4569. if (adapter->port[i]) {
  4570. struct port_info *pi = adap2pinfo(adapter, i);
  4571. if (pi->viid != 0)
  4572. t4_free_vi(adapter, adapter->mbox, adapter->pf,
  4573. 0, pi->viid);
  4574. kfree(adap2pinfo(adapter, i)->rss);
  4575. free_netdev(adapter->port[i]);
  4576. }
  4577. if (adapter->flags & FW_OK)
  4578. t4_fw_bye(adapter, adapter->pf);
  4579. }
  4580. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  4581. #define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
  4582. NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
  4583. #define SEGMENT_SIZE 128
  4584. static int t4_get_chip_type(struct adapter *adap, int ver)
  4585. {
  4586. u32 pl_rev = REV_G(t4_read_reg(adap, PL_REV_A));
  4587. switch (ver) {
  4588. case CHELSIO_T4:
  4589. return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  4590. case CHELSIO_T5:
  4591. return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  4592. case CHELSIO_T6:
  4593. return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  4594. default:
  4595. break;
  4596. }
  4597. return -EINVAL;
  4598. }
  4599. #ifdef CONFIG_PCI_IOV
  4600. static void cxgb4_mgmt_setup(struct net_device *dev)
  4601. {
  4602. dev->type = ARPHRD_NONE;
  4603. dev->mtu = 0;
  4604. dev->hard_header_len = 0;
  4605. dev->addr_len = 0;
  4606. dev->tx_queue_len = 0;
  4607. dev->flags |= IFF_NOARP;
  4608. dev->priv_flags |= IFF_NO_QUEUE;
  4609. /* Initialize the device structure. */
  4610. dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
  4611. dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
  4612. }
  4613. static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
  4614. {
  4615. struct adapter *adap = pci_get_drvdata(pdev);
  4616. int err = 0;
  4617. int current_vfs = pci_num_vf(pdev);
  4618. u32 pcie_fw;
  4619. pcie_fw = readl(adap->regs + PCIE_FW_A);
  4620. /* Check if fw is initialized */
  4621. if (!(pcie_fw & PCIE_FW_INIT_F)) {
  4622. dev_warn(&pdev->dev, "Device not initialized\n");
  4623. return -EOPNOTSUPP;
  4624. }
  4625. /* If any of the VF's is already assigned to Guest OS, then
  4626. * SRIOV for the same cannot be modified
  4627. */
  4628. if (current_vfs && pci_vfs_assigned(pdev)) {
  4629. dev_err(&pdev->dev,
  4630. "Cannot modify SR-IOV while VFs are assigned\n");
  4631. return current_vfs;
  4632. }
  4633. /* Note that the upper-level code ensures that we're never called with
  4634. * a non-zero "num_vfs" when we already have VFs instantiated. But
  4635. * it never hurts to code defensively.
  4636. */
  4637. if (num_vfs != 0 && current_vfs != 0)
  4638. return -EBUSY;
  4639. /* Nothing to do for no change. */
  4640. if (num_vfs == current_vfs)
  4641. return num_vfs;
  4642. /* Disable SRIOV when zero is passed. */
  4643. if (!num_vfs) {
  4644. pci_disable_sriov(pdev);
  4645. /* free VF Management Interface */
  4646. unregister_netdev(adap->port[0]);
  4647. free_netdev(adap->port[0]);
  4648. adap->port[0] = NULL;
  4649. /* free VF resources */
  4650. adap->num_vfs = 0;
  4651. kfree(adap->vfinfo);
  4652. adap->vfinfo = NULL;
  4653. return 0;
  4654. }
  4655. if (!current_vfs) {
  4656. struct fw_pfvf_cmd port_cmd, port_rpl;
  4657. struct net_device *netdev;
  4658. unsigned int pmask, port;
  4659. struct pci_dev *pbridge;
  4660. struct port_info *pi;
  4661. char name[IFNAMSIZ];
  4662. u32 devcap2;
  4663. u16 flags;
  4664. int pos;
  4665. /* If we want to instantiate Virtual Functions, then our
  4666. * parent bridge's PCI-E needs to support Alternative Routing
  4667. * ID (ARI) because our VFs will show up at function offset 8
  4668. * and above.
  4669. */
  4670. pbridge = pdev->bus->self;
  4671. pos = pci_find_capability(pbridge, PCI_CAP_ID_EXP);
  4672. pci_read_config_word(pbridge, pos + PCI_EXP_FLAGS, &flags);
  4673. pci_read_config_dword(pbridge, pos + PCI_EXP_DEVCAP2, &devcap2);
  4674. if ((flags & PCI_EXP_FLAGS_VERS) < 2 ||
  4675. !(devcap2 & PCI_EXP_DEVCAP2_ARI)) {
  4676. /* Our parent bridge does not support ARI so issue a
  4677. * warning and skip instantiating the VFs. They
  4678. * won't be reachable.
  4679. */
  4680. dev_warn(&pdev->dev, "Parent bridge %02x:%02x.%x doesn't support ARI; can't instantiate Virtual Functions\n",
  4681. pbridge->bus->number, PCI_SLOT(pbridge->devfn),
  4682. PCI_FUNC(pbridge->devfn));
  4683. return -ENOTSUPP;
  4684. }
  4685. memset(&port_cmd, 0, sizeof(port_cmd));
  4686. port_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) |
  4687. FW_CMD_REQUEST_F |
  4688. FW_CMD_READ_F |
  4689. FW_PFVF_CMD_PFN_V(adap->pf) |
  4690. FW_PFVF_CMD_VFN_V(0));
  4691. port_cmd.retval_len16 = cpu_to_be32(FW_LEN16(port_cmd));
  4692. err = t4_wr_mbox(adap, adap->mbox, &port_cmd, sizeof(port_cmd),
  4693. &port_rpl);
  4694. if (err)
  4695. return err;
  4696. pmask = FW_PFVF_CMD_PMASK_G(be32_to_cpu(port_rpl.type_to_neq));
  4697. port = ffs(pmask) - 1;
  4698. /* Allocate VF Management Interface. */
  4699. snprintf(name, IFNAMSIZ, "mgmtpf%d,%d", adap->adap_idx,
  4700. adap->pf);
  4701. netdev = alloc_netdev(sizeof(struct port_info),
  4702. name, NET_NAME_UNKNOWN, cxgb4_mgmt_setup);
  4703. if (!netdev)
  4704. return -ENOMEM;
  4705. pi = netdev_priv(netdev);
  4706. pi->adapter = adap;
  4707. pi->lport = port;
  4708. pi->tx_chan = port;
  4709. SET_NETDEV_DEV(netdev, &pdev->dev);
  4710. adap->port[0] = netdev;
  4711. pi->port_id = 0;
  4712. err = register_netdev(adap->port[0]);
  4713. if (err) {
  4714. pr_info("Unable to register VF mgmt netdev %s\n", name);
  4715. free_netdev(adap->port[0]);
  4716. adap->port[0] = NULL;
  4717. return err;
  4718. }
  4719. /* Allocate and set up VF Information. */
  4720. adap->vfinfo = kcalloc(pci_sriov_get_totalvfs(pdev),
  4721. sizeof(struct vf_info), GFP_KERNEL);
  4722. if (!adap->vfinfo) {
  4723. unregister_netdev(adap->port[0]);
  4724. free_netdev(adap->port[0]);
  4725. adap->port[0] = NULL;
  4726. return -ENOMEM;
  4727. }
  4728. cxgb4_mgmt_fill_vf_station_mac_addr(adap);
  4729. }
  4730. /* Instantiate the requested number of VFs. */
  4731. err = pci_enable_sriov(pdev, num_vfs);
  4732. if (err) {
  4733. pr_info("Unable to instantiate %d VFs\n", num_vfs);
  4734. if (!current_vfs) {
  4735. unregister_netdev(adap->port[0]);
  4736. free_netdev(adap->port[0]);
  4737. adap->port[0] = NULL;
  4738. kfree(adap->vfinfo);
  4739. adap->vfinfo = NULL;
  4740. }
  4741. return err;
  4742. }
  4743. adap->num_vfs = num_vfs;
  4744. return num_vfs;
  4745. }
  4746. #endif /* CONFIG_PCI_IOV */
  4747. static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4748. {
  4749. struct net_device *netdev;
  4750. struct adapter *adapter;
  4751. static int adap_idx = 1;
  4752. int s_qpp, qpp, num_seg;
  4753. struct port_info *pi;
  4754. bool highdma = false;
  4755. enum chip_type chip;
  4756. void __iomem *regs;
  4757. int func, chip_ver;
  4758. u16 device_id;
  4759. int i, err;
  4760. u32 whoami;
  4761. printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  4762. err = pci_request_regions(pdev, KBUILD_MODNAME);
  4763. if (err) {
  4764. /* Just info, some other driver may have claimed the device. */
  4765. dev_info(&pdev->dev, "cannot obtain PCI resources\n");
  4766. return err;
  4767. }
  4768. err = pci_enable_device(pdev);
  4769. if (err) {
  4770. dev_err(&pdev->dev, "cannot enable PCI device\n");
  4771. goto out_release_regions;
  4772. }
  4773. regs = pci_ioremap_bar(pdev, 0);
  4774. if (!regs) {
  4775. dev_err(&pdev->dev, "cannot map device registers\n");
  4776. err = -ENOMEM;
  4777. goto out_disable_device;
  4778. }
  4779. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  4780. if (!adapter) {
  4781. err = -ENOMEM;
  4782. goto out_unmap_bar0;
  4783. }
  4784. adapter->regs = regs;
  4785. err = t4_wait_dev_ready(regs);
  4786. if (err < 0)
  4787. goto out_free_adapter;
  4788. /* We control everything through one PF */
  4789. whoami = t4_read_reg(adapter, PL_WHOAMI_A);
  4790. pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
  4791. chip = t4_get_chip_type(adapter, CHELSIO_PCI_ID_VER(device_id));
  4792. if ((int)chip < 0) {
  4793. dev_err(&pdev->dev, "Device %d is not supported\n", device_id);
  4794. err = chip;
  4795. goto out_free_adapter;
  4796. }
  4797. chip_ver = CHELSIO_CHIP_VERSION(chip);
  4798. func = chip_ver <= CHELSIO_T5 ?
  4799. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4800. adapter->pdev = pdev;
  4801. adapter->pdev_dev = &pdev->dev;
  4802. adapter->name = pci_name(pdev);
  4803. adapter->mbox = func;
  4804. adapter->pf = func;
  4805. adapter->params.chip = chip;
  4806. adapter->adap_idx = adap_idx;
  4807. adapter->msg_enable = DFLT_MSG_ENABLE;
  4808. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  4809. (sizeof(struct mbox_cmd) *
  4810. T4_OS_LOG_MBOX_CMDS),
  4811. GFP_KERNEL);
  4812. if (!adapter->mbox_log) {
  4813. err = -ENOMEM;
  4814. goto out_free_adapter;
  4815. }
  4816. spin_lock_init(&adapter->mbox_lock);
  4817. INIT_LIST_HEAD(&adapter->mlist.list);
  4818. adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
  4819. pci_set_drvdata(pdev, adapter);
  4820. if (func != ent->driver_data) {
  4821. pci_disable_device(pdev);
  4822. pci_save_state(pdev); /* to restore SR-IOV later */
  4823. return 0;
  4824. }
  4825. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  4826. highdma = true;
  4827. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4828. if (err) {
  4829. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
  4830. "coherent allocations\n");
  4831. goto out_free_adapter;
  4832. }
  4833. } else {
  4834. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4835. if (err) {
  4836. dev_err(&pdev->dev, "no usable DMA configuration\n");
  4837. goto out_free_adapter;
  4838. }
  4839. }
  4840. pci_enable_pcie_error_reporting(pdev);
  4841. pci_set_master(pdev);
  4842. pci_save_state(pdev);
  4843. adap_idx++;
  4844. adapter->workq = create_singlethread_workqueue("cxgb4");
  4845. if (!adapter->workq) {
  4846. err = -ENOMEM;
  4847. goto out_free_adapter;
  4848. }
  4849. /* PCI device has been enabled */
  4850. adapter->flags |= DEV_ENABLED;
  4851. memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
  4852. /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
  4853. * Ingress Packet Data to Free List Buffers in order to allow for
  4854. * chipset performance optimizations between the Root Complex and
  4855. * Memory Controllers. (Messages to the associated Ingress Queue
  4856. * notifying new Packet Placement in the Free Lists Buffers will be
  4857. * send without the Relaxed Ordering Attribute thus guaranteeing that
  4858. * all preceding PCIe Transaction Layer Packets will be processed
  4859. * first.) But some Root Complexes have various issues with Upstream
  4860. * Transaction Layer Packets with the Relaxed Ordering Attribute set.
  4861. * The PCIe devices which under the Root Complexes will be cleared the
  4862. * Relaxed Ordering bit in the configuration space, So we check our
  4863. * PCIe configuration space to see if it's flagged with advice against
  4864. * using Relaxed Ordering.
  4865. */
  4866. if (!pcie_relaxed_ordering_enabled(pdev))
  4867. adapter->flags |= ROOT_NO_RELAXED_ORDERING;
  4868. spin_lock_init(&adapter->stats_lock);
  4869. spin_lock_init(&adapter->tid_release_lock);
  4870. spin_lock_init(&adapter->win0_lock);
  4871. INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
  4872. INIT_WORK(&adapter->db_full_task, process_db_full);
  4873. INIT_WORK(&adapter->db_drop_task, process_db_drop);
  4874. INIT_WORK(&adapter->fatal_err_notify_task, notify_fatal_err);
  4875. err = t4_prep_adapter(adapter);
  4876. if (err)
  4877. goto out_free_adapter;
  4878. if (is_kdump_kernel()) {
  4879. /* Collect hardware state and append to /proc/vmcore */
  4880. err = cxgb4_cudbg_vmcore_add_dump(adapter);
  4881. if (err) {
  4882. dev_warn(adapter->pdev_dev,
  4883. "Fail collecting vmcore device dump, err: %d. Continuing\n",
  4884. err);
  4885. err = 0;
  4886. }
  4887. }
  4888. if (!is_t4(adapter->params.chip)) {
  4889. s_qpp = (QUEUESPERPAGEPF0_S +
  4890. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
  4891. adapter->pf);
  4892. qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
  4893. SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
  4894. num_seg = PAGE_SIZE / SEGMENT_SIZE;
  4895. /* Each segment size is 128B. Write coalescing is enabled only
  4896. * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
  4897. * queue is less no of segments that can be accommodated in
  4898. * a page size.
  4899. */
  4900. if (qpp > num_seg) {
  4901. dev_err(&pdev->dev,
  4902. "Incorrect number of egress queues per page\n");
  4903. err = -EINVAL;
  4904. goto out_free_adapter;
  4905. }
  4906. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  4907. pci_resource_len(pdev, 2));
  4908. if (!adapter->bar2) {
  4909. dev_err(&pdev->dev, "cannot map device bar2 region\n");
  4910. err = -ENOMEM;
  4911. goto out_free_adapter;
  4912. }
  4913. }
  4914. setup_memwin(adapter);
  4915. err = adap_init0(adapter);
  4916. #ifdef CONFIG_DEBUG_FS
  4917. bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
  4918. #endif
  4919. setup_memwin_rdma(adapter);
  4920. if (err)
  4921. goto out_unmap_bar;
  4922. /* configure SGE_STAT_CFG_A to read WC stats */
  4923. if (!is_t4(adapter->params.chip))
  4924. t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
  4925. (is_t5(adapter->params.chip) ? STATMODE_V(0) :
  4926. T6_STATMODE_V(0)));
  4927. /* Initialize hash mac addr list */
  4928. INIT_LIST_HEAD(&adapter->mac_hlist);
  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. struct hash_mac_addr *entry, *tmp;
  5165. if (!adapter) {
  5166. pci_release_regions(pdev);
  5167. return;
  5168. }
  5169. adapter->flags |= SHUTTING_DOWN;
  5170. if (adapter->pf == 4) {
  5171. int i;
  5172. /* Tear down per-adapter Work Queue first since it can contain
  5173. * references to our adapter data structure.
  5174. */
  5175. destroy_workqueue(adapter->workq);
  5176. if (is_uld(adapter)) {
  5177. detach_ulds(adapter);
  5178. t4_uld_clean_up(adapter);
  5179. }
  5180. adap_free_hma_mem(adapter);
  5181. disable_interrupts(adapter);
  5182. for_each_port(adapter, i)
  5183. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5184. unregister_netdev(adapter->port[i]);
  5185. debugfs_remove_recursive(adapter->debugfs_root);
  5186. if (!is_t4(adapter->params.chip))
  5187. cxgb4_ptp_stop(adapter);
  5188. /* If we allocated filters, free up state associated with any
  5189. * valid filters ...
  5190. */
  5191. clear_all_filters(adapter);
  5192. if (adapter->flags & FULL_INIT_DONE)
  5193. cxgb_down(adapter);
  5194. if (adapter->flags & USING_MSIX)
  5195. free_msix_info(adapter);
  5196. if (adapter->num_uld || adapter->num_ofld_uld)
  5197. t4_uld_mem_free(adapter);
  5198. free_some_resources(adapter);
  5199. list_for_each_entry_safe(entry, tmp, &adapter->mac_hlist,
  5200. list) {
  5201. list_del(&entry->list);
  5202. kfree(entry);
  5203. }
  5204. #if IS_ENABLED(CONFIG_IPV6)
  5205. t4_cleanup_clip_tbl(adapter);
  5206. #endif
  5207. if (!is_t4(adapter->params.chip))
  5208. iounmap(adapter->bar2);
  5209. }
  5210. #ifdef CONFIG_PCI_IOV
  5211. else {
  5212. cxgb4_iov_configure(adapter->pdev, 0);
  5213. }
  5214. #endif
  5215. iounmap(adapter->regs);
  5216. pci_disable_pcie_error_reporting(pdev);
  5217. if ((adapter->flags & DEV_ENABLED)) {
  5218. pci_disable_device(pdev);
  5219. adapter->flags &= ~DEV_ENABLED;
  5220. }
  5221. pci_release_regions(pdev);
  5222. kfree(adapter->mbox_log);
  5223. synchronize_rcu();
  5224. kfree(adapter);
  5225. }
  5226. /* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
  5227. * delivery. This is essentially a stripped down version of the PCI remove()
  5228. * function where we do the minimal amount of work necessary to shutdown any
  5229. * further activity.
  5230. */
  5231. static void shutdown_one(struct pci_dev *pdev)
  5232. {
  5233. struct adapter *adapter = pci_get_drvdata(pdev);
  5234. /* As with remove_one() above (see extended comment), we only want do
  5235. * do cleanup on PCI Devices which went all the way through init_one()
  5236. * ...
  5237. */
  5238. if (!adapter) {
  5239. pci_release_regions(pdev);
  5240. return;
  5241. }
  5242. adapter->flags |= SHUTTING_DOWN;
  5243. if (adapter->pf == 4) {
  5244. int i;
  5245. for_each_port(adapter, i)
  5246. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5247. cxgb_close(adapter->port[i]);
  5248. if (is_uld(adapter)) {
  5249. detach_ulds(adapter);
  5250. t4_uld_clean_up(adapter);
  5251. }
  5252. disable_interrupts(adapter);
  5253. disable_msi(adapter);
  5254. t4_sge_stop(adapter);
  5255. if (adapter->flags & FW_OK)
  5256. t4_fw_bye(adapter, adapter->mbox);
  5257. }
  5258. }
  5259. static struct pci_driver cxgb4_driver = {
  5260. .name = KBUILD_MODNAME,
  5261. .id_table = cxgb4_pci_tbl,
  5262. .probe = init_one,
  5263. .remove = remove_one,
  5264. .shutdown = shutdown_one,
  5265. #ifdef CONFIG_PCI_IOV
  5266. .sriov_configure = cxgb4_iov_configure,
  5267. #endif
  5268. .err_handler = &cxgb4_eeh,
  5269. };
  5270. static int __init cxgb4_init_module(void)
  5271. {
  5272. int ret;
  5273. /* Debugfs support is optional, just warn if this fails */
  5274. cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  5275. if (!cxgb4_debugfs_root)
  5276. pr_warn("could not create debugfs entry, continuing\n");
  5277. ret = pci_register_driver(&cxgb4_driver);
  5278. if (ret < 0)
  5279. goto err_pci;
  5280. #if IS_ENABLED(CONFIG_IPV6)
  5281. if (!inet6addr_registered) {
  5282. ret = register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5283. if (ret)
  5284. pci_unregister_driver(&cxgb4_driver);
  5285. else
  5286. inet6addr_registered = true;
  5287. }
  5288. #endif
  5289. if (ret == 0)
  5290. return ret;
  5291. err_pci:
  5292. debugfs_remove(cxgb4_debugfs_root);
  5293. return ret;
  5294. }
  5295. static void __exit cxgb4_cleanup_module(void)
  5296. {
  5297. #if IS_ENABLED(CONFIG_IPV6)
  5298. if (inet6addr_registered) {
  5299. unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5300. inet6addr_registered = false;
  5301. }
  5302. #endif
  5303. pci_unregister_driver(&cxgb4_driver);
  5304. debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
  5305. }
  5306. module_init(cxgb4_init_module);
  5307. module_exit(cxgb4_cleanup_module);