cxgb4_main.c 162 KB

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