bnxt.c 364 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107
  1. /* Broadcom NetXtreme-C/E network driver.
  2. *
  3. * Copyright (c) 2014-2016 Broadcom Corporation
  4. * Copyright (c) 2016-2019 Broadcom Limited
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/stringify.h>
  12. #include <linux/kernel.h>
  13. #include <linux/timer.h>
  14. #include <linux/errno.h>
  15. #include <linux/ioport.h>
  16. #include <linux/slab.h>
  17. #include <linux/vmalloc.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/pci.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/bitops.h>
  25. #include <linux/io.h>
  26. #include <linux/irq.h>
  27. #include <linux/delay.h>
  28. #include <asm/byteorder.h>
  29. #include <asm/page.h>
  30. #include <linux/time.h>
  31. #include <linux/mii.h>
  32. #include <linux/mdio.h>
  33. #include <linux/if.h>
  34. #include <linux/if_vlan.h>
  35. #include <linux/if_bridge.h>
  36. #include <linux/rtc.h>
  37. #include <linux/bpf.h>
  38. #include <net/gro.h>
  39. #include <net/ip.h>
  40. #include <net/tcp.h>
  41. #include <net/udp.h>
  42. #include <net/checksum.h>
  43. #include <net/ip6_checksum.h>
  44. #include <net/udp_tunnel.h>
  45. #include <linux/workqueue.h>
  46. #include <linux/prefetch.h>
  47. #include <linux/cache.h>
  48. #include <linux/log2.h>
  49. #include <linux/aer.h>
  50. #include <linux/bitmap.h>
  51. #include <linux/cpu_rmap.h>
  52. #include <linux/cpumask.h>
  53. #include <net/pkt_cls.h>
  54. #include <linux/hwmon.h>
  55. #include <linux/hwmon-sysfs.h>
  56. #include <net/page_pool.h>
  57. #include <linux/align.h>
  58. #include "bnxt_hsi.h"
  59. #include "bnxt.h"
  60. #include "bnxt_hwrm.h"
  61. #include "bnxt_ulp.h"
  62. #include "bnxt_sriov.h"
  63. #include "bnxt_ethtool.h"
  64. #include "bnxt_dcb.h"
  65. #include "bnxt_xdp.h"
  66. #include "bnxt_ptp.h"
  67. #include "bnxt_vfr.h"
  68. #include "bnxt_tc.h"
  69. #include "bnxt_devlink.h"
  70. #include "bnxt_debugfs.h"
  71. #define BNXT_TX_TIMEOUT (5 * HZ)
  72. #define BNXT_DEF_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_HW | \
  73. NETIF_MSG_TX_ERR)
  74. MODULE_LICENSE("GPL");
  75. MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
  76. #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
  77. #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
  78. #define BNXT_RX_COPY_THRESH 256
  79. #define BNXT_TX_PUSH_THRESH 164
  80. /* indexed by enum board_idx */
  81. static const struct {
  82. char *name;
  83. } board_info[] = {
  84. [BCM57301] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
  85. [BCM57302] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
  86. [BCM57304] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
  87. [BCM57417_NPAR] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
  88. [BCM58700] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
  89. [BCM57311] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
  90. [BCM57312] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
  91. [BCM57402] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
  92. [BCM57404] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
  93. [BCM57406] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
  94. [BCM57402_NPAR] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
  95. [BCM57407] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
  96. [BCM57412] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
  97. [BCM57414] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
  98. [BCM57416] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
  99. [BCM57417] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
  100. [BCM57412_NPAR] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
  101. [BCM57314] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
  102. [BCM57417_SFP] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
  103. [BCM57416_SFP] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
  104. [BCM57404_NPAR] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
  105. [BCM57406_NPAR] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
  106. [BCM57407_SFP] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
  107. [BCM57407_NPAR] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
  108. [BCM57414_NPAR] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
  109. [BCM57416_NPAR] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
  110. [BCM57452] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
  111. [BCM57454] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
  112. [BCM5745x_NPAR] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" },
  113. [BCM57508] = { "Broadcom BCM57508 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
  114. [BCM57504] = { "Broadcom BCM57504 NetXtreme-E 10Gb/25Gb/50Gb/100Gb/200Gb Ethernet" },
  115. [BCM57502] = { "Broadcom BCM57502 NetXtreme-E 10Gb/25Gb/50Gb Ethernet" },
  116. [BCM57508_NPAR] = { "Broadcom BCM57508 NetXtreme-E Ethernet Partition" },
  117. [BCM57504_NPAR] = { "Broadcom BCM57504 NetXtreme-E Ethernet Partition" },
  118. [BCM57502_NPAR] = { "Broadcom BCM57502 NetXtreme-E Ethernet Partition" },
  119. [BCM58802] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" },
  120. [BCM58804] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
  121. [BCM58808] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
  122. [NETXTREME_E_VF] = { "Broadcom NetXtreme-E Ethernet Virtual Function" },
  123. [NETXTREME_C_VF] = { "Broadcom NetXtreme-C Ethernet Virtual Function" },
  124. [NETXTREME_S_VF] = { "Broadcom NetXtreme-S Ethernet Virtual Function" },
  125. [NETXTREME_C_VF_HV] = { "Broadcom NetXtreme-C Virtual Function for Hyper-V" },
  126. [NETXTREME_E_VF_HV] = { "Broadcom NetXtreme-E Virtual Function for Hyper-V" },
  127. [NETXTREME_E_P5_VF] = { "Broadcom BCM5750X NetXtreme-E Ethernet Virtual Function" },
  128. [NETXTREME_E_P5_VF_HV] = { "Broadcom BCM5750X NetXtreme-E Virtual Function for Hyper-V" },
  129. };
  130. static const struct pci_device_id bnxt_pci_tbl[] = {
  131. { PCI_VDEVICE(BROADCOM, 0x1604), .driver_data = BCM5745x_NPAR },
  132. { PCI_VDEVICE(BROADCOM, 0x1605), .driver_data = BCM5745x_NPAR },
  133. { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 },
  134. { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR },
  135. { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 },
  136. { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 },
  137. { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 },
  138. { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR },
  139. { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 },
  140. { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 },
  141. { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 },
  142. { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 },
  143. { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 },
  144. { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 },
  145. { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR },
  146. { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 },
  147. { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 },
  148. { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 },
  149. { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 },
  150. { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 },
  151. { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR },
  152. { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 },
  153. { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP },
  154. { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP },
  155. { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR },
  156. { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR },
  157. { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP },
  158. { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR },
  159. { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR },
  160. { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR },
  161. { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR },
  162. { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR },
  163. { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR },
  164. { PCI_VDEVICE(BROADCOM, 0x16f0), .driver_data = BCM58808 },
  165. { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 },
  166. { PCI_VDEVICE(BROADCOM, 0x1750), .driver_data = BCM57508 },
  167. { PCI_VDEVICE(BROADCOM, 0x1751), .driver_data = BCM57504 },
  168. { PCI_VDEVICE(BROADCOM, 0x1752), .driver_data = BCM57502 },
  169. { PCI_VDEVICE(BROADCOM, 0x1800), .driver_data = BCM57502_NPAR },
  170. { PCI_VDEVICE(BROADCOM, 0x1801), .driver_data = BCM57504_NPAR },
  171. { PCI_VDEVICE(BROADCOM, 0x1802), .driver_data = BCM57508_NPAR },
  172. { PCI_VDEVICE(BROADCOM, 0x1803), .driver_data = BCM57502_NPAR },
  173. { PCI_VDEVICE(BROADCOM, 0x1804), .driver_data = BCM57504_NPAR },
  174. { PCI_VDEVICE(BROADCOM, 0x1805), .driver_data = BCM57508_NPAR },
  175. { PCI_VDEVICE(BROADCOM, 0xd802), .driver_data = BCM58802 },
  176. { PCI_VDEVICE(BROADCOM, 0xd804), .driver_data = BCM58804 },
  177. #ifdef CONFIG_BNXT_SRIOV
  178. { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF },
  179. { PCI_VDEVICE(BROADCOM, 0x1607), .driver_data = NETXTREME_E_VF_HV },
  180. { PCI_VDEVICE(BROADCOM, 0x1608), .driver_data = NETXTREME_E_VF_HV },
  181. { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF },
  182. { PCI_VDEVICE(BROADCOM, 0x16bd), .driver_data = NETXTREME_E_VF_HV },
  183. { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
  184. { PCI_VDEVICE(BROADCOM, 0x16c2), .driver_data = NETXTREME_C_VF_HV },
  185. { PCI_VDEVICE(BROADCOM, 0x16c3), .driver_data = NETXTREME_C_VF_HV },
  186. { PCI_VDEVICE(BROADCOM, 0x16c4), .driver_data = NETXTREME_E_VF_HV },
  187. { PCI_VDEVICE(BROADCOM, 0x16c5), .driver_data = NETXTREME_E_VF_HV },
  188. { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
  189. { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
  190. { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
  191. { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
  192. { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
  193. { PCI_VDEVICE(BROADCOM, 0x16e6), .driver_data = NETXTREME_C_VF_HV },
  194. { PCI_VDEVICE(BROADCOM, 0x1806), .driver_data = NETXTREME_E_P5_VF },
  195. { PCI_VDEVICE(BROADCOM, 0x1807), .driver_data = NETXTREME_E_P5_VF },
  196. { PCI_VDEVICE(BROADCOM, 0x1808), .driver_data = NETXTREME_E_P5_VF_HV },
  197. { PCI_VDEVICE(BROADCOM, 0x1809), .driver_data = NETXTREME_E_P5_VF_HV },
  198. { PCI_VDEVICE(BROADCOM, 0xd800), .driver_data = NETXTREME_S_VF },
  199. #endif
  200. { 0 }
  201. };
  202. MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
  203. static const u16 bnxt_vf_req_snif[] = {
  204. HWRM_FUNC_CFG,
  205. HWRM_FUNC_VF_CFG,
  206. HWRM_PORT_PHY_QCFG,
  207. HWRM_CFA_L2_FILTER_ALLOC,
  208. };
  209. static const u16 bnxt_async_events_arr[] = {
  210. ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
  211. ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE,
  212. ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
  213. ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
  214. ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
  215. ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
  216. ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE,
  217. ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY,
  218. ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY,
  219. ASYNC_EVENT_CMPL_EVENT_ID_DEBUG_NOTIFICATION,
  220. ASYNC_EVENT_CMPL_EVENT_ID_DEFERRED_RESPONSE,
  221. ASYNC_EVENT_CMPL_EVENT_ID_RING_MONITOR_MSG,
  222. ASYNC_EVENT_CMPL_EVENT_ID_ECHO_REQUEST,
  223. ASYNC_EVENT_CMPL_EVENT_ID_PPS_TIMESTAMP,
  224. ASYNC_EVENT_CMPL_EVENT_ID_ERROR_REPORT,
  225. ASYNC_EVENT_CMPL_EVENT_ID_PHC_UPDATE,
  226. };
  227. static struct workqueue_struct *bnxt_pf_wq;
  228. static bool bnxt_vf_pciid(enum board_idx idx)
  229. {
  230. return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF ||
  231. idx == NETXTREME_S_VF || idx == NETXTREME_C_VF_HV ||
  232. idx == NETXTREME_E_VF_HV || idx == NETXTREME_E_P5_VF ||
  233. idx == NETXTREME_E_P5_VF_HV);
  234. }
  235. #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
  236. #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
  237. #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
  238. #define BNXT_CP_DB_IRQ_DIS(db) \
  239. writel(DB_CP_IRQ_DIS_FLAGS, db)
  240. #define BNXT_DB_CQ(db, idx) \
  241. writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell)
  242. #define BNXT_DB_NQ_P5(db, idx) \
  243. bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), \
  244. (db)->doorbell)
  245. #define BNXT_DB_CQ_ARM(db, idx) \
  246. writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell)
  247. #define BNXT_DB_NQ_ARM_P5(db, idx) \
  248. bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx),\
  249. (db)->doorbell)
  250. static void bnxt_db_nq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
  251. {
  252. if (bp->flags & BNXT_FLAG_CHIP_P5)
  253. BNXT_DB_NQ_P5(db, idx);
  254. else
  255. BNXT_DB_CQ(db, idx);
  256. }
  257. static void bnxt_db_nq_arm(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
  258. {
  259. if (bp->flags & BNXT_FLAG_CHIP_P5)
  260. BNXT_DB_NQ_ARM_P5(db, idx);
  261. else
  262. BNXT_DB_CQ_ARM(db, idx);
  263. }
  264. static void bnxt_db_cq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
  265. {
  266. if (bp->flags & BNXT_FLAG_CHIP_P5)
  267. bnxt_writeq(bp, db->db_key64 | DBR_TYPE_CQ_ARMALL |
  268. RING_CMP(idx), db->doorbell);
  269. else
  270. BNXT_DB_CQ(db, idx);
  271. }
  272. const u16 bnxt_lhint_arr[] = {
  273. TX_BD_FLAGS_LHINT_512_AND_SMALLER,
  274. TX_BD_FLAGS_LHINT_512_TO_1023,
  275. TX_BD_FLAGS_LHINT_1024_TO_2047,
  276. TX_BD_FLAGS_LHINT_1024_TO_2047,
  277. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  278. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  279. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  280. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  281. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  282. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  283. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  284. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  285. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  286. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  287. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  288. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  289. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  290. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  291. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  292. };
  293. static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb)
  294. {
  295. struct metadata_dst *md_dst = skb_metadata_dst(skb);
  296. if (!md_dst || md_dst->type != METADATA_HW_PORT_MUX)
  297. return 0;
  298. return md_dst->u.port_info.port_id;
  299. }
  300. static void bnxt_txr_db_kick(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
  301. u16 prod)
  302. {
  303. bnxt_db_write(bp, &txr->tx_db, prod);
  304. txr->kick_pending = 0;
  305. }
  306. static bool bnxt_txr_netif_try_stop_queue(struct bnxt *bp,
  307. struct bnxt_tx_ring_info *txr,
  308. struct netdev_queue *txq)
  309. {
  310. netif_tx_stop_queue(txq);
  311. /* netif_tx_stop_queue() must be done before checking
  312. * tx index in bnxt_tx_avail() below, because in
  313. * bnxt_tx_int(), we update tx index before checking for
  314. * netif_tx_queue_stopped().
  315. */
  316. smp_mb();
  317. if (bnxt_tx_avail(bp, txr) >= bp->tx_wake_thresh) {
  318. netif_tx_wake_queue(txq);
  319. return false;
  320. }
  321. return true;
  322. }
  323. static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
  324. {
  325. struct bnxt *bp = netdev_priv(dev);
  326. struct tx_bd *txbd;
  327. struct tx_bd_ext *txbd1;
  328. struct netdev_queue *txq;
  329. int i;
  330. dma_addr_t mapping;
  331. unsigned int length, pad = 0;
  332. u32 len, free_size, vlan_tag_flags, cfa_action, flags;
  333. u16 prod, last_frag;
  334. struct pci_dev *pdev = bp->pdev;
  335. struct bnxt_tx_ring_info *txr;
  336. struct bnxt_sw_tx_bd *tx_buf;
  337. __le32 lflags = 0;
  338. i = skb_get_queue_mapping(skb);
  339. if (unlikely(i >= bp->tx_nr_rings)) {
  340. dev_kfree_skb_any(skb);
  341. dev_core_stats_tx_dropped_inc(dev);
  342. return NETDEV_TX_OK;
  343. }
  344. txq = netdev_get_tx_queue(dev, i);
  345. txr = &bp->tx_ring[bp->tx_ring_map[i]];
  346. prod = txr->tx_prod;
  347. free_size = bnxt_tx_avail(bp, txr);
  348. if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
  349. /* We must have raced with NAPI cleanup */
  350. if (net_ratelimit() && txr->kick_pending)
  351. netif_warn(bp, tx_err, dev,
  352. "bnxt: ring busy w/ flush pending!\n");
  353. if (bnxt_txr_netif_try_stop_queue(bp, txr, txq))
  354. return NETDEV_TX_BUSY;
  355. }
  356. length = skb->len;
  357. len = skb_headlen(skb);
  358. last_frag = skb_shinfo(skb)->nr_frags;
  359. txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  360. txbd->tx_bd_opaque = prod;
  361. tx_buf = &txr->tx_buf_ring[prod];
  362. tx_buf->skb = skb;
  363. tx_buf->nr_frags = last_frag;
  364. vlan_tag_flags = 0;
  365. cfa_action = bnxt_xmit_get_cfa_action(skb);
  366. if (skb_vlan_tag_present(skb)) {
  367. vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
  368. skb_vlan_tag_get(skb);
  369. /* Currently supports 8021Q, 8021AD vlan offloads
  370. * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
  371. */
  372. if (skb->vlan_proto == htons(ETH_P_8021Q))
  373. vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
  374. }
  375. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  376. struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
  377. if (ptp && ptp->tx_tstamp_en && !skb_is_gso(skb) &&
  378. atomic_dec_if_positive(&ptp->tx_avail) >= 0) {
  379. if (!bnxt_ptp_parse(skb, &ptp->tx_seqid,
  380. &ptp->tx_hdr_off)) {
  381. if (vlan_tag_flags)
  382. ptp->tx_hdr_off += VLAN_HLEN;
  383. lflags |= cpu_to_le32(TX_BD_FLAGS_STAMP);
  384. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  385. } else {
  386. atomic_inc(&bp->ptp_cfg->tx_avail);
  387. }
  388. }
  389. }
  390. if (unlikely(skb->no_fcs))
  391. lflags |= cpu_to_le32(TX_BD_FLAGS_NO_CRC);
  392. if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh &&
  393. !lflags) {
  394. struct tx_push_buffer *tx_push_buf = txr->tx_push;
  395. struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
  396. struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
  397. void __iomem *db = txr->tx_db.doorbell;
  398. void *pdata = tx_push_buf->data;
  399. u64 *end;
  400. int j, push_len;
  401. /* Set COAL_NOW to be ready quickly for the next push */
  402. tx_push->tx_bd_len_flags_type =
  403. cpu_to_le32((length << TX_BD_LEN_SHIFT) |
  404. TX_BD_TYPE_LONG_TX_BD |
  405. TX_BD_FLAGS_LHINT_512_AND_SMALLER |
  406. TX_BD_FLAGS_COAL_NOW |
  407. TX_BD_FLAGS_PACKET_END |
  408. (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
  409. if (skb->ip_summed == CHECKSUM_PARTIAL)
  410. tx_push1->tx_bd_hsize_lflags =
  411. cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
  412. else
  413. tx_push1->tx_bd_hsize_lflags = 0;
  414. tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
  415. tx_push1->tx_bd_cfa_action =
  416. cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
  417. end = pdata + length;
  418. end = PTR_ALIGN(end, 8) - 1;
  419. *end = 0;
  420. skb_copy_from_linear_data(skb, pdata, len);
  421. pdata += len;
  422. for (j = 0; j < last_frag; j++) {
  423. skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
  424. void *fptr;
  425. fptr = skb_frag_address_safe(frag);
  426. if (!fptr)
  427. goto normal_tx;
  428. memcpy(pdata, fptr, skb_frag_size(frag));
  429. pdata += skb_frag_size(frag);
  430. }
  431. txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
  432. txbd->tx_bd_haddr = txr->data_mapping;
  433. prod = NEXT_TX(prod);
  434. txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  435. memcpy(txbd, tx_push1, sizeof(*txbd));
  436. prod = NEXT_TX(prod);
  437. tx_push->doorbell =
  438. cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
  439. txr->tx_prod = prod;
  440. tx_buf->is_push = 1;
  441. netdev_tx_sent_queue(txq, skb->len);
  442. wmb(); /* Sync is_push and byte queue before pushing data */
  443. push_len = (length + sizeof(*tx_push) + 7) / 8;
  444. if (push_len > 16) {
  445. __iowrite64_copy(db, tx_push_buf, 16);
  446. __iowrite32_copy(db + 4, tx_push_buf + 1,
  447. (push_len - 16) << 1);
  448. } else {
  449. __iowrite64_copy(db, tx_push_buf, push_len);
  450. }
  451. goto tx_done;
  452. }
  453. normal_tx:
  454. if (length < BNXT_MIN_PKT_SIZE) {
  455. pad = BNXT_MIN_PKT_SIZE - length;
  456. if (skb_pad(skb, pad))
  457. /* SKB already freed. */
  458. goto tx_kick_pending;
  459. length = BNXT_MIN_PKT_SIZE;
  460. }
  461. mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
  462. if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
  463. goto tx_free;
  464. dma_unmap_addr_set(tx_buf, mapping, mapping);
  465. flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
  466. ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
  467. txbd->tx_bd_haddr = cpu_to_le64(mapping);
  468. prod = NEXT_TX(prod);
  469. txbd1 = (struct tx_bd_ext *)
  470. &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  471. txbd1->tx_bd_hsize_lflags = lflags;
  472. if (skb_is_gso(skb)) {
  473. u32 hdr_len;
  474. if (skb->encapsulation)
  475. hdr_len = skb_inner_tcp_all_headers(skb);
  476. else
  477. hdr_len = skb_tcp_all_headers(skb);
  478. txbd1->tx_bd_hsize_lflags |= cpu_to_le32(TX_BD_FLAGS_LSO |
  479. TX_BD_FLAGS_T_IPID |
  480. (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
  481. length = skb_shinfo(skb)->gso_size;
  482. txbd1->tx_bd_mss = cpu_to_le32(length);
  483. length += hdr_len;
  484. } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
  485. txbd1->tx_bd_hsize_lflags |=
  486. cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
  487. txbd1->tx_bd_mss = 0;
  488. }
  489. length >>= 9;
  490. if (unlikely(length >= ARRAY_SIZE(bnxt_lhint_arr))) {
  491. dev_warn_ratelimited(&pdev->dev, "Dropped oversize %d bytes TX packet.\n",
  492. skb->len);
  493. i = 0;
  494. goto tx_dma_error;
  495. }
  496. flags |= bnxt_lhint_arr[length];
  497. txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
  498. txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
  499. txbd1->tx_bd_cfa_action =
  500. cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT);
  501. for (i = 0; i < last_frag; i++) {
  502. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  503. prod = NEXT_TX(prod);
  504. txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  505. len = skb_frag_size(frag);
  506. mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
  507. DMA_TO_DEVICE);
  508. if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
  509. goto tx_dma_error;
  510. tx_buf = &txr->tx_buf_ring[prod];
  511. dma_unmap_addr_set(tx_buf, mapping, mapping);
  512. txbd->tx_bd_haddr = cpu_to_le64(mapping);
  513. flags = len << TX_BD_LEN_SHIFT;
  514. txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
  515. }
  516. flags &= ~TX_BD_LEN;
  517. txbd->tx_bd_len_flags_type =
  518. cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
  519. TX_BD_FLAGS_PACKET_END);
  520. netdev_tx_sent_queue(txq, skb->len);
  521. skb_tx_timestamp(skb);
  522. /* Sync BD data before updating doorbell */
  523. wmb();
  524. prod = NEXT_TX(prod);
  525. txr->tx_prod = prod;
  526. if (!netdev_xmit_more() || netif_xmit_stopped(txq))
  527. bnxt_txr_db_kick(bp, txr, prod);
  528. else
  529. txr->kick_pending = 1;
  530. tx_done:
  531. if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
  532. if (netdev_xmit_more() && !tx_buf->is_push)
  533. bnxt_txr_db_kick(bp, txr, prod);
  534. bnxt_txr_netif_try_stop_queue(bp, txr, txq);
  535. }
  536. return NETDEV_TX_OK;
  537. tx_dma_error:
  538. if (BNXT_TX_PTP_IS_SET(lflags))
  539. atomic_inc(&bp->ptp_cfg->tx_avail);
  540. last_frag = i;
  541. /* start back at beginning and unmap skb */
  542. prod = txr->tx_prod;
  543. tx_buf = &txr->tx_buf_ring[prod];
  544. dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
  545. skb_headlen(skb), DMA_TO_DEVICE);
  546. prod = NEXT_TX(prod);
  547. /* unmap remaining mapped pages */
  548. for (i = 0; i < last_frag; i++) {
  549. prod = NEXT_TX(prod);
  550. tx_buf = &txr->tx_buf_ring[prod];
  551. dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
  552. skb_frag_size(&skb_shinfo(skb)->frags[i]),
  553. DMA_TO_DEVICE);
  554. }
  555. tx_free:
  556. dev_kfree_skb_any(skb);
  557. tx_kick_pending:
  558. if (txr->kick_pending)
  559. bnxt_txr_db_kick(bp, txr, txr->tx_prod);
  560. txr->tx_buf_ring[txr->tx_prod].skb = NULL;
  561. dev_core_stats_tx_dropped_inc(dev);
  562. return NETDEV_TX_OK;
  563. }
  564. static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
  565. {
  566. struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
  567. struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
  568. u16 cons = txr->tx_cons;
  569. struct pci_dev *pdev = bp->pdev;
  570. int i;
  571. unsigned int tx_bytes = 0;
  572. for (i = 0; i < nr_pkts; i++) {
  573. struct bnxt_sw_tx_bd *tx_buf;
  574. struct sk_buff *skb;
  575. int j, last;
  576. tx_buf = &txr->tx_buf_ring[cons];
  577. cons = NEXT_TX(cons);
  578. skb = tx_buf->skb;
  579. tx_buf->skb = NULL;
  580. tx_bytes += skb->len;
  581. if (tx_buf->is_push) {
  582. tx_buf->is_push = 0;
  583. goto next_tx_int;
  584. }
  585. dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
  586. skb_headlen(skb), DMA_TO_DEVICE);
  587. last = tx_buf->nr_frags;
  588. for (j = 0; j < last; j++) {
  589. cons = NEXT_TX(cons);
  590. tx_buf = &txr->tx_buf_ring[cons];
  591. dma_unmap_page(
  592. &pdev->dev,
  593. dma_unmap_addr(tx_buf, mapping),
  594. skb_frag_size(&skb_shinfo(skb)->frags[j]),
  595. DMA_TO_DEVICE);
  596. }
  597. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
  598. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  599. /* PTP worker takes ownership of the skb */
  600. if (!bnxt_get_tx_ts_p5(bp, skb))
  601. skb = NULL;
  602. else
  603. atomic_inc(&bp->ptp_cfg->tx_avail);
  604. }
  605. }
  606. next_tx_int:
  607. cons = NEXT_TX(cons);
  608. dev_kfree_skb_any(skb);
  609. }
  610. netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
  611. txr->tx_cons = cons;
  612. /* Need to make the tx_cons update visible to bnxt_start_xmit()
  613. * before checking for netif_tx_queue_stopped(). Without the
  614. * memory barrier, there is a small possibility that bnxt_start_xmit()
  615. * will miss it and cause the queue to be stopped forever.
  616. */
  617. smp_mb();
  618. if (unlikely(netif_tx_queue_stopped(txq)) &&
  619. bnxt_tx_avail(bp, txr) >= bp->tx_wake_thresh &&
  620. READ_ONCE(txr->dev_state) != BNXT_DEV_STATE_CLOSING)
  621. netif_tx_wake_queue(txq);
  622. }
  623. static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
  624. struct bnxt_rx_ring_info *rxr,
  625. unsigned int *offset,
  626. gfp_t gfp)
  627. {
  628. struct device *dev = &bp->pdev->dev;
  629. struct page *page;
  630. if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
  631. page = page_pool_dev_alloc_frag(rxr->page_pool, offset,
  632. BNXT_RX_PAGE_SIZE);
  633. } else {
  634. page = page_pool_dev_alloc_pages(rxr->page_pool);
  635. *offset = 0;
  636. }
  637. if (!page)
  638. return NULL;
  639. *mapping = dma_map_page_attrs(dev, page, *offset, BNXT_RX_PAGE_SIZE,
  640. bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
  641. if (dma_mapping_error(dev, *mapping)) {
  642. page_pool_recycle_direct(rxr->page_pool, page);
  643. return NULL;
  644. }
  645. return page;
  646. }
  647. static inline u8 *__bnxt_alloc_rx_frag(struct bnxt *bp, dma_addr_t *mapping,
  648. gfp_t gfp)
  649. {
  650. u8 *data;
  651. struct pci_dev *pdev = bp->pdev;
  652. if (gfp == GFP_ATOMIC)
  653. data = napi_alloc_frag(bp->rx_buf_size);
  654. else
  655. data = netdev_alloc_frag(bp->rx_buf_size);
  656. if (!data)
  657. return NULL;
  658. *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset,
  659. bp->rx_buf_use_size, bp->rx_dir,
  660. DMA_ATTR_WEAK_ORDERING);
  661. if (dma_mapping_error(&pdev->dev, *mapping)) {
  662. skb_free_frag(data);
  663. data = NULL;
  664. }
  665. return data;
  666. }
  667. int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
  668. u16 prod, gfp_t gfp)
  669. {
  670. struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  671. struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
  672. dma_addr_t mapping;
  673. if (BNXT_RX_PAGE_MODE(bp)) {
  674. unsigned int offset;
  675. struct page *page =
  676. __bnxt_alloc_rx_page(bp, &mapping, rxr, &offset, gfp);
  677. if (!page)
  678. return -ENOMEM;
  679. mapping += bp->rx_dma_offset;
  680. rx_buf->data = page;
  681. rx_buf->data_ptr = page_address(page) + offset + bp->rx_offset;
  682. } else {
  683. u8 *data = __bnxt_alloc_rx_frag(bp, &mapping, gfp);
  684. if (!data)
  685. return -ENOMEM;
  686. rx_buf->data = data;
  687. rx_buf->data_ptr = data + bp->rx_offset;
  688. }
  689. rx_buf->mapping = mapping;
  690. rxbd->rx_bd_haddr = cpu_to_le64(mapping);
  691. return 0;
  692. }
  693. void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data)
  694. {
  695. u16 prod = rxr->rx_prod;
  696. struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
  697. struct rx_bd *cons_bd, *prod_bd;
  698. prod_rx_buf = &rxr->rx_buf_ring[prod];
  699. cons_rx_buf = &rxr->rx_buf_ring[cons];
  700. prod_rx_buf->data = data;
  701. prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
  702. prod_rx_buf->mapping = cons_rx_buf->mapping;
  703. prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  704. cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  705. prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
  706. }
  707. static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
  708. {
  709. u16 next, max = rxr->rx_agg_bmap_size;
  710. next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
  711. if (next >= max)
  712. next = find_first_zero_bit(rxr->rx_agg_bmap, max);
  713. return next;
  714. }
  715. static inline int bnxt_alloc_rx_page(struct bnxt *bp,
  716. struct bnxt_rx_ring_info *rxr,
  717. u16 prod, gfp_t gfp)
  718. {
  719. struct rx_bd *rxbd =
  720. &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  721. struct bnxt_sw_rx_agg_bd *rx_agg_buf;
  722. struct pci_dev *pdev = bp->pdev;
  723. struct page *page;
  724. dma_addr_t mapping;
  725. u16 sw_prod = rxr->rx_sw_agg_prod;
  726. unsigned int offset = 0;
  727. if (BNXT_RX_PAGE_MODE(bp)) {
  728. page = __bnxt_alloc_rx_page(bp, &mapping, rxr, &offset, gfp);
  729. if (!page)
  730. return -ENOMEM;
  731. } else {
  732. if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
  733. page = rxr->rx_page;
  734. if (!page) {
  735. page = alloc_page(gfp);
  736. if (!page)
  737. return -ENOMEM;
  738. rxr->rx_page = page;
  739. rxr->rx_page_offset = 0;
  740. }
  741. offset = rxr->rx_page_offset;
  742. rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
  743. if (rxr->rx_page_offset == PAGE_SIZE)
  744. rxr->rx_page = NULL;
  745. else
  746. get_page(page);
  747. } else {
  748. page = alloc_page(gfp);
  749. if (!page)
  750. return -ENOMEM;
  751. }
  752. mapping = dma_map_page_attrs(&pdev->dev, page, offset,
  753. BNXT_RX_PAGE_SIZE, DMA_FROM_DEVICE,
  754. DMA_ATTR_WEAK_ORDERING);
  755. if (dma_mapping_error(&pdev->dev, mapping)) {
  756. __free_page(page);
  757. return -EIO;
  758. }
  759. }
  760. if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
  761. sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
  762. __set_bit(sw_prod, rxr->rx_agg_bmap);
  763. rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
  764. rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
  765. rx_agg_buf->page = page;
  766. rx_agg_buf->offset = offset;
  767. rx_agg_buf->mapping = mapping;
  768. rxbd->rx_bd_haddr = cpu_to_le64(mapping);
  769. rxbd->rx_bd_opaque = sw_prod;
  770. return 0;
  771. }
  772. static struct rx_agg_cmp *bnxt_get_agg(struct bnxt *bp,
  773. struct bnxt_cp_ring_info *cpr,
  774. u16 cp_cons, u16 curr)
  775. {
  776. struct rx_agg_cmp *agg;
  777. cp_cons = RING_CMP(ADV_RAW_CMP(cp_cons, curr));
  778. agg = (struct rx_agg_cmp *)
  779. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  780. return agg;
  781. }
  782. static struct rx_agg_cmp *bnxt_get_tpa_agg_p5(struct bnxt *bp,
  783. struct bnxt_rx_ring_info *rxr,
  784. u16 agg_id, u16 curr)
  785. {
  786. struct bnxt_tpa_info *tpa_info = &rxr->rx_tpa[agg_id];
  787. return &tpa_info->agg_arr[curr];
  788. }
  789. static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
  790. u16 start, u32 agg_bufs, bool tpa)
  791. {
  792. struct bnxt_napi *bnapi = cpr->bnapi;
  793. struct bnxt *bp = bnapi->bp;
  794. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  795. u16 prod = rxr->rx_agg_prod;
  796. u16 sw_prod = rxr->rx_sw_agg_prod;
  797. bool p5_tpa = false;
  798. u32 i;
  799. if ((bp->flags & BNXT_FLAG_CHIP_P5) && tpa)
  800. p5_tpa = true;
  801. for (i = 0; i < agg_bufs; i++) {
  802. u16 cons;
  803. struct rx_agg_cmp *agg;
  804. struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
  805. struct rx_bd *prod_bd;
  806. struct page *page;
  807. if (p5_tpa)
  808. agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, start + i);
  809. else
  810. agg = bnxt_get_agg(bp, cpr, idx, start + i);
  811. cons = agg->rx_agg_cmp_opaque;
  812. __clear_bit(cons, rxr->rx_agg_bmap);
  813. if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
  814. sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
  815. __set_bit(sw_prod, rxr->rx_agg_bmap);
  816. prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
  817. cons_rx_buf = &rxr->rx_agg_ring[cons];
  818. /* It is possible for sw_prod to be equal to cons, so
  819. * set cons_rx_buf->page to NULL first.
  820. */
  821. page = cons_rx_buf->page;
  822. cons_rx_buf->page = NULL;
  823. prod_rx_buf->page = page;
  824. prod_rx_buf->offset = cons_rx_buf->offset;
  825. prod_rx_buf->mapping = cons_rx_buf->mapping;
  826. prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  827. prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
  828. prod_bd->rx_bd_opaque = sw_prod;
  829. prod = NEXT_RX_AGG(prod);
  830. sw_prod = NEXT_RX_AGG(sw_prod);
  831. }
  832. rxr->rx_agg_prod = prod;
  833. rxr->rx_sw_agg_prod = sw_prod;
  834. }
  835. static struct sk_buff *bnxt_rx_multi_page_skb(struct bnxt *bp,
  836. struct bnxt_rx_ring_info *rxr,
  837. u16 cons, void *data, u8 *data_ptr,
  838. dma_addr_t dma_addr,
  839. unsigned int offset_and_len)
  840. {
  841. unsigned int len = offset_and_len & 0xffff;
  842. struct page *page = data;
  843. u16 prod = rxr->rx_prod;
  844. struct sk_buff *skb;
  845. int err;
  846. err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
  847. if (unlikely(err)) {
  848. bnxt_reuse_rx_data(rxr, cons, data);
  849. return NULL;
  850. }
  851. dma_addr -= bp->rx_dma_offset;
  852. dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, BNXT_RX_PAGE_SIZE,
  853. bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
  854. skb = build_skb(data_ptr - bp->rx_offset, BNXT_RX_PAGE_SIZE);
  855. if (!skb) {
  856. page_pool_recycle_direct(rxr->page_pool, page);
  857. return NULL;
  858. }
  859. skb_mark_for_recycle(skb);
  860. skb_reserve(skb, bp->rx_offset);
  861. __skb_put(skb, len);
  862. return skb;
  863. }
  864. static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
  865. struct bnxt_rx_ring_info *rxr,
  866. u16 cons, void *data, u8 *data_ptr,
  867. dma_addr_t dma_addr,
  868. unsigned int offset_and_len)
  869. {
  870. unsigned int payload = offset_and_len >> 16;
  871. unsigned int len = offset_and_len & 0xffff;
  872. skb_frag_t *frag;
  873. struct page *page = data;
  874. u16 prod = rxr->rx_prod;
  875. struct sk_buff *skb;
  876. int off, err;
  877. err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
  878. if (unlikely(err)) {
  879. bnxt_reuse_rx_data(rxr, cons, data);
  880. return NULL;
  881. }
  882. dma_addr -= bp->rx_dma_offset;
  883. dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, BNXT_RX_PAGE_SIZE,
  884. bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
  885. if (unlikely(!payload))
  886. payload = eth_get_headlen(bp->dev, data_ptr, len);
  887. skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
  888. if (!skb) {
  889. page_pool_recycle_direct(rxr->page_pool, page);
  890. return NULL;
  891. }
  892. skb_mark_for_recycle(skb);
  893. off = (void *)data_ptr - page_address(page);
  894. skb_add_rx_frag(skb, 0, page, off, len, BNXT_RX_PAGE_SIZE);
  895. memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
  896. payload + NET_IP_ALIGN);
  897. frag = &skb_shinfo(skb)->frags[0];
  898. skb_frag_size_sub(frag, payload);
  899. skb_frag_off_add(frag, payload);
  900. skb->data_len -= payload;
  901. skb->tail += payload;
  902. return skb;
  903. }
  904. static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
  905. struct bnxt_rx_ring_info *rxr, u16 cons,
  906. void *data, u8 *data_ptr,
  907. dma_addr_t dma_addr,
  908. unsigned int offset_and_len)
  909. {
  910. u16 prod = rxr->rx_prod;
  911. struct sk_buff *skb;
  912. int err;
  913. err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
  914. if (unlikely(err)) {
  915. bnxt_reuse_rx_data(rxr, cons, data);
  916. return NULL;
  917. }
  918. skb = build_skb(data, bp->rx_buf_size);
  919. dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
  920. bp->rx_dir, DMA_ATTR_WEAK_ORDERING);
  921. if (!skb) {
  922. skb_free_frag(data);
  923. return NULL;
  924. }
  925. skb_reserve(skb, bp->rx_offset);
  926. skb_put(skb, offset_and_len & 0xffff);
  927. return skb;
  928. }
  929. static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
  930. struct bnxt_cp_ring_info *cpr,
  931. struct skb_shared_info *shinfo,
  932. u16 idx, u32 agg_bufs, bool tpa,
  933. struct xdp_buff *xdp)
  934. {
  935. struct bnxt_napi *bnapi = cpr->bnapi;
  936. struct pci_dev *pdev = bp->pdev;
  937. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  938. u16 prod = rxr->rx_agg_prod;
  939. u32 i, total_frag_len = 0;
  940. bool p5_tpa = false;
  941. if ((bp->flags & BNXT_FLAG_CHIP_P5) && tpa)
  942. p5_tpa = true;
  943. for (i = 0; i < agg_bufs; i++) {
  944. skb_frag_t *frag = &shinfo->frags[i];
  945. u16 cons, frag_len;
  946. struct rx_agg_cmp *agg;
  947. struct bnxt_sw_rx_agg_bd *cons_rx_buf;
  948. struct page *page;
  949. dma_addr_t mapping;
  950. if (p5_tpa)
  951. agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
  952. else
  953. agg = bnxt_get_agg(bp, cpr, idx, i);
  954. cons = agg->rx_agg_cmp_opaque;
  955. frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
  956. RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
  957. cons_rx_buf = &rxr->rx_agg_ring[cons];
  958. skb_frag_off_set(frag, cons_rx_buf->offset);
  959. skb_frag_size_set(frag, frag_len);
  960. __skb_frag_set_page(frag, cons_rx_buf->page);
  961. shinfo->nr_frags = i + 1;
  962. __clear_bit(cons, rxr->rx_agg_bmap);
  963. /* It is possible for bnxt_alloc_rx_page() to allocate
  964. * a sw_prod index that equals the cons index, so we
  965. * need to clear the cons entry now.
  966. */
  967. mapping = cons_rx_buf->mapping;
  968. page = cons_rx_buf->page;
  969. cons_rx_buf->page = NULL;
  970. if (xdp && page_is_pfmemalloc(page))
  971. xdp_buff_set_frag_pfmemalloc(xdp);
  972. if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
  973. unsigned int nr_frags;
  974. nr_frags = --shinfo->nr_frags;
  975. __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
  976. cons_rx_buf->page = page;
  977. /* Update prod since possibly some pages have been
  978. * allocated already.
  979. */
  980. rxr->rx_agg_prod = prod;
  981. bnxt_reuse_rx_agg_bufs(cpr, idx, i, agg_bufs - i, tpa);
  982. return 0;
  983. }
  984. dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
  985. bp->rx_dir,
  986. DMA_ATTR_WEAK_ORDERING);
  987. total_frag_len += frag_len;
  988. prod = NEXT_RX_AGG(prod);
  989. }
  990. rxr->rx_agg_prod = prod;
  991. return total_frag_len;
  992. }
  993. static struct sk_buff *bnxt_rx_agg_pages_skb(struct bnxt *bp,
  994. struct bnxt_cp_ring_info *cpr,
  995. struct sk_buff *skb, u16 idx,
  996. u32 agg_bufs, bool tpa)
  997. {
  998. struct skb_shared_info *shinfo = skb_shinfo(skb);
  999. u32 total_frag_len = 0;
  1000. total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo, idx,
  1001. agg_bufs, tpa, NULL);
  1002. if (!total_frag_len) {
  1003. dev_kfree_skb(skb);
  1004. return NULL;
  1005. }
  1006. skb->data_len += total_frag_len;
  1007. skb->len += total_frag_len;
  1008. skb->truesize += BNXT_RX_PAGE_SIZE * agg_bufs;
  1009. return skb;
  1010. }
  1011. static u32 bnxt_rx_agg_pages_xdp(struct bnxt *bp,
  1012. struct bnxt_cp_ring_info *cpr,
  1013. struct xdp_buff *xdp, u16 idx,
  1014. u32 agg_bufs, bool tpa)
  1015. {
  1016. struct skb_shared_info *shinfo = xdp_get_shared_info_from_buff(xdp);
  1017. u32 total_frag_len = 0;
  1018. if (!xdp_buff_has_frags(xdp))
  1019. shinfo->nr_frags = 0;
  1020. total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo,
  1021. idx, agg_bufs, tpa, xdp);
  1022. if (total_frag_len) {
  1023. xdp_buff_set_frags_flag(xdp);
  1024. shinfo->nr_frags = agg_bufs;
  1025. shinfo->xdp_frags_size = total_frag_len;
  1026. }
  1027. return total_frag_len;
  1028. }
  1029. static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
  1030. u8 agg_bufs, u32 *raw_cons)
  1031. {
  1032. u16 last;
  1033. struct rx_agg_cmp *agg;
  1034. *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
  1035. last = RING_CMP(*raw_cons);
  1036. agg = (struct rx_agg_cmp *)
  1037. &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
  1038. return RX_AGG_CMP_VALID(agg, *raw_cons);
  1039. }
  1040. static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
  1041. unsigned int len,
  1042. dma_addr_t mapping)
  1043. {
  1044. struct bnxt *bp = bnapi->bp;
  1045. struct pci_dev *pdev = bp->pdev;
  1046. struct sk_buff *skb;
  1047. skb = napi_alloc_skb(&bnapi->napi, len);
  1048. if (!skb)
  1049. return NULL;
  1050. dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
  1051. bp->rx_dir);
  1052. memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
  1053. len + NET_IP_ALIGN);
  1054. dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
  1055. bp->rx_dir);
  1056. skb_put(skb, len);
  1057. return skb;
  1058. }
  1059. static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
  1060. u32 *raw_cons, void *cmp)
  1061. {
  1062. struct rx_cmp *rxcmp = cmp;
  1063. u32 tmp_raw_cons = *raw_cons;
  1064. u8 cmp_type, agg_bufs = 0;
  1065. cmp_type = RX_CMP_TYPE(rxcmp);
  1066. if (cmp_type == CMP_TYPE_RX_L2_CMP) {
  1067. agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
  1068. RX_CMP_AGG_BUFS) >>
  1069. RX_CMP_AGG_BUFS_SHIFT;
  1070. } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
  1071. struct rx_tpa_end_cmp *tpa_end = cmp;
  1072. if (bp->flags & BNXT_FLAG_CHIP_P5)
  1073. return 0;
  1074. agg_bufs = TPA_END_AGG_BUFS(tpa_end);
  1075. }
  1076. if (agg_bufs) {
  1077. if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
  1078. return -EBUSY;
  1079. }
  1080. *raw_cons = tmp_raw_cons;
  1081. return 0;
  1082. }
  1083. static void bnxt_queue_fw_reset_work(struct bnxt *bp, unsigned long delay)
  1084. {
  1085. if (!(test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)))
  1086. return;
  1087. if (BNXT_PF(bp))
  1088. queue_delayed_work(bnxt_pf_wq, &bp->fw_reset_task, delay);
  1089. else
  1090. schedule_delayed_work(&bp->fw_reset_task, delay);
  1091. }
  1092. static void bnxt_queue_sp_work(struct bnxt *bp)
  1093. {
  1094. if (BNXT_PF(bp))
  1095. queue_work(bnxt_pf_wq, &bp->sp_task);
  1096. else
  1097. schedule_work(&bp->sp_task);
  1098. }
  1099. static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
  1100. {
  1101. if (!rxr->bnapi->in_reset) {
  1102. rxr->bnapi->in_reset = true;
  1103. if (bp->flags & BNXT_FLAG_CHIP_P5)
  1104. set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
  1105. else
  1106. set_bit(BNXT_RST_RING_SP_EVENT, &bp->sp_event);
  1107. bnxt_queue_sp_work(bp);
  1108. }
  1109. rxr->rx_next_cons = 0xffff;
  1110. }
  1111. static u16 bnxt_alloc_agg_idx(struct bnxt_rx_ring_info *rxr, u16 agg_id)
  1112. {
  1113. struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
  1114. u16 idx = agg_id & MAX_TPA_P5_MASK;
  1115. if (test_bit(idx, map->agg_idx_bmap))
  1116. idx = find_first_zero_bit(map->agg_idx_bmap,
  1117. BNXT_AGG_IDX_BMAP_SIZE);
  1118. __set_bit(idx, map->agg_idx_bmap);
  1119. map->agg_id_tbl[agg_id] = idx;
  1120. return idx;
  1121. }
  1122. static void bnxt_free_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
  1123. {
  1124. struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
  1125. __clear_bit(idx, map->agg_idx_bmap);
  1126. }
  1127. static u16 bnxt_lookup_agg_idx(struct bnxt_rx_ring_info *rxr, u16 agg_id)
  1128. {
  1129. struct bnxt_tpa_idx_map *map = rxr->rx_tpa_idx_map;
  1130. return map->agg_id_tbl[agg_id];
  1131. }
  1132. static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
  1133. struct rx_tpa_start_cmp *tpa_start,
  1134. struct rx_tpa_start_cmp_ext *tpa_start1)
  1135. {
  1136. struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
  1137. struct bnxt_tpa_info *tpa_info;
  1138. u16 cons, prod, agg_id;
  1139. struct rx_bd *prod_bd;
  1140. dma_addr_t mapping;
  1141. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  1142. agg_id = TPA_START_AGG_ID_P5(tpa_start);
  1143. agg_id = bnxt_alloc_agg_idx(rxr, agg_id);
  1144. } else {
  1145. agg_id = TPA_START_AGG_ID(tpa_start);
  1146. }
  1147. cons = tpa_start->rx_tpa_start_cmp_opaque;
  1148. prod = rxr->rx_prod;
  1149. cons_rx_buf = &rxr->rx_buf_ring[cons];
  1150. prod_rx_buf = &rxr->rx_buf_ring[prod];
  1151. tpa_info = &rxr->rx_tpa[agg_id];
  1152. if (unlikely(cons != rxr->rx_next_cons ||
  1153. TPA_START_ERROR(tpa_start))) {
  1154. netdev_warn(bp->dev, "TPA cons %x, expected cons %x, error code %x\n",
  1155. cons, rxr->rx_next_cons,
  1156. TPA_START_ERROR_CODE(tpa_start1));
  1157. bnxt_sched_reset(bp, rxr);
  1158. return;
  1159. }
  1160. /* Store cfa_code in tpa_info to use in tpa_end
  1161. * completion processing.
  1162. */
  1163. tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1);
  1164. prod_rx_buf->data = tpa_info->data;
  1165. prod_rx_buf->data_ptr = tpa_info->data_ptr;
  1166. mapping = tpa_info->mapping;
  1167. prod_rx_buf->mapping = mapping;
  1168. prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  1169. prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
  1170. tpa_info->data = cons_rx_buf->data;
  1171. tpa_info->data_ptr = cons_rx_buf->data_ptr;
  1172. cons_rx_buf->data = NULL;
  1173. tpa_info->mapping = cons_rx_buf->mapping;
  1174. tpa_info->len =
  1175. le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
  1176. RX_TPA_START_CMP_LEN_SHIFT;
  1177. if (likely(TPA_START_HASH_VALID(tpa_start))) {
  1178. u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
  1179. tpa_info->hash_type = PKT_HASH_TYPE_L4;
  1180. tpa_info->gso_type = SKB_GSO_TCPV4;
  1181. /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
  1182. if (hash_type == 3 || TPA_START_IS_IPV6(tpa_start1))
  1183. tpa_info->gso_type = SKB_GSO_TCPV6;
  1184. tpa_info->rss_hash =
  1185. le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
  1186. } else {
  1187. tpa_info->hash_type = PKT_HASH_TYPE_NONE;
  1188. tpa_info->gso_type = 0;
  1189. netif_warn(bp, rx_err, bp->dev, "TPA packet without valid hash\n");
  1190. }
  1191. tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
  1192. tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
  1193. tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
  1194. tpa_info->agg_count = 0;
  1195. rxr->rx_prod = NEXT_RX(prod);
  1196. cons = NEXT_RX(cons);
  1197. rxr->rx_next_cons = NEXT_RX(cons);
  1198. cons_rx_buf = &rxr->rx_buf_ring[cons];
  1199. bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
  1200. rxr->rx_prod = NEXT_RX(rxr->rx_prod);
  1201. cons_rx_buf->data = NULL;
  1202. }
  1203. static void bnxt_abort_tpa(struct bnxt_cp_ring_info *cpr, u16 idx, u32 agg_bufs)
  1204. {
  1205. if (agg_bufs)
  1206. bnxt_reuse_rx_agg_bufs(cpr, idx, 0, agg_bufs, true);
  1207. }
  1208. #ifdef CONFIG_INET
  1209. static void bnxt_gro_tunnel(struct sk_buff *skb, __be16 ip_proto)
  1210. {
  1211. struct udphdr *uh = NULL;
  1212. if (ip_proto == htons(ETH_P_IP)) {
  1213. struct iphdr *iph = (struct iphdr *)skb->data;
  1214. if (iph->protocol == IPPROTO_UDP)
  1215. uh = (struct udphdr *)(iph + 1);
  1216. } else {
  1217. struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
  1218. if (iph->nexthdr == IPPROTO_UDP)
  1219. uh = (struct udphdr *)(iph + 1);
  1220. }
  1221. if (uh) {
  1222. if (uh->check)
  1223. skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
  1224. else
  1225. skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
  1226. }
  1227. }
  1228. #endif
  1229. static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
  1230. int payload_off, int tcp_ts,
  1231. struct sk_buff *skb)
  1232. {
  1233. #ifdef CONFIG_INET
  1234. struct tcphdr *th;
  1235. int len, nw_off;
  1236. u16 outer_ip_off, inner_ip_off, inner_mac_off;
  1237. u32 hdr_info = tpa_info->hdr_info;
  1238. bool loopback = false;
  1239. inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
  1240. inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
  1241. outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
  1242. /* If the packet is an internal loopback packet, the offsets will
  1243. * have an extra 4 bytes.
  1244. */
  1245. if (inner_mac_off == 4) {
  1246. loopback = true;
  1247. } else if (inner_mac_off > 4) {
  1248. __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
  1249. ETH_HLEN - 2));
  1250. /* We only support inner iPv4/ipv6. If we don't see the
  1251. * correct protocol ID, it must be a loopback packet where
  1252. * the offsets are off by 4.
  1253. */
  1254. if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
  1255. loopback = true;
  1256. }
  1257. if (loopback) {
  1258. /* internal loopback packet, subtract all offsets by 4 */
  1259. inner_ip_off -= 4;
  1260. inner_mac_off -= 4;
  1261. outer_ip_off -= 4;
  1262. }
  1263. nw_off = inner_ip_off - ETH_HLEN;
  1264. skb_set_network_header(skb, nw_off);
  1265. if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
  1266. struct ipv6hdr *iph = ipv6_hdr(skb);
  1267. skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
  1268. len = skb->len - skb_transport_offset(skb);
  1269. th = tcp_hdr(skb);
  1270. th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
  1271. } else {
  1272. struct iphdr *iph = ip_hdr(skb);
  1273. skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
  1274. len = skb->len - skb_transport_offset(skb);
  1275. th = tcp_hdr(skb);
  1276. th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
  1277. }
  1278. if (inner_mac_off) { /* tunnel */
  1279. __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
  1280. ETH_HLEN - 2));
  1281. bnxt_gro_tunnel(skb, proto);
  1282. }
  1283. #endif
  1284. return skb;
  1285. }
  1286. static struct sk_buff *bnxt_gro_func_5750x(struct bnxt_tpa_info *tpa_info,
  1287. int payload_off, int tcp_ts,
  1288. struct sk_buff *skb)
  1289. {
  1290. #ifdef CONFIG_INET
  1291. u16 outer_ip_off, inner_ip_off, inner_mac_off;
  1292. u32 hdr_info = tpa_info->hdr_info;
  1293. int iphdr_len, nw_off;
  1294. inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
  1295. inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
  1296. outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
  1297. nw_off = inner_ip_off - ETH_HLEN;
  1298. skb_set_network_header(skb, nw_off);
  1299. iphdr_len = (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) ?
  1300. sizeof(struct ipv6hdr) : sizeof(struct iphdr);
  1301. skb_set_transport_header(skb, nw_off + iphdr_len);
  1302. if (inner_mac_off) { /* tunnel */
  1303. __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
  1304. ETH_HLEN - 2));
  1305. bnxt_gro_tunnel(skb, proto);
  1306. }
  1307. #endif
  1308. return skb;
  1309. }
  1310. #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
  1311. #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
  1312. static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
  1313. int payload_off, int tcp_ts,
  1314. struct sk_buff *skb)
  1315. {
  1316. #ifdef CONFIG_INET
  1317. struct tcphdr *th;
  1318. int len, nw_off, tcp_opt_len = 0;
  1319. if (tcp_ts)
  1320. tcp_opt_len = 12;
  1321. if (tpa_info->gso_type == SKB_GSO_TCPV4) {
  1322. struct iphdr *iph;
  1323. nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
  1324. ETH_HLEN;
  1325. skb_set_network_header(skb, nw_off);
  1326. iph = ip_hdr(skb);
  1327. skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
  1328. len = skb->len - skb_transport_offset(skb);
  1329. th = tcp_hdr(skb);
  1330. th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
  1331. } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
  1332. struct ipv6hdr *iph;
  1333. nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
  1334. ETH_HLEN;
  1335. skb_set_network_header(skb, nw_off);
  1336. iph = ipv6_hdr(skb);
  1337. skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
  1338. len = skb->len - skb_transport_offset(skb);
  1339. th = tcp_hdr(skb);
  1340. th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
  1341. } else {
  1342. dev_kfree_skb_any(skb);
  1343. return NULL;
  1344. }
  1345. if (nw_off) /* tunnel */
  1346. bnxt_gro_tunnel(skb, skb->protocol);
  1347. #endif
  1348. return skb;
  1349. }
  1350. static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
  1351. struct bnxt_tpa_info *tpa_info,
  1352. struct rx_tpa_end_cmp *tpa_end,
  1353. struct rx_tpa_end_cmp_ext *tpa_end1,
  1354. struct sk_buff *skb)
  1355. {
  1356. #ifdef CONFIG_INET
  1357. int payload_off;
  1358. u16 segs;
  1359. segs = TPA_END_TPA_SEGS(tpa_end);
  1360. if (segs == 1)
  1361. return skb;
  1362. NAPI_GRO_CB(skb)->count = segs;
  1363. skb_shinfo(skb)->gso_size =
  1364. le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
  1365. skb_shinfo(skb)->gso_type = tpa_info->gso_type;
  1366. if (bp->flags & BNXT_FLAG_CHIP_P5)
  1367. payload_off = TPA_END_PAYLOAD_OFF_P5(tpa_end1);
  1368. else
  1369. payload_off = TPA_END_PAYLOAD_OFF(tpa_end);
  1370. skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
  1371. if (likely(skb))
  1372. tcp_gro_complete(skb);
  1373. #endif
  1374. return skb;
  1375. }
  1376. /* Given the cfa_code of a received packet determine which
  1377. * netdev (vf-rep or PF) the packet is destined to.
  1378. */
  1379. static struct net_device *bnxt_get_pkt_dev(struct bnxt *bp, u16 cfa_code)
  1380. {
  1381. struct net_device *dev = bnxt_get_vf_rep(bp, cfa_code);
  1382. /* if vf-rep dev is NULL, the must belongs to the PF */
  1383. return dev ? dev : bp->dev;
  1384. }
  1385. static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
  1386. struct bnxt_cp_ring_info *cpr,
  1387. u32 *raw_cons,
  1388. struct rx_tpa_end_cmp *tpa_end,
  1389. struct rx_tpa_end_cmp_ext *tpa_end1,
  1390. u8 *event)
  1391. {
  1392. struct bnxt_napi *bnapi = cpr->bnapi;
  1393. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  1394. u8 *data_ptr, agg_bufs;
  1395. unsigned int len;
  1396. struct bnxt_tpa_info *tpa_info;
  1397. dma_addr_t mapping;
  1398. struct sk_buff *skb;
  1399. u16 idx = 0, agg_id;
  1400. void *data;
  1401. bool gro;
  1402. if (unlikely(bnapi->in_reset)) {
  1403. int rc = bnxt_discard_rx(bp, cpr, raw_cons, tpa_end);
  1404. if (rc < 0)
  1405. return ERR_PTR(-EBUSY);
  1406. return NULL;
  1407. }
  1408. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  1409. agg_id = TPA_END_AGG_ID_P5(tpa_end);
  1410. agg_id = bnxt_lookup_agg_idx(rxr, agg_id);
  1411. agg_bufs = TPA_END_AGG_BUFS_P5(tpa_end1);
  1412. tpa_info = &rxr->rx_tpa[agg_id];
  1413. if (unlikely(agg_bufs != tpa_info->agg_count)) {
  1414. netdev_warn(bp->dev, "TPA end agg_buf %d != expected agg_bufs %d\n",
  1415. agg_bufs, tpa_info->agg_count);
  1416. agg_bufs = tpa_info->agg_count;
  1417. }
  1418. tpa_info->agg_count = 0;
  1419. *event |= BNXT_AGG_EVENT;
  1420. bnxt_free_agg_idx(rxr, agg_id);
  1421. idx = agg_id;
  1422. gro = !!(bp->flags & BNXT_FLAG_GRO);
  1423. } else {
  1424. agg_id = TPA_END_AGG_ID(tpa_end);
  1425. agg_bufs = TPA_END_AGG_BUFS(tpa_end);
  1426. tpa_info = &rxr->rx_tpa[agg_id];
  1427. idx = RING_CMP(*raw_cons);
  1428. if (agg_bufs) {
  1429. if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
  1430. return ERR_PTR(-EBUSY);
  1431. *event |= BNXT_AGG_EVENT;
  1432. idx = NEXT_CMP(idx);
  1433. }
  1434. gro = !!TPA_END_GRO(tpa_end);
  1435. }
  1436. data = tpa_info->data;
  1437. data_ptr = tpa_info->data_ptr;
  1438. prefetch(data_ptr);
  1439. len = tpa_info->len;
  1440. mapping = tpa_info->mapping;
  1441. if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) {
  1442. bnxt_abort_tpa(cpr, idx, agg_bufs);
  1443. if (agg_bufs > MAX_SKB_FRAGS)
  1444. netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
  1445. agg_bufs, (int)MAX_SKB_FRAGS);
  1446. return NULL;
  1447. }
  1448. if (len <= bp->rx_copy_thresh) {
  1449. skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
  1450. if (!skb) {
  1451. bnxt_abort_tpa(cpr, idx, agg_bufs);
  1452. cpr->sw_stats.rx.rx_oom_discards += 1;
  1453. return NULL;
  1454. }
  1455. } else {
  1456. u8 *new_data;
  1457. dma_addr_t new_mapping;
  1458. new_data = __bnxt_alloc_rx_frag(bp, &new_mapping, GFP_ATOMIC);
  1459. if (!new_data) {
  1460. bnxt_abort_tpa(cpr, idx, agg_bufs);
  1461. cpr->sw_stats.rx.rx_oom_discards += 1;
  1462. return NULL;
  1463. }
  1464. tpa_info->data = new_data;
  1465. tpa_info->data_ptr = new_data + bp->rx_offset;
  1466. tpa_info->mapping = new_mapping;
  1467. skb = build_skb(data, bp->rx_buf_size);
  1468. dma_unmap_single_attrs(&bp->pdev->dev, mapping,
  1469. bp->rx_buf_use_size, bp->rx_dir,
  1470. DMA_ATTR_WEAK_ORDERING);
  1471. if (!skb) {
  1472. skb_free_frag(data);
  1473. bnxt_abort_tpa(cpr, idx, agg_bufs);
  1474. cpr->sw_stats.rx.rx_oom_discards += 1;
  1475. return NULL;
  1476. }
  1477. skb_reserve(skb, bp->rx_offset);
  1478. skb_put(skb, len);
  1479. }
  1480. if (agg_bufs) {
  1481. skb = bnxt_rx_agg_pages_skb(bp, cpr, skb, idx, agg_bufs, true);
  1482. if (!skb) {
  1483. /* Page reuse already handled by bnxt_rx_pages(). */
  1484. cpr->sw_stats.rx.rx_oom_discards += 1;
  1485. return NULL;
  1486. }
  1487. }
  1488. skb->protocol =
  1489. eth_type_trans(skb, bnxt_get_pkt_dev(bp, tpa_info->cfa_code));
  1490. if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
  1491. skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
  1492. if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
  1493. (skb->dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)) {
  1494. __be16 vlan_proto = htons(tpa_info->metadata >>
  1495. RX_CMP_FLAGS2_METADATA_TPID_SFT);
  1496. u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK;
  1497. if (eth_type_vlan(vlan_proto)) {
  1498. __vlan_hwaccel_put_tag(skb, vlan_proto, vtag);
  1499. } else {
  1500. dev_kfree_skb(skb);
  1501. return NULL;
  1502. }
  1503. }
  1504. skb_checksum_none_assert(skb);
  1505. if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
  1506. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1507. skb->csum_level =
  1508. (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
  1509. }
  1510. if (gro)
  1511. skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
  1512. return skb;
  1513. }
  1514. static void bnxt_tpa_agg(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
  1515. struct rx_agg_cmp *rx_agg)
  1516. {
  1517. u16 agg_id = TPA_AGG_AGG_ID(rx_agg);
  1518. struct bnxt_tpa_info *tpa_info;
  1519. agg_id = bnxt_lookup_agg_idx(rxr, agg_id);
  1520. tpa_info = &rxr->rx_tpa[agg_id];
  1521. BUG_ON(tpa_info->agg_count >= MAX_SKB_FRAGS);
  1522. tpa_info->agg_arr[tpa_info->agg_count++] = *rx_agg;
  1523. }
  1524. static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi,
  1525. struct sk_buff *skb)
  1526. {
  1527. if (skb->dev != bp->dev) {
  1528. /* this packet belongs to a vf-rep */
  1529. bnxt_vf_rep_rx(bp, skb);
  1530. return;
  1531. }
  1532. skb_record_rx_queue(skb, bnapi->index);
  1533. napi_gro_receive(&bnapi->napi, skb);
  1534. }
  1535. /* returns the following:
  1536. * 1 - 1 packet successfully received
  1537. * 0 - successful TPA_START, packet not completed yet
  1538. * -EBUSY - completion ring does not have all the agg buffers yet
  1539. * -ENOMEM - packet aborted due to out of memory
  1540. * -EIO - packet aborted due to hw error indicated in BD
  1541. */
  1542. static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
  1543. u32 *raw_cons, u8 *event)
  1544. {
  1545. struct bnxt_napi *bnapi = cpr->bnapi;
  1546. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  1547. struct net_device *dev = bp->dev;
  1548. struct rx_cmp *rxcmp;
  1549. struct rx_cmp_ext *rxcmp1;
  1550. u32 tmp_raw_cons = *raw_cons;
  1551. u16 cfa_code, cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
  1552. struct bnxt_sw_rx_bd *rx_buf;
  1553. unsigned int len;
  1554. u8 *data_ptr, agg_bufs, cmp_type;
  1555. bool xdp_active = false;
  1556. dma_addr_t dma_addr;
  1557. struct sk_buff *skb;
  1558. struct xdp_buff xdp;
  1559. u32 flags, misc;
  1560. void *data;
  1561. int rc = 0;
  1562. rxcmp = (struct rx_cmp *)
  1563. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1564. cmp_type = RX_CMP_TYPE(rxcmp);
  1565. if (cmp_type == CMP_TYPE_RX_TPA_AGG_CMP) {
  1566. bnxt_tpa_agg(bp, rxr, (struct rx_agg_cmp *)rxcmp);
  1567. goto next_rx_no_prod_no_len;
  1568. }
  1569. tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
  1570. cp_cons = RING_CMP(tmp_raw_cons);
  1571. rxcmp1 = (struct rx_cmp_ext *)
  1572. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1573. if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
  1574. return -EBUSY;
  1575. /* The valid test of the entry must be done first before
  1576. * reading any further.
  1577. */
  1578. dma_rmb();
  1579. prod = rxr->rx_prod;
  1580. if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
  1581. bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
  1582. (struct rx_tpa_start_cmp_ext *)rxcmp1);
  1583. *event |= BNXT_RX_EVENT;
  1584. goto next_rx_no_prod_no_len;
  1585. } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
  1586. skb = bnxt_tpa_end(bp, cpr, &tmp_raw_cons,
  1587. (struct rx_tpa_end_cmp *)rxcmp,
  1588. (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
  1589. if (IS_ERR(skb))
  1590. return -EBUSY;
  1591. rc = -ENOMEM;
  1592. if (likely(skb)) {
  1593. bnxt_deliver_skb(bp, bnapi, skb);
  1594. rc = 1;
  1595. }
  1596. *event |= BNXT_RX_EVENT;
  1597. goto next_rx_no_prod_no_len;
  1598. }
  1599. cons = rxcmp->rx_cmp_opaque;
  1600. if (unlikely(cons != rxr->rx_next_cons)) {
  1601. int rc1 = bnxt_discard_rx(bp, cpr, &tmp_raw_cons, rxcmp);
  1602. /* 0xffff is forced error, don't print it */
  1603. if (rxr->rx_next_cons != 0xffff)
  1604. netdev_warn(bp->dev, "RX cons %x != expected cons %x\n",
  1605. cons, rxr->rx_next_cons);
  1606. bnxt_sched_reset(bp, rxr);
  1607. if (rc1)
  1608. return rc1;
  1609. goto next_rx_no_prod_no_len;
  1610. }
  1611. rx_buf = &rxr->rx_buf_ring[cons];
  1612. data = rx_buf->data;
  1613. data_ptr = rx_buf->data_ptr;
  1614. prefetch(data_ptr);
  1615. misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
  1616. agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
  1617. if (agg_bufs) {
  1618. if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
  1619. return -EBUSY;
  1620. cp_cons = NEXT_CMP(cp_cons);
  1621. *event |= BNXT_AGG_EVENT;
  1622. }
  1623. *event |= BNXT_RX_EVENT;
  1624. rx_buf->data = NULL;
  1625. if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
  1626. u32 rx_err = le32_to_cpu(rxcmp1->rx_cmp_cfa_code_errors_v2);
  1627. bnxt_reuse_rx_data(rxr, cons, data);
  1628. if (agg_bufs)
  1629. bnxt_reuse_rx_agg_bufs(cpr, cp_cons, 0, agg_bufs,
  1630. false);
  1631. rc = -EIO;
  1632. if (rx_err & RX_CMPL_ERRORS_BUFFER_ERROR_MASK) {
  1633. bnapi->cp_ring.sw_stats.rx.rx_buf_errors++;
  1634. if (!(bp->flags & BNXT_FLAG_CHIP_P5) &&
  1635. !(bp->fw_cap & BNXT_FW_CAP_RING_MONITOR)) {
  1636. netdev_warn_once(bp->dev, "RX buffer error %x\n",
  1637. rx_err);
  1638. bnxt_sched_reset(bp, rxr);
  1639. }
  1640. }
  1641. goto next_rx_no_len;
  1642. }
  1643. flags = le32_to_cpu(rxcmp->rx_cmp_len_flags_type);
  1644. len = flags >> RX_CMP_LEN_SHIFT;
  1645. dma_addr = rx_buf->mapping;
  1646. if (bnxt_xdp_attached(bp, rxr)) {
  1647. bnxt_xdp_buff_init(bp, rxr, cons, data_ptr, len, &xdp);
  1648. if (agg_bufs) {
  1649. u32 frag_len = bnxt_rx_agg_pages_xdp(bp, cpr, &xdp,
  1650. cp_cons, agg_bufs,
  1651. false);
  1652. if (!frag_len) {
  1653. cpr->sw_stats.rx.rx_oom_discards += 1;
  1654. rc = -ENOMEM;
  1655. goto next_rx;
  1656. }
  1657. }
  1658. xdp_active = true;
  1659. }
  1660. if (xdp_active) {
  1661. if (bnxt_rx_xdp(bp, rxr, cons, xdp, data, &data_ptr, &len, event)) {
  1662. rc = 1;
  1663. goto next_rx;
  1664. }
  1665. }
  1666. if (len <= bp->rx_copy_thresh) {
  1667. skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
  1668. bnxt_reuse_rx_data(rxr, cons, data);
  1669. if (!skb) {
  1670. if (agg_bufs) {
  1671. if (!xdp_active)
  1672. bnxt_reuse_rx_agg_bufs(cpr, cp_cons, 0,
  1673. agg_bufs, false);
  1674. else
  1675. bnxt_xdp_buff_frags_free(rxr, &xdp);
  1676. }
  1677. cpr->sw_stats.rx.rx_oom_discards += 1;
  1678. rc = -ENOMEM;
  1679. goto next_rx;
  1680. }
  1681. } else {
  1682. u32 payload;
  1683. if (rx_buf->data_ptr == data_ptr)
  1684. payload = misc & RX_CMP_PAYLOAD_OFFSET;
  1685. else
  1686. payload = 0;
  1687. skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
  1688. payload | len);
  1689. if (!skb) {
  1690. cpr->sw_stats.rx.rx_oom_discards += 1;
  1691. rc = -ENOMEM;
  1692. goto next_rx;
  1693. }
  1694. }
  1695. if (agg_bufs) {
  1696. if (!xdp_active) {
  1697. skb = bnxt_rx_agg_pages_skb(bp, cpr, skb, cp_cons, agg_bufs, false);
  1698. if (!skb) {
  1699. cpr->sw_stats.rx.rx_oom_discards += 1;
  1700. rc = -ENOMEM;
  1701. goto next_rx;
  1702. }
  1703. } else {
  1704. skb = bnxt_xdp_build_skb(bp, skb, agg_bufs, rxr->page_pool, &xdp, rxcmp1);
  1705. if (!skb) {
  1706. /* we should be able to free the old skb here */
  1707. bnxt_xdp_buff_frags_free(rxr, &xdp);
  1708. cpr->sw_stats.rx.rx_oom_discards += 1;
  1709. rc = -ENOMEM;
  1710. goto next_rx;
  1711. }
  1712. }
  1713. }
  1714. if (RX_CMP_HASH_VALID(rxcmp)) {
  1715. u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
  1716. enum pkt_hash_types type = PKT_HASH_TYPE_L4;
  1717. /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
  1718. if (hash_type != 1 && hash_type != 3)
  1719. type = PKT_HASH_TYPE_L3;
  1720. skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
  1721. }
  1722. cfa_code = RX_CMP_CFA_CODE(rxcmp1);
  1723. skb->protocol = eth_type_trans(skb, bnxt_get_pkt_dev(bp, cfa_code));
  1724. if ((rxcmp1->rx_cmp_flags2 &
  1725. cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
  1726. (skb->dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)) {
  1727. u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
  1728. u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK;
  1729. __be16 vlan_proto = htons(meta_data >>
  1730. RX_CMP_FLAGS2_METADATA_TPID_SFT);
  1731. if (eth_type_vlan(vlan_proto)) {
  1732. __vlan_hwaccel_put_tag(skb, vlan_proto, vtag);
  1733. } else {
  1734. dev_kfree_skb(skb);
  1735. goto next_rx;
  1736. }
  1737. }
  1738. skb_checksum_none_assert(skb);
  1739. if (RX_CMP_L4_CS_OK(rxcmp1)) {
  1740. if (dev->features & NETIF_F_RXCSUM) {
  1741. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1742. skb->csum_level = RX_CMP_ENCAP(rxcmp1);
  1743. }
  1744. } else {
  1745. if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
  1746. if (dev->features & NETIF_F_RXCSUM)
  1747. bnapi->cp_ring.sw_stats.rx.rx_l4_csum_errors++;
  1748. }
  1749. }
  1750. if (unlikely((flags & RX_CMP_FLAGS_ITYPES_MASK) ==
  1751. RX_CMP_FLAGS_ITYPE_PTP_W_TS) || bp->ptp_all_rx_tstamp) {
  1752. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  1753. u32 cmpl_ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp);
  1754. u64 ns, ts;
  1755. if (!bnxt_get_rx_ts_p5(bp, &ts, cmpl_ts)) {
  1756. struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
  1757. spin_lock_bh(&ptp->ptp_lock);
  1758. ns = timecounter_cyc2time(&ptp->tc, ts);
  1759. spin_unlock_bh(&ptp->ptp_lock);
  1760. memset(skb_hwtstamps(skb), 0,
  1761. sizeof(*skb_hwtstamps(skb)));
  1762. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  1763. }
  1764. }
  1765. }
  1766. bnxt_deliver_skb(bp, bnapi, skb);
  1767. rc = 1;
  1768. next_rx:
  1769. cpr->rx_packets += 1;
  1770. cpr->rx_bytes += len;
  1771. next_rx_no_len:
  1772. rxr->rx_prod = NEXT_RX(prod);
  1773. rxr->rx_next_cons = NEXT_RX(cons);
  1774. next_rx_no_prod_no_len:
  1775. *raw_cons = tmp_raw_cons;
  1776. return rc;
  1777. }
  1778. /* In netpoll mode, if we are using a combined completion ring, we need to
  1779. * discard the rx packets and recycle the buffers.
  1780. */
  1781. static int bnxt_force_rx_discard(struct bnxt *bp,
  1782. struct bnxt_cp_ring_info *cpr,
  1783. u32 *raw_cons, u8 *event)
  1784. {
  1785. u32 tmp_raw_cons = *raw_cons;
  1786. struct rx_cmp_ext *rxcmp1;
  1787. struct rx_cmp *rxcmp;
  1788. u16 cp_cons;
  1789. u8 cmp_type;
  1790. int rc;
  1791. cp_cons = RING_CMP(tmp_raw_cons);
  1792. rxcmp = (struct rx_cmp *)
  1793. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1794. tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
  1795. cp_cons = RING_CMP(tmp_raw_cons);
  1796. rxcmp1 = (struct rx_cmp_ext *)
  1797. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1798. if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
  1799. return -EBUSY;
  1800. /* The valid test of the entry must be done first before
  1801. * reading any further.
  1802. */
  1803. dma_rmb();
  1804. cmp_type = RX_CMP_TYPE(rxcmp);
  1805. if (cmp_type == CMP_TYPE_RX_L2_CMP) {
  1806. rxcmp1->rx_cmp_cfa_code_errors_v2 |=
  1807. cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
  1808. } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
  1809. struct rx_tpa_end_cmp_ext *tpa_end1;
  1810. tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1;
  1811. tpa_end1->rx_tpa_end_cmp_errors_v2 |=
  1812. cpu_to_le32(RX_TPA_END_CMP_ERRORS);
  1813. }
  1814. rc = bnxt_rx_pkt(bp, cpr, raw_cons, event);
  1815. if (rc && rc != -EBUSY)
  1816. cpr->sw_stats.rx.rx_netpoll_discards += 1;
  1817. return rc;
  1818. }
  1819. u32 bnxt_fw_health_readl(struct bnxt *bp, int reg_idx)
  1820. {
  1821. struct bnxt_fw_health *fw_health = bp->fw_health;
  1822. u32 reg = fw_health->regs[reg_idx];
  1823. u32 reg_type, reg_off, val = 0;
  1824. reg_type = BNXT_FW_HEALTH_REG_TYPE(reg);
  1825. reg_off = BNXT_FW_HEALTH_REG_OFF(reg);
  1826. switch (reg_type) {
  1827. case BNXT_FW_HEALTH_REG_TYPE_CFG:
  1828. pci_read_config_dword(bp->pdev, reg_off, &val);
  1829. break;
  1830. case BNXT_FW_HEALTH_REG_TYPE_GRC:
  1831. reg_off = fw_health->mapped_regs[reg_idx];
  1832. fallthrough;
  1833. case BNXT_FW_HEALTH_REG_TYPE_BAR0:
  1834. val = readl(bp->bar0 + reg_off);
  1835. break;
  1836. case BNXT_FW_HEALTH_REG_TYPE_BAR1:
  1837. val = readl(bp->bar1 + reg_off);
  1838. break;
  1839. }
  1840. if (reg_idx == BNXT_FW_RESET_INPROG_REG)
  1841. val &= fw_health->fw_reset_inprog_reg_mask;
  1842. return val;
  1843. }
  1844. static u16 bnxt_agg_ring_id_to_grp_idx(struct bnxt *bp, u16 ring_id)
  1845. {
  1846. int i;
  1847. for (i = 0; i < bp->rx_nr_rings; i++) {
  1848. u16 grp_idx = bp->rx_ring[i].bnapi->index;
  1849. struct bnxt_ring_grp_info *grp_info;
  1850. grp_info = &bp->grp_info[grp_idx];
  1851. if (grp_info->agg_fw_ring_id == ring_id)
  1852. return grp_idx;
  1853. }
  1854. return INVALID_HW_RING_ID;
  1855. }
  1856. static void bnxt_event_error_report(struct bnxt *bp, u32 data1, u32 data2)
  1857. {
  1858. u32 err_type = BNXT_EVENT_ERROR_REPORT_TYPE(data1);
  1859. switch (err_type) {
  1860. case ASYNC_EVENT_CMPL_ERROR_REPORT_BASE_EVENT_DATA1_ERROR_TYPE_INVALID_SIGNAL:
  1861. netdev_err(bp->dev, "1PPS: Received invalid signal on pin%lu from the external source. Please fix the signal and reconfigure the pin\n",
  1862. BNXT_EVENT_INVALID_SIGNAL_DATA(data2));
  1863. break;
  1864. case ASYNC_EVENT_CMPL_ERROR_REPORT_BASE_EVENT_DATA1_ERROR_TYPE_PAUSE_STORM:
  1865. netdev_warn(bp->dev, "Pause Storm detected!\n");
  1866. break;
  1867. case ASYNC_EVENT_CMPL_ERROR_REPORT_BASE_EVENT_DATA1_ERROR_TYPE_DOORBELL_DROP_THRESHOLD:
  1868. netdev_warn(bp->dev, "One or more MMIO doorbells dropped by the device!\n");
  1869. break;
  1870. default:
  1871. netdev_err(bp->dev, "FW reported unknown error type %u\n",
  1872. err_type);
  1873. break;
  1874. }
  1875. }
  1876. #define BNXT_GET_EVENT_PORT(data) \
  1877. ((data) & \
  1878. ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
  1879. #define BNXT_EVENT_RING_TYPE(data2) \
  1880. ((data2) & \
  1881. ASYNC_EVENT_CMPL_RING_MONITOR_MSG_EVENT_DATA2_DISABLE_RING_TYPE_MASK)
  1882. #define BNXT_EVENT_RING_TYPE_RX(data2) \
  1883. (BNXT_EVENT_RING_TYPE(data2) == \
  1884. ASYNC_EVENT_CMPL_RING_MONITOR_MSG_EVENT_DATA2_DISABLE_RING_TYPE_RX)
  1885. #define BNXT_EVENT_PHC_EVENT_TYPE(data1) \
  1886. (((data1) & ASYNC_EVENT_CMPL_PHC_UPDATE_EVENT_DATA1_FLAGS_MASK) >>\
  1887. ASYNC_EVENT_CMPL_PHC_UPDATE_EVENT_DATA1_FLAGS_SFT)
  1888. #define BNXT_EVENT_PHC_RTC_UPDATE(data1) \
  1889. (((data1) & ASYNC_EVENT_CMPL_PHC_UPDATE_EVENT_DATA1_PHC_TIME_MSB_MASK) >>\
  1890. ASYNC_EVENT_CMPL_PHC_UPDATE_EVENT_DATA1_PHC_TIME_MSB_SFT)
  1891. #define BNXT_PHC_BITS 48
  1892. static int bnxt_async_event_process(struct bnxt *bp,
  1893. struct hwrm_async_event_cmpl *cmpl)
  1894. {
  1895. u16 event_id = le16_to_cpu(cmpl->event_id);
  1896. u32 data1 = le32_to_cpu(cmpl->event_data1);
  1897. u32 data2 = le32_to_cpu(cmpl->event_data2);
  1898. netdev_dbg(bp->dev, "hwrm event 0x%x {0x%x, 0x%x}\n",
  1899. event_id, data1, data2);
  1900. /* TODO CHIMP_FW: Define event id's for link change, error etc */
  1901. switch (event_id) {
  1902. case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
  1903. struct bnxt_link_info *link_info = &bp->link_info;
  1904. if (BNXT_VF(bp))
  1905. goto async_event_process_exit;
  1906. /* print unsupported speed warning in forced speed mode only */
  1907. if (!(link_info->autoneg & BNXT_AUTONEG_SPEED) &&
  1908. (data1 & 0x20000)) {
  1909. u16 fw_speed = link_info->force_link_speed;
  1910. u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
  1911. if (speed != SPEED_UNKNOWN)
  1912. netdev_warn(bp->dev, "Link speed %d no longer supported\n",
  1913. speed);
  1914. }
  1915. set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
  1916. }
  1917. fallthrough;
  1918. case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE:
  1919. case ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE:
  1920. set_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT, &bp->sp_event);
  1921. fallthrough;
  1922. case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
  1923. set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
  1924. break;
  1925. case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
  1926. set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
  1927. break;
  1928. case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
  1929. u16 port_id = BNXT_GET_EVENT_PORT(data1);
  1930. if (BNXT_VF(bp))
  1931. break;
  1932. if (bp->pf.port_id != port_id)
  1933. break;
  1934. set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
  1935. break;
  1936. }
  1937. case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
  1938. if (BNXT_PF(bp))
  1939. goto async_event_process_exit;
  1940. set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
  1941. break;
  1942. case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY: {
  1943. char *type_str = "Solicited";
  1944. if (!bp->fw_health)
  1945. goto async_event_process_exit;
  1946. bp->fw_reset_timestamp = jiffies;
  1947. bp->fw_reset_min_dsecs = cmpl->timestamp_lo;
  1948. if (!bp->fw_reset_min_dsecs)
  1949. bp->fw_reset_min_dsecs = BNXT_DFLT_FW_RST_MIN_DSECS;
  1950. bp->fw_reset_max_dsecs = le16_to_cpu(cmpl->timestamp_hi);
  1951. if (!bp->fw_reset_max_dsecs)
  1952. bp->fw_reset_max_dsecs = BNXT_DFLT_FW_RST_MAX_DSECS;
  1953. if (EVENT_DATA1_RESET_NOTIFY_FW_ACTIVATION(data1)) {
  1954. set_bit(BNXT_STATE_FW_ACTIVATE_RESET, &bp->state);
  1955. } else if (EVENT_DATA1_RESET_NOTIFY_FATAL(data1)) {
  1956. type_str = "Fatal";
  1957. bp->fw_health->fatalities++;
  1958. set_bit(BNXT_STATE_FW_FATAL_COND, &bp->state);
  1959. } else if (data2 && BNXT_FW_STATUS_HEALTHY !=
  1960. EVENT_DATA2_RESET_NOTIFY_FW_STATUS_CODE(data2)) {
  1961. type_str = "Non-fatal";
  1962. bp->fw_health->survivals++;
  1963. set_bit(BNXT_STATE_FW_NON_FATAL_COND, &bp->state);
  1964. }
  1965. netif_warn(bp, hw, bp->dev,
  1966. "%s firmware reset event, data1: 0x%x, data2: 0x%x, min wait %u ms, max wait %u ms\n",
  1967. type_str, data1, data2,
  1968. bp->fw_reset_min_dsecs * 100,
  1969. bp->fw_reset_max_dsecs * 100);
  1970. set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event);
  1971. break;
  1972. }
  1973. case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY: {
  1974. struct bnxt_fw_health *fw_health = bp->fw_health;
  1975. char *status_desc = "healthy";
  1976. u32 status;
  1977. if (!fw_health)
  1978. goto async_event_process_exit;
  1979. if (!EVENT_DATA1_RECOVERY_ENABLED(data1)) {
  1980. fw_health->enabled = false;
  1981. netif_info(bp, drv, bp->dev, "Driver recovery watchdog is disabled\n");
  1982. break;
  1983. }
  1984. fw_health->primary = EVENT_DATA1_RECOVERY_MASTER_FUNC(data1);
  1985. fw_health->tmr_multiplier =
  1986. DIV_ROUND_UP(fw_health->polling_dsecs * HZ,
  1987. bp->current_interval * 10);
  1988. fw_health->tmr_counter = fw_health->tmr_multiplier;
  1989. if (!fw_health->enabled)
  1990. fw_health->last_fw_heartbeat =
  1991. bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
  1992. fw_health->last_fw_reset_cnt =
  1993. bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
  1994. status = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
  1995. if (status != BNXT_FW_STATUS_HEALTHY)
  1996. status_desc = "unhealthy";
  1997. netif_info(bp, drv, bp->dev,
  1998. "Driver recovery watchdog, role: %s, firmware status: 0x%x (%s), resets: %u\n",
  1999. fw_health->primary ? "primary" : "backup", status,
  2000. status_desc, fw_health->last_fw_reset_cnt);
  2001. if (!fw_health->enabled) {
  2002. /* Make sure tmr_counter is set and visible to
  2003. * bnxt_health_check() before setting enabled to true.
  2004. */
  2005. smp_wmb();
  2006. fw_health->enabled = true;
  2007. }
  2008. goto async_event_process_exit;
  2009. }
  2010. case ASYNC_EVENT_CMPL_EVENT_ID_DEBUG_NOTIFICATION:
  2011. netif_notice(bp, hw, bp->dev,
  2012. "Received firmware debug notification, data1: 0x%x, data2: 0x%x\n",
  2013. data1, data2);
  2014. goto async_event_process_exit;
  2015. case ASYNC_EVENT_CMPL_EVENT_ID_RING_MONITOR_MSG: {
  2016. struct bnxt_rx_ring_info *rxr;
  2017. u16 grp_idx;
  2018. if (bp->flags & BNXT_FLAG_CHIP_P5)
  2019. goto async_event_process_exit;
  2020. netdev_warn(bp->dev, "Ring monitor event, ring type %lu id 0x%x\n",
  2021. BNXT_EVENT_RING_TYPE(data2), data1);
  2022. if (!BNXT_EVENT_RING_TYPE_RX(data2))
  2023. goto async_event_process_exit;
  2024. grp_idx = bnxt_agg_ring_id_to_grp_idx(bp, data1);
  2025. if (grp_idx == INVALID_HW_RING_ID) {
  2026. netdev_warn(bp->dev, "Unknown RX agg ring id 0x%x\n",
  2027. data1);
  2028. goto async_event_process_exit;
  2029. }
  2030. rxr = bp->bnapi[grp_idx]->rx_ring;
  2031. bnxt_sched_reset(bp, rxr);
  2032. goto async_event_process_exit;
  2033. }
  2034. case ASYNC_EVENT_CMPL_EVENT_ID_ECHO_REQUEST: {
  2035. struct bnxt_fw_health *fw_health = bp->fw_health;
  2036. netif_notice(bp, hw, bp->dev,
  2037. "Received firmware echo request, data1: 0x%x, data2: 0x%x\n",
  2038. data1, data2);
  2039. if (fw_health) {
  2040. fw_health->echo_req_data1 = data1;
  2041. fw_health->echo_req_data2 = data2;
  2042. set_bit(BNXT_FW_ECHO_REQUEST_SP_EVENT, &bp->sp_event);
  2043. break;
  2044. }
  2045. goto async_event_process_exit;
  2046. }
  2047. case ASYNC_EVENT_CMPL_EVENT_ID_PPS_TIMESTAMP: {
  2048. bnxt_ptp_pps_event(bp, data1, data2);
  2049. goto async_event_process_exit;
  2050. }
  2051. case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_REPORT: {
  2052. bnxt_event_error_report(bp, data1, data2);
  2053. goto async_event_process_exit;
  2054. }
  2055. case ASYNC_EVENT_CMPL_EVENT_ID_PHC_UPDATE: {
  2056. switch (BNXT_EVENT_PHC_EVENT_TYPE(data1)) {
  2057. case ASYNC_EVENT_CMPL_PHC_UPDATE_EVENT_DATA1_FLAGS_PHC_RTC_UPDATE:
  2058. if (bp->fw_cap & BNXT_FW_CAP_PTP_RTC) {
  2059. struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
  2060. u64 ns;
  2061. if (!ptp)
  2062. goto async_event_process_exit;
  2063. spin_lock_bh(&ptp->ptp_lock);
  2064. bnxt_ptp_update_current_time(bp);
  2065. ns = (((u64)BNXT_EVENT_PHC_RTC_UPDATE(data1) <<
  2066. BNXT_PHC_BITS) | ptp->current_time);
  2067. bnxt_ptp_rtc_timecounter_init(ptp, ns);
  2068. spin_unlock_bh(&ptp->ptp_lock);
  2069. }
  2070. break;
  2071. }
  2072. goto async_event_process_exit;
  2073. }
  2074. case ASYNC_EVENT_CMPL_EVENT_ID_DEFERRED_RESPONSE: {
  2075. u16 seq_id = le32_to_cpu(cmpl->event_data2) & 0xffff;
  2076. hwrm_update_token(bp, seq_id, BNXT_HWRM_DEFERRED);
  2077. goto async_event_process_exit;
  2078. }
  2079. default:
  2080. goto async_event_process_exit;
  2081. }
  2082. bnxt_queue_sp_work(bp);
  2083. async_event_process_exit:
  2084. bnxt_ulp_async_events(bp, cmpl);
  2085. return 0;
  2086. }
  2087. static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
  2088. {
  2089. u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
  2090. struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
  2091. struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
  2092. (struct hwrm_fwd_req_cmpl *)txcmp;
  2093. switch (cmpl_type) {
  2094. case CMPL_BASE_TYPE_HWRM_DONE:
  2095. seq_id = le16_to_cpu(h_cmpl->sequence_id);
  2096. hwrm_update_token(bp, seq_id, BNXT_HWRM_COMPLETE);
  2097. break;
  2098. case CMPL_BASE_TYPE_HWRM_FWD_REQ:
  2099. vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
  2100. if ((vf_id < bp->pf.first_vf_id) ||
  2101. (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
  2102. netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
  2103. vf_id);
  2104. return -EINVAL;
  2105. }
  2106. set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
  2107. set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
  2108. bnxt_queue_sp_work(bp);
  2109. break;
  2110. case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
  2111. bnxt_async_event_process(bp,
  2112. (struct hwrm_async_event_cmpl *)txcmp);
  2113. break;
  2114. default:
  2115. break;
  2116. }
  2117. return 0;
  2118. }
  2119. static irqreturn_t bnxt_msix(int irq, void *dev_instance)
  2120. {
  2121. struct bnxt_napi *bnapi = dev_instance;
  2122. struct bnxt *bp = bnapi->bp;
  2123. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2124. u32 cons = RING_CMP(cpr->cp_raw_cons);
  2125. cpr->event_ctr++;
  2126. prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
  2127. napi_schedule(&bnapi->napi);
  2128. return IRQ_HANDLED;
  2129. }
  2130. static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
  2131. {
  2132. u32 raw_cons = cpr->cp_raw_cons;
  2133. u16 cons = RING_CMP(raw_cons);
  2134. struct tx_cmp *txcmp;
  2135. txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
  2136. return TX_CMP_VALID(txcmp, raw_cons);
  2137. }
  2138. static irqreturn_t bnxt_inta(int irq, void *dev_instance)
  2139. {
  2140. struct bnxt_napi *bnapi = dev_instance;
  2141. struct bnxt *bp = bnapi->bp;
  2142. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2143. u32 cons = RING_CMP(cpr->cp_raw_cons);
  2144. u32 int_status;
  2145. prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
  2146. if (!bnxt_has_work(bp, cpr)) {
  2147. int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
  2148. /* return if erroneous interrupt */
  2149. if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
  2150. return IRQ_NONE;
  2151. }
  2152. /* disable ring IRQ */
  2153. BNXT_CP_DB_IRQ_DIS(cpr->cp_db.doorbell);
  2154. /* Return here if interrupt is shared and is disabled. */
  2155. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  2156. return IRQ_HANDLED;
  2157. napi_schedule(&bnapi->napi);
  2158. return IRQ_HANDLED;
  2159. }
  2160. static int __bnxt_poll_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
  2161. int budget)
  2162. {
  2163. struct bnxt_napi *bnapi = cpr->bnapi;
  2164. u32 raw_cons = cpr->cp_raw_cons;
  2165. u32 cons;
  2166. int tx_pkts = 0;
  2167. int rx_pkts = 0;
  2168. u8 event = 0;
  2169. struct tx_cmp *txcmp;
  2170. cpr->has_more_work = 0;
  2171. cpr->had_work_done = 1;
  2172. while (1) {
  2173. int rc;
  2174. cons = RING_CMP(raw_cons);
  2175. txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
  2176. if (!TX_CMP_VALID(txcmp, raw_cons))
  2177. break;
  2178. /* The valid test of the entry must be done first before
  2179. * reading any further.
  2180. */
  2181. dma_rmb();
  2182. if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
  2183. tx_pkts++;
  2184. /* return full budget so NAPI will complete. */
  2185. if (unlikely(tx_pkts >= bp->tx_wake_thresh)) {
  2186. rx_pkts = budget;
  2187. raw_cons = NEXT_RAW_CMP(raw_cons);
  2188. if (budget)
  2189. cpr->has_more_work = 1;
  2190. break;
  2191. }
  2192. } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
  2193. if (likely(budget))
  2194. rc = bnxt_rx_pkt(bp, cpr, &raw_cons, &event);
  2195. else
  2196. rc = bnxt_force_rx_discard(bp, cpr, &raw_cons,
  2197. &event);
  2198. if (likely(rc >= 0))
  2199. rx_pkts += rc;
  2200. /* Increment rx_pkts when rc is -ENOMEM to count towards
  2201. * the NAPI budget. Otherwise, we may potentially loop
  2202. * here forever if we consistently cannot allocate
  2203. * buffers.
  2204. */
  2205. else if (rc == -ENOMEM && budget)
  2206. rx_pkts++;
  2207. else if (rc == -EBUSY) /* partial completion */
  2208. break;
  2209. } else if (unlikely((TX_CMP_TYPE(txcmp) ==
  2210. CMPL_BASE_TYPE_HWRM_DONE) ||
  2211. (TX_CMP_TYPE(txcmp) ==
  2212. CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
  2213. (TX_CMP_TYPE(txcmp) ==
  2214. CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
  2215. bnxt_hwrm_handler(bp, txcmp);
  2216. }
  2217. raw_cons = NEXT_RAW_CMP(raw_cons);
  2218. if (rx_pkts && rx_pkts == budget) {
  2219. cpr->has_more_work = 1;
  2220. break;
  2221. }
  2222. }
  2223. if (event & BNXT_REDIRECT_EVENT)
  2224. xdp_do_flush();
  2225. if (event & BNXT_TX_EVENT) {
  2226. struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
  2227. u16 prod = txr->tx_prod;
  2228. /* Sync BD data before updating doorbell */
  2229. wmb();
  2230. bnxt_db_write_relaxed(bp, &txr->tx_db, prod);
  2231. }
  2232. cpr->cp_raw_cons = raw_cons;
  2233. bnapi->tx_pkts += tx_pkts;
  2234. bnapi->events |= event;
  2235. return rx_pkts;
  2236. }
  2237. static void __bnxt_poll_work_done(struct bnxt *bp, struct bnxt_napi *bnapi)
  2238. {
  2239. if (bnapi->tx_pkts) {
  2240. bnapi->tx_int(bp, bnapi, bnapi->tx_pkts);
  2241. bnapi->tx_pkts = 0;
  2242. }
  2243. if ((bnapi->events & BNXT_RX_EVENT) && !(bnapi->in_reset)) {
  2244. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  2245. bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
  2246. }
  2247. if (bnapi->events & BNXT_AGG_EVENT) {
  2248. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  2249. bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
  2250. }
  2251. bnapi->events = 0;
  2252. }
  2253. static int bnxt_poll_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
  2254. int budget)
  2255. {
  2256. struct bnxt_napi *bnapi = cpr->bnapi;
  2257. int rx_pkts;
  2258. rx_pkts = __bnxt_poll_work(bp, cpr, budget);
  2259. /* ACK completion ring before freeing tx ring and producing new
  2260. * buffers in rx/agg rings to prevent overflowing the completion
  2261. * ring.
  2262. */
  2263. bnxt_db_cq(bp, &cpr->cp_db, cpr->cp_raw_cons);
  2264. __bnxt_poll_work_done(bp, bnapi);
  2265. return rx_pkts;
  2266. }
  2267. static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
  2268. {
  2269. struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
  2270. struct bnxt *bp = bnapi->bp;
  2271. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2272. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  2273. struct tx_cmp *txcmp;
  2274. struct rx_cmp_ext *rxcmp1;
  2275. u32 cp_cons, tmp_raw_cons;
  2276. u32 raw_cons = cpr->cp_raw_cons;
  2277. bool flush_xdp = false;
  2278. u32 rx_pkts = 0;
  2279. u8 event = 0;
  2280. while (1) {
  2281. int rc;
  2282. cp_cons = RING_CMP(raw_cons);
  2283. txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  2284. if (!TX_CMP_VALID(txcmp, raw_cons))
  2285. break;
  2286. /* The valid test of the entry must be done first before
  2287. * reading any further.
  2288. */
  2289. dma_rmb();
  2290. if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
  2291. tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
  2292. cp_cons = RING_CMP(tmp_raw_cons);
  2293. rxcmp1 = (struct rx_cmp_ext *)
  2294. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  2295. if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
  2296. break;
  2297. /* force an error to recycle the buffer */
  2298. rxcmp1->rx_cmp_cfa_code_errors_v2 |=
  2299. cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
  2300. rc = bnxt_rx_pkt(bp, cpr, &raw_cons, &event);
  2301. if (likely(rc == -EIO) && budget)
  2302. rx_pkts++;
  2303. else if (rc == -EBUSY) /* partial completion */
  2304. break;
  2305. if (event & BNXT_REDIRECT_EVENT)
  2306. flush_xdp = true;
  2307. } else if (unlikely(TX_CMP_TYPE(txcmp) ==
  2308. CMPL_BASE_TYPE_HWRM_DONE)) {
  2309. bnxt_hwrm_handler(bp, txcmp);
  2310. } else {
  2311. netdev_err(bp->dev,
  2312. "Invalid completion received on special ring\n");
  2313. }
  2314. raw_cons = NEXT_RAW_CMP(raw_cons);
  2315. if (rx_pkts == budget)
  2316. break;
  2317. }
  2318. cpr->cp_raw_cons = raw_cons;
  2319. BNXT_DB_CQ(&cpr->cp_db, cpr->cp_raw_cons);
  2320. bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
  2321. if (event & BNXT_AGG_EVENT)
  2322. bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
  2323. if (flush_xdp)
  2324. xdp_do_flush();
  2325. if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
  2326. napi_complete_done(napi, rx_pkts);
  2327. BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
  2328. }
  2329. return rx_pkts;
  2330. }
  2331. static int bnxt_poll(struct napi_struct *napi, int budget)
  2332. {
  2333. struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
  2334. struct bnxt *bp = bnapi->bp;
  2335. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2336. int work_done = 0;
  2337. if (unlikely(test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))) {
  2338. napi_complete(napi);
  2339. return 0;
  2340. }
  2341. while (1) {
  2342. work_done += bnxt_poll_work(bp, cpr, budget - work_done);
  2343. if (work_done >= budget) {
  2344. if (!budget)
  2345. BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
  2346. break;
  2347. }
  2348. if (!bnxt_has_work(bp, cpr)) {
  2349. if (napi_complete_done(napi, work_done))
  2350. BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons);
  2351. break;
  2352. }
  2353. }
  2354. if (bp->flags & BNXT_FLAG_DIM) {
  2355. struct dim_sample dim_sample = {};
  2356. dim_update_sample(cpr->event_ctr,
  2357. cpr->rx_packets,
  2358. cpr->rx_bytes,
  2359. &dim_sample);
  2360. net_dim(&cpr->dim, dim_sample);
  2361. }
  2362. return work_done;
  2363. }
  2364. static int __bnxt_poll_cqs(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
  2365. {
  2366. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2367. int i, work_done = 0;
  2368. for (i = 0; i < 2; i++) {
  2369. struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[i];
  2370. if (cpr2) {
  2371. work_done += __bnxt_poll_work(bp, cpr2,
  2372. budget - work_done);
  2373. cpr->has_more_work |= cpr2->has_more_work;
  2374. }
  2375. }
  2376. return work_done;
  2377. }
  2378. static void __bnxt_poll_cqs_done(struct bnxt *bp, struct bnxt_napi *bnapi,
  2379. u64 dbr_type)
  2380. {
  2381. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2382. int i;
  2383. for (i = 0; i < 2; i++) {
  2384. struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[i];
  2385. struct bnxt_db_info *db;
  2386. if (cpr2 && cpr2->had_work_done) {
  2387. db = &cpr2->cp_db;
  2388. bnxt_writeq(bp, db->db_key64 | dbr_type |
  2389. RING_CMP(cpr2->cp_raw_cons), db->doorbell);
  2390. cpr2->had_work_done = 0;
  2391. }
  2392. }
  2393. __bnxt_poll_work_done(bp, bnapi);
  2394. }
  2395. static int bnxt_poll_p5(struct napi_struct *napi, int budget)
  2396. {
  2397. struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
  2398. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2399. struct bnxt_cp_ring_info *cpr_rx;
  2400. u32 raw_cons = cpr->cp_raw_cons;
  2401. struct bnxt *bp = bnapi->bp;
  2402. struct nqe_cn *nqcmp;
  2403. int work_done = 0;
  2404. u32 cons;
  2405. if (unlikely(test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))) {
  2406. napi_complete(napi);
  2407. return 0;
  2408. }
  2409. if (cpr->has_more_work) {
  2410. cpr->has_more_work = 0;
  2411. work_done = __bnxt_poll_cqs(bp, bnapi, budget);
  2412. }
  2413. while (1) {
  2414. cons = RING_CMP(raw_cons);
  2415. nqcmp = &cpr->nq_desc_ring[CP_RING(cons)][CP_IDX(cons)];
  2416. if (!NQ_CMP_VALID(nqcmp, raw_cons)) {
  2417. if (cpr->has_more_work)
  2418. break;
  2419. __bnxt_poll_cqs_done(bp, bnapi, DBR_TYPE_CQ_ARMALL);
  2420. cpr->cp_raw_cons = raw_cons;
  2421. if (napi_complete_done(napi, work_done))
  2422. BNXT_DB_NQ_ARM_P5(&cpr->cp_db,
  2423. cpr->cp_raw_cons);
  2424. goto poll_done;
  2425. }
  2426. /* The valid test of the entry must be done first before
  2427. * reading any further.
  2428. */
  2429. dma_rmb();
  2430. if (nqcmp->type == cpu_to_le16(NQ_CN_TYPE_CQ_NOTIFICATION)) {
  2431. u32 idx = le32_to_cpu(nqcmp->cq_handle_low);
  2432. struct bnxt_cp_ring_info *cpr2;
  2433. /* No more budget for RX work */
  2434. if (budget && work_done >= budget && idx == BNXT_RX_HDL)
  2435. break;
  2436. cpr2 = cpr->cp_ring_arr[idx];
  2437. work_done += __bnxt_poll_work(bp, cpr2,
  2438. budget - work_done);
  2439. cpr->has_more_work |= cpr2->has_more_work;
  2440. } else {
  2441. bnxt_hwrm_handler(bp, (struct tx_cmp *)nqcmp);
  2442. }
  2443. raw_cons = NEXT_RAW_CMP(raw_cons);
  2444. }
  2445. __bnxt_poll_cqs_done(bp, bnapi, DBR_TYPE_CQ);
  2446. if (raw_cons != cpr->cp_raw_cons) {
  2447. cpr->cp_raw_cons = raw_cons;
  2448. BNXT_DB_NQ_P5(&cpr->cp_db, raw_cons);
  2449. }
  2450. poll_done:
  2451. cpr_rx = cpr->cp_ring_arr[BNXT_RX_HDL];
  2452. if (cpr_rx && (bp->flags & BNXT_FLAG_DIM)) {
  2453. struct dim_sample dim_sample = {};
  2454. dim_update_sample(cpr->event_ctr,
  2455. cpr_rx->rx_packets,
  2456. cpr_rx->rx_bytes,
  2457. &dim_sample);
  2458. net_dim(&cpr->dim, dim_sample);
  2459. }
  2460. return work_done;
  2461. }
  2462. static void bnxt_free_tx_skbs(struct bnxt *bp)
  2463. {
  2464. int i, max_idx;
  2465. struct pci_dev *pdev = bp->pdev;
  2466. if (!bp->tx_ring)
  2467. return;
  2468. max_idx = bp->tx_nr_pages * TX_DESC_CNT;
  2469. for (i = 0; i < bp->tx_nr_rings; i++) {
  2470. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  2471. int j;
  2472. if (!txr->tx_buf_ring)
  2473. continue;
  2474. for (j = 0; j < max_idx;) {
  2475. struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
  2476. struct sk_buff *skb;
  2477. int k, last;
  2478. if (i < bp->tx_nr_rings_xdp &&
  2479. tx_buf->action == XDP_REDIRECT) {
  2480. dma_unmap_single(&pdev->dev,
  2481. dma_unmap_addr(tx_buf, mapping),
  2482. dma_unmap_len(tx_buf, len),
  2483. DMA_TO_DEVICE);
  2484. xdp_return_frame(tx_buf->xdpf);
  2485. tx_buf->action = 0;
  2486. tx_buf->xdpf = NULL;
  2487. j++;
  2488. continue;
  2489. }
  2490. skb = tx_buf->skb;
  2491. if (!skb) {
  2492. j++;
  2493. continue;
  2494. }
  2495. tx_buf->skb = NULL;
  2496. if (tx_buf->is_push) {
  2497. dev_kfree_skb(skb);
  2498. j += 2;
  2499. continue;
  2500. }
  2501. dma_unmap_single(&pdev->dev,
  2502. dma_unmap_addr(tx_buf, mapping),
  2503. skb_headlen(skb),
  2504. DMA_TO_DEVICE);
  2505. last = tx_buf->nr_frags;
  2506. j += 2;
  2507. for (k = 0; k < last; k++, j++) {
  2508. int ring_idx = j & bp->tx_ring_mask;
  2509. skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
  2510. tx_buf = &txr->tx_buf_ring[ring_idx];
  2511. dma_unmap_page(
  2512. &pdev->dev,
  2513. dma_unmap_addr(tx_buf, mapping),
  2514. skb_frag_size(frag), DMA_TO_DEVICE);
  2515. }
  2516. dev_kfree_skb(skb);
  2517. }
  2518. netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
  2519. }
  2520. }
  2521. static void bnxt_free_one_rx_ring_skbs(struct bnxt *bp, int ring_nr)
  2522. {
  2523. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
  2524. struct pci_dev *pdev = bp->pdev;
  2525. struct bnxt_tpa_idx_map *map;
  2526. int i, max_idx, max_agg_idx;
  2527. max_idx = bp->rx_nr_pages * RX_DESC_CNT;
  2528. max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
  2529. if (!rxr->rx_tpa)
  2530. goto skip_rx_tpa_free;
  2531. for (i = 0; i < bp->max_tpa; i++) {
  2532. struct bnxt_tpa_info *tpa_info = &rxr->rx_tpa[i];
  2533. u8 *data = tpa_info->data;
  2534. if (!data)
  2535. continue;
  2536. dma_unmap_single_attrs(&pdev->dev, tpa_info->mapping,
  2537. bp->rx_buf_use_size, bp->rx_dir,
  2538. DMA_ATTR_WEAK_ORDERING);
  2539. tpa_info->data = NULL;
  2540. skb_free_frag(data);
  2541. }
  2542. skip_rx_tpa_free:
  2543. if (!rxr->rx_buf_ring)
  2544. goto skip_rx_buf_free;
  2545. for (i = 0; i < max_idx; i++) {
  2546. struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[i];
  2547. dma_addr_t mapping = rx_buf->mapping;
  2548. void *data = rx_buf->data;
  2549. if (!data)
  2550. continue;
  2551. rx_buf->data = NULL;
  2552. if (BNXT_RX_PAGE_MODE(bp)) {
  2553. mapping -= bp->rx_dma_offset;
  2554. dma_unmap_page_attrs(&pdev->dev, mapping,
  2555. BNXT_RX_PAGE_SIZE, bp->rx_dir,
  2556. DMA_ATTR_WEAK_ORDERING);
  2557. page_pool_recycle_direct(rxr->page_pool, data);
  2558. } else {
  2559. dma_unmap_single_attrs(&pdev->dev, mapping,
  2560. bp->rx_buf_use_size, bp->rx_dir,
  2561. DMA_ATTR_WEAK_ORDERING);
  2562. skb_free_frag(data);
  2563. }
  2564. }
  2565. skip_rx_buf_free:
  2566. if (!rxr->rx_agg_ring)
  2567. goto skip_rx_agg_free;
  2568. for (i = 0; i < max_agg_idx; i++) {
  2569. struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
  2570. struct page *page = rx_agg_buf->page;
  2571. if (!page)
  2572. continue;
  2573. if (BNXT_RX_PAGE_MODE(bp)) {
  2574. dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
  2575. BNXT_RX_PAGE_SIZE, bp->rx_dir,
  2576. DMA_ATTR_WEAK_ORDERING);
  2577. rx_agg_buf->page = NULL;
  2578. __clear_bit(i, rxr->rx_agg_bmap);
  2579. page_pool_recycle_direct(rxr->page_pool, page);
  2580. } else {
  2581. dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping,
  2582. BNXT_RX_PAGE_SIZE, DMA_FROM_DEVICE,
  2583. DMA_ATTR_WEAK_ORDERING);
  2584. rx_agg_buf->page = NULL;
  2585. __clear_bit(i, rxr->rx_agg_bmap);
  2586. __free_page(page);
  2587. }
  2588. }
  2589. skip_rx_agg_free:
  2590. if (rxr->rx_page) {
  2591. __free_page(rxr->rx_page);
  2592. rxr->rx_page = NULL;
  2593. }
  2594. map = rxr->rx_tpa_idx_map;
  2595. if (map)
  2596. memset(map->agg_idx_bmap, 0, sizeof(map->agg_idx_bmap));
  2597. }
  2598. static void bnxt_free_rx_skbs(struct bnxt *bp)
  2599. {
  2600. int i;
  2601. if (!bp->rx_ring)
  2602. return;
  2603. for (i = 0; i < bp->rx_nr_rings; i++)
  2604. bnxt_free_one_rx_ring_skbs(bp, i);
  2605. }
  2606. static void bnxt_free_skbs(struct bnxt *bp)
  2607. {
  2608. bnxt_free_tx_skbs(bp);
  2609. bnxt_free_rx_skbs(bp);
  2610. }
  2611. static void bnxt_init_ctx_mem(struct bnxt_mem_init *mem_init, void *p, int len)
  2612. {
  2613. u8 init_val = mem_init->init_val;
  2614. u16 offset = mem_init->offset;
  2615. u8 *p2 = p;
  2616. int i;
  2617. if (!init_val)
  2618. return;
  2619. if (offset == BNXT_MEM_INVALID_OFFSET) {
  2620. memset(p, init_val, len);
  2621. return;
  2622. }
  2623. for (i = 0; i < len; i += mem_init->size)
  2624. *(p2 + i + offset) = init_val;
  2625. }
  2626. static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
  2627. {
  2628. struct pci_dev *pdev = bp->pdev;
  2629. int i;
  2630. if (!rmem->pg_arr)
  2631. goto skip_pages;
  2632. for (i = 0; i < rmem->nr_pages; i++) {
  2633. if (!rmem->pg_arr[i])
  2634. continue;
  2635. dma_free_coherent(&pdev->dev, rmem->page_size,
  2636. rmem->pg_arr[i], rmem->dma_arr[i]);
  2637. rmem->pg_arr[i] = NULL;
  2638. }
  2639. skip_pages:
  2640. if (rmem->pg_tbl) {
  2641. size_t pg_tbl_size = rmem->nr_pages * 8;
  2642. if (rmem->flags & BNXT_RMEM_USE_FULL_PAGE_FLAG)
  2643. pg_tbl_size = rmem->page_size;
  2644. dma_free_coherent(&pdev->dev, pg_tbl_size,
  2645. rmem->pg_tbl, rmem->pg_tbl_map);
  2646. rmem->pg_tbl = NULL;
  2647. }
  2648. if (rmem->vmem_size && *rmem->vmem) {
  2649. vfree(*rmem->vmem);
  2650. *rmem->vmem = NULL;
  2651. }
  2652. }
  2653. static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem)
  2654. {
  2655. struct pci_dev *pdev = bp->pdev;
  2656. u64 valid_bit = 0;
  2657. int i;
  2658. if (rmem->flags & (BNXT_RMEM_VALID_PTE_FLAG | BNXT_RMEM_RING_PTE_FLAG))
  2659. valid_bit = PTU_PTE_VALID;
  2660. if ((rmem->nr_pages > 1 || rmem->depth > 0) && !rmem->pg_tbl) {
  2661. size_t pg_tbl_size = rmem->nr_pages * 8;
  2662. if (rmem->flags & BNXT_RMEM_USE_FULL_PAGE_FLAG)
  2663. pg_tbl_size = rmem->page_size;
  2664. rmem->pg_tbl = dma_alloc_coherent(&pdev->dev, pg_tbl_size,
  2665. &rmem->pg_tbl_map,
  2666. GFP_KERNEL);
  2667. if (!rmem->pg_tbl)
  2668. return -ENOMEM;
  2669. }
  2670. for (i = 0; i < rmem->nr_pages; i++) {
  2671. u64 extra_bits = valid_bit;
  2672. rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
  2673. rmem->page_size,
  2674. &rmem->dma_arr[i],
  2675. GFP_KERNEL);
  2676. if (!rmem->pg_arr[i])
  2677. return -ENOMEM;
  2678. if (rmem->mem_init)
  2679. bnxt_init_ctx_mem(rmem->mem_init, rmem->pg_arr[i],
  2680. rmem->page_size);
  2681. if (rmem->nr_pages > 1 || rmem->depth > 0) {
  2682. if (i == rmem->nr_pages - 2 &&
  2683. (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
  2684. extra_bits |= PTU_PTE_NEXT_TO_LAST;
  2685. else if (i == rmem->nr_pages - 1 &&
  2686. (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
  2687. extra_bits |= PTU_PTE_LAST;
  2688. rmem->pg_tbl[i] =
  2689. cpu_to_le64(rmem->dma_arr[i] | extra_bits);
  2690. }
  2691. }
  2692. if (rmem->vmem_size) {
  2693. *rmem->vmem = vzalloc(rmem->vmem_size);
  2694. if (!(*rmem->vmem))
  2695. return -ENOMEM;
  2696. }
  2697. return 0;
  2698. }
  2699. static void bnxt_free_tpa_info(struct bnxt *bp)
  2700. {
  2701. int i, j;
  2702. for (i = 0; i < bp->rx_nr_rings; i++) {
  2703. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  2704. kfree(rxr->rx_tpa_idx_map);
  2705. rxr->rx_tpa_idx_map = NULL;
  2706. if (rxr->rx_tpa) {
  2707. for (j = 0; j < bp->max_tpa; j++) {
  2708. kfree(rxr->rx_tpa[j].agg_arr);
  2709. rxr->rx_tpa[j].agg_arr = NULL;
  2710. }
  2711. }
  2712. kfree(rxr->rx_tpa);
  2713. rxr->rx_tpa = NULL;
  2714. }
  2715. }
  2716. static int bnxt_alloc_tpa_info(struct bnxt *bp)
  2717. {
  2718. int i, j;
  2719. bp->max_tpa = MAX_TPA;
  2720. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  2721. if (!bp->max_tpa_v2)
  2722. return 0;
  2723. bp->max_tpa = max_t(u16, bp->max_tpa_v2, MAX_TPA_P5);
  2724. }
  2725. for (i = 0; i < bp->rx_nr_rings; i++) {
  2726. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  2727. struct rx_agg_cmp *agg;
  2728. rxr->rx_tpa = kcalloc(bp->max_tpa, sizeof(struct bnxt_tpa_info),
  2729. GFP_KERNEL);
  2730. if (!rxr->rx_tpa)
  2731. return -ENOMEM;
  2732. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  2733. continue;
  2734. for (j = 0; j < bp->max_tpa; j++) {
  2735. agg = kcalloc(MAX_SKB_FRAGS, sizeof(*agg), GFP_KERNEL);
  2736. if (!agg)
  2737. return -ENOMEM;
  2738. rxr->rx_tpa[j].agg_arr = agg;
  2739. }
  2740. rxr->rx_tpa_idx_map = kzalloc(sizeof(*rxr->rx_tpa_idx_map),
  2741. GFP_KERNEL);
  2742. if (!rxr->rx_tpa_idx_map)
  2743. return -ENOMEM;
  2744. }
  2745. return 0;
  2746. }
  2747. static void bnxt_free_rx_rings(struct bnxt *bp)
  2748. {
  2749. int i;
  2750. if (!bp->rx_ring)
  2751. return;
  2752. bnxt_free_tpa_info(bp);
  2753. for (i = 0; i < bp->rx_nr_rings; i++) {
  2754. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  2755. struct bnxt_ring_struct *ring;
  2756. if (rxr->xdp_prog)
  2757. bpf_prog_put(rxr->xdp_prog);
  2758. if (xdp_rxq_info_is_reg(&rxr->xdp_rxq))
  2759. xdp_rxq_info_unreg(&rxr->xdp_rxq);
  2760. page_pool_destroy(rxr->page_pool);
  2761. rxr->page_pool = NULL;
  2762. kfree(rxr->rx_agg_bmap);
  2763. rxr->rx_agg_bmap = NULL;
  2764. ring = &rxr->rx_ring_struct;
  2765. bnxt_free_ring(bp, &ring->ring_mem);
  2766. ring = &rxr->rx_agg_ring_struct;
  2767. bnxt_free_ring(bp, &ring->ring_mem);
  2768. }
  2769. }
  2770. static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
  2771. struct bnxt_rx_ring_info *rxr)
  2772. {
  2773. struct page_pool_params pp = { 0 };
  2774. pp.pool_size = bp->rx_ring_size;
  2775. pp.nid = dev_to_node(&bp->pdev->dev);
  2776. pp.dev = &bp->pdev->dev;
  2777. pp.dma_dir = DMA_BIDIRECTIONAL;
  2778. if (PAGE_SIZE > BNXT_RX_PAGE_SIZE)
  2779. pp.flags |= PP_FLAG_PAGE_FRAG;
  2780. rxr->page_pool = page_pool_create(&pp);
  2781. if (IS_ERR(rxr->page_pool)) {
  2782. int err = PTR_ERR(rxr->page_pool);
  2783. rxr->page_pool = NULL;
  2784. return err;
  2785. }
  2786. return 0;
  2787. }
  2788. static int bnxt_alloc_rx_rings(struct bnxt *bp)
  2789. {
  2790. int i, rc = 0, agg_rings = 0;
  2791. if (!bp->rx_ring)
  2792. return -ENOMEM;
  2793. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  2794. agg_rings = 1;
  2795. for (i = 0; i < bp->rx_nr_rings; i++) {
  2796. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  2797. struct bnxt_ring_struct *ring;
  2798. ring = &rxr->rx_ring_struct;
  2799. rc = bnxt_alloc_rx_page_pool(bp, rxr);
  2800. if (rc)
  2801. return rc;
  2802. rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i, 0);
  2803. if (rc < 0)
  2804. return rc;
  2805. rc = xdp_rxq_info_reg_mem_model(&rxr->xdp_rxq,
  2806. MEM_TYPE_PAGE_POOL,
  2807. rxr->page_pool);
  2808. if (rc) {
  2809. xdp_rxq_info_unreg(&rxr->xdp_rxq);
  2810. return rc;
  2811. }
  2812. rc = bnxt_alloc_ring(bp, &ring->ring_mem);
  2813. if (rc)
  2814. return rc;
  2815. ring->grp_idx = i;
  2816. if (agg_rings) {
  2817. u16 mem_size;
  2818. ring = &rxr->rx_agg_ring_struct;
  2819. rc = bnxt_alloc_ring(bp, &ring->ring_mem);
  2820. if (rc)
  2821. return rc;
  2822. ring->grp_idx = i;
  2823. rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
  2824. mem_size = rxr->rx_agg_bmap_size / 8;
  2825. rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
  2826. if (!rxr->rx_agg_bmap)
  2827. return -ENOMEM;
  2828. }
  2829. }
  2830. if (bp->flags & BNXT_FLAG_TPA)
  2831. rc = bnxt_alloc_tpa_info(bp);
  2832. return rc;
  2833. }
  2834. static void bnxt_free_tx_rings(struct bnxt *bp)
  2835. {
  2836. int i;
  2837. struct pci_dev *pdev = bp->pdev;
  2838. if (!bp->tx_ring)
  2839. return;
  2840. for (i = 0; i < bp->tx_nr_rings; i++) {
  2841. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  2842. struct bnxt_ring_struct *ring;
  2843. if (txr->tx_push) {
  2844. dma_free_coherent(&pdev->dev, bp->tx_push_size,
  2845. txr->tx_push, txr->tx_push_mapping);
  2846. txr->tx_push = NULL;
  2847. }
  2848. ring = &txr->tx_ring_struct;
  2849. bnxt_free_ring(bp, &ring->ring_mem);
  2850. }
  2851. }
  2852. static int bnxt_alloc_tx_rings(struct bnxt *bp)
  2853. {
  2854. int i, j, rc;
  2855. struct pci_dev *pdev = bp->pdev;
  2856. bp->tx_push_size = 0;
  2857. if (bp->tx_push_thresh) {
  2858. int push_size;
  2859. push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
  2860. bp->tx_push_thresh);
  2861. if (push_size > 256) {
  2862. push_size = 0;
  2863. bp->tx_push_thresh = 0;
  2864. }
  2865. bp->tx_push_size = push_size;
  2866. }
  2867. for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
  2868. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  2869. struct bnxt_ring_struct *ring;
  2870. u8 qidx;
  2871. ring = &txr->tx_ring_struct;
  2872. rc = bnxt_alloc_ring(bp, &ring->ring_mem);
  2873. if (rc)
  2874. return rc;
  2875. ring->grp_idx = txr->bnapi->index;
  2876. if (bp->tx_push_size) {
  2877. dma_addr_t mapping;
  2878. /* One pre-allocated DMA buffer to backup
  2879. * TX push operation
  2880. */
  2881. txr->tx_push = dma_alloc_coherent(&pdev->dev,
  2882. bp->tx_push_size,
  2883. &txr->tx_push_mapping,
  2884. GFP_KERNEL);
  2885. if (!txr->tx_push)
  2886. return -ENOMEM;
  2887. mapping = txr->tx_push_mapping +
  2888. sizeof(struct tx_push_bd);
  2889. txr->data_mapping = cpu_to_le64(mapping);
  2890. }
  2891. qidx = bp->tc_to_qidx[j];
  2892. ring->queue_id = bp->q_info[qidx].queue_id;
  2893. spin_lock_init(&txr->xdp_tx_lock);
  2894. if (i < bp->tx_nr_rings_xdp)
  2895. continue;
  2896. if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
  2897. j++;
  2898. }
  2899. return 0;
  2900. }
  2901. static void bnxt_free_cp_arrays(struct bnxt_cp_ring_info *cpr)
  2902. {
  2903. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  2904. kfree(cpr->cp_desc_ring);
  2905. cpr->cp_desc_ring = NULL;
  2906. ring->ring_mem.pg_arr = NULL;
  2907. kfree(cpr->cp_desc_mapping);
  2908. cpr->cp_desc_mapping = NULL;
  2909. ring->ring_mem.dma_arr = NULL;
  2910. }
  2911. static int bnxt_alloc_cp_arrays(struct bnxt_cp_ring_info *cpr, int n)
  2912. {
  2913. cpr->cp_desc_ring = kcalloc(n, sizeof(*cpr->cp_desc_ring), GFP_KERNEL);
  2914. if (!cpr->cp_desc_ring)
  2915. return -ENOMEM;
  2916. cpr->cp_desc_mapping = kcalloc(n, sizeof(*cpr->cp_desc_mapping),
  2917. GFP_KERNEL);
  2918. if (!cpr->cp_desc_mapping)
  2919. return -ENOMEM;
  2920. return 0;
  2921. }
  2922. static void bnxt_free_all_cp_arrays(struct bnxt *bp)
  2923. {
  2924. int i;
  2925. if (!bp->bnapi)
  2926. return;
  2927. for (i = 0; i < bp->cp_nr_rings; i++) {
  2928. struct bnxt_napi *bnapi = bp->bnapi[i];
  2929. if (!bnapi)
  2930. continue;
  2931. bnxt_free_cp_arrays(&bnapi->cp_ring);
  2932. }
  2933. }
  2934. static int bnxt_alloc_all_cp_arrays(struct bnxt *bp)
  2935. {
  2936. int i, n = bp->cp_nr_pages;
  2937. for (i = 0; i < bp->cp_nr_rings; i++) {
  2938. struct bnxt_napi *bnapi = bp->bnapi[i];
  2939. int rc;
  2940. if (!bnapi)
  2941. continue;
  2942. rc = bnxt_alloc_cp_arrays(&bnapi->cp_ring, n);
  2943. if (rc)
  2944. return rc;
  2945. }
  2946. return 0;
  2947. }
  2948. static void bnxt_free_cp_rings(struct bnxt *bp)
  2949. {
  2950. int i;
  2951. if (!bp->bnapi)
  2952. return;
  2953. for (i = 0; i < bp->cp_nr_rings; i++) {
  2954. struct bnxt_napi *bnapi = bp->bnapi[i];
  2955. struct bnxt_cp_ring_info *cpr;
  2956. struct bnxt_ring_struct *ring;
  2957. int j;
  2958. if (!bnapi)
  2959. continue;
  2960. cpr = &bnapi->cp_ring;
  2961. ring = &cpr->cp_ring_struct;
  2962. bnxt_free_ring(bp, &ring->ring_mem);
  2963. for (j = 0; j < 2; j++) {
  2964. struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
  2965. if (cpr2) {
  2966. ring = &cpr2->cp_ring_struct;
  2967. bnxt_free_ring(bp, &ring->ring_mem);
  2968. bnxt_free_cp_arrays(cpr2);
  2969. kfree(cpr2);
  2970. cpr->cp_ring_arr[j] = NULL;
  2971. }
  2972. }
  2973. }
  2974. }
  2975. static struct bnxt_cp_ring_info *bnxt_alloc_cp_sub_ring(struct bnxt *bp)
  2976. {
  2977. struct bnxt_ring_mem_info *rmem;
  2978. struct bnxt_ring_struct *ring;
  2979. struct bnxt_cp_ring_info *cpr;
  2980. int rc;
  2981. cpr = kzalloc(sizeof(*cpr), GFP_KERNEL);
  2982. if (!cpr)
  2983. return NULL;
  2984. rc = bnxt_alloc_cp_arrays(cpr, bp->cp_nr_pages);
  2985. if (rc) {
  2986. bnxt_free_cp_arrays(cpr);
  2987. kfree(cpr);
  2988. return NULL;
  2989. }
  2990. ring = &cpr->cp_ring_struct;
  2991. rmem = &ring->ring_mem;
  2992. rmem->nr_pages = bp->cp_nr_pages;
  2993. rmem->page_size = HW_CMPD_RING_SIZE;
  2994. rmem->pg_arr = (void **)cpr->cp_desc_ring;
  2995. rmem->dma_arr = cpr->cp_desc_mapping;
  2996. rmem->flags = BNXT_RMEM_RING_PTE_FLAG;
  2997. rc = bnxt_alloc_ring(bp, rmem);
  2998. if (rc) {
  2999. bnxt_free_ring(bp, rmem);
  3000. bnxt_free_cp_arrays(cpr);
  3001. kfree(cpr);
  3002. cpr = NULL;
  3003. }
  3004. return cpr;
  3005. }
  3006. static int bnxt_alloc_cp_rings(struct bnxt *bp)
  3007. {
  3008. bool sh = !!(bp->flags & BNXT_FLAG_SHARED_RINGS);
  3009. int i, rc, ulp_base_vec, ulp_msix;
  3010. ulp_msix = bnxt_get_ulp_msix_num(bp);
  3011. ulp_base_vec = bnxt_get_ulp_msix_base(bp);
  3012. for (i = 0; i < bp->cp_nr_rings; i++) {
  3013. struct bnxt_napi *bnapi = bp->bnapi[i];
  3014. struct bnxt_cp_ring_info *cpr;
  3015. struct bnxt_ring_struct *ring;
  3016. if (!bnapi)
  3017. continue;
  3018. cpr = &bnapi->cp_ring;
  3019. cpr->bnapi = bnapi;
  3020. ring = &cpr->cp_ring_struct;
  3021. rc = bnxt_alloc_ring(bp, &ring->ring_mem);
  3022. if (rc)
  3023. return rc;
  3024. if (ulp_msix && i >= ulp_base_vec)
  3025. ring->map_idx = i + ulp_msix;
  3026. else
  3027. ring->map_idx = i;
  3028. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  3029. continue;
  3030. if (i < bp->rx_nr_rings) {
  3031. struct bnxt_cp_ring_info *cpr2 =
  3032. bnxt_alloc_cp_sub_ring(bp);
  3033. cpr->cp_ring_arr[BNXT_RX_HDL] = cpr2;
  3034. if (!cpr2)
  3035. return -ENOMEM;
  3036. cpr2->bnapi = bnapi;
  3037. }
  3038. if ((sh && i < bp->tx_nr_rings) ||
  3039. (!sh && i >= bp->rx_nr_rings)) {
  3040. struct bnxt_cp_ring_info *cpr2 =
  3041. bnxt_alloc_cp_sub_ring(bp);
  3042. cpr->cp_ring_arr[BNXT_TX_HDL] = cpr2;
  3043. if (!cpr2)
  3044. return -ENOMEM;
  3045. cpr2->bnapi = bnapi;
  3046. }
  3047. }
  3048. return 0;
  3049. }
  3050. static void bnxt_init_ring_struct(struct bnxt *bp)
  3051. {
  3052. int i;
  3053. for (i = 0; i < bp->cp_nr_rings; i++) {
  3054. struct bnxt_napi *bnapi = bp->bnapi[i];
  3055. struct bnxt_ring_mem_info *rmem;
  3056. struct bnxt_cp_ring_info *cpr;
  3057. struct bnxt_rx_ring_info *rxr;
  3058. struct bnxt_tx_ring_info *txr;
  3059. struct bnxt_ring_struct *ring;
  3060. if (!bnapi)
  3061. continue;
  3062. cpr = &bnapi->cp_ring;
  3063. ring = &cpr->cp_ring_struct;
  3064. rmem = &ring->ring_mem;
  3065. rmem->nr_pages = bp->cp_nr_pages;
  3066. rmem->page_size = HW_CMPD_RING_SIZE;
  3067. rmem->pg_arr = (void **)cpr->cp_desc_ring;
  3068. rmem->dma_arr = cpr->cp_desc_mapping;
  3069. rmem->vmem_size = 0;
  3070. rxr = bnapi->rx_ring;
  3071. if (!rxr)
  3072. goto skip_rx;
  3073. ring = &rxr->rx_ring_struct;
  3074. rmem = &ring->ring_mem;
  3075. rmem->nr_pages = bp->rx_nr_pages;
  3076. rmem->page_size = HW_RXBD_RING_SIZE;
  3077. rmem->pg_arr = (void **)rxr->rx_desc_ring;
  3078. rmem->dma_arr = rxr->rx_desc_mapping;
  3079. rmem->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
  3080. rmem->vmem = (void **)&rxr->rx_buf_ring;
  3081. ring = &rxr->rx_agg_ring_struct;
  3082. rmem = &ring->ring_mem;
  3083. rmem->nr_pages = bp->rx_agg_nr_pages;
  3084. rmem->page_size = HW_RXBD_RING_SIZE;
  3085. rmem->pg_arr = (void **)rxr->rx_agg_desc_ring;
  3086. rmem->dma_arr = rxr->rx_agg_desc_mapping;
  3087. rmem->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
  3088. rmem->vmem = (void **)&rxr->rx_agg_ring;
  3089. skip_rx:
  3090. txr = bnapi->tx_ring;
  3091. if (!txr)
  3092. continue;
  3093. ring = &txr->tx_ring_struct;
  3094. rmem = &ring->ring_mem;
  3095. rmem->nr_pages = bp->tx_nr_pages;
  3096. rmem->page_size = HW_RXBD_RING_SIZE;
  3097. rmem->pg_arr = (void **)txr->tx_desc_ring;
  3098. rmem->dma_arr = txr->tx_desc_mapping;
  3099. rmem->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
  3100. rmem->vmem = (void **)&txr->tx_buf_ring;
  3101. }
  3102. }
  3103. static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
  3104. {
  3105. int i;
  3106. u32 prod;
  3107. struct rx_bd **rx_buf_ring;
  3108. rx_buf_ring = (struct rx_bd **)ring->ring_mem.pg_arr;
  3109. for (i = 0, prod = 0; i < ring->ring_mem.nr_pages; i++) {
  3110. int j;
  3111. struct rx_bd *rxbd;
  3112. rxbd = rx_buf_ring[i];
  3113. if (!rxbd)
  3114. continue;
  3115. for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
  3116. rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
  3117. rxbd->rx_bd_opaque = prod;
  3118. }
  3119. }
  3120. }
  3121. static int bnxt_alloc_one_rx_ring(struct bnxt *bp, int ring_nr)
  3122. {
  3123. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
  3124. struct net_device *dev = bp->dev;
  3125. u32 prod;
  3126. int i;
  3127. prod = rxr->rx_prod;
  3128. for (i = 0; i < bp->rx_ring_size; i++) {
  3129. if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL)) {
  3130. netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
  3131. ring_nr, i, bp->rx_ring_size);
  3132. break;
  3133. }
  3134. prod = NEXT_RX(prod);
  3135. }
  3136. rxr->rx_prod = prod;
  3137. if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
  3138. return 0;
  3139. prod = rxr->rx_agg_prod;
  3140. for (i = 0; i < bp->rx_agg_ring_size; i++) {
  3141. if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL)) {
  3142. netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
  3143. ring_nr, i, bp->rx_ring_size);
  3144. break;
  3145. }
  3146. prod = NEXT_RX_AGG(prod);
  3147. }
  3148. rxr->rx_agg_prod = prod;
  3149. if (rxr->rx_tpa) {
  3150. dma_addr_t mapping;
  3151. u8 *data;
  3152. for (i = 0; i < bp->max_tpa; i++) {
  3153. data = __bnxt_alloc_rx_frag(bp, &mapping, GFP_KERNEL);
  3154. if (!data)
  3155. return -ENOMEM;
  3156. rxr->rx_tpa[i].data = data;
  3157. rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
  3158. rxr->rx_tpa[i].mapping = mapping;
  3159. }
  3160. }
  3161. return 0;
  3162. }
  3163. static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
  3164. {
  3165. struct bnxt_rx_ring_info *rxr;
  3166. struct bnxt_ring_struct *ring;
  3167. u32 type;
  3168. type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
  3169. RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
  3170. if (NET_IP_ALIGN == 2)
  3171. type |= RX_BD_FLAGS_SOP;
  3172. rxr = &bp->rx_ring[ring_nr];
  3173. ring = &rxr->rx_ring_struct;
  3174. bnxt_init_rxbd_pages(ring, type);
  3175. if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
  3176. bpf_prog_add(bp->xdp_prog, 1);
  3177. rxr->xdp_prog = bp->xdp_prog;
  3178. }
  3179. ring->fw_ring_id = INVALID_HW_RING_ID;
  3180. ring = &rxr->rx_agg_ring_struct;
  3181. ring->fw_ring_id = INVALID_HW_RING_ID;
  3182. if ((bp->flags & BNXT_FLAG_AGG_RINGS)) {
  3183. type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
  3184. RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
  3185. bnxt_init_rxbd_pages(ring, type);
  3186. }
  3187. return bnxt_alloc_one_rx_ring(bp, ring_nr);
  3188. }
  3189. static void bnxt_init_cp_rings(struct bnxt *bp)
  3190. {
  3191. int i, j;
  3192. for (i = 0; i < bp->cp_nr_rings; i++) {
  3193. struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
  3194. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  3195. ring->fw_ring_id = INVALID_HW_RING_ID;
  3196. cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
  3197. cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
  3198. for (j = 0; j < 2; j++) {
  3199. struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
  3200. if (!cpr2)
  3201. continue;
  3202. ring = &cpr2->cp_ring_struct;
  3203. ring->fw_ring_id = INVALID_HW_RING_ID;
  3204. cpr2->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks;
  3205. cpr2->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs;
  3206. }
  3207. }
  3208. }
  3209. static int bnxt_init_rx_rings(struct bnxt *bp)
  3210. {
  3211. int i, rc = 0;
  3212. if (BNXT_RX_PAGE_MODE(bp)) {
  3213. bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
  3214. bp->rx_dma_offset = XDP_PACKET_HEADROOM;
  3215. } else {
  3216. bp->rx_offset = BNXT_RX_OFFSET;
  3217. bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
  3218. }
  3219. for (i = 0; i < bp->rx_nr_rings; i++) {
  3220. rc = bnxt_init_one_rx_ring(bp, i);
  3221. if (rc)
  3222. break;
  3223. }
  3224. return rc;
  3225. }
  3226. static int bnxt_init_tx_rings(struct bnxt *bp)
  3227. {
  3228. u16 i;
  3229. bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
  3230. BNXT_MIN_TX_DESC_CNT);
  3231. for (i = 0; i < bp->tx_nr_rings; i++) {
  3232. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  3233. struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
  3234. ring->fw_ring_id = INVALID_HW_RING_ID;
  3235. }
  3236. return 0;
  3237. }
  3238. static void bnxt_free_ring_grps(struct bnxt *bp)
  3239. {
  3240. kfree(bp->grp_info);
  3241. bp->grp_info = NULL;
  3242. }
  3243. static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
  3244. {
  3245. int i;
  3246. if (irq_re_init) {
  3247. bp->grp_info = kcalloc(bp->cp_nr_rings,
  3248. sizeof(struct bnxt_ring_grp_info),
  3249. GFP_KERNEL);
  3250. if (!bp->grp_info)
  3251. return -ENOMEM;
  3252. }
  3253. for (i = 0; i < bp->cp_nr_rings; i++) {
  3254. if (irq_re_init)
  3255. bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
  3256. bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
  3257. bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
  3258. bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
  3259. bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
  3260. }
  3261. return 0;
  3262. }
  3263. static void bnxt_free_vnics(struct bnxt *bp)
  3264. {
  3265. kfree(bp->vnic_info);
  3266. bp->vnic_info = NULL;
  3267. bp->nr_vnics = 0;
  3268. }
  3269. static int bnxt_alloc_vnics(struct bnxt *bp)
  3270. {
  3271. int num_vnics = 1;
  3272. #ifdef CONFIG_RFS_ACCEL
  3273. if ((bp->flags & (BNXT_FLAG_RFS | BNXT_FLAG_CHIP_P5)) == BNXT_FLAG_RFS)
  3274. num_vnics += bp->rx_nr_rings;
  3275. #endif
  3276. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  3277. num_vnics++;
  3278. bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
  3279. GFP_KERNEL);
  3280. if (!bp->vnic_info)
  3281. return -ENOMEM;
  3282. bp->nr_vnics = num_vnics;
  3283. return 0;
  3284. }
  3285. static void bnxt_init_vnics(struct bnxt *bp)
  3286. {
  3287. int i;
  3288. for (i = 0; i < bp->nr_vnics; i++) {
  3289. struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
  3290. int j;
  3291. vnic->fw_vnic_id = INVALID_HW_RING_ID;
  3292. for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++)
  3293. vnic->fw_rss_cos_lb_ctx[j] = INVALID_HW_RING_ID;
  3294. vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
  3295. if (bp->vnic_info[i].rss_hash_key) {
  3296. if (i == 0)
  3297. get_random_bytes(vnic->rss_hash_key,
  3298. HW_HASH_KEY_SIZE);
  3299. else
  3300. memcpy(vnic->rss_hash_key,
  3301. bp->vnic_info[0].rss_hash_key,
  3302. HW_HASH_KEY_SIZE);
  3303. }
  3304. }
  3305. }
  3306. static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
  3307. {
  3308. int pages;
  3309. pages = ring_size / desc_per_pg;
  3310. if (!pages)
  3311. return 1;
  3312. pages++;
  3313. while (pages & (pages - 1))
  3314. pages++;
  3315. return pages;
  3316. }
  3317. void bnxt_set_tpa_flags(struct bnxt *bp)
  3318. {
  3319. bp->flags &= ~BNXT_FLAG_TPA;
  3320. if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
  3321. return;
  3322. if (bp->dev->features & NETIF_F_LRO)
  3323. bp->flags |= BNXT_FLAG_LRO;
  3324. else if (bp->dev->features & NETIF_F_GRO_HW)
  3325. bp->flags |= BNXT_FLAG_GRO;
  3326. }
  3327. /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
  3328. * be set on entry.
  3329. */
  3330. void bnxt_set_ring_params(struct bnxt *bp)
  3331. {
  3332. u32 ring_size, rx_size, rx_space, max_rx_cmpl;
  3333. u32 agg_factor = 0, agg_ring_size = 0;
  3334. /* 8 for CRC and VLAN */
  3335. rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
  3336. rx_space = rx_size + ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) +
  3337. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  3338. bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
  3339. ring_size = bp->rx_ring_size;
  3340. bp->rx_agg_ring_size = 0;
  3341. bp->rx_agg_nr_pages = 0;
  3342. if (bp->flags & BNXT_FLAG_TPA)
  3343. agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
  3344. bp->flags &= ~BNXT_FLAG_JUMBO;
  3345. if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
  3346. u32 jumbo_factor;
  3347. bp->flags |= BNXT_FLAG_JUMBO;
  3348. jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
  3349. if (jumbo_factor > agg_factor)
  3350. agg_factor = jumbo_factor;
  3351. }
  3352. if (agg_factor) {
  3353. if (ring_size > BNXT_MAX_RX_DESC_CNT_JUM_ENA) {
  3354. ring_size = BNXT_MAX_RX_DESC_CNT_JUM_ENA;
  3355. netdev_warn(bp->dev, "RX ring size reduced from %d to %d because the jumbo ring is now enabled\n",
  3356. bp->rx_ring_size, ring_size);
  3357. bp->rx_ring_size = ring_size;
  3358. }
  3359. agg_ring_size = ring_size * agg_factor;
  3360. bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
  3361. RX_DESC_CNT);
  3362. if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
  3363. u32 tmp = agg_ring_size;
  3364. bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
  3365. agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
  3366. netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
  3367. tmp, agg_ring_size);
  3368. }
  3369. bp->rx_agg_ring_size = agg_ring_size;
  3370. bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
  3371. if (BNXT_RX_PAGE_MODE(bp)) {
  3372. rx_space = PAGE_SIZE;
  3373. rx_size = PAGE_SIZE -
  3374. ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
  3375. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  3376. } else {
  3377. rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
  3378. rx_space = rx_size + NET_SKB_PAD +
  3379. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  3380. }
  3381. }
  3382. bp->rx_buf_use_size = rx_size;
  3383. bp->rx_buf_size = rx_space;
  3384. bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
  3385. bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
  3386. ring_size = bp->tx_ring_size;
  3387. bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
  3388. bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
  3389. max_rx_cmpl = bp->rx_ring_size;
  3390. /* MAX TPA needs to be added because TPA_START completions are
  3391. * immediately recycled, so the TPA completions are not bound by
  3392. * the RX ring size.
  3393. */
  3394. if (bp->flags & BNXT_FLAG_TPA)
  3395. max_rx_cmpl += bp->max_tpa;
  3396. /* RX and TPA completions are 32-byte, all others are 16-byte */
  3397. ring_size = max_rx_cmpl * 2 + agg_ring_size + bp->tx_ring_size;
  3398. bp->cp_ring_size = ring_size;
  3399. bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
  3400. if (bp->cp_nr_pages > MAX_CP_PAGES) {
  3401. bp->cp_nr_pages = MAX_CP_PAGES;
  3402. bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
  3403. netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
  3404. ring_size, bp->cp_ring_size);
  3405. }
  3406. bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
  3407. bp->cp_ring_mask = bp->cp_bit - 1;
  3408. }
  3409. /* Changing allocation mode of RX rings.
  3410. * TODO: Update when extending xdp_rxq_info to support allocation modes.
  3411. */
  3412. int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
  3413. {
  3414. struct net_device *dev = bp->dev;
  3415. if (page_mode) {
  3416. bp->flags &= ~BNXT_FLAG_AGG_RINGS;
  3417. bp->flags |= BNXT_FLAG_RX_PAGE_MODE;
  3418. if (bp->xdp_prog->aux->xdp_has_frags)
  3419. dev->max_mtu = min_t(u16, bp->max_mtu, BNXT_MAX_MTU);
  3420. else
  3421. dev->max_mtu =
  3422. min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU);
  3423. if (dev->mtu > BNXT_MAX_PAGE_MODE_MTU) {
  3424. bp->flags |= BNXT_FLAG_JUMBO;
  3425. bp->rx_skb_func = bnxt_rx_multi_page_skb;
  3426. } else {
  3427. bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
  3428. bp->rx_skb_func = bnxt_rx_page_skb;
  3429. }
  3430. bp->rx_dir = DMA_BIDIRECTIONAL;
  3431. /* Disable LRO or GRO_HW */
  3432. netdev_update_features(dev);
  3433. } else {
  3434. dev->max_mtu = bp->max_mtu;
  3435. bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
  3436. bp->rx_dir = DMA_FROM_DEVICE;
  3437. bp->rx_skb_func = bnxt_rx_skb;
  3438. }
  3439. return 0;
  3440. }
  3441. static void bnxt_free_vnic_attributes(struct bnxt *bp)
  3442. {
  3443. int i;
  3444. struct bnxt_vnic_info *vnic;
  3445. struct pci_dev *pdev = bp->pdev;
  3446. if (!bp->vnic_info)
  3447. return;
  3448. for (i = 0; i < bp->nr_vnics; i++) {
  3449. vnic = &bp->vnic_info[i];
  3450. kfree(vnic->fw_grp_ids);
  3451. vnic->fw_grp_ids = NULL;
  3452. kfree(vnic->uc_list);
  3453. vnic->uc_list = NULL;
  3454. if (vnic->mc_list) {
  3455. dma_free_coherent(&pdev->dev, vnic->mc_list_size,
  3456. vnic->mc_list, vnic->mc_list_mapping);
  3457. vnic->mc_list = NULL;
  3458. }
  3459. if (vnic->rss_table) {
  3460. dma_free_coherent(&pdev->dev, vnic->rss_table_size,
  3461. vnic->rss_table,
  3462. vnic->rss_table_dma_addr);
  3463. vnic->rss_table = NULL;
  3464. }
  3465. vnic->rss_hash_key = NULL;
  3466. vnic->flags = 0;
  3467. }
  3468. }
  3469. static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
  3470. {
  3471. int i, rc = 0, size;
  3472. struct bnxt_vnic_info *vnic;
  3473. struct pci_dev *pdev = bp->pdev;
  3474. int max_rings;
  3475. for (i = 0; i < bp->nr_vnics; i++) {
  3476. vnic = &bp->vnic_info[i];
  3477. if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
  3478. int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
  3479. if (mem_size > 0) {
  3480. vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
  3481. if (!vnic->uc_list) {
  3482. rc = -ENOMEM;
  3483. goto out;
  3484. }
  3485. }
  3486. }
  3487. if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
  3488. vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
  3489. vnic->mc_list =
  3490. dma_alloc_coherent(&pdev->dev,
  3491. vnic->mc_list_size,
  3492. &vnic->mc_list_mapping,
  3493. GFP_KERNEL);
  3494. if (!vnic->mc_list) {
  3495. rc = -ENOMEM;
  3496. goto out;
  3497. }
  3498. }
  3499. if (bp->flags & BNXT_FLAG_CHIP_P5)
  3500. goto vnic_skip_grps;
  3501. if (vnic->flags & BNXT_VNIC_RSS_FLAG)
  3502. max_rings = bp->rx_nr_rings;
  3503. else
  3504. max_rings = 1;
  3505. vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
  3506. if (!vnic->fw_grp_ids) {
  3507. rc = -ENOMEM;
  3508. goto out;
  3509. }
  3510. vnic_skip_grps:
  3511. if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
  3512. !(vnic->flags & BNXT_VNIC_RSS_FLAG))
  3513. continue;
  3514. /* Allocate rss table and hash key */
  3515. size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
  3516. if (bp->flags & BNXT_FLAG_CHIP_P5)
  3517. size = L1_CACHE_ALIGN(BNXT_MAX_RSS_TABLE_SIZE_P5);
  3518. vnic->rss_table_size = size + HW_HASH_KEY_SIZE;
  3519. vnic->rss_table = dma_alloc_coherent(&pdev->dev,
  3520. vnic->rss_table_size,
  3521. &vnic->rss_table_dma_addr,
  3522. GFP_KERNEL);
  3523. if (!vnic->rss_table) {
  3524. rc = -ENOMEM;
  3525. goto out;
  3526. }
  3527. vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
  3528. vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
  3529. }
  3530. return 0;
  3531. out:
  3532. return rc;
  3533. }
  3534. static void bnxt_free_hwrm_resources(struct bnxt *bp)
  3535. {
  3536. struct bnxt_hwrm_wait_token *token;
  3537. dma_pool_destroy(bp->hwrm_dma_pool);
  3538. bp->hwrm_dma_pool = NULL;
  3539. rcu_read_lock();
  3540. hlist_for_each_entry_rcu(token, &bp->hwrm_pending_list, node)
  3541. WRITE_ONCE(token->state, BNXT_HWRM_CANCELLED);
  3542. rcu_read_unlock();
  3543. }
  3544. static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
  3545. {
  3546. bp->hwrm_dma_pool = dma_pool_create("bnxt_hwrm", &bp->pdev->dev,
  3547. BNXT_HWRM_DMA_SIZE,
  3548. BNXT_HWRM_DMA_ALIGN, 0);
  3549. if (!bp->hwrm_dma_pool)
  3550. return -ENOMEM;
  3551. INIT_HLIST_HEAD(&bp->hwrm_pending_list);
  3552. return 0;
  3553. }
  3554. static void bnxt_free_stats_mem(struct bnxt *bp, struct bnxt_stats_mem *stats)
  3555. {
  3556. kfree(stats->hw_masks);
  3557. stats->hw_masks = NULL;
  3558. kfree(stats->sw_stats);
  3559. stats->sw_stats = NULL;
  3560. if (stats->hw_stats) {
  3561. dma_free_coherent(&bp->pdev->dev, stats->len, stats->hw_stats,
  3562. stats->hw_stats_map);
  3563. stats->hw_stats = NULL;
  3564. }
  3565. }
  3566. static int bnxt_alloc_stats_mem(struct bnxt *bp, struct bnxt_stats_mem *stats,
  3567. bool alloc_masks)
  3568. {
  3569. stats->hw_stats = dma_alloc_coherent(&bp->pdev->dev, stats->len,
  3570. &stats->hw_stats_map, GFP_KERNEL);
  3571. if (!stats->hw_stats)
  3572. return -ENOMEM;
  3573. stats->sw_stats = kzalloc(stats->len, GFP_KERNEL);
  3574. if (!stats->sw_stats)
  3575. goto stats_mem_err;
  3576. if (alloc_masks) {
  3577. stats->hw_masks = kzalloc(stats->len, GFP_KERNEL);
  3578. if (!stats->hw_masks)
  3579. goto stats_mem_err;
  3580. }
  3581. return 0;
  3582. stats_mem_err:
  3583. bnxt_free_stats_mem(bp, stats);
  3584. return -ENOMEM;
  3585. }
  3586. static void bnxt_fill_masks(u64 *mask_arr, u64 mask, int count)
  3587. {
  3588. int i;
  3589. for (i = 0; i < count; i++)
  3590. mask_arr[i] = mask;
  3591. }
  3592. static void bnxt_copy_hw_masks(u64 *mask_arr, __le64 *hw_mask_arr, int count)
  3593. {
  3594. int i;
  3595. for (i = 0; i < count; i++)
  3596. mask_arr[i] = le64_to_cpu(hw_mask_arr[i]);
  3597. }
  3598. static int bnxt_hwrm_func_qstat_ext(struct bnxt *bp,
  3599. struct bnxt_stats_mem *stats)
  3600. {
  3601. struct hwrm_func_qstats_ext_output *resp;
  3602. struct hwrm_func_qstats_ext_input *req;
  3603. __le64 *hw_masks;
  3604. int rc;
  3605. if (!(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED) ||
  3606. !(bp->flags & BNXT_FLAG_CHIP_P5))
  3607. return -EOPNOTSUPP;
  3608. rc = hwrm_req_init(bp, req, HWRM_FUNC_QSTATS_EXT);
  3609. if (rc)
  3610. return rc;
  3611. req->fid = cpu_to_le16(0xffff);
  3612. req->flags = FUNC_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK;
  3613. resp = hwrm_req_hold(bp, req);
  3614. rc = hwrm_req_send(bp, req);
  3615. if (!rc) {
  3616. hw_masks = &resp->rx_ucast_pkts;
  3617. bnxt_copy_hw_masks(stats->hw_masks, hw_masks, stats->len / 8);
  3618. }
  3619. hwrm_req_drop(bp, req);
  3620. return rc;
  3621. }
  3622. static int bnxt_hwrm_port_qstats(struct bnxt *bp, u8 flags);
  3623. static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp, u8 flags);
  3624. static void bnxt_init_stats(struct bnxt *bp)
  3625. {
  3626. struct bnxt_napi *bnapi = bp->bnapi[0];
  3627. struct bnxt_cp_ring_info *cpr;
  3628. struct bnxt_stats_mem *stats;
  3629. __le64 *rx_stats, *tx_stats;
  3630. int rc, rx_count, tx_count;
  3631. u64 *rx_masks, *tx_masks;
  3632. u64 mask;
  3633. u8 flags;
  3634. cpr = &bnapi->cp_ring;
  3635. stats = &cpr->stats;
  3636. rc = bnxt_hwrm_func_qstat_ext(bp, stats);
  3637. if (rc) {
  3638. if (bp->flags & BNXT_FLAG_CHIP_P5)
  3639. mask = (1ULL << 48) - 1;
  3640. else
  3641. mask = -1ULL;
  3642. bnxt_fill_masks(stats->hw_masks, mask, stats->len / 8);
  3643. }
  3644. if (bp->flags & BNXT_FLAG_PORT_STATS) {
  3645. stats = &bp->port_stats;
  3646. rx_stats = stats->hw_stats;
  3647. rx_masks = stats->hw_masks;
  3648. rx_count = sizeof(struct rx_port_stats) / 8;
  3649. tx_stats = rx_stats + BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
  3650. tx_masks = rx_masks + BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
  3651. tx_count = sizeof(struct tx_port_stats) / 8;
  3652. flags = PORT_QSTATS_REQ_FLAGS_COUNTER_MASK;
  3653. rc = bnxt_hwrm_port_qstats(bp, flags);
  3654. if (rc) {
  3655. mask = (1ULL << 40) - 1;
  3656. bnxt_fill_masks(rx_masks, mask, rx_count);
  3657. bnxt_fill_masks(tx_masks, mask, tx_count);
  3658. } else {
  3659. bnxt_copy_hw_masks(rx_masks, rx_stats, rx_count);
  3660. bnxt_copy_hw_masks(tx_masks, tx_stats, tx_count);
  3661. bnxt_hwrm_port_qstats(bp, 0);
  3662. }
  3663. }
  3664. if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
  3665. stats = &bp->rx_port_stats_ext;
  3666. rx_stats = stats->hw_stats;
  3667. rx_masks = stats->hw_masks;
  3668. rx_count = sizeof(struct rx_port_stats_ext) / 8;
  3669. stats = &bp->tx_port_stats_ext;
  3670. tx_stats = stats->hw_stats;
  3671. tx_masks = stats->hw_masks;
  3672. tx_count = sizeof(struct tx_port_stats_ext) / 8;
  3673. flags = PORT_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK;
  3674. rc = bnxt_hwrm_port_qstats_ext(bp, flags);
  3675. if (rc) {
  3676. mask = (1ULL << 40) - 1;
  3677. bnxt_fill_masks(rx_masks, mask, rx_count);
  3678. if (tx_stats)
  3679. bnxt_fill_masks(tx_masks, mask, tx_count);
  3680. } else {
  3681. bnxt_copy_hw_masks(rx_masks, rx_stats, rx_count);
  3682. if (tx_stats)
  3683. bnxt_copy_hw_masks(tx_masks, tx_stats,
  3684. tx_count);
  3685. bnxt_hwrm_port_qstats_ext(bp, 0);
  3686. }
  3687. }
  3688. }
  3689. static void bnxt_free_port_stats(struct bnxt *bp)
  3690. {
  3691. bp->flags &= ~BNXT_FLAG_PORT_STATS;
  3692. bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT;
  3693. bnxt_free_stats_mem(bp, &bp->port_stats);
  3694. bnxt_free_stats_mem(bp, &bp->rx_port_stats_ext);
  3695. bnxt_free_stats_mem(bp, &bp->tx_port_stats_ext);
  3696. }
  3697. static void bnxt_free_ring_stats(struct bnxt *bp)
  3698. {
  3699. int i;
  3700. if (!bp->bnapi)
  3701. return;
  3702. for (i = 0; i < bp->cp_nr_rings; i++) {
  3703. struct bnxt_napi *bnapi = bp->bnapi[i];
  3704. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3705. bnxt_free_stats_mem(bp, &cpr->stats);
  3706. }
  3707. }
  3708. static int bnxt_alloc_stats(struct bnxt *bp)
  3709. {
  3710. u32 size, i;
  3711. int rc;
  3712. size = bp->hw_ring_stats_size;
  3713. for (i = 0; i < bp->cp_nr_rings; i++) {
  3714. struct bnxt_napi *bnapi = bp->bnapi[i];
  3715. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3716. cpr->stats.len = size;
  3717. rc = bnxt_alloc_stats_mem(bp, &cpr->stats, !i);
  3718. if (rc)
  3719. return rc;
  3720. cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
  3721. }
  3722. if (BNXT_VF(bp) || bp->chip_num == CHIP_NUM_58700)
  3723. return 0;
  3724. if (bp->port_stats.hw_stats)
  3725. goto alloc_ext_stats;
  3726. bp->port_stats.len = BNXT_PORT_STATS_SIZE;
  3727. rc = bnxt_alloc_stats_mem(bp, &bp->port_stats, true);
  3728. if (rc)
  3729. return rc;
  3730. bp->flags |= BNXT_FLAG_PORT_STATS;
  3731. alloc_ext_stats:
  3732. /* Display extended statistics only if FW supports it */
  3733. if (bp->hwrm_spec_code < 0x10804 || bp->hwrm_spec_code == 0x10900)
  3734. if (!(bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED))
  3735. return 0;
  3736. if (bp->rx_port_stats_ext.hw_stats)
  3737. goto alloc_tx_ext_stats;
  3738. bp->rx_port_stats_ext.len = sizeof(struct rx_port_stats_ext);
  3739. rc = bnxt_alloc_stats_mem(bp, &bp->rx_port_stats_ext, true);
  3740. /* Extended stats are optional */
  3741. if (rc)
  3742. return 0;
  3743. alloc_tx_ext_stats:
  3744. if (bp->tx_port_stats_ext.hw_stats)
  3745. return 0;
  3746. if (bp->hwrm_spec_code >= 0x10902 ||
  3747. (bp->fw_cap & BNXT_FW_CAP_EXT_STATS_SUPPORTED)) {
  3748. bp->tx_port_stats_ext.len = sizeof(struct tx_port_stats_ext);
  3749. rc = bnxt_alloc_stats_mem(bp, &bp->tx_port_stats_ext, true);
  3750. /* Extended stats are optional */
  3751. if (rc)
  3752. return 0;
  3753. }
  3754. bp->flags |= BNXT_FLAG_PORT_STATS_EXT;
  3755. return 0;
  3756. }
  3757. static void bnxt_clear_ring_indices(struct bnxt *bp)
  3758. {
  3759. int i;
  3760. if (!bp->bnapi)
  3761. return;
  3762. for (i = 0; i < bp->cp_nr_rings; i++) {
  3763. struct bnxt_napi *bnapi = bp->bnapi[i];
  3764. struct bnxt_cp_ring_info *cpr;
  3765. struct bnxt_rx_ring_info *rxr;
  3766. struct bnxt_tx_ring_info *txr;
  3767. if (!bnapi)
  3768. continue;
  3769. cpr = &bnapi->cp_ring;
  3770. cpr->cp_raw_cons = 0;
  3771. txr = bnapi->tx_ring;
  3772. if (txr) {
  3773. txr->tx_prod = 0;
  3774. txr->tx_cons = 0;
  3775. }
  3776. rxr = bnapi->rx_ring;
  3777. if (rxr) {
  3778. rxr->rx_prod = 0;
  3779. rxr->rx_agg_prod = 0;
  3780. rxr->rx_sw_agg_prod = 0;
  3781. rxr->rx_next_cons = 0;
  3782. }
  3783. }
  3784. }
  3785. static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
  3786. {
  3787. #ifdef CONFIG_RFS_ACCEL
  3788. int i;
  3789. /* Under rtnl_lock and all our NAPIs have been disabled. It's
  3790. * safe to delete the hash table.
  3791. */
  3792. for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
  3793. struct hlist_head *head;
  3794. struct hlist_node *tmp;
  3795. struct bnxt_ntuple_filter *fltr;
  3796. head = &bp->ntp_fltr_hash_tbl[i];
  3797. hlist_for_each_entry_safe(fltr, tmp, head, hash) {
  3798. hlist_del(&fltr->hash);
  3799. kfree(fltr);
  3800. }
  3801. }
  3802. if (irq_reinit) {
  3803. bitmap_free(bp->ntp_fltr_bmap);
  3804. bp->ntp_fltr_bmap = NULL;
  3805. }
  3806. bp->ntp_fltr_count = 0;
  3807. #endif
  3808. }
  3809. static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
  3810. {
  3811. #ifdef CONFIG_RFS_ACCEL
  3812. int i, rc = 0;
  3813. if (!(bp->flags & BNXT_FLAG_RFS))
  3814. return 0;
  3815. for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
  3816. INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
  3817. bp->ntp_fltr_count = 0;
  3818. bp->ntp_fltr_bmap = bitmap_zalloc(BNXT_NTP_FLTR_MAX_FLTR, GFP_KERNEL);
  3819. if (!bp->ntp_fltr_bmap)
  3820. rc = -ENOMEM;
  3821. return rc;
  3822. #else
  3823. return 0;
  3824. #endif
  3825. }
  3826. static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
  3827. {
  3828. bnxt_free_vnic_attributes(bp);
  3829. bnxt_free_tx_rings(bp);
  3830. bnxt_free_rx_rings(bp);
  3831. bnxt_free_cp_rings(bp);
  3832. bnxt_free_all_cp_arrays(bp);
  3833. bnxt_free_ntp_fltrs(bp, irq_re_init);
  3834. if (irq_re_init) {
  3835. bnxt_free_ring_stats(bp);
  3836. if (!(bp->phy_flags & BNXT_PHY_FL_PORT_STATS_NO_RESET) ||
  3837. test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
  3838. bnxt_free_port_stats(bp);
  3839. bnxt_free_ring_grps(bp);
  3840. bnxt_free_vnics(bp);
  3841. kfree(bp->tx_ring_map);
  3842. bp->tx_ring_map = NULL;
  3843. kfree(bp->tx_ring);
  3844. bp->tx_ring = NULL;
  3845. kfree(bp->rx_ring);
  3846. bp->rx_ring = NULL;
  3847. kfree(bp->bnapi);
  3848. bp->bnapi = NULL;
  3849. } else {
  3850. bnxt_clear_ring_indices(bp);
  3851. }
  3852. }
  3853. static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
  3854. {
  3855. int i, j, rc, size, arr_size;
  3856. void *bnapi;
  3857. if (irq_re_init) {
  3858. /* Allocate bnapi mem pointer array and mem block for
  3859. * all queues
  3860. */
  3861. arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
  3862. bp->cp_nr_rings);
  3863. size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
  3864. bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
  3865. if (!bnapi)
  3866. return -ENOMEM;
  3867. bp->bnapi = bnapi;
  3868. bnapi += arr_size;
  3869. for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
  3870. bp->bnapi[i] = bnapi;
  3871. bp->bnapi[i]->index = i;
  3872. bp->bnapi[i]->bp = bp;
  3873. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  3874. struct bnxt_cp_ring_info *cpr =
  3875. &bp->bnapi[i]->cp_ring;
  3876. cpr->cp_ring_struct.ring_mem.flags =
  3877. BNXT_RMEM_RING_PTE_FLAG;
  3878. }
  3879. }
  3880. bp->rx_ring = kcalloc(bp->rx_nr_rings,
  3881. sizeof(struct bnxt_rx_ring_info),
  3882. GFP_KERNEL);
  3883. if (!bp->rx_ring)
  3884. return -ENOMEM;
  3885. for (i = 0; i < bp->rx_nr_rings; i++) {
  3886. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  3887. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  3888. rxr->rx_ring_struct.ring_mem.flags =
  3889. BNXT_RMEM_RING_PTE_FLAG;
  3890. rxr->rx_agg_ring_struct.ring_mem.flags =
  3891. BNXT_RMEM_RING_PTE_FLAG;
  3892. }
  3893. rxr->bnapi = bp->bnapi[i];
  3894. bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
  3895. }
  3896. bp->tx_ring = kcalloc(bp->tx_nr_rings,
  3897. sizeof(struct bnxt_tx_ring_info),
  3898. GFP_KERNEL);
  3899. if (!bp->tx_ring)
  3900. return -ENOMEM;
  3901. bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
  3902. GFP_KERNEL);
  3903. if (!bp->tx_ring_map)
  3904. return -ENOMEM;
  3905. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  3906. j = 0;
  3907. else
  3908. j = bp->rx_nr_rings;
  3909. for (i = 0; i < bp->tx_nr_rings; i++, j++) {
  3910. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  3911. if (bp->flags & BNXT_FLAG_CHIP_P5)
  3912. txr->tx_ring_struct.ring_mem.flags =
  3913. BNXT_RMEM_RING_PTE_FLAG;
  3914. txr->bnapi = bp->bnapi[j];
  3915. bp->bnapi[j]->tx_ring = txr;
  3916. bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
  3917. if (i >= bp->tx_nr_rings_xdp) {
  3918. txr->txq_index = i - bp->tx_nr_rings_xdp;
  3919. bp->bnapi[j]->tx_int = bnxt_tx_int;
  3920. } else {
  3921. bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
  3922. bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
  3923. }
  3924. }
  3925. rc = bnxt_alloc_stats(bp);
  3926. if (rc)
  3927. goto alloc_mem_err;
  3928. bnxt_init_stats(bp);
  3929. rc = bnxt_alloc_ntp_fltrs(bp);
  3930. if (rc)
  3931. goto alloc_mem_err;
  3932. rc = bnxt_alloc_vnics(bp);
  3933. if (rc)
  3934. goto alloc_mem_err;
  3935. }
  3936. rc = bnxt_alloc_all_cp_arrays(bp);
  3937. if (rc)
  3938. goto alloc_mem_err;
  3939. bnxt_init_ring_struct(bp);
  3940. rc = bnxt_alloc_rx_rings(bp);
  3941. if (rc)
  3942. goto alloc_mem_err;
  3943. rc = bnxt_alloc_tx_rings(bp);
  3944. if (rc)
  3945. goto alloc_mem_err;
  3946. rc = bnxt_alloc_cp_rings(bp);
  3947. if (rc)
  3948. goto alloc_mem_err;
  3949. bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
  3950. BNXT_VNIC_UCAST_FLAG;
  3951. rc = bnxt_alloc_vnic_attributes(bp);
  3952. if (rc)
  3953. goto alloc_mem_err;
  3954. return 0;
  3955. alloc_mem_err:
  3956. bnxt_free_mem(bp, true);
  3957. return rc;
  3958. }
  3959. static void bnxt_disable_int(struct bnxt *bp)
  3960. {
  3961. int i;
  3962. if (!bp->bnapi)
  3963. return;
  3964. for (i = 0; i < bp->cp_nr_rings; i++) {
  3965. struct bnxt_napi *bnapi = bp->bnapi[i];
  3966. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3967. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  3968. if (ring->fw_ring_id != INVALID_HW_RING_ID)
  3969. bnxt_db_nq(bp, &cpr->cp_db, cpr->cp_raw_cons);
  3970. }
  3971. }
  3972. static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n)
  3973. {
  3974. struct bnxt_napi *bnapi = bp->bnapi[n];
  3975. struct bnxt_cp_ring_info *cpr;
  3976. cpr = &bnapi->cp_ring;
  3977. return cpr->cp_ring_struct.map_idx;
  3978. }
  3979. static void bnxt_disable_int_sync(struct bnxt *bp)
  3980. {
  3981. int i;
  3982. if (!bp->irq_tbl)
  3983. return;
  3984. atomic_inc(&bp->intr_sem);
  3985. bnxt_disable_int(bp);
  3986. for (i = 0; i < bp->cp_nr_rings; i++) {
  3987. int map_idx = bnxt_cp_num_to_irq_num(bp, i);
  3988. synchronize_irq(bp->irq_tbl[map_idx].vector);
  3989. }
  3990. }
  3991. static void bnxt_enable_int(struct bnxt *bp)
  3992. {
  3993. int i;
  3994. atomic_set(&bp->intr_sem, 0);
  3995. for (i = 0; i < bp->cp_nr_rings; i++) {
  3996. struct bnxt_napi *bnapi = bp->bnapi[i];
  3997. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3998. bnxt_db_nq_arm(bp, &cpr->cp_db, cpr->cp_raw_cons);
  3999. }
  4000. }
  4001. int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp, unsigned long *bmap, int bmap_size,
  4002. bool async_only)
  4003. {
  4004. DECLARE_BITMAP(async_events_bmap, 256);
  4005. u32 *events = (u32 *)async_events_bmap;
  4006. struct hwrm_func_drv_rgtr_output *resp;
  4007. struct hwrm_func_drv_rgtr_input *req;
  4008. u32 flags;
  4009. int rc, i;
  4010. rc = hwrm_req_init(bp, req, HWRM_FUNC_DRV_RGTR);
  4011. if (rc)
  4012. return rc;
  4013. req->enables = cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
  4014. FUNC_DRV_RGTR_REQ_ENABLES_VER |
  4015. FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
  4016. req->os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
  4017. flags = FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE;
  4018. if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
  4019. flags |= FUNC_DRV_RGTR_REQ_FLAGS_HOT_RESET_SUPPORT;
  4020. if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
  4021. flags |= FUNC_DRV_RGTR_REQ_FLAGS_ERROR_RECOVERY_SUPPORT |
  4022. FUNC_DRV_RGTR_REQ_FLAGS_MASTER_SUPPORT;
  4023. req->flags = cpu_to_le32(flags);
  4024. req->ver_maj_8b = DRV_VER_MAJ;
  4025. req->ver_min_8b = DRV_VER_MIN;
  4026. req->ver_upd_8b = DRV_VER_UPD;
  4027. req->ver_maj = cpu_to_le16(DRV_VER_MAJ);
  4028. req->ver_min = cpu_to_le16(DRV_VER_MIN);
  4029. req->ver_upd = cpu_to_le16(DRV_VER_UPD);
  4030. if (BNXT_PF(bp)) {
  4031. u32 data[8];
  4032. int i;
  4033. memset(data, 0, sizeof(data));
  4034. for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) {
  4035. u16 cmd = bnxt_vf_req_snif[i];
  4036. unsigned int bit, idx;
  4037. idx = cmd / 32;
  4038. bit = cmd % 32;
  4039. data[idx] |= 1 << bit;
  4040. }
  4041. for (i = 0; i < 8; i++)
  4042. req->vf_req_fwd[i] = cpu_to_le32(data[i]);
  4043. req->enables |=
  4044. cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
  4045. }
  4046. if (bp->fw_cap & BNXT_FW_CAP_OVS_64BIT_HANDLE)
  4047. req->flags |= cpu_to_le32(
  4048. FUNC_DRV_RGTR_REQ_FLAGS_FLOW_HANDLE_64BIT_MODE);
  4049. memset(async_events_bmap, 0, sizeof(async_events_bmap));
  4050. for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) {
  4051. u16 event_id = bnxt_async_events_arr[i];
  4052. if (event_id == ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY &&
  4053. !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
  4054. continue;
  4055. if (event_id == ASYNC_EVENT_CMPL_EVENT_ID_PHC_UPDATE &&
  4056. !bp->ptp_cfg)
  4057. continue;
  4058. __set_bit(bnxt_async_events_arr[i], async_events_bmap);
  4059. }
  4060. if (bmap && bmap_size) {
  4061. for (i = 0; i < bmap_size; i++) {
  4062. if (test_bit(i, bmap))
  4063. __set_bit(i, async_events_bmap);
  4064. }
  4065. }
  4066. for (i = 0; i < 8; i++)
  4067. req->async_event_fwd[i] |= cpu_to_le32(events[i]);
  4068. if (async_only)
  4069. req->enables =
  4070. cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
  4071. resp = hwrm_req_hold(bp, req);
  4072. rc = hwrm_req_send(bp, req);
  4073. if (!rc) {
  4074. set_bit(BNXT_STATE_DRV_REGISTERED, &bp->state);
  4075. if (resp->flags &
  4076. cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED))
  4077. bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
  4078. }
  4079. hwrm_req_drop(bp, req);
  4080. return rc;
  4081. }
  4082. int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
  4083. {
  4084. struct hwrm_func_drv_unrgtr_input *req;
  4085. int rc;
  4086. if (!test_and_clear_bit(BNXT_STATE_DRV_REGISTERED, &bp->state))
  4087. return 0;
  4088. rc = hwrm_req_init(bp, req, HWRM_FUNC_DRV_UNRGTR);
  4089. if (rc)
  4090. return rc;
  4091. return hwrm_req_send(bp, req);
  4092. }
  4093. static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
  4094. {
  4095. struct hwrm_tunnel_dst_port_free_input *req;
  4096. int rc;
  4097. if (tunnel_type == TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN &&
  4098. bp->vxlan_fw_dst_port_id == INVALID_HW_RING_ID)
  4099. return 0;
  4100. if (tunnel_type == TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE &&
  4101. bp->nge_fw_dst_port_id == INVALID_HW_RING_ID)
  4102. return 0;
  4103. rc = hwrm_req_init(bp, req, HWRM_TUNNEL_DST_PORT_FREE);
  4104. if (rc)
  4105. return rc;
  4106. req->tunnel_type = tunnel_type;
  4107. switch (tunnel_type) {
  4108. case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
  4109. req->tunnel_dst_port_id = cpu_to_le16(bp->vxlan_fw_dst_port_id);
  4110. bp->vxlan_port = 0;
  4111. bp->vxlan_fw_dst_port_id = INVALID_HW_RING_ID;
  4112. break;
  4113. case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
  4114. req->tunnel_dst_port_id = cpu_to_le16(bp->nge_fw_dst_port_id);
  4115. bp->nge_port = 0;
  4116. bp->nge_fw_dst_port_id = INVALID_HW_RING_ID;
  4117. break;
  4118. default:
  4119. break;
  4120. }
  4121. rc = hwrm_req_send(bp, req);
  4122. if (rc)
  4123. netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
  4124. rc);
  4125. return rc;
  4126. }
  4127. static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
  4128. u8 tunnel_type)
  4129. {
  4130. struct hwrm_tunnel_dst_port_alloc_output *resp;
  4131. struct hwrm_tunnel_dst_port_alloc_input *req;
  4132. int rc;
  4133. rc = hwrm_req_init(bp, req, HWRM_TUNNEL_DST_PORT_ALLOC);
  4134. if (rc)
  4135. return rc;
  4136. req->tunnel_type = tunnel_type;
  4137. req->tunnel_dst_port_val = port;
  4138. resp = hwrm_req_hold(bp, req);
  4139. rc = hwrm_req_send(bp, req);
  4140. if (rc) {
  4141. netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
  4142. rc);
  4143. goto err_out;
  4144. }
  4145. switch (tunnel_type) {
  4146. case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
  4147. bp->vxlan_port = port;
  4148. bp->vxlan_fw_dst_port_id =
  4149. le16_to_cpu(resp->tunnel_dst_port_id);
  4150. break;
  4151. case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
  4152. bp->nge_port = port;
  4153. bp->nge_fw_dst_port_id = le16_to_cpu(resp->tunnel_dst_port_id);
  4154. break;
  4155. default:
  4156. break;
  4157. }
  4158. err_out:
  4159. hwrm_req_drop(bp, req);
  4160. return rc;
  4161. }
  4162. static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
  4163. {
  4164. struct hwrm_cfa_l2_set_rx_mask_input *req;
  4165. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4166. int rc;
  4167. rc = hwrm_req_init(bp, req, HWRM_CFA_L2_SET_RX_MASK);
  4168. if (rc)
  4169. return rc;
  4170. req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
  4171. if (vnic->rx_mask & CFA_L2_SET_RX_MASK_REQ_MASK_MCAST) {
  4172. req->num_mc_entries = cpu_to_le32(vnic->mc_list_count);
  4173. req->mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
  4174. }
  4175. req->mask = cpu_to_le32(vnic->rx_mask);
  4176. return hwrm_req_send_silent(bp, req);
  4177. }
  4178. #ifdef CONFIG_RFS_ACCEL
  4179. static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
  4180. struct bnxt_ntuple_filter *fltr)
  4181. {
  4182. struct hwrm_cfa_ntuple_filter_free_input *req;
  4183. int rc;
  4184. rc = hwrm_req_init(bp, req, HWRM_CFA_NTUPLE_FILTER_FREE);
  4185. if (rc)
  4186. return rc;
  4187. req->ntuple_filter_id = fltr->filter_id;
  4188. return hwrm_req_send(bp, req);
  4189. }
  4190. #define BNXT_NTP_FLTR_FLAGS \
  4191. (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
  4192. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
  4193. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
  4194. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
  4195. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
  4196. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
  4197. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
  4198. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
  4199. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
  4200. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
  4201. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
  4202. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
  4203. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
  4204. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
  4205. #define BNXT_NTP_TUNNEL_FLTR_FLAG \
  4206. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
  4207. static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
  4208. struct bnxt_ntuple_filter *fltr)
  4209. {
  4210. struct hwrm_cfa_ntuple_filter_alloc_output *resp;
  4211. struct hwrm_cfa_ntuple_filter_alloc_input *req;
  4212. struct flow_keys *keys = &fltr->fkeys;
  4213. struct bnxt_vnic_info *vnic;
  4214. u32 flags = 0;
  4215. int rc;
  4216. rc = hwrm_req_init(bp, req, HWRM_CFA_NTUPLE_FILTER_ALLOC);
  4217. if (rc)
  4218. return rc;
  4219. req->l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
  4220. if (bp->fw_cap & BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2) {
  4221. flags = CFA_NTUPLE_FILTER_ALLOC_REQ_FLAGS_DEST_RFS_RING_IDX;
  4222. req->dst_id = cpu_to_le16(fltr->rxq);
  4223. } else {
  4224. vnic = &bp->vnic_info[fltr->rxq + 1];
  4225. req->dst_id = cpu_to_le16(vnic->fw_vnic_id);
  4226. }
  4227. req->flags = cpu_to_le32(flags);
  4228. req->enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
  4229. req->ethertype = htons(ETH_P_IP);
  4230. memcpy(req->src_macaddr, fltr->src_mac_addr, ETH_ALEN);
  4231. req->ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
  4232. req->ip_protocol = keys->basic.ip_proto;
  4233. if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
  4234. int i;
  4235. req->ethertype = htons(ETH_P_IPV6);
  4236. req->ip_addr_type =
  4237. CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
  4238. *(struct in6_addr *)&req->src_ipaddr[0] =
  4239. keys->addrs.v6addrs.src;
  4240. *(struct in6_addr *)&req->dst_ipaddr[0] =
  4241. keys->addrs.v6addrs.dst;
  4242. for (i = 0; i < 4; i++) {
  4243. req->src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
  4244. req->dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
  4245. }
  4246. } else {
  4247. req->src_ipaddr[0] = keys->addrs.v4addrs.src;
  4248. req->src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
  4249. req->dst_ipaddr[0] = keys->addrs.v4addrs.dst;
  4250. req->dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
  4251. }
  4252. if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
  4253. req->enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
  4254. req->tunnel_type =
  4255. CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
  4256. }
  4257. req->src_port = keys->ports.src;
  4258. req->src_port_mask = cpu_to_be16(0xffff);
  4259. req->dst_port = keys->ports.dst;
  4260. req->dst_port_mask = cpu_to_be16(0xffff);
  4261. resp = hwrm_req_hold(bp, req);
  4262. rc = hwrm_req_send(bp, req);
  4263. if (!rc)
  4264. fltr->filter_id = resp->ntuple_filter_id;
  4265. hwrm_req_drop(bp, req);
  4266. return rc;
  4267. }
  4268. #endif
  4269. static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
  4270. const u8 *mac_addr)
  4271. {
  4272. struct hwrm_cfa_l2_filter_alloc_output *resp;
  4273. struct hwrm_cfa_l2_filter_alloc_input *req;
  4274. int rc;
  4275. rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_ALLOC);
  4276. if (rc)
  4277. return rc;
  4278. req->flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
  4279. if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
  4280. req->flags |=
  4281. cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
  4282. req->dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
  4283. req->enables =
  4284. cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
  4285. CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
  4286. CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
  4287. memcpy(req->l2_addr, mac_addr, ETH_ALEN);
  4288. req->l2_addr_mask[0] = 0xff;
  4289. req->l2_addr_mask[1] = 0xff;
  4290. req->l2_addr_mask[2] = 0xff;
  4291. req->l2_addr_mask[3] = 0xff;
  4292. req->l2_addr_mask[4] = 0xff;
  4293. req->l2_addr_mask[5] = 0xff;
  4294. resp = hwrm_req_hold(bp, req);
  4295. rc = hwrm_req_send(bp, req);
  4296. if (!rc)
  4297. bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
  4298. resp->l2_filter_id;
  4299. hwrm_req_drop(bp, req);
  4300. return rc;
  4301. }
  4302. static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
  4303. {
  4304. struct hwrm_cfa_l2_filter_free_input *req;
  4305. u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
  4306. int rc;
  4307. /* Any associated ntuple filters will also be cleared by firmware. */
  4308. rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_FREE);
  4309. if (rc)
  4310. return rc;
  4311. hwrm_req_hold(bp, req);
  4312. for (i = 0; i < num_of_vnics; i++) {
  4313. struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
  4314. for (j = 0; j < vnic->uc_filter_count; j++) {
  4315. req->l2_filter_id = vnic->fw_l2_filter_id[j];
  4316. rc = hwrm_req_send(bp, req);
  4317. }
  4318. vnic->uc_filter_count = 0;
  4319. }
  4320. hwrm_req_drop(bp, req);
  4321. return rc;
  4322. }
  4323. static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
  4324. {
  4325. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4326. u16 max_aggs = VNIC_TPA_CFG_REQ_MAX_AGGS_MAX;
  4327. struct hwrm_vnic_tpa_cfg_input *req;
  4328. int rc;
  4329. if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
  4330. return 0;
  4331. rc = hwrm_req_init(bp, req, HWRM_VNIC_TPA_CFG);
  4332. if (rc)
  4333. return rc;
  4334. if (tpa_flags) {
  4335. u16 mss = bp->dev->mtu - 40;
  4336. u32 nsegs, n, segs = 0, flags;
  4337. flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
  4338. VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
  4339. VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
  4340. VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
  4341. VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
  4342. if (tpa_flags & BNXT_FLAG_GRO)
  4343. flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
  4344. req->flags = cpu_to_le32(flags);
  4345. req->enables =
  4346. cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
  4347. VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
  4348. VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
  4349. /* Number of segs are log2 units, and first packet is not
  4350. * included as part of this units.
  4351. */
  4352. if (mss <= BNXT_RX_PAGE_SIZE) {
  4353. n = BNXT_RX_PAGE_SIZE / mss;
  4354. nsegs = (MAX_SKB_FRAGS - 1) * n;
  4355. } else {
  4356. n = mss / BNXT_RX_PAGE_SIZE;
  4357. if (mss & (BNXT_RX_PAGE_SIZE - 1))
  4358. n++;
  4359. nsegs = (MAX_SKB_FRAGS - n) / n;
  4360. }
  4361. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4362. segs = MAX_TPA_SEGS_P5;
  4363. max_aggs = bp->max_tpa;
  4364. } else {
  4365. segs = ilog2(nsegs);
  4366. }
  4367. req->max_agg_segs = cpu_to_le16(segs);
  4368. req->max_aggs = cpu_to_le16(max_aggs);
  4369. req->min_agg_len = cpu_to_le32(512);
  4370. }
  4371. req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
  4372. return hwrm_req_send(bp, req);
  4373. }
  4374. static u16 bnxt_cp_ring_from_grp(struct bnxt *bp, struct bnxt_ring_struct *ring)
  4375. {
  4376. struct bnxt_ring_grp_info *grp_info;
  4377. grp_info = &bp->grp_info[ring->grp_idx];
  4378. return grp_info->cp_fw_ring_id;
  4379. }
  4380. static u16 bnxt_cp_ring_for_rx(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
  4381. {
  4382. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4383. struct bnxt_napi *bnapi = rxr->bnapi;
  4384. struct bnxt_cp_ring_info *cpr;
  4385. cpr = bnapi->cp_ring.cp_ring_arr[BNXT_RX_HDL];
  4386. return cpr->cp_ring_struct.fw_ring_id;
  4387. } else {
  4388. return bnxt_cp_ring_from_grp(bp, &rxr->rx_ring_struct);
  4389. }
  4390. }
  4391. static u16 bnxt_cp_ring_for_tx(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
  4392. {
  4393. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4394. struct bnxt_napi *bnapi = txr->bnapi;
  4395. struct bnxt_cp_ring_info *cpr;
  4396. cpr = bnapi->cp_ring.cp_ring_arr[BNXT_TX_HDL];
  4397. return cpr->cp_ring_struct.fw_ring_id;
  4398. } else {
  4399. return bnxt_cp_ring_from_grp(bp, &txr->tx_ring_struct);
  4400. }
  4401. }
  4402. static int bnxt_alloc_rss_indir_tbl(struct bnxt *bp)
  4403. {
  4404. int entries;
  4405. if (bp->flags & BNXT_FLAG_CHIP_P5)
  4406. entries = BNXT_MAX_RSS_TABLE_ENTRIES_P5;
  4407. else
  4408. entries = HW_HASH_INDEX_SIZE;
  4409. bp->rss_indir_tbl_entries = entries;
  4410. bp->rss_indir_tbl = kmalloc_array(entries, sizeof(*bp->rss_indir_tbl),
  4411. GFP_KERNEL);
  4412. if (!bp->rss_indir_tbl)
  4413. return -ENOMEM;
  4414. return 0;
  4415. }
  4416. static void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp)
  4417. {
  4418. u16 max_rings, max_entries, pad, i;
  4419. if (!bp->rx_nr_rings)
  4420. return;
  4421. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  4422. max_rings = bp->rx_nr_rings - 1;
  4423. else
  4424. max_rings = bp->rx_nr_rings;
  4425. max_entries = bnxt_get_rxfh_indir_size(bp->dev);
  4426. for (i = 0; i < max_entries; i++)
  4427. bp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, max_rings);
  4428. pad = bp->rss_indir_tbl_entries - max_entries;
  4429. if (pad)
  4430. memset(&bp->rss_indir_tbl[i], 0, pad * sizeof(u16));
  4431. }
  4432. static u16 bnxt_get_max_rss_ring(struct bnxt *bp)
  4433. {
  4434. u16 i, tbl_size, max_ring = 0;
  4435. if (!bp->rss_indir_tbl)
  4436. return 0;
  4437. tbl_size = bnxt_get_rxfh_indir_size(bp->dev);
  4438. for (i = 0; i < tbl_size; i++)
  4439. max_ring = max(max_ring, bp->rss_indir_tbl[i]);
  4440. return max_ring;
  4441. }
  4442. int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings)
  4443. {
  4444. if (bp->flags & BNXT_FLAG_CHIP_P5)
  4445. return DIV_ROUND_UP(rx_rings, BNXT_RSS_TABLE_ENTRIES_P5);
  4446. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  4447. return 2;
  4448. return 1;
  4449. }
  4450. static void __bnxt_fill_hw_rss_tbl(struct bnxt *bp, struct bnxt_vnic_info *vnic)
  4451. {
  4452. bool no_rss = !(vnic->flags & BNXT_VNIC_RSS_FLAG);
  4453. u16 i, j;
  4454. /* Fill the RSS indirection table with ring group ids */
  4455. for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++) {
  4456. if (!no_rss)
  4457. j = bp->rss_indir_tbl[i];
  4458. vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
  4459. }
  4460. }
  4461. static void __bnxt_fill_hw_rss_tbl_p5(struct bnxt *bp,
  4462. struct bnxt_vnic_info *vnic)
  4463. {
  4464. __le16 *ring_tbl = vnic->rss_table;
  4465. struct bnxt_rx_ring_info *rxr;
  4466. u16 tbl_size, i;
  4467. tbl_size = bnxt_get_rxfh_indir_size(bp->dev);
  4468. for (i = 0; i < tbl_size; i++) {
  4469. u16 ring_id, j;
  4470. j = bp->rss_indir_tbl[i];
  4471. rxr = &bp->rx_ring[j];
  4472. ring_id = rxr->rx_ring_struct.fw_ring_id;
  4473. *ring_tbl++ = cpu_to_le16(ring_id);
  4474. ring_id = bnxt_cp_ring_for_rx(bp, rxr);
  4475. *ring_tbl++ = cpu_to_le16(ring_id);
  4476. }
  4477. }
  4478. static void bnxt_fill_hw_rss_tbl(struct bnxt *bp, struct bnxt_vnic_info *vnic)
  4479. {
  4480. if (bp->flags & BNXT_FLAG_CHIP_P5)
  4481. __bnxt_fill_hw_rss_tbl_p5(bp, vnic);
  4482. else
  4483. __bnxt_fill_hw_rss_tbl(bp, vnic);
  4484. }
  4485. static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
  4486. {
  4487. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4488. struct hwrm_vnic_rss_cfg_input *req;
  4489. int rc;
  4490. if ((bp->flags & BNXT_FLAG_CHIP_P5) ||
  4491. vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
  4492. return 0;
  4493. rc = hwrm_req_init(bp, req, HWRM_VNIC_RSS_CFG);
  4494. if (rc)
  4495. return rc;
  4496. if (set_rss) {
  4497. bnxt_fill_hw_rss_tbl(bp, vnic);
  4498. req->hash_type = cpu_to_le32(bp->rss_hash_cfg);
  4499. req->hash_mode_flags = VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT;
  4500. req->ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
  4501. req->hash_key_tbl_addr =
  4502. cpu_to_le64(vnic->rss_hash_key_dma_addr);
  4503. }
  4504. req->rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
  4505. return hwrm_req_send(bp, req);
  4506. }
  4507. static int bnxt_hwrm_vnic_set_rss_p5(struct bnxt *bp, u16 vnic_id, bool set_rss)
  4508. {
  4509. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4510. struct hwrm_vnic_rss_cfg_input *req;
  4511. dma_addr_t ring_tbl_map;
  4512. u32 i, nr_ctxs;
  4513. int rc;
  4514. rc = hwrm_req_init(bp, req, HWRM_VNIC_RSS_CFG);
  4515. if (rc)
  4516. return rc;
  4517. req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
  4518. if (!set_rss)
  4519. return hwrm_req_send(bp, req);
  4520. bnxt_fill_hw_rss_tbl(bp, vnic);
  4521. req->hash_type = cpu_to_le32(bp->rss_hash_cfg);
  4522. req->hash_mode_flags = VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT;
  4523. req->hash_key_tbl_addr = cpu_to_le64(vnic->rss_hash_key_dma_addr);
  4524. ring_tbl_map = vnic->rss_table_dma_addr;
  4525. nr_ctxs = bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings);
  4526. hwrm_req_hold(bp, req);
  4527. for (i = 0; i < nr_ctxs; ring_tbl_map += BNXT_RSS_TABLE_SIZE_P5, i++) {
  4528. req->ring_grp_tbl_addr = cpu_to_le64(ring_tbl_map);
  4529. req->ring_table_pair_index = i;
  4530. req->rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[i]);
  4531. rc = hwrm_req_send(bp, req);
  4532. if (rc)
  4533. goto exit;
  4534. }
  4535. exit:
  4536. hwrm_req_drop(bp, req);
  4537. return rc;
  4538. }
  4539. static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
  4540. {
  4541. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4542. struct hwrm_vnic_plcmodes_cfg_input *req;
  4543. int rc;
  4544. rc = hwrm_req_init(bp, req, HWRM_VNIC_PLCMODES_CFG);
  4545. if (rc)
  4546. return rc;
  4547. req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
  4548. req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
  4549. if (BNXT_RX_PAGE_MODE(bp)) {
  4550. req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
  4551. } else {
  4552. req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
  4553. VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
  4554. req->enables |=
  4555. cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
  4556. req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
  4557. req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
  4558. }
  4559. req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
  4560. return hwrm_req_send(bp, req);
  4561. }
  4562. static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
  4563. u16 ctx_idx)
  4564. {
  4565. struct hwrm_vnic_rss_cos_lb_ctx_free_input *req;
  4566. if (hwrm_req_init(bp, req, HWRM_VNIC_RSS_COS_LB_CTX_FREE))
  4567. return;
  4568. req->rss_cos_lb_ctx_id =
  4569. cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
  4570. hwrm_req_send(bp, req);
  4571. bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
  4572. }
  4573. static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
  4574. {
  4575. int i, j;
  4576. for (i = 0; i < bp->nr_vnics; i++) {
  4577. struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
  4578. for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
  4579. if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
  4580. bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
  4581. }
  4582. }
  4583. bp->rsscos_nr_ctxs = 0;
  4584. }
  4585. static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
  4586. {
  4587. struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp;
  4588. struct hwrm_vnic_rss_cos_lb_ctx_alloc_input *req;
  4589. int rc;
  4590. rc = hwrm_req_init(bp, req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC);
  4591. if (rc)
  4592. return rc;
  4593. resp = hwrm_req_hold(bp, req);
  4594. rc = hwrm_req_send(bp, req);
  4595. if (!rc)
  4596. bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
  4597. le16_to_cpu(resp->rss_cos_lb_ctx_id);
  4598. hwrm_req_drop(bp, req);
  4599. return rc;
  4600. }
  4601. static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp)
  4602. {
  4603. if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP)
  4604. return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE;
  4605. return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE;
  4606. }
  4607. int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
  4608. {
  4609. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4610. struct hwrm_vnic_cfg_input *req;
  4611. unsigned int ring = 0, grp_idx;
  4612. u16 def_vlan = 0;
  4613. int rc;
  4614. rc = hwrm_req_init(bp, req, HWRM_VNIC_CFG);
  4615. if (rc)
  4616. return rc;
  4617. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4618. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0];
  4619. req->default_rx_ring_id =
  4620. cpu_to_le16(rxr->rx_ring_struct.fw_ring_id);
  4621. req->default_cmpl_ring_id =
  4622. cpu_to_le16(bnxt_cp_ring_for_rx(bp, rxr));
  4623. req->enables =
  4624. cpu_to_le32(VNIC_CFG_REQ_ENABLES_DEFAULT_RX_RING_ID |
  4625. VNIC_CFG_REQ_ENABLES_DEFAULT_CMPL_RING_ID);
  4626. goto vnic_mru;
  4627. }
  4628. req->enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
  4629. /* Only RSS support for now TBD: COS & LB */
  4630. if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
  4631. req->rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
  4632. req->enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
  4633. VNIC_CFG_REQ_ENABLES_MRU);
  4634. } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
  4635. req->rss_rule =
  4636. cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
  4637. req->enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
  4638. VNIC_CFG_REQ_ENABLES_MRU);
  4639. req->flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
  4640. } else {
  4641. req->rss_rule = cpu_to_le16(0xffff);
  4642. }
  4643. if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
  4644. (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
  4645. req->cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
  4646. req->enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
  4647. } else {
  4648. req->cos_rule = cpu_to_le16(0xffff);
  4649. }
  4650. if (vnic->flags & BNXT_VNIC_RSS_FLAG)
  4651. ring = 0;
  4652. else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
  4653. ring = vnic_id - 1;
  4654. else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
  4655. ring = bp->rx_nr_rings - 1;
  4656. grp_idx = bp->rx_ring[ring].bnapi->index;
  4657. req->dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
  4658. req->lb_rule = cpu_to_le16(0xffff);
  4659. vnic_mru:
  4660. req->mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + VLAN_HLEN);
  4661. req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
  4662. #ifdef CONFIG_BNXT_SRIOV
  4663. if (BNXT_VF(bp))
  4664. def_vlan = bp->vf.vlan;
  4665. #endif
  4666. if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
  4667. req->flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
  4668. if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
  4669. req->flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp));
  4670. return hwrm_req_send(bp, req);
  4671. }
  4672. static void bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
  4673. {
  4674. if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
  4675. struct hwrm_vnic_free_input *req;
  4676. if (hwrm_req_init(bp, req, HWRM_VNIC_FREE))
  4677. return;
  4678. req->vnic_id =
  4679. cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
  4680. hwrm_req_send(bp, req);
  4681. bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
  4682. }
  4683. }
  4684. static void bnxt_hwrm_vnic_free(struct bnxt *bp)
  4685. {
  4686. u16 i;
  4687. for (i = 0; i < bp->nr_vnics; i++)
  4688. bnxt_hwrm_vnic_free_one(bp, i);
  4689. }
  4690. static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
  4691. unsigned int start_rx_ring_idx,
  4692. unsigned int nr_rings)
  4693. {
  4694. unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
  4695. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  4696. struct hwrm_vnic_alloc_output *resp;
  4697. struct hwrm_vnic_alloc_input *req;
  4698. int rc;
  4699. rc = hwrm_req_init(bp, req, HWRM_VNIC_ALLOC);
  4700. if (rc)
  4701. return rc;
  4702. if (bp->flags & BNXT_FLAG_CHIP_P5)
  4703. goto vnic_no_ring_grps;
  4704. /* map ring groups to this vnic */
  4705. for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
  4706. grp_idx = bp->rx_ring[i].bnapi->index;
  4707. if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
  4708. netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
  4709. j, nr_rings);
  4710. break;
  4711. }
  4712. vnic->fw_grp_ids[j] = bp->grp_info[grp_idx].fw_grp_id;
  4713. }
  4714. vnic_no_ring_grps:
  4715. for (i = 0; i < BNXT_MAX_CTX_PER_VNIC; i++)
  4716. vnic->fw_rss_cos_lb_ctx[i] = INVALID_HW_RING_ID;
  4717. if (vnic_id == 0)
  4718. req->flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
  4719. resp = hwrm_req_hold(bp, req);
  4720. rc = hwrm_req_send(bp, req);
  4721. if (!rc)
  4722. vnic->fw_vnic_id = le32_to_cpu(resp->vnic_id);
  4723. hwrm_req_drop(bp, req);
  4724. return rc;
  4725. }
  4726. static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
  4727. {
  4728. struct hwrm_vnic_qcaps_output *resp;
  4729. struct hwrm_vnic_qcaps_input *req;
  4730. int rc;
  4731. bp->hw_ring_stats_size = sizeof(struct ctx_hw_stats);
  4732. bp->flags &= ~(BNXT_FLAG_NEW_RSS_CAP | BNXT_FLAG_ROCE_MIRROR_CAP);
  4733. if (bp->hwrm_spec_code < 0x10600)
  4734. return 0;
  4735. rc = hwrm_req_init(bp, req, HWRM_VNIC_QCAPS);
  4736. if (rc)
  4737. return rc;
  4738. resp = hwrm_req_hold(bp, req);
  4739. rc = hwrm_req_send(bp, req);
  4740. if (!rc) {
  4741. u32 flags = le32_to_cpu(resp->flags);
  4742. if (!(bp->flags & BNXT_FLAG_CHIP_P5) &&
  4743. (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP))
  4744. bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
  4745. if (flags &
  4746. VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP)
  4747. bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP;
  4748. /* Older P5 fw before EXT_HW_STATS support did not set
  4749. * VLAN_STRIP_CAP properly.
  4750. */
  4751. if ((flags & VNIC_QCAPS_RESP_FLAGS_VLAN_STRIP_CAP) ||
  4752. (BNXT_CHIP_P5_THOR(bp) &&
  4753. !(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED)))
  4754. bp->fw_cap |= BNXT_FW_CAP_VLAN_RX_STRIP;
  4755. bp->max_tpa_v2 = le16_to_cpu(resp->max_aggs_supported);
  4756. if (bp->max_tpa_v2) {
  4757. if (BNXT_CHIP_P5_THOR(bp))
  4758. bp->hw_ring_stats_size = BNXT_RING_STATS_SIZE_P5;
  4759. else
  4760. bp->hw_ring_stats_size = BNXT_RING_STATS_SIZE_P5_SR2;
  4761. }
  4762. }
  4763. hwrm_req_drop(bp, req);
  4764. return rc;
  4765. }
  4766. static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
  4767. {
  4768. struct hwrm_ring_grp_alloc_output *resp;
  4769. struct hwrm_ring_grp_alloc_input *req;
  4770. int rc;
  4771. u16 i;
  4772. if (bp->flags & BNXT_FLAG_CHIP_P5)
  4773. return 0;
  4774. rc = hwrm_req_init(bp, req, HWRM_RING_GRP_ALLOC);
  4775. if (rc)
  4776. return rc;
  4777. resp = hwrm_req_hold(bp, req);
  4778. for (i = 0; i < bp->rx_nr_rings; i++) {
  4779. unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
  4780. req->cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
  4781. req->rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
  4782. req->ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
  4783. req->sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
  4784. rc = hwrm_req_send(bp, req);
  4785. if (rc)
  4786. break;
  4787. bp->grp_info[grp_idx].fw_grp_id =
  4788. le32_to_cpu(resp->ring_group_id);
  4789. }
  4790. hwrm_req_drop(bp, req);
  4791. return rc;
  4792. }
  4793. static void bnxt_hwrm_ring_grp_free(struct bnxt *bp)
  4794. {
  4795. struct hwrm_ring_grp_free_input *req;
  4796. u16 i;
  4797. if (!bp->grp_info || (bp->flags & BNXT_FLAG_CHIP_P5))
  4798. return;
  4799. if (hwrm_req_init(bp, req, HWRM_RING_GRP_FREE))
  4800. return;
  4801. hwrm_req_hold(bp, req);
  4802. for (i = 0; i < bp->cp_nr_rings; i++) {
  4803. if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
  4804. continue;
  4805. req->ring_group_id =
  4806. cpu_to_le32(bp->grp_info[i].fw_grp_id);
  4807. hwrm_req_send(bp, req);
  4808. bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
  4809. }
  4810. hwrm_req_drop(bp, req);
  4811. }
  4812. static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
  4813. struct bnxt_ring_struct *ring,
  4814. u32 ring_type, u32 map_index)
  4815. {
  4816. struct hwrm_ring_alloc_output *resp;
  4817. struct hwrm_ring_alloc_input *req;
  4818. struct bnxt_ring_mem_info *rmem = &ring->ring_mem;
  4819. struct bnxt_ring_grp_info *grp_info;
  4820. int rc, err = 0;
  4821. u16 ring_id;
  4822. rc = hwrm_req_init(bp, req, HWRM_RING_ALLOC);
  4823. if (rc)
  4824. goto exit;
  4825. req->enables = 0;
  4826. if (rmem->nr_pages > 1) {
  4827. req->page_tbl_addr = cpu_to_le64(rmem->pg_tbl_map);
  4828. /* Page size is in log2 units */
  4829. req->page_size = BNXT_PAGE_SHIFT;
  4830. req->page_tbl_depth = 1;
  4831. } else {
  4832. req->page_tbl_addr = cpu_to_le64(rmem->dma_arr[0]);
  4833. }
  4834. req->fbo = 0;
  4835. /* Association of ring index with doorbell index and MSIX number */
  4836. req->logical_id = cpu_to_le16(map_index);
  4837. switch (ring_type) {
  4838. case HWRM_RING_ALLOC_TX: {
  4839. struct bnxt_tx_ring_info *txr;
  4840. txr = container_of(ring, struct bnxt_tx_ring_info,
  4841. tx_ring_struct);
  4842. req->ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
  4843. /* Association of transmit ring with completion ring */
  4844. grp_info = &bp->grp_info[ring->grp_idx];
  4845. req->cmpl_ring_id = cpu_to_le16(bnxt_cp_ring_for_tx(bp, txr));
  4846. req->length = cpu_to_le32(bp->tx_ring_mask + 1);
  4847. req->stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
  4848. req->queue_id = cpu_to_le16(ring->queue_id);
  4849. break;
  4850. }
  4851. case HWRM_RING_ALLOC_RX:
  4852. req->ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
  4853. req->length = cpu_to_le32(bp->rx_ring_mask + 1);
  4854. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4855. u16 flags = 0;
  4856. /* Association of rx ring with stats context */
  4857. grp_info = &bp->grp_info[ring->grp_idx];
  4858. req->rx_buf_size = cpu_to_le16(bp->rx_buf_use_size);
  4859. req->stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
  4860. req->enables |= cpu_to_le32(
  4861. RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID);
  4862. if (NET_IP_ALIGN == 2)
  4863. flags = RING_ALLOC_REQ_FLAGS_RX_SOP_PAD;
  4864. req->flags = cpu_to_le16(flags);
  4865. }
  4866. break;
  4867. case HWRM_RING_ALLOC_AGG:
  4868. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4869. req->ring_type = RING_ALLOC_REQ_RING_TYPE_RX_AGG;
  4870. /* Association of agg ring with rx ring */
  4871. grp_info = &bp->grp_info[ring->grp_idx];
  4872. req->rx_ring_id = cpu_to_le16(grp_info->rx_fw_ring_id);
  4873. req->rx_buf_size = cpu_to_le16(BNXT_RX_PAGE_SIZE);
  4874. req->stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
  4875. req->enables |= cpu_to_le32(
  4876. RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID |
  4877. RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID);
  4878. } else {
  4879. req->ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
  4880. }
  4881. req->length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
  4882. break;
  4883. case HWRM_RING_ALLOC_CMPL:
  4884. req->ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
  4885. req->length = cpu_to_le32(bp->cp_ring_mask + 1);
  4886. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4887. /* Association of cp ring with nq */
  4888. grp_info = &bp->grp_info[map_index];
  4889. req->nq_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id);
  4890. req->cq_handle = cpu_to_le64(ring->handle);
  4891. req->enables |= cpu_to_le32(
  4892. RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID);
  4893. } else if (bp->flags & BNXT_FLAG_USING_MSIX) {
  4894. req->int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
  4895. }
  4896. break;
  4897. case HWRM_RING_ALLOC_NQ:
  4898. req->ring_type = RING_ALLOC_REQ_RING_TYPE_NQ;
  4899. req->length = cpu_to_le32(bp->cp_ring_mask + 1);
  4900. if (bp->flags & BNXT_FLAG_USING_MSIX)
  4901. req->int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
  4902. break;
  4903. default:
  4904. netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
  4905. ring_type);
  4906. return -1;
  4907. }
  4908. resp = hwrm_req_hold(bp, req);
  4909. rc = hwrm_req_send(bp, req);
  4910. err = le16_to_cpu(resp->error_code);
  4911. ring_id = le16_to_cpu(resp->ring_id);
  4912. hwrm_req_drop(bp, req);
  4913. exit:
  4914. if (rc || err) {
  4915. netdev_err(bp->dev, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n",
  4916. ring_type, rc, err);
  4917. return -EIO;
  4918. }
  4919. ring->fw_ring_id = ring_id;
  4920. return rc;
  4921. }
  4922. static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
  4923. {
  4924. int rc;
  4925. if (BNXT_PF(bp)) {
  4926. struct hwrm_func_cfg_input *req;
  4927. rc = hwrm_req_init(bp, req, HWRM_FUNC_CFG);
  4928. if (rc)
  4929. return rc;
  4930. req->fid = cpu_to_le16(0xffff);
  4931. req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
  4932. req->async_event_cr = cpu_to_le16(idx);
  4933. return hwrm_req_send(bp, req);
  4934. } else {
  4935. struct hwrm_func_vf_cfg_input *req;
  4936. rc = hwrm_req_init(bp, req, HWRM_FUNC_VF_CFG);
  4937. if (rc)
  4938. return rc;
  4939. req->enables =
  4940. cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
  4941. req->async_event_cr = cpu_to_le16(idx);
  4942. return hwrm_req_send(bp, req);
  4943. }
  4944. }
  4945. static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type,
  4946. u32 map_idx, u32 xid)
  4947. {
  4948. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  4949. if (BNXT_PF(bp))
  4950. db->doorbell = bp->bar1 + DB_PF_OFFSET_P5;
  4951. else
  4952. db->doorbell = bp->bar1 + DB_VF_OFFSET_P5;
  4953. switch (ring_type) {
  4954. case HWRM_RING_ALLOC_TX:
  4955. db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SQ;
  4956. break;
  4957. case HWRM_RING_ALLOC_RX:
  4958. case HWRM_RING_ALLOC_AGG:
  4959. db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SRQ;
  4960. break;
  4961. case HWRM_RING_ALLOC_CMPL:
  4962. db->db_key64 = DBR_PATH_L2;
  4963. break;
  4964. case HWRM_RING_ALLOC_NQ:
  4965. db->db_key64 = DBR_PATH_L2;
  4966. break;
  4967. }
  4968. db->db_key64 |= (u64)xid << DBR_XID_SFT;
  4969. } else {
  4970. db->doorbell = bp->bar1 + map_idx * 0x80;
  4971. switch (ring_type) {
  4972. case HWRM_RING_ALLOC_TX:
  4973. db->db_key32 = DB_KEY_TX;
  4974. break;
  4975. case HWRM_RING_ALLOC_RX:
  4976. case HWRM_RING_ALLOC_AGG:
  4977. db->db_key32 = DB_KEY_RX;
  4978. break;
  4979. case HWRM_RING_ALLOC_CMPL:
  4980. db->db_key32 = DB_KEY_CP;
  4981. break;
  4982. }
  4983. }
  4984. }
  4985. static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
  4986. {
  4987. bool agg_rings = !!(bp->flags & BNXT_FLAG_AGG_RINGS);
  4988. int i, rc = 0;
  4989. u32 type;
  4990. if (bp->flags & BNXT_FLAG_CHIP_P5)
  4991. type = HWRM_RING_ALLOC_NQ;
  4992. else
  4993. type = HWRM_RING_ALLOC_CMPL;
  4994. for (i = 0; i < bp->cp_nr_rings; i++) {
  4995. struct bnxt_napi *bnapi = bp->bnapi[i];
  4996. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  4997. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  4998. u32 map_idx = ring->map_idx;
  4999. unsigned int vector;
  5000. vector = bp->irq_tbl[map_idx].vector;
  5001. disable_irq_nosync(vector);
  5002. rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
  5003. if (rc) {
  5004. enable_irq(vector);
  5005. goto err_out;
  5006. }
  5007. bnxt_set_db(bp, &cpr->cp_db, type, map_idx, ring->fw_ring_id);
  5008. bnxt_db_nq(bp, &cpr->cp_db, cpr->cp_raw_cons);
  5009. enable_irq(vector);
  5010. bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
  5011. if (!i) {
  5012. rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
  5013. if (rc)
  5014. netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
  5015. }
  5016. }
  5017. type = HWRM_RING_ALLOC_TX;
  5018. for (i = 0; i < bp->tx_nr_rings; i++) {
  5019. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  5020. struct bnxt_ring_struct *ring;
  5021. u32 map_idx;
  5022. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5023. struct bnxt_napi *bnapi = txr->bnapi;
  5024. struct bnxt_cp_ring_info *cpr, *cpr2;
  5025. u32 type2 = HWRM_RING_ALLOC_CMPL;
  5026. cpr = &bnapi->cp_ring;
  5027. cpr2 = cpr->cp_ring_arr[BNXT_TX_HDL];
  5028. ring = &cpr2->cp_ring_struct;
  5029. ring->handle = BNXT_TX_HDL;
  5030. map_idx = bnapi->index;
  5031. rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx);
  5032. if (rc)
  5033. goto err_out;
  5034. bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx,
  5035. ring->fw_ring_id);
  5036. bnxt_db_cq(bp, &cpr2->cp_db, cpr2->cp_raw_cons);
  5037. }
  5038. ring = &txr->tx_ring_struct;
  5039. map_idx = i;
  5040. rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
  5041. if (rc)
  5042. goto err_out;
  5043. bnxt_set_db(bp, &txr->tx_db, type, map_idx, ring->fw_ring_id);
  5044. }
  5045. type = HWRM_RING_ALLOC_RX;
  5046. for (i = 0; i < bp->rx_nr_rings; i++) {
  5047. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  5048. struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
  5049. struct bnxt_napi *bnapi = rxr->bnapi;
  5050. u32 map_idx = bnapi->index;
  5051. rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
  5052. if (rc)
  5053. goto err_out;
  5054. bnxt_set_db(bp, &rxr->rx_db, type, map_idx, ring->fw_ring_id);
  5055. /* If we have agg rings, post agg buffers first. */
  5056. if (!agg_rings)
  5057. bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
  5058. bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
  5059. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5060. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5061. u32 type2 = HWRM_RING_ALLOC_CMPL;
  5062. struct bnxt_cp_ring_info *cpr2;
  5063. cpr2 = cpr->cp_ring_arr[BNXT_RX_HDL];
  5064. ring = &cpr2->cp_ring_struct;
  5065. ring->handle = BNXT_RX_HDL;
  5066. rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx);
  5067. if (rc)
  5068. goto err_out;
  5069. bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx,
  5070. ring->fw_ring_id);
  5071. bnxt_db_cq(bp, &cpr2->cp_db, cpr2->cp_raw_cons);
  5072. }
  5073. }
  5074. if (agg_rings) {
  5075. type = HWRM_RING_ALLOC_AGG;
  5076. for (i = 0; i < bp->rx_nr_rings; i++) {
  5077. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  5078. struct bnxt_ring_struct *ring =
  5079. &rxr->rx_agg_ring_struct;
  5080. u32 grp_idx = ring->grp_idx;
  5081. u32 map_idx = grp_idx + bp->rx_nr_rings;
  5082. rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx);
  5083. if (rc)
  5084. goto err_out;
  5085. bnxt_set_db(bp, &rxr->rx_agg_db, type, map_idx,
  5086. ring->fw_ring_id);
  5087. bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
  5088. bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
  5089. bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
  5090. }
  5091. }
  5092. err_out:
  5093. return rc;
  5094. }
  5095. static int hwrm_ring_free_send_msg(struct bnxt *bp,
  5096. struct bnxt_ring_struct *ring,
  5097. u32 ring_type, int cmpl_ring_id)
  5098. {
  5099. struct hwrm_ring_free_output *resp;
  5100. struct hwrm_ring_free_input *req;
  5101. u16 error_code = 0;
  5102. int rc;
  5103. if (BNXT_NO_FW_ACCESS(bp))
  5104. return 0;
  5105. rc = hwrm_req_init(bp, req, HWRM_RING_FREE);
  5106. if (rc)
  5107. goto exit;
  5108. req->cmpl_ring = cpu_to_le16(cmpl_ring_id);
  5109. req->ring_type = ring_type;
  5110. req->ring_id = cpu_to_le16(ring->fw_ring_id);
  5111. resp = hwrm_req_hold(bp, req);
  5112. rc = hwrm_req_send(bp, req);
  5113. error_code = le16_to_cpu(resp->error_code);
  5114. hwrm_req_drop(bp, req);
  5115. exit:
  5116. if (rc || error_code) {
  5117. netdev_err(bp->dev, "hwrm_ring_free type %d failed. rc:%x err:%x\n",
  5118. ring_type, rc, error_code);
  5119. return -EIO;
  5120. }
  5121. return 0;
  5122. }
  5123. static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
  5124. {
  5125. u32 type;
  5126. int i;
  5127. if (!bp->bnapi)
  5128. return;
  5129. for (i = 0; i < bp->tx_nr_rings; i++) {
  5130. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  5131. struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
  5132. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  5133. u32 cmpl_ring_id = bnxt_cp_ring_for_tx(bp, txr);
  5134. hwrm_ring_free_send_msg(bp, ring,
  5135. RING_FREE_REQ_RING_TYPE_TX,
  5136. close_path ? cmpl_ring_id :
  5137. INVALID_HW_RING_ID);
  5138. ring->fw_ring_id = INVALID_HW_RING_ID;
  5139. }
  5140. }
  5141. for (i = 0; i < bp->rx_nr_rings; i++) {
  5142. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  5143. struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
  5144. u32 grp_idx = rxr->bnapi->index;
  5145. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  5146. u32 cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr);
  5147. hwrm_ring_free_send_msg(bp, ring,
  5148. RING_FREE_REQ_RING_TYPE_RX,
  5149. close_path ? cmpl_ring_id :
  5150. INVALID_HW_RING_ID);
  5151. ring->fw_ring_id = INVALID_HW_RING_ID;
  5152. bp->grp_info[grp_idx].rx_fw_ring_id =
  5153. INVALID_HW_RING_ID;
  5154. }
  5155. }
  5156. if (bp->flags & BNXT_FLAG_CHIP_P5)
  5157. type = RING_FREE_REQ_RING_TYPE_RX_AGG;
  5158. else
  5159. type = RING_FREE_REQ_RING_TYPE_RX;
  5160. for (i = 0; i < bp->rx_nr_rings; i++) {
  5161. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  5162. struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
  5163. u32 grp_idx = rxr->bnapi->index;
  5164. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  5165. u32 cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr);
  5166. hwrm_ring_free_send_msg(bp, ring, type,
  5167. close_path ? cmpl_ring_id :
  5168. INVALID_HW_RING_ID);
  5169. ring->fw_ring_id = INVALID_HW_RING_ID;
  5170. bp->grp_info[grp_idx].agg_fw_ring_id =
  5171. INVALID_HW_RING_ID;
  5172. }
  5173. }
  5174. /* The completion rings are about to be freed. After that the
  5175. * IRQ doorbell will not work anymore. So we need to disable
  5176. * IRQ here.
  5177. */
  5178. bnxt_disable_int_sync(bp);
  5179. if (bp->flags & BNXT_FLAG_CHIP_P5)
  5180. type = RING_FREE_REQ_RING_TYPE_NQ;
  5181. else
  5182. type = RING_FREE_REQ_RING_TYPE_L2_CMPL;
  5183. for (i = 0; i < bp->cp_nr_rings; i++) {
  5184. struct bnxt_napi *bnapi = bp->bnapi[i];
  5185. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5186. struct bnxt_ring_struct *ring;
  5187. int j;
  5188. for (j = 0; j < 2; j++) {
  5189. struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
  5190. if (cpr2) {
  5191. ring = &cpr2->cp_ring_struct;
  5192. if (ring->fw_ring_id == INVALID_HW_RING_ID)
  5193. continue;
  5194. hwrm_ring_free_send_msg(bp, ring,
  5195. RING_FREE_REQ_RING_TYPE_L2_CMPL,
  5196. INVALID_HW_RING_ID);
  5197. ring->fw_ring_id = INVALID_HW_RING_ID;
  5198. }
  5199. }
  5200. ring = &cpr->cp_ring_struct;
  5201. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  5202. hwrm_ring_free_send_msg(bp, ring, type,
  5203. INVALID_HW_RING_ID);
  5204. ring->fw_ring_id = INVALID_HW_RING_ID;
  5205. bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
  5206. }
  5207. }
  5208. }
  5209. static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
  5210. bool shared);
  5211. static int bnxt_hwrm_get_rings(struct bnxt *bp)
  5212. {
  5213. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  5214. struct hwrm_func_qcfg_output *resp;
  5215. struct hwrm_func_qcfg_input *req;
  5216. int rc;
  5217. if (bp->hwrm_spec_code < 0x10601)
  5218. return 0;
  5219. rc = hwrm_req_init(bp, req, HWRM_FUNC_QCFG);
  5220. if (rc)
  5221. return rc;
  5222. req->fid = cpu_to_le16(0xffff);
  5223. resp = hwrm_req_hold(bp, req);
  5224. rc = hwrm_req_send(bp, req);
  5225. if (rc) {
  5226. hwrm_req_drop(bp, req);
  5227. return rc;
  5228. }
  5229. hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
  5230. if (BNXT_NEW_RM(bp)) {
  5231. u16 cp, stats;
  5232. hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings);
  5233. hw_resc->resv_hw_ring_grps =
  5234. le32_to_cpu(resp->alloc_hw_ring_grps);
  5235. hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
  5236. cp = le16_to_cpu(resp->alloc_cmpl_rings);
  5237. stats = le16_to_cpu(resp->alloc_stat_ctx);
  5238. hw_resc->resv_irqs = cp;
  5239. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5240. int rx = hw_resc->resv_rx_rings;
  5241. int tx = hw_resc->resv_tx_rings;
  5242. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  5243. rx >>= 1;
  5244. if (cp < (rx + tx)) {
  5245. bnxt_trim_rings(bp, &rx, &tx, cp, false);
  5246. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  5247. rx <<= 1;
  5248. hw_resc->resv_rx_rings = rx;
  5249. hw_resc->resv_tx_rings = tx;
  5250. }
  5251. hw_resc->resv_irqs = le16_to_cpu(resp->alloc_msix);
  5252. hw_resc->resv_hw_ring_grps = rx;
  5253. }
  5254. hw_resc->resv_cp_rings = cp;
  5255. hw_resc->resv_stat_ctxs = stats;
  5256. }
  5257. hwrm_req_drop(bp, req);
  5258. return 0;
  5259. }
  5260. int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
  5261. {
  5262. struct hwrm_func_qcfg_output *resp;
  5263. struct hwrm_func_qcfg_input *req;
  5264. int rc;
  5265. if (bp->hwrm_spec_code < 0x10601)
  5266. return 0;
  5267. rc = hwrm_req_init(bp, req, HWRM_FUNC_QCFG);
  5268. if (rc)
  5269. return rc;
  5270. req->fid = cpu_to_le16(fid);
  5271. resp = hwrm_req_hold(bp, req);
  5272. rc = hwrm_req_send(bp, req);
  5273. if (!rc)
  5274. *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
  5275. hwrm_req_drop(bp, req);
  5276. return rc;
  5277. }
  5278. static bool bnxt_rfs_supported(struct bnxt *bp);
  5279. static struct hwrm_func_cfg_input *
  5280. __bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5281. int ring_grps, int cp_rings, int stats, int vnics)
  5282. {
  5283. struct hwrm_func_cfg_input *req;
  5284. u32 enables = 0;
  5285. if (hwrm_req_init(bp, req, HWRM_FUNC_CFG))
  5286. return NULL;
  5287. req->fid = cpu_to_le16(0xffff);
  5288. enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
  5289. req->num_tx_rings = cpu_to_le16(tx_rings);
  5290. if (BNXT_NEW_RM(bp)) {
  5291. enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
  5292. enables |= stats ? FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
  5293. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5294. enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_MSIX : 0;
  5295. enables |= tx_rings + ring_grps ?
  5296. FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
  5297. enables |= rx_rings ?
  5298. FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
  5299. } else {
  5300. enables |= cp_rings ?
  5301. FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
  5302. enables |= ring_grps ?
  5303. FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS |
  5304. FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
  5305. }
  5306. enables |= vnics ? FUNC_CFG_REQ_ENABLES_NUM_VNICS : 0;
  5307. req->num_rx_rings = cpu_to_le16(rx_rings);
  5308. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5309. req->num_cmpl_rings = cpu_to_le16(tx_rings + ring_grps);
  5310. req->num_msix = cpu_to_le16(cp_rings);
  5311. req->num_rsscos_ctxs =
  5312. cpu_to_le16(DIV_ROUND_UP(ring_grps, 64));
  5313. } else {
  5314. req->num_cmpl_rings = cpu_to_le16(cp_rings);
  5315. req->num_hw_ring_grps = cpu_to_le16(ring_grps);
  5316. req->num_rsscos_ctxs = cpu_to_le16(1);
  5317. if (!(bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
  5318. bnxt_rfs_supported(bp))
  5319. req->num_rsscos_ctxs =
  5320. cpu_to_le16(ring_grps + 1);
  5321. }
  5322. req->num_stat_ctxs = cpu_to_le16(stats);
  5323. req->num_vnics = cpu_to_le16(vnics);
  5324. }
  5325. req->enables = cpu_to_le32(enables);
  5326. return req;
  5327. }
  5328. static struct hwrm_func_vf_cfg_input *
  5329. __bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5330. int ring_grps, int cp_rings, int stats, int vnics)
  5331. {
  5332. struct hwrm_func_vf_cfg_input *req;
  5333. u32 enables = 0;
  5334. if (hwrm_req_init(bp, req, HWRM_FUNC_VF_CFG))
  5335. return NULL;
  5336. enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
  5337. enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS |
  5338. FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
  5339. enables |= stats ? FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
  5340. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5341. enables |= tx_rings + ring_grps ?
  5342. FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
  5343. } else {
  5344. enables |= cp_rings ?
  5345. FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
  5346. enables |= ring_grps ?
  5347. FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0;
  5348. }
  5349. enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0;
  5350. enables |= FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS;
  5351. req->num_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX);
  5352. req->num_tx_rings = cpu_to_le16(tx_rings);
  5353. req->num_rx_rings = cpu_to_le16(rx_rings);
  5354. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5355. req->num_cmpl_rings = cpu_to_le16(tx_rings + ring_grps);
  5356. req->num_rsscos_ctxs = cpu_to_le16(DIV_ROUND_UP(ring_grps, 64));
  5357. } else {
  5358. req->num_cmpl_rings = cpu_to_le16(cp_rings);
  5359. req->num_hw_ring_grps = cpu_to_le16(ring_grps);
  5360. req->num_rsscos_ctxs = cpu_to_le16(BNXT_VF_MAX_RSS_CTX);
  5361. }
  5362. req->num_stat_ctxs = cpu_to_le16(stats);
  5363. req->num_vnics = cpu_to_le16(vnics);
  5364. req->enables = cpu_to_le32(enables);
  5365. return req;
  5366. }
  5367. static int
  5368. bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5369. int ring_grps, int cp_rings, int stats, int vnics)
  5370. {
  5371. struct hwrm_func_cfg_input *req;
  5372. int rc;
  5373. req = __bnxt_hwrm_reserve_pf_rings(bp, tx_rings, rx_rings, ring_grps,
  5374. cp_rings, stats, vnics);
  5375. if (!req)
  5376. return -ENOMEM;
  5377. if (!req->enables) {
  5378. hwrm_req_drop(bp, req);
  5379. return 0;
  5380. }
  5381. rc = hwrm_req_send(bp, req);
  5382. if (rc)
  5383. return rc;
  5384. if (bp->hwrm_spec_code < 0x10601)
  5385. bp->hw_resc.resv_tx_rings = tx_rings;
  5386. return bnxt_hwrm_get_rings(bp);
  5387. }
  5388. static int
  5389. bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5390. int ring_grps, int cp_rings, int stats, int vnics)
  5391. {
  5392. struct hwrm_func_vf_cfg_input *req;
  5393. int rc;
  5394. if (!BNXT_NEW_RM(bp)) {
  5395. bp->hw_resc.resv_tx_rings = tx_rings;
  5396. return 0;
  5397. }
  5398. req = __bnxt_hwrm_reserve_vf_rings(bp, tx_rings, rx_rings, ring_grps,
  5399. cp_rings, stats, vnics);
  5400. if (!req)
  5401. return -ENOMEM;
  5402. rc = hwrm_req_send(bp, req);
  5403. if (rc)
  5404. return rc;
  5405. return bnxt_hwrm_get_rings(bp);
  5406. }
  5407. static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp,
  5408. int cp, int stat, int vnic)
  5409. {
  5410. if (BNXT_PF(bp))
  5411. return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, stat,
  5412. vnic);
  5413. else
  5414. return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, stat,
  5415. vnic);
  5416. }
  5417. int bnxt_nq_rings_in_use(struct bnxt *bp)
  5418. {
  5419. int cp = bp->cp_nr_rings;
  5420. int ulp_msix, ulp_base;
  5421. ulp_msix = bnxt_get_ulp_msix_num(bp);
  5422. if (ulp_msix) {
  5423. ulp_base = bnxt_get_ulp_msix_base(bp);
  5424. cp += ulp_msix;
  5425. if ((ulp_base + ulp_msix) > cp)
  5426. cp = ulp_base + ulp_msix;
  5427. }
  5428. return cp;
  5429. }
  5430. static int bnxt_cp_rings_in_use(struct bnxt *bp)
  5431. {
  5432. int cp;
  5433. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  5434. return bnxt_nq_rings_in_use(bp);
  5435. cp = bp->tx_nr_rings + bp->rx_nr_rings;
  5436. return cp;
  5437. }
  5438. static int bnxt_get_func_stat_ctxs(struct bnxt *bp)
  5439. {
  5440. int ulp_stat = bnxt_get_ulp_stat_ctxs(bp);
  5441. int cp = bp->cp_nr_rings;
  5442. if (!ulp_stat)
  5443. return cp;
  5444. if (bnxt_nq_rings_in_use(bp) > cp + bnxt_get_ulp_msix_num(bp))
  5445. return bnxt_get_ulp_msix_base(bp) + ulp_stat;
  5446. return cp + ulp_stat;
  5447. }
  5448. /* Check if a default RSS map needs to be setup. This function is only
  5449. * used on older firmware that does not require reserving RX rings.
  5450. */
  5451. static void bnxt_check_rss_tbl_no_rmgr(struct bnxt *bp)
  5452. {
  5453. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  5454. /* The RSS map is valid for RX rings set to resv_rx_rings */
  5455. if (hw_resc->resv_rx_rings != bp->rx_nr_rings) {
  5456. hw_resc->resv_rx_rings = bp->rx_nr_rings;
  5457. if (!netif_is_rxfh_configured(bp->dev))
  5458. bnxt_set_dflt_rss_indir_tbl(bp);
  5459. }
  5460. }
  5461. static bool bnxt_need_reserve_rings(struct bnxt *bp)
  5462. {
  5463. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  5464. int cp = bnxt_cp_rings_in_use(bp);
  5465. int nq = bnxt_nq_rings_in_use(bp);
  5466. int rx = bp->rx_nr_rings, stat;
  5467. int vnic = 1, grp = rx;
  5468. if (hw_resc->resv_tx_rings != bp->tx_nr_rings &&
  5469. bp->hwrm_spec_code >= 0x10601)
  5470. return true;
  5471. /* Old firmware does not need RX ring reservations but we still
  5472. * need to setup a default RSS map when needed. With new firmware
  5473. * we go through RX ring reservations first and then set up the
  5474. * RSS map for the successfully reserved RX rings when needed.
  5475. */
  5476. if (!BNXT_NEW_RM(bp)) {
  5477. bnxt_check_rss_tbl_no_rmgr(bp);
  5478. return false;
  5479. }
  5480. if ((bp->flags & BNXT_FLAG_RFS) && !(bp->flags & BNXT_FLAG_CHIP_P5))
  5481. vnic = rx + 1;
  5482. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  5483. rx <<= 1;
  5484. stat = bnxt_get_func_stat_ctxs(bp);
  5485. if (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
  5486. hw_resc->resv_vnics != vnic || hw_resc->resv_stat_ctxs != stat ||
  5487. (hw_resc->resv_hw_ring_grps != grp &&
  5488. !(bp->flags & BNXT_FLAG_CHIP_P5)))
  5489. return true;
  5490. if ((bp->flags & BNXT_FLAG_CHIP_P5) && BNXT_PF(bp) &&
  5491. hw_resc->resv_irqs != nq)
  5492. return true;
  5493. return false;
  5494. }
  5495. static int __bnxt_reserve_rings(struct bnxt *bp)
  5496. {
  5497. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  5498. int cp = bnxt_nq_rings_in_use(bp);
  5499. int tx = bp->tx_nr_rings;
  5500. int rx = bp->rx_nr_rings;
  5501. int grp, rx_rings, rc;
  5502. int vnic = 1, stat;
  5503. bool sh = false;
  5504. if (!bnxt_need_reserve_rings(bp))
  5505. return 0;
  5506. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  5507. sh = true;
  5508. if ((bp->flags & BNXT_FLAG_RFS) && !(bp->flags & BNXT_FLAG_CHIP_P5))
  5509. vnic = rx + 1;
  5510. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  5511. rx <<= 1;
  5512. grp = bp->rx_nr_rings;
  5513. stat = bnxt_get_func_stat_ctxs(bp);
  5514. rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, stat, vnic);
  5515. if (rc)
  5516. return rc;
  5517. tx = hw_resc->resv_tx_rings;
  5518. if (BNXT_NEW_RM(bp)) {
  5519. rx = hw_resc->resv_rx_rings;
  5520. cp = hw_resc->resv_irqs;
  5521. grp = hw_resc->resv_hw_ring_grps;
  5522. vnic = hw_resc->resv_vnics;
  5523. stat = hw_resc->resv_stat_ctxs;
  5524. }
  5525. rx_rings = rx;
  5526. if (bp->flags & BNXT_FLAG_AGG_RINGS) {
  5527. if (rx >= 2) {
  5528. rx_rings = rx >> 1;
  5529. } else {
  5530. if (netif_running(bp->dev))
  5531. return -ENOMEM;
  5532. bp->flags &= ~BNXT_FLAG_AGG_RINGS;
  5533. bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
  5534. bp->dev->hw_features &= ~NETIF_F_LRO;
  5535. bp->dev->features &= ~NETIF_F_LRO;
  5536. bnxt_set_ring_params(bp);
  5537. }
  5538. }
  5539. rx_rings = min_t(int, rx_rings, grp);
  5540. cp = min_t(int, cp, bp->cp_nr_rings);
  5541. if (stat > bnxt_get_ulp_stat_ctxs(bp))
  5542. stat -= bnxt_get_ulp_stat_ctxs(bp);
  5543. cp = min_t(int, cp, stat);
  5544. rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
  5545. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  5546. rx = rx_rings << 1;
  5547. cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
  5548. bp->tx_nr_rings = tx;
  5549. /* If we cannot reserve all the RX rings, reset the RSS map only
  5550. * if absolutely necessary
  5551. */
  5552. if (rx_rings != bp->rx_nr_rings) {
  5553. netdev_warn(bp->dev, "Able to reserve only %d out of %d requested RX rings\n",
  5554. rx_rings, bp->rx_nr_rings);
  5555. if (netif_is_rxfh_configured(bp->dev) &&
  5556. (bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings) !=
  5557. bnxt_get_nr_rss_ctxs(bp, rx_rings) ||
  5558. bnxt_get_max_rss_ring(bp) >= rx_rings)) {
  5559. netdev_warn(bp->dev, "RSS table entries reverting to default\n");
  5560. bp->dev->priv_flags &= ~IFF_RXFH_CONFIGURED;
  5561. }
  5562. }
  5563. bp->rx_nr_rings = rx_rings;
  5564. bp->cp_nr_rings = cp;
  5565. if (!tx || !rx || !cp || !grp || !vnic || !stat)
  5566. return -ENOMEM;
  5567. if (!netif_is_rxfh_configured(bp->dev))
  5568. bnxt_set_dflt_rss_indir_tbl(bp);
  5569. return rc;
  5570. }
  5571. static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5572. int ring_grps, int cp_rings, int stats,
  5573. int vnics)
  5574. {
  5575. struct hwrm_func_vf_cfg_input *req;
  5576. u32 flags;
  5577. if (!BNXT_NEW_RM(bp))
  5578. return 0;
  5579. req = __bnxt_hwrm_reserve_vf_rings(bp, tx_rings, rx_rings, ring_grps,
  5580. cp_rings, stats, vnics);
  5581. flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST |
  5582. FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST |
  5583. FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
  5584. FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
  5585. FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST |
  5586. FUNC_VF_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST;
  5587. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  5588. flags |= FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST;
  5589. req->flags = cpu_to_le32(flags);
  5590. return hwrm_req_send_silent(bp, req);
  5591. }
  5592. static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5593. int ring_grps, int cp_rings, int stats,
  5594. int vnics)
  5595. {
  5596. struct hwrm_func_cfg_input *req;
  5597. u32 flags;
  5598. req = __bnxt_hwrm_reserve_pf_rings(bp, tx_rings, rx_rings, ring_grps,
  5599. cp_rings, stats, vnics);
  5600. flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST;
  5601. if (BNXT_NEW_RM(bp)) {
  5602. flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST |
  5603. FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST |
  5604. FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST |
  5605. FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST;
  5606. if (bp->flags & BNXT_FLAG_CHIP_P5)
  5607. flags |= FUNC_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST |
  5608. FUNC_CFG_REQ_FLAGS_NQ_ASSETS_TEST;
  5609. else
  5610. flags |= FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST;
  5611. }
  5612. req->flags = cpu_to_le32(flags);
  5613. return hwrm_req_send_silent(bp, req);
  5614. }
  5615. static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings,
  5616. int ring_grps, int cp_rings, int stats,
  5617. int vnics)
  5618. {
  5619. if (bp->hwrm_spec_code < 0x10801)
  5620. return 0;
  5621. if (BNXT_PF(bp))
  5622. return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings,
  5623. ring_grps, cp_rings, stats,
  5624. vnics);
  5625. return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps,
  5626. cp_rings, stats, vnics);
  5627. }
  5628. static void bnxt_hwrm_coal_params_qcaps(struct bnxt *bp)
  5629. {
  5630. struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
  5631. struct hwrm_ring_aggint_qcaps_output *resp;
  5632. struct hwrm_ring_aggint_qcaps_input *req;
  5633. int rc;
  5634. coal_cap->cmpl_params = BNXT_LEGACY_COAL_CMPL_PARAMS;
  5635. coal_cap->num_cmpl_dma_aggr_max = 63;
  5636. coal_cap->num_cmpl_dma_aggr_during_int_max = 63;
  5637. coal_cap->cmpl_aggr_dma_tmr_max = 65535;
  5638. coal_cap->cmpl_aggr_dma_tmr_during_int_max = 65535;
  5639. coal_cap->int_lat_tmr_min_max = 65535;
  5640. coal_cap->int_lat_tmr_max_max = 65535;
  5641. coal_cap->num_cmpl_aggr_int_max = 65535;
  5642. coal_cap->timer_units = 80;
  5643. if (bp->hwrm_spec_code < 0x10902)
  5644. return;
  5645. if (hwrm_req_init(bp, req, HWRM_RING_AGGINT_QCAPS))
  5646. return;
  5647. resp = hwrm_req_hold(bp, req);
  5648. rc = hwrm_req_send_silent(bp, req);
  5649. if (!rc) {
  5650. coal_cap->cmpl_params = le32_to_cpu(resp->cmpl_params);
  5651. coal_cap->nq_params = le32_to_cpu(resp->nq_params);
  5652. coal_cap->num_cmpl_dma_aggr_max =
  5653. le16_to_cpu(resp->num_cmpl_dma_aggr_max);
  5654. coal_cap->num_cmpl_dma_aggr_during_int_max =
  5655. le16_to_cpu(resp->num_cmpl_dma_aggr_during_int_max);
  5656. coal_cap->cmpl_aggr_dma_tmr_max =
  5657. le16_to_cpu(resp->cmpl_aggr_dma_tmr_max);
  5658. coal_cap->cmpl_aggr_dma_tmr_during_int_max =
  5659. le16_to_cpu(resp->cmpl_aggr_dma_tmr_during_int_max);
  5660. coal_cap->int_lat_tmr_min_max =
  5661. le16_to_cpu(resp->int_lat_tmr_min_max);
  5662. coal_cap->int_lat_tmr_max_max =
  5663. le16_to_cpu(resp->int_lat_tmr_max_max);
  5664. coal_cap->num_cmpl_aggr_int_max =
  5665. le16_to_cpu(resp->num_cmpl_aggr_int_max);
  5666. coal_cap->timer_units = le16_to_cpu(resp->timer_units);
  5667. }
  5668. hwrm_req_drop(bp, req);
  5669. }
  5670. static u16 bnxt_usec_to_coal_tmr(struct bnxt *bp, u16 usec)
  5671. {
  5672. struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
  5673. return usec * 1000 / coal_cap->timer_units;
  5674. }
  5675. static void bnxt_hwrm_set_coal_params(struct bnxt *bp,
  5676. struct bnxt_coal *hw_coal,
  5677. struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
  5678. {
  5679. struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
  5680. u16 val, tmr, max, flags = hw_coal->flags;
  5681. u32 cmpl_params = coal_cap->cmpl_params;
  5682. max = hw_coal->bufs_per_record * 128;
  5683. if (hw_coal->budget)
  5684. max = hw_coal->bufs_per_record * hw_coal->budget;
  5685. max = min_t(u16, max, coal_cap->num_cmpl_aggr_int_max);
  5686. val = clamp_t(u16, hw_coal->coal_bufs, 1, max);
  5687. req->num_cmpl_aggr_int = cpu_to_le16(val);
  5688. val = min_t(u16, val, coal_cap->num_cmpl_dma_aggr_max);
  5689. req->num_cmpl_dma_aggr = cpu_to_le16(val);
  5690. val = clamp_t(u16, hw_coal->coal_bufs_irq, 1,
  5691. coal_cap->num_cmpl_dma_aggr_during_int_max);
  5692. req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val);
  5693. tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks);
  5694. tmr = clamp_t(u16, tmr, 1, coal_cap->int_lat_tmr_max_max);
  5695. req->int_lat_tmr_max = cpu_to_le16(tmr);
  5696. /* min timer set to 1/2 of interrupt timer */
  5697. if (cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN) {
  5698. val = tmr / 2;
  5699. val = clamp_t(u16, val, 1, coal_cap->int_lat_tmr_min_max);
  5700. req->int_lat_tmr_min = cpu_to_le16(val);
  5701. req->enables |= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE);
  5702. }
  5703. /* buf timer set to 1/4 of interrupt timer */
  5704. val = clamp_t(u16, tmr / 4, 1, coal_cap->cmpl_aggr_dma_tmr_max);
  5705. req->cmpl_aggr_dma_tmr = cpu_to_le16(val);
  5706. if (cmpl_params &
  5707. RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT) {
  5708. tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks_irq);
  5709. val = clamp_t(u16, tmr, 1,
  5710. coal_cap->cmpl_aggr_dma_tmr_during_int_max);
  5711. req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(val);
  5712. req->enables |=
  5713. cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE);
  5714. }
  5715. if ((cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE) &&
  5716. hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh)
  5717. flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
  5718. req->flags = cpu_to_le16(flags);
  5719. req->enables |= cpu_to_le16(BNXT_COAL_CMPL_ENABLES);
  5720. }
  5721. static int __bnxt_hwrm_set_coal_nq(struct bnxt *bp, struct bnxt_napi *bnapi,
  5722. struct bnxt_coal *hw_coal)
  5723. {
  5724. struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req;
  5725. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5726. struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
  5727. u32 nq_params = coal_cap->nq_params;
  5728. u16 tmr;
  5729. int rc;
  5730. if (!(nq_params & RING_AGGINT_QCAPS_RESP_NQ_PARAMS_INT_LAT_TMR_MIN))
  5731. return 0;
  5732. rc = hwrm_req_init(bp, req, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS);
  5733. if (rc)
  5734. return rc;
  5735. req->ring_id = cpu_to_le16(cpr->cp_ring_struct.fw_ring_id);
  5736. req->flags =
  5737. cpu_to_le16(RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_IS_NQ);
  5738. tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks) / 2;
  5739. tmr = clamp_t(u16, tmr, 1, coal_cap->int_lat_tmr_min_max);
  5740. req->int_lat_tmr_min = cpu_to_le16(tmr);
  5741. req->enables |= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE);
  5742. return hwrm_req_send(bp, req);
  5743. }
  5744. int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi)
  5745. {
  5746. struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req_rx;
  5747. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5748. struct bnxt_coal coal;
  5749. int rc;
  5750. /* Tick values in micro seconds.
  5751. * 1 coal_buf x bufs_per_record = 1 completion record.
  5752. */
  5753. memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal));
  5754. coal.coal_ticks = cpr->rx_ring_coal.coal_ticks;
  5755. coal.coal_bufs = cpr->rx_ring_coal.coal_bufs;
  5756. if (!bnapi->rx_ring)
  5757. return -ENODEV;
  5758. rc = hwrm_req_init(bp, req_rx, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS);
  5759. if (rc)
  5760. return rc;
  5761. bnxt_hwrm_set_coal_params(bp, &coal, req_rx);
  5762. req_rx->ring_id = cpu_to_le16(bnxt_cp_ring_for_rx(bp, bnapi->rx_ring));
  5763. return hwrm_req_send(bp, req_rx);
  5764. }
  5765. int bnxt_hwrm_set_coal(struct bnxt *bp)
  5766. {
  5767. struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req_rx, *req_tx,
  5768. *req;
  5769. int i, rc;
  5770. rc = hwrm_req_init(bp, req_rx, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS);
  5771. if (rc)
  5772. return rc;
  5773. rc = hwrm_req_init(bp, req_tx, HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS);
  5774. if (rc) {
  5775. hwrm_req_drop(bp, req_rx);
  5776. return rc;
  5777. }
  5778. bnxt_hwrm_set_coal_params(bp, &bp->rx_coal, req_rx);
  5779. bnxt_hwrm_set_coal_params(bp, &bp->tx_coal, req_tx);
  5780. hwrm_req_hold(bp, req_rx);
  5781. hwrm_req_hold(bp, req_tx);
  5782. for (i = 0; i < bp->cp_nr_rings; i++) {
  5783. struct bnxt_napi *bnapi = bp->bnapi[i];
  5784. struct bnxt_coal *hw_coal;
  5785. u16 ring_id;
  5786. req = req_rx;
  5787. if (!bnapi->rx_ring) {
  5788. ring_id = bnxt_cp_ring_for_tx(bp, bnapi->tx_ring);
  5789. req = req_tx;
  5790. } else {
  5791. ring_id = bnxt_cp_ring_for_rx(bp, bnapi->rx_ring);
  5792. }
  5793. req->ring_id = cpu_to_le16(ring_id);
  5794. rc = hwrm_req_send(bp, req);
  5795. if (rc)
  5796. break;
  5797. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  5798. continue;
  5799. if (bnapi->rx_ring && bnapi->tx_ring) {
  5800. req = req_tx;
  5801. ring_id = bnxt_cp_ring_for_tx(bp, bnapi->tx_ring);
  5802. req->ring_id = cpu_to_le16(ring_id);
  5803. rc = hwrm_req_send(bp, req);
  5804. if (rc)
  5805. break;
  5806. }
  5807. if (bnapi->rx_ring)
  5808. hw_coal = &bp->rx_coal;
  5809. else
  5810. hw_coal = &bp->tx_coal;
  5811. __bnxt_hwrm_set_coal_nq(bp, bnapi, hw_coal);
  5812. }
  5813. hwrm_req_drop(bp, req_rx);
  5814. hwrm_req_drop(bp, req_tx);
  5815. return rc;
  5816. }
  5817. static void bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
  5818. {
  5819. struct hwrm_stat_ctx_clr_stats_input *req0 = NULL;
  5820. struct hwrm_stat_ctx_free_input *req;
  5821. int i;
  5822. if (!bp->bnapi)
  5823. return;
  5824. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  5825. return;
  5826. if (hwrm_req_init(bp, req, HWRM_STAT_CTX_FREE))
  5827. return;
  5828. if (BNXT_FW_MAJ(bp) <= 20) {
  5829. if (hwrm_req_init(bp, req0, HWRM_STAT_CTX_CLR_STATS)) {
  5830. hwrm_req_drop(bp, req);
  5831. return;
  5832. }
  5833. hwrm_req_hold(bp, req0);
  5834. }
  5835. hwrm_req_hold(bp, req);
  5836. for (i = 0; i < bp->cp_nr_rings; i++) {
  5837. struct bnxt_napi *bnapi = bp->bnapi[i];
  5838. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5839. if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
  5840. req->stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
  5841. if (req0) {
  5842. req0->stat_ctx_id = req->stat_ctx_id;
  5843. hwrm_req_send(bp, req0);
  5844. }
  5845. hwrm_req_send(bp, req);
  5846. cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
  5847. }
  5848. }
  5849. hwrm_req_drop(bp, req);
  5850. if (req0)
  5851. hwrm_req_drop(bp, req0);
  5852. }
  5853. static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
  5854. {
  5855. struct hwrm_stat_ctx_alloc_output *resp;
  5856. struct hwrm_stat_ctx_alloc_input *req;
  5857. int rc, i;
  5858. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  5859. return 0;
  5860. rc = hwrm_req_init(bp, req, HWRM_STAT_CTX_ALLOC);
  5861. if (rc)
  5862. return rc;
  5863. req->stats_dma_length = cpu_to_le16(bp->hw_ring_stats_size);
  5864. req->update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
  5865. resp = hwrm_req_hold(bp, req);
  5866. for (i = 0; i < bp->cp_nr_rings; i++) {
  5867. struct bnxt_napi *bnapi = bp->bnapi[i];
  5868. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5869. req->stats_dma_addr = cpu_to_le64(cpr->stats.hw_stats_map);
  5870. rc = hwrm_req_send(bp, req);
  5871. if (rc)
  5872. break;
  5873. cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
  5874. bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
  5875. }
  5876. hwrm_req_drop(bp, req);
  5877. return rc;
  5878. }
  5879. static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
  5880. {
  5881. struct hwrm_func_qcfg_output *resp;
  5882. struct hwrm_func_qcfg_input *req;
  5883. u32 min_db_offset = 0;
  5884. u16 flags;
  5885. int rc;
  5886. rc = hwrm_req_init(bp, req, HWRM_FUNC_QCFG);
  5887. if (rc)
  5888. return rc;
  5889. req->fid = cpu_to_le16(0xffff);
  5890. resp = hwrm_req_hold(bp, req);
  5891. rc = hwrm_req_send(bp, req);
  5892. if (rc)
  5893. goto func_qcfg_exit;
  5894. #ifdef CONFIG_BNXT_SRIOV
  5895. if (BNXT_VF(bp)) {
  5896. struct bnxt_vf_info *vf = &bp->vf;
  5897. vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
  5898. } else {
  5899. bp->pf.registered_vfs = le16_to_cpu(resp->registered_vfs);
  5900. }
  5901. #endif
  5902. flags = le16_to_cpu(resp->flags);
  5903. if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
  5904. FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) {
  5905. bp->fw_cap |= BNXT_FW_CAP_LLDP_AGENT;
  5906. if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
  5907. bp->fw_cap |= BNXT_FW_CAP_DCBX_AGENT;
  5908. }
  5909. if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
  5910. bp->flags |= BNXT_FLAG_MULTI_HOST;
  5911. if (flags & FUNC_QCFG_RESP_FLAGS_RING_MONITOR_ENABLED)
  5912. bp->fw_cap |= BNXT_FW_CAP_RING_MONITOR;
  5913. switch (resp->port_partition_type) {
  5914. case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
  5915. case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
  5916. case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
  5917. bp->port_partition_type = resp->port_partition_type;
  5918. break;
  5919. }
  5920. if (bp->hwrm_spec_code < 0x10707 ||
  5921. resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB)
  5922. bp->br_mode = BRIDGE_MODE_VEB;
  5923. else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA)
  5924. bp->br_mode = BRIDGE_MODE_VEPA;
  5925. else
  5926. bp->br_mode = BRIDGE_MODE_UNDEF;
  5927. bp->max_mtu = le16_to_cpu(resp->max_mtu_configured);
  5928. if (!bp->max_mtu)
  5929. bp->max_mtu = BNXT_MAX_MTU;
  5930. if (bp->db_size)
  5931. goto func_qcfg_exit;
  5932. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  5933. if (BNXT_PF(bp))
  5934. min_db_offset = DB_PF_OFFSET_P5;
  5935. else
  5936. min_db_offset = DB_VF_OFFSET_P5;
  5937. }
  5938. bp->db_size = PAGE_ALIGN(le16_to_cpu(resp->l2_doorbell_bar_size_kb) *
  5939. 1024);
  5940. if (!bp->db_size || bp->db_size > pci_resource_len(bp->pdev, 2) ||
  5941. bp->db_size <= min_db_offset)
  5942. bp->db_size = pci_resource_len(bp->pdev, 2);
  5943. func_qcfg_exit:
  5944. hwrm_req_drop(bp, req);
  5945. return rc;
  5946. }
  5947. static void bnxt_init_ctx_initializer(struct bnxt_ctx_mem_info *ctx,
  5948. struct hwrm_func_backing_store_qcaps_output *resp)
  5949. {
  5950. struct bnxt_mem_init *mem_init;
  5951. u16 init_mask;
  5952. u8 init_val;
  5953. u8 *offset;
  5954. int i;
  5955. init_val = resp->ctx_kind_initializer;
  5956. init_mask = le16_to_cpu(resp->ctx_init_mask);
  5957. offset = &resp->qp_init_offset;
  5958. mem_init = &ctx->mem_init[BNXT_CTX_MEM_INIT_QP];
  5959. for (i = 0; i < BNXT_CTX_MEM_INIT_MAX; i++, mem_init++, offset++) {
  5960. mem_init->init_val = init_val;
  5961. mem_init->offset = BNXT_MEM_INVALID_OFFSET;
  5962. if (!init_mask)
  5963. continue;
  5964. if (i == BNXT_CTX_MEM_INIT_STAT)
  5965. offset = &resp->stat_init_offset;
  5966. if (init_mask & (1 << i))
  5967. mem_init->offset = *offset * 4;
  5968. else
  5969. mem_init->init_val = 0;
  5970. }
  5971. ctx->mem_init[BNXT_CTX_MEM_INIT_QP].size = ctx->qp_entry_size;
  5972. ctx->mem_init[BNXT_CTX_MEM_INIT_SRQ].size = ctx->srq_entry_size;
  5973. ctx->mem_init[BNXT_CTX_MEM_INIT_CQ].size = ctx->cq_entry_size;
  5974. ctx->mem_init[BNXT_CTX_MEM_INIT_VNIC].size = ctx->vnic_entry_size;
  5975. ctx->mem_init[BNXT_CTX_MEM_INIT_STAT].size = ctx->stat_entry_size;
  5976. ctx->mem_init[BNXT_CTX_MEM_INIT_MRAV].size = ctx->mrav_entry_size;
  5977. }
  5978. static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
  5979. {
  5980. struct hwrm_func_backing_store_qcaps_output *resp;
  5981. struct hwrm_func_backing_store_qcaps_input *req;
  5982. int rc;
  5983. if (bp->hwrm_spec_code < 0x10902 || BNXT_VF(bp) || bp->ctx)
  5984. return 0;
  5985. rc = hwrm_req_init(bp, req, HWRM_FUNC_BACKING_STORE_QCAPS);
  5986. if (rc)
  5987. return rc;
  5988. resp = hwrm_req_hold(bp, req);
  5989. rc = hwrm_req_send_silent(bp, req);
  5990. if (!rc) {
  5991. struct bnxt_ctx_pg_info *ctx_pg;
  5992. struct bnxt_ctx_mem_info *ctx;
  5993. int i, tqm_rings;
  5994. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  5995. if (!ctx) {
  5996. rc = -ENOMEM;
  5997. goto ctx_err;
  5998. }
  5999. ctx->qp_max_entries = le32_to_cpu(resp->qp_max_entries);
  6000. ctx->qp_min_qp1_entries = le16_to_cpu(resp->qp_min_qp1_entries);
  6001. ctx->qp_max_l2_entries = le16_to_cpu(resp->qp_max_l2_entries);
  6002. ctx->qp_entry_size = le16_to_cpu(resp->qp_entry_size);
  6003. ctx->srq_max_l2_entries = le16_to_cpu(resp->srq_max_l2_entries);
  6004. ctx->srq_max_entries = le32_to_cpu(resp->srq_max_entries);
  6005. ctx->srq_entry_size = le16_to_cpu(resp->srq_entry_size);
  6006. ctx->cq_max_l2_entries = le16_to_cpu(resp->cq_max_l2_entries);
  6007. ctx->cq_max_entries = le32_to_cpu(resp->cq_max_entries);
  6008. ctx->cq_entry_size = le16_to_cpu(resp->cq_entry_size);
  6009. ctx->vnic_max_vnic_entries =
  6010. le16_to_cpu(resp->vnic_max_vnic_entries);
  6011. ctx->vnic_max_ring_table_entries =
  6012. le16_to_cpu(resp->vnic_max_ring_table_entries);
  6013. ctx->vnic_entry_size = le16_to_cpu(resp->vnic_entry_size);
  6014. ctx->stat_max_entries = le32_to_cpu(resp->stat_max_entries);
  6015. ctx->stat_entry_size = le16_to_cpu(resp->stat_entry_size);
  6016. ctx->tqm_entry_size = le16_to_cpu(resp->tqm_entry_size);
  6017. ctx->tqm_min_entries_per_ring =
  6018. le32_to_cpu(resp->tqm_min_entries_per_ring);
  6019. ctx->tqm_max_entries_per_ring =
  6020. le32_to_cpu(resp->tqm_max_entries_per_ring);
  6021. ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
  6022. if (!ctx->tqm_entries_multiple)
  6023. ctx->tqm_entries_multiple = 1;
  6024. ctx->mrav_max_entries = le32_to_cpu(resp->mrav_max_entries);
  6025. ctx->mrav_entry_size = le16_to_cpu(resp->mrav_entry_size);
  6026. ctx->mrav_num_entries_units =
  6027. le16_to_cpu(resp->mrav_num_entries_units);
  6028. ctx->tim_entry_size = le16_to_cpu(resp->tim_entry_size);
  6029. ctx->tim_max_entries = le32_to_cpu(resp->tim_max_entries);
  6030. bnxt_init_ctx_initializer(ctx, resp);
  6031. ctx->tqm_fp_rings_count = resp->tqm_fp_rings_count;
  6032. if (!ctx->tqm_fp_rings_count)
  6033. ctx->tqm_fp_rings_count = bp->max_q;
  6034. else if (ctx->tqm_fp_rings_count > BNXT_MAX_TQM_FP_RINGS)
  6035. ctx->tqm_fp_rings_count = BNXT_MAX_TQM_FP_RINGS;
  6036. tqm_rings = ctx->tqm_fp_rings_count + BNXT_MAX_TQM_SP_RINGS;
  6037. ctx_pg = kcalloc(tqm_rings, sizeof(*ctx_pg), GFP_KERNEL);
  6038. if (!ctx_pg) {
  6039. kfree(ctx);
  6040. rc = -ENOMEM;
  6041. goto ctx_err;
  6042. }
  6043. for (i = 0; i < tqm_rings; i++, ctx_pg++)
  6044. ctx->tqm_mem[i] = ctx_pg;
  6045. bp->ctx = ctx;
  6046. } else {
  6047. rc = 0;
  6048. }
  6049. ctx_err:
  6050. hwrm_req_drop(bp, req);
  6051. return rc;
  6052. }
  6053. static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem, u8 *pg_attr,
  6054. __le64 *pg_dir)
  6055. {
  6056. if (!rmem->nr_pages)
  6057. return;
  6058. BNXT_SET_CTX_PAGE_ATTR(*pg_attr);
  6059. if (rmem->depth >= 1) {
  6060. if (rmem->depth == 2)
  6061. *pg_attr |= 2;
  6062. else
  6063. *pg_attr |= 1;
  6064. *pg_dir = cpu_to_le64(rmem->pg_tbl_map);
  6065. } else {
  6066. *pg_dir = cpu_to_le64(rmem->dma_arr[0]);
  6067. }
  6068. }
  6069. #define FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES \
  6070. (FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP | \
  6071. FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ | \
  6072. FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ | \
  6073. FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC | \
  6074. FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT)
  6075. static int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, u32 enables)
  6076. {
  6077. struct hwrm_func_backing_store_cfg_input *req;
  6078. struct bnxt_ctx_mem_info *ctx = bp->ctx;
  6079. struct bnxt_ctx_pg_info *ctx_pg;
  6080. void **__req = (void **)&req;
  6081. u32 req_len = sizeof(*req);
  6082. __le32 *num_entries;
  6083. __le64 *pg_dir;
  6084. u32 flags = 0;
  6085. u8 *pg_attr;
  6086. u32 ena;
  6087. int rc;
  6088. int i;
  6089. if (!ctx)
  6090. return 0;
  6091. if (req_len > bp->hwrm_max_ext_req_len)
  6092. req_len = BNXT_BACKING_STORE_CFG_LEGACY_LEN;
  6093. rc = __hwrm_req_init(bp, __req, HWRM_FUNC_BACKING_STORE_CFG, req_len);
  6094. if (rc)
  6095. return rc;
  6096. req->enables = cpu_to_le32(enables);
  6097. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP) {
  6098. ctx_pg = &ctx->qp_mem;
  6099. req->qp_num_entries = cpu_to_le32(ctx_pg->entries);
  6100. req->qp_num_qp1_entries = cpu_to_le16(ctx->qp_min_qp1_entries);
  6101. req->qp_num_l2_entries = cpu_to_le16(ctx->qp_max_l2_entries);
  6102. req->qp_entry_size = cpu_to_le16(ctx->qp_entry_size);
  6103. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6104. &req->qpc_pg_size_qpc_lvl,
  6105. &req->qpc_page_dir);
  6106. }
  6107. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ) {
  6108. ctx_pg = &ctx->srq_mem;
  6109. req->srq_num_entries = cpu_to_le32(ctx_pg->entries);
  6110. req->srq_num_l2_entries = cpu_to_le16(ctx->srq_max_l2_entries);
  6111. req->srq_entry_size = cpu_to_le16(ctx->srq_entry_size);
  6112. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6113. &req->srq_pg_size_srq_lvl,
  6114. &req->srq_page_dir);
  6115. }
  6116. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ) {
  6117. ctx_pg = &ctx->cq_mem;
  6118. req->cq_num_entries = cpu_to_le32(ctx_pg->entries);
  6119. req->cq_num_l2_entries = cpu_to_le16(ctx->cq_max_l2_entries);
  6120. req->cq_entry_size = cpu_to_le16(ctx->cq_entry_size);
  6121. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6122. &req->cq_pg_size_cq_lvl,
  6123. &req->cq_page_dir);
  6124. }
  6125. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC) {
  6126. ctx_pg = &ctx->vnic_mem;
  6127. req->vnic_num_vnic_entries =
  6128. cpu_to_le16(ctx->vnic_max_vnic_entries);
  6129. req->vnic_num_ring_table_entries =
  6130. cpu_to_le16(ctx->vnic_max_ring_table_entries);
  6131. req->vnic_entry_size = cpu_to_le16(ctx->vnic_entry_size);
  6132. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6133. &req->vnic_pg_size_vnic_lvl,
  6134. &req->vnic_page_dir);
  6135. }
  6136. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT) {
  6137. ctx_pg = &ctx->stat_mem;
  6138. req->stat_num_entries = cpu_to_le32(ctx->stat_max_entries);
  6139. req->stat_entry_size = cpu_to_le16(ctx->stat_entry_size);
  6140. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6141. &req->stat_pg_size_stat_lvl,
  6142. &req->stat_page_dir);
  6143. }
  6144. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV) {
  6145. ctx_pg = &ctx->mrav_mem;
  6146. req->mrav_num_entries = cpu_to_le32(ctx_pg->entries);
  6147. if (ctx->mrav_num_entries_units)
  6148. flags |=
  6149. FUNC_BACKING_STORE_CFG_REQ_FLAGS_MRAV_RESERVATION_SPLIT;
  6150. req->mrav_entry_size = cpu_to_le16(ctx->mrav_entry_size);
  6151. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6152. &req->mrav_pg_size_mrav_lvl,
  6153. &req->mrav_page_dir);
  6154. }
  6155. if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM) {
  6156. ctx_pg = &ctx->tim_mem;
  6157. req->tim_num_entries = cpu_to_le32(ctx_pg->entries);
  6158. req->tim_entry_size = cpu_to_le16(ctx->tim_entry_size);
  6159. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
  6160. &req->tim_pg_size_tim_lvl,
  6161. &req->tim_page_dir);
  6162. }
  6163. for (i = 0, num_entries = &req->tqm_sp_num_entries,
  6164. pg_attr = &req->tqm_sp_pg_size_tqm_sp_lvl,
  6165. pg_dir = &req->tqm_sp_page_dir,
  6166. ena = FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP;
  6167. i < BNXT_MAX_TQM_RINGS;
  6168. i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
  6169. if (!(enables & ena))
  6170. continue;
  6171. req->tqm_entry_size = cpu_to_le16(ctx->tqm_entry_size);
  6172. ctx_pg = ctx->tqm_mem[i];
  6173. *num_entries = cpu_to_le32(ctx_pg->entries);
  6174. bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
  6175. }
  6176. req->flags = cpu_to_le32(flags);
  6177. return hwrm_req_send(bp, req);
  6178. }
  6179. static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
  6180. struct bnxt_ctx_pg_info *ctx_pg)
  6181. {
  6182. struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
  6183. rmem->page_size = BNXT_PAGE_SIZE;
  6184. rmem->pg_arr = ctx_pg->ctx_pg_arr;
  6185. rmem->dma_arr = ctx_pg->ctx_dma_arr;
  6186. rmem->flags = BNXT_RMEM_VALID_PTE_FLAG;
  6187. if (rmem->depth >= 1)
  6188. rmem->flags |= BNXT_RMEM_USE_FULL_PAGE_FLAG;
  6189. return bnxt_alloc_ring(bp, rmem);
  6190. }
  6191. static int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp,
  6192. struct bnxt_ctx_pg_info *ctx_pg, u32 mem_size,
  6193. u8 depth, struct bnxt_mem_init *mem_init)
  6194. {
  6195. struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
  6196. int rc;
  6197. if (!mem_size)
  6198. return -EINVAL;
  6199. ctx_pg->nr_pages = DIV_ROUND_UP(mem_size, BNXT_PAGE_SIZE);
  6200. if (ctx_pg->nr_pages > MAX_CTX_TOTAL_PAGES) {
  6201. ctx_pg->nr_pages = 0;
  6202. return -EINVAL;
  6203. }
  6204. if (ctx_pg->nr_pages > MAX_CTX_PAGES || depth > 1) {
  6205. int nr_tbls, i;
  6206. rmem->depth = 2;
  6207. ctx_pg->ctx_pg_tbl = kcalloc(MAX_CTX_PAGES, sizeof(ctx_pg),
  6208. GFP_KERNEL);
  6209. if (!ctx_pg->ctx_pg_tbl)
  6210. return -ENOMEM;
  6211. nr_tbls = DIV_ROUND_UP(ctx_pg->nr_pages, MAX_CTX_PAGES);
  6212. rmem->nr_pages = nr_tbls;
  6213. rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg);
  6214. if (rc)
  6215. return rc;
  6216. for (i = 0; i < nr_tbls; i++) {
  6217. struct bnxt_ctx_pg_info *pg_tbl;
  6218. pg_tbl = kzalloc(sizeof(*pg_tbl), GFP_KERNEL);
  6219. if (!pg_tbl)
  6220. return -ENOMEM;
  6221. ctx_pg->ctx_pg_tbl[i] = pg_tbl;
  6222. rmem = &pg_tbl->ring_mem;
  6223. rmem->pg_tbl = ctx_pg->ctx_pg_arr[i];
  6224. rmem->pg_tbl_map = ctx_pg->ctx_dma_arr[i];
  6225. rmem->depth = 1;
  6226. rmem->nr_pages = MAX_CTX_PAGES;
  6227. rmem->mem_init = mem_init;
  6228. if (i == (nr_tbls - 1)) {
  6229. int rem = ctx_pg->nr_pages % MAX_CTX_PAGES;
  6230. if (rem)
  6231. rmem->nr_pages = rem;
  6232. }
  6233. rc = bnxt_alloc_ctx_mem_blk(bp, pg_tbl);
  6234. if (rc)
  6235. break;
  6236. }
  6237. } else {
  6238. rmem->nr_pages = DIV_ROUND_UP(mem_size, BNXT_PAGE_SIZE);
  6239. if (rmem->nr_pages > 1 || depth)
  6240. rmem->depth = 1;
  6241. rmem->mem_init = mem_init;
  6242. rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg);
  6243. }
  6244. return rc;
  6245. }
  6246. static void bnxt_free_ctx_pg_tbls(struct bnxt *bp,
  6247. struct bnxt_ctx_pg_info *ctx_pg)
  6248. {
  6249. struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
  6250. if (rmem->depth > 1 || ctx_pg->nr_pages > MAX_CTX_PAGES ||
  6251. ctx_pg->ctx_pg_tbl) {
  6252. int i, nr_tbls = rmem->nr_pages;
  6253. for (i = 0; i < nr_tbls; i++) {
  6254. struct bnxt_ctx_pg_info *pg_tbl;
  6255. struct bnxt_ring_mem_info *rmem2;
  6256. pg_tbl = ctx_pg->ctx_pg_tbl[i];
  6257. if (!pg_tbl)
  6258. continue;
  6259. rmem2 = &pg_tbl->ring_mem;
  6260. bnxt_free_ring(bp, rmem2);
  6261. ctx_pg->ctx_pg_arr[i] = NULL;
  6262. kfree(pg_tbl);
  6263. ctx_pg->ctx_pg_tbl[i] = NULL;
  6264. }
  6265. kfree(ctx_pg->ctx_pg_tbl);
  6266. ctx_pg->ctx_pg_tbl = NULL;
  6267. }
  6268. bnxt_free_ring(bp, rmem);
  6269. ctx_pg->nr_pages = 0;
  6270. }
  6271. void bnxt_free_ctx_mem(struct bnxt *bp)
  6272. {
  6273. struct bnxt_ctx_mem_info *ctx = bp->ctx;
  6274. int i;
  6275. if (!ctx)
  6276. return;
  6277. if (ctx->tqm_mem[0]) {
  6278. for (i = 0; i < ctx->tqm_fp_rings_count + 1; i++)
  6279. bnxt_free_ctx_pg_tbls(bp, ctx->tqm_mem[i]);
  6280. kfree(ctx->tqm_mem[0]);
  6281. ctx->tqm_mem[0] = NULL;
  6282. }
  6283. bnxt_free_ctx_pg_tbls(bp, &ctx->tim_mem);
  6284. bnxt_free_ctx_pg_tbls(bp, &ctx->mrav_mem);
  6285. bnxt_free_ctx_pg_tbls(bp, &ctx->stat_mem);
  6286. bnxt_free_ctx_pg_tbls(bp, &ctx->vnic_mem);
  6287. bnxt_free_ctx_pg_tbls(bp, &ctx->cq_mem);
  6288. bnxt_free_ctx_pg_tbls(bp, &ctx->srq_mem);
  6289. bnxt_free_ctx_pg_tbls(bp, &ctx->qp_mem);
  6290. ctx->flags &= ~BNXT_CTX_FLAG_INITED;
  6291. }
  6292. static int bnxt_alloc_ctx_mem(struct bnxt *bp)
  6293. {
  6294. struct bnxt_ctx_pg_info *ctx_pg;
  6295. struct bnxt_ctx_mem_info *ctx;
  6296. struct bnxt_mem_init *init;
  6297. u32 mem_size, ena, entries;
  6298. u32 entries_sp, min;
  6299. u32 num_mr, num_ah;
  6300. u32 extra_srqs = 0;
  6301. u32 extra_qps = 0;
  6302. u8 pg_lvl = 1;
  6303. int i, rc;
  6304. rc = bnxt_hwrm_func_backing_store_qcaps(bp);
  6305. if (rc) {
  6306. netdev_err(bp->dev, "Failed querying context mem capability, rc = %d.\n",
  6307. rc);
  6308. return rc;
  6309. }
  6310. ctx = bp->ctx;
  6311. if (!ctx || (ctx->flags & BNXT_CTX_FLAG_INITED))
  6312. return 0;
  6313. if ((bp->flags & BNXT_FLAG_ROCE_CAP) && !is_kdump_kernel()) {
  6314. pg_lvl = 2;
  6315. extra_qps = 65536;
  6316. extra_srqs = 8192;
  6317. }
  6318. ctx_pg = &ctx->qp_mem;
  6319. ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries +
  6320. extra_qps;
  6321. if (ctx->qp_entry_size) {
  6322. mem_size = ctx->qp_entry_size * ctx_pg->entries;
  6323. init = &ctx->mem_init[BNXT_CTX_MEM_INIT_QP];
  6324. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, pg_lvl, init);
  6325. if (rc)
  6326. return rc;
  6327. }
  6328. ctx_pg = &ctx->srq_mem;
  6329. ctx_pg->entries = ctx->srq_max_l2_entries + extra_srqs;
  6330. if (ctx->srq_entry_size) {
  6331. mem_size = ctx->srq_entry_size * ctx_pg->entries;
  6332. init = &ctx->mem_init[BNXT_CTX_MEM_INIT_SRQ];
  6333. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, pg_lvl, init);
  6334. if (rc)
  6335. return rc;
  6336. }
  6337. ctx_pg = &ctx->cq_mem;
  6338. ctx_pg->entries = ctx->cq_max_l2_entries + extra_qps * 2;
  6339. if (ctx->cq_entry_size) {
  6340. mem_size = ctx->cq_entry_size * ctx_pg->entries;
  6341. init = &ctx->mem_init[BNXT_CTX_MEM_INIT_CQ];
  6342. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, pg_lvl, init);
  6343. if (rc)
  6344. return rc;
  6345. }
  6346. ctx_pg = &ctx->vnic_mem;
  6347. ctx_pg->entries = ctx->vnic_max_vnic_entries +
  6348. ctx->vnic_max_ring_table_entries;
  6349. if (ctx->vnic_entry_size) {
  6350. mem_size = ctx->vnic_entry_size * ctx_pg->entries;
  6351. init = &ctx->mem_init[BNXT_CTX_MEM_INIT_VNIC];
  6352. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, init);
  6353. if (rc)
  6354. return rc;
  6355. }
  6356. ctx_pg = &ctx->stat_mem;
  6357. ctx_pg->entries = ctx->stat_max_entries;
  6358. if (ctx->stat_entry_size) {
  6359. mem_size = ctx->stat_entry_size * ctx_pg->entries;
  6360. init = &ctx->mem_init[BNXT_CTX_MEM_INIT_STAT];
  6361. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, init);
  6362. if (rc)
  6363. return rc;
  6364. }
  6365. ena = 0;
  6366. if (!(bp->flags & BNXT_FLAG_ROCE_CAP))
  6367. goto skip_rdma;
  6368. ctx_pg = &ctx->mrav_mem;
  6369. /* 128K extra is needed to accommodate static AH context
  6370. * allocation by f/w.
  6371. */
  6372. num_mr = 1024 * 256;
  6373. num_ah = 1024 * 128;
  6374. ctx_pg->entries = num_mr + num_ah;
  6375. if (ctx->mrav_entry_size) {
  6376. mem_size = ctx->mrav_entry_size * ctx_pg->entries;
  6377. init = &ctx->mem_init[BNXT_CTX_MEM_INIT_MRAV];
  6378. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 2, init);
  6379. if (rc)
  6380. return rc;
  6381. }
  6382. ena = FUNC_BACKING_STORE_CFG_REQ_ENABLES_MRAV;
  6383. if (ctx->mrav_num_entries_units)
  6384. ctx_pg->entries =
  6385. ((num_mr / ctx->mrav_num_entries_units) << 16) |
  6386. (num_ah / ctx->mrav_num_entries_units);
  6387. ctx_pg = &ctx->tim_mem;
  6388. ctx_pg->entries = ctx->qp_mem.entries;
  6389. if (ctx->tim_entry_size) {
  6390. mem_size = ctx->tim_entry_size * ctx_pg->entries;
  6391. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1, NULL);
  6392. if (rc)
  6393. return rc;
  6394. }
  6395. ena |= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TIM;
  6396. skip_rdma:
  6397. min = ctx->tqm_min_entries_per_ring;
  6398. entries_sp = ctx->vnic_max_vnic_entries + ctx->qp_max_l2_entries +
  6399. 2 * (extra_qps + ctx->qp_min_qp1_entries) + min;
  6400. entries_sp = roundup(entries_sp, ctx->tqm_entries_multiple);
  6401. entries = ctx->qp_max_l2_entries + 2 * (extra_qps + ctx->qp_min_qp1_entries);
  6402. entries = roundup(entries, ctx->tqm_entries_multiple);
  6403. entries = clamp_t(u32, entries, min, ctx->tqm_max_entries_per_ring);
  6404. for (i = 0; i < ctx->tqm_fp_rings_count + 1; i++) {
  6405. ctx_pg = ctx->tqm_mem[i];
  6406. ctx_pg->entries = i ? entries : entries_sp;
  6407. if (ctx->tqm_entry_size) {
  6408. mem_size = ctx->tqm_entry_size * ctx_pg->entries;
  6409. rc = bnxt_alloc_ctx_pg_tbls(bp, ctx_pg, mem_size, 1,
  6410. NULL);
  6411. if (rc)
  6412. return rc;
  6413. }
  6414. ena |= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP << i;
  6415. }
  6416. ena |= FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES;
  6417. rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
  6418. if (rc) {
  6419. netdev_err(bp->dev, "Failed configuring context mem, rc = %d.\n",
  6420. rc);
  6421. return rc;
  6422. }
  6423. ctx->flags |= BNXT_CTX_FLAG_INITED;
  6424. return 0;
  6425. }
  6426. int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all)
  6427. {
  6428. struct hwrm_func_resource_qcaps_output *resp;
  6429. struct hwrm_func_resource_qcaps_input *req;
  6430. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  6431. int rc;
  6432. rc = hwrm_req_init(bp, req, HWRM_FUNC_RESOURCE_QCAPS);
  6433. if (rc)
  6434. return rc;
  6435. req->fid = cpu_to_le16(0xffff);
  6436. resp = hwrm_req_hold(bp, req);
  6437. rc = hwrm_req_send_silent(bp, req);
  6438. if (rc)
  6439. goto hwrm_func_resc_qcaps_exit;
  6440. hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
  6441. if (!all)
  6442. goto hwrm_func_resc_qcaps_exit;
  6443. hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx);
  6444. hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
  6445. hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings);
  6446. hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
  6447. hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings);
  6448. hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
  6449. hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings);
  6450. hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
  6451. hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps);
  6452. hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps);
  6453. hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs);
  6454. hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
  6455. hw_resc->min_vnics = le16_to_cpu(resp->min_vnics);
  6456. hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
  6457. hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
  6458. hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
  6459. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  6460. u16 max_msix = le16_to_cpu(resp->max_msix);
  6461. hw_resc->max_nqs = max_msix;
  6462. hw_resc->max_hw_ring_grps = hw_resc->max_rx_rings;
  6463. }
  6464. if (BNXT_PF(bp)) {
  6465. struct bnxt_pf_info *pf = &bp->pf;
  6466. pf->vf_resv_strategy =
  6467. le16_to_cpu(resp->vf_reservation_strategy);
  6468. if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC)
  6469. pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL;
  6470. }
  6471. hwrm_func_resc_qcaps_exit:
  6472. hwrm_req_drop(bp, req);
  6473. return rc;
  6474. }
  6475. static int __bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
  6476. {
  6477. struct hwrm_port_mac_ptp_qcfg_output *resp;
  6478. struct hwrm_port_mac_ptp_qcfg_input *req;
  6479. struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
  6480. bool phc_cfg;
  6481. u8 flags;
  6482. int rc;
  6483. if (bp->hwrm_spec_code < 0x10801 || !BNXT_CHIP_P5_THOR(bp)) {
  6484. rc = -ENODEV;
  6485. goto no_ptp;
  6486. }
  6487. rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_PTP_QCFG);
  6488. if (rc)
  6489. goto no_ptp;
  6490. req->port_id = cpu_to_le16(bp->pf.port_id);
  6491. resp = hwrm_req_hold(bp, req);
  6492. rc = hwrm_req_send(bp, req);
  6493. if (rc)
  6494. goto exit;
  6495. flags = resp->flags;
  6496. if (!(flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_HWRM_ACCESS)) {
  6497. rc = -ENODEV;
  6498. goto exit;
  6499. }
  6500. if (!ptp) {
  6501. ptp = kzalloc(sizeof(*ptp), GFP_KERNEL);
  6502. if (!ptp) {
  6503. rc = -ENOMEM;
  6504. goto exit;
  6505. }
  6506. ptp->bp = bp;
  6507. bp->ptp_cfg = ptp;
  6508. }
  6509. if (flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_PARTIAL_DIRECT_ACCESS_REF_CLOCK) {
  6510. ptp->refclk_regs[0] = le32_to_cpu(resp->ts_ref_clock_reg_lower);
  6511. ptp->refclk_regs[1] = le32_to_cpu(resp->ts_ref_clock_reg_upper);
  6512. } else if (bp->flags & BNXT_FLAG_CHIP_P5) {
  6513. ptp->refclk_regs[0] = BNXT_TS_REG_TIMESYNC_TS0_LOWER;
  6514. ptp->refclk_regs[1] = BNXT_TS_REG_TIMESYNC_TS0_UPPER;
  6515. } else {
  6516. rc = -ENODEV;
  6517. goto exit;
  6518. }
  6519. phc_cfg = (flags & PORT_MAC_PTP_QCFG_RESP_FLAGS_RTC_CONFIGURED) != 0;
  6520. rc = bnxt_ptp_init(bp, phc_cfg);
  6521. if (rc)
  6522. netdev_warn(bp->dev, "PTP initialization failed.\n");
  6523. exit:
  6524. hwrm_req_drop(bp, req);
  6525. if (!rc)
  6526. return 0;
  6527. no_ptp:
  6528. bnxt_ptp_clear(bp);
  6529. kfree(ptp);
  6530. bp->ptp_cfg = NULL;
  6531. return rc;
  6532. }
  6533. static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
  6534. {
  6535. struct hwrm_func_qcaps_output *resp;
  6536. struct hwrm_func_qcaps_input *req;
  6537. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  6538. u32 flags, flags_ext, flags_ext2;
  6539. int rc;
  6540. rc = hwrm_req_init(bp, req, HWRM_FUNC_QCAPS);
  6541. if (rc)
  6542. return rc;
  6543. req->fid = cpu_to_le16(0xffff);
  6544. resp = hwrm_req_hold(bp, req);
  6545. rc = hwrm_req_send(bp, req);
  6546. if (rc)
  6547. goto hwrm_func_qcaps_exit;
  6548. flags = le32_to_cpu(resp->flags);
  6549. if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)
  6550. bp->flags |= BNXT_FLAG_ROCEV1_CAP;
  6551. if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
  6552. bp->flags |= BNXT_FLAG_ROCEV2_CAP;
  6553. if (flags & FUNC_QCAPS_RESP_FLAGS_PCIE_STATS_SUPPORTED)
  6554. bp->fw_cap |= BNXT_FW_CAP_PCIE_STATS_SUPPORTED;
  6555. if (flags & FUNC_QCAPS_RESP_FLAGS_HOT_RESET_CAPABLE)
  6556. bp->fw_cap |= BNXT_FW_CAP_HOT_RESET;
  6557. if (flags & FUNC_QCAPS_RESP_FLAGS_EXT_STATS_SUPPORTED)
  6558. bp->fw_cap |= BNXT_FW_CAP_EXT_STATS_SUPPORTED;
  6559. if (flags & FUNC_QCAPS_RESP_FLAGS_ERROR_RECOVERY_CAPABLE)
  6560. bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY;
  6561. if (flags & FUNC_QCAPS_RESP_FLAGS_ERR_RECOVER_RELOAD)
  6562. bp->fw_cap |= BNXT_FW_CAP_ERR_RECOVER_RELOAD;
  6563. if (!(flags & FUNC_QCAPS_RESP_FLAGS_VLAN_ACCELERATION_TX_DISABLED))
  6564. bp->fw_cap |= BNXT_FW_CAP_VLAN_TX_INSERT;
  6565. if (flags & FUNC_QCAPS_RESP_FLAGS_DBG_QCAPS_CMD_SUPPORTED)
  6566. bp->fw_cap |= BNXT_FW_CAP_DBG_QCAPS;
  6567. flags_ext = le32_to_cpu(resp->flags_ext);
  6568. if (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_EXT_HW_STATS_SUPPORTED)
  6569. bp->fw_cap |= BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED;
  6570. if (BNXT_PF(bp) && (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_PTP_PPS_SUPPORTED))
  6571. bp->fw_cap |= BNXT_FW_CAP_PTP_PPS;
  6572. if (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_PTP_64BIT_RTC_SUPPORTED)
  6573. bp->fw_cap |= BNXT_FW_CAP_PTP_RTC;
  6574. if (BNXT_PF(bp) && (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_HOT_RESET_IF_SUPPORT))
  6575. bp->fw_cap |= BNXT_FW_CAP_HOT_RESET_IF;
  6576. if (BNXT_PF(bp) && (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_FW_LIVEPATCH_SUPPORTED))
  6577. bp->fw_cap |= BNXT_FW_CAP_LIVEPATCH;
  6578. flags_ext2 = le32_to_cpu(resp->flags_ext2);
  6579. if (flags_ext2 & FUNC_QCAPS_RESP_FLAGS_EXT2_RX_ALL_PKTS_TIMESTAMPS_SUPPORTED)
  6580. bp->fw_cap |= BNXT_FW_CAP_RX_ALL_PKT_TS;
  6581. bp->tx_push_thresh = 0;
  6582. if ((flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) &&
  6583. BNXT_FW_MAJ(bp) > 217)
  6584. bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
  6585. hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
  6586. hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
  6587. hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
  6588. hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
  6589. hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
  6590. if (!hw_resc->max_hw_ring_grps)
  6591. hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings;
  6592. hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
  6593. hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
  6594. hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
  6595. if (BNXT_PF(bp)) {
  6596. struct bnxt_pf_info *pf = &bp->pf;
  6597. pf->fw_fid = le16_to_cpu(resp->fid);
  6598. pf->port_id = le16_to_cpu(resp->port_id);
  6599. memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
  6600. pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
  6601. pf->max_vfs = le16_to_cpu(resp->max_vfs);
  6602. pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
  6603. pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
  6604. pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
  6605. pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
  6606. pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
  6607. pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
  6608. bp->flags &= ~BNXT_FLAG_WOL_CAP;
  6609. if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED)
  6610. bp->flags |= BNXT_FLAG_WOL_CAP;
  6611. if (flags & FUNC_QCAPS_RESP_FLAGS_PTP_SUPPORTED) {
  6612. __bnxt_hwrm_ptp_qcfg(bp);
  6613. } else {
  6614. bnxt_ptp_clear(bp);
  6615. kfree(bp->ptp_cfg);
  6616. bp->ptp_cfg = NULL;
  6617. }
  6618. } else {
  6619. #ifdef CONFIG_BNXT_SRIOV
  6620. struct bnxt_vf_info *vf = &bp->vf;
  6621. vf->fw_fid = le16_to_cpu(resp->fid);
  6622. memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
  6623. #endif
  6624. }
  6625. hwrm_func_qcaps_exit:
  6626. hwrm_req_drop(bp, req);
  6627. return rc;
  6628. }
  6629. static void bnxt_hwrm_dbg_qcaps(struct bnxt *bp)
  6630. {
  6631. struct hwrm_dbg_qcaps_output *resp;
  6632. struct hwrm_dbg_qcaps_input *req;
  6633. int rc;
  6634. bp->fw_dbg_cap = 0;
  6635. if (!(bp->fw_cap & BNXT_FW_CAP_DBG_QCAPS))
  6636. return;
  6637. rc = hwrm_req_init(bp, req, HWRM_DBG_QCAPS);
  6638. if (rc)
  6639. return;
  6640. req->fid = cpu_to_le16(0xffff);
  6641. resp = hwrm_req_hold(bp, req);
  6642. rc = hwrm_req_send(bp, req);
  6643. if (rc)
  6644. goto hwrm_dbg_qcaps_exit;
  6645. bp->fw_dbg_cap = le32_to_cpu(resp->flags);
  6646. hwrm_dbg_qcaps_exit:
  6647. hwrm_req_drop(bp, req);
  6648. }
  6649. static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp);
  6650. int bnxt_hwrm_func_qcaps(struct bnxt *bp)
  6651. {
  6652. int rc;
  6653. rc = __bnxt_hwrm_func_qcaps(bp);
  6654. if (rc)
  6655. return rc;
  6656. bnxt_hwrm_dbg_qcaps(bp);
  6657. rc = bnxt_hwrm_queue_qportcfg(bp);
  6658. if (rc) {
  6659. netdev_err(bp->dev, "hwrm query qportcfg failure rc: %d\n", rc);
  6660. return rc;
  6661. }
  6662. if (bp->hwrm_spec_code >= 0x10803) {
  6663. rc = bnxt_alloc_ctx_mem(bp);
  6664. if (rc)
  6665. return rc;
  6666. rc = bnxt_hwrm_func_resc_qcaps(bp, true);
  6667. if (!rc)
  6668. bp->fw_cap |= BNXT_FW_CAP_NEW_RM;
  6669. }
  6670. return 0;
  6671. }
  6672. static int bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(struct bnxt *bp)
  6673. {
  6674. struct hwrm_cfa_adv_flow_mgnt_qcaps_output *resp;
  6675. struct hwrm_cfa_adv_flow_mgnt_qcaps_input *req;
  6676. u32 flags;
  6677. int rc;
  6678. if (!(bp->fw_cap & BNXT_FW_CAP_CFA_ADV_FLOW))
  6679. return 0;
  6680. rc = hwrm_req_init(bp, req, HWRM_CFA_ADV_FLOW_MGNT_QCAPS);
  6681. if (rc)
  6682. return rc;
  6683. resp = hwrm_req_hold(bp, req);
  6684. rc = hwrm_req_send(bp, req);
  6685. if (rc)
  6686. goto hwrm_cfa_adv_qcaps_exit;
  6687. flags = le32_to_cpu(resp->flags);
  6688. if (flags &
  6689. CFA_ADV_FLOW_MGNT_QCAPS_RESP_FLAGS_RFS_RING_TBL_IDX_V2_SUPPORTED)
  6690. bp->fw_cap |= BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2;
  6691. hwrm_cfa_adv_qcaps_exit:
  6692. hwrm_req_drop(bp, req);
  6693. return rc;
  6694. }
  6695. static int __bnxt_alloc_fw_health(struct bnxt *bp)
  6696. {
  6697. if (bp->fw_health)
  6698. return 0;
  6699. bp->fw_health = kzalloc(sizeof(*bp->fw_health), GFP_KERNEL);
  6700. if (!bp->fw_health)
  6701. return -ENOMEM;
  6702. mutex_init(&bp->fw_health->lock);
  6703. return 0;
  6704. }
  6705. static int bnxt_alloc_fw_health(struct bnxt *bp)
  6706. {
  6707. int rc;
  6708. if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET) &&
  6709. !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
  6710. return 0;
  6711. rc = __bnxt_alloc_fw_health(bp);
  6712. if (rc) {
  6713. bp->fw_cap &= ~BNXT_FW_CAP_HOT_RESET;
  6714. bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
  6715. return rc;
  6716. }
  6717. return 0;
  6718. }
  6719. static void __bnxt_map_fw_health_reg(struct bnxt *bp, u32 reg)
  6720. {
  6721. writel(reg & BNXT_GRC_BASE_MASK, bp->bar0 +
  6722. BNXT_GRCPF_REG_WINDOW_BASE_OUT +
  6723. BNXT_FW_HEALTH_WIN_MAP_OFF);
  6724. }
  6725. static void bnxt_inv_fw_health_reg(struct bnxt *bp)
  6726. {
  6727. struct bnxt_fw_health *fw_health = bp->fw_health;
  6728. u32 reg_type;
  6729. if (!fw_health)
  6730. return;
  6731. reg_type = BNXT_FW_HEALTH_REG_TYPE(fw_health->regs[BNXT_FW_HEALTH_REG]);
  6732. if (reg_type == BNXT_FW_HEALTH_REG_TYPE_GRC)
  6733. fw_health->status_reliable = false;
  6734. reg_type = BNXT_FW_HEALTH_REG_TYPE(fw_health->regs[BNXT_FW_RESET_CNT_REG]);
  6735. if (reg_type == BNXT_FW_HEALTH_REG_TYPE_GRC)
  6736. fw_health->resets_reliable = false;
  6737. }
  6738. static void bnxt_try_map_fw_health_reg(struct bnxt *bp)
  6739. {
  6740. void __iomem *hs;
  6741. u32 status_loc;
  6742. u32 reg_type;
  6743. u32 sig;
  6744. if (bp->fw_health)
  6745. bp->fw_health->status_reliable = false;
  6746. __bnxt_map_fw_health_reg(bp, HCOMM_STATUS_STRUCT_LOC);
  6747. hs = bp->bar0 + BNXT_FW_HEALTH_WIN_OFF(HCOMM_STATUS_STRUCT_LOC);
  6748. sig = readl(hs + offsetof(struct hcomm_status, sig_ver));
  6749. if ((sig & HCOMM_STATUS_SIGNATURE_MASK) != HCOMM_STATUS_SIGNATURE_VAL) {
  6750. if (!bp->chip_num) {
  6751. __bnxt_map_fw_health_reg(bp, BNXT_GRC_REG_BASE);
  6752. bp->chip_num = readl(bp->bar0 +
  6753. BNXT_FW_HEALTH_WIN_BASE +
  6754. BNXT_GRC_REG_CHIP_NUM);
  6755. }
  6756. if (!BNXT_CHIP_P5(bp))
  6757. return;
  6758. status_loc = BNXT_GRC_REG_STATUS_P5 |
  6759. BNXT_FW_HEALTH_REG_TYPE_BAR0;
  6760. } else {
  6761. status_loc = readl(hs + offsetof(struct hcomm_status,
  6762. fw_status_loc));
  6763. }
  6764. if (__bnxt_alloc_fw_health(bp)) {
  6765. netdev_warn(bp->dev, "no memory for firmware status checks\n");
  6766. return;
  6767. }
  6768. bp->fw_health->regs[BNXT_FW_HEALTH_REG] = status_loc;
  6769. reg_type = BNXT_FW_HEALTH_REG_TYPE(status_loc);
  6770. if (reg_type == BNXT_FW_HEALTH_REG_TYPE_GRC) {
  6771. __bnxt_map_fw_health_reg(bp, status_loc);
  6772. bp->fw_health->mapped_regs[BNXT_FW_HEALTH_REG] =
  6773. BNXT_FW_HEALTH_WIN_OFF(status_loc);
  6774. }
  6775. bp->fw_health->status_reliable = true;
  6776. }
  6777. static int bnxt_map_fw_health_regs(struct bnxt *bp)
  6778. {
  6779. struct bnxt_fw_health *fw_health = bp->fw_health;
  6780. u32 reg_base = 0xffffffff;
  6781. int i;
  6782. bp->fw_health->status_reliable = false;
  6783. bp->fw_health->resets_reliable = false;
  6784. /* Only pre-map the monitoring GRC registers using window 3 */
  6785. for (i = 0; i < 4; i++) {
  6786. u32 reg = fw_health->regs[i];
  6787. if (BNXT_FW_HEALTH_REG_TYPE(reg) != BNXT_FW_HEALTH_REG_TYPE_GRC)
  6788. continue;
  6789. if (reg_base == 0xffffffff)
  6790. reg_base = reg & BNXT_GRC_BASE_MASK;
  6791. if ((reg & BNXT_GRC_BASE_MASK) != reg_base)
  6792. return -ERANGE;
  6793. fw_health->mapped_regs[i] = BNXT_FW_HEALTH_WIN_OFF(reg);
  6794. }
  6795. bp->fw_health->status_reliable = true;
  6796. bp->fw_health->resets_reliable = true;
  6797. if (reg_base == 0xffffffff)
  6798. return 0;
  6799. __bnxt_map_fw_health_reg(bp, reg_base);
  6800. return 0;
  6801. }
  6802. static void bnxt_remap_fw_health_regs(struct bnxt *bp)
  6803. {
  6804. if (!bp->fw_health)
  6805. return;
  6806. if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY) {
  6807. bp->fw_health->status_reliable = true;
  6808. bp->fw_health->resets_reliable = true;
  6809. } else {
  6810. bnxt_try_map_fw_health_reg(bp);
  6811. }
  6812. }
  6813. static int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
  6814. {
  6815. struct bnxt_fw_health *fw_health = bp->fw_health;
  6816. struct hwrm_error_recovery_qcfg_output *resp;
  6817. struct hwrm_error_recovery_qcfg_input *req;
  6818. int rc, i;
  6819. if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
  6820. return 0;
  6821. rc = hwrm_req_init(bp, req, HWRM_ERROR_RECOVERY_QCFG);
  6822. if (rc)
  6823. return rc;
  6824. resp = hwrm_req_hold(bp, req);
  6825. rc = hwrm_req_send(bp, req);
  6826. if (rc)
  6827. goto err_recovery_out;
  6828. fw_health->flags = le32_to_cpu(resp->flags);
  6829. if ((fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) &&
  6830. !(bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL)) {
  6831. rc = -EINVAL;
  6832. goto err_recovery_out;
  6833. }
  6834. fw_health->polling_dsecs = le32_to_cpu(resp->driver_polling_freq);
  6835. fw_health->master_func_wait_dsecs =
  6836. le32_to_cpu(resp->master_func_wait_period);
  6837. fw_health->normal_func_wait_dsecs =
  6838. le32_to_cpu(resp->normal_func_wait_period);
  6839. fw_health->post_reset_wait_dsecs =
  6840. le32_to_cpu(resp->master_func_wait_period_after_reset);
  6841. fw_health->post_reset_max_wait_dsecs =
  6842. le32_to_cpu(resp->max_bailout_time_after_reset);
  6843. fw_health->regs[BNXT_FW_HEALTH_REG] =
  6844. le32_to_cpu(resp->fw_health_status_reg);
  6845. fw_health->regs[BNXT_FW_HEARTBEAT_REG] =
  6846. le32_to_cpu(resp->fw_heartbeat_reg);
  6847. fw_health->regs[BNXT_FW_RESET_CNT_REG] =
  6848. le32_to_cpu(resp->fw_reset_cnt_reg);
  6849. fw_health->regs[BNXT_FW_RESET_INPROG_REG] =
  6850. le32_to_cpu(resp->reset_inprogress_reg);
  6851. fw_health->fw_reset_inprog_reg_mask =
  6852. le32_to_cpu(resp->reset_inprogress_reg_mask);
  6853. fw_health->fw_reset_seq_cnt = resp->reg_array_cnt;
  6854. if (fw_health->fw_reset_seq_cnt >= 16) {
  6855. rc = -EINVAL;
  6856. goto err_recovery_out;
  6857. }
  6858. for (i = 0; i < fw_health->fw_reset_seq_cnt; i++) {
  6859. fw_health->fw_reset_seq_regs[i] =
  6860. le32_to_cpu(resp->reset_reg[i]);
  6861. fw_health->fw_reset_seq_vals[i] =
  6862. le32_to_cpu(resp->reset_reg_val[i]);
  6863. fw_health->fw_reset_seq_delay_msec[i] =
  6864. resp->delay_after_reset[i];
  6865. }
  6866. err_recovery_out:
  6867. hwrm_req_drop(bp, req);
  6868. if (!rc)
  6869. rc = bnxt_map_fw_health_regs(bp);
  6870. if (rc)
  6871. bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
  6872. return rc;
  6873. }
  6874. static int bnxt_hwrm_func_reset(struct bnxt *bp)
  6875. {
  6876. struct hwrm_func_reset_input *req;
  6877. int rc;
  6878. rc = hwrm_req_init(bp, req, HWRM_FUNC_RESET);
  6879. if (rc)
  6880. return rc;
  6881. req->enables = 0;
  6882. hwrm_req_timeout(bp, req, HWRM_RESET_TIMEOUT);
  6883. return hwrm_req_send(bp, req);
  6884. }
  6885. static void bnxt_nvm_cfg_ver_get(struct bnxt *bp)
  6886. {
  6887. struct hwrm_nvm_get_dev_info_output nvm_info;
  6888. if (!bnxt_hwrm_nvm_get_dev_info(bp, &nvm_info))
  6889. snprintf(bp->nvm_cfg_ver, FW_VER_STR_LEN, "%d.%d.%d",
  6890. nvm_info.nvm_cfg_ver_maj, nvm_info.nvm_cfg_ver_min,
  6891. nvm_info.nvm_cfg_ver_upd);
  6892. }
  6893. static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
  6894. {
  6895. struct hwrm_queue_qportcfg_output *resp;
  6896. struct hwrm_queue_qportcfg_input *req;
  6897. u8 i, j, *qptr;
  6898. bool no_rdma;
  6899. int rc = 0;
  6900. rc = hwrm_req_init(bp, req, HWRM_QUEUE_QPORTCFG);
  6901. if (rc)
  6902. return rc;
  6903. resp = hwrm_req_hold(bp, req);
  6904. rc = hwrm_req_send(bp, req);
  6905. if (rc)
  6906. goto qportcfg_exit;
  6907. if (!resp->max_configurable_queues) {
  6908. rc = -EINVAL;
  6909. goto qportcfg_exit;
  6910. }
  6911. bp->max_tc = resp->max_configurable_queues;
  6912. bp->max_lltc = resp->max_configurable_lossless_queues;
  6913. if (bp->max_tc > BNXT_MAX_QUEUE)
  6914. bp->max_tc = BNXT_MAX_QUEUE;
  6915. no_rdma = !(bp->flags & BNXT_FLAG_ROCE_CAP);
  6916. qptr = &resp->queue_id0;
  6917. for (i = 0, j = 0; i < bp->max_tc; i++) {
  6918. bp->q_info[j].queue_id = *qptr;
  6919. bp->q_ids[i] = *qptr++;
  6920. bp->q_info[j].queue_profile = *qptr++;
  6921. bp->tc_to_qidx[j] = j;
  6922. if (!BNXT_CNPQ(bp->q_info[j].queue_profile) ||
  6923. (no_rdma && BNXT_PF(bp)))
  6924. j++;
  6925. }
  6926. bp->max_q = bp->max_tc;
  6927. bp->max_tc = max_t(u8, j, 1);
  6928. if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
  6929. bp->max_tc = 1;
  6930. if (bp->max_lltc > bp->max_tc)
  6931. bp->max_lltc = bp->max_tc;
  6932. qportcfg_exit:
  6933. hwrm_req_drop(bp, req);
  6934. return rc;
  6935. }
  6936. static int bnxt_hwrm_poll(struct bnxt *bp)
  6937. {
  6938. struct hwrm_ver_get_input *req;
  6939. int rc;
  6940. rc = hwrm_req_init(bp, req, HWRM_VER_GET);
  6941. if (rc)
  6942. return rc;
  6943. req->hwrm_intf_maj = HWRM_VERSION_MAJOR;
  6944. req->hwrm_intf_min = HWRM_VERSION_MINOR;
  6945. req->hwrm_intf_upd = HWRM_VERSION_UPDATE;
  6946. hwrm_req_flags(bp, req, BNXT_HWRM_CTX_SILENT | BNXT_HWRM_FULL_WAIT);
  6947. rc = hwrm_req_send(bp, req);
  6948. return rc;
  6949. }
  6950. static int bnxt_hwrm_ver_get(struct bnxt *bp)
  6951. {
  6952. struct hwrm_ver_get_output *resp;
  6953. struct hwrm_ver_get_input *req;
  6954. u16 fw_maj, fw_min, fw_bld, fw_rsv;
  6955. u32 dev_caps_cfg, hwrm_ver;
  6956. int rc, len;
  6957. rc = hwrm_req_init(bp, req, HWRM_VER_GET);
  6958. if (rc)
  6959. return rc;
  6960. hwrm_req_flags(bp, req, BNXT_HWRM_FULL_WAIT);
  6961. bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
  6962. req->hwrm_intf_maj = HWRM_VERSION_MAJOR;
  6963. req->hwrm_intf_min = HWRM_VERSION_MINOR;
  6964. req->hwrm_intf_upd = HWRM_VERSION_UPDATE;
  6965. resp = hwrm_req_hold(bp, req);
  6966. rc = hwrm_req_send(bp, req);
  6967. if (rc)
  6968. goto hwrm_ver_get_exit;
  6969. memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
  6970. bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 |
  6971. resp->hwrm_intf_min_8b << 8 |
  6972. resp->hwrm_intf_upd_8b;
  6973. if (resp->hwrm_intf_maj_8b < 1) {
  6974. netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
  6975. resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
  6976. resp->hwrm_intf_upd_8b);
  6977. netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
  6978. }
  6979. hwrm_ver = HWRM_VERSION_MAJOR << 16 | HWRM_VERSION_MINOR << 8 |
  6980. HWRM_VERSION_UPDATE;
  6981. if (bp->hwrm_spec_code > hwrm_ver)
  6982. snprintf(bp->hwrm_ver_supp, FW_VER_STR_LEN, "%d.%d.%d",
  6983. HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR,
  6984. HWRM_VERSION_UPDATE);
  6985. else
  6986. snprintf(bp->hwrm_ver_supp, FW_VER_STR_LEN, "%d.%d.%d",
  6987. resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
  6988. resp->hwrm_intf_upd_8b);
  6989. fw_maj = le16_to_cpu(resp->hwrm_fw_major);
  6990. if (bp->hwrm_spec_code > 0x10803 && fw_maj) {
  6991. fw_min = le16_to_cpu(resp->hwrm_fw_minor);
  6992. fw_bld = le16_to_cpu(resp->hwrm_fw_build);
  6993. fw_rsv = le16_to_cpu(resp->hwrm_fw_patch);
  6994. len = FW_VER_STR_LEN;
  6995. } else {
  6996. fw_maj = resp->hwrm_fw_maj_8b;
  6997. fw_min = resp->hwrm_fw_min_8b;
  6998. fw_bld = resp->hwrm_fw_bld_8b;
  6999. fw_rsv = resp->hwrm_fw_rsvd_8b;
  7000. len = BC_HWRM_STR_LEN;
  7001. }
  7002. bp->fw_ver_code = BNXT_FW_VER_CODE(fw_maj, fw_min, fw_bld, fw_rsv);
  7003. snprintf(bp->fw_ver_str, len, "%d.%d.%d.%d", fw_maj, fw_min, fw_bld,
  7004. fw_rsv);
  7005. if (strlen(resp->active_pkg_name)) {
  7006. int fw_ver_len = strlen(bp->fw_ver_str);
  7007. snprintf(bp->fw_ver_str + fw_ver_len,
  7008. FW_VER_STR_LEN - fw_ver_len - 1, "/pkg %s",
  7009. resp->active_pkg_name);
  7010. bp->fw_cap |= BNXT_FW_CAP_PKG_VER;
  7011. }
  7012. bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
  7013. if (!bp->hwrm_cmd_timeout)
  7014. bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
  7015. bp->hwrm_cmd_max_timeout = le16_to_cpu(resp->max_req_timeout) * 1000;
  7016. if (!bp->hwrm_cmd_max_timeout)
  7017. bp->hwrm_cmd_max_timeout = HWRM_CMD_MAX_TIMEOUT;
  7018. else if (bp->hwrm_cmd_max_timeout > HWRM_CMD_MAX_TIMEOUT)
  7019. netdev_warn(bp->dev, "Device requests max timeout of %d seconds, may trigger hung task watchdog\n",
  7020. bp->hwrm_cmd_max_timeout / 1000);
  7021. if (resp->hwrm_intf_maj_8b >= 1) {
  7022. bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
  7023. bp->hwrm_max_ext_req_len = le16_to_cpu(resp->max_ext_req_len);
  7024. }
  7025. if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
  7026. bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
  7027. bp->chip_num = le16_to_cpu(resp->chip_num);
  7028. bp->chip_rev = resp->chip_rev;
  7029. if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
  7030. !resp->chip_metal)
  7031. bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
  7032. dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
  7033. if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
  7034. (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
  7035. bp->fw_cap |= BNXT_FW_CAP_SHORT_CMD;
  7036. if (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED)
  7037. bp->fw_cap |= BNXT_FW_CAP_KONG_MB_CHNL;
  7038. if (dev_caps_cfg &
  7039. VER_GET_RESP_DEV_CAPS_CFG_FLOW_HANDLE_64BIT_SUPPORTED)
  7040. bp->fw_cap |= BNXT_FW_CAP_OVS_64BIT_HANDLE;
  7041. if (dev_caps_cfg &
  7042. VER_GET_RESP_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
  7043. bp->fw_cap |= BNXT_FW_CAP_TRUSTED_VF;
  7044. if (dev_caps_cfg &
  7045. VER_GET_RESP_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED)
  7046. bp->fw_cap |= BNXT_FW_CAP_CFA_ADV_FLOW;
  7047. hwrm_ver_get_exit:
  7048. hwrm_req_drop(bp, req);
  7049. return rc;
  7050. }
  7051. int bnxt_hwrm_fw_set_time(struct bnxt *bp)
  7052. {
  7053. struct hwrm_fw_set_time_input *req;
  7054. struct tm tm;
  7055. time64_t now = ktime_get_real_seconds();
  7056. int rc;
  7057. if ((BNXT_VF(bp) && bp->hwrm_spec_code < 0x10901) ||
  7058. bp->hwrm_spec_code < 0x10400)
  7059. return -EOPNOTSUPP;
  7060. time64_to_tm(now, 0, &tm);
  7061. rc = hwrm_req_init(bp, req, HWRM_FW_SET_TIME);
  7062. if (rc)
  7063. return rc;
  7064. req->year = cpu_to_le16(1900 + tm.tm_year);
  7065. req->month = 1 + tm.tm_mon;
  7066. req->day = tm.tm_mday;
  7067. req->hour = tm.tm_hour;
  7068. req->minute = tm.tm_min;
  7069. req->second = tm.tm_sec;
  7070. return hwrm_req_send(bp, req);
  7071. }
  7072. static void bnxt_add_one_ctr(u64 hw, u64 *sw, u64 mask)
  7073. {
  7074. u64 sw_tmp;
  7075. hw &= mask;
  7076. sw_tmp = (*sw & ~mask) | hw;
  7077. if (hw < (*sw & mask))
  7078. sw_tmp += mask + 1;
  7079. WRITE_ONCE(*sw, sw_tmp);
  7080. }
  7081. static void __bnxt_accumulate_stats(__le64 *hw_stats, u64 *sw_stats, u64 *masks,
  7082. int count, bool ignore_zero)
  7083. {
  7084. int i;
  7085. for (i = 0; i < count; i++) {
  7086. u64 hw = le64_to_cpu(READ_ONCE(hw_stats[i]));
  7087. if (ignore_zero && !hw)
  7088. continue;
  7089. if (masks[i] == -1ULL)
  7090. sw_stats[i] = hw;
  7091. else
  7092. bnxt_add_one_ctr(hw, &sw_stats[i], masks[i]);
  7093. }
  7094. }
  7095. static void bnxt_accumulate_stats(struct bnxt_stats_mem *stats)
  7096. {
  7097. if (!stats->hw_stats)
  7098. return;
  7099. __bnxt_accumulate_stats(stats->hw_stats, stats->sw_stats,
  7100. stats->hw_masks, stats->len / 8, false);
  7101. }
  7102. static void bnxt_accumulate_all_stats(struct bnxt *bp)
  7103. {
  7104. struct bnxt_stats_mem *ring0_stats;
  7105. bool ignore_zero = false;
  7106. int i;
  7107. /* Chip bug. Counter intermittently becomes 0. */
  7108. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7109. ignore_zero = true;
  7110. for (i = 0; i < bp->cp_nr_rings; i++) {
  7111. struct bnxt_napi *bnapi = bp->bnapi[i];
  7112. struct bnxt_cp_ring_info *cpr;
  7113. struct bnxt_stats_mem *stats;
  7114. cpr = &bnapi->cp_ring;
  7115. stats = &cpr->stats;
  7116. if (!i)
  7117. ring0_stats = stats;
  7118. __bnxt_accumulate_stats(stats->hw_stats, stats->sw_stats,
  7119. ring0_stats->hw_masks,
  7120. ring0_stats->len / 8, ignore_zero);
  7121. }
  7122. if (bp->flags & BNXT_FLAG_PORT_STATS) {
  7123. struct bnxt_stats_mem *stats = &bp->port_stats;
  7124. __le64 *hw_stats = stats->hw_stats;
  7125. u64 *sw_stats = stats->sw_stats;
  7126. u64 *masks = stats->hw_masks;
  7127. int cnt;
  7128. cnt = sizeof(struct rx_port_stats) / 8;
  7129. __bnxt_accumulate_stats(hw_stats, sw_stats, masks, cnt, false);
  7130. hw_stats += BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
  7131. sw_stats += BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
  7132. masks += BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
  7133. cnt = sizeof(struct tx_port_stats) / 8;
  7134. __bnxt_accumulate_stats(hw_stats, sw_stats, masks, cnt, false);
  7135. }
  7136. if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
  7137. bnxt_accumulate_stats(&bp->rx_port_stats_ext);
  7138. bnxt_accumulate_stats(&bp->tx_port_stats_ext);
  7139. }
  7140. }
  7141. static int bnxt_hwrm_port_qstats(struct bnxt *bp, u8 flags)
  7142. {
  7143. struct hwrm_port_qstats_input *req;
  7144. struct bnxt_pf_info *pf = &bp->pf;
  7145. int rc;
  7146. if (!(bp->flags & BNXT_FLAG_PORT_STATS))
  7147. return 0;
  7148. if (flags && !(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED))
  7149. return -EOPNOTSUPP;
  7150. rc = hwrm_req_init(bp, req, HWRM_PORT_QSTATS);
  7151. if (rc)
  7152. return rc;
  7153. req->flags = flags;
  7154. req->port_id = cpu_to_le16(pf->port_id);
  7155. req->tx_stat_host_addr = cpu_to_le64(bp->port_stats.hw_stats_map +
  7156. BNXT_TX_PORT_STATS_BYTE_OFFSET);
  7157. req->rx_stat_host_addr = cpu_to_le64(bp->port_stats.hw_stats_map);
  7158. return hwrm_req_send(bp, req);
  7159. }
  7160. static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp, u8 flags)
  7161. {
  7162. struct hwrm_queue_pri2cos_qcfg_output *resp_qc;
  7163. struct hwrm_queue_pri2cos_qcfg_input *req_qc;
  7164. struct hwrm_port_qstats_ext_output *resp_qs;
  7165. struct hwrm_port_qstats_ext_input *req_qs;
  7166. struct bnxt_pf_info *pf = &bp->pf;
  7167. u32 tx_stat_size;
  7168. int rc;
  7169. if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT))
  7170. return 0;
  7171. if (flags && !(bp->fw_cap & BNXT_FW_CAP_EXT_HW_STATS_SUPPORTED))
  7172. return -EOPNOTSUPP;
  7173. rc = hwrm_req_init(bp, req_qs, HWRM_PORT_QSTATS_EXT);
  7174. if (rc)
  7175. return rc;
  7176. req_qs->flags = flags;
  7177. req_qs->port_id = cpu_to_le16(pf->port_id);
  7178. req_qs->rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
  7179. req_qs->rx_stat_host_addr = cpu_to_le64(bp->rx_port_stats_ext.hw_stats_map);
  7180. tx_stat_size = bp->tx_port_stats_ext.hw_stats ?
  7181. sizeof(struct tx_port_stats_ext) : 0;
  7182. req_qs->tx_stat_size = cpu_to_le16(tx_stat_size);
  7183. req_qs->tx_stat_host_addr = cpu_to_le64(bp->tx_port_stats_ext.hw_stats_map);
  7184. resp_qs = hwrm_req_hold(bp, req_qs);
  7185. rc = hwrm_req_send(bp, req_qs);
  7186. if (!rc) {
  7187. bp->fw_rx_stats_ext_size =
  7188. le16_to_cpu(resp_qs->rx_stat_size) / 8;
  7189. if (BNXT_FW_MAJ(bp) < 220 &&
  7190. bp->fw_rx_stats_ext_size > BNXT_RX_STATS_EXT_NUM_LEGACY)
  7191. bp->fw_rx_stats_ext_size = BNXT_RX_STATS_EXT_NUM_LEGACY;
  7192. bp->fw_tx_stats_ext_size = tx_stat_size ?
  7193. le16_to_cpu(resp_qs->tx_stat_size) / 8 : 0;
  7194. } else {
  7195. bp->fw_rx_stats_ext_size = 0;
  7196. bp->fw_tx_stats_ext_size = 0;
  7197. }
  7198. hwrm_req_drop(bp, req_qs);
  7199. if (flags)
  7200. return rc;
  7201. if (bp->fw_tx_stats_ext_size <=
  7202. offsetof(struct tx_port_stats_ext, pfc_pri0_tx_duration_us) / 8) {
  7203. bp->pri2cos_valid = 0;
  7204. return rc;
  7205. }
  7206. rc = hwrm_req_init(bp, req_qc, HWRM_QUEUE_PRI2COS_QCFG);
  7207. if (rc)
  7208. return rc;
  7209. req_qc->flags = cpu_to_le32(QUEUE_PRI2COS_QCFG_REQ_FLAGS_IVLAN);
  7210. resp_qc = hwrm_req_hold(bp, req_qc);
  7211. rc = hwrm_req_send(bp, req_qc);
  7212. if (!rc) {
  7213. u8 *pri2cos;
  7214. int i, j;
  7215. pri2cos = &resp_qc->pri0_cos_queue_id;
  7216. for (i = 0; i < 8; i++) {
  7217. u8 queue_id = pri2cos[i];
  7218. u8 queue_idx;
  7219. /* Per port queue IDs start from 0, 10, 20, etc */
  7220. queue_idx = queue_id % 10;
  7221. if (queue_idx > BNXT_MAX_QUEUE) {
  7222. bp->pri2cos_valid = false;
  7223. hwrm_req_drop(bp, req_qc);
  7224. return rc;
  7225. }
  7226. for (j = 0; j < bp->max_q; j++) {
  7227. if (bp->q_ids[j] == queue_id)
  7228. bp->pri2cos_idx[i] = queue_idx;
  7229. }
  7230. }
  7231. bp->pri2cos_valid = true;
  7232. }
  7233. hwrm_req_drop(bp, req_qc);
  7234. return rc;
  7235. }
  7236. static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
  7237. {
  7238. bnxt_hwrm_tunnel_dst_port_free(bp,
  7239. TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
  7240. bnxt_hwrm_tunnel_dst_port_free(bp,
  7241. TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
  7242. }
  7243. static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
  7244. {
  7245. int rc, i;
  7246. u32 tpa_flags = 0;
  7247. if (set_tpa)
  7248. tpa_flags = bp->flags & BNXT_FLAG_TPA;
  7249. else if (BNXT_NO_FW_ACCESS(bp))
  7250. return 0;
  7251. for (i = 0; i < bp->nr_vnics; i++) {
  7252. rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
  7253. if (rc) {
  7254. netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
  7255. i, rc);
  7256. return rc;
  7257. }
  7258. }
  7259. return 0;
  7260. }
  7261. static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
  7262. {
  7263. int i;
  7264. for (i = 0; i < bp->nr_vnics; i++)
  7265. bnxt_hwrm_vnic_set_rss(bp, i, false);
  7266. }
  7267. static void bnxt_clear_vnic(struct bnxt *bp)
  7268. {
  7269. if (!bp->vnic_info)
  7270. return;
  7271. bnxt_hwrm_clear_vnic_filter(bp);
  7272. if (!(bp->flags & BNXT_FLAG_CHIP_P5)) {
  7273. /* clear all RSS setting before free vnic ctx */
  7274. bnxt_hwrm_clear_vnic_rss(bp);
  7275. bnxt_hwrm_vnic_ctx_free(bp);
  7276. }
  7277. /* before free the vnic, undo the vnic tpa settings */
  7278. if (bp->flags & BNXT_FLAG_TPA)
  7279. bnxt_set_tpa(bp, false);
  7280. bnxt_hwrm_vnic_free(bp);
  7281. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7282. bnxt_hwrm_vnic_ctx_free(bp);
  7283. }
  7284. static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
  7285. bool irq_re_init)
  7286. {
  7287. bnxt_clear_vnic(bp);
  7288. bnxt_hwrm_ring_free(bp, close_path);
  7289. bnxt_hwrm_ring_grp_free(bp);
  7290. if (irq_re_init) {
  7291. bnxt_hwrm_stat_ctx_free(bp);
  7292. bnxt_hwrm_free_tunnel_ports(bp);
  7293. }
  7294. }
  7295. static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode)
  7296. {
  7297. struct hwrm_func_cfg_input *req;
  7298. u8 evb_mode;
  7299. int rc;
  7300. if (br_mode == BRIDGE_MODE_VEB)
  7301. evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB;
  7302. else if (br_mode == BRIDGE_MODE_VEPA)
  7303. evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA;
  7304. else
  7305. return -EINVAL;
  7306. rc = hwrm_req_init(bp, req, HWRM_FUNC_CFG);
  7307. if (rc)
  7308. return rc;
  7309. req->fid = cpu_to_le16(0xffff);
  7310. req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE);
  7311. req->evb_mode = evb_mode;
  7312. return hwrm_req_send(bp, req);
  7313. }
  7314. static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size)
  7315. {
  7316. struct hwrm_func_cfg_input *req;
  7317. int rc;
  7318. if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803)
  7319. return 0;
  7320. rc = hwrm_req_init(bp, req, HWRM_FUNC_CFG);
  7321. if (rc)
  7322. return rc;
  7323. req->fid = cpu_to_le16(0xffff);
  7324. req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE);
  7325. req->options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64;
  7326. if (size == 128)
  7327. req->options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128;
  7328. return hwrm_req_send(bp, req);
  7329. }
  7330. static int __bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
  7331. {
  7332. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  7333. int rc;
  7334. if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
  7335. goto skip_rss_ctx;
  7336. /* allocate context for vnic */
  7337. rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
  7338. if (rc) {
  7339. netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
  7340. vnic_id, rc);
  7341. goto vnic_setup_err;
  7342. }
  7343. bp->rsscos_nr_ctxs++;
  7344. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  7345. rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
  7346. if (rc) {
  7347. netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
  7348. vnic_id, rc);
  7349. goto vnic_setup_err;
  7350. }
  7351. bp->rsscos_nr_ctxs++;
  7352. }
  7353. skip_rss_ctx:
  7354. /* configure default vnic, ring grp */
  7355. rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
  7356. if (rc) {
  7357. netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
  7358. vnic_id, rc);
  7359. goto vnic_setup_err;
  7360. }
  7361. /* Enable RSS hashing on vnic */
  7362. rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
  7363. if (rc) {
  7364. netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
  7365. vnic_id, rc);
  7366. goto vnic_setup_err;
  7367. }
  7368. if (bp->flags & BNXT_FLAG_AGG_RINGS) {
  7369. rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
  7370. if (rc) {
  7371. netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
  7372. vnic_id, rc);
  7373. }
  7374. }
  7375. vnic_setup_err:
  7376. return rc;
  7377. }
  7378. static int __bnxt_setup_vnic_p5(struct bnxt *bp, u16 vnic_id)
  7379. {
  7380. int rc, i, nr_ctxs;
  7381. nr_ctxs = bnxt_get_nr_rss_ctxs(bp, bp->rx_nr_rings);
  7382. for (i = 0; i < nr_ctxs; i++) {
  7383. rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, i);
  7384. if (rc) {
  7385. netdev_err(bp->dev, "hwrm vnic %d ctx %d alloc failure rc: %x\n",
  7386. vnic_id, i, rc);
  7387. break;
  7388. }
  7389. bp->rsscos_nr_ctxs++;
  7390. }
  7391. if (i < nr_ctxs)
  7392. return -ENOMEM;
  7393. rc = bnxt_hwrm_vnic_set_rss_p5(bp, vnic_id, true);
  7394. if (rc) {
  7395. netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %d\n",
  7396. vnic_id, rc);
  7397. return rc;
  7398. }
  7399. rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
  7400. if (rc) {
  7401. netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
  7402. vnic_id, rc);
  7403. return rc;
  7404. }
  7405. if (bp->flags & BNXT_FLAG_AGG_RINGS) {
  7406. rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
  7407. if (rc) {
  7408. netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
  7409. vnic_id, rc);
  7410. }
  7411. }
  7412. return rc;
  7413. }
  7414. static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
  7415. {
  7416. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7417. return __bnxt_setup_vnic_p5(bp, vnic_id);
  7418. else
  7419. return __bnxt_setup_vnic(bp, vnic_id);
  7420. }
  7421. static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
  7422. {
  7423. #ifdef CONFIG_RFS_ACCEL
  7424. int i, rc = 0;
  7425. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7426. return 0;
  7427. for (i = 0; i < bp->rx_nr_rings; i++) {
  7428. struct bnxt_vnic_info *vnic;
  7429. u16 vnic_id = i + 1;
  7430. u16 ring_id = i;
  7431. if (vnic_id >= bp->nr_vnics)
  7432. break;
  7433. vnic = &bp->vnic_info[vnic_id];
  7434. vnic->flags |= BNXT_VNIC_RFS_FLAG;
  7435. if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
  7436. vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
  7437. rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
  7438. if (rc) {
  7439. netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
  7440. vnic_id, rc);
  7441. break;
  7442. }
  7443. rc = bnxt_setup_vnic(bp, vnic_id);
  7444. if (rc)
  7445. break;
  7446. }
  7447. return rc;
  7448. #else
  7449. return 0;
  7450. #endif
  7451. }
  7452. /* Allow PF, trusted VFs and VFs with default VLAN to be in promiscuous mode */
  7453. static bool bnxt_promisc_ok(struct bnxt *bp)
  7454. {
  7455. #ifdef CONFIG_BNXT_SRIOV
  7456. if (BNXT_VF(bp) && !bp->vf.vlan && !bnxt_is_trusted_vf(bp, &bp->vf))
  7457. return false;
  7458. #endif
  7459. return true;
  7460. }
  7461. static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
  7462. {
  7463. unsigned int rc = 0;
  7464. rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
  7465. if (rc) {
  7466. netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
  7467. rc);
  7468. return rc;
  7469. }
  7470. rc = bnxt_hwrm_vnic_cfg(bp, 1);
  7471. if (rc) {
  7472. netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
  7473. rc);
  7474. return rc;
  7475. }
  7476. return rc;
  7477. }
  7478. static int bnxt_cfg_rx_mode(struct bnxt *);
  7479. static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
  7480. static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
  7481. {
  7482. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  7483. int rc = 0;
  7484. unsigned int rx_nr_rings = bp->rx_nr_rings;
  7485. if (irq_re_init) {
  7486. rc = bnxt_hwrm_stat_ctx_alloc(bp);
  7487. if (rc) {
  7488. netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
  7489. rc);
  7490. goto err_out;
  7491. }
  7492. }
  7493. rc = bnxt_hwrm_ring_alloc(bp);
  7494. if (rc) {
  7495. netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
  7496. goto err_out;
  7497. }
  7498. rc = bnxt_hwrm_ring_grp_alloc(bp);
  7499. if (rc) {
  7500. netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
  7501. goto err_out;
  7502. }
  7503. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  7504. rx_nr_rings--;
  7505. /* default vnic 0 */
  7506. rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
  7507. if (rc) {
  7508. netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
  7509. goto err_out;
  7510. }
  7511. if (BNXT_VF(bp))
  7512. bnxt_hwrm_func_qcfg(bp);
  7513. rc = bnxt_setup_vnic(bp, 0);
  7514. if (rc)
  7515. goto err_out;
  7516. if (bp->flags & BNXT_FLAG_RFS) {
  7517. rc = bnxt_alloc_rfs_vnics(bp);
  7518. if (rc)
  7519. goto err_out;
  7520. }
  7521. if (bp->flags & BNXT_FLAG_TPA) {
  7522. rc = bnxt_set_tpa(bp, true);
  7523. if (rc)
  7524. goto err_out;
  7525. }
  7526. if (BNXT_VF(bp))
  7527. bnxt_update_vf_mac(bp);
  7528. /* Filter for default vnic 0 */
  7529. rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
  7530. if (rc) {
  7531. if (BNXT_VF(bp) && rc == -ENODEV)
  7532. netdev_err(bp->dev, "Cannot configure L2 filter while PF is unavailable\n");
  7533. else
  7534. netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
  7535. goto err_out;
  7536. }
  7537. vnic->uc_filter_count = 1;
  7538. vnic->rx_mask = 0;
  7539. if (test_bit(BNXT_STATE_HALF_OPEN, &bp->state))
  7540. goto skip_rx_mask;
  7541. if (bp->dev->flags & IFF_BROADCAST)
  7542. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
  7543. if (bp->dev->flags & IFF_PROMISC)
  7544. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  7545. if (bp->dev->flags & IFF_ALLMULTI) {
  7546. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  7547. vnic->mc_list_count = 0;
  7548. } else if (bp->dev->flags & IFF_MULTICAST) {
  7549. u32 mask = 0;
  7550. bnxt_mc_list_updated(bp, &mask);
  7551. vnic->rx_mask |= mask;
  7552. }
  7553. rc = bnxt_cfg_rx_mode(bp);
  7554. if (rc)
  7555. goto err_out;
  7556. skip_rx_mask:
  7557. rc = bnxt_hwrm_set_coal(bp);
  7558. if (rc)
  7559. netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
  7560. rc);
  7561. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  7562. rc = bnxt_setup_nitroa0_vnic(bp);
  7563. if (rc)
  7564. netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
  7565. rc);
  7566. }
  7567. if (BNXT_VF(bp)) {
  7568. bnxt_hwrm_func_qcfg(bp);
  7569. netdev_update_features(bp->dev);
  7570. }
  7571. return 0;
  7572. err_out:
  7573. bnxt_hwrm_resource_free(bp, 0, true);
  7574. return rc;
  7575. }
  7576. static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
  7577. {
  7578. bnxt_hwrm_resource_free(bp, 1, irq_re_init);
  7579. return 0;
  7580. }
  7581. static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
  7582. {
  7583. bnxt_init_cp_rings(bp);
  7584. bnxt_init_rx_rings(bp);
  7585. bnxt_init_tx_rings(bp);
  7586. bnxt_init_ring_grps(bp, irq_re_init);
  7587. bnxt_init_vnics(bp);
  7588. return bnxt_init_chip(bp, irq_re_init);
  7589. }
  7590. static int bnxt_set_real_num_queues(struct bnxt *bp)
  7591. {
  7592. int rc;
  7593. struct net_device *dev = bp->dev;
  7594. rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
  7595. bp->tx_nr_rings_xdp);
  7596. if (rc)
  7597. return rc;
  7598. rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
  7599. if (rc)
  7600. return rc;
  7601. #ifdef CONFIG_RFS_ACCEL
  7602. if (bp->flags & BNXT_FLAG_RFS)
  7603. dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
  7604. #endif
  7605. return rc;
  7606. }
  7607. static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
  7608. bool shared)
  7609. {
  7610. int _rx = *rx, _tx = *tx;
  7611. if (shared) {
  7612. *rx = min_t(int, _rx, max);
  7613. *tx = min_t(int, _tx, max);
  7614. } else {
  7615. if (max < 2)
  7616. return -ENOMEM;
  7617. while (_rx + _tx > max) {
  7618. if (_rx > _tx && _rx > 1)
  7619. _rx--;
  7620. else if (_tx > 1)
  7621. _tx--;
  7622. }
  7623. *rx = _rx;
  7624. *tx = _tx;
  7625. }
  7626. return 0;
  7627. }
  7628. static void bnxt_setup_msix(struct bnxt *bp)
  7629. {
  7630. const int len = sizeof(bp->irq_tbl[0].name);
  7631. struct net_device *dev = bp->dev;
  7632. int tcs, i;
  7633. tcs = netdev_get_num_tc(dev);
  7634. if (tcs) {
  7635. int i, off, count;
  7636. for (i = 0; i < tcs; i++) {
  7637. count = bp->tx_nr_rings_per_tc;
  7638. off = i * count;
  7639. netdev_set_tc_queue(dev, i, count, off);
  7640. }
  7641. }
  7642. for (i = 0; i < bp->cp_nr_rings; i++) {
  7643. int map_idx = bnxt_cp_num_to_irq_num(bp, i);
  7644. char *attr;
  7645. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  7646. attr = "TxRx";
  7647. else if (i < bp->rx_nr_rings)
  7648. attr = "rx";
  7649. else
  7650. attr = "tx";
  7651. snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name,
  7652. attr, i);
  7653. bp->irq_tbl[map_idx].handler = bnxt_msix;
  7654. }
  7655. }
  7656. static void bnxt_setup_inta(struct bnxt *bp)
  7657. {
  7658. const int len = sizeof(bp->irq_tbl[0].name);
  7659. if (netdev_get_num_tc(bp->dev))
  7660. netdev_reset_tc(bp->dev);
  7661. snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
  7662. 0);
  7663. bp->irq_tbl[0].handler = bnxt_inta;
  7664. }
  7665. static int bnxt_init_int_mode(struct bnxt *bp);
  7666. static int bnxt_setup_int_mode(struct bnxt *bp)
  7667. {
  7668. int rc;
  7669. if (!bp->irq_tbl) {
  7670. rc = bnxt_init_int_mode(bp);
  7671. if (rc || !bp->irq_tbl)
  7672. return rc ?: -ENODEV;
  7673. }
  7674. if (bp->flags & BNXT_FLAG_USING_MSIX)
  7675. bnxt_setup_msix(bp);
  7676. else
  7677. bnxt_setup_inta(bp);
  7678. rc = bnxt_set_real_num_queues(bp);
  7679. return rc;
  7680. }
  7681. #ifdef CONFIG_RFS_ACCEL
  7682. static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
  7683. {
  7684. return bp->hw_resc.max_rsscos_ctxs;
  7685. }
  7686. static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
  7687. {
  7688. return bp->hw_resc.max_vnics;
  7689. }
  7690. #endif
  7691. unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
  7692. {
  7693. return bp->hw_resc.max_stat_ctxs;
  7694. }
  7695. unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
  7696. {
  7697. return bp->hw_resc.max_cp_rings;
  7698. }
  7699. static unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp)
  7700. {
  7701. unsigned int cp = bp->hw_resc.max_cp_rings;
  7702. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  7703. cp -= bnxt_get_ulp_msix_num(bp);
  7704. return cp;
  7705. }
  7706. static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
  7707. {
  7708. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  7709. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7710. return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_nqs);
  7711. return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings);
  7712. }
  7713. static void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
  7714. {
  7715. bp->hw_resc.max_irqs = max_irqs;
  7716. }
  7717. unsigned int bnxt_get_avail_cp_rings_for_en(struct bnxt *bp)
  7718. {
  7719. unsigned int cp;
  7720. cp = bnxt_get_max_func_cp_rings_for_en(bp);
  7721. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7722. return cp - bp->rx_nr_rings - bp->tx_nr_rings;
  7723. else
  7724. return cp - bp->cp_nr_rings;
  7725. }
  7726. unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt *bp)
  7727. {
  7728. return bnxt_get_max_func_stat_ctxs(bp) - bnxt_get_func_stat_ctxs(bp);
  7729. }
  7730. int bnxt_get_avail_msix(struct bnxt *bp, int num)
  7731. {
  7732. int max_cp = bnxt_get_max_func_cp_rings(bp);
  7733. int max_irq = bnxt_get_max_func_irqs(bp);
  7734. int total_req = bp->cp_nr_rings + num;
  7735. int max_idx, avail_msix;
  7736. max_idx = bp->total_irqs;
  7737. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  7738. max_idx = min_t(int, bp->total_irqs, max_cp);
  7739. avail_msix = max_idx - bp->cp_nr_rings;
  7740. if (!BNXT_NEW_RM(bp) || avail_msix >= num)
  7741. return avail_msix;
  7742. if (max_irq < total_req) {
  7743. num = max_irq - bp->cp_nr_rings;
  7744. if (num <= 0)
  7745. return 0;
  7746. }
  7747. return num;
  7748. }
  7749. static int bnxt_get_num_msix(struct bnxt *bp)
  7750. {
  7751. if (!BNXT_NEW_RM(bp))
  7752. return bnxt_get_max_func_irqs(bp);
  7753. return bnxt_nq_rings_in_use(bp);
  7754. }
  7755. static int bnxt_init_msix(struct bnxt *bp)
  7756. {
  7757. int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
  7758. struct msix_entry *msix_ent;
  7759. total_vecs = bnxt_get_num_msix(bp);
  7760. max = bnxt_get_max_func_irqs(bp);
  7761. if (total_vecs > max)
  7762. total_vecs = max;
  7763. if (!total_vecs)
  7764. return 0;
  7765. msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
  7766. if (!msix_ent)
  7767. return -ENOMEM;
  7768. for (i = 0; i < total_vecs; i++) {
  7769. msix_ent[i].entry = i;
  7770. msix_ent[i].vector = 0;
  7771. }
  7772. if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
  7773. min = 2;
  7774. total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
  7775. ulp_msix = bnxt_get_ulp_msix_num(bp);
  7776. if (total_vecs < 0 || total_vecs < ulp_msix) {
  7777. rc = -ENODEV;
  7778. goto msix_setup_exit;
  7779. }
  7780. bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
  7781. if (bp->irq_tbl) {
  7782. for (i = 0; i < total_vecs; i++)
  7783. bp->irq_tbl[i].vector = msix_ent[i].vector;
  7784. bp->total_irqs = total_vecs;
  7785. /* Trim rings based upon num of vectors allocated */
  7786. rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
  7787. total_vecs - ulp_msix, min == 1);
  7788. if (rc)
  7789. goto msix_setup_exit;
  7790. bp->cp_nr_rings = (min == 1) ?
  7791. max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
  7792. bp->tx_nr_rings + bp->rx_nr_rings;
  7793. } else {
  7794. rc = -ENOMEM;
  7795. goto msix_setup_exit;
  7796. }
  7797. bp->flags |= BNXT_FLAG_USING_MSIX;
  7798. kfree(msix_ent);
  7799. return 0;
  7800. msix_setup_exit:
  7801. netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
  7802. kfree(bp->irq_tbl);
  7803. bp->irq_tbl = NULL;
  7804. pci_disable_msix(bp->pdev);
  7805. kfree(msix_ent);
  7806. return rc;
  7807. }
  7808. static int bnxt_init_inta(struct bnxt *bp)
  7809. {
  7810. bp->irq_tbl = kzalloc(sizeof(struct bnxt_irq), GFP_KERNEL);
  7811. if (!bp->irq_tbl)
  7812. return -ENOMEM;
  7813. bp->total_irqs = 1;
  7814. bp->rx_nr_rings = 1;
  7815. bp->tx_nr_rings = 1;
  7816. bp->cp_nr_rings = 1;
  7817. bp->flags |= BNXT_FLAG_SHARED_RINGS;
  7818. bp->irq_tbl[0].vector = bp->pdev->irq;
  7819. return 0;
  7820. }
  7821. static int bnxt_init_int_mode(struct bnxt *bp)
  7822. {
  7823. int rc = -ENODEV;
  7824. if (bp->flags & BNXT_FLAG_MSIX_CAP)
  7825. rc = bnxt_init_msix(bp);
  7826. if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
  7827. /* fallback to INTA */
  7828. rc = bnxt_init_inta(bp);
  7829. }
  7830. return rc;
  7831. }
  7832. static void bnxt_clear_int_mode(struct bnxt *bp)
  7833. {
  7834. if (bp->flags & BNXT_FLAG_USING_MSIX)
  7835. pci_disable_msix(bp->pdev);
  7836. kfree(bp->irq_tbl);
  7837. bp->irq_tbl = NULL;
  7838. bp->flags &= ~BNXT_FLAG_USING_MSIX;
  7839. }
  7840. int bnxt_reserve_rings(struct bnxt *bp, bool irq_re_init)
  7841. {
  7842. int tcs = netdev_get_num_tc(bp->dev);
  7843. bool irq_cleared = false;
  7844. int rc;
  7845. if (!bnxt_need_reserve_rings(bp))
  7846. return 0;
  7847. if (irq_re_init && BNXT_NEW_RM(bp) &&
  7848. bnxt_get_num_msix(bp) != bp->total_irqs) {
  7849. bnxt_ulp_irq_stop(bp);
  7850. bnxt_clear_int_mode(bp);
  7851. irq_cleared = true;
  7852. }
  7853. rc = __bnxt_reserve_rings(bp);
  7854. if (irq_cleared) {
  7855. if (!rc)
  7856. rc = bnxt_init_int_mode(bp);
  7857. bnxt_ulp_irq_restart(bp, rc);
  7858. }
  7859. if (rc) {
  7860. netdev_err(bp->dev, "ring reservation/IRQ init failure rc: %d\n", rc);
  7861. return rc;
  7862. }
  7863. if (tcs && (bp->tx_nr_rings_per_tc * tcs !=
  7864. bp->tx_nr_rings - bp->tx_nr_rings_xdp)) {
  7865. netdev_err(bp->dev, "tx ring reservation failure\n");
  7866. netdev_reset_tc(bp->dev);
  7867. if (bp->tx_nr_rings_xdp)
  7868. bp->tx_nr_rings_per_tc = bp->tx_nr_rings_xdp;
  7869. else
  7870. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  7871. return -ENOMEM;
  7872. }
  7873. return 0;
  7874. }
  7875. static void bnxt_free_irq(struct bnxt *bp)
  7876. {
  7877. struct bnxt_irq *irq;
  7878. int i;
  7879. #ifdef CONFIG_RFS_ACCEL
  7880. free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
  7881. bp->dev->rx_cpu_rmap = NULL;
  7882. #endif
  7883. if (!bp->irq_tbl || !bp->bnapi)
  7884. return;
  7885. for (i = 0; i < bp->cp_nr_rings; i++) {
  7886. int map_idx = bnxt_cp_num_to_irq_num(bp, i);
  7887. irq = &bp->irq_tbl[map_idx];
  7888. if (irq->requested) {
  7889. if (irq->have_cpumask) {
  7890. irq_set_affinity_hint(irq->vector, NULL);
  7891. free_cpumask_var(irq->cpu_mask);
  7892. irq->have_cpumask = 0;
  7893. }
  7894. free_irq(irq->vector, bp->bnapi[i]);
  7895. }
  7896. irq->requested = 0;
  7897. }
  7898. }
  7899. static int bnxt_request_irq(struct bnxt *bp)
  7900. {
  7901. int i, j, rc = 0;
  7902. unsigned long flags = 0;
  7903. #ifdef CONFIG_RFS_ACCEL
  7904. struct cpu_rmap *rmap;
  7905. #endif
  7906. rc = bnxt_setup_int_mode(bp);
  7907. if (rc) {
  7908. netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
  7909. rc);
  7910. return rc;
  7911. }
  7912. #ifdef CONFIG_RFS_ACCEL
  7913. rmap = bp->dev->rx_cpu_rmap;
  7914. #endif
  7915. if (!(bp->flags & BNXT_FLAG_USING_MSIX))
  7916. flags = IRQF_SHARED;
  7917. for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
  7918. int map_idx = bnxt_cp_num_to_irq_num(bp, i);
  7919. struct bnxt_irq *irq = &bp->irq_tbl[map_idx];
  7920. #ifdef CONFIG_RFS_ACCEL
  7921. if (rmap && bp->bnapi[i]->rx_ring) {
  7922. rc = irq_cpu_rmap_add(rmap, irq->vector);
  7923. if (rc)
  7924. netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
  7925. j);
  7926. j++;
  7927. }
  7928. #endif
  7929. rc = request_irq(irq->vector, irq->handler, flags, irq->name,
  7930. bp->bnapi[i]);
  7931. if (rc)
  7932. break;
  7933. irq->requested = 1;
  7934. if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) {
  7935. int numa_node = dev_to_node(&bp->pdev->dev);
  7936. irq->have_cpumask = 1;
  7937. cpumask_set_cpu(cpumask_local_spread(i, numa_node),
  7938. irq->cpu_mask);
  7939. rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask);
  7940. if (rc) {
  7941. netdev_warn(bp->dev,
  7942. "Set affinity failed, IRQ = %d\n",
  7943. irq->vector);
  7944. break;
  7945. }
  7946. }
  7947. }
  7948. return rc;
  7949. }
  7950. static void bnxt_del_napi(struct bnxt *bp)
  7951. {
  7952. int i;
  7953. if (!bp->bnapi)
  7954. return;
  7955. for (i = 0; i < bp->cp_nr_rings; i++) {
  7956. struct bnxt_napi *bnapi = bp->bnapi[i];
  7957. __netif_napi_del(&bnapi->napi);
  7958. }
  7959. /* We called __netif_napi_del(), we need
  7960. * to respect an RCU grace period before freeing napi structures.
  7961. */
  7962. synchronize_net();
  7963. }
  7964. static void bnxt_init_napi(struct bnxt *bp)
  7965. {
  7966. int i;
  7967. unsigned int cp_nr_rings = bp->cp_nr_rings;
  7968. struct bnxt_napi *bnapi;
  7969. if (bp->flags & BNXT_FLAG_USING_MSIX) {
  7970. int (*poll_fn)(struct napi_struct *, int) = bnxt_poll;
  7971. if (bp->flags & BNXT_FLAG_CHIP_P5)
  7972. poll_fn = bnxt_poll_p5;
  7973. else if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  7974. cp_nr_rings--;
  7975. for (i = 0; i < cp_nr_rings; i++) {
  7976. bnapi = bp->bnapi[i];
  7977. netif_napi_add(bp->dev, &bnapi->napi, poll_fn);
  7978. }
  7979. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  7980. bnapi = bp->bnapi[cp_nr_rings];
  7981. netif_napi_add(bp->dev, &bnapi->napi,
  7982. bnxt_poll_nitroa0);
  7983. }
  7984. } else {
  7985. bnapi = bp->bnapi[0];
  7986. netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll);
  7987. }
  7988. }
  7989. static void bnxt_disable_napi(struct bnxt *bp)
  7990. {
  7991. int i;
  7992. if (!bp->bnapi ||
  7993. test_and_set_bit(BNXT_STATE_NAPI_DISABLED, &bp->state))
  7994. return;
  7995. for (i = 0; i < bp->cp_nr_rings; i++) {
  7996. struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
  7997. napi_disable(&bp->bnapi[i]->napi);
  7998. if (bp->bnapi[i]->rx_ring)
  7999. cancel_work_sync(&cpr->dim.work);
  8000. }
  8001. }
  8002. static void bnxt_enable_napi(struct bnxt *bp)
  8003. {
  8004. int i;
  8005. clear_bit(BNXT_STATE_NAPI_DISABLED, &bp->state);
  8006. for (i = 0; i < bp->cp_nr_rings; i++) {
  8007. struct bnxt_napi *bnapi = bp->bnapi[i];
  8008. struct bnxt_cp_ring_info *cpr;
  8009. cpr = &bnapi->cp_ring;
  8010. if (bnapi->in_reset)
  8011. cpr->sw_stats.rx.rx_resets++;
  8012. bnapi->in_reset = false;
  8013. if (bnapi->rx_ring) {
  8014. INIT_WORK(&cpr->dim.work, bnxt_dim_work);
  8015. cpr->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
  8016. }
  8017. napi_enable(&bnapi->napi);
  8018. }
  8019. }
  8020. void bnxt_tx_disable(struct bnxt *bp)
  8021. {
  8022. int i;
  8023. struct bnxt_tx_ring_info *txr;
  8024. if (bp->tx_ring) {
  8025. for (i = 0; i < bp->tx_nr_rings; i++) {
  8026. txr = &bp->tx_ring[i];
  8027. WRITE_ONCE(txr->dev_state, BNXT_DEV_STATE_CLOSING);
  8028. }
  8029. }
  8030. /* Make sure napi polls see @dev_state change */
  8031. synchronize_net();
  8032. /* Drop carrier first to prevent TX timeout */
  8033. netif_carrier_off(bp->dev);
  8034. /* Stop all TX queues */
  8035. netif_tx_disable(bp->dev);
  8036. }
  8037. void bnxt_tx_enable(struct bnxt *bp)
  8038. {
  8039. int i;
  8040. struct bnxt_tx_ring_info *txr;
  8041. for (i = 0; i < bp->tx_nr_rings; i++) {
  8042. txr = &bp->tx_ring[i];
  8043. WRITE_ONCE(txr->dev_state, 0);
  8044. }
  8045. /* Make sure napi polls see @dev_state change */
  8046. synchronize_net();
  8047. netif_tx_wake_all_queues(bp->dev);
  8048. if (BNXT_LINK_IS_UP(bp))
  8049. netif_carrier_on(bp->dev);
  8050. }
  8051. static char *bnxt_report_fec(struct bnxt_link_info *link_info)
  8052. {
  8053. u8 active_fec = link_info->active_fec_sig_mode &
  8054. PORT_PHY_QCFG_RESP_ACTIVE_FEC_MASK;
  8055. switch (active_fec) {
  8056. default:
  8057. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_NONE_ACTIVE:
  8058. return "None";
  8059. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_CLAUSE74_ACTIVE:
  8060. return "Clause 74 BaseR";
  8061. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_CLAUSE91_ACTIVE:
  8062. return "Clause 91 RS(528,514)";
  8063. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS544_1XN_ACTIVE:
  8064. return "Clause 91 RS544_1XN";
  8065. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS544_IEEE_ACTIVE:
  8066. return "Clause 91 RS(544,514)";
  8067. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS272_1XN_ACTIVE:
  8068. return "Clause 91 RS272_1XN";
  8069. case PORT_PHY_QCFG_RESP_ACTIVE_FEC_FEC_RS272_IEEE_ACTIVE:
  8070. return "Clause 91 RS(272,257)";
  8071. }
  8072. }
  8073. void bnxt_report_link(struct bnxt *bp)
  8074. {
  8075. if (BNXT_LINK_IS_UP(bp)) {
  8076. const char *signal = "";
  8077. const char *flow_ctrl;
  8078. const char *duplex;
  8079. u32 speed;
  8080. u16 fec;
  8081. netif_carrier_on(bp->dev);
  8082. speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
  8083. if (speed == SPEED_UNKNOWN) {
  8084. netdev_info(bp->dev, "NIC Link is Up, speed unknown\n");
  8085. return;
  8086. }
  8087. if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
  8088. duplex = "full";
  8089. else
  8090. duplex = "half";
  8091. if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
  8092. flow_ctrl = "ON - receive & transmit";
  8093. else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
  8094. flow_ctrl = "ON - transmit";
  8095. else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
  8096. flow_ctrl = "ON - receive";
  8097. else
  8098. flow_ctrl = "none";
  8099. if (bp->link_info.phy_qcfg_resp.option_flags &
  8100. PORT_PHY_QCFG_RESP_OPTION_FLAGS_SIGNAL_MODE_KNOWN) {
  8101. u8 sig_mode = bp->link_info.active_fec_sig_mode &
  8102. PORT_PHY_QCFG_RESP_SIGNAL_MODE_MASK;
  8103. switch (sig_mode) {
  8104. case PORT_PHY_QCFG_RESP_SIGNAL_MODE_NRZ:
  8105. signal = "(NRZ) ";
  8106. break;
  8107. case PORT_PHY_QCFG_RESP_SIGNAL_MODE_PAM4:
  8108. signal = "(PAM4) ";
  8109. break;
  8110. default:
  8111. break;
  8112. }
  8113. }
  8114. netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s%s duplex, Flow control: %s\n",
  8115. speed, signal, duplex, flow_ctrl);
  8116. if (bp->phy_flags & BNXT_PHY_FL_EEE_CAP)
  8117. netdev_info(bp->dev, "EEE is %s\n",
  8118. bp->eee.eee_active ? "active" :
  8119. "not active");
  8120. fec = bp->link_info.fec_cfg;
  8121. if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
  8122. netdev_info(bp->dev, "FEC autoneg %s encoding: %s\n",
  8123. (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
  8124. bnxt_report_fec(&bp->link_info));
  8125. } else {
  8126. netif_carrier_off(bp->dev);
  8127. netdev_err(bp->dev, "NIC Link is Down\n");
  8128. }
  8129. }
  8130. static bool bnxt_phy_qcaps_no_speed(struct hwrm_port_phy_qcaps_output *resp)
  8131. {
  8132. if (!resp->supported_speeds_auto_mode &&
  8133. !resp->supported_speeds_force_mode &&
  8134. !resp->supported_pam4_speeds_auto_mode &&
  8135. !resp->supported_pam4_speeds_force_mode)
  8136. return true;
  8137. return false;
  8138. }
  8139. static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
  8140. {
  8141. struct bnxt_link_info *link_info = &bp->link_info;
  8142. struct hwrm_port_phy_qcaps_output *resp;
  8143. struct hwrm_port_phy_qcaps_input *req;
  8144. int rc = 0;
  8145. if (bp->hwrm_spec_code < 0x10201)
  8146. return 0;
  8147. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_QCAPS);
  8148. if (rc)
  8149. return rc;
  8150. resp = hwrm_req_hold(bp, req);
  8151. rc = hwrm_req_send(bp, req);
  8152. if (rc)
  8153. goto hwrm_phy_qcaps_exit;
  8154. bp->phy_flags = resp->flags | (le16_to_cpu(resp->flags2) << 8);
  8155. if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) {
  8156. struct ethtool_eee *eee = &bp->eee;
  8157. u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
  8158. eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
  8159. bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
  8160. PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
  8161. bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
  8162. PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
  8163. }
  8164. if (bp->hwrm_spec_code >= 0x10a01) {
  8165. if (bnxt_phy_qcaps_no_speed(resp)) {
  8166. link_info->phy_state = BNXT_PHY_STATE_DISABLED;
  8167. netdev_warn(bp->dev, "Ethernet link disabled\n");
  8168. } else if (link_info->phy_state == BNXT_PHY_STATE_DISABLED) {
  8169. link_info->phy_state = BNXT_PHY_STATE_ENABLED;
  8170. netdev_info(bp->dev, "Ethernet link enabled\n");
  8171. /* Phy re-enabled, reprobe the speeds */
  8172. link_info->support_auto_speeds = 0;
  8173. link_info->support_pam4_auto_speeds = 0;
  8174. }
  8175. }
  8176. if (resp->supported_speeds_auto_mode)
  8177. link_info->support_auto_speeds =
  8178. le16_to_cpu(resp->supported_speeds_auto_mode);
  8179. if (resp->supported_pam4_speeds_auto_mode)
  8180. link_info->support_pam4_auto_speeds =
  8181. le16_to_cpu(resp->supported_pam4_speeds_auto_mode);
  8182. bp->port_count = resp->port_cnt;
  8183. hwrm_phy_qcaps_exit:
  8184. hwrm_req_drop(bp, req);
  8185. return rc;
  8186. }
  8187. static bool bnxt_support_dropped(u16 advertising, u16 supported)
  8188. {
  8189. u16 diff = advertising ^ supported;
  8190. return ((supported | diff) != supported);
  8191. }
  8192. int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
  8193. {
  8194. struct bnxt_link_info *link_info = &bp->link_info;
  8195. struct hwrm_port_phy_qcfg_output *resp;
  8196. struct hwrm_port_phy_qcfg_input *req;
  8197. u8 link_state = link_info->link_state;
  8198. bool support_changed = false;
  8199. int rc;
  8200. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_QCFG);
  8201. if (rc)
  8202. return rc;
  8203. resp = hwrm_req_hold(bp, req);
  8204. rc = hwrm_req_send(bp, req);
  8205. if (rc) {
  8206. hwrm_req_drop(bp, req);
  8207. if (BNXT_VF(bp) && rc == -ENODEV) {
  8208. netdev_warn(bp->dev, "Cannot obtain link state while PF unavailable.\n");
  8209. rc = 0;
  8210. }
  8211. return rc;
  8212. }
  8213. memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
  8214. link_info->phy_link_status = resp->link;
  8215. link_info->duplex = resp->duplex_cfg;
  8216. if (bp->hwrm_spec_code >= 0x10800)
  8217. link_info->duplex = resp->duplex_state;
  8218. link_info->pause = resp->pause;
  8219. link_info->auto_mode = resp->auto_mode;
  8220. link_info->auto_pause_setting = resp->auto_pause;
  8221. link_info->lp_pause = resp->link_partner_adv_pause;
  8222. link_info->force_pause_setting = resp->force_pause;
  8223. link_info->duplex_setting = resp->duplex_cfg;
  8224. if (link_info->phy_link_status == BNXT_LINK_LINK)
  8225. link_info->link_speed = le16_to_cpu(resp->link_speed);
  8226. else
  8227. link_info->link_speed = 0;
  8228. link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
  8229. link_info->force_pam4_link_speed =
  8230. le16_to_cpu(resp->force_pam4_link_speed);
  8231. link_info->support_speeds = le16_to_cpu(resp->support_speeds);
  8232. link_info->support_pam4_speeds = le16_to_cpu(resp->support_pam4_speeds);
  8233. link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
  8234. link_info->auto_pam4_link_speeds =
  8235. le16_to_cpu(resp->auto_pam4_link_speed_mask);
  8236. link_info->lp_auto_link_speeds =
  8237. le16_to_cpu(resp->link_partner_adv_speeds);
  8238. link_info->lp_auto_pam4_link_speeds =
  8239. resp->link_partner_pam4_adv_speeds;
  8240. link_info->preemphasis = le32_to_cpu(resp->preemphasis);
  8241. link_info->phy_ver[0] = resp->phy_maj;
  8242. link_info->phy_ver[1] = resp->phy_min;
  8243. link_info->phy_ver[2] = resp->phy_bld;
  8244. link_info->media_type = resp->media_type;
  8245. link_info->phy_type = resp->phy_type;
  8246. link_info->transceiver = resp->xcvr_pkg_type;
  8247. link_info->phy_addr = resp->eee_config_phy_addr &
  8248. PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
  8249. link_info->module_status = resp->module_status;
  8250. if (bp->phy_flags & BNXT_PHY_FL_EEE_CAP) {
  8251. struct ethtool_eee *eee = &bp->eee;
  8252. u16 fw_speeds;
  8253. eee->eee_active = 0;
  8254. if (resp->eee_config_phy_addr &
  8255. PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
  8256. eee->eee_active = 1;
  8257. fw_speeds = le16_to_cpu(
  8258. resp->link_partner_adv_eee_link_speed_mask);
  8259. eee->lp_advertised =
  8260. _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
  8261. }
  8262. /* Pull initial EEE config */
  8263. if (!chng_link_state) {
  8264. if (resp->eee_config_phy_addr &
  8265. PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
  8266. eee->eee_enabled = 1;
  8267. fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
  8268. eee->advertised =
  8269. _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
  8270. if (resp->eee_config_phy_addr &
  8271. PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
  8272. __le32 tmr;
  8273. eee->tx_lpi_enabled = 1;
  8274. tmr = resp->xcvr_identifier_type_tx_lpi_timer;
  8275. eee->tx_lpi_timer = le32_to_cpu(tmr) &
  8276. PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
  8277. }
  8278. }
  8279. }
  8280. link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
  8281. if (bp->hwrm_spec_code >= 0x10504) {
  8282. link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
  8283. link_info->active_fec_sig_mode = resp->active_fec_signal_mode;
  8284. }
  8285. /* TODO: need to add more logic to report VF link */
  8286. if (chng_link_state) {
  8287. if (link_info->phy_link_status == BNXT_LINK_LINK)
  8288. link_info->link_state = BNXT_LINK_STATE_UP;
  8289. else
  8290. link_info->link_state = BNXT_LINK_STATE_DOWN;
  8291. if (link_state != link_info->link_state)
  8292. bnxt_report_link(bp);
  8293. } else {
  8294. /* always link down if not require to update link state */
  8295. link_info->link_state = BNXT_LINK_STATE_DOWN;
  8296. }
  8297. hwrm_req_drop(bp, req);
  8298. if (!BNXT_PHY_CFG_ABLE(bp))
  8299. return 0;
  8300. /* Check if any advertised speeds are no longer supported. The caller
  8301. * holds the link_lock mutex, so we can modify link_info settings.
  8302. */
  8303. if (bnxt_support_dropped(link_info->advertising,
  8304. link_info->support_auto_speeds)) {
  8305. link_info->advertising = link_info->support_auto_speeds;
  8306. support_changed = true;
  8307. }
  8308. if (bnxt_support_dropped(link_info->advertising_pam4,
  8309. link_info->support_pam4_auto_speeds)) {
  8310. link_info->advertising_pam4 = link_info->support_pam4_auto_speeds;
  8311. support_changed = true;
  8312. }
  8313. if (support_changed && (link_info->autoneg & BNXT_AUTONEG_SPEED))
  8314. bnxt_hwrm_set_link_setting(bp, true, false);
  8315. return 0;
  8316. }
  8317. static void bnxt_get_port_module_status(struct bnxt *bp)
  8318. {
  8319. struct bnxt_link_info *link_info = &bp->link_info;
  8320. struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
  8321. u8 module_status;
  8322. if (bnxt_update_link(bp, true))
  8323. return;
  8324. module_status = link_info->module_status;
  8325. switch (module_status) {
  8326. case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
  8327. case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
  8328. case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
  8329. netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
  8330. bp->pf.port_id);
  8331. if (bp->hwrm_spec_code >= 0x10201) {
  8332. netdev_warn(bp->dev, "Module part number %s\n",
  8333. resp->phy_vendor_partnumber);
  8334. }
  8335. if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
  8336. netdev_warn(bp->dev, "TX is disabled\n");
  8337. if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
  8338. netdev_warn(bp->dev, "SFP+ module is shutdown\n");
  8339. }
  8340. }
  8341. static void
  8342. bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
  8343. {
  8344. if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
  8345. if (bp->hwrm_spec_code >= 0x10201)
  8346. req->auto_pause =
  8347. PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
  8348. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
  8349. req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
  8350. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
  8351. req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
  8352. req->enables |=
  8353. cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
  8354. } else {
  8355. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
  8356. req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
  8357. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
  8358. req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
  8359. req->enables |=
  8360. cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
  8361. if (bp->hwrm_spec_code >= 0x10201) {
  8362. req->auto_pause = req->force_pause;
  8363. req->enables |= cpu_to_le32(
  8364. PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
  8365. }
  8366. }
  8367. }
  8368. static void bnxt_hwrm_set_link_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
  8369. {
  8370. if (bp->link_info.autoneg & BNXT_AUTONEG_SPEED) {
  8371. req->auto_mode |= PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
  8372. if (bp->link_info.advertising) {
  8373. req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
  8374. req->auto_link_speed_mask = cpu_to_le16(bp->link_info.advertising);
  8375. }
  8376. if (bp->link_info.advertising_pam4) {
  8377. req->enables |=
  8378. cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAM4_LINK_SPEED_MASK);
  8379. req->auto_link_pam4_speed_mask =
  8380. cpu_to_le16(bp->link_info.advertising_pam4);
  8381. }
  8382. req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
  8383. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
  8384. } else {
  8385. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
  8386. if (bp->link_info.req_signal_mode == BNXT_SIG_MODE_PAM4) {
  8387. req->force_pam4_link_speed = cpu_to_le16(bp->link_info.req_link_speed);
  8388. req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAM4_LINK_SPEED);
  8389. } else {
  8390. req->force_link_speed = cpu_to_le16(bp->link_info.req_link_speed);
  8391. }
  8392. }
  8393. /* tell chimp that the setting takes effect immediately */
  8394. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
  8395. }
  8396. int bnxt_hwrm_set_pause(struct bnxt *bp)
  8397. {
  8398. struct hwrm_port_phy_cfg_input *req;
  8399. int rc;
  8400. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_CFG);
  8401. if (rc)
  8402. return rc;
  8403. bnxt_hwrm_set_pause_common(bp, req);
  8404. if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
  8405. bp->link_info.force_link_chng)
  8406. bnxt_hwrm_set_link_common(bp, req);
  8407. rc = hwrm_req_send(bp, req);
  8408. if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
  8409. /* since changing of pause setting doesn't trigger any link
  8410. * change event, the driver needs to update the current pause
  8411. * result upon successfully return of the phy_cfg command
  8412. */
  8413. bp->link_info.pause =
  8414. bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
  8415. bp->link_info.auto_pause_setting = 0;
  8416. if (!bp->link_info.force_link_chng)
  8417. bnxt_report_link(bp);
  8418. }
  8419. bp->link_info.force_link_chng = false;
  8420. return rc;
  8421. }
  8422. static void bnxt_hwrm_set_eee(struct bnxt *bp,
  8423. struct hwrm_port_phy_cfg_input *req)
  8424. {
  8425. struct ethtool_eee *eee = &bp->eee;
  8426. if (eee->eee_enabled) {
  8427. u16 eee_speeds;
  8428. u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
  8429. if (eee->tx_lpi_enabled)
  8430. flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
  8431. else
  8432. flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
  8433. req->flags |= cpu_to_le32(flags);
  8434. eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
  8435. req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
  8436. req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
  8437. } else {
  8438. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
  8439. }
  8440. }
  8441. int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
  8442. {
  8443. struct hwrm_port_phy_cfg_input *req;
  8444. int rc;
  8445. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_CFG);
  8446. if (rc)
  8447. return rc;
  8448. if (set_pause)
  8449. bnxt_hwrm_set_pause_common(bp, req);
  8450. bnxt_hwrm_set_link_common(bp, req);
  8451. if (set_eee)
  8452. bnxt_hwrm_set_eee(bp, req);
  8453. return hwrm_req_send(bp, req);
  8454. }
  8455. static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
  8456. {
  8457. struct hwrm_port_phy_cfg_input *req;
  8458. int rc;
  8459. if (!BNXT_SINGLE_PF(bp))
  8460. return 0;
  8461. if (pci_num_vf(bp->pdev) &&
  8462. !(bp->phy_flags & BNXT_PHY_FL_FW_MANAGED_LKDN))
  8463. return 0;
  8464. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_CFG);
  8465. if (rc)
  8466. return rc;
  8467. req->flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
  8468. rc = hwrm_req_send(bp, req);
  8469. if (!rc) {
  8470. mutex_lock(&bp->link_lock);
  8471. /* Device is not obliged link down in certain scenarios, even
  8472. * when forced. Setting the state unknown is consistent with
  8473. * driver startup and will force link state to be reported
  8474. * during subsequent open based on PORT_PHY_QCFG.
  8475. */
  8476. bp->link_info.link_state = BNXT_LINK_STATE_UNKNOWN;
  8477. mutex_unlock(&bp->link_lock);
  8478. }
  8479. return rc;
  8480. }
  8481. static int bnxt_fw_reset_via_optee(struct bnxt *bp)
  8482. {
  8483. #ifdef CONFIG_TEE_BNXT_FW
  8484. int rc = tee_bnxt_fw_load();
  8485. if (rc)
  8486. netdev_err(bp->dev, "Failed FW reset via OP-TEE, rc=%d\n", rc);
  8487. return rc;
  8488. #else
  8489. netdev_err(bp->dev, "OP-TEE not supported\n");
  8490. return -ENODEV;
  8491. #endif
  8492. }
  8493. static int bnxt_try_recover_fw(struct bnxt *bp)
  8494. {
  8495. if (bp->fw_health && bp->fw_health->status_reliable) {
  8496. int retry = 0, rc;
  8497. u32 sts;
  8498. do {
  8499. sts = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
  8500. rc = bnxt_hwrm_poll(bp);
  8501. if (!BNXT_FW_IS_BOOTING(sts) &&
  8502. !BNXT_FW_IS_RECOVERING(sts))
  8503. break;
  8504. retry++;
  8505. } while (rc == -EBUSY && retry < BNXT_FW_RETRY);
  8506. if (!BNXT_FW_IS_HEALTHY(sts)) {
  8507. netdev_err(bp->dev,
  8508. "Firmware not responding, status: 0x%x\n",
  8509. sts);
  8510. rc = -ENODEV;
  8511. }
  8512. if (sts & FW_STATUS_REG_CRASHED_NO_MASTER) {
  8513. netdev_warn(bp->dev, "Firmware recover via OP-TEE requested\n");
  8514. return bnxt_fw_reset_via_optee(bp);
  8515. }
  8516. return rc;
  8517. }
  8518. return -ENODEV;
  8519. }
  8520. static void bnxt_clear_reservations(struct bnxt *bp, bool fw_reset)
  8521. {
  8522. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  8523. if (!BNXT_NEW_RM(bp))
  8524. return; /* no resource reservations required */
  8525. hw_resc->resv_cp_rings = 0;
  8526. hw_resc->resv_stat_ctxs = 0;
  8527. hw_resc->resv_irqs = 0;
  8528. hw_resc->resv_tx_rings = 0;
  8529. hw_resc->resv_rx_rings = 0;
  8530. hw_resc->resv_hw_ring_grps = 0;
  8531. hw_resc->resv_vnics = 0;
  8532. if (!fw_reset) {
  8533. bp->tx_nr_rings = 0;
  8534. bp->rx_nr_rings = 0;
  8535. }
  8536. }
  8537. int bnxt_cancel_reservations(struct bnxt *bp, bool fw_reset)
  8538. {
  8539. int rc;
  8540. if (!BNXT_NEW_RM(bp))
  8541. return 0; /* no resource reservations required */
  8542. rc = bnxt_hwrm_func_resc_qcaps(bp, true);
  8543. if (rc)
  8544. netdev_err(bp->dev, "resc_qcaps failed\n");
  8545. bnxt_clear_reservations(bp, fw_reset);
  8546. return rc;
  8547. }
  8548. static int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
  8549. {
  8550. struct hwrm_func_drv_if_change_output *resp;
  8551. struct hwrm_func_drv_if_change_input *req;
  8552. bool fw_reset = !bp->irq_tbl;
  8553. bool resc_reinit = false;
  8554. int rc, retry = 0;
  8555. u32 flags = 0;
  8556. if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
  8557. return 0;
  8558. rc = hwrm_req_init(bp, req, HWRM_FUNC_DRV_IF_CHANGE);
  8559. if (rc)
  8560. return rc;
  8561. if (up)
  8562. req->flags = cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP);
  8563. resp = hwrm_req_hold(bp, req);
  8564. hwrm_req_flags(bp, req, BNXT_HWRM_FULL_WAIT);
  8565. while (retry < BNXT_FW_IF_RETRY) {
  8566. rc = hwrm_req_send(bp, req);
  8567. if (rc != -EAGAIN)
  8568. break;
  8569. msleep(50);
  8570. retry++;
  8571. }
  8572. if (rc == -EAGAIN) {
  8573. hwrm_req_drop(bp, req);
  8574. return rc;
  8575. } else if (!rc) {
  8576. flags = le32_to_cpu(resp->flags);
  8577. } else if (up) {
  8578. rc = bnxt_try_recover_fw(bp);
  8579. fw_reset = true;
  8580. }
  8581. hwrm_req_drop(bp, req);
  8582. if (rc)
  8583. return rc;
  8584. if (!up) {
  8585. bnxt_inv_fw_health_reg(bp);
  8586. return 0;
  8587. }
  8588. if (flags & FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE)
  8589. resc_reinit = true;
  8590. if (flags & FUNC_DRV_IF_CHANGE_RESP_FLAGS_HOT_FW_RESET_DONE ||
  8591. test_bit(BNXT_STATE_FW_RESET_DET, &bp->state))
  8592. fw_reset = true;
  8593. else
  8594. bnxt_remap_fw_health_regs(bp);
  8595. if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state) && !fw_reset) {
  8596. netdev_err(bp->dev, "RESET_DONE not set during FW reset.\n");
  8597. set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
  8598. return -ENODEV;
  8599. }
  8600. if (resc_reinit || fw_reset) {
  8601. if (fw_reset) {
  8602. set_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
  8603. if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
  8604. bnxt_ulp_stop(bp);
  8605. bnxt_free_ctx_mem(bp);
  8606. kfree(bp->ctx);
  8607. bp->ctx = NULL;
  8608. bnxt_dcb_free(bp);
  8609. rc = bnxt_fw_init_one(bp);
  8610. if (rc) {
  8611. clear_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
  8612. set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
  8613. return rc;
  8614. }
  8615. bnxt_clear_int_mode(bp);
  8616. rc = bnxt_init_int_mode(bp);
  8617. if (rc) {
  8618. clear_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
  8619. netdev_err(bp->dev, "init int mode failed\n");
  8620. return rc;
  8621. }
  8622. }
  8623. rc = bnxt_cancel_reservations(bp, fw_reset);
  8624. }
  8625. return rc;
  8626. }
  8627. static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
  8628. {
  8629. struct hwrm_port_led_qcaps_output *resp;
  8630. struct hwrm_port_led_qcaps_input *req;
  8631. struct bnxt_pf_info *pf = &bp->pf;
  8632. int rc;
  8633. bp->num_leds = 0;
  8634. if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
  8635. return 0;
  8636. rc = hwrm_req_init(bp, req, HWRM_PORT_LED_QCAPS);
  8637. if (rc)
  8638. return rc;
  8639. req->port_id = cpu_to_le16(pf->port_id);
  8640. resp = hwrm_req_hold(bp, req);
  8641. rc = hwrm_req_send(bp, req);
  8642. if (rc) {
  8643. hwrm_req_drop(bp, req);
  8644. return rc;
  8645. }
  8646. if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
  8647. int i;
  8648. bp->num_leds = resp->num_leds;
  8649. memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
  8650. bp->num_leds);
  8651. for (i = 0; i < bp->num_leds; i++) {
  8652. struct bnxt_led_info *led = &bp->leds[i];
  8653. __le16 caps = led->led_state_caps;
  8654. if (!led->led_group_id ||
  8655. !BNXT_LED_ALT_BLINK_CAP(caps)) {
  8656. bp->num_leds = 0;
  8657. break;
  8658. }
  8659. }
  8660. }
  8661. hwrm_req_drop(bp, req);
  8662. return 0;
  8663. }
  8664. int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
  8665. {
  8666. struct hwrm_wol_filter_alloc_output *resp;
  8667. struct hwrm_wol_filter_alloc_input *req;
  8668. int rc;
  8669. rc = hwrm_req_init(bp, req, HWRM_WOL_FILTER_ALLOC);
  8670. if (rc)
  8671. return rc;
  8672. req->port_id = cpu_to_le16(bp->pf.port_id);
  8673. req->wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
  8674. req->enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
  8675. memcpy(req->mac_address, bp->dev->dev_addr, ETH_ALEN);
  8676. resp = hwrm_req_hold(bp, req);
  8677. rc = hwrm_req_send(bp, req);
  8678. if (!rc)
  8679. bp->wol_filter_id = resp->wol_filter_id;
  8680. hwrm_req_drop(bp, req);
  8681. return rc;
  8682. }
  8683. int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
  8684. {
  8685. struct hwrm_wol_filter_free_input *req;
  8686. int rc;
  8687. rc = hwrm_req_init(bp, req, HWRM_WOL_FILTER_FREE);
  8688. if (rc)
  8689. return rc;
  8690. req->port_id = cpu_to_le16(bp->pf.port_id);
  8691. req->enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
  8692. req->wol_filter_id = bp->wol_filter_id;
  8693. return hwrm_req_send(bp, req);
  8694. }
  8695. static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
  8696. {
  8697. struct hwrm_wol_filter_qcfg_output *resp;
  8698. struct hwrm_wol_filter_qcfg_input *req;
  8699. u16 next_handle = 0;
  8700. int rc;
  8701. rc = hwrm_req_init(bp, req, HWRM_WOL_FILTER_QCFG);
  8702. if (rc)
  8703. return rc;
  8704. req->port_id = cpu_to_le16(bp->pf.port_id);
  8705. req->handle = cpu_to_le16(handle);
  8706. resp = hwrm_req_hold(bp, req);
  8707. rc = hwrm_req_send(bp, req);
  8708. if (!rc) {
  8709. next_handle = le16_to_cpu(resp->next_handle);
  8710. if (next_handle != 0) {
  8711. if (resp->wol_type ==
  8712. WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
  8713. bp->wol = 1;
  8714. bp->wol_filter_id = resp->wol_filter_id;
  8715. }
  8716. }
  8717. }
  8718. hwrm_req_drop(bp, req);
  8719. return next_handle;
  8720. }
  8721. static void bnxt_get_wol_settings(struct bnxt *bp)
  8722. {
  8723. u16 handle = 0;
  8724. bp->wol = 0;
  8725. if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
  8726. return;
  8727. do {
  8728. handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
  8729. } while (handle && handle != 0xffff);
  8730. }
  8731. #ifdef CONFIG_BNXT_HWMON
  8732. static ssize_t bnxt_show_temp(struct device *dev,
  8733. struct device_attribute *devattr, char *buf)
  8734. {
  8735. struct hwrm_temp_monitor_query_output *resp;
  8736. struct hwrm_temp_monitor_query_input *req;
  8737. struct bnxt *bp = dev_get_drvdata(dev);
  8738. u32 len = 0;
  8739. int rc;
  8740. rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
  8741. if (rc)
  8742. return rc;
  8743. resp = hwrm_req_hold(bp, req);
  8744. rc = hwrm_req_send(bp, req);
  8745. if (!rc)
  8746. len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
  8747. hwrm_req_drop(bp, req);
  8748. if (rc)
  8749. return rc;
  8750. return len;
  8751. }
  8752. static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
  8753. static struct attribute *bnxt_attrs[] = {
  8754. &sensor_dev_attr_temp1_input.dev_attr.attr,
  8755. NULL
  8756. };
  8757. ATTRIBUTE_GROUPS(bnxt);
  8758. static void bnxt_hwmon_close(struct bnxt *bp)
  8759. {
  8760. if (bp->hwmon_dev) {
  8761. hwmon_device_unregister(bp->hwmon_dev);
  8762. bp->hwmon_dev = NULL;
  8763. }
  8764. }
  8765. static void bnxt_hwmon_open(struct bnxt *bp)
  8766. {
  8767. struct hwrm_temp_monitor_query_input *req;
  8768. struct pci_dev *pdev = bp->pdev;
  8769. int rc;
  8770. rc = hwrm_req_init(bp, req, HWRM_TEMP_MONITOR_QUERY);
  8771. if (!rc)
  8772. rc = hwrm_req_send_silent(bp, req);
  8773. if (rc == -EACCES || rc == -EOPNOTSUPP) {
  8774. bnxt_hwmon_close(bp);
  8775. return;
  8776. }
  8777. if (bp->hwmon_dev)
  8778. return;
  8779. bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev,
  8780. DRV_MODULE_NAME, bp,
  8781. bnxt_groups);
  8782. if (IS_ERR(bp->hwmon_dev)) {
  8783. bp->hwmon_dev = NULL;
  8784. dev_warn(&pdev->dev, "Cannot register hwmon device\n");
  8785. }
  8786. }
  8787. #else
  8788. static void bnxt_hwmon_close(struct bnxt *bp)
  8789. {
  8790. }
  8791. static void bnxt_hwmon_open(struct bnxt *bp)
  8792. {
  8793. }
  8794. #endif
  8795. static bool bnxt_eee_config_ok(struct bnxt *bp)
  8796. {
  8797. struct ethtool_eee *eee = &bp->eee;
  8798. struct bnxt_link_info *link_info = &bp->link_info;
  8799. if (!(bp->phy_flags & BNXT_PHY_FL_EEE_CAP))
  8800. return true;
  8801. if (eee->eee_enabled) {
  8802. u32 advertising =
  8803. _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
  8804. if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
  8805. eee->eee_enabled = 0;
  8806. return false;
  8807. }
  8808. if (eee->advertised & ~advertising) {
  8809. eee->advertised = advertising & eee->supported;
  8810. return false;
  8811. }
  8812. }
  8813. return true;
  8814. }
  8815. static int bnxt_update_phy_setting(struct bnxt *bp)
  8816. {
  8817. int rc;
  8818. bool update_link = false;
  8819. bool update_pause = false;
  8820. bool update_eee = false;
  8821. struct bnxt_link_info *link_info = &bp->link_info;
  8822. rc = bnxt_update_link(bp, true);
  8823. if (rc) {
  8824. netdev_err(bp->dev, "failed to update link (rc: %x)\n",
  8825. rc);
  8826. return rc;
  8827. }
  8828. if (!BNXT_SINGLE_PF(bp))
  8829. return 0;
  8830. if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
  8831. (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
  8832. link_info->req_flow_ctrl)
  8833. update_pause = true;
  8834. if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
  8835. link_info->force_pause_setting != link_info->req_flow_ctrl)
  8836. update_pause = true;
  8837. if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
  8838. if (BNXT_AUTO_MODE(link_info->auto_mode))
  8839. update_link = true;
  8840. if (link_info->req_signal_mode == BNXT_SIG_MODE_NRZ &&
  8841. link_info->req_link_speed != link_info->force_link_speed)
  8842. update_link = true;
  8843. else if (link_info->req_signal_mode == BNXT_SIG_MODE_PAM4 &&
  8844. link_info->req_link_speed != link_info->force_pam4_link_speed)
  8845. update_link = true;
  8846. if (link_info->req_duplex != link_info->duplex_setting)
  8847. update_link = true;
  8848. } else {
  8849. if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
  8850. update_link = true;
  8851. if (link_info->advertising != link_info->auto_link_speeds ||
  8852. link_info->advertising_pam4 != link_info->auto_pam4_link_speeds)
  8853. update_link = true;
  8854. }
  8855. /* The last close may have shutdown the link, so need to call
  8856. * PHY_CFG to bring it back up.
  8857. */
  8858. if (!BNXT_LINK_IS_UP(bp))
  8859. update_link = true;
  8860. if (!bnxt_eee_config_ok(bp))
  8861. update_eee = true;
  8862. if (update_link)
  8863. rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
  8864. else if (update_pause)
  8865. rc = bnxt_hwrm_set_pause(bp);
  8866. if (rc) {
  8867. netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
  8868. rc);
  8869. return rc;
  8870. }
  8871. return rc;
  8872. }
  8873. /* Common routine to pre-map certain register block to different GRC window.
  8874. * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
  8875. * in PF and 3 windows in VF that can be customized to map in different
  8876. * register blocks.
  8877. */
  8878. static void bnxt_preset_reg_win(struct bnxt *bp)
  8879. {
  8880. if (BNXT_PF(bp)) {
  8881. /* CAG registers map to GRC window #4 */
  8882. writel(BNXT_CAG_REG_BASE,
  8883. bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
  8884. }
  8885. }
  8886. static int bnxt_init_dflt_ring_mode(struct bnxt *bp);
  8887. static int bnxt_reinit_after_abort(struct bnxt *bp)
  8888. {
  8889. int rc;
  8890. if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
  8891. return -EBUSY;
  8892. if (bp->dev->reg_state == NETREG_UNREGISTERED)
  8893. return -ENODEV;
  8894. rc = bnxt_fw_init_one(bp);
  8895. if (!rc) {
  8896. bnxt_clear_int_mode(bp);
  8897. rc = bnxt_init_int_mode(bp);
  8898. if (!rc) {
  8899. clear_bit(BNXT_STATE_ABORT_ERR, &bp->state);
  8900. set_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
  8901. }
  8902. }
  8903. return rc;
  8904. }
  8905. static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  8906. {
  8907. int rc = 0;
  8908. bnxt_preset_reg_win(bp);
  8909. netif_carrier_off(bp->dev);
  8910. if (irq_re_init) {
  8911. /* Reserve rings now if none were reserved at driver probe. */
  8912. rc = bnxt_init_dflt_ring_mode(bp);
  8913. if (rc) {
  8914. netdev_err(bp->dev, "Failed to reserve default rings at open\n");
  8915. return rc;
  8916. }
  8917. }
  8918. rc = bnxt_reserve_rings(bp, irq_re_init);
  8919. if (rc)
  8920. return rc;
  8921. if ((bp->flags & BNXT_FLAG_RFS) &&
  8922. !(bp->flags & BNXT_FLAG_USING_MSIX)) {
  8923. /* disable RFS if falling back to INTA */
  8924. bp->dev->hw_features &= ~NETIF_F_NTUPLE;
  8925. bp->flags &= ~BNXT_FLAG_RFS;
  8926. }
  8927. rc = bnxt_alloc_mem(bp, irq_re_init);
  8928. if (rc) {
  8929. netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
  8930. goto open_err_free_mem;
  8931. }
  8932. if (irq_re_init) {
  8933. bnxt_init_napi(bp);
  8934. rc = bnxt_request_irq(bp);
  8935. if (rc) {
  8936. netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
  8937. goto open_err_irq;
  8938. }
  8939. }
  8940. rc = bnxt_init_nic(bp, irq_re_init);
  8941. if (rc) {
  8942. netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
  8943. goto open_err_irq;
  8944. }
  8945. bnxt_enable_napi(bp);
  8946. bnxt_debug_dev_init(bp);
  8947. if (link_re_init) {
  8948. mutex_lock(&bp->link_lock);
  8949. rc = bnxt_update_phy_setting(bp);
  8950. mutex_unlock(&bp->link_lock);
  8951. if (rc) {
  8952. netdev_warn(bp->dev, "failed to update phy settings\n");
  8953. if (BNXT_SINGLE_PF(bp)) {
  8954. bp->link_info.phy_retry = true;
  8955. bp->link_info.phy_retry_expires =
  8956. jiffies + 5 * HZ;
  8957. }
  8958. }
  8959. }
  8960. if (irq_re_init)
  8961. udp_tunnel_nic_reset_ntf(bp->dev);
  8962. if (bp->tx_nr_rings_xdp < num_possible_cpus()) {
  8963. if (!static_key_enabled(&bnxt_xdp_locking_key))
  8964. static_branch_enable(&bnxt_xdp_locking_key);
  8965. } else if (static_key_enabled(&bnxt_xdp_locking_key)) {
  8966. static_branch_disable(&bnxt_xdp_locking_key);
  8967. }
  8968. set_bit(BNXT_STATE_OPEN, &bp->state);
  8969. bnxt_enable_int(bp);
  8970. /* Enable TX queues */
  8971. bnxt_tx_enable(bp);
  8972. mod_timer(&bp->timer, jiffies + bp->current_interval);
  8973. /* Poll link status and check for SFP+ module status */
  8974. mutex_lock(&bp->link_lock);
  8975. bnxt_get_port_module_status(bp);
  8976. mutex_unlock(&bp->link_lock);
  8977. /* VF-reps may need to be re-opened after the PF is re-opened */
  8978. if (BNXT_PF(bp))
  8979. bnxt_vf_reps_open(bp);
  8980. bnxt_ptp_init_rtc(bp, true);
  8981. bnxt_ptp_cfg_tstamp_filters(bp);
  8982. return 0;
  8983. open_err_irq:
  8984. bnxt_del_napi(bp);
  8985. open_err_free_mem:
  8986. bnxt_free_skbs(bp);
  8987. bnxt_free_irq(bp);
  8988. bnxt_free_mem(bp, true);
  8989. return rc;
  8990. }
  8991. /* rtnl_lock held */
  8992. int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  8993. {
  8994. int rc = 0;
  8995. if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state))
  8996. rc = -EIO;
  8997. if (!rc)
  8998. rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
  8999. if (rc) {
  9000. netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
  9001. dev_close(bp->dev);
  9002. }
  9003. return rc;
  9004. }
  9005. /* rtnl_lock held, open the NIC half way by allocating all resources, but
  9006. * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
  9007. * self tests.
  9008. */
  9009. int bnxt_half_open_nic(struct bnxt *bp)
  9010. {
  9011. int rc = 0;
  9012. if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
  9013. netdev_err(bp->dev, "A previous firmware reset has not completed, aborting half open\n");
  9014. rc = -ENODEV;
  9015. goto half_open_err;
  9016. }
  9017. rc = bnxt_alloc_mem(bp, true);
  9018. if (rc) {
  9019. netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
  9020. goto half_open_err;
  9021. }
  9022. set_bit(BNXT_STATE_HALF_OPEN, &bp->state);
  9023. rc = bnxt_init_nic(bp, true);
  9024. if (rc) {
  9025. clear_bit(BNXT_STATE_HALF_OPEN, &bp->state);
  9026. netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
  9027. goto half_open_err;
  9028. }
  9029. return 0;
  9030. half_open_err:
  9031. bnxt_free_skbs(bp);
  9032. bnxt_free_mem(bp, true);
  9033. dev_close(bp->dev);
  9034. return rc;
  9035. }
  9036. /* rtnl_lock held, this call can only be made after a previous successful
  9037. * call to bnxt_half_open_nic().
  9038. */
  9039. void bnxt_half_close_nic(struct bnxt *bp)
  9040. {
  9041. bnxt_hwrm_resource_free(bp, false, true);
  9042. bnxt_free_skbs(bp);
  9043. bnxt_free_mem(bp, true);
  9044. clear_bit(BNXT_STATE_HALF_OPEN, &bp->state);
  9045. }
  9046. void bnxt_reenable_sriov(struct bnxt *bp)
  9047. {
  9048. if (BNXT_PF(bp)) {
  9049. struct bnxt_pf_info *pf = &bp->pf;
  9050. int n = pf->active_vfs;
  9051. if (n)
  9052. bnxt_cfg_hw_sriov(bp, &n, true);
  9053. }
  9054. }
  9055. static int bnxt_open(struct net_device *dev)
  9056. {
  9057. struct bnxt *bp = netdev_priv(dev);
  9058. int rc;
  9059. if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
  9060. rc = bnxt_reinit_after_abort(bp);
  9061. if (rc) {
  9062. if (rc == -EBUSY)
  9063. netdev_err(bp->dev, "A previous firmware reset has not completed, aborting\n");
  9064. else
  9065. netdev_err(bp->dev, "Failed to reinitialize after aborted firmware reset\n");
  9066. return -ENODEV;
  9067. }
  9068. }
  9069. rc = bnxt_hwrm_if_change(bp, true);
  9070. if (rc)
  9071. return rc;
  9072. rc = __bnxt_open_nic(bp, true, true);
  9073. if (rc) {
  9074. bnxt_hwrm_if_change(bp, false);
  9075. } else {
  9076. if (test_and_clear_bit(BNXT_STATE_FW_RESET_DET, &bp->state)) {
  9077. if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
  9078. bnxt_ulp_start(bp, 0);
  9079. bnxt_reenable_sriov(bp);
  9080. }
  9081. }
  9082. bnxt_hwmon_open(bp);
  9083. }
  9084. return rc;
  9085. }
  9086. static bool bnxt_drv_busy(struct bnxt *bp)
  9087. {
  9088. return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) ||
  9089. test_bit(BNXT_STATE_READ_STATS, &bp->state));
  9090. }
  9091. static void bnxt_get_ring_stats(struct bnxt *bp,
  9092. struct rtnl_link_stats64 *stats);
  9093. static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init,
  9094. bool link_re_init)
  9095. {
  9096. /* Close the VF-reps before closing PF */
  9097. if (BNXT_PF(bp))
  9098. bnxt_vf_reps_close(bp);
  9099. /* Change device state to avoid TX queue wake up's */
  9100. bnxt_tx_disable(bp);
  9101. clear_bit(BNXT_STATE_OPEN, &bp->state);
  9102. smp_mb__after_atomic();
  9103. while (bnxt_drv_busy(bp))
  9104. msleep(20);
  9105. /* Flush rings and disable interrupts */
  9106. bnxt_shutdown_nic(bp, irq_re_init);
  9107. /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
  9108. bnxt_debug_dev_exit(bp);
  9109. bnxt_disable_napi(bp);
  9110. del_timer_sync(&bp->timer);
  9111. bnxt_free_skbs(bp);
  9112. /* Save ring stats before shutdown */
  9113. if (bp->bnapi && irq_re_init)
  9114. bnxt_get_ring_stats(bp, &bp->net_stats_prev);
  9115. if (irq_re_init) {
  9116. bnxt_free_irq(bp);
  9117. bnxt_del_napi(bp);
  9118. }
  9119. bnxt_free_mem(bp, irq_re_init);
  9120. }
  9121. int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  9122. {
  9123. int rc = 0;
  9124. if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
  9125. /* If we get here, it means firmware reset is in progress
  9126. * while we are trying to close. We can safely proceed with
  9127. * the close because we are holding rtnl_lock(). Some firmware
  9128. * messages may fail as we proceed to close. We set the
  9129. * ABORT_ERR flag here so that the FW reset thread will later
  9130. * abort when it gets the rtnl_lock() and sees the flag.
  9131. */
  9132. netdev_warn(bp->dev, "FW reset in progress during close, FW reset will be aborted\n");
  9133. set_bit(BNXT_STATE_ABORT_ERR, &bp->state);
  9134. }
  9135. #ifdef CONFIG_BNXT_SRIOV
  9136. if (bp->sriov_cfg) {
  9137. rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
  9138. !bp->sriov_cfg,
  9139. BNXT_SRIOV_CFG_WAIT_TMO);
  9140. if (rc)
  9141. netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
  9142. }
  9143. #endif
  9144. __bnxt_close_nic(bp, irq_re_init, link_re_init);
  9145. return rc;
  9146. }
  9147. static int bnxt_close(struct net_device *dev)
  9148. {
  9149. struct bnxt *bp = netdev_priv(dev);
  9150. bnxt_hwmon_close(bp);
  9151. bnxt_close_nic(bp, true, true);
  9152. bnxt_hwrm_shutdown_link(bp);
  9153. bnxt_hwrm_if_change(bp, false);
  9154. return 0;
  9155. }
  9156. static int bnxt_hwrm_port_phy_read(struct bnxt *bp, u16 phy_addr, u16 reg,
  9157. u16 *val)
  9158. {
  9159. struct hwrm_port_phy_mdio_read_output *resp;
  9160. struct hwrm_port_phy_mdio_read_input *req;
  9161. int rc;
  9162. if (bp->hwrm_spec_code < 0x10a00)
  9163. return -EOPNOTSUPP;
  9164. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_MDIO_READ);
  9165. if (rc)
  9166. return rc;
  9167. req->port_id = cpu_to_le16(bp->pf.port_id);
  9168. req->phy_addr = phy_addr;
  9169. req->reg_addr = cpu_to_le16(reg & 0x1f);
  9170. if (mdio_phy_id_is_c45(phy_addr)) {
  9171. req->cl45_mdio = 1;
  9172. req->phy_addr = mdio_phy_id_prtad(phy_addr);
  9173. req->dev_addr = mdio_phy_id_devad(phy_addr);
  9174. req->reg_addr = cpu_to_le16(reg);
  9175. }
  9176. resp = hwrm_req_hold(bp, req);
  9177. rc = hwrm_req_send(bp, req);
  9178. if (!rc)
  9179. *val = le16_to_cpu(resp->reg_data);
  9180. hwrm_req_drop(bp, req);
  9181. return rc;
  9182. }
  9183. static int bnxt_hwrm_port_phy_write(struct bnxt *bp, u16 phy_addr, u16 reg,
  9184. u16 val)
  9185. {
  9186. struct hwrm_port_phy_mdio_write_input *req;
  9187. int rc;
  9188. if (bp->hwrm_spec_code < 0x10a00)
  9189. return -EOPNOTSUPP;
  9190. rc = hwrm_req_init(bp, req, HWRM_PORT_PHY_MDIO_WRITE);
  9191. if (rc)
  9192. return rc;
  9193. req->port_id = cpu_to_le16(bp->pf.port_id);
  9194. req->phy_addr = phy_addr;
  9195. req->reg_addr = cpu_to_le16(reg & 0x1f);
  9196. if (mdio_phy_id_is_c45(phy_addr)) {
  9197. req->cl45_mdio = 1;
  9198. req->phy_addr = mdio_phy_id_prtad(phy_addr);
  9199. req->dev_addr = mdio_phy_id_devad(phy_addr);
  9200. req->reg_addr = cpu_to_le16(reg);
  9201. }
  9202. req->reg_data = cpu_to_le16(val);
  9203. return hwrm_req_send(bp, req);
  9204. }
  9205. /* rtnl_lock held */
  9206. static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9207. {
  9208. struct mii_ioctl_data *mdio = if_mii(ifr);
  9209. struct bnxt *bp = netdev_priv(dev);
  9210. int rc;
  9211. switch (cmd) {
  9212. case SIOCGMIIPHY:
  9213. mdio->phy_id = bp->link_info.phy_addr;
  9214. fallthrough;
  9215. case SIOCGMIIREG: {
  9216. u16 mii_regval = 0;
  9217. if (!netif_running(dev))
  9218. return -EAGAIN;
  9219. rc = bnxt_hwrm_port_phy_read(bp, mdio->phy_id, mdio->reg_num,
  9220. &mii_regval);
  9221. mdio->val_out = mii_regval;
  9222. return rc;
  9223. }
  9224. case SIOCSMIIREG:
  9225. if (!netif_running(dev))
  9226. return -EAGAIN;
  9227. return bnxt_hwrm_port_phy_write(bp, mdio->phy_id, mdio->reg_num,
  9228. mdio->val_in);
  9229. case SIOCSHWTSTAMP:
  9230. return bnxt_hwtstamp_set(dev, ifr);
  9231. case SIOCGHWTSTAMP:
  9232. return bnxt_hwtstamp_get(dev, ifr);
  9233. default:
  9234. /* do nothing */
  9235. break;
  9236. }
  9237. return -EOPNOTSUPP;
  9238. }
  9239. static void bnxt_get_ring_stats(struct bnxt *bp,
  9240. struct rtnl_link_stats64 *stats)
  9241. {
  9242. int i;
  9243. for (i = 0; i < bp->cp_nr_rings; i++) {
  9244. struct bnxt_napi *bnapi = bp->bnapi[i];
  9245. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  9246. u64 *sw = cpr->stats.sw_stats;
  9247. stats->rx_packets += BNXT_GET_RING_STATS64(sw, rx_ucast_pkts);
  9248. stats->rx_packets += BNXT_GET_RING_STATS64(sw, rx_mcast_pkts);
  9249. stats->rx_packets += BNXT_GET_RING_STATS64(sw, rx_bcast_pkts);
  9250. stats->tx_packets += BNXT_GET_RING_STATS64(sw, tx_ucast_pkts);
  9251. stats->tx_packets += BNXT_GET_RING_STATS64(sw, tx_mcast_pkts);
  9252. stats->tx_packets += BNXT_GET_RING_STATS64(sw, tx_bcast_pkts);
  9253. stats->rx_bytes += BNXT_GET_RING_STATS64(sw, rx_ucast_bytes);
  9254. stats->rx_bytes += BNXT_GET_RING_STATS64(sw, rx_mcast_bytes);
  9255. stats->rx_bytes += BNXT_GET_RING_STATS64(sw, rx_bcast_bytes);
  9256. stats->tx_bytes += BNXT_GET_RING_STATS64(sw, tx_ucast_bytes);
  9257. stats->tx_bytes += BNXT_GET_RING_STATS64(sw, tx_mcast_bytes);
  9258. stats->tx_bytes += BNXT_GET_RING_STATS64(sw, tx_bcast_bytes);
  9259. stats->rx_missed_errors +=
  9260. BNXT_GET_RING_STATS64(sw, rx_discard_pkts);
  9261. stats->multicast += BNXT_GET_RING_STATS64(sw, rx_mcast_pkts);
  9262. stats->tx_dropped += BNXT_GET_RING_STATS64(sw, tx_error_pkts);
  9263. stats->rx_dropped +=
  9264. cpr->sw_stats.rx.rx_netpoll_discards +
  9265. cpr->sw_stats.rx.rx_oom_discards;
  9266. }
  9267. }
  9268. static void bnxt_add_prev_stats(struct bnxt *bp,
  9269. struct rtnl_link_stats64 *stats)
  9270. {
  9271. struct rtnl_link_stats64 *prev_stats = &bp->net_stats_prev;
  9272. stats->rx_packets += prev_stats->rx_packets;
  9273. stats->tx_packets += prev_stats->tx_packets;
  9274. stats->rx_bytes += prev_stats->rx_bytes;
  9275. stats->tx_bytes += prev_stats->tx_bytes;
  9276. stats->rx_missed_errors += prev_stats->rx_missed_errors;
  9277. stats->multicast += prev_stats->multicast;
  9278. stats->rx_dropped += prev_stats->rx_dropped;
  9279. stats->tx_dropped += prev_stats->tx_dropped;
  9280. }
  9281. static void
  9282. bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
  9283. {
  9284. struct bnxt *bp = netdev_priv(dev);
  9285. set_bit(BNXT_STATE_READ_STATS, &bp->state);
  9286. /* Make sure bnxt_close_nic() sees that we are reading stats before
  9287. * we check the BNXT_STATE_OPEN flag.
  9288. */
  9289. smp_mb__after_atomic();
  9290. if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
  9291. clear_bit(BNXT_STATE_READ_STATS, &bp->state);
  9292. *stats = bp->net_stats_prev;
  9293. return;
  9294. }
  9295. bnxt_get_ring_stats(bp, stats);
  9296. bnxt_add_prev_stats(bp, stats);
  9297. if (bp->flags & BNXT_FLAG_PORT_STATS) {
  9298. u64 *rx = bp->port_stats.sw_stats;
  9299. u64 *tx = bp->port_stats.sw_stats +
  9300. BNXT_TX_PORT_STATS_BYTE_OFFSET / 8;
  9301. stats->rx_crc_errors =
  9302. BNXT_GET_RX_PORT_STATS64(rx, rx_fcs_err_frames);
  9303. stats->rx_frame_errors =
  9304. BNXT_GET_RX_PORT_STATS64(rx, rx_align_err_frames);
  9305. stats->rx_length_errors =
  9306. BNXT_GET_RX_PORT_STATS64(rx, rx_undrsz_frames) +
  9307. BNXT_GET_RX_PORT_STATS64(rx, rx_ovrsz_frames) +
  9308. BNXT_GET_RX_PORT_STATS64(rx, rx_runt_frames);
  9309. stats->rx_errors =
  9310. BNXT_GET_RX_PORT_STATS64(rx, rx_false_carrier_frames) +
  9311. BNXT_GET_RX_PORT_STATS64(rx, rx_jbr_frames);
  9312. stats->collisions =
  9313. BNXT_GET_TX_PORT_STATS64(tx, tx_total_collisions);
  9314. stats->tx_fifo_errors =
  9315. BNXT_GET_TX_PORT_STATS64(tx, tx_fifo_underruns);
  9316. stats->tx_errors = BNXT_GET_TX_PORT_STATS64(tx, tx_err);
  9317. }
  9318. clear_bit(BNXT_STATE_READ_STATS, &bp->state);
  9319. }
  9320. static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
  9321. {
  9322. struct net_device *dev = bp->dev;
  9323. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  9324. struct netdev_hw_addr *ha;
  9325. u8 *haddr;
  9326. int mc_count = 0;
  9327. bool update = false;
  9328. int off = 0;
  9329. netdev_for_each_mc_addr(ha, dev) {
  9330. if (mc_count >= BNXT_MAX_MC_ADDRS) {
  9331. *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  9332. vnic->mc_list_count = 0;
  9333. return false;
  9334. }
  9335. haddr = ha->addr;
  9336. if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
  9337. memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
  9338. update = true;
  9339. }
  9340. off += ETH_ALEN;
  9341. mc_count++;
  9342. }
  9343. if (mc_count)
  9344. *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
  9345. if (mc_count != vnic->mc_list_count) {
  9346. vnic->mc_list_count = mc_count;
  9347. update = true;
  9348. }
  9349. return update;
  9350. }
  9351. static bool bnxt_uc_list_updated(struct bnxt *bp)
  9352. {
  9353. struct net_device *dev = bp->dev;
  9354. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  9355. struct netdev_hw_addr *ha;
  9356. int off = 0;
  9357. if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
  9358. return true;
  9359. netdev_for_each_uc_addr(ha, dev) {
  9360. if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
  9361. return true;
  9362. off += ETH_ALEN;
  9363. }
  9364. return false;
  9365. }
  9366. static void bnxt_set_rx_mode(struct net_device *dev)
  9367. {
  9368. struct bnxt *bp = netdev_priv(dev);
  9369. struct bnxt_vnic_info *vnic;
  9370. bool mc_update = false;
  9371. bool uc_update;
  9372. u32 mask;
  9373. if (!test_bit(BNXT_STATE_OPEN, &bp->state))
  9374. return;
  9375. vnic = &bp->vnic_info[0];
  9376. mask = vnic->rx_mask;
  9377. mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
  9378. CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
  9379. CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST |
  9380. CFA_L2_SET_RX_MASK_REQ_MASK_BCAST);
  9381. if (dev->flags & IFF_PROMISC)
  9382. mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  9383. uc_update = bnxt_uc_list_updated(bp);
  9384. if (dev->flags & IFF_BROADCAST)
  9385. mask |= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
  9386. if (dev->flags & IFF_ALLMULTI) {
  9387. mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  9388. vnic->mc_list_count = 0;
  9389. } else if (dev->flags & IFF_MULTICAST) {
  9390. mc_update = bnxt_mc_list_updated(bp, &mask);
  9391. }
  9392. if (mask != vnic->rx_mask || uc_update || mc_update) {
  9393. vnic->rx_mask = mask;
  9394. set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
  9395. bnxt_queue_sp_work(bp);
  9396. }
  9397. }
  9398. static int bnxt_cfg_rx_mode(struct bnxt *bp)
  9399. {
  9400. struct net_device *dev = bp->dev;
  9401. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  9402. struct hwrm_cfa_l2_filter_free_input *req;
  9403. struct netdev_hw_addr *ha;
  9404. int i, off = 0, rc;
  9405. bool uc_update;
  9406. netif_addr_lock_bh(dev);
  9407. uc_update = bnxt_uc_list_updated(bp);
  9408. netif_addr_unlock_bh(dev);
  9409. if (!uc_update)
  9410. goto skip_uc;
  9411. rc = hwrm_req_init(bp, req, HWRM_CFA_L2_FILTER_FREE);
  9412. if (rc)
  9413. return rc;
  9414. hwrm_req_hold(bp, req);
  9415. for (i = 1; i < vnic->uc_filter_count; i++) {
  9416. req->l2_filter_id = vnic->fw_l2_filter_id[i];
  9417. rc = hwrm_req_send(bp, req);
  9418. }
  9419. hwrm_req_drop(bp, req);
  9420. vnic->uc_filter_count = 1;
  9421. netif_addr_lock_bh(dev);
  9422. if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
  9423. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  9424. } else {
  9425. netdev_for_each_uc_addr(ha, dev) {
  9426. memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
  9427. off += ETH_ALEN;
  9428. vnic->uc_filter_count++;
  9429. }
  9430. }
  9431. netif_addr_unlock_bh(dev);
  9432. for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
  9433. rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
  9434. if (rc) {
  9435. if (BNXT_VF(bp) && rc == -ENODEV) {
  9436. if (!test_and_set_bit(BNXT_STATE_L2_FILTER_RETRY, &bp->state))
  9437. netdev_warn(bp->dev, "Cannot configure L2 filters while PF is unavailable, will retry\n");
  9438. else
  9439. netdev_dbg(bp->dev, "PF still unavailable while configuring L2 filters.\n");
  9440. rc = 0;
  9441. } else {
  9442. netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
  9443. }
  9444. vnic->uc_filter_count = i;
  9445. return rc;
  9446. }
  9447. }
  9448. if (test_and_clear_bit(BNXT_STATE_L2_FILTER_RETRY, &bp->state))
  9449. netdev_notice(bp->dev, "Retry of L2 filter configuration successful.\n");
  9450. skip_uc:
  9451. if ((vnic->rx_mask & CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS) &&
  9452. !bnxt_promisc_ok(bp))
  9453. vnic->rx_mask &= ~CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  9454. rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
  9455. if (rc && (vnic->rx_mask & CFA_L2_SET_RX_MASK_REQ_MASK_MCAST)) {
  9456. netdev_info(bp->dev, "Failed setting MC filters rc: %d, turning on ALL_MCAST mode\n",
  9457. rc);
  9458. vnic->rx_mask &= ~CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
  9459. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  9460. vnic->mc_list_count = 0;
  9461. rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
  9462. }
  9463. if (rc)
  9464. netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %d\n",
  9465. rc);
  9466. return rc;
  9467. }
  9468. static bool bnxt_can_reserve_rings(struct bnxt *bp)
  9469. {
  9470. #ifdef CONFIG_BNXT_SRIOV
  9471. if (BNXT_NEW_RM(bp) && BNXT_VF(bp)) {
  9472. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  9473. /* No minimum rings were provisioned by the PF. Don't
  9474. * reserve rings by default when device is down.
  9475. */
  9476. if (hw_resc->min_tx_rings || hw_resc->resv_tx_rings)
  9477. return true;
  9478. if (!netif_running(bp->dev))
  9479. return false;
  9480. }
  9481. #endif
  9482. return true;
  9483. }
  9484. /* If the chip and firmware supports RFS */
  9485. static bool bnxt_rfs_supported(struct bnxt *bp)
  9486. {
  9487. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  9488. if (bp->fw_cap & BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX_V2)
  9489. return true;
  9490. return false;
  9491. }
  9492. /* 212 firmware is broken for aRFS */
  9493. if (BNXT_FW_MAJ(bp) == 212)
  9494. return false;
  9495. if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
  9496. return true;
  9497. if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
  9498. return true;
  9499. return false;
  9500. }
  9501. /* If runtime conditions support RFS */
  9502. static bool bnxt_rfs_capable(struct bnxt *bp)
  9503. {
  9504. #ifdef CONFIG_RFS_ACCEL
  9505. int vnics, max_vnics, max_rss_ctxs;
  9506. if (bp->flags & BNXT_FLAG_CHIP_P5)
  9507. return bnxt_rfs_supported(bp);
  9508. if (!(bp->flags & BNXT_FLAG_MSIX_CAP) || !bnxt_can_reserve_rings(bp) || !bp->rx_nr_rings)
  9509. return false;
  9510. vnics = 1 + bp->rx_nr_rings;
  9511. max_vnics = bnxt_get_max_func_vnics(bp);
  9512. max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
  9513. /* RSS contexts not a limiting factor */
  9514. if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
  9515. max_rss_ctxs = max_vnics;
  9516. if (vnics > max_vnics || vnics > max_rss_ctxs) {
  9517. if (bp->rx_nr_rings > 1)
  9518. netdev_warn(bp->dev,
  9519. "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
  9520. min(max_rss_ctxs - 1, max_vnics - 1));
  9521. return false;
  9522. }
  9523. if (!BNXT_NEW_RM(bp))
  9524. return true;
  9525. if (vnics == bp->hw_resc.resv_vnics)
  9526. return true;
  9527. bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, vnics);
  9528. if (vnics <= bp->hw_resc.resv_vnics)
  9529. return true;
  9530. netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n");
  9531. bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 0, 1);
  9532. return false;
  9533. #else
  9534. return false;
  9535. #endif
  9536. }
  9537. static netdev_features_t bnxt_fix_features(struct net_device *dev,
  9538. netdev_features_t features)
  9539. {
  9540. struct bnxt *bp = netdev_priv(dev);
  9541. netdev_features_t vlan_features;
  9542. if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
  9543. features &= ~NETIF_F_NTUPLE;
  9544. if ((bp->flags & BNXT_FLAG_NO_AGG_RINGS) || bp->xdp_prog)
  9545. features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  9546. if (!(features & NETIF_F_GRO))
  9547. features &= ~NETIF_F_GRO_HW;
  9548. if (features & NETIF_F_GRO_HW)
  9549. features &= ~NETIF_F_LRO;
  9550. /* Both CTAG and STAG VLAN accelaration on the RX side have to be
  9551. * turned on or off together.
  9552. */
  9553. vlan_features = features & BNXT_HW_FEATURE_VLAN_ALL_RX;
  9554. if (vlan_features != BNXT_HW_FEATURE_VLAN_ALL_RX) {
  9555. if (dev->features & BNXT_HW_FEATURE_VLAN_ALL_RX)
  9556. features &= ~BNXT_HW_FEATURE_VLAN_ALL_RX;
  9557. else if (vlan_features)
  9558. features |= BNXT_HW_FEATURE_VLAN_ALL_RX;
  9559. }
  9560. #ifdef CONFIG_BNXT_SRIOV
  9561. if (BNXT_VF(bp) && bp->vf.vlan)
  9562. features &= ~BNXT_HW_FEATURE_VLAN_ALL_RX;
  9563. #endif
  9564. return features;
  9565. }
  9566. static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
  9567. {
  9568. struct bnxt *bp = netdev_priv(dev);
  9569. u32 flags = bp->flags;
  9570. u32 changes;
  9571. int rc = 0;
  9572. bool re_init = false;
  9573. bool update_tpa = false;
  9574. flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
  9575. if (features & NETIF_F_GRO_HW)
  9576. flags |= BNXT_FLAG_GRO;
  9577. else if (features & NETIF_F_LRO)
  9578. flags |= BNXT_FLAG_LRO;
  9579. if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
  9580. flags &= ~BNXT_FLAG_TPA;
  9581. if (features & BNXT_HW_FEATURE_VLAN_ALL_RX)
  9582. flags |= BNXT_FLAG_STRIP_VLAN;
  9583. if (features & NETIF_F_NTUPLE)
  9584. flags |= BNXT_FLAG_RFS;
  9585. changes = flags ^ bp->flags;
  9586. if (changes & BNXT_FLAG_TPA) {
  9587. update_tpa = true;
  9588. if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
  9589. (flags & BNXT_FLAG_TPA) == 0 ||
  9590. (bp->flags & BNXT_FLAG_CHIP_P5))
  9591. re_init = true;
  9592. }
  9593. if (changes & ~BNXT_FLAG_TPA)
  9594. re_init = true;
  9595. if (flags != bp->flags) {
  9596. u32 old_flags = bp->flags;
  9597. if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
  9598. bp->flags = flags;
  9599. if (update_tpa)
  9600. bnxt_set_ring_params(bp);
  9601. return rc;
  9602. }
  9603. if (re_init) {
  9604. bnxt_close_nic(bp, false, false);
  9605. bp->flags = flags;
  9606. if (update_tpa)
  9607. bnxt_set_ring_params(bp);
  9608. return bnxt_open_nic(bp, false, false);
  9609. }
  9610. if (update_tpa) {
  9611. bp->flags = flags;
  9612. rc = bnxt_set_tpa(bp,
  9613. (flags & BNXT_FLAG_TPA) ?
  9614. true : false);
  9615. if (rc)
  9616. bp->flags = old_flags;
  9617. }
  9618. }
  9619. return rc;
  9620. }
  9621. static bool bnxt_exthdr_check(struct bnxt *bp, struct sk_buff *skb, int nw_off,
  9622. u8 **nextp)
  9623. {
  9624. struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + nw_off);
  9625. int hdr_count = 0;
  9626. u8 *nexthdr;
  9627. int start;
  9628. /* Check that there are at most 2 IPv6 extension headers, no
  9629. * fragment header, and each is <= 64 bytes.
  9630. */
  9631. start = nw_off + sizeof(*ip6h);
  9632. nexthdr = &ip6h->nexthdr;
  9633. while (ipv6_ext_hdr(*nexthdr)) {
  9634. struct ipv6_opt_hdr *hp;
  9635. int hdrlen;
  9636. if (hdr_count >= 3 || *nexthdr == NEXTHDR_NONE ||
  9637. *nexthdr == NEXTHDR_FRAGMENT)
  9638. return false;
  9639. hp = __skb_header_pointer(NULL, start, sizeof(*hp), skb->data,
  9640. skb_headlen(skb), NULL);
  9641. if (!hp)
  9642. return false;
  9643. if (*nexthdr == NEXTHDR_AUTH)
  9644. hdrlen = ipv6_authlen(hp);
  9645. else
  9646. hdrlen = ipv6_optlen(hp);
  9647. if (hdrlen > 64)
  9648. return false;
  9649. nexthdr = &hp->nexthdr;
  9650. start += hdrlen;
  9651. hdr_count++;
  9652. }
  9653. if (nextp) {
  9654. /* Caller will check inner protocol */
  9655. if (skb->encapsulation) {
  9656. *nextp = nexthdr;
  9657. return true;
  9658. }
  9659. *nextp = NULL;
  9660. }
  9661. /* Only support TCP/UDP for non-tunneled ipv6 and inner ipv6 */
  9662. return *nexthdr == IPPROTO_TCP || *nexthdr == IPPROTO_UDP;
  9663. }
  9664. /* For UDP, we can only handle 1 Vxlan port and 1 Geneve port. */
  9665. static bool bnxt_udp_tunl_check(struct bnxt *bp, struct sk_buff *skb)
  9666. {
  9667. struct udphdr *uh = udp_hdr(skb);
  9668. __be16 udp_port = uh->dest;
  9669. if (udp_port != bp->vxlan_port && udp_port != bp->nge_port)
  9670. return false;
  9671. if (skb->inner_protocol_type == ENCAP_TYPE_ETHER) {
  9672. struct ethhdr *eh = inner_eth_hdr(skb);
  9673. switch (eh->h_proto) {
  9674. case htons(ETH_P_IP):
  9675. return true;
  9676. case htons(ETH_P_IPV6):
  9677. return bnxt_exthdr_check(bp, skb,
  9678. skb_inner_network_offset(skb),
  9679. NULL);
  9680. }
  9681. }
  9682. return false;
  9683. }
  9684. static bool bnxt_tunl_check(struct bnxt *bp, struct sk_buff *skb, u8 l4_proto)
  9685. {
  9686. switch (l4_proto) {
  9687. case IPPROTO_UDP:
  9688. return bnxt_udp_tunl_check(bp, skb);
  9689. case IPPROTO_IPIP:
  9690. return true;
  9691. case IPPROTO_GRE: {
  9692. switch (skb->inner_protocol) {
  9693. default:
  9694. return false;
  9695. case htons(ETH_P_IP):
  9696. return true;
  9697. case htons(ETH_P_IPV6):
  9698. fallthrough;
  9699. }
  9700. }
  9701. case IPPROTO_IPV6:
  9702. /* Check ext headers of inner ipv6 */
  9703. return bnxt_exthdr_check(bp, skb, skb_inner_network_offset(skb),
  9704. NULL);
  9705. }
  9706. return false;
  9707. }
  9708. static netdev_features_t bnxt_features_check(struct sk_buff *skb,
  9709. struct net_device *dev,
  9710. netdev_features_t features)
  9711. {
  9712. struct bnxt *bp = netdev_priv(dev);
  9713. u8 *l4_proto;
  9714. features = vlan_features_check(skb, features);
  9715. switch (vlan_get_protocol(skb)) {
  9716. case htons(ETH_P_IP):
  9717. if (!skb->encapsulation)
  9718. return features;
  9719. l4_proto = &ip_hdr(skb)->protocol;
  9720. if (bnxt_tunl_check(bp, skb, *l4_proto))
  9721. return features;
  9722. break;
  9723. case htons(ETH_P_IPV6):
  9724. if (!bnxt_exthdr_check(bp, skb, skb_network_offset(skb),
  9725. &l4_proto))
  9726. break;
  9727. if (!l4_proto || bnxt_tunl_check(bp, skb, *l4_proto))
  9728. return features;
  9729. break;
  9730. }
  9731. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  9732. }
  9733. int bnxt_dbg_hwrm_rd_reg(struct bnxt *bp, u32 reg_off, u16 num_words,
  9734. u32 *reg_buf)
  9735. {
  9736. struct hwrm_dbg_read_direct_output *resp;
  9737. struct hwrm_dbg_read_direct_input *req;
  9738. __le32 *dbg_reg_buf;
  9739. dma_addr_t mapping;
  9740. int rc, i;
  9741. rc = hwrm_req_init(bp, req, HWRM_DBG_READ_DIRECT);
  9742. if (rc)
  9743. return rc;
  9744. dbg_reg_buf = hwrm_req_dma_slice(bp, req, num_words * 4,
  9745. &mapping);
  9746. if (!dbg_reg_buf) {
  9747. rc = -ENOMEM;
  9748. goto dbg_rd_reg_exit;
  9749. }
  9750. req->host_dest_addr = cpu_to_le64(mapping);
  9751. resp = hwrm_req_hold(bp, req);
  9752. req->read_addr = cpu_to_le32(reg_off + CHIMP_REG_VIEW_ADDR);
  9753. req->read_len32 = cpu_to_le32(num_words);
  9754. rc = hwrm_req_send(bp, req);
  9755. if (rc || resp->error_code) {
  9756. rc = -EIO;
  9757. goto dbg_rd_reg_exit;
  9758. }
  9759. for (i = 0; i < num_words; i++)
  9760. reg_buf[i] = le32_to_cpu(dbg_reg_buf[i]);
  9761. dbg_rd_reg_exit:
  9762. hwrm_req_drop(bp, req);
  9763. return rc;
  9764. }
  9765. static int bnxt_dbg_hwrm_ring_info_get(struct bnxt *bp, u8 ring_type,
  9766. u32 ring_id, u32 *prod, u32 *cons)
  9767. {
  9768. struct hwrm_dbg_ring_info_get_output *resp;
  9769. struct hwrm_dbg_ring_info_get_input *req;
  9770. int rc;
  9771. rc = hwrm_req_init(bp, req, HWRM_DBG_RING_INFO_GET);
  9772. if (rc)
  9773. return rc;
  9774. req->ring_type = ring_type;
  9775. req->fw_ring_id = cpu_to_le32(ring_id);
  9776. resp = hwrm_req_hold(bp, req);
  9777. rc = hwrm_req_send(bp, req);
  9778. if (!rc) {
  9779. *prod = le32_to_cpu(resp->producer_index);
  9780. *cons = le32_to_cpu(resp->consumer_index);
  9781. }
  9782. hwrm_req_drop(bp, req);
  9783. return rc;
  9784. }
  9785. static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
  9786. {
  9787. struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
  9788. int i = bnapi->index;
  9789. if (!txr)
  9790. return;
  9791. netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
  9792. i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
  9793. txr->tx_cons);
  9794. }
  9795. static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
  9796. {
  9797. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  9798. int i = bnapi->index;
  9799. if (!rxr)
  9800. return;
  9801. netdev_info(bnapi->bp->dev, "[%d]: rx{fw_ring: %d prod: %x} rx_agg{fw_ring: %d agg_prod: %x sw_agg_prod: %x}\n",
  9802. i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
  9803. rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
  9804. rxr->rx_sw_agg_prod);
  9805. }
  9806. static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
  9807. {
  9808. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  9809. int i = bnapi->index;
  9810. netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
  9811. i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
  9812. }
  9813. static void bnxt_dbg_dump_states(struct bnxt *bp)
  9814. {
  9815. int i;
  9816. struct bnxt_napi *bnapi;
  9817. for (i = 0; i < bp->cp_nr_rings; i++) {
  9818. bnapi = bp->bnapi[i];
  9819. if (netif_msg_drv(bp)) {
  9820. bnxt_dump_tx_sw_state(bnapi);
  9821. bnxt_dump_rx_sw_state(bnapi);
  9822. bnxt_dump_cp_sw_state(bnapi);
  9823. }
  9824. }
  9825. }
  9826. static int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int ring_nr)
  9827. {
  9828. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[ring_nr];
  9829. struct hwrm_ring_reset_input *req;
  9830. struct bnxt_napi *bnapi = rxr->bnapi;
  9831. struct bnxt_cp_ring_info *cpr;
  9832. u16 cp_ring_id;
  9833. int rc;
  9834. rc = hwrm_req_init(bp, req, HWRM_RING_RESET);
  9835. if (rc)
  9836. return rc;
  9837. cpr = &bnapi->cp_ring;
  9838. cp_ring_id = cpr->cp_ring_struct.fw_ring_id;
  9839. req->cmpl_ring = cpu_to_le16(cp_ring_id);
  9840. req->ring_type = RING_RESET_REQ_RING_TYPE_RX_RING_GRP;
  9841. req->ring_id = cpu_to_le16(bp->grp_info[bnapi->index].fw_grp_id);
  9842. return hwrm_req_send_silent(bp, req);
  9843. }
  9844. static void bnxt_reset_task(struct bnxt *bp, bool silent)
  9845. {
  9846. if (!silent)
  9847. bnxt_dbg_dump_states(bp);
  9848. if (netif_running(bp->dev)) {
  9849. int rc;
  9850. if (silent) {
  9851. bnxt_close_nic(bp, false, false);
  9852. bnxt_open_nic(bp, false, false);
  9853. } else {
  9854. bnxt_ulp_stop(bp);
  9855. bnxt_close_nic(bp, true, false);
  9856. rc = bnxt_open_nic(bp, true, false);
  9857. bnxt_ulp_start(bp, rc);
  9858. }
  9859. }
  9860. }
  9861. static void bnxt_tx_timeout(struct net_device *dev, unsigned int txqueue)
  9862. {
  9863. struct bnxt *bp = netdev_priv(dev);
  9864. netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
  9865. set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
  9866. bnxt_queue_sp_work(bp);
  9867. }
  9868. static void bnxt_fw_health_check(struct bnxt *bp)
  9869. {
  9870. struct bnxt_fw_health *fw_health = bp->fw_health;
  9871. struct pci_dev *pdev = bp->pdev;
  9872. u32 val;
  9873. if (!fw_health->enabled || test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
  9874. return;
  9875. /* Make sure it is enabled before checking the tmr_counter. */
  9876. smp_rmb();
  9877. if (fw_health->tmr_counter) {
  9878. fw_health->tmr_counter--;
  9879. return;
  9880. }
  9881. val = bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
  9882. if (val == fw_health->last_fw_heartbeat && pci_device_is_present(pdev)) {
  9883. fw_health->arrests++;
  9884. goto fw_reset;
  9885. }
  9886. fw_health->last_fw_heartbeat = val;
  9887. val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
  9888. if (val != fw_health->last_fw_reset_cnt && pci_device_is_present(pdev)) {
  9889. fw_health->discoveries++;
  9890. goto fw_reset;
  9891. }
  9892. fw_health->tmr_counter = fw_health->tmr_multiplier;
  9893. return;
  9894. fw_reset:
  9895. set_bit(BNXT_FW_EXCEPTION_SP_EVENT, &bp->sp_event);
  9896. bnxt_queue_sp_work(bp);
  9897. }
  9898. static void bnxt_timer(struct timer_list *t)
  9899. {
  9900. struct bnxt *bp = from_timer(bp, t, timer);
  9901. struct net_device *dev = bp->dev;
  9902. if (!netif_running(dev) || !test_bit(BNXT_STATE_OPEN, &bp->state))
  9903. return;
  9904. if (atomic_read(&bp->intr_sem) != 0)
  9905. goto bnxt_restart_timer;
  9906. if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
  9907. bnxt_fw_health_check(bp);
  9908. if (BNXT_LINK_IS_UP(bp) && bp->stats_coal_ticks) {
  9909. set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
  9910. bnxt_queue_sp_work(bp);
  9911. }
  9912. if (bnxt_tc_flower_enabled(bp)) {
  9913. set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event);
  9914. bnxt_queue_sp_work(bp);
  9915. }
  9916. #ifdef CONFIG_RFS_ACCEL
  9917. if ((bp->flags & BNXT_FLAG_RFS) && bp->ntp_fltr_count) {
  9918. set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
  9919. bnxt_queue_sp_work(bp);
  9920. }
  9921. #endif /*CONFIG_RFS_ACCEL*/
  9922. if (bp->link_info.phy_retry) {
  9923. if (time_after(jiffies, bp->link_info.phy_retry_expires)) {
  9924. bp->link_info.phy_retry = false;
  9925. netdev_warn(bp->dev, "failed to update phy settings after maximum retries.\n");
  9926. } else {
  9927. set_bit(BNXT_UPDATE_PHY_SP_EVENT, &bp->sp_event);
  9928. bnxt_queue_sp_work(bp);
  9929. }
  9930. }
  9931. if (test_bit(BNXT_STATE_L2_FILTER_RETRY, &bp->state)) {
  9932. set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
  9933. bnxt_queue_sp_work(bp);
  9934. }
  9935. if ((bp->flags & BNXT_FLAG_CHIP_P5) && !bp->chip_rev &&
  9936. netif_carrier_ok(dev)) {
  9937. set_bit(BNXT_RING_COAL_NOW_SP_EVENT, &bp->sp_event);
  9938. bnxt_queue_sp_work(bp);
  9939. }
  9940. bnxt_restart_timer:
  9941. mod_timer(&bp->timer, jiffies + bp->current_interval);
  9942. }
  9943. static void bnxt_rtnl_lock_sp(struct bnxt *bp)
  9944. {
  9945. /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
  9946. * set. If the device is being closed, bnxt_close() may be holding
  9947. * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
  9948. * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
  9949. */
  9950. clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  9951. rtnl_lock();
  9952. }
  9953. static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
  9954. {
  9955. set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  9956. rtnl_unlock();
  9957. }
  9958. /* Only called from bnxt_sp_task() */
  9959. static void bnxt_reset(struct bnxt *bp, bool silent)
  9960. {
  9961. bnxt_rtnl_lock_sp(bp);
  9962. if (test_bit(BNXT_STATE_OPEN, &bp->state))
  9963. bnxt_reset_task(bp, silent);
  9964. bnxt_rtnl_unlock_sp(bp);
  9965. }
  9966. /* Only called from bnxt_sp_task() */
  9967. static void bnxt_rx_ring_reset(struct bnxt *bp)
  9968. {
  9969. int i;
  9970. bnxt_rtnl_lock_sp(bp);
  9971. if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
  9972. bnxt_rtnl_unlock_sp(bp);
  9973. return;
  9974. }
  9975. /* Disable and flush TPA before resetting the RX ring */
  9976. if (bp->flags & BNXT_FLAG_TPA)
  9977. bnxt_set_tpa(bp, false);
  9978. for (i = 0; i < bp->rx_nr_rings; i++) {
  9979. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  9980. struct bnxt_cp_ring_info *cpr;
  9981. int rc;
  9982. if (!rxr->bnapi->in_reset)
  9983. continue;
  9984. rc = bnxt_hwrm_rx_ring_reset(bp, i);
  9985. if (rc) {
  9986. if (rc == -EINVAL || rc == -EOPNOTSUPP)
  9987. netdev_info_once(bp->dev, "RX ring reset not supported by firmware, falling back to global reset\n");
  9988. else
  9989. netdev_warn(bp->dev, "RX ring reset failed, rc = %d, falling back to global reset\n",
  9990. rc);
  9991. bnxt_reset_task(bp, true);
  9992. break;
  9993. }
  9994. bnxt_free_one_rx_ring_skbs(bp, i);
  9995. rxr->rx_prod = 0;
  9996. rxr->rx_agg_prod = 0;
  9997. rxr->rx_sw_agg_prod = 0;
  9998. rxr->rx_next_cons = 0;
  9999. rxr->bnapi->in_reset = false;
  10000. bnxt_alloc_one_rx_ring(bp, i);
  10001. cpr = &rxr->bnapi->cp_ring;
  10002. cpr->sw_stats.rx.rx_resets++;
  10003. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  10004. bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod);
  10005. bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod);
  10006. }
  10007. if (bp->flags & BNXT_FLAG_TPA)
  10008. bnxt_set_tpa(bp, true);
  10009. bnxt_rtnl_unlock_sp(bp);
  10010. }
  10011. static void bnxt_fw_reset_close(struct bnxt *bp)
  10012. {
  10013. bnxt_ulp_stop(bp);
  10014. /* When firmware is in fatal state, quiesce device and disable
  10015. * bus master to prevent any potential bad DMAs before freeing
  10016. * kernel memory.
  10017. */
  10018. if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) {
  10019. u16 val = 0;
  10020. pci_read_config_word(bp->pdev, PCI_SUBSYSTEM_ID, &val);
  10021. if (val == 0xffff)
  10022. bp->fw_reset_min_dsecs = 0;
  10023. bnxt_tx_disable(bp);
  10024. bnxt_disable_napi(bp);
  10025. bnxt_disable_int_sync(bp);
  10026. bnxt_free_irq(bp);
  10027. bnxt_clear_int_mode(bp);
  10028. pci_disable_device(bp->pdev);
  10029. }
  10030. __bnxt_close_nic(bp, true, false);
  10031. bnxt_vf_reps_free(bp);
  10032. bnxt_clear_int_mode(bp);
  10033. bnxt_hwrm_func_drv_unrgtr(bp);
  10034. if (pci_is_enabled(bp->pdev))
  10035. pci_disable_device(bp->pdev);
  10036. bnxt_free_ctx_mem(bp);
  10037. kfree(bp->ctx);
  10038. bp->ctx = NULL;
  10039. }
  10040. static bool is_bnxt_fw_ok(struct bnxt *bp)
  10041. {
  10042. struct bnxt_fw_health *fw_health = bp->fw_health;
  10043. bool no_heartbeat = false, has_reset = false;
  10044. u32 val;
  10045. val = bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG);
  10046. if (val == fw_health->last_fw_heartbeat)
  10047. no_heartbeat = true;
  10048. val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
  10049. if (val != fw_health->last_fw_reset_cnt)
  10050. has_reset = true;
  10051. if (!no_heartbeat && has_reset)
  10052. return true;
  10053. return false;
  10054. }
  10055. /* rtnl_lock is acquired before calling this function */
  10056. static void bnxt_force_fw_reset(struct bnxt *bp)
  10057. {
  10058. struct bnxt_fw_health *fw_health = bp->fw_health;
  10059. struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
  10060. u32 wait_dsecs;
  10061. if (!test_bit(BNXT_STATE_OPEN, &bp->state) ||
  10062. test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
  10063. return;
  10064. if (ptp) {
  10065. spin_lock_bh(&ptp->ptp_lock);
  10066. set_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10067. spin_unlock_bh(&ptp->ptp_lock);
  10068. } else {
  10069. set_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10070. }
  10071. bnxt_fw_reset_close(bp);
  10072. wait_dsecs = fw_health->master_func_wait_dsecs;
  10073. if (fw_health->primary) {
  10074. if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU)
  10075. wait_dsecs = 0;
  10076. bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW;
  10077. } else {
  10078. bp->fw_reset_timestamp = jiffies + wait_dsecs * HZ / 10;
  10079. wait_dsecs = fw_health->normal_func_wait_dsecs;
  10080. bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
  10081. }
  10082. bp->fw_reset_min_dsecs = fw_health->post_reset_wait_dsecs;
  10083. bp->fw_reset_max_dsecs = fw_health->post_reset_max_wait_dsecs;
  10084. bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10);
  10085. }
  10086. void bnxt_fw_exception(struct bnxt *bp)
  10087. {
  10088. netdev_warn(bp->dev, "Detected firmware fatal condition, initiating reset\n");
  10089. set_bit(BNXT_STATE_FW_FATAL_COND, &bp->state);
  10090. bnxt_rtnl_lock_sp(bp);
  10091. bnxt_force_fw_reset(bp);
  10092. bnxt_rtnl_unlock_sp(bp);
  10093. }
  10094. /* Returns the number of registered VFs, or 1 if VF configuration is pending, or
  10095. * < 0 on error.
  10096. */
  10097. static int bnxt_get_registered_vfs(struct bnxt *bp)
  10098. {
  10099. #ifdef CONFIG_BNXT_SRIOV
  10100. int rc;
  10101. if (!BNXT_PF(bp))
  10102. return 0;
  10103. rc = bnxt_hwrm_func_qcfg(bp);
  10104. if (rc) {
  10105. netdev_err(bp->dev, "func_qcfg cmd failed, rc = %d\n", rc);
  10106. return rc;
  10107. }
  10108. if (bp->pf.registered_vfs)
  10109. return bp->pf.registered_vfs;
  10110. if (bp->sriov_cfg)
  10111. return 1;
  10112. #endif
  10113. return 0;
  10114. }
  10115. void bnxt_fw_reset(struct bnxt *bp)
  10116. {
  10117. bnxt_rtnl_lock_sp(bp);
  10118. if (test_bit(BNXT_STATE_OPEN, &bp->state) &&
  10119. !test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
  10120. struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
  10121. int n = 0, tmo;
  10122. if (ptp) {
  10123. spin_lock_bh(&ptp->ptp_lock);
  10124. set_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10125. spin_unlock_bh(&ptp->ptp_lock);
  10126. } else {
  10127. set_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10128. }
  10129. if (bp->pf.active_vfs &&
  10130. !test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state))
  10131. n = bnxt_get_registered_vfs(bp);
  10132. if (n < 0) {
  10133. netdev_err(bp->dev, "Firmware reset aborted, rc = %d\n",
  10134. n);
  10135. clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10136. dev_close(bp->dev);
  10137. goto fw_reset_exit;
  10138. } else if (n > 0) {
  10139. u16 vf_tmo_dsecs = n * 10;
  10140. if (bp->fw_reset_max_dsecs < vf_tmo_dsecs)
  10141. bp->fw_reset_max_dsecs = vf_tmo_dsecs;
  10142. bp->fw_reset_state =
  10143. BNXT_FW_RESET_STATE_POLL_VF;
  10144. bnxt_queue_fw_reset_work(bp, HZ / 10);
  10145. goto fw_reset_exit;
  10146. }
  10147. bnxt_fw_reset_close(bp);
  10148. if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) {
  10149. bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW_DOWN;
  10150. tmo = HZ / 10;
  10151. } else {
  10152. bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
  10153. tmo = bp->fw_reset_min_dsecs * HZ / 10;
  10154. }
  10155. bnxt_queue_fw_reset_work(bp, tmo);
  10156. }
  10157. fw_reset_exit:
  10158. bnxt_rtnl_unlock_sp(bp);
  10159. }
  10160. static void bnxt_chk_missed_irq(struct bnxt *bp)
  10161. {
  10162. int i;
  10163. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  10164. return;
  10165. for (i = 0; i < bp->cp_nr_rings; i++) {
  10166. struct bnxt_napi *bnapi = bp->bnapi[i];
  10167. struct bnxt_cp_ring_info *cpr;
  10168. u32 fw_ring_id;
  10169. int j;
  10170. if (!bnapi)
  10171. continue;
  10172. cpr = &bnapi->cp_ring;
  10173. for (j = 0; j < 2; j++) {
  10174. struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j];
  10175. u32 val[2];
  10176. if (!cpr2 || cpr2->has_more_work ||
  10177. !bnxt_has_work(bp, cpr2))
  10178. continue;
  10179. if (cpr2->cp_raw_cons != cpr2->last_cp_raw_cons) {
  10180. cpr2->last_cp_raw_cons = cpr2->cp_raw_cons;
  10181. continue;
  10182. }
  10183. fw_ring_id = cpr2->cp_ring_struct.fw_ring_id;
  10184. bnxt_dbg_hwrm_ring_info_get(bp,
  10185. DBG_RING_INFO_GET_REQ_RING_TYPE_L2_CMPL,
  10186. fw_ring_id, &val[0], &val[1]);
  10187. cpr->sw_stats.cmn.missed_irqs++;
  10188. }
  10189. }
  10190. }
  10191. static void bnxt_cfg_ntp_filters(struct bnxt *);
  10192. static void bnxt_init_ethtool_link_settings(struct bnxt *bp)
  10193. {
  10194. struct bnxt_link_info *link_info = &bp->link_info;
  10195. if (BNXT_AUTO_MODE(link_info->auto_mode)) {
  10196. link_info->autoneg = BNXT_AUTONEG_SPEED;
  10197. if (bp->hwrm_spec_code >= 0x10201) {
  10198. if (link_info->auto_pause_setting &
  10199. PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
  10200. link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
  10201. } else {
  10202. link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
  10203. }
  10204. link_info->advertising = link_info->auto_link_speeds;
  10205. link_info->advertising_pam4 = link_info->auto_pam4_link_speeds;
  10206. } else {
  10207. link_info->req_link_speed = link_info->force_link_speed;
  10208. link_info->req_signal_mode = BNXT_SIG_MODE_NRZ;
  10209. if (link_info->force_pam4_link_speed) {
  10210. link_info->req_link_speed =
  10211. link_info->force_pam4_link_speed;
  10212. link_info->req_signal_mode = BNXT_SIG_MODE_PAM4;
  10213. }
  10214. link_info->req_duplex = link_info->duplex_setting;
  10215. }
  10216. if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
  10217. link_info->req_flow_ctrl =
  10218. link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
  10219. else
  10220. link_info->req_flow_ctrl = link_info->force_pause_setting;
  10221. }
  10222. static void bnxt_fw_echo_reply(struct bnxt *bp)
  10223. {
  10224. struct bnxt_fw_health *fw_health = bp->fw_health;
  10225. struct hwrm_func_echo_response_input *req;
  10226. int rc;
  10227. rc = hwrm_req_init(bp, req, HWRM_FUNC_ECHO_RESPONSE);
  10228. if (rc)
  10229. return;
  10230. req->event_data1 = cpu_to_le32(fw_health->echo_req_data1);
  10231. req->event_data2 = cpu_to_le32(fw_health->echo_req_data2);
  10232. hwrm_req_send(bp, req);
  10233. }
  10234. static void bnxt_sp_task(struct work_struct *work)
  10235. {
  10236. struct bnxt *bp = container_of(work, struct bnxt, sp_task);
  10237. set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  10238. smp_mb__after_atomic();
  10239. if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
  10240. clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  10241. return;
  10242. }
  10243. if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
  10244. bnxt_cfg_rx_mode(bp);
  10245. if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
  10246. bnxt_cfg_ntp_filters(bp);
  10247. if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
  10248. bnxt_hwrm_exec_fwd_req(bp);
  10249. if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) {
  10250. bnxt_hwrm_port_qstats(bp, 0);
  10251. bnxt_hwrm_port_qstats_ext(bp, 0);
  10252. bnxt_accumulate_all_stats(bp);
  10253. }
  10254. if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
  10255. int rc;
  10256. mutex_lock(&bp->link_lock);
  10257. if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
  10258. &bp->sp_event))
  10259. bnxt_hwrm_phy_qcaps(bp);
  10260. rc = bnxt_update_link(bp, true);
  10261. if (rc)
  10262. netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
  10263. rc);
  10264. if (test_and_clear_bit(BNXT_LINK_CFG_CHANGE_SP_EVENT,
  10265. &bp->sp_event))
  10266. bnxt_init_ethtool_link_settings(bp);
  10267. mutex_unlock(&bp->link_lock);
  10268. }
  10269. if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT, &bp->sp_event)) {
  10270. int rc;
  10271. mutex_lock(&bp->link_lock);
  10272. rc = bnxt_update_phy_setting(bp);
  10273. mutex_unlock(&bp->link_lock);
  10274. if (rc) {
  10275. netdev_warn(bp->dev, "update phy settings retry failed\n");
  10276. } else {
  10277. bp->link_info.phy_retry = false;
  10278. netdev_info(bp->dev, "update phy settings retry succeeded\n");
  10279. }
  10280. }
  10281. if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
  10282. mutex_lock(&bp->link_lock);
  10283. bnxt_get_port_module_status(bp);
  10284. mutex_unlock(&bp->link_lock);
  10285. }
  10286. if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event))
  10287. bnxt_tc_flow_stats_work(bp);
  10288. if (test_and_clear_bit(BNXT_RING_COAL_NOW_SP_EVENT, &bp->sp_event))
  10289. bnxt_chk_missed_irq(bp);
  10290. if (test_and_clear_bit(BNXT_FW_ECHO_REQUEST_SP_EVENT, &bp->sp_event))
  10291. bnxt_fw_echo_reply(bp);
  10292. /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
  10293. * must be the last functions to be called before exiting.
  10294. */
  10295. if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
  10296. bnxt_reset(bp, false);
  10297. if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
  10298. bnxt_reset(bp, true);
  10299. if (test_and_clear_bit(BNXT_RST_RING_SP_EVENT, &bp->sp_event))
  10300. bnxt_rx_ring_reset(bp);
  10301. if (test_and_clear_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event)) {
  10302. if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state) ||
  10303. test_bit(BNXT_STATE_FW_NON_FATAL_COND, &bp->state))
  10304. bnxt_devlink_health_fw_report(bp);
  10305. else
  10306. bnxt_fw_reset(bp);
  10307. }
  10308. if (test_and_clear_bit(BNXT_FW_EXCEPTION_SP_EVENT, &bp->sp_event)) {
  10309. if (!is_bnxt_fw_ok(bp))
  10310. bnxt_devlink_health_fw_report(bp);
  10311. }
  10312. smp_mb__before_atomic();
  10313. clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  10314. }
  10315. /* Under rtnl_lock */
  10316. int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
  10317. int tx_xdp)
  10318. {
  10319. int max_rx, max_tx, tx_sets = 1;
  10320. int tx_rings_needed, stats;
  10321. int rx_rings = rx;
  10322. int cp, vnics, rc;
  10323. if (tcs)
  10324. tx_sets = tcs;
  10325. rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
  10326. if (rc)
  10327. return rc;
  10328. if (max_rx < rx)
  10329. return -ENOMEM;
  10330. tx_rings_needed = tx * tx_sets + tx_xdp;
  10331. if (max_tx < tx_rings_needed)
  10332. return -ENOMEM;
  10333. vnics = 1;
  10334. if ((bp->flags & (BNXT_FLAG_RFS | BNXT_FLAG_CHIP_P5)) == BNXT_FLAG_RFS)
  10335. vnics += rx_rings;
  10336. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  10337. rx_rings <<= 1;
  10338. cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
  10339. stats = cp;
  10340. if (BNXT_NEW_RM(bp)) {
  10341. cp += bnxt_get_ulp_msix_num(bp);
  10342. stats += bnxt_get_ulp_stat_ctxs(bp);
  10343. }
  10344. return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp,
  10345. stats, vnics);
  10346. }
  10347. static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
  10348. {
  10349. if (bp->bar2) {
  10350. pci_iounmap(pdev, bp->bar2);
  10351. bp->bar2 = NULL;
  10352. }
  10353. if (bp->bar1) {
  10354. pci_iounmap(pdev, bp->bar1);
  10355. bp->bar1 = NULL;
  10356. }
  10357. if (bp->bar0) {
  10358. pci_iounmap(pdev, bp->bar0);
  10359. bp->bar0 = NULL;
  10360. }
  10361. }
  10362. static void bnxt_cleanup_pci(struct bnxt *bp)
  10363. {
  10364. bnxt_unmap_bars(bp, bp->pdev);
  10365. pci_release_regions(bp->pdev);
  10366. if (pci_is_enabled(bp->pdev))
  10367. pci_disable_device(bp->pdev);
  10368. }
  10369. static void bnxt_init_dflt_coal(struct bnxt *bp)
  10370. {
  10371. struct bnxt_coal_cap *coal_cap = &bp->coal_cap;
  10372. struct bnxt_coal *coal;
  10373. u16 flags = 0;
  10374. if (coal_cap->cmpl_params &
  10375. RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET)
  10376. flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
  10377. /* Tick values in micro seconds.
  10378. * 1 coal_buf x bufs_per_record = 1 completion record.
  10379. */
  10380. coal = &bp->rx_coal;
  10381. coal->coal_ticks = 10;
  10382. coal->coal_bufs = 30;
  10383. coal->coal_ticks_irq = 1;
  10384. coal->coal_bufs_irq = 2;
  10385. coal->idle_thresh = 50;
  10386. coal->bufs_per_record = 2;
  10387. coal->budget = 64; /* NAPI budget */
  10388. coal->flags = flags;
  10389. coal = &bp->tx_coal;
  10390. coal->coal_ticks = 28;
  10391. coal->coal_bufs = 30;
  10392. coal->coal_ticks_irq = 2;
  10393. coal->coal_bufs_irq = 2;
  10394. coal->bufs_per_record = 1;
  10395. coal->flags = flags;
  10396. bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
  10397. }
  10398. static int bnxt_fw_init_one_p1(struct bnxt *bp)
  10399. {
  10400. int rc;
  10401. bp->fw_cap = 0;
  10402. rc = bnxt_hwrm_ver_get(bp);
  10403. bnxt_try_map_fw_health_reg(bp);
  10404. if (rc) {
  10405. rc = bnxt_try_recover_fw(bp);
  10406. if (rc)
  10407. return rc;
  10408. rc = bnxt_hwrm_ver_get(bp);
  10409. if (rc)
  10410. return rc;
  10411. }
  10412. bnxt_nvm_cfg_ver_get(bp);
  10413. rc = bnxt_hwrm_func_reset(bp);
  10414. if (rc)
  10415. return -ENODEV;
  10416. bnxt_hwrm_fw_set_time(bp);
  10417. return 0;
  10418. }
  10419. static int bnxt_fw_init_one_p2(struct bnxt *bp)
  10420. {
  10421. int rc;
  10422. /* Get the MAX capabilities for this function */
  10423. rc = bnxt_hwrm_func_qcaps(bp);
  10424. if (rc) {
  10425. netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
  10426. rc);
  10427. return -ENODEV;
  10428. }
  10429. rc = bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(bp);
  10430. if (rc)
  10431. netdev_warn(bp->dev, "hwrm query adv flow mgnt failure rc: %d\n",
  10432. rc);
  10433. if (bnxt_alloc_fw_health(bp)) {
  10434. netdev_warn(bp->dev, "no memory for firmware error recovery\n");
  10435. } else {
  10436. rc = bnxt_hwrm_error_recovery_qcfg(bp);
  10437. if (rc)
  10438. netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n",
  10439. rc);
  10440. }
  10441. rc = bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, false);
  10442. if (rc)
  10443. return -ENODEV;
  10444. bnxt_hwrm_func_qcfg(bp);
  10445. bnxt_hwrm_vnic_qcaps(bp);
  10446. bnxt_hwrm_port_led_qcaps(bp);
  10447. bnxt_ethtool_init(bp);
  10448. bnxt_dcb_init(bp);
  10449. return 0;
  10450. }
  10451. static void bnxt_set_dflt_rss_hash_type(struct bnxt *bp)
  10452. {
  10453. bp->flags &= ~BNXT_FLAG_UDP_RSS_CAP;
  10454. bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
  10455. VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
  10456. VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
  10457. VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
  10458. if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) {
  10459. bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
  10460. bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
  10461. VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
  10462. }
  10463. }
  10464. static void bnxt_set_dflt_rfs(struct bnxt *bp)
  10465. {
  10466. struct net_device *dev = bp->dev;
  10467. dev->hw_features &= ~NETIF_F_NTUPLE;
  10468. dev->features &= ~NETIF_F_NTUPLE;
  10469. bp->flags &= ~BNXT_FLAG_RFS;
  10470. if (bnxt_rfs_supported(bp)) {
  10471. dev->hw_features |= NETIF_F_NTUPLE;
  10472. if (bnxt_rfs_capable(bp)) {
  10473. bp->flags |= BNXT_FLAG_RFS;
  10474. dev->features |= NETIF_F_NTUPLE;
  10475. }
  10476. }
  10477. }
  10478. static void bnxt_fw_init_one_p3(struct bnxt *bp)
  10479. {
  10480. struct pci_dev *pdev = bp->pdev;
  10481. bnxt_set_dflt_rss_hash_type(bp);
  10482. bnxt_set_dflt_rfs(bp);
  10483. bnxt_get_wol_settings(bp);
  10484. if (bp->flags & BNXT_FLAG_WOL_CAP)
  10485. device_set_wakeup_enable(&pdev->dev, bp->wol);
  10486. else
  10487. device_set_wakeup_capable(&pdev->dev, false);
  10488. bnxt_hwrm_set_cache_line_size(bp, cache_line_size());
  10489. bnxt_hwrm_coal_params_qcaps(bp);
  10490. }
  10491. static int bnxt_probe_phy(struct bnxt *bp, bool fw_dflt);
  10492. int bnxt_fw_init_one(struct bnxt *bp)
  10493. {
  10494. int rc;
  10495. rc = bnxt_fw_init_one_p1(bp);
  10496. if (rc) {
  10497. netdev_err(bp->dev, "Firmware init phase 1 failed\n");
  10498. return rc;
  10499. }
  10500. rc = bnxt_fw_init_one_p2(bp);
  10501. if (rc) {
  10502. netdev_err(bp->dev, "Firmware init phase 2 failed\n");
  10503. return rc;
  10504. }
  10505. rc = bnxt_probe_phy(bp, false);
  10506. if (rc)
  10507. return rc;
  10508. rc = bnxt_approve_mac(bp, bp->dev->dev_addr, false);
  10509. if (rc)
  10510. return rc;
  10511. bnxt_fw_init_one_p3(bp);
  10512. return 0;
  10513. }
  10514. static void bnxt_fw_reset_writel(struct bnxt *bp, int reg_idx)
  10515. {
  10516. struct bnxt_fw_health *fw_health = bp->fw_health;
  10517. u32 reg = fw_health->fw_reset_seq_regs[reg_idx];
  10518. u32 val = fw_health->fw_reset_seq_vals[reg_idx];
  10519. u32 reg_type, reg_off, delay_msecs;
  10520. delay_msecs = fw_health->fw_reset_seq_delay_msec[reg_idx];
  10521. reg_type = BNXT_FW_HEALTH_REG_TYPE(reg);
  10522. reg_off = BNXT_FW_HEALTH_REG_OFF(reg);
  10523. switch (reg_type) {
  10524. case BNXT_FW_HEALTH_REG_TYPE_CFG:
  10525. pci_write_config_dword(bp->pdev, reg_off, val);
  10526. break;
  10527. case BNXT_FW_HEALTH_REG_TYPE_GRC:
  10528. writel(reg_off & BNXT_GRC_BASE_MASK,
  10529. bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
  10530. reg_off = (reg_off & BNXT_GRC_OFFSET_MASK) + 0x2000;
  10531. fallthrough;
  10532. case BNXT_FW_HEALTH_REG_TYPE_BAR0:
  10533. writel(val, bp->bar0 + reg_off);
  10534. break;
  10535. case BNXT_FW_HEALTH_REG_TYPE_BAR1:
  10536. writel(val, bp->bar1 + reg_off);
  10537. break;
  10538. }
  10539. if (delay_msecs) {
  10540. pci_read_config_dword(bp->pdev, 0, &val);
  10541. msleep(delay_msecs);
  10542. }
  10543. }
  10544. bool bnxt_hwrm_reset_permitted(struct bnxt *bp)
  10545. {
  10546. struct hwrm_func_qcfg_output *resp;
  10547. struct hwrm_func_qcfg_input *req;
  10548. bool result = true; /* firmware will enforce if unknown */
  10549. if (~bp->fw_cap & BNXT_FW_CAP_HOT_RESET_IF)
  10550. return result;
  10551. if (hwrm_req_init(bp, req, HWRM_FUNC_QCFG))
  10552. return result;
  10553. req->fid = cpu_to_le16(0xffff);
  10554. resp = hwrm_req_hold(bp, req);
  10555. if (!hwrm_req_send(bp, req))
  10556. result = !!(le16_to_cpu(resp->flags) &
  10557. FUNC_QCFG_RESP_FLAGS_HOT_RESET_ALLOWED);
  10558. hwrm_req_drop(bp, req);
  10559. return result;
  10560. }
  10561. static void bnxt_reset_all(struct bnxt *bp)
  10562. {
  10563. struct bnxt_fw_health *fw_health = bp->fw_health;
  10564. int i, rc;
  10565. if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) {
  10566. bnxt_fw_reset_via_optee(bp);
  10567. bp->fw_reset_timestamp = jiffies;
  10568. return;
  10569. }
  10570. if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_HOST) {
  10571. for (i = 0; i < fw_health->fw_reset_seq_cnt; i++)
  10572. bnxt_fw_reset_writel(bp, i);
  10573. } else if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) {
  10574. struct hwrm_fw_reset_input *req;
  10575. rc = hwrm_req_init(bp, req, HWRM_FW_RESET);
  10576. if (!rc) {
  10577. req->target_id = cpu_to_le16(HWRM_TARGET_ID_KONG);
  10578. req->embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP;
  10579. req->selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP;
  10580. req->flags = FW_RESET_REQ_FLAGS_RESET_GRACEFUL;
  10581. rc = hwrm_req_send(bp, req);
  10582. }
  10583. if (rc != -ENODEV)
  10584. netdev_warn(bp->dev, "Unable to reset FW rc=%d\n", rc);
  10585. }
  10586. bp->fw_reset_timestamp = jiffies;
  10587. }
  10588. static bool bnxt_fw_reset_timeout(struct bnxt *bp)
  10589. {
  10590. return time_after(jiffies, bp->fw_reset_timestamp +
  10591. (bp->fw_reset_max_dsecs * HZ / 10));
  10592. }
  10593. static void bnxt_fw_reset_abort(struct bnxt *bp, int rc)
  10594. {
  10595. clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10596. if (bp->fw_reset_state != BNXT_FW_RESET_STATE_POLL_VF) {
  10597. bnxt_ulp_start(bp, rc);
  10598. bnxt_dl_health_fw_status_update(bp, false);
  10599. }
  10600. bp->fw_reset_state = 0;
  10601. dev_close(bp->dev);
  10602. }
  10603. static void bnxt_fw_reset_task(struct work_struct *work)
  10604. {
  10605. struct bnxt *bp = container_of(work, struct bnxt, fw_reset_task.work);
  10606. int rc = 0;
  10607. if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
  10608. netdev_err(bp->dev, "bnxt_fw_reset_task() called when not in fw reset mode!\n");
  10609. return;
  10610. }
  10611. switch (bp->fw_reset_state) {
  10612. case BNXT_FW_RESET_STATE_POLL_VF: {
  10613. int n = bnxt_get_registered_vfs(bp);
  10614. int tmo;
  10615. if (n < 0) {
  10616. netdev_err(bp->dev, "Firmware reset aborted, subsequent func_qcfg cmd failed, rc = %d, %d msecs since reset timestamp\n",
  10617. n, jiffies_to_msecs(jiffies -
  10618. bp->fw_reset_timestamp));
  10619. goto fw_reset_abort;
  10620. } else if (n > 0) {
  10621. if (bnxt_fw_reset_timeout(bp)) {
  10622. clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10623. bp->fw_reset_state = 0;
  10624. netdev_err(bp->dev, "Firmware reset aborted, bnxt_get_registered_vfs() returns %d\n",
  10625. n);
  10626. return;
  10627. }
  10628. bnxt_queue_fw_reset_work(bp, HZ / 10);
  10629. return;
  10630. }
  10631. bp->fw_reset_timestamp = jiffies;
  10632. rtnl_lock();
  10633. if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) {
  10634. bnxt_fw_reset_abort(bp, rc);
  10635. rtnl_unlock();
  10636. return;
  10637. }
  10638. bnxt_fw_reset_close(bp);
  10639. if (bp->fw_cap & BNXT_FW_CAP_ERR_RECOVER_RELOAD) {
  10640. bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW_DOWN;
  10641. tmo = HZ / 10;
  10642. } else {
  10643. bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
  10644. tmo = bp->fw_reset_min_dsecs * HZ / 10;
  10645. }
  10646. rtnl_unlock();
  10647. bnxt_queue_fw_reset_work(bp, tmo);
  10648. return;
  10649. }
  10650. case BNXT_FW_RESET_STATE_POLL_FW_DOWN: {
  10651. u32 val;
  10652. val = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
  10653. if (!(val & BNXT_FW_STATUS_SHUTDOWN) &&
  10654. !bnxt_fw_reset_timeout(bp)) {
  10655. bnxt_queue_fw_reset_work(bp, HZ / 5);
  10656. return;
  10657. }
  10658. if (!bp->fw_health->primary) {
  10659. u32 wait_dsecs = bp->fw_health->normal_func_wait_dsecs;
  10660. bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
  10661. bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10);
  10662. return;
  10663. }
  10664. bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW;
  10665. }
  10666. fallthrough;
  10667. case BNXT_FW_RESET_STATE_RESET_FW:
  10668. bnxt_reset_all(bp);
  10669. bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV;
  10670. bnxt_queue_fw_reset_work(bp, bp->fw_reset_min_dsecs * HZ / 10);
  10671. return;
  10672. case BNXT_FW_RESET_STATE_ENABLE_DEV:
  10673. bnxt_inv_fw_health_reg(bp);
  10674. if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state) &&
  10675. !bp->fw_reset_min_dsecs) {
  10676. u16 val;
  10677. pci_read_config_word(bp->pdev, PCI_SUBSYSTEM_ID, &val);
  10678. if (val == 0xffff) {
  10679. if (bnxt_fw_reset_timeout(bp)) {
  10680. netdev_err(bp->dev, "Firmware reset aborted, PCI config space invalid\n");
  10681. rc = -ETIMEDOUT;
  10682. goto fw_reset_abort;
  10683. }
  10684. bnxt_queue_fw_reset_work(bp, HZ / 1000);
  10685. return;
  10686. }
  10687. }
  10688. clear_bit(BNXT_STATE_FW_FATAL_COND, &bp->state);
  10689. clear_bit(BNXT_STATE_FW_NON_FATAL_COND, &bp->state);
  10690. if (test_and_clear_bit(BNXT_STATE_FW_ACTIVATE_RESET, &bp->state) &&
  10691. !test_bit(BNXT_STATE_FW_ACTIVATE, &bp->state))
  10692. bnxt_dl_remote_reload(bp);
  10693. if (pci_enable_device(bp->pdev)) {
  10694. netdev_err(bp->dev, "Cannot re-enable PCI device\n");
  10695. rc = -ENODEV;
  10696. goto fw_reset_abort;
  10697. }
  10698. pci_set_master(bp->pdev);
  10699. bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW;
  10700. fallthrough;
  10701. case BNXT_FW_RESET_STATE_POLL_FW:
  10702. bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT;
  10703. rc = bnxt_hwrm_poll(bp);
  10704. if (rc) {
  10705. if (bnxt_fw_reset_timeout(bp)) {
  10706. netdev_err(bp->dev, "Firmware reset aborted\n");
  10707. goto fw_reset_abort_status;
  10708. }
  10709. bnxt_queue_fw_reset_work(bp, HZ / 5);
  10710. return;
  10711. }
  10712. bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
  10713. bp->fw_reset_state = BNXT_FW_RESET_STATE_OPENING;
  10714. fallthrough;
  10715. case BNXT_FW_RESET_STATE_OPENING:
  10716. while (!rtnl_trylock()) {
  10717. bnxt_queue_fw_reset_work(bp, HZ / 10);
  10718. return;
  10719. }
  10720. rc = bnxt_open(bp->dev);
  10721. if (rc) {
  10722. netdev_err(bp->dev, "bnxt_open() failed during FW reset\n");
  10723. bnxt_fw_reset_abort(bp, rc);
  10724. rtnl_unlock();
  10725. return;
  10726. }
  10727. if ((bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY) &&
  10728. bp->fw_health->enabled) {
  10729. bp->fw_health->last_fw_reset_cnt =
  10730. bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG);
  10731. }
  10732. bp->fw_reset_state = 0;
  10733. /* Make sure fw_reset_state is 0 before clearing the flag */
  10734. smp_mb__before_atomic();
  10735. clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  10736. bnxt_ulp_start(bp, 0);
  10737. bnxt_reenable_sriov(bp);
  10738. bnxt_vf_reps_alloc(bp);
  10739. bnxt_vf_reps_open(bp);
  10740. bnxt_ptp_reapply_pps(bp);
  10741. clear_bit(BNXT_STATE_FW_ACTIVATE, &bp->state);
  10742. if (test_and_clear_bit(BNXT_STATE_RECOVER, &bp->state)) {
  10743. bnxt_dl_health_fw_recovery_done(bp);
  10744. bnxt_dl_health_fw_status_update(bp, true);
  10745. }
  10746. rtnl_unlock();
  10747. break;
  10748. }
  10749. return;
  10750. fw_reset_abort_status:
  10751. if (bp->fw_health->status_reliable ||
  10752. (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) {
  10753. u32 sts = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG);
  10754. netdev_err(bp->dev, "fw_health_status 0x%x\n", sts);
  10755. }
  10756. fw_reset_abort:
  10757. rtnl_lock();
  10758. bnxt_fw_reset_abort(bp, rc);
  10759. rtnl_unlock();
  10760. }
  10761. static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
  10762. {
  10763. int rc;
  10764. struct bnxt *bp = netdev_priv(dev);
  10765. SET_NETDEV_DEV(dev, &pdev->dev);
  10766. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  10767. rc = pci_enable_device(pdev);
  10768. if (rc) {
  10769. dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
  10770. goto init_err;
  10771. }
  10772. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10773. dev_err(&pdev->dev,
  10774. "Cannot find PCI device base address, aborting\n");
  10775. rc = -ENODEV;
  10776. goto init_err_disable;
  10777. }
  10778. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10779. if (rc) {
  10780. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
  10781. goto init_err_disable;
  10782. }
  10783. if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
  10784. dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
  10785. dev_err(&pdev->dev, "System does not support DMA, aborting\n");
  10786. rc = -EIO;
  10787. goto init_err_release;
  10788. }
  10789. pci_set_master(pdev);
  10790. bp->dev = dev;
  10791. bp->pdev = pdev;
  10792. /* Doorbell BAR bp->bar1 is mapped after bnxt_fw_init_one_p2()
  10793. * determines the BAR size.
  10794. */
  10795. bp->bar0 = pci_ioremap_bar(pdev, 0);
  10796. if (!bp->bar0) {
  10797. dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
  10798. rc = -ENOMEM;
  10799. goto init_err_release;
  10800. }
  10801. bp->bar2 = pci_ioremap_bar(pdev, 4);
  10802. if (!bp->bar2) {
  10803. dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
  10804. rc = -ENOMEM;
  10805. goto init_err_release;
  10806. }
  10807. pci_enable_pcie_error_reporting(pdev);
  10808. INIT_WORK(&bp->sp_task, bnxt_sp_task);
  10809. INIT_DELAYED_WORK(&bp->fw_reset_task, bnxt_fw_reset_task);
  10810. spin_lock_init(&bp->ntp_fltr_lock);
  10811. #if BITS_PER_LONG == 32
  10812. spin_lock_init(&bp->db_lock);
  10813. #endif
  10814. bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
  10815. bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
  10816. timer_setup(&bp->timer, bnxt_timer, 0);
  10817. bp->current_interval = BNXT_TIMER_INTERVAL;
  10818. bp->vxlan_fw_dst_port_id = INVALID_HW_RING_ID;
  10819. bp->nge_fw_dst_port_id = INVALID_HW_RING_ID;
  10820. clear_bit(BNXT_STATE_OPEN, &bp->state);
  10821. return 0;
  10822. init_err_release:
  10823. bnxt_unmap_bars(bp, pdev);
  10824. pci_release_regions(pdev);
  10825. init_err_disable:
  10826. pci_disable_device(pdev);
  10827. init_err:
  10828. return rc;
  10829. }
  10830. /* rtnl_lock held */
  10831. static int bnxt_change_mac_addr(struct net_device *dev, void *p)
  10832. {
  10833. struct sockaddr *addr = p;
  10834. struct bnxt *bp = netdev_priv(dev);
  10835. int rc = 0;
  10836. if (!is_valid_ether_addr(addr->sa_data))
  10837. return -EADDRNOTAVAIL;
  10838. if (ether_addr_equal(addr->sa_data, dev->dev_addr))
  10839. return 0;
  10840. rc = bnxt_approve_mac(bp, addr->sa_data, true);
  10841. if (rc)
  10842. return rc;
  10843. eth_hw_addr_set(dev, addr->sa_data);
  10844. if (netif_running(dev)) {
  10845. bnxt_close_nic(bp, false, false);
  10846. rc = bnxt_open_nic(bp, false, false);
  10847. }
  10848. return rc;
  10849. }
  10850. /* rtnl_lock held */
  10851. static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
  10852. {
  10853. struct bnxt *bp = netdev_priv(dev);
  10854. if (netif_running(dev))
  10855. bnxt_close_nic(bp, true, false);
  10856. dev->mtu = new_mtu;
  10857. bnxt_set_ring_params(bp);
  10858. if (netif_running(dev))
  10859. return bnxt_open_nic(bp, true, false);
  10860. return 0;
  10861. }
  10862. int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
  10863. {
  10864. struct bnxt *bp = netdev_priv(dev);
  10865. bool sh = false;
  10866. int rc;
  10867. if (tc > bp->max_tc) {
  10868. netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
  10869. tc, bp->max_tc);
  10870. return -EINVAL;
  10871. }
  10872. if (netdev_get_num_tc(dev) == tc)
  10873. return 0;
  10874. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  10875. sh = true;
  10876. rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
  10877. sh, tc, bp->tx_nr_rings_xdp);
  10878. if (rc)
  10879. return rc;
  10880. /* Needs to close the device and do hw resource re-allocations */
  10881. if (netif_running(bp->dev))
  10882. bnxt_close_nic(bp, true, false);
  10883. if (tc) {
  10884. bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
  10885. netdev_set_num_tc(dev, tc);
  10886. } else {
  10887. bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
  10888. netdev_reset_tc(dev);
  10889. }
  10890. bp->tx_nr_rings += bp->tx_nr_rings_xdp;
  10891. bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
  10892. bp->tx_nr_rings + bp->rx_nr_rings;
  10893. if (netif_running(bp->dev))
  10894. return bnxt_open_nic(bp, true, false);
  10895. return 0;
  10896. }
  10897. static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  10898. void *cb_priv)
  10899. {
  10900. struct bnxt *bp = cb_priv;
  10901. if (!bnxt_tc_flower_enabled(bp) ||
  10902. !tc_cls_can_offload_and_chain0(bp->dev, type_data))
  10903. return -EOPNOTSUPP;
  10904. switch (type) {
  10905. case TC_SETUP_CLSFLOWER:
  10906. return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data);
  10907. default:
  10908. return -EOPNOTSUPP;
  10909. }
  10910. }
  10911. LIST_HEAD(bnxt_block_cb_list);
  10912. static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
  10913. void *type_data)
  10914. {
  10915. struct bnxt *bp = netdev_priv(dev);
  10916. switch (type) {
  10917. case TC_SETUP_BLOCK:
  10918. return flow_block_cb_setup_simple(type_data,
  10919. &bnxt_block_cb_list,
  10920. bnxt_setup_tc_block_cb,
  10921. bp, bp, true);
  10922. case TC_SETUP_QDISC_MQPRIO: {
  10923. struct tc_mqprio_qopt *mqprio = type_data;
  10924. mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  10925. return bnxt_setup_mq_tc(dev, mqprio->num_tc);
  10926. }
  10927. default:
  10928. return -EOPNOTSUPP;
  10929. }
  10930. }
  10931. #ifdef CONFIG_RFS_ACCEL
  10932. static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
  10933. struct bnxt_ntuple_filter *f2)
  10934. {
  10935. struct flow_keys *keys1 = &f1->fkeys;
  10936. struct flow_keys *keys2 = &f2->fkeys;
  10937. if (keys1->basic.n_proto != keys2->basic.n_proto ||
  10938. keys1->basic.ip_proto != keys2->basic.ip_proto)
  10939. return false;
  10940. if (keys1->basic.n_proto == htons(ETH_P_IP)) {
  10941. if (keys1->addrs.v4addrs.src != keys2->addrs.v4addrs.src ||
  10942. keys1->addrs.v4addrs.dst != keys2->addrs.v4addrs.dst)
  10943. return false;
  10944. } else {
  10945. if (memcmp(&keys1->addrs.v6addrs.src, &keys2->addrs.v6addrs.src,
  10946. sizeof(keys1->addrs.v6addrs.src)) ||
  10947. memcmp(&keys1->addrs.v6addrs.dst, &keys2->addrs.v6addrs.dst,
  10948. sizeof(keys1->addrs.v6addrs.dst)))
  10949. return false;
  10950. }
  10951. if (keys1->ports.ports == keys2->ports.ports &&
  10952. keys1->control.flags == keys2->control.flags &&
  10953. ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
  10954. ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
  10955. return true;
  10956. return false;
  10957. }
  10958. static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
  10959. u16 rxq_index, u32 flow_id)
  10960. {
  10961. struct bnxt *bp = netdev_priv(dev);
  10962. struct bnxt_ntuple_filter *fltr, *new_fltr;
  10963. struct flow_keys *fkeys;
  10964. struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
  10965. int rc = 0, idx, bit_id, l2_idx = 0;
  10966. struct hlist_head *head;
  10967. u32 flags;
  10968. if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
  10969. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  10970. int off = 0, j;
  10971. netif_addr_lock_bh(dev);
  10972. for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
  10973. if (ether_addr_equal(eth->h_dest,
  10974. vnic->uc_list + off)) {
  10975. l2_idx = j + 1;
  10976. break;
  10977. }
  10978. }
  10979. netif_addr_unlock_bh(dev);
  10980. if (!l2_idx)
  10981. return -EINVAL;
  10982. }
  10983. new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
  10984. if (!new_fltr)
  10985. return -ENOMEM;
  10986. fkeys = &new_fltr->fkeys;
  10987. if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
  10988. rc = -EPROTONOSUPPORT;
  10989. goto err_free;
  10990. }
  10991. if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
  10992. fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
  10993. ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
  10994. (fkeys->basic.ip_proto != IPPROTO_UDP))) {
  10995. rc = -EPROTONOSUPPORT;
  10996. goto err_free;
  10997. }
  10998. if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
  10999. bp->hwrm_spec_code < 0x10601) {
  11000. rc = -EPROTONOSUPPORT;
  11001. goto err_free;
  11002. }
  11003. flags = fkeys->control.flags;
  11004. if (((flags & FLOW_DIS_ENCAPSULATION) &&
  11005. bp->hwrm_spec_code < 0x10601) || (flags & FLOW_DIS_IS_FRAGMENT)) {
  11006. rc = -EPROTONOSUPPORT;
  11007. goto err_free;
  11008. }
  11009. memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
  11010. memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
  11011. idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
  11012. head = &bp->ntp_fltr_hash_tbl[idx];
  11013. rcu_read_lock();
  11014. hlist_for_each_entry_rcu(fltr, head, hash) {
  11015. if (bnxt_fltr_match(fltr, new_fltr)) {
  11016. rc = fltr->sw_id;
  11017. rcu_read_unlock();
  11018. goto err_free;
  11019. }
  11020. }
  11021. rcu_read_unlock();
  11022. spin_lock_bh(&bp->ntp_fltr_lock);
  11023. bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
  11024. BNXT_NTP_FLTR_MAX_FLTR, 0);
  11025. if (bit_id < 0) {
  11026. spin_unlock_bh(&bp->ntp_fltr_lock);
  11027. rc = -ENOMEM;
  11028. goto err_free;
  11029. }
  11030. new_fltr->sw_id = (u16)bit_id;
  11031. new_fltr->flow_id = flow_id;
  11032. new_fltr->l2_fltr_idx = l2_idx;
  11033. new_fltr->rxq = rxq_index;
  11034. hlist_add_head_rcu(&new_fltr->hash, head);
  11035. bp->ntp_fltr_count++;
  11036. spin_unlock_bh(&bp->ntp_fltr_lock);
  11037. set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
  11038. bnxt_queue_sp_work(bp);
  11039. return new_fltr->sw_id;
  11040. err_free:
  11041. kfree(new_fltr);
  11042. return rc;
  11043. }
  11044. static void bnxt_cfg_ntp_filters(struct bnxt *bp)
  11045. {
  11046. int i;
  11047. for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
  11048. struct hlist_head *head;
  11049. struct hlist_node *tmp;
  11050. struct bnxt_ntuple_filter *fltr;
  11051. int rc;
  11052. head = &bp->ntp_fltr_hash_tbl[i];
  11053. hlist_for_each_entry_safe(fltr, tmp, head, hash) {
  11054. bool del = false;
  11055. if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
  11056. if (rps_may_expire_flow(bp->dev, fltr->rxq,
  11057. fltr->flow_id,
  11058. fltr->sw_id)) {
  11059. bnxt_hwrm_cfa_ntuple_filter_free(bp,
  11060. fltr);
  11061. del = true;
  11062. }
  11063. } else {
  11064. rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
  11065. fltr);
  11066. if (rc)
  11067. del = true;
  11068. else
  11069. set_bit(BNXT_FLTR_VALID, &fltr->state);
  11070. }
  11071. if (del) {
  11072. spin_lock_bh(&bp->ntp_fltr_lock);
  11073. hlist_del_rcu(&fltr->hash);
  11074. bp->ntp_fltr_count--;
  11075. spin_unlock_bh(&bp->ntp_fltr_lock);
  11076. synchronize_rcu();
  11077. clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
  11078. kfree(fltr);
  11079. }
  11080. }
  11081. }
  11082. if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
  11083. netdev_info(bp->dev, "Receive PF driver unload event!\n");
  11084. }
  11085. #else
  11086. static void bnxt_cfg_ntp_filters(struct bnxt *bp)
  11087. {
  11088. }
  11089. #endif /* CONFIG_RFS_ACCEL */
  11090. static int bnxt_udp_tunnel_set_port(struct net_device *netdev, unsigned int table,
  11091. unsigned int entry, struct udp_tunnel_info *ti)
  11092. {
  11093. struct bnxt *bp = netdev_priv(netdev);
  11094. unsigned int cmd;
  11095. if (ti->type == UDP_TUNNEL_TYPE_VXLAN)
  11096. cmd = TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN;
  11097. else
  11098. cmd = TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE;
  11099. return bnxt_hwrm_tunnel_dst_port_alloc(bp, ti->port, cmd);
  11100. }
  11101. static int bnxt_udp_tunnel_unset_port(struct net_device *netdev, unsigned int table,
  11102. unsigned int entry, struct udp_tunnel_info *ti)
  11103. {
  11104. struct bnxt *bp = netdev_priv(netdev);
  11105. unsigned int cmd;
  11106. if (ti->type == UDP_TUNNEL_TYPE_VXLAN)
  11107. cmd = TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN;
  11108. else
  11109. cmd = TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE;
  11110. return bnxt_hwrm_tunnel_dst_port_free(bp, cmd);
  11111. }
  11112. static const struct udp_tunnel_nic_info bnxt_udp_tunnels = {
  11113. .set_port = bnxt_udp_tunnel_set_port,
  11114. .unset_port = bnxt_udp_tunnel_unset_port,
  11115. .flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP |
  11116. UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
  11117. .tables = {
  11118. { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
  11119. { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_GENEVE, },
  11120. },
  11121. };
  11122. static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  11123. struct net_device *dev, u32 filter_mask,
  11124. int nlflags)
  11125. {
  11126. struct bnxt *bp = netdev_priv(dev);
  11127. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0,
  11128. nlflags, filter_mask, NULL);
  11129. }
  11130. static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
  11131. u16 flags, struct netlink_ext_ack *extack)
  11132. {
  11133. struct bnxt *bp = netdev_priv(dev);
  11134. struct nlattr *attr, *br_spec;
  11135. int rem, rc = 0;
  11136. if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp))
  11137. return -EOPNOTSUPP;
  11138. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  11139. if (!br_spec)
  11140. return -EINVAL;
  11141. nla_for_each_nested(attr, br_spec, rem) {
  11142. u16 mode;
  11143. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  11144. continue;
  11145. if (nla_len(attr) < sizeof(mode))
  11146. return -EINVAL;
  11147. mode = nla_get_u16(attr);
  11148. if (mode == bp->br_mode)
  11149. break;
  11150. rc = bnxt_hwrm_set_br_mode(bp, mode);
  11151. if (!rc)
  11152. bp->br_mode = mode;
  11153. break;
  11154. }
  11155. return rc;
  11156. }
  11157. int bnxt_get_port_parent_id(struct net_device *dev,
  11158. struct netdev_phys_item_id *ppid)
  11159. {
  11160. struct bnxt *bp = netdev_priv(dev);
  11161. if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV)
  11162. return -EOPNOTSUPP;
  11163. /* The PF and it's VF-reps only support the switchdev framework */
  11164. if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_DSN_VALID))
  11165. return -EOPNOTSUPP;
  11166. ppid->id_len = sizeof(bp->dsn);
  11167. memcpy(ppid->id, bp->dsn, ppid->id_len);
  11168. return 0;
  11169. }
  11170. static struct devlink_port *bnxt_get_devlink_port(struct net_device *dev)
  11171. {
  11172. struct bnxt *bp = netdev_priv(dev);
  11173. return &bp->dl_port;
  11174. }
  11175. static const struct net_device_ops bnxt_netdev_ops = {
  11176. .ndo_open = bnxt_open,
  11177. .ndo_start_xmit = bnxt_start_xmit,
  11178. .ndo_stop = bnxt_close,
  11179. .ndo_get_stats64 = bnxt_get_stats64,
  11180. .ndo_set_rx_mode = bnxt_set_rx_mode,
  11181. .ndo_eth_ioctl = bnxt_ioctl,
  11182. .ndo_validate_addr = eth_validate_addr,
  11183. .ndo_set_mac_address = bnxt_change_mac_addr,
  11184. .ndo_change_mtu = bnxt_change_mtu,
  11185. .ndo_fix_features = bnxt_fix_features,
  11186. .ndo_set_features = bnxt_set_features,
  11187. .ndo_features_check = bnxt_features_check,
  11188. .ndo_tx_timeout = bnxt_tx_timeout,
  11189. #ifdef CONFIG_BNXT_SRIOV
  11190. .ndo_get_vf_config = bnxt_get_vf_config,
  11191. .ndo_set_vf_mac = bnxt_set_vf_mac,
  11192. .ndo_set_vf_vlan = bnxt_set_vf_vlan,
  11193. .ndo_set_vf_rate = bnxt_set_vf_bw,
  11194. .ndo_set_vf_link_state = bnxt_set_vf_link_state,
  11195. .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
  11196. .ndo_set_vf_trust = bnxt_set_vf_trust,
  11197. #endif
  11198. .ndo_setup_tc = bnxt_setup_tc,
  11199. #ifdef CONFIG_RFS_ACCEL
  11200. .ndo_rx_flow_steer = bnxt_rx_flow_steer,
  11201. #endif
  11202. .ndo_bpf = bnxt_xdp,
  11203. .ndo_xdp_xmit = bnxt_xdp_xmit,
  11204. .ndo_bridge_getlink = bnxt_bridge_getlink,
  11205. .ndo_bridge_setlink = bnxt_bridge_setlink,
  11206. .ndo_get_devlink_port = bnxt_get_devlink_port,
  11207. };
  11208. static void bnxt_remove_one(struct pci_dev *pdev)
  11209. {
  11210. struct net_device *dev = pci_get_drvdata(pdev);
  11211. struct bnxt *bp = netdev_priv(dev);
  11212. if (BNXT_PF(bp))
  11213. bnxt_sriov_disable(bp);
  11214. if (BNXT_PF(bp))
  11215. devlink_port_type_clear(&bp->dl_port);
  11216. bnxt_ptp_clear(bp);
  11217. pci_disable_pcie_error_reporting(pdev);
  11218. unregister_netdev(dev);
  11219. clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
  11220. /* Flush any pending tasks */
  11221. cancel_work_sync(&bp->sp_task);
  11222. cancel_delayed_work_sync(&bp->fw_reset_task);
  11223. bp->sp_event = 0;
  11224. bnxt_dl_fw_reporters_destroy(bp);
  11225. bnxt_dl_unregister(bp);
  11226. bnxt_shutdown_tc(bp);
  11227. bnxt_clear_int_mode(bp);
  11228. bnxt_hwrm_func_drv_unrgtr(bp);
  11229. bnxt_free_hwrm_resources(bp);
  11230. bnxt_ethtool_free(bp);
  11231. bnxt_dcb_free(bp);
  11232. kfree(bp->edev);
  11233. bp->edev = NULL;
  11234. kfree(bp->ptp_cfg);
  11235. bp->ptp_cfg = NULL;
  11236. kfree(bp->fw_health);
  11237. bp->fw_health = NULL;
  11238. bnxt_cleanup_pci(bp);
  11239. bnxt_free_ctx_mem(bp);
  11240. kfree(bp->ctx);
  11241. bp->ctx = NULL;
  11242. kfree(bp->rss_indir_tbl);
  11243. bp->rss_indir_tbl = NULL;
  11244. bnxt_free_port_stats(bp);
  11245. free_netdev(dev);
  11246. }
  11247. static int bnxt_probe_phy(struct bnxt *bp, bool fw_dflt)
  11248. {
  11249. int rc = 0;
  11250. struct bnxt_link_info *link_info = &bp->link_info;
  11251. bp->phy_flags = 0;
  11252. rc = bnxt_hwrm_phy_qcaps(bp);
  11253. if (rc) {
  11254. netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
  11255. rc);
  11256. return rc;
  11257. }
  11258. if (bp->phy_flags & BNXT_PHY_FL_NO_FCS)
  11259. bp->dev->priv_flags |= IFF_SUPP_NOFCS;
  11260. else
  11261. bp->dev->priv_flags &= ~IFF_SUPP_NOFCS;
  11262. if (!fw_dflt)
  11263. return 0;
  11264. mutex_lock(&bp->link_lock);
  11265. rc = bnxt_update_link(bp, false);
  11266. if (rc) {
  11267. mutex_unlock(&bp->link_lock);
  11268. netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
  11269. rc);
  11270. return rc;
  11271. }
  11272. /* Older firmware does not have supported_auto_speeds, so assume
  11273. * that all supported speeds can be autonegotiated.
  11274. */
  11275. if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
  11276. link_info->support_auto_speeds = link_info->support_speeds;
  11277. bnxt_init_ethtool_link_settings(bp);
  11278. mutex_unlock(&bp->link_lock);
  11279. return 0;
  11280. }
  11281. static int bnxt_get_max_irq(struct pci_dev *pdev)
  11282. {
  11283. u16 ctrl;
  11284. if (!pdev->msix_cap)
  11285. return 1;
  11286. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
  11287. return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
  11288. }
  11289. static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
  11290. int *max_cp)
  11291. {
  11292. struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
  11293. int max_ring_grps = 0, max_irq;
  11294. *max_tx = hw_resc->max_tx_rings;
  11295. *max_rx = hw_resc->max_rx_rings;
  11296. *max_cp = bnxt_get_max_func_cp_rings_for_en(bp);
  11297. max_irq = min_t(int, bnxt_get_max_func_irqs(bp) -
  11298. bnxt_get_ulp_msix_num(bp),
  11299. hw_resc->max_stat_ctxs - bnxt_get_ulp_stat_ctxs(bp));
  11300. if (!(bp->flags & BNXT_FLAG_CHIP_P5))
  11301. *max_cp = min_t(int, *max_cp, max_irq);
  11302. max_ring_grps = hw_resc->max_hw_ring_grps;
  11303. if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
  11304. *max_cp -= 1;
  11305. *max_rx -= 2;
  11306. }
  11307. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  11308. *max_rx >>= 1;
  11309. if (bp->flags & BNXT_FLAG_CHIP_P5) {
  11310. bnxt_trim_rings(bp, max_rx, max_tx, *max_cp, false);
  11311. /* On P5 chips, max_cp output param should be available NQs */
  11312. *max_cp = max_irq;
  11313. }
  11314. *max_rx = min_t(int, *max_rx, max_ring_grps);
  11315. }
  11316. int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
  11317. {
  11318. int rx, tx, cp;
  11319. _bnxt_get_max_rings(bp, &rx, &tx, &cp);
  11320. *max_rx = rx;
  11321. *max_tx = tx;
  11322. if (!rx || !tx || !cp)
  11323. return -ENOMEM;
  11324. return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
  11325. }
  11326. static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
  11327. bool shared)
  11328. {
  11329. int rc;
  11330. rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
  11331. if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
  11332. /* Not enough rings, try disabling agg rings. */
  11333. bp->flags &= ~BNXT_FLAG_AGG_RINGS;
  11334. rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
  11335. if (rc) {
  11336. /* set BNXT_FLAG_AGG_RINGS back for consistency */
  11337. bp->flags |= BNXT_FLAG_AGG_RINGS;
  11338. return rc;
  11339. }
  11340. bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
  11341. bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  11342. bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  11343. bnxt_set_ring_params(bp);
  11344. }
  11345. if (bp->flags & BNXT_FLAG_ROCE_CAP) {
  11346. int max_cp, max_stat, max_irq;
  11347. /* Reserve minimum resources for RoCE */
  11348. max_cp = bnxt_get_max_func_cp_rings(bp);
  11349. max_stat = bnxt_get_max_func_stat_ctxs(bp);
  11350. max_irq = bnxt_get_max_func_irqs(bp);
  11351. if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
  11352. max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
  11353. max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
  11354. return 0;
  11355. max_cp -= BNXT_MIN_ROCE_CP_RINGS;
  11356. max_irq -= BNXT_MIN_ROCE_CP_RINGS;
  11357. max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
  11358. max_cp = min_t(int, max_cp, max_irq);
  11359. max_cp = min_t(int, max_cp, max_stat);
  11360. rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
  11361. if (rc)
  11362. rc = 0;
  11363. }
  11364. return rc;
  11365. }
  11366. /* In initial default shared ring setting, each shared ring must have a
  11367. * RX/TX ring pair.
  11368. */
  11369. static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
  11370. {
  11371. bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings);
  11372. bp->rx_nr_rings = bp->cp_nr_rings;
  11373. bp->tx_nr_rings_per_tc = bp->cp_nr_rings;
  11374. bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
  11375. }
  11376. static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
  11377. {
  11378. int dflt_rings, max_rx_rings, max_tx_rings, rc;
  11379. if (!bnxt_can_reserve_rings(bp))
  11380. return 0;
  11381. if (sh)
  11382. bp->flags |= BNXT_FLAG_SHARED_RINGS;
  11383. dflt_rings = is_kdump_kernel() ? 1 : netif_get_num_default_rss_queues();
  11384. /* Reduce default rings on multi-port cards so that total default
  11385. * rings do not exceed CPU count.
  11386. */
  11387. if (bp->port_count > 1) {
  11388. int max_rings =
  11389. max_t(int, num_online_cpus() / bp->port_count, 1);
  11390. dflt_rings = min_t(int, dflt_rings, max_rings);
  11391. }
  11392. rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
  11393. if (rc)
  11394. return rc;
  11395. bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
  11396. bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
  11397. if (sh)
  11398. bnxt_trim_dflt_sh_rings(bp);
  11399. else
  11400. bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
  11401. bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
  11402. rc = __bnxt_reserve_rings(bp);
  11403. if (rc && rc != -ENODEV)
  11404. netdev_warn(bp->dev, "Unable to reserve tx rings\n");
  11405. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  11406. if (sh)
  11407. bnxt_trim_dflt_sh_rings(bp);
  11408. /* Rings may have been trimmed, re-reserve the trimmed rings. */
  11409. if (bnxt_need_reserve_rings(bp)) {
  11410. rc = __bnxt_reserve_rings(bp);
  11411. if (rc && rc != -ENODEV)
  11412. netdev_warn(bp->dev, "2nd rings reservation failed.\n");
  11413. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  11414. }
  11415. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  11416. bp->rx_nr_rings++;
  11417. bp->cp_nr_rings++;
  11418. }
  11419. if (rc) {
  11420. bp->tx_nr_rings = 0;
  11421. bp->rx_nr_rings = 0;
  11422. }
  11423. return rc;
  11424. }
  11425. static int bnxt_init_dflt_ring_mode(struct bnxt *bp)
  11426. {
  11427. int rc;
  11428. if (bp->tx_nr_rings)
  11429. return 0;
  11430. bnxt_ulp_irq_stop(bp);
  11431. bnxt_clear_int_mode(bp);
  11432. rc = bnxt_set_dflt_rings(bp, true);
  11433. if (rc) {
  11434. if (BNXT_VF(bp) && rc == -ENODEV)
  11435. netdev_err(bp->dev, "Cannot configure VF rings while PF is unavailable.\n");
  11436. else
  11437. netdev_err(bp->dev, "Not enough rings available.\n");
  11438. goto init_dflt_ring_err;
  11439. }
  11440. rc = bnxt_init_int_mode(bp);
  11441. if (rc)
  11442. goto init_dflt_ring_err;
  11443. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  11444. bnxt_set_dflt_rfs(bp);
  11445. init_dflt_ring_err:
  11446. bnxt_ulp_irq_restart(bp, rc);
  11447. return rc;
  11448. }
  11449. int bnxt_restore_pf_fw_resources(struct bnxt *bp)
  11450. {
  11451. int rc;
  11452. ASSERT_RTNL();
  11453. bnxt_hwrm_func_qcaps(bp);
  11454. if (netif_running(bp->dev))
  11455. __bnxt_close_nic(bp, true, false);
  11456. bnxt_ulp_irq_stop(bp);
  11457. bnxt_clear_int_mode(bp);
  11458. rc = bnxt_init_int_mode(bp);
  11459. bnxt_ulp_irq_restart(bp, rc);
  11460. if (netif_running(bp->dev)) {
  11461. if (rc)
  11462. dev_close(bp->dev);
  11463. else
  11464. rc = bnxt_open_nic(bp, true, false);
  11465. }
  11466. return rc;
  11467. }
  11468. static int bnxt_init_mac_addr(struct bnxt *bp)
  11469. {
  11470. int rc = 0;
  11471. if (BNXT_PF(bp)) {
  11472. eth_hw_addr_set(bp->dev, bp->pf.mac_addr);
  11473. } else {
  11474. #ifdef CONFIG_BNXT_SRIOV
  11475. struct bnxt_vf_info *vf = &bp->vf;
  11476. bool strict_approval = true;
  11477. if (is_valid_ether_addr(vf->mac_addr)) {
  11478. /* overwrite netdev dev_addr with admin VF MAC */
  11479. eth_hw_addr_set(bp->dev, vf->mac_addr);
  11480. /* Older PF driver or firmware may not approve this
  11481. * correctly.
  11482. */
  11483. strict_approval = false;
  11484. } else {
  11485. eth_hw_addr_random(bp->dev);
  11486. }
  11487. rc = bnxt_approve_mac(bp, bp->dev->dev_addr, strict_approval);
  11488. #endif
  11489. }
  11490. return rc;
  11491. }
  11492. static void bnxt_vpd_read_info(struct bnxt *bp)
  11493. {
  11494. struct pci_dev *pdev = bp->pdev;
  11495. unsigned int vpd_size, kw_len;
  11496. int pos, size;
  11497. u8 *vpd_data;
  11498. vpd_data = pci_vpd_alloc(pdev, &vpd_size);
  11499. if (IS_ERR(vpd_data)) {
  11500. pci_warn(pdev, "Unable to read VPD\n");
  11501. return;
  11502. }
  11503. pos = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
  11504. PCI_VPD_RO_KEYWORD_PARTNO, &kw_len);
  11505. if (pos < 0)
  11506. goto read_sn;
  11507. size = min_t(int, kw_len, BNXT_VPD_FLD_LEN - 1);
  11508. memcpy(bp->board_partno, &vpd_data[pos], size);
  11509. read_sn:
  11510. pos = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
  11511. PCI_VPD_RO_KEYWORD_SERIALNO,
  11512. &kw_len);
  11513. if (pos < 0)
  11514. goto exit;
  11515. size = min_t(int, kw_len, BNXT_VPD_FLD_LEN - 1);
  11516. memcpy(bp->board_serialno, &vpd_data[pos], size);
  11517. exit:
  11518. kfree(vpd_data);
  11519. }
  11520. static int bnxt_pcie_dsn_get(struct bnxt *bp, u8 dsn[])
  11521. {
  11522. struct pci_dev *pdev = bp->pdev;
  11523. u64 qword;
  11524. qword = pci_get_dsn(pdev);
  11525. if (!qword) {
  11526. netdev_info(bp->dev, "Unable to read adapter's DSN\n");
  11527. return -EOPNOTSUPP;
  11528. }
  11529. put_unaligned_le64(qword, dsn);
  11530. bp->flags |= BNXT_FLAG_DSN_VALID;
  11531. return 0;
  11532. }
  11533. static int bnxt_map_db_bar(struct bnxt *bp)
  11534. {
  11535. if (!bp->db_size)
  11536. return -ENODEV;
  11537. bp->bar1 = pci_iomap(bp->pdev, 2, bp->db_size);
  11538. if (!bp->bar1)
  11539. return -ENOMEM;
  11540. return 0;
  11541. }
  11542. void bnxt_print_device_info(struct bnxt *bp)
  11543. {
  11544. netdev_info(bp->dev, "%s found at mem %lx, node addr %pM\n",
  11545. board_info[bp->board_idx].name,
  11546. (long)pci_resource_start(bp->pdev, 0), bp->dev->dev_addr);
  11547. pcie_print_link_status(bp->pdev);
  11548. }
  11549. static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  11550. {
  11551. struct net_device *dev;
  11552. struct bnxt *bp;
  11553. int rc, max_irqs;
  11554. if (pci_is_bridge(pdev))
  11555. return -ENODEV;
  11556. /* Clear any pending DMA transactions from crash kernel
  11557. * while loading driver in capture kernel.
  11558. */
  11559. if (is_kdump_kernel()) {
  11560. pci_clear_master(pdev);
  11561. pcie_flr(pdev);
  11562. }
  11563. max_irqs = bnxt_get_max_irq(pdev);
  11564. dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
  11565. if (!dev)
  11566. return -ENOMEM;
  11567. bp = netdev_priv(dev);
  11568. bp->board_idx = ent->driver_data;
  11569. bp->msg_enable = BNXT_DEF_MSG_ENABLE;
  11570. bnxt_set_max_func_irqs(bp, max_irqs);
  11571. if (bnxt_vf_pciid(bp->board_idx))
  11572. bp->flags |= BNXT_FLAG_VF;
  11573. if (pdev->msix_cap)
  11574. bp->flags |= BNXT_FLAG_MSIX_CAP;
  11575. rc = bnxt_init_board(pdev, dev);
  11576. if (rc < 0)
  11577. goto init_err_free;
  11578. dev->netdev_ops = &bnxt_netdev_ops;
  11579. dev->watchdog_timeo = BNXT_TX_TIMEOUT;
  11580. dev->ethtool_ops = &bnxt_ethtool_ops;
  11581. pci_set_drvdata(pdev, dev);
  11582. rc = bnxt_alloc_hwrm_resources(bp);
  11583. if (rc)
  11584. goto init_err_pci_clean;
  11585. mutex_init(&bp->hwrm_cmd_lock);
  11586. mutex_init(&bp->link_lock);
  11587. rc = bnxt_fw_init_one_p1(bp);
  11588. if (rc)
  11589. goto init_err_pci_clean;
  11590. if (BNXT_PF(bp))
  11591. bnxt_vpd_read_info(bp);
  11592. if (BNXT_CHIP_P5(bp)) {
  11593. bp->flags |= BNXT_FLAG_CHIP_P5;
  11594. if (BNXT_CHIP_SR2(bp))
  11595. bp->flags |= BNXT_FLAG_CHIP_SR2;
  11596. }
  11597. rc = bnxt_alloc_rss_indir_tbl(bp);
  11598. if (rc)
  11599. goto init_err_pci_clean;
  11600. rc = bnxt_fw_init_one_p2(bp);
  11601. if (rc)
  11602. goto init_err_pci_clean;
  11603. rc = bnxt_map_db_bar(bp);
  11604. if (rc) {
  11605. dev_err(&pdev->dev, "Cannot map doorbell BAR rc = %d, aborting\n",
  11606. rc);
  11607. goto init_err_pci_clean;
  11608. }
  11609. dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11610. NETIF_F_TSO | NETIF_F_TSO6 |
  11611. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
  11612. NETIF_F_GSO_IPXIP4 |
  11613. NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
  11614. NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
  11615. NETIF_F_RXCSUM | NETIF_F_GRO;
  11616. if (BNXT_SUPPORTS_TPA(bp))
  11617. dev->hw_features |= NETIF_F_LRO;
  11618. dev->hw_enc_features =
  11619. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11620. NETIF_F_TSO | NETIF_F_TSO6 |
  11621. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
  11622. NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
  11623. NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
  11624. dev->udp_tunnel_nic_info = &bnxt_udp_tunnels;
  11625. dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11626. NETIF_F_GSO_GRE_CSUM;
  11627. dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
  11628. if (bp->fw_cap & BNXT_FW_CAP_VLAN_RX_STRIP)
  11629. dev->hw_features |= BNXT_HW_FEATURE_VLAN_ALL_RX;
  11630. if (bp->fw_cap & BNXT_FW_CAP_VLAN_TX_INSERT)
  11631. dev->hw_features |= BNXT_HW_FEATURE_VLAN_ALL_TX;
  11632. if (BNXT_SUPPORTS_TPA(bp))
  11633. dev->hw_features |= NETIF_F_GRO_HW;
  11634. dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
  11635. if (dev->features & NETIF_F_GRO_HW)
  11636. dev->features &= ~NETIF_F_LRO;
  11637. dev->priv_flags |= IFF_UNICAST_FLT;
  11638. #ifdef CONFIG_BNXT_SRIOV
  11639. init_waitqueue_head(&bp->sriov_cfg_wait);
  11640. #endif
  11641. if (BNXT_SUPPORTS_TPA(bp)) {
  11642. bp->gro_func = bnxt_gro_func_5730x;
  11643. if (BNXT_CHIP_P4(bp))
  11644. bp->gro_func = bnxt_gro_func_5731x;
  11645. else if (BNXT_CHIP_P5(bp))
  11646. bp->gro_func = bnxt_gro_func_5750x;
  11647. }
  11648. if (!BNXT_CHIP_P4_PLUS(bp))
  11649. bp->flags |= BNXT_FLAG_DOUBLE_DB;
  11650. rc = bnxt_init_mac_addr(bp);
  11651. if (rc) {
  11652. dev_err(&pdev->dev, "Unable to initialize mac address.\n");
  11653. rc = -EADDRNOTAVAIL;
  11654. goto init_err_pci_clean;
  11655. }
  11656. if (BNXT_PF(bp)) {
  11657. /* Read the adapter's DSN to use as the eswitch switch_id */
  11658. rc = bnxt_pcie_dsn_get(bp, bp->dsn);
  11659. }
  11660. /* MTU range: 60 - FW defined max */
  11661. dev->min_mtu = ETH_ZLEN;
  11662. dev->max_mtu = bp->max_mtu;
  11663. rc = bnxt_probe_phy(bp, true);
  11664. if (rc)
  11665. goto init_err_pci_clean;
  11666. bnxt_set_rx_skb_mode(bp, false);
  11667. bnxt_set_tpa_flags(bp);
  11668. bnxt_set_ring_params(bp);
  11669. rc = bnxt_set_dflt_rings(bp, true);
  11670. if (rc) {
  11671. if (BNXT_VF(bp) && rc == -ENODEV) {
  11672. netdev_err(bp->dev, "Cannot configure VF rings while PF is unavailable.\n");
  11673. } else {
  11674. netdev_err(bp->dev, "Not enough rings available.\n");
  11675. rc = -ENOMEM;
  11676. }
  11677. goto init_err_pci_clean;
  11678. }
  11679. bnxt_fw_init_one_p3(bp);
  11680. bnxt_init_dflt_coal(bp);
  11681. if (dev->hw_features & BNXT_HW_FEATURE_VLAN_ALL_RX)
  11682. bp->flags |= BNXT_FLAG_STRIP_VLAN;
  11683. rc = bnxt_init_int_mode(bp);
  11684. if (rc)
  11685. goto init_err_pci_clean;
  11686. /* No TC has been set yet and rings may have been trimmed due to
  11687. * limited MSIX, so we re-initialize the TX rings per TC.
  11688. */
  11689. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  11690. if (BNXT_PF(bp)) {
  11691. if (!bnxt_pf_wq) {
  11692. bnxt_pf_wq =
  11693. create_singlethread_workqueue("bnxt_pf_wq");
  11694. if (!bnxt_pf_wq) {
  11695. dev_err(&pdev->dev, "Unable to create workqueue.\n");
  11696. rc = -ENOMEM;
  11697. goto init_err_pci_clean;
  11698. }
  11699. }
  11700. rc = bnxt_init_tc(bp);
  11701. if (rc)
  11702. netdev_err(dev, "Failed to initialize TC flower offload, err = %d.\n",
  11703. rc);
  11704. }
  11705. bnxt_inv_fw_health_reg(bp);
  11706. rc = bnxt_dl_register(bp);
  11707. if (rc)
  11708. goto init_err_dl;
  11709. rc = register_netdev(dev);
  11710. if (rc)
  11711. goto init_err_cleanup;
  11712. if (BNXT_PF(bp))
  11713. devlink_port_type_eth_set(&bp->dl_port, bp->dev);
  11714. bnxt_dl_fw_reporters_create(bp);
  11715. bnxt_print_device_info(bp);
  11716. pci_save_state(pdev);
  11717. return 0;
  11718. init_err_cleanup:
  11719. bnxt_dl_unregister(bp);
  11720. init_err_dl:
  11721. bnxt_shutdown_tc(bp);
  11722. bnxt_clear_int_mode(bp);
  11723. init_err_pci_clean:
  11724. bnxt_hwrm_func_drv_unrgtr(bp);
  11725. bnxt_free_hwrm_resources(bp);
  11726. bnxt_ethtool_free(bp);
  11727. bnxt_ptp_clear(bp);
  11728. kfree(bp->ptp_cfg);
  11729. bp->ptp_cfg = NULL;
  11730. kfree(bp->fw_health);
  11731. bp->fw_health = NULL;
  11732. bnxt_cleanup_pci(bp);
  11733. bnxt_free_ctx_mem(bp);
  11734. kfree(bp->ctx);
  11735. bp->ctx = NULL;
  11736. kfree(bp->rss_indir_tbl);
  11737. bp->rss_indir_tbl = NULL;
  11738. init_err_free:
  11739. free_netdev(dev);
  11740. return rc;
  11741. }
  11742. static void bnxt_shutdown(struct pci_dev *pdev)
  11743. {
  11744. struct net_device *dev = pci_get_drvdata(pdev);
  11745. struct bnxt *bp;
  11746. if (!dev)
  11747. return;
  11748. rtnl_lock();
  11749. bp = netdev_priv(dev);
  11750. if (!bp)
  11751. goto shutdown_exit;
  11752. if (netif_running(dev))
  11753. dev_close(dev);
  11754. bnxt_ulp_shutdown(bp);
  11755. bnxt_clear_int_mode(bp);
  11756. pci_disable_device(pdev);
  11757. if (system_state == SYSTEM_POWER_OFF) {
  11758. pci_wake_from_d3(pdev, bp->wol);
  11759. pci_set_power_state(pdev, PCI_D3hot);
  11760. }
  11761. shutdown_exit:
  11762. rtnl_unlock();
  11763. }
  11764. #ifdef CONFIG_PM_SLEEP
  11765. static int bnxt_suspend(struct device *device)
  11766. {
  11767. struct net_device *dev = dev_get_drvdata(device);
  11768. struct bnxt *bp = netdev_priv(dev);
  11769. int rc = 0;
  11770. rtnl_lock();
  11771. bnxt_ulp_stop(bp);
  11772. if (netif_running(dev)) {
  11773. netif_device_detach(dev);
  11774. rc = bnxt_close(dev);
  11775. }
  11776. bnxt_hwrm_func_drv_unrgtr(bp);
  11777. pci_disable_device(bp->pdev);
  11778. bnxt_free_ctx_mem(bp);
  11779. kfree(bp->ctx);
  11780. bp->ctx = NULL;
  11781. rtnl_unlock();
  11782. return rc;
  11783. }
  11784. static int bnxt_resume(struct device *device)
  11785. {
  11786. struct net_device *dev = dev_get_drvdata(device);
  11787. struct bnxt *bp = netdev_priv(dev);
  11788. int rc = 0;
  11789. rtnl_lock();
  11790. rc = pci_enable_device(bp->pdev);
  11791. if (rc) {
  11792. netdev_err(dev, "Cannot re-enable PCI device during resume, err = %d\n",
  11793. rc);
  11794. goto resume_exit;
  11795. }
  11796. pci_set_master(bp->pdev);
  11797. if (bnxt_hwrm_ver_get(bp)) {
  11798. rc = -ENODEV;
  11799. goto resume_exit;
  11800. }
  11801. rc = bnxt_hwrm_func_reset(bp);
  11802. if (rc) {
  11803. rc = -EBUSY;
  11804. goto resume_exit;
  11805. }
  11806. rc = bnxt_hwrm_func_qcaps(bp);
  11807. if (rc)
  11808. goto resume_exit;
  11809. if (bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, false)) {
  11810. rc = -ENODEV;
  11811. goto resume_exit;
  11812. }
  11813. bnxt_get_wol_settings(bp);
  11814. if (netif_running(dev)) {
  11815. rc = bnxt_open(dev);
  11816. if (!rc)
  11817. netif_device_attach(dev);
  11818. }
  11819. resume_exit:
  11820. bnxt_ulp_start(bp, rc);
  11821. if (!rc)
  11822. bnxt_reenable_sriov(bp);
  11823. rtnl_unlock();
  11824. return rc;
  11825. }
  11826. static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
  11827. #define BNXT_PM_OPS (&bnxt_pm_ops)
  11828. #else
  11829. #define BNXT_PM_OPS NULL
  11830. #endif /* CONFIG_PM_SLEEP */
  11831. /**
  11832. * bnxt_io_error_detected - called when PCI error is detected
  11833. * @pdev: Pointer to PCI device
  11834. * @state: The current pci connection state
  11835. *
  11836. * This function is called after a PCI bus error affecting
  11837. * this device has been detected.
  11838. */
  11839. static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
  11840. pci_channel_state_t state)
  11841. {
  11842. struct net_device *netdev = pci_get_drvdata(pdev);
  11843. struct bnxt *bp = netdev_priv(netdev);
  11844. netdev_info(netdev, "PCI I/O error detected\n");
  11845. rtnl_lock();
  11846. netif_device_detach(netdev);
  11847. bnxt_ulp_stop(bp);
  11848. if (state == pci_channel_io_perm_failure) {
  11849. rtnl_unlock();
  11850. return PCI_ERS_RESULT_DISCONNECT;
  11851. }
  11852. if (state == pci_channel_io_frozen)
  11853. set_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, &bp->state);
  11854. if (netif_running(netdev))
  11855. bnxt_close(netdev);
  11856. if (pci_is_enabled(pdev))
  11857. pci_disable_device(pdev);
  11858. bnxt_free_ctx_mem(bp);
  11859. kfree(bp->ctx);
  11860. bp->ctx = NULL;
  11861. rtnl_unlock();
  11862. /* Request a slot slot reset. */
  11863. return PCI_ERS_RESULT_NEED_RESET;
  11864. }
  11865. /**
  11866. * bnxt_io_slot_reset - called after the pci bus has been reset.
  11867. * @pdev: Pointer to PCI device
  11868. *
  11869. * Restart the card from scratch, as if from a cold-boot.
  11870. * At this point, the card has exprienced a hard reset,
  11871. * followed by fixups by BIOS, and has its config space
  11872. * set up identically to what it was at cold boot.
  11873. */
  11874. static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
  11875. {
  11876. pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
  11877. struct net_device *netdev = pci_get_drvdata(pdev);
  11878. struct bnxt *bp = netdev_priv(netdev);
  11879. int retry = 0;
  11880. int err = 0;
  11881. int off;
  11882. netdev_info(bp->dev, "PCI Slot Reset\n");
  11883. rtnl_lock();
  11884. if (pci_enable_device(pdev)) {
  11885. dev_err(&pdev->dev,
  11886. "Cannot re-enable PCI device after reset.\n");
  11887. } else {
  11888. pci_set_master(pdev);
  11889. /* Upon fatal error, our device internal logic that latches to
  11890. * BAR value is getting reset and will restore only upon
  11891. * rewritting the BARs.
  11892. *
  11893. * As pci_restore_state() does not re-write the BARs if the
  11894. * value is same as saved value earlier, driver needs to
  11895. * write the BARs to 0 to force restore, in case of fatal error.
  11896. */
  11897. if (test_and_clear_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN,
  11898. &bp->state)) {
  11899. for (off = PCI_BASE_ADDRESS_0;
  11900. off <= PCI_BASE_ADDRESS_5; off += 4)
  11901. pci_write_config_dword(bp->pdev, off, 0);
  11902. }
  11903. pci_restore_state(pdev);
  11904. pci_save_state(pdev);
  11905. bnxt_inv_fw_health_reg(bp);
  11906. bnxt_try_map_fw_health_reg(bp);
  11907. /* In some PCIe AER scenarios, firmware may take up to
  11908. * 10 seconds to become ready in the worst case.
  11909. */
  11910. do {
  11911. err = bnxt_try_recover_fw(bp);
  11912. if (!err)
  11913. break;
  11914. retry++;
  11915. } while (retry < BNXT_FW_SLOT_RESET_RETRY);
  11916. if (err) {
  11917. dev_err(&pdev->dev, "Firmware not ready\n");
  11918. goto reset_exit;
  11919. }
  11920. err = bnxt_hwrm_func_reset(bp);
  11921. if (!err)
  11922. result = PCI_ERS_RESULT_RECOVERED;
  11923. bnxt_ulp_irq_stop(bp);
  11924. bnxt_clear_int_mode(bp);
  11925. err = bnxt_init_int_mode(bp);
  11926. bnxt_ulp_irq_restart(bp, err);
  11927. }
  11928. reset_exit:
  11929. bnxt_clear_reservations(bp, true);
  11930. rtnl_unlock();
  11931. return result;
  11932. }
  11933. /**
  11934. * bnxt_io_resume - called when traffic can start flowing again.
  11935. * @pdev: Pointer to PCI device
  11936. *
  11937. * This callback is called when the error recovery driver tells
  11938. * us that its OK to resume normal operation.
  11939. */
  11940. static void bnxt_io_resume(struct pci_dev *pdev)
  11941. {
  11942. struct net_device *netdev = pci_get_drvdata(pdev);
  11943. struct bnxt *bp = netdev_priv(netdev);
  11944. int err;
  11945. netdev_info(bp->dev, "PCI Slot Resume\n");
  11946. rtnl_lock();
  11947. err = bnxt_hwrm_func_qcaps(bp);
  11948. if (!err && netif_running(netdev))
  11949. err = bnxt_open(netdev);
  11950. bnxt_ulp_start(bp, err);
  11951. if (!err) {
  11952. bnxt_reenable_sriov(bp);
  11953. netif_device_attach(netdev);
  11954. }
  11955. rtnl_unlock();
  11956. }
  11957. static const struct pci_error_handlers bnxt_err_handler = {
  11958. .error_detected = bnxt_io_error_detected,
  11959. .slot_reset = bnxt_io_slot_reset,
  11960. .resume = bnxt_io_resume
  11961. };
  11962. static struct pci_driver bnxt_pci_driver = {
  11963. .name = DRV_MODULE_NAME,
  11964. .id_table = bnxt_pci_tbl,
  11965. .probe = bnxt_init_one,
  11966. .remove = bnxt_remove_one,
  11967. .shutdown = bnxt_shutdown,
  11968. .driver.pm = BNXT_PM_OPS,
  11969. .err_handler = &bnxt_err_handler,
  11970. #if defined(CONFIG_BNXT_SRIOV)
  11971. .sriov_configure = bnxt_sriov_configure,
  11972. #endif
  11973. };
  11974. static int __init bnxt_init(void)
  11975. {
  11976. int err;
  11977. bnxt_debug_init();
  11978. err = pci_register_driver(&bnxt_pci_driver);
  11979. if (err) {
  11980. bnxt_debug_exit();
  11981. return err;
  11982. }
  11983. return 0;
  11984. }
  11985. static void __exit bnxt_exit(void)
  11986. {
  11987. pci_unregister_driver(&bnxt_pci_driver);
  11988. if (bnxt_pf_wq)
  11989. destroy_workqueue(bnxt_pf_wq);
  11990. bnxt_debug_exit();
  11991. }
  11992. module_init(bnxt_init);
  11993. module_exit(bnxt_exit);