bnxt.c 201 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951
  1. /* Broadcom NetXtreme-C/E network driver.
  2. *
  3. * Copyright (c) 2014-2016 Broadcom Corporation
  4. * Copyright (c) 2016-2017 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/if.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/rtc.h>
  35. #include <linux/bpf.h>
  36. #include <net/ip.h>
  37. #include <net/tcp.h>
  38. #include <net/udp.h>
  39. #include <net/checksum.h>
  40. #include <net/ip6_checksum.h>
  41. #include <net/udp_tunnel.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/prefetch.h>
  44. #include <linux/cache.h>
  45. #include <linux/log2.h>
  46. #include <linux/aer.h>
  47. #include <linux/bitmap.h>
  48. #include <linux/cpu_rmap.h>
  49. #include "bnxt_hsi.h"
  50. #include "bnxt.h"
  51. #include "bnxt_ulp.h"
  52. #include "bnxt_sriov.h"
  53. #include "bnxt_ethtool.h"
  54. #include "bnxt_dcb.h"
  55. #include "bnxt_xdp.h"
  56. #define BNXT_TX_TIMEOUT (5 * HZ)
  57. static const char version[] =
  58. "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n";
  59. MODULE_LICENSE("GPL");
  60. MODULE_DESCRIPTION("Broadcom BCM573xx network driver");
  61. MODULE_VERSION(DRV_MODULE_VERSION);
  62. #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
  63. #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
  64. #define BNXT_RX_COPY_THRESH 256
  65. #define BNXT_TX_PUSH_THRESH 164
  66. enum board_idx {
  67. BCM57301,
  68. BCM57302,
  69. BCM57304,
  70. BCM57417_NPAR,
  71. BCM58700,
  72. BCM57311,
  73. BCM57312,
  74. BCM57402,
  75. BCM57404,
  76. BCM57406,
  77. BCM57402_NPAR,
  78. BCM57407,
  79. BCM57412,
  80. BCM57414,
  81. BCM57416,
  82. BCM57417,
  83. BCM57412_NPAR,
  84. BCM57314,
  85. BCM57417_SFP,
  86. BCM57416_SFP,
  87. BCM57404_NPAR,
  88. BCM57406_NPAR,
  89. BCM57407_SFP,
  90. BCM57407_NPAR,
  91. BCM57414_NPAR,
  92. BCM57416_NPAR,
  93. BCM57452,
  94. BCM57454,
  95. NETXTREME_E_VF,
  96. NETXTREME_C_VF,
  97. };
  98. /* indexed by enum above */
  99. static const struct {
  100. char *name;
  101. } board_info[] = {
  102. { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" },
  103. { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" },
  104. { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
  105. { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" },
  106. { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" },
  107. { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" },
  108. { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" },
  109. { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" },
  110. { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" },
  111. { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" },
  112. { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" },
  113. { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" },
  114. { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" },
  115. { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" },
  116. { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" },
  117. { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" },
  118. { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" },
  119. { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" },
  120. { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" },
  121. { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" },
  122. { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" },
  123. { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" },
  124. { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" },
  125. { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" },
  126. { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" },
  127. { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" },
  128. { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" },
  129. { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" },
  130. { "Broadcom NetXtreme-E Ethernet Virtual Function" },
  131. { "Broadcom NetXtreme-C Ethernet Virtual Function" },
  132. };
  133. static const struct pci_device_id bnxt_pci_tbl[] = {
  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, 0x16f1), .driver_data = BCM57452 },
  165. { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 },
  166. #ifdef CONFIG_BNXT_SRIOV
  167. { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF },
  168. { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF },
  169. { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF },
  170. { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF },
  171. { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF },
  172. { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF },
  173. #endif
  174. { 0 }
  175. };
  176. MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
  177. static const u16 bnxt_vf_req_snif[] = {
  178. HWRM_FUNC_CFG,
  179. HWRM_PORT_PHY_QCFG,
  180. HWRM_CFA_L2_FILTER_ALLOC,
  181. };
  182. static const u16 bnxt_async_events_arr[] = {
  183. ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
  184. ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD,
  185. ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED,
  186. ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE,
  187. ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
  188. };
  189. static bool bnxt_vf_pciid(enum board_idx idx)
  190. {
  191. return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF);
  192. }
  193. #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID)
  194. #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS)
  195. #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS)
  196. #define BNXT_CP_DB_REARM(db, raw_cons) \
  197. writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db)
  198. #define BNXT_CP_DB(db, raw_cons) \
  199. writel(DB_CP_FLAGS | RING_CMP(raw_cons), db)
  200. #define BNXT_CP_DB_IRQ_DIS(db) \
  201. writel(DB_CP_IRQ_DIS_FLAGS, db)
  202. const u16 bnxt_lhint_arr[] = {
  203. TX_BD_FLAGS_LHINT_512_AND_SMALLER,
  204. TX_BD_FLAGS_LHINT_512_TO_1023,
  205. TX_BD_FLAGS_LHINT_1024_TO_2047,
  206. TX_BD_FLAGS_LHINT_1024_TO_2047,
  207. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  208. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  209. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  210. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  211. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  212. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  213. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  214. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  215. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  216. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  217. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  218. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  219. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  220. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  221. TX_BD_FLAGS_LHINT_2048_AND_LARGER,
  222. };
  223. static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
  224. {
  225. struct bnxt *bp = netdev_priv(dev);
  226. struct tx_bd *txbd;
  227. struct tx_bd_ext *txbd1;
  228. struct netdev_queue *txq;
  229. int i;
  230. dma_addr_t mapping;
  231. unsigned int length, pad = 0;
  232. u32 len, free_size, vlan_tag_flags, cfa_action, flags;
  233. u16 prod, last_frag;
  234. struct pci_dev *pdev = bp->pdev;
  235. struct bnxt_tx_ring_info *txr;
  236. struct bnxt_sw_tx_bd *tx_buf;
  237. i = skb_get_queue_mapping(skb);
  238. if (unlikely(i >= bp->tx_nr_rings)) {
  239. dev_kfree_skb_any(skb);
  240. return NETDEV_TX_OK;
  241. }
  242. txq = netdev_get_tx_queue(dev, i);
  243. txr = &bp->tx_ring[bp->tx_ring_map[i]];
  244. prod = txr->tx_prod;
  245. free_size = bnxt_tx_avail(bp, txr);
  246. if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
  247. netif_tx_stop_queue(txq);
  248. return NETDEV_TX_BUSY;
  249. }
  250. length = skb->len;
  251. len = skb_headlen(skb);
  252. last_frag = skb_shinfo(skb)->nr_frags;
  253. txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  254. txbd->tx_bd_opaque = prod;
  255. tx_buf = &txr->tx_buf_ring[prod];
  256. tx_buf->skb = skb;
  257. tx_buf->nr_frags = last_frag;
  258. vlan_tag_flags = 0;
  259. cfa_action = 0;
  260. if (skb_vlan_tag_present(skb)) {
  261. vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN |
  262. skb_vlan_tag_get(skb);
  263. /* Currently supports 8021Q, 8021AD vlan offloads
  264. * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
  265. */
  266. if (skb->vlan_proto == htons(ETH_P_8021Q))
  267. vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT;
  268. }
  269. if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) {
  270. struct tx_push_buffer *tx_push_buf = txr->tx_push;
  271. struct tx_push_bd *tx_push = &tx_push_buf->push_bd;
  272. struct tx_bd_ext *tx_push1 = &tx_push->txbd2;
  273. void *pdata = tx_push_buf->data;
  274. u64 *end;
  275. int j, push_len;
  276. /* Set COAL_NOW to be ready quickly for the next push */
  277. tx_push->tx_bd_len_flags_type =
  278. cpu_to_le32((length << TX_BD_LEN_SHIFT) |
  279. TX_BD_TYPE_LONG_TX_BD |
  280. TX_BD_FLAGS_LHINT_512_AND_SMALLER |
  281. TX_BD_FLAGS_COAL_NOW |
  282. TX_BD_FLAGS_PACKET_END |
  283. (2 << TX_BD_FLAGS_BD_CNT_SHIFT));
  284. if (skb->ip_summed == CHECKSUM_PARTIAL)
  285. tx_push1->tx_bd_hsize_lflags =
  286. cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
  287. else
  288. tx_push1->tx_bd_hsize_lflags = 0;
  289. tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
  290. tx_push1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
  291. end = pdata + length;
  292. end = PTR_ALIGN(end, 8) - 1;
  293. *end = 0;
  294. skb_copy_from_linear_data(skb, pdata, len);
  295. pdata += len;
  296. for (j = 0; j < last_frag; j++) {
  297. skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
  298. void *fptr;
  299. fptr = skb_frag_address_safe(frag);
  300. if (!fptr)
  301. goto normal_tx;
  302. memcpy(pdata, fptr, skb_frag_size(frag));
  303. pdata += skb_frag_size(frag);
  304. }
  305. txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type;
  306. txbd->tx_bd_haddr = txr->data_mapping;
  307. prod = NEXT_TX(prod);
  308. txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  309. memcpy(txbd, tx_push1, sizeof(*txbd));
  310. prod = NEXT_TX(prod);
  311. tx_push->doorbell =
  312. cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
  313. txr->tx_prod = prod;
  314. tx_buf->is_push = 1;
  315. netdev_tx_sent_queue(txq, skb->len);
  316. wmb(); /* Sync is_push and byte queue before pushing data */
  317. push_len = (length + sizeof(*tx_push) + 7) / 8;
  318. if (push_len > 16) {
  319. __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16);
  320. __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1,
  321. (push_len - 16) << 1);
  322. } else {
  323. __iowrite64_copy(txr->tx_doorbell, tx_push_buf,
  324. push_len);
  325. }
  326. goto tx_done;
  327. }
  328. normal_tx:
  329. if (length < BNXT_MIN_PKT_SIZE) {
  330. pad = BNXT_MIN_PKT_SIZE - length;
  331. if (skb_pad(skb, pad)) {
  332. /* SKB already freed. */
  333. tx_buf->skb = NULL;
  334. return NETDEV_TX_OK;
  335. }
  336. length = BNXT_MIN_PKT_SIZE;
  337. }
  338. mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
  339. if (unlikely(dma_mapping_error(&pdev->dev, mapping))) {
  340. dev_kfree_skb_any(skb);
  341. tx_buf->skb = NULL;
  342. return NETDEV_TX_OK;
  343. }
  344. dma_unmap_addr_set(tx_buf, mapping, mapping);
  345. flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD |
  346. ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT);
  347. txbd->tx_bd_haddr = cpu_to_le64(mapping);
  348. prod = NEXT_TX(prod);
  349. txbd1 = (struct tx_bd_ext *)
  350. &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  351. txbd1->tx_bd_hsize_lflags = 0;
  352. if (skb_is_gso(skb)) {
  353. u32 hdr_len;
  354. if (skb->encapsulation)
  355. hdr_len = skb_inner_network_offset(skb) +
  356. skb_inner_network_header_len(skb) +
  357. inner_tcp_hdrlen(skb);
  358. else
  359. hdr_len = skb_transport_offset(skb) +
  360. tcp_hdrlen(skb);
  361. txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO |
  362. TX_BD_FLAGS_T_IPID |
  363. (hdr_len << (TX_BD_HSIZE_SHIFT - 1)));
  364. length = skb_shinfo(skb)->gso_size;
  365. txbd1->tx_bd_mss = cpu_to_le32(length);
  366. length += hdr_len;
  367. } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
  368. txbd1->tx_bd_hsize_lflags =
  369. cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM);
  370. txbd1->tx_bd_mss = 0;
  371. }
  372. length >>= 9;
  373. flags |= bnxt_lhint_arr[length];
  374. txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
  375. txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags);
  376. txbd1->tx_bd_cfa_action = cpu_to_le32(cfa_action);
  377. for (i = 0; i < last_frag; i++) {
  378. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  379. prod = NEXT_TX(prod);
  380. txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
  381. len = skb_frag_size(frag);
  382. mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
  383. DMA_TO_DEVICE);
  384. if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
  385. goto tx_dma_error;
  386. tx_buf = &txr->tx_buf_ring[prod];
  387. dma_unmap_addr_set(tx_buf, mapping, mapping);
  388. txbd->tx_bd_haddr = cpu_to_le64(mapping);
  389. flags = len << TX_BD_LEN_SHIFT;
  390. txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
  391. }
  392. flags &= ~TX_BD_LEN;
  393. txbd->tx_bd_len_flags_type =
  394. cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
  395. TX_BD_FLAGS_PACKET_END);
  396. netdev_tx_sent_queue(txq, skb->len);
  397. /* Sync BD data before updating doorbell */
  398. wmb();
  399. prod = NEXT_TX(prod);
  400. txr->tx_prod = prod;
  401. writel(DB_KEY_TX | prod, txr->tx_doorbell);
  402. writel(DB_KEY_TX | prod, txr->tx_doorbell);
  403. tx_done:
  404. mmiowb();
  405. if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) {
  406. netif_tx_stop_queue(txq);
  407. /* netif_tx_stop_queue() must be done before checking
  408. * tx index in bnxt_tx_avail() below, because in
  409. * bnxt_tx_int(), we update tx index before checking for
  410. * netif_tx_queue_stopped().
  411. */
  412. smp_mb();
  413. if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)
  414. netif_tx_wake_queue(txq);
  415. }
  416. return NETDEV_TX_OK;
  417. tx_dma_error:
  418. last_frag = i;
  419. /* start back at beginning and unmap skb */
  420. prod = txr->tx_prod;
  421. tx_buf = &txr->tx_buf_ring[prod];
  422. tx_buf->skb = NULL;
  423. dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
  424. skb_headlen(skb), PCI_DMA_TODEVICE);
  425. prod = NEXT_TX(prod);
  426. /* unmap remaining mapped pages */
  427. for (i = 0; i < last_frag; i++) {
  428. prod = NEXT_TX(prod);
  429. tx_buf = &txr->tx_buf_ring[prod];
  430. dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
  431. skb_frag_size(&skb_shinfo(skb)->frags[i]),
  432. PCI_DMA_TODEVICE);
  433. }
  434. dev_kfree_skb_any(skb);
  435. return NETDEV_TX_OK;
  436. }
  437. static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
  438. {
  439. struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
  440. struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
  441. u16 cons = txr->tx_cons;
  442. struct pci_dev *pdev = bp->pdev;
  443. int i;
  444. unsigned int tx_bytes = 0;
  445. for (i = 0; i < nr_pkts; i++) {
  446. struct bnxt_sw_tx_bd *tx_buf;
  447. struct sk_buff *skb;
  448. int j, last;
  449. tx_buf = &txr->tx_buf_ring[cons];
  450. cons = NEXT_TX(cons);
  451. skb = tx_buf->skb;
  452. tx_buf->skb = NULL;
  453. if (tx_buf->is_push) {
  454. tx_buf->is_push = 0;
  455. goto next_tx_int;
  456. }
  457. dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping),
  458. skb_headlen(skb), PCI_DMA_TODEVICE);
  459. last = tx_buf->nr_frags;
  460. for (j = 0; j < last; j++) {
  461. cons = NEXT_TX(cons);
  462. tx_buf = &txr->tx_buf_ring[cons];
  463. dma_unmap_page(
  464. &pdev->dev,
  465. dma_unmap_addr(tx_buf, mapping),
  466. skb_frag_size(&skb_shinfo(skb)->frags[j]),
  467. PCI_DMA_TODEVICE);
  468. }
  469. next_tx_int:
  470. cons = NEXT_TX(cons);
  471. tx_bytes += skb->len;
  472. dev_kfree_skb_any(skb);
  473. }
  474. netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);
  475. txr->tx_cons = cons;
  476. /* Need to make the tx_cons update visible to bnxt_start_xmit()
  477. * before checking for netif_tx_queue_stopped(). Without the
  478. * memory barrier, there is a small possibility that bnxt_start_xmit()
  479. * will miss it and cause the queue to be stopped forever.
  480. */
  481. smp_mb();
  482. if (unlikely(netif_tx_queue_stopped(txq)) &&
  483. (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) {
  484. __netif_tx_lock(txq, smp_processor_id());
  485. if (netif_tx_queue_stopped(txq) &&
  486. bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh &&
  487. txr->dev_state != BNXT_DEV_STATE_CLOSING)
  488. netif_tx_wake_queue(txq);
  489. __netif_tx_unlock(txq);
  490. }
  491. }
  492. static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
  493. gfp_t gfp)
  494. {
  495. struct device *dev = &bp->pdev->dev;
  496. struct page *page;
  497. page = alloc_page(gfp);
  498. if (!page)
  499. return NULL;
  500. *mapping = dma_map_page(dev, page, 0, PAGE_SIZE, bp->rx_dir);
  501. if (dma_mapping_error(dev, *mapping)) {
  502. __free_page(page);
  503. return NULL;
  504. }
  505. *mapping += bp->rx_dma_offset;
  506. return page;
  507. }
  508. static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping,
  509. gfp_t gfp)
  510. {
  511. u8 *data;
  512. struct pci_dev *pdev = bp->pdev;
  513. data = kmalloc(bp->rx_buf_size, gfp);
  514. if (!data)
  515. return NULL;
  516. *mapping = dma_map_single(&pdev->dev, data + bp->rx_dma_offset,
  517. bp->rx_buf_use_size, bp->rx_dir);
  518. if (dma_mapping_error(&pdev->dev, *mapping)) {
  519. kfree(data);
  520. data = NULL;
  521. }
  522. return data;
  523. }
  524. int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
  525. u16 prod, gfp_t gfp)
  526. {
  527. struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  528. struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
  529. dma_addr_t mapping;
  530. if (BNXT_RX_PAGE_MODE(bp)) {
  531. struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp);
  532. if (!page)
  533. return -ENOMEM;
  534. rx_buf->data = page;
  535. rx_buf->data_ptr = page_address(page) + bp->rx_offset;
  536. } else {
  537. u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp);
  538. if (!data)
  539. return -ENOMEM;
  540. rx_buf->data = data;
  541. rx_buf->data_ptr = data + bp->rx_offset;
  542. }
  543. rx_buf->mapping = mapping;
  544. rxbd->rx_bd_haddr = cpu_to_le64(mapping);
  545. return 0;
  546. }
  547. void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data)
  548. {
  549. u16 prod = rxr->rx_prod;
  550. struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
  551. struct rx_bd *cons_bd, *prod_bd;
  552. prod_rx_buf = &rxr->rx_buf_ring[prod];
  553. cons_rx_buf = &rxr->rx_buf_ring[cons];
  554. prod_rx_buf->data = data;
  555. prod_rx_buf->data_ptr = cons_rx_buf->data_ptr;
  556. prod_rx_buf->mapping = cons_rx_buf->mapping;
  557. prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  558. cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  559. prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr;
  560. }
  561. static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
  562. {
  563. u16 next, max = rxr->rx_agg_bmap_size;
  564. next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx);
  565. if (next >= max)
  566. next = find_first_zero_bit(rxr->rx_agg_bmap, max);
  567. return next;
  568. }
  569. static inline int bnxt_alloc_rx_page(struct bnxt *bp,
  570. struct bnxt_rx_ring_info *rxr,
  571. u16 prod, gfp_t gfp)
  572. {
  573. struct rx_bd *rxbd =
  574. &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  575. struct bnxt_sw_rx_agg_bd *rx_agg_buf;
  576. struct pci_dev *pdev = bp->pdev;
  577. struct page *page;
  578. dma_addr_t mapping;
  579. u16 sw_prod = rxr->rx_sw_agg_prod;
  580. unsigned int offset = 0;
  581. if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) {
  582. page = rxr->rx_page;
  583. if (!page) {
  584. page = alloc_page(gfp);
  585. if (!page)
  586. return -ENOMEM;
  587. rxr->rx_page = page;
  588. rxr->rx_page_offset = 0;
  589. }
  590. offset = rxr->rx_page_offset;
  591. rxr->rx_page_offset += BNXT_RX_PAGE_SIZE;
  592. if (rxr->rx_page_offset == PAGE_SIZE)
  593. rxr->rx_page = NULL;
  594. else
  595. get_page(page);
  596. } else {
  597. page = alloc_page(gfp);
  598. if (!page)
  599. return -ENOMEM;
  600. }
  601. mapping = dma_map_page(&pdev->dev, page, offset, BNXT_RX_PAGE_SIZE,
  602. PCI_DMA_FROMDEVICE);
  603. if (dma_mapping_error(&pdev->dev, mapping)) {
  604. __free_page(page);
  605. return -EIO;
  606. }
  607. if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
  608. sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
  609. __set_bit(sw_prod, rxr->rx_agg_bmap);
  610. rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
  611. rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod);
  612. rx_agg_buf->page = page;
  613. rx_agg_buf->offset = offset;
  614. rx_agg_buf->mapping = mapping;
  615. rxbd->rx_bd_haddr = cpu_to_le64(mapping);
  616. rxbd->rx_bd_opaque = sw_prod;
  617. return 0;
  618. }
  619. static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons,
  620. u32 agg_bufs)
  621. {
  622. struct bnxt *bp = bnapi->bp;
  623. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  624. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  625. u16 prod = rxr->rx_agg_prod;
  626. u16 sw_prod = rxr->rx_sw_agg_prod;
  627. u32 i;
  628. for (i = 0; i < agg_bufs; i++) {
  629. u16 cons;
  630. struct rx_agg_cmp *agg;
  631. struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
  632. struct rx_bd *prod_bd;
  633. struct page *page;
  634. agg = (struct rx_agg_cmp *)
  635. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  636. cons = agg->rx_agg_cmp_opaque;
  637. __clear_bit(cons, rxr->rx_agg_bmap);
  638. if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
  639. sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod);
  640. __set_bit(sw_prod, rxr->rx_agg_bmap);
  641. prod_rx_buf = &rxr->rx_agg_ring[sw_prod];
  642. cons_rx_buf = &rxr->rx_agg_ring[cons];
  643. /* It is possible for sw_prod to be equal to cons, so
  644. * set cons_rx_buf->page to NULL first.
  645. */
  646. page = cons_rx_buf->page;
  647. cons_rx_buf->page = NULL;
  648. prod_rx_buf->page = page;
  649. prod_rx_buf->offset = cons_rx_buf->offset;
  650. prod_rx_buf->mapping = cons_rx_buf->mapping;
  651. prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  652. prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping);
  653. prod_bd->rx_bd_opaque = sw_prod;
  654. prod = NEXT_RX_AGG(prod);
  655. sw_prod = NEXT_RX_AGG(sw_prod);
  656. cp_cons = NEXT_CMP(cp_cons);
  657. }
  658. rxr->rx_agg_prod = prod;
  659. rxr->rx_sw_agg_prod = sw_prod;
  660. }
  661. static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp,
  662. struct bnxt_rx_ring_info *rxr,
  663. u16 cons, void *data, u8 *data_ptr,
  664. dma_addr_t dma_addr,
  665. unsigned int offset_and_len)
  666. {
  667. unsigned int payload = offset_and_len >> 16;
  668. unsigned int len = offset_and_len & 0xffff;
  669. struct skb_frag_struct *frag;
  670. struct page *page = data;
  671. u16 prod = rxr->rx_prod;
  672. struct sk_buff *skb;
  673. int off, err;
  674. err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
  675. if (unlikely(err)) {
  676. bnxt_reuse_rx_data(rxr, cons, data);
  677. return NULL;
  678. }
  679. dma_addr -= bp->rx_dma_offset;
  680. dma_unmap_page(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir);
  681. if (unlikely(!payload))
  682. payload = eth_get_headlen(data_ptr, len);
  683. skb = napi_alloc_skb(&rxr->bnapi->napi, payload);
  684. if (!skb) {
  685. __free_page(page);
  686. return NULL;
  687. }
  688. off = (void *)data_ptr - page_address(page);
  689. skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE);
  690. memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN,
  691. payload + NET_IP_ALIGN);
  692. frag = &skb_shinfo(skb)->frags[0];
  693. skb_frag_size_sub(frag, payload);
  694. frag->page_offset += payload;
  695. skb->data_len -= payload;
  696. skb->tail += payload;
  697. return skb;
  698. }
  699. static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
  700. struct bnxt_rx_ring_info *rxr, u16 cons,
  701. void *data, u8 *data_ptr,
  702. dma_addr_t dma_addr,
  703. unsigned int offset_and_len)
  704. {
  705. u16 prod = rxr->rx_prod;
  706. struct sk_buff *skb;
  707. int err;
  708. err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC);
  709. if (unlikely(err)) {
  710. bnxt_reuse_rx_data(rxr, cons, data);
  711. return NULL;
  712. }
  713. skb = build_skb(data, 0);
  714. dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
  715. bp->rx_dir);
  716. if (!skb) {
  717. kfree(data);
  718. return NULL;
  719. }
  720. skb_reserve(skb, bp->rx_offset);
  721. skb_put(skb, offset_and_len & 0xffff);
  722. return skb;
  723. }
  724. static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi,
  725. struct sk_buff *skb, u16 cp_cons,
  726. u32 agg_bufs)
  727. {
  728. struct pci_dev *pdev = bp->pdev;
  729. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  730. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  731. u16 prod = rxr->rx_agg_prod;
  732. u32 i;
  733. for (i = 0; i < agg_bufs; i++) {
  734. u16 cons, frag_len;
  735. struct rx_agg_cmp *agg;
  736. struct bnxt_sw_rx_agg_bd *cons_rx_buf;
  737. struct page *page;
  738. dma_addr_t mapping;
  739. agg = (struct rx_agg_cmp *)
  740. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  741. cons = agg->rx_agg_cmp_opaque;
  742. frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
  743. RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
  744. cons_rx_buf = &rxr->rx_agg_ring[cons];
  745. skb_fill_page_desc(skb, i, cons_rx_buf->page,
  746. cons_rx_buf->offset, frag_len);
  747. __clear_bit(cons, rxr->rx_agg_bmap);
  748. /* It is possible for bnxt_alloc_rx_page() to allocate
  749. * a sw_prod index that equals the cons index, so we
  750. * need to clear the cons entry now.
  751. */
  752. mapping = cons_rx_buf->mapping;
  753. page = cons_rx_buf->page;
  754. cons_rx_buf->page = NULL;
  755. if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
  756. struct skb_shared_info *shinfo;
  757. unsigned int nr_frags;
  758. shinfo = skb_shinfo(skb);
  759. nr_frags = --shinfo->nr_frags;
  760. __skb_frag_set_page(&shinfo->frags[nr_frags], NULL);
  761. dev_kfree_skb(skb);
  762. cons_rx_buf->page = page;
  763. /* Update prod since possibly some pages have been
  764. * allocated already.
  765. */
  766. rxr->rx_agg_prod = prod;
  767. bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i);
  768. return NULL;
  769. }
  770. dma_unmap_page(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
  771. PCI_DMA_FROMDEVICE);
  772. skb->data_len += frag_len;
  773. skb->len += frag_len;
  774. skb->truesize += PAGE_SIZE;
  775. prod = NEXT_RX_AGG(prod);
  776. cp_cons = NEXT_CMP(cp_cons);
  777. }
  778. rxr->rx_agg_prod = prod;
  779. return skb;
  780. }
  781. static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
  782. u8 agg_bufs, u32 *raw_cons)
  783. {
  784. u16 last;
  785. struct rx_agg_cmp *agg;
  786. *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs);
  787. last = RING_CMP(*raw_cons);
  788. agg = (struct rx_agg_cmp *)
  789. &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)];
  790. return RX_AGG_CMP_VALID(agg, *raw_cons);
  791. }
  792. static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data,
  793. unsigned int len,
  794. dma_addr_t mapping)
  795. {
  796. struct bnxt *bp = bnapi->bp;
  797. struct pci_dev *pdev = bp->pdev;
  798. struct sk_buff *skb;
  799. skb = napi_alloc_skb(&bnapi->napi, len);
  800. if (!skb)
  801. return NULL;
  802. dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
  803. bp->rx_dir);
  804. memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
  805. len + NET_IP_ALIGN);
  806. dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
  807. bp->rx_dir);
  808. skb_put(skb, len);
  809. return skb;
  810. }
  811. static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi,
  812. u32 *raw_cons, void *cmp)
  813. {
  814. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  815. struct rx_cmp *rxcmp = cmp;
  816. u32 tmp_raw_cons = *raw_cons;
  817. u8 cmp_type, agg_bufs = 0;
  818. cmp_type = RX_CMP_TYPE(rxcmp);
  819. if (cmp_type == CMP_TYPE_RX_L2_CMP) {
  820. agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) &
  821. RX_CMP_AGG_BUFS) >>
  822. RX_CMP_AGG_BUFS_SHIFT;
  823. } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
  824. struct rx_tpa_end_cmp *tpa_end = cmp;
  825. agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
  826. RX_TPA_END_CMP_AGG_BUFS) >>
  827. RX_TPA_END_CMP_AGG_BUFS_SHIFT;
  828. }
  829. if (agg_bufs) {
  830. if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
  831. return -EBUSY;
  832. }
  833. *raw_cons = tmp_raw_cons;
  834. return 0;
  835. }
  836. static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
  837. {
  838. if (!rxr->bnapi->in_reset) {
  839. rxr->bnapi->in_reset = true;
  840. set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
  841. schedule_work(&bp->sp_task);
  842. }
  843. rxr->rx_next_cons = 0xffff;
  844. }
  845. static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr,
  846. struct rx_tpa_start_cmp *tpa_start,
  847. struct rx_tpa_start_cmp_ext *tpa_start1)
  848. {
  849. u8 agg_id = TPA_START_AGG_ID(tpa_start);
  850. u16 cons, prod;
  851. struct bnxt_tpa_info *tpa_info;
  852. struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf;
  853. struct rx_bd *prod_bd;
  854. dma_addr_t mapping;
  855. cons = tpa_start->rx_tpa_start_cmp_opaque;
  856. prod = rxr->rx_prod;
  857. cons_rx_buf = &rxr->rx_buf_ring[cons];
  858. prod_rx_buf = &rxr->rx_buf_ring[prod];
  859. tpa_info = &rxr->rx_tpa[agg_id];
  860. if (unlikely(cons != rxr->rx_next_cons)) {
  861. bnxt_sched_reset(bp, rxr);
  862. return;
  863. }
  864. prod_rx_buf->data = tpa_info->data;
  865. prod_rx_buf->data_ptr = tpa_info->data_ptr;
  866. mapping = tpa_info->mapping;
  867. prod_rx_buf->mapping = mapping;
  868. prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  869. prod_bd->rx_bd_haddr = cpu_to_le64(mapping);
  870. tpa_info->data = cons_rx_buf->data;
  871. tpa_info->data_ptr = cons_rx_buf->data_ptr;
  872. cons_rx_buf->data = NULL;
  873. tpa_info->mapping = cons_rx_buf->mapping;
  874. tpa_info->len =
  875. le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >>
  876. RX_TPA_START_CMP_LEN_SHIFT;
  877. if (likely(TPA_START_HASH_VALID(tpa_start))) {
  878. u32 hash_type = TPA_START_HASH_TYPE(tpa_start);
  879. tpa_info->hash_type = PKT_HASH_TYPE_L4;
  880. tpa_info->gso_type = SKB_GSO_TCPV4;
  881. /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
  882. if (hash_type == 3)
  883. tpa_info->gso_type = SKB_GSO_TCPV6;
  884. tpa_info->rss_hash =
  885. le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash);
  886. } else {
  887. tpa_info->hash_type = PKT_HASH_TYPE_NONE;
  888. tpa_info->gso_type = 0;
  889. if (netif_msg_rx_err(bp))
  890. netdev_warn(bp->dev, "TPA packet without valid hash\n");
  891. }
  892. tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2);
  893. tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata);
  894. tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info);
  895. rxr->rx_prod = NEXT_RX(prod);
  896. cons = NEXT_RX(cons);
  897. rxr->rx_next_cons = NEXT_RX(cons);
  898. cons_rx_buf = &rxr->rx_buf_ring[cons];
  899. bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data);
  900. rxr->rx_prod = NEXT_RX(rxr->rx_prod);
  901. cons_rx_buf->data = NULL;
  902. }
  903. static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi,
  904. u16 cp_cons, u32 agg_bufs)
  905. {
  906. if (agg_bufs)
  907. bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
  908. }
  909. static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info,
  910. int payload_off, int tcp_ts,
  911. struct sk_buff *skb)
  912. {
  913. #ifdef CONFIG_INET
  914. struct tcphdr *th;
  915. int len, nw_off;
  916. u16 outer_ip_off, inner_ip_off, inner_mac_off;
  917. u32 hdr_info = tpa_info->hdr_info;
  918. bool loopback = false;
  919. inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info);
  920. inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info);
  921. outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info);
  922. /* If the packet is an internal loopback packet, the offsets will
  923. * have an extra 4 bytes.
  924. */
  925. if (inner_mac_off == 4) {
  926. loopback = true;
  927. } else if (inner_mac_off > 4) {
  928. __be16 proto = *((__be16 *)(skb->data + inner_ip_off -
  929. ETH_HLEN - 2));
  930. /* We only support inner iPv4/ipv6. If we don't see the
  931. * correct protocol ID, it must be a loopback packet where
  932. * the offsets are off by 4.
  933. */
  934. if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6))
  935. loopback = true;
  936. }
  937. if (loopback) {
  938. /* internal loopback packet, subtract all offsets by 4 */
  939. inner_ip_off -= 4;
  940. inner_mac_off -= 4;
  941. outer_ip_off -= 4;
  942. }
  943. nw_off = inner_ip_off - ETH_HLEN;
  944. skb_set_network_header(skb, nw_off);
  945. if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) {
  946. struct ipv6hdr *iph = ipv6_hdr(skb);
  947. skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
  948. len = skb->len - skb_transport_offset(skb);
  949. th = tcp_hdr(skb);
  950. th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
  951. } else {
  952. struct iphdr *iph = ip_hdr(skb);
  953. skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
  954. len = skb->len - skb_transport_offset(skb);
  955. th = tcp_hdr(skb);
  956. th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
  957. }
  958. if (inner_mac_off) { /* tunnel */
  959. struct udphdr *uh = NULL;
  960. __be16 proto = *((__be16 *)(skb->data + outer_ip_off -
  961. ETH_HLEN - 2));
  962. if (proto == htons(ETH_P_IP)) {
  963. struct iphdr *iph = (struct iphdr *)skb->data;
  964. if (iph->protocol == IPPROTO_UDP)
  965. uh = (struct udphdr *)(iph + 1);
  966. } else {
  967. struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
  968. if (iph->nexthdr == IPPROTO_UDP)
  969. uh = (struct udphdr *)(iph + 1);
  970. }
  971. if (uh) {
  972. if (uh->check)
  973. skb_shinfo(skb)->gso_type |=
  974. SKB_GSO_UDP_TUNNEL_CSUM;
  975. else
  976. skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
  977. }
  978. }
  979. #endif
  980. return skb;
  981. }
  982. #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr))
  983. #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr))
  984. static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info,
  985. int payload_off, int tcp_ts,
  986. struct sk_buff *skb)
  987. {
  988. #ifdef CONFIG_INET
  989. struct tcphdr *th;
  990. int len, nw_off, tcp_opt_len = 0;
  991. if (tcp_ts)
  992. tcp_opt_len = 12;
  993. if (tpa_info->gso_type == SKB_GSO_TCPV4) {
  994. struct iphdr *iph;
  995. nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len -
  996. ETH_HLEN;
  997. skb_set_network_header(skb, nw_off);
  998. iph = ip_hdr(skb);
  999. skb_set_transport_header(skb, nw_off + sizeof(struct iphdr));
  1000. len = skb->len - skb_transport_offset(skb);
  1001. th = tcp_hdr(skb);
  1002. th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0);
  1003. } else if (tpa_info->gso_type == SKB_GSO_TCPV6) {
  1004. struct ipv6hdr *iph;
  1005. nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len -
  1006. ETH_HLEN;
  1007. skb_set_network_header(skb, nw_off);
  1008. iph = ipv6_hdr(skb);
  1009. skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr));
  1010. len = skb->len - skb_transport_offset(skb);
  1011. th = tcp_hdr(skb);
  1012. th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0);
  1013. } else {
  1014. dev_kfree_skb_any(skb);
  1015. return NULL;
  1016. }
  1017. if (nw_off) { /* tunnel */
  1018. struct udphdr *uh = NULL;
  1019. if (skb->protocol == htons(ETH_P_IP)) {
  1020. struct iphdr *iph = (struct iphdr *)skb->data;
  1021. if (iph->protocol == IPPROTO_UDP)
  1022. uh = (struct udphdr *)(iph + 1);
  1023. } else {
  1024. struct ipv6hdr *iph = (struct ipv6hdr *)skb->data;
  1025. if (iph->nexthdr == IPPROTO_UDP)
  1026. uh = (struct udphdr *)(iph + 1);
  1027. }
  1028. if (uh) {
  1029. if (uh->check)
  1030. skb_shinfo(skb)->gso_type |=
  1031. SKB_GSO_UDP_TUNNEL_CSUM;
  1032. else
  1033. skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
  1034. }
  1035. }
  1036. #endif
  1037. return skb;
  1038. }
  1039. static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp,
  1040. struct bnxt_tpa_info *tpa_info,
  1041. struct rx_tpa_end_cmp *tpa_end,
  1042. struct rx_tpa_end_cmp_ext *tpa_end1,
  1043. struct sk_buff *skb)
  1044. {
  1045. #ifdef CONFIG_INET
  1046. int payload_off;
  1047. u16 segs;
  1048. segs = TPA_END_TPA_SEGS(tpa_end);
  1049. if (segs == 1)
  1050. return skb;
  1051. NAPI_GRO_CB(skb)->count = segs;
  1052. skb_shinfo(skb)->gso_size =
  1053. le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len);
  1054. skb_shinfo(skb)->gso_type = tpa_info->gso_type;
  1055. payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
  1056. RX_TPA_END_CMP_PAYLOAD_OFFSET) >>
  1057. RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT;
  1058. skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb);
  1059. if (likely(skb))
  1060. tcp_gro_complete(skb);
  1061. #endif
  1062. return skb;
  1063. }
  1064. static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
  1065. struct bnxt_napi *bnapi,
  1066. u32 *raw_cons,
  1067. struct rx_tpa_end_cmp *tpa_end,
  1068. struct rx_tpa_end_cmp_ext *tpa_end1,
  1069. u8 *event)
  1070. {
  1071. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1072. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  1073. u8 agg_id = TPA_END_AGG_ID(tpa_end);
  1074. u8 *data_ptr, agg_bufs;
  1075. u16 cp_cons = RING_CMP(*raw_cons);
  1076. unsigned int len;
  1077. struct bnxt_tpa_info *tpa_info;
  1078. dma_addr_t mapping;
  1079. struct sk_buff *skb;
  1080. void *data;
  1081. if (unlikely(bnapi->in_reset)) {
  1082. int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end);
  1083. if (rc < 0)
  1084. return ERR_PTR(-EBUSY);
  1085. return NULL;
  1086. }
  1087. tpa_info = &rxr->rx_tpa[agg_id];
  1088. data = tpa_info->data;
  1089. data_ptr = tpa_info->data_ptr;
  1090. prefetch(data_ptr);
  1091. len = tpa_info->len;
  1092. mapping = tpa_info->mapping;
  1093. agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) &
  1094. RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT;
  1095. if (agg_bufs) {
  1096. if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons))
  1097. return ERR_PTR(-EBUSY);
  1098. *event |= BNXT_AGG_EVENT;
  1099. cp_cons = NEXT_CMP(cp_cons);
  1100. }
  1101. if (unlikely(agg_bufs > MAX_SKB_FRAGS)) {
  1102. bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
  1103. netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n",
  1104. agg_bufs, (int)MAX_SKB_FRAGS);
  1105. return NULL;
  1106. }
  1107. if (len <= bp->rx_copy_thresh) {
  1108. skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
  1109. if (!skb) {
  1110. bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
  1111. return NULL;
  1112. }
  1113. } else {
  1114. u8 *new_data;
  1115. dma_addr_t new_mapping;
  1116. new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC);
  1117. if (!new_data) {
  1118. bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
  1119. return NULL;
  1120. }
  1121. tpa_info->data = new_data;
  1122. tpa_info->data_ptr = new_data + bp->rx_offset;
  1123. tpa_info->mapping = new_mapping;
  1124. skb = build_skb(data, 0);
  1125. dma_unmap_single(&bp->pdev->dev, mapping, bp->rx_buf_use_size,
  1126. bp->rx_dir);
  1127. if (!skb) {
  1128. kfree(data);
  1129. bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs);
  1130. return NULL;
  1131. }
  1132. skb_reserve(skb, bp->rx_offset);
  1133. skb_put(skb, len);
  1134. }
  1135. if (agg_bufs) {
  1136. skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
  1137. if (!skb) {
  1138. /* Page reuse already handled by bnxt_rx_pages(). */
  1139. return NULL;
  1140. }
  1141. }
  1142. skb->protocol = eth_type_trans(skb, bp->dev);
  1143. if (tpa_info->hash_type != PKT_HASH_TYPE_NONE)
  1144. skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type);
  1145. if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) &&
  1146. (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
  1147. u16 vlan_proto = tpa_info->metadata >>
  1148. RX_CMP_FLAGS2_METADATA_TPID_SFT;
  1149. u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_VID_MASK;
  1150. __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
  1151. }
  1152. skb_checksum_none_assert(skb);
  1153. if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) {
  1154. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1155. skb->csum_level =
  1156. (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3;
  1157. }
  1158. if (TPA_END_GRO(tpa_end))
  1159. skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb);
  1160. return skb;
  1161. }
  1162. /* returns the following:
  1163. * 1 - 1 packet successfully received
  1164. * 0 - successful TPA_START, packet not completed yet
  1165. * -EBUSY - completion ring does not have all the agg buffers yet
  1166. * -ENOMEM - packet aborted due to out of memory
  1167. * -EIO - packet aborted due to hw error indicated in BD
  1168. */
  1169. static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons,
  1170. u8 *event)
  1171. {
  1172. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1173. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  1174. struct net_device *dev = bp->dev;
  1175. struct rx_cmp *rxcmp;
  1176. struct rx_cmp_ext *rxcmp1;
  1177. u32 tmp_raw_cons = *raw_cons;
  1178. u16 cons, prod, cp_cons = RING_CMP(tmp_raw_cons);
  1179. struct bnxt_sw_rx_bd *rx_buf;
  1180. unsigned int len;
  1181. u8 *data_ptr, agg_bufs, cmp_type;
  1182. dma_addr_t dma_addr;
  1183. struct sk_buff *skb;
  1184. void *data;
  1185. int rc = 0;
  1186. u32 misc;
  1187. rxcmp = (struct rx_cmp *)
  1188. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1189. tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
  1190. cp_cons = RING_CMP(tmp_raw_cons);
  1191. rxcmp1 = (struct rx_cmp_ext *)
  1192. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1193. if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
  1194. return -EBUSY;
  1195. cmp_type = RX_CMP_TYPE(rxcmp);
  1196. prod = rxr->rx_prod;
  1197. if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) {
  1198. bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp,
  1199. (struct rx_tpa_start_cmp_ext *)rxcmp1);
  1200. *event |= BNXT_RX_EVENT;
  1201. goto next_rx_no_prod;
  1202. } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) {
  1203. skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons,
  1204. (struct rx_tpa_end_cmp *)rxcmp,
  1205. (struct rx_tpa_end_cmp_ext *)rxcmp1, event);
  1206. if (unlikely(IS_ERR(skb)))
  1207. return -EBUSY;
  1208. rc = -ENOMEM;
  1209. if (likely(skb)) {
  1210. skb_record_rx_queue(skb, bnapi->index);
  1211. napi_gro_receive(&bnapi->napi, skb);
  1212. rc = 1;
  1213. }
  1214. *event |= BNXT_RX_EVENT;
  1215. goto next_rx_no_prod;
  1216. }
  1217. cons = rxcmp->rx_cmp_opaque;
  1218. rx_buf = &rxr->rx_buf_ring[cons];
  1219. data = rx_buf->data;
  1220. data_ptr = rx_buf->data_ptr;
  1221. if (unlikely(cons != rxr->rx_next_cons)) {
  1222. int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp);
  1223. bnxt_sched_reset(bp, rxr);
  1224. return rc1;
  1225. }
  1226. prefetch(data_ptr);
  1227. misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1);
  1228. agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT;
  1229. if (agg_bufs) {
  1230. if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons))
  1231. return -EBUSY;
  1232. cp_cons = NEXT_CMP(cp_cons);
  1233. *event |= BNXT_AGG_EVENT;
  1234. }
  1235. *event |= BNXT_RX_EVENT;
  1236. rx_buf->data = NULL;
  1237. if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) {
  1238. bnxt_reuse_rx_data(rxr, cons, data);
  1239. if (agg_bufs)
  1240. bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs);
  1241. rc = -EIO;
  1242. goto next_rx;
  1243. }
  1244. len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
  1245. dma_addr = rx_buf->mapping;
  1246. if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) {
  1247. rc = 1;
  1248. goto next_rx;
  1249. }
  1250. if (len <= bp->rx_copy_thresh) {
  1251. skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
  1252. bnxt_reuse_rx_data(rxr, cons, data);
  1253. if (!skb) {
  1254. rc = -ENOMEM;
  1255. goto next_rx;
  1256. }
  1257. } else {
  1258. u32 payload;
  1259. if (rx_buf->data_ptr == data_ptr)
  1260. payload = misc & RX_CMP_PAYLOAD_OFFSET;
  1261. else
  1262. payload = 0;
  1263. skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr,
  1264. payload | len);
  1265. if (!skb) {
  1266. rc = -ENOMEM;
  1267. goto next_rx;
  1268. }
  1269. }
  1270. if (agg_bufs) {
  1271. skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs);
  1272. if (!skb) {
  1273. rc = -ENOMEM;
  1274. goto next_rx;
  1275. }
  1276. }
  1277. if (RX_CMP_HASH_VALID(rxcmp)) {
  1278. u32 hash_type = RX_CMP_HASH_TYPE(rxcmp);
  1279. enum pkt_hash_types type = PKT_HASH_TYPE_L4;
  1280. /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */
  1281. if (hash_type != 1 && hash_type != 3)
  1282. type = PKT_HASH_TYPE_L3;
  1283. skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type);
  1284. }
  1285. skb->protocol = eth_type_trans(skb, dev);
  1286. if ((rxcmp1->rx_cmp_flags2 &
  1287. cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) &&
  1288. (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) {
  1289. u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data);
  1290. u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_VID_MASK;
  1291. u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT;
  1292. __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag);
  1293. }
  1294. skb_checksum_none_assert(skb);
  1295. if (RX_CMP_L4_CS_OK(rxcmp1)) {
  1296. if (dev->features & NETIF_F_RXCSUM) {
  1297. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1298. skb->csum_level = RX_CMP_ENCAP(rxcmp1);
  1299. }
  1300. } else {
  1301. if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) {
  1302. if (dev->features & NETIF_F_RXCSUM)
  1303. cpr->rx_l4_csum_errors++;
  1304. }
  1305. }
  1306. skb_record_rx_queue(skb, bnapi->index);
  1307. napi_gro_receive(&bnapi->napi, skb);
  1308. rc = 1;
  1309. next_rx:
  1310. rxr->rx_prod = NEXT_RX(prod);
  1311. rxr->rx_next_cons = NEXT_RX(cons);
  1312. next_rx_no_prod:
  1313. *raw_cons = tmp_raw_cons;
  1314. return rc;
  1315. }
  1316. #define BNXT_GET_EVENT_PORT(data) \
  1317. ((data) & \
  1318. ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK)
  1319. static int bnxt_async_event_process(struct bnxt *bp,
  1320. struct hwrm_async_event_cmpl *cmpl)
  1321. {
  1322. u16 event_id = le16_to_cpu(cmpl->event_id);
  1323. /* TODO CHIMP_FW: Define event id's for link change, error etc */
  1324. switch (event_id) {
  1325. case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: {
  1326. u32 data1 = le32_to_cpu(cmpl->event_data1);
  1327. struct bnxt_link_info *link_info = &bp->link_info;
  1328. if (BNXT_VF(bp))
  1329. goto async_event_process_exit;
  1330. if (data1 & 0x20000) {
  1331. u16 fw_speed = link_info->force_link_speed;
  1332. u32 speed = bnxt_fw_to_ethtool_speed(fw_speed);
  1333. netdev_warn(bp->dev, "Link speed %d no longer supported\n",
  1334. speed);
  1335. }
  1336. set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event);
  1337. /* fall thru */
  1338. }
  1339. case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE:
  1340. set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event);
  1341. break;
  1342. case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD:
  1343. set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event);
  1344. break;
  1345. case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: {
  1346. u32 data1 = le32_to_cpu(cmpl->event_data1);
  1347. u16 port_id = BNXT_GET_EVENT_PORT(data1);
  1348. if (BNXT_VF(bp))
  1349. break;
  1350. if (bp->pf.port_id != port_id)
  1351. break;
  1352. set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event);
  1353. break;
  1354. }
  1355. case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE:
  1356. if (BNXT_PF(bp))
  1357. goto async_event_process_exit;
  1358. set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event);
  1359. break;
  1360. default:
  1361. goto async_event_process_exit;
  1362. }
  1363. schedule_work(&bp->sp_task);
  1364. async_event_process_exit:
  1365. bnxt_ulp_async_events(bp, cmpl);
  1366. return 0;
  1367. }
  1368. static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp)
  1369. {
  1370. u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id;
  1371. struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp;
  1372. struct hwrm_fwd_req_cmpl *fwd_req_cmpl =
  1373. (struct hwrm_fwd_req_cmpl *)txcmp;
  1374. switch (cmpl_type) {
  1375. case CMPL_BASE_TYPE_HWRM_DONE:
  1376. seq_id = le16_to_cpu(h_cmpl->sequence_id);
  1377. if (seq_id == bp->hwrm_intr_seq_id)
  1378. bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID;
  1379. else
  1380. netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id);
  1381. break;
  1382. case CMPL_BASE_TYPE_HWRM_FWD_REQ:
  1383. vf_id = le16_to_cpu(fwd_req_cmpl->source_id);
  1384. if ((vf_id < bp->pf.first_vf_id) ||
  1385. (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) {
  1386. netdev_err(bp->dev, "Msg contains invalid VF id %x\n",
  1387. vf_id);
  1388. return -EINVAL;
  1389. }
  1390. set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap);
  1391. set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event);
  1392. schedule_work(&bp->sp_task);
  1393. break;
  1394. case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT:
  1395. bnxt_async_event_process(bp,
  1396. (struct hwrm_async_event_cmpl *)txcmp);
  1397. default:
  1398. break;
  1399. }
  1400. return 0;
  1401. }
  1402. static irqreturn_t bnxt_msix(int irq, void *dev_instance)
  1403. {
  1404. struct bnxt_napi *bnapi = dev_instance;
  1405. struct bnxt *bp = bnapi->bp;
  1406. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1407. u32 cons = RING_CMP(cpr->cp_raw_cons);
  1408. prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
  1409. napi_schedule(&bnapi->napi);
  1410. return IRQ_HANDLED;
  1411. }
  1412. static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
  1413. {
  1414. u32 raw_cons = cpr->cp_raw_cons;
  1415. u16 cons = RING_CMP(raw_cons);
  1416. struct tx_cmp *txcmp;
  1417. txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
  1418. return TX_CMP_VALID(txcmp, raw_cons);
  1419. }
  1420. static irqreturn_t bnxt_inta(int irq, void *dev_instance)
  1421. {
  1422. struct bnxt_napi *bnapi = dev_instance;
  1423. struct bnxt *bp = bnapi->bp;
  1424. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1425. u32 cons = RING_CMP(cpr->cp_raw_cons);
  1426. u32 int_status;
  1427. prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]);
  1428. if (!bnxt_has_work(bp, cpr)) {
  1429. int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS);
  1430. /* return if erroneous interrupt */
  1431. if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id)))
  1432. return IRQ_NONE;
  1433. }
  1434. /* disable ring IRQ */
  1435. BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell);
  1436. /* Return here if interrupt is shared and is disabled. */
  1437. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1438. return IRQ_HANDLED;
  1439. napi_schedule(&bnapi->napi);
  1440. return IRQ_HANDLED;
  1441. }
  1442. static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
  1443. {
  1444. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1445. u32 raw_cons = cpr->cp_raw_cons;
  1446. u32 cons;
  1447. int tx_pkts = 0;
  1448. int rx_pkts = 0;
  1449. u8 event = 0;
  1450. struct tx_cmp *txcmp;
  1451. while (1) {
  1452. int rc;
  1453. cons = RING_CMP(raw_cons);
  1454. txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
  1455. if (!TX_CMP_VALID(txcmp, raw_cons))
  1456. break;
  1457. /* The valid test of the entry must be done first before
  1458. * reading any further.
  1459. */
  1460. dma_rmb();
  1461. if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) {
  1462. tx_pkts++;
  1463. /* return full budget so NAPI will complete. */
  1464. if (unlikely(tx_pkts > bp->tx_wake_thresh))
  1465. rx_pkts = budget;
  1466. } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
  1467. rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
  1468. if (likely(rc >= 0))
  1469. rx_pkts += rc;
  1470. else if (rc == -EBUSY) /* partial completion */
  1471. break;
  1472. } else if (unlikely((TX_CMP_TYPE(txcmp) ==
  1473. CMPL_BASE_TYPE_HWRM_DONE) ||
  1474. (TX_CMP_TYPE(txcmp) ==
  1475. CMPL_BASE_TYPE_HWRM_FWD_REQ) ||
  1476. (TX_CMP_TYPE(txcmp) ==
  1477. CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) {
  1478. bnxt_hwrm_handler(bp, txcmp);
  1479. }
  1480. raw_cons = NEXT_RAW_CMP(raw_cons);
  1481. if (rx_pkts == budget)
  1482. break;
  1483. }
  1484. if (event & BNXT_TX_EVENT) {
  1485. struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
  1486. void __iomem *db = txr->tx_doorbell;
  1487. u16 prod = txr->tx_prod;
  1488. /* Sync BD data before updating doorbell */
  1489. wmb();
  1490. writel(DB_KEY_TX | prod, db);
  1491. writel(DB_KEY_TX | prod, db);
  1492. }
  1493. cpr->cp_raw_cons = raw_cons;
  1494. /* ACK completion ring before freeing tx ring and producing new
  1495. * buffers in rx/agg rings to prevent overflowing the completion
  1496. * ring.
  1497. */
  1498. BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
  1499. if (tx_pkts)
  1500. bnapi->tx_int(bp, bnapi, tx_pkts);
  1501. if (event & BNXT_RX_EVENT) {
  1502. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  1503. writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
  1504. writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
  1505. if (event & BNXT_AGG_EVENT) {
  1506. writel(DB_KEY_RX | rxr->rx_agg_prod,
  1507. rxr->rx_agg_doorbell);
  1508. writel(DB_KEY_RX | rxr->rx_agg_prod,
  1509. rxr->rx_agg_doorbell);
  1510. }
  1511. }
  1512. return rx_pkts;
  1513. }
  1514. static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget)
  1515. {
  1516. struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
  1517. struct bnxt *bp = bnapi->bp;
  1518. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1519. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  1520. struct tx_cmp *txcmp;
  1521. struct rx_cmp_ext *rxcmp1;
  1522. u32 cp_cons, tmp_raw_cons;
  1523. u32 raw_cons = cpr->cp_raw_cons;
  1524. u32 rx_pkts = 0;
  1525. u8 event = 0;
  1526. while (1) {
  1527. int rc;
  1528. cp_cons = RING_CMP(raw_cons);
  1529. txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1530. if (!TX_CMP_VALID(txcmp, raw_cons))
  1531. break;
  1532. if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) {
  1533. tmp_raw_cons = NEXT_RAW_CMP(raw_cons);
  1534. cp_cons = RING_CMP(tmp_raw_cons);
  1535. rxcmp1 = (struct rx_cmp_ext *)
  1536. &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
  1537. if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons))
  1538. break;
  1539. /* force an error to recycle the buffer */
  1540. rxcmp1->rx_cmp_cfa_code_errors_v2 |=
  1541. cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR);
  1542. rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event);
  1543. if (likely(rc == -EIO))
  1544. rx_pkts++;
  1545. else if (rc == -EBUSY) /* partial completion */
  1546. break;
  1547. } else if (unlikely(TX_CMP_TYPE(txcmp) ==
  1548. CMPL_BASE_TYPE_HWRM_DONE)) {
  1549. bnxt_hwrm_handler(bp, txcmp);
  1550. } else {
  1551. netdev_err(bp->dev,
  1552. "Invalid completion received on special ring\n");
  1553. }
  1554. raw_cons = NEXT_RAW_CMP(raw_cons);
  1555. if (rx_pkts == budget)
  1556. break;
  1557. }
  1558. cpr->cp_raw_cons = raw_cons;
  1559. BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
  1560. writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
  1561. writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
  1562. if (event & BNXT_AGG_EVENT) {
  1563. writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell);
  1564. writel(DB_KEY_RX | rxr->rx_agg_prod, rxr->rx_agg_doorbell);
  1565. }
  1566. if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) {
  1567. napi_complete_done(napi, rx_pkts);
  1568. BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
  1569. }
  1570. return rx_pkts;
  1571. }
  1572. static int bnxt_poll(struct napi_struct *napi, int budget)
  1573. {
  1574. struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi);
  1575. struct bnxt *bp = bnapi->bp;
  1576. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  1577. int work_done = 0;
  1578. while (1) {
  1579. work_done += bnxt_poll_work(bp, bnapi, budget - work_done);
  1580. if (work_done >= budget)
  1581. break;
  1582. if (!bnxt_has_work(bp, cpr)) {
  1583. if (napi_complete_done(napi, work_done))
  1584. BNXT_CP_DB_REARM(cpr->cp_doorbell,
  1585. cpr->cp_raw_cons);
  1586. break;
  1587. }
  1588. }
  1589. mmiowb();
  1590. return work_done;
  1591. }
  1592. static void bnxt_free_tx_skbs(struct bnxt *bp)
  1593. {
  1594. int i, max_idx;
  1595. struct pci_dev *pdev = bp->pdev;
  1596. if (!bp->tx_ring)
  1597. return;
  1598. max_idx = bp->tx_nr_pages * TX_DESC_CNT;
  1599. for (i = 0; i < bp->tx_nr_rings; i++) {
  1600. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  1601. int j;
  1602. for (j = 0; j < max_idx;) {
  1603. struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j];
  1604. struct sk_buff *skb = tx_buf->skb;
  1605. int k, last;
  1606. if (!skb) {
  1607. j++;
  1608. continue;
  1609. }
  1610. tx_buf->skb = NULL;
  1611. if (tx_buf->is_push) {
  1612. dev_kfree_skb(skb);
  1613. j += 2;
  1614. continue;
  1615. }
  1616. dma_unmap_single(&pdev->dev,
  1617. dma_unmap_addr(tx_buf, mapping),
  1618. skb_headlen(skb),
  1619. PCI_DMA_TODEVICE);
  1620. last = tx_buf->nr_frags;
  1621. j += 2;
  1622. for (k = 0; k < last; k++, j++) {
  1623. int ring_idx = j & bp->tx_ring_mask;
  1624. skb_frag_t *frag = &skb_shinfo(skb)->frags[k];
  1625. tx_buf = &txr->tx_buf_ring[ring_idx];
  1626. dma_unmap_page(
  1627. &pdev->dev,
  1628. dma_unmap_addr(tx_buf, mapping),
  1629. skb_frag_size(frag), PCI_DMA_TODEVICE);
  1630. }
  1631. dev_kfree_skb(skb);
  1632. }
  1633. netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i));
  1634. }
  1635. }
  1636. static void bnxt_free_rx_skbs(struct bnxt *bp)
  1637. {
  1638. int i, max_idx, max_agg_idx;
  1639. struct pci_dev *pdev = bp->pdev;
  1640. if (!bp->rx_ring)
  1641. return;
  1642. max_idx = bp->rx_nr_pages * RX_DESC_CNT;
  1643. max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT;
  1644. for (i = 0; i < bp->rx_nr_rings; i++) {
  1645. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  1646. int j;
  1647. if (rxr->rx_tpa) {
  1648. for (j = 0; j < MAX_TPA; j++) {
  1649. struct bnxt_tpa_info *tpa_info =
  1650. &rxr->rx_tpa[j];
  1651. u8 *data = tpa_info->data;
  1652. if (!data)
  1653. continue;
  1654. dma_unmap_single(&pdev->dev, tpa_info->mapping,
  1655. bp->rx_buf_use_size,
  1656. bp->rx_dir);
  1657. tpa_info->data = NULL;
  1658. kfree(data);
  1659. }
  1660. }
  1661. for (j = 0; j < max_idx; j++) {
  1662. struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j];
  1663. dma_addr_t mapping = rx_buf->mapping;
  1664. void *data = rx_buf->data;
  1665. if (!data)
  1666. continue;
  1667. rx_buf->data = NULL;
  1668. if (BNXT_RX_PAGE_MODE(bp)) {
  1669. mapping -= bp->rx_dma_offset;
  1670. dma_unmap_page(&pdev->dev, mapping,
  1671. PAGE_SIZE, bp->rx_dir);
  1672. __free_page(data);
  1673. } else {
  1674. dma_unmap_single(&pdev->dev, mapping,
  1675. bp->rx_buf_use_size,
  1676. bp->rx_dir);
  1677. kfree(data);
  1678. }
  1679. }
  1680. for (j = 0; j < max_agg_idx; j++) {
  1681. struct bnxt_sw_rx_agg_bd *rx_agg_buf =
  1682. &rxr->rx_agg_ring[j];
  1683. struct page *page = rx_agg_buf->page;
  1684. if (!page)
  1685. continue;
  1686. dma_unmap_page(&pdev->dev, rx_agg_buf->mapping,
  1687. BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE);
  1688. rx_agg_buf->page = NULL;
  1689. __clear_bit(j, rxr->rx_agg_bmap);
  1690. __free_page(page);
  1691. }
  1692. if (rxr->rx_page) {
  1693. __free_page(rxr->rx_page);
  1694. rxr->rx_page = NULL;
  1695. }
  1696. }
  1697. }
  1698. static void bnxt_free_skbs(struct bnxt *bp)
  1699. {
  1700. bnxt_free_tx_skbs(bp);
  1701. bnxt_free_rx_skbs(bp);
  1702. }
  1703. static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
  1704. {
  1705. struct pci_dev *pdev = bp->pdev;
  1706. int i;
  1707. for (i = 0; i < ring->nr_pages; i++) {
  1708. if (!ring->pg_arr[i])
  1709. continue;
  1710. dma_free_coherent(&pdev->dev, ring->page_size,
  1711. ring->pg_arr[i], ring->dma_arr[i]);
  1712. ring->pg_arr[i] = NULL;
  1713. }
  1714. if (ring->pg_tbl) {
  1715. dma_free_coherent(&pdev->dev, ring->nr_pages * 8,
  1716. ring->pg_tbl, ring->pg_tbl_map);
  1717. ring->pg_tbl = NULL;
  1718. }
  1719. if (ring->vmem_size && *ring->vmem) {
  1720. vfree(*ring->vmem);
  1721. *ring->vmem = NULL;
  1722. }
  1723. }
  1724. static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring)
  1725. {
  1726. int i;
  1727. struct pci_dev *pdev = bp->pdev;
  1728. if (ring->nr_pages > 1) {
  1729. ring->pg_tbl = dma_alloc_coherent(&pdev->dev,
  1730. ring->nr_pages * 8,
  1731. &ring->pg_tbl_map,
  1732. GFP_KERNEL);
  1733. if (!ring->pg_tbl)
  1734. return -ENOMEM;
  1735. }
  1736. for (i = 0; i < ring->nr_pages; i++) {
  1737. ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
  1738. ring->page_size,
  1739. &ring->dma_arr[i],
  1740. GFP_KERNEL);
  1741. if (!ring->pg_arr[i])
  1742. return -ENOMEM;
  1743. if (ring->nr_pages > 1)
  1744. ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]);
  1745. }
  1746. if (ring->vmem_size) {
  1747. *ring->vmem = vzalloc(ring->vmem_size);
  1748. if (!(*ring->vmem))
  1749. return -ENOMEM;
  1750. }
  1751. return 0;
  1752. }
  1753. static void bnxt_free_rx_rings(struct bnxt *bp)
  1754. {
  1755. int i;
  1756. if (!bp->rx_ring)
  1757. return;
  1758. for (i = 0; i < bp->rx_nr_rings; i++) {
  1759. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  1760. struct bnxt_ring_struct *ring;
  1761. if (rxr->xdp_prog)
  1762. bpf_prog_put(rxr->xdp_prog);
  1763. kfree(rxr->rx_tpa);
  1764. rxr->rx_tpa = NULL;
  1765. kfree(rxr->rx_agg_bmap);
  1766. rxr->rx_agg_bmap = NULL;
  1767. ring = &rxr->rx_ring_struct;
  1768. bnxt_free_ring(bp, ring);
  1769. ring = &rxr->rx_agg_ring_struct;
  1770. bnxt_free_ring(bp, ring);
  1771. }
  1772. }
  1773. static int bnxt_alloc_rx_rings(struct bnxt *bp)
  1774. {
  1775. int i, rc, agg_rings = 0, tpa_rings = 0;
  1776. if (!bp->rx_ring)
  1777. return -ENOMEM;
  1778. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  1779. agg_rings = 1;
  1780. if (bp->flags & BNXT_FLAG_TPA)
  1781. tpa_rings = 1;
  1782. for (i = 0; i < bp->rx_nr_rings; i++) {
  1783. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  1784. struct bnxt_ring_struct *ring;
  1785. ring = &rxr->rx_ring_struct;
  1786. rc = bnxt_alloc_ring(bp, ring);
  1787. if (rc)
  1788. return rc;
  1789. if (agg_rings) {
  1790. u16 mem_size;
  1791. ring = &rxr->rx_agg_ring_struct;
  1792. rc = bnxt_alloc_ring(bp, ring);
  1793. if (rc)
  1794. return rc;
  1795. rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1;
  1796. mem_size = rxr->rx_agg_bmap_size / 8;
  1797. rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL);
  1798. if (!rxr->rx_agg_bmap)
  1799. return -ENOMEM;
  1800. if (tpa_rings) {
  1801. rxr->rx_tpa = kcalloc(MAX_TPA,
  1802. sizeof(struct bnxt_tpa_info),
  1803. GFP_KERNEL);
  1804. if (!rxr->rx_tpa)
  1805. return -ENOMEM;
  1806. }
  1807. }
  1808. }
  1809. return 0;
  1810. }
  1811. static void bnxt_free_tx_rings(struct bnxt *bp)
  1812. {
  1813. int i;
  1814. struct pci_dev *pdev = bp->pdev;
  1815. if (!bp->tx_ring)
  1816. return;
  1817. for (i = 0; i < bp->tx_nr_rings; i++) {
  1818. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  1819. struct bnxt_ring_struct *ring;
  1820. if (txr->tx_push) {
  1821. dma_free_coherent(&pdev->dev, bp->tx_push_size,
  1822. txr->tx_push, txr->tx_push_mapping);
  1823. txr->tx_push = NULL;
  1824. }
  1825. ring = &txr->tx_ring_struct;
  1826. bnxt_free_ring(bp, ring);
  1827. }
  1828. }
  1829. static int bnxt_alloc_tx_rings(struct bnxt *bp)
  1830. {
  1831. int i, j, rc;
  1832. struct pci_dev *pdev = bp->pdev;
  1833. bp->tx_push_size = 0;
  1834. if (bp->tx_push_thresh) {
  1835. int push_size;
  1836. push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) +
  1837. bp->tx_push_thresh);
  1838. if (push_size > 256) {
  1839. push_size = 0;
  1840. bp->tx_push_thresh = 0;
  1841. }
  1842. bp->tx_push_size = push_size;
  1843. }
  1844. for (i = 0, j = 0; i < bp->tx_nr_rings; i++) {
  1845. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  1846. struct bnxt_ring_struct *ring;
  1847. ring = &txr->tx_ring_struct;
  1848. rc = bnxt_alloc_ring(bp, ring);
  1849. if (rc)
  1850. return rc;
  1851. if (bp->tx_push_size) {
  1852. dma_addr_t mapping;
  1853. /* One pre-allocated DMA buffer to backup
  1854. * TX push operation
  1855. */
  1856. txr->tx_push = dma_alloc_coherent(&pdev->dev,
  1857. bp->tx_push_size,
  1858. &txr->tx_push_mapping,
  1859. GFP_KERNEL);
  1860. if (!txr->tx_push)
  1861. return -ENOMEM;
  1862. mapping = txr->tx_push_mapping +
  1863. sizeof(struct tx_push_bd);
  1864. txr->data_mapping = cpu_to_le64(mapping);
  1865. memset(txr->tx_push, 0, sizeof(struct tx_push_bd));
  1866. }
  1867. ring->queue_id = bp->q_info[j].queue_id;
  1868. if (i < bp->tx_nr_rings_xdp)
  1869. continue;
  1870. if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1))
  1871. j++;
  1872. }
  1873. return 0;
  1874. }
  1875. static void bnxt_free_cp_rings(struct bnxt *bp)
  1876. {
  1877. int i;
  1878. if (!bp->bnapi)
  1879. return;
  1880. for (i = 0; i < bp->cp_nr_rings; i++) {
  1881. struct bnxt_napi *bnapi = bp->bnapi[i];
  1882. struct bnxt_cp_ring_info *cpr;
  1883. struct bnxt_ring_struct *ring;
  1884. if (!bnapi)
  1885. continue;
  1886. cpr = &bnapi->cp_ring;
  1887. ring = &cpr->cp_ring_struct;
  1888. bnxt_free_ring(bp, ring);
  1889. }
  1890. }
  1891. static int bnxt_alloc_cp_rings(struct bnxt *bp)
  1892. {
  1893. int i, rc;
  1894. for (i = 0; i < bp->cp_nr_rings; i++) {
  1895. struct bnxt_napi *bnapi = bp->bnapi[i];
  1896. struct bnxt_cp_ring_info *cpr;
  1897. struct bnxt_ring_struct *ring;
  1898. if (!bnapi)
  1899. continue;
  1900. cpr = &bnapi->cp_ring;
  1901. ring = &cpr->cp_ring_struct;
  1902. rc = bnxt_alloc_ring(bp, ring);
  1903. if (rc)
  1904. return rc;
  1905. }
  1906. return 0;
  1907. }
  1908. static void bnxt_init_ring_struct(struct bnxt *bp)
  1909. {
  1910. int i;
  1911. for (i = 0; i < bp->cp_nr_rings; i++) {
  1912. struct bnxt_napi *bnapi = bp->bnapi[i];
  1913. struct bnxt_cp_ring_info *cpr;
  1914. struct bnxt_rx_ring_info *rxr;
  1915. struct bnxt_tx_ring_info *txr;
  1916. struct bnxt_ring_struct *ring;
  1917. if (!bnapi)
  1918. continue;
  1919. cpr = &bnapi->cp_ring;
  1920. ring = &cpr->cp_ring_struct;
  1921. ring->nr_pages = bp->cp_nr_pages;
  1922. ring->page_size = HW_CMPD_RING_SIZE;
  1923. ring->pg_arr = (void **)cpr->cp_desc_ring;
  1924. ring->dma_arr = cpr->cp_desc_mapping;
  1925. ring->vmem_size = 0;
  1926. rxr = bnapi->rx_ring;
  1927. if (!rxr)
  1928. goto skip_rx;
  1929. ring = &rxr->rx_ring_struct;
  1930. ring->nr_pages = bp->rx_nr_pages;
  1931. ring->page_size = HW_RXBD_RING_SIZE;
  1932. ring->pg_arr = (void **)rxr->rx_desc_ring;
  1933. ring->dma_arr = rxr->rx_desc_mapping;
  1934. ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages;
  1935. ring->vmem = (void **)&rxr->rx_buf_ring;
  1936. ring = &rxr->rx_agg_ring_struct;
  1937. ring->nr_pages = bp->rx_agg_nr_pages;
  1938. ring->page_size = HW_RXBD_RING_SIZE;
  1939. ring->pg_arr = (void **)rxr->rx_agg_desc_ring;
  1940. ring->dma_arr = rxr->rx_agg_desc_mapping;
  1941. ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages;
  1942. ring->vmem = (void **)&rxr->rx_agg_ring;
  1943. skip_rx:
  1944. txr = bnapi->tx_ring;
  1945. if (!txr)
  1946. continue;
  1947. ring = &txr->tx_ring_struct;
  1948. ring->nr_pages = bp->tx_nr_pages;
  1949. ring->page_size = HW_RXBD_RING_SIZE;
  1950. ring->pg_arr = (void **)txr->tx_desc_ring;
  1951. ring->dma_arr = txr->tx_desc_mapping;
  1952. ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages;
  1953. ring->vmem = (void **)&txr->tx_buf_ring;
  1954. }
  1955. }
  1956. static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type)
  1957. {
  1958. int i;
  1959. u32 prod;
  1960. struct rx_bd **rx_buf_ring;
  1961. rx_buf_ring = (struct rx_bd **)ring->pg_arr;
  1962. for (i = 0, prod = 0; i < ring->nr_pages; i++) {
  1963. int j;
  1964. struct rx_bd *rxbd;
  1965. rxbd = rx_buf_ring[i];
  1966. if (!rxbd)
  1967. continue;
  1968. for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) {
  1969. rxbd->rx_bd_len_flags_type = cpu_to_le32(type);
  1970. rxbd->rx_bd_opaque = prod;
  1971. }
  1972. }
  1973. }
  1974. static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
  1975. {
  1976. struct net_device *dev = bp->dev;
  1977. struct bnxt_rx_ring_info *rxr;
  1978. struct bnxt_ring_struct *ring;
  1979. u32 prod, type;
  1980. int i;
  1981. type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) |
  1982. RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP;
  1983. if (NET_IP_ALIGN == 2)
  1984. type |= RX_BD_FLAGS_SOP;
  1985. rxr = &bp->rx_ring[ring_nr];
  1986. ring = &rxr->rx_ring_struct;
  1987. bnxt_init_rxbd_pages(ring, type);
  1988. if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) {
  1989. rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1);
  1990. if (IS_ERR(rxr->xdp_prog)) {
  1991. int rc = PTR_ERR(rxr->xdp_prog);
  1992. rxr->xdp_prog = NULL;
  1993. return rc;
  1994. }
  1995. }
  1996. prod = rxr->rx_prod;
  1997. for (i = 0; i < bp->rx_ring_size; i++) {
  1998. if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) {
  1999. netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n",
  2000. ring_nr, i, bp->rx_ring_size);
  2001. break;
  2002. }
  2003. prod = NEXT_RX(prod);
  2004. }
  2005. rxr->rx_prod = prod;
  2006. ring->fw_ring_id = INVALID_HW_RING_ID;
  2007. ring = &rxr->rx_agg_ring_struct;
  2008. ring->fw_ring_id = INVALID_HW_RING_ID;
  2009. if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
  2010. return 0;
  2011. type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) |
  2012. RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
  2013. bnxt_init_rxbd_pages(ring, type);
  2014. prod = rxr->rx_agg_prod;
  2015. for (i = 0; i < bp->rx_agg_ring_size; i++) {
  2016. if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) {
  2017. netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n",
  2018. ring_nr, i, bp->rx_ring_size);
  2019. break;
  2020. }
  2021. prod = NEXT_RX_AGG(prod);
  2022. }
  2023. rxr->rx_agg_prod = prod;
  2024. if (bp->flags & BNXT_FLAG_TPA) {
  2025. if (rxr->rx_tpa) {
  2026. u8 *data;
  2027. dma_addr_t mapping;
  2028. for (i = 0; i < MAX_TPA; i++) {
  2029. data = __bnxt_alloc_rx_data(bp, &mapping,
  2030. GFP_KERNEL);
  2031. if (!data)
  2032. return -ENOMEM;
  2033. rxr->rx_tpa[i].data = data;
  2034. rxr->rx_tpa[i].data_ptr = data + bp->rx_offset;
  2035. rxr->rx_tpa[i].mapping = mapping;
  2036. }
  2037. } else {
  2038. netdev_err(bp->dev, "No resource allocated for LRO/GRO\n");
  2039. return -ENOMEM;
  2040. }
  2041. }
  2042. return 0;
  2043. }
  2044. static void bnxt_init_cp_rings(struct bnxt *bp)
  2045. {
  2046. int i;
  2047. for (i = 0; i < bp->cp_nr_rings; i++) {
  2048. struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
  2049. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  2050. ring->fw_ring_id = INVALID_HW_RING_ID;
  2051. }
  2052. }
  2053. static int bnxt_init_rx_rings(struct bnxt *bp)
  2054. {
  2055. int i, rc = 0;
  2056. if (BNXT_RX_PAGE_MODE(bp)) {
  2057. bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM;
  2058. bp->rx_dma_offset = XDP_PACKET_HEADROOM;
  2059. } else {
  2060. bp->rx_offset = BNXT_RX_OFFSET;
  2061. bp->rx_dma_offset = BNXT_RX_DMA_OFFSET;
  2062. }
  2063. for (i = 0; i < bp->rx_nr_rings; i++) {
  2064. rc = bnxt_init_one_rx_ring(bp, i);
  2065. if (rc)
  2066. break;
  2067. }
  2068. return rc;
  2069. }
  2070. static int bnxt_init_tx_rings(struct bnxt *bp)
  2071. {
  2072. u16 i;
  2073. bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2,
  2074. MAX_SKB_FRAGS + 1);
  2075. for (i = 0; i < bp->tx_nr_rings; i++) {
  2076. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  2077. struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
  2078. ring->fw_ring_id = INVALID_HW_RING_ID;
  2079. }
  2080. return 0;
  2081. }
  2082. static void bnxt_free_ring_grps(struct bnxt *bp)
  2083. {
  2084. kfree(bp->grp_info);
  2085. bp->grp_info = NULL;
  2086. }
  2087. static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init)
  2088. {
  2089. int i;
  2090. if (irq_re_init) {
  2091. bp->grp_info = kcalloc(bp->cp_nr_rings,
  2092. sizeof(struct bnxt_ring_grp_info),
  2093. GFP_KERNEL);
  2094. if (!bp->grp_info)
  2095. return -ENOMEM;
  2096. }
  2097. for (i = 0; i < bp->cp_nr_rings; i++) {
  2098. if (irq_re_init)
  2099. bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID;
  2100. bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
  2101. bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
  2102. bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
  2103. bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
  2104. }
  2105. return 0;
  2106. }
  2107. static void bnxt_free_vnics(struct bnxt *bp)
  2108. {
  2109. kfree(bp->vnic_info);
  2110. bp->vnic_info = NULL;
  2111. bp->nr_vnics = 0;
  2112. }
  2113. static int bnxt_alloc_vnics(struct bnxt *bp)
  2114. {
  2115. int num_vnics = 1;
  2116. #ifdef CONFIG_RFS_ACCEL
  2117. if (bp->flags & BNXT_FLAG_RFS)
  2118. num_vnics += bp->rx_nr_rings;
  2119. #endif
  2120. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  2121. num_vnics++;
  2122. bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info),
  2123. GFP_KERNEL);
  2124. if (!bp->vnic_info)
  2125. return -ENOMEM;
  2126. bp->nr_vnics = num_vnics;
  2127. return 0;
  2128. }
  2129. static void bnxt_init_vnics(struct bnxt *bp)
  2130. {
  2131. int i;
  2132. for (i = 0; i < bp->nr_vnics; i++) {
  2133. struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
  2134. vnic->fw_vnic_id = INVALID_HW_RING_ID;
  2135. vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
  2136. vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
  2137. vnic->fw_l2_ctx_id = INVALID_HW_RING_ID;
  2138. if (bp->vnic_info[i].rss_hash_key) {
  2139. if (i == 0)
  2140. prandom_bytes(vnic->rss_hash_key,
  2141. HW_HASH_KEY_SIZE);
  2142. else
  2143. memcpy(vnic->rss_hash_key,
  2144. bp->vnic_info[0].rss_hash_key,
  2145. HW_HASH_KEY_SIZE);
  2146. }
  2147. }
  2148. }
  2149. static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg)
  2150. {
  2151. int pages;
  2152. pages = ring_size / desc_per_pg;
  2153. if (!pages)
  2154. return 1;
  2155. pages++;
  2156. while (pages & (pages - 1))
  2157. pages++;
  2158. return pages;
  2159. }
  2160. void bnxt_set_tpa_flags(struct bnxt *bp)
  2161. {
  2162. bp->flags &= ~BNXT_FLAG_TPA;
  2163. if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
  2164. return;
  2165. if (bp->dev->features & NETIF_F_LRO)
  2166. bp->flags |= BNXT_FLAG_LRO;
  2167. if (bp->dev->features & NETIF_F_GRO)
  2168. bp->flags |= BNXT_FLAG_GRO;
  2169. }
  2170. /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
  2171. * be set on entry.
  2172. */
  2173. void bnxt_set_ring_params(struct bnxt *bp)
  2174. {
  2175. u32 ring_size, rx_size, rx_space;
  2176. u32 agg_factor = 0, agg_ring_size = 0;
  2177. /* 8 for CRC and VLAN */
  2178. rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8);
  2179. rx_space = rx_size + NET_SKB_PAD +
  2180. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  2181. bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
  2182. ring_size = bp->rx_ring_size;
  2183. bp->rx_agg_ring_size = 0;
  2184. bp->rx_agg_nr_pages = 0;
  2185. if (bp->flags & BNXT_FLAG_TPA)
  2186. agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
  2187. bp->flags &= ~BNXT_FLAG_JUMBO;
  2188. if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) {
  2189. u32 jumbo_factor;
  2190. bp->flags |= BNXT_FLAG_JUMBO;
  2191. jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT;
  2192. if (jumbo_factor > agg_factor)
  2193. agg_factor = jumbo_factor;
  2194. }
  2195. agg_ring_size = ring_size * agg_factor;
  2196. if (agg_ring_size) {
  2197. bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size,
  2198. RX_DESC_CNT);
  2199. if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) {
  2200. u32 tmp = agg_ring_size;
  2201. bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES;
  2202. agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1;
  2203. netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n",
  2204. tmp, agg_ring_size);
  2205. }
  2206. bp->rx_agg_ring_size = agg_ring_size;
  2207. bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1;
  2208. rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
  2209. rx_space = rx_size + NET_SKB_PAD +
  2210. SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
  2211. }
  2212. bp->rx_buf_use_size = rx_size;
  2213. bp->rx_buf_size = rx_space;
  2214. bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT);
  2215. bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1;
  2216. ring_size = bp->tx_ring_size;
  2217. bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT);
  2218. bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1;
  2219. ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size;
  2220. bp->cp_ring_size = ring_size;
  2221. bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT);
  2222. if (bp->cp_nr_pages > MAX_CP_PAGES) {
  2223. bp->cp_nr_pages = MAX_CP_PAGES;
  2224. bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1;
  2225. netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n",
  2226. ring_size, bp->cp_ring_size);
  2227. }
  2228. bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT;
  2229. bp->cp_ring_mask = bp->cp_bit - 1;
  2230. }
  2231. int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode)
  2232. {
  2233. if (page_mode) {
  2234. if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU)
  2235. return -EOPNOTSUPP;
  2236. bp->dev->max_mtu = BNXT_MAX_PAGE_MODE_MTU;
  2237. bp->flags &= ~BNXT_FLAG_AGG_RINGS;
  2238. bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE;
  2239. bp->dev->hw_features &= ~NETIF_F_LRO;
  2240. bp->dev->features &= ~NETIF_F_LRO;
  2241. bp->rx_dir = DMA_BIDIRECTIONAL;
  2242. bp->rx_skb_func = bnxt_rx_page_skb;
  2243. } else {
  2244. bp->dev->max_mtu = BNXT_MAX_MTU;
  2245. bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE;
  2246. bp->rx_dir = DMA_FROM_DEVICE;
  2247. bp->rx_skb_func = bnxt_rx_skb;
  2248. }
  2249. return 0;
  2250. }
  2251. static void bnxt_free_vnic_attributes(struct bnxt *bp)
  2252. {
  2253. int i;
  2254. struct bnxt_vnic_info *vnic;
  2255. struct pci_dev *pdev = bp->pdev;
  2256. if (!bp->vnic_info)
  2257. return;
  2258. for (i = 0; i < bp->nr_vnics; i++) {
  2259. vnic = &bp->vnic_info[i];
  2260. kfree(vnic->fw_grp_ids);
  2261. vnic->fw_grp_ids = NULL;
  2262. kfree(vnic->uc_list);
  2263. vnic->uc_list = NULL;
  2264. if (vnic->mc_list) {
  2265. dma_free_coherent(&pdev->dev, vnic->mc_list_size,
  2266. vnic->mc_list, vnic->mc_list_mapping);
  2267. vnic->mc_list = NULL;
  2268. }
  2269. if (vnic->rss_table) {
  2270. dma_free_coherent(&pdev->dev, PAGE_SIZE,
  2271. vnic->rss_table,
  2272. vnic->rss_table_dma_addr);
  2273. vnic->rss_table = NULL;
  2274. }
  2275. vnic->rss_hash_key = NULL;
  2276. vnic->flags = 0;
  2277. }
  2278. }
  2279. static int bnxt_alloc_vnic_attributes(struct bnxt *bp)
  2280. {
  2281. int i, rc = 0, size;
  2282. struct bnxt_vnic_info *vnic;
  2283. struct pci_dev *pdev = bp->pdev;
  2284. int max_rings;
  2285. for (i = 0; i < bp->nr_vnics; i++) {
  2286. vnic = &bp->vnic_info[i];
  2287. if (vnic->flags & BNXT_VNIC_UCAST_FLAG) {
  2288. int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN;
  2289. if (mem_size > 0) {
  2290. vnic->uc_list = kmalloc(mem_size, GFP_KERNEL);
  2291. if (!vnic->uc_list) {
  2292. rc = -ENOMEM;
  2293. goto out;
  2294. }
  2295. }
  2296. }
  2297. if (vnic->flags & BNXT_VNIC_MCAST_FLAG) {
  2298. vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN;
  2299. vnic->mc_list =
  2300. dma_alloc_coherent(&pdev->dev,
  2301. vnic->mc_list_size,
  2302. &vnic->mc_list_mapping,
  2303. GFP_KERNEL);
  2304. if (!vnic->mc_list) {
  2305. rc = -ENOMEM;
  2306. goto out;
  2307. }
  2308. }
  2309. if (vnic->flags & BNXT_VNIC_RSS_FLAG)
  2310. max_rings = bp->rx_nr_rings;
  2311. else
  2312. max_rings = 1;
  2313. vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL);
  2314. if (!vnic->fw_grp_ids) {
  2315. rc = -ENOMEM;
  2316. goto out;
  2317. }
  2318. if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) &&
  2319. !(vnic->flags & BNXT_VNIC_RSS_FLAG))
  2320. continue;
  2321. /* Allocate rss table and hash key */
  2322. vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
  2323. &vnic->rss_table_dma_addr,
  2324. GFP_KERNEL);
  2325. if (!vnic->rss_table) {
  2326. rc = -ENOMEM;
  2327. goto out;
  2328. }
  2329. size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16));
  2330. vnic->rss_hash_key = ((void *)vnic->rss_table) + size;
  2331. vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size;
  2332. }
  2333. return 0;
  2334. out:
  2335. return rc;
  2336. }
  2337. static void bnxt_free_hwrm_resources(struct bnxt *bp)
  2338. {
  2339. struct pci_dev *pdev = bp->pdev;
  2340. dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr,
  2341. bp->hwrm_cmd_resp_dma_addr);
  2342. bp->hwrm_cmd_resp_addr = NULL;
  2343. if (bp->hwrm_dbg_resp_addr) {
  2344. dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE,
  2345. bp->hwrm_dbg_resp_addr,
  2346. bp->hwrm_dbg_resp_dma_addr);
  2347. bp->hwrm_dbg_resp_addr = NULL;
  2348. }
  2349. }
  2350. static int bnxt_alloc_hwrm_resources(struct bnxt *bp)
  2351. {
  2352. struct pci_dev *pdev = bp->pdev;
  2353. bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
  2354. &bp->hwrm_cmd_resp_dma_addr,
  2355. GFP_KERNEL);
  2356. if (!bp->hwrm_cmd_resp_addr)
  2357. return -ENOMEM;
  2358. bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev,
  2359. HWRM_DBG_REG_BUF_SIZE,
  2360. &bp->hwrm_dbg_resp_dma_addr,
  2361. GFP_KERNEL);
  2362. if (!bp->hwrm_dbg_resp_addr)
  2363. netdev_warn(bp->dev, "fail to alloc debug register dma mem\n");
  2364. return 0;
  2365. }
  2366. static void bnxt_free_stats(struct bnxt *bp)
  2367. {
  2368. u32 size, i;
  2369. struct pci_dev *pdev = bp->pdev;
  2370. if (bp->hw_rx_port_stats) {
  2371. dma_free_coherent(&pdev->dev, bp->hw_port_stats_size,
  2372. bp->hw_rx_port_stats,
  2373. bp->hw_rx_port_stats_map);
  2374. bp->hw_rx_port_stats = NULL;
  2375. bp->flags &= ~BNXT_FLAG_PORT_STATS;
  2376. }
  2377. if (!bp->bnapi)
  2378. return;
  2379. size = sizeof(struct ctx_hw_stats);
  2380. for (i = 0; i < bp->cp_nr_rings; i++) {
  2381. struct bnxt_napi *bnapi = bp->bnapi[i];
  2382. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2383. if (cpr->hw_stats) {
  2384. dma_free_coherent(&pdev->dev, size, cpr->hw_stats,
  2385. cpr->hw_stats_map);
  2386. cpr->hw_stats = NULL;
  2387. }
  2388. }
  2389. }
  2390. static int bnxt_alloc_stats(struct bnxt *bp)
  2391. {
  2392. u32 size, i;
  2393. struct pci_dev *pdev = bp->pdev;
  2394. size = sizeof(struct ctx_hw_stats);
  2395. for (i = 0; i < bp->cp_nr_rings; i++) {
  2396. struct bnxt_napi *bnapi = bp->bnapi[i];
  2397. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2398. cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size,
  2399. &cpr->hw_stats_map,
  2400. GFP_KERNEL);
  2401. if (!cpr->hw_stats)
  2402. return -ENOMEM;
  2403. cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
  2404. }
  2405. if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) {
  2406. bp->hw_port_stats_size = sizeof(struct rx_port_stats) +
  2407. sizeof(struct tx_port_stats) + 1024;
  2408. bp->hw_rx_port_stats =
  2409. dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size,
  2410. &bp->hw_rx_port_stats_map,
  2411. GFP_KERNEL);
  2412. if (!bp->hw_rx_port_stats)
  2413. return -ENOMEM;
  2414. bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) +
  2415. 512;
  2416. bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map +
  2417. sizeof(struct rx_port_stats) + 512;
  2418. bp->flags |= BNXT_FLAG_PORT_STATS;
  2419. }
  2420. return 0;
  2421. }
  2422. static void bnxt_clear_ring_indices(struct bnxt *bp)
  2423. {
  2424. int i;
  2425. if (!bp->bnapi)
  2426. return;
  2427. for (i = 0; i < bp->cp_nr_rings; i++) {
  2428. struct bnxt_napi *bnapi = bp->bnapi[i];
  2429. struct bnxt_cp_ring_info *cpr;
  2430. struct bnxt_rx_ring_info *rxr;
  2431. struct bnxt_tx_ring_info *txr;
  2432. if (!bnapi)
  2433. continue;
  2434. cpr = &bnapi->cp_ring;
  2435. cpr->cp_raw_cons = 0;
  2436. txr = bnapi->tx_ring;
  2437. if (txr) {
  2438. txr->tx_prod = 0;
  2439. txr->tx_cons = 0;
  2440. }
  2441. rxr = bnapi->rx_ring;
  2442. if (rxr) {
  2443. rxr->rx_prod = 0;
  2444. rxr->rx_agg_prod = 0;
  2445. rxr->rx_sw_agg_prod = 0;
  2446. rxr->rx_next_cons = 0;
  2447. }
  2448. }
  2449. }
  2450. static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit)
  2451. {
  2452. #ifdef CONFIG_RFS_ACCEL
  2453. int i;
  2454. /* Under rtnl_lock and all our NAPIs have been disabled. It's
  2455. * safe to delete the hash table.
  2456. */
  2457. for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
  2458. struct hlist_head *head;
  2459. struct hlist_node *tmp;
  2460. struct bnxt_ntuple_filter *fltr;
  2461. head = &bp->ntp_fltr_hash_tbl[i];
  2462. hlist_for_each_entry_safe(fltr, tmp, head, hash) {
  2463. hlist_del(&fltr->hash);
  2464. kfree(fltr);
  2465. }
  2466. }
  2467. if (irq_reinit) {
  2468. kfree(bp->ntp_fltr_bmap);
  2469. bp->ntp_fltr_bmap = NULL;
  2470. }
  2471. bp->ntp_fltr_count = 0;
  2472. #endif
  2473. }
  2474. static int bnxt_alloc_ntp_fltrs(struct bnxt *bp)
  2475. {
  2476. #ifdef CONFIG_RFS_ACCEL
  2477. int i, rc = 0;
  2478. if (!(bp->flags & BNXT_FLAG_RFS))
  2479. return 0;
  2480. for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++)
  2481. INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]);
  2482. bp->ntp_fltr_count = 0;
  2483. bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR),
  2484. sizeof(long),
  2485. GFP_KERNEL);
  2486. if (!bp->ntp_fltr_bmap)
  2487. rc = -ENOMEM;
  2488. return rc;
  2489. #else
  2490. return 0;
  2491. #endif
  2492. }
  2493. static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
  2494. {
  2495. bnxt_free_vnic_attributes(bp);
  2496. bnxt_free_tx_rings(bp);
  2497. bnxt_free_rx_rings(bp);
  2498. bnxt_free_cp_rings(bp);
  2499. bnxt_free_ntp_fltrs(bp, irq_re_init);
  2500. if (irq_re_init) {
  2501. bnxt_free_stats(bp);
  2502. bnxt_free_ring_grps(bp);
  2503. bnxt_free_vnics(bp);
  2504. kfree(bp->tx_ring_map);
  2505. bp->tx_ring_map = NULL;
  2506. kfree(bp->tx_ring);
  2507. bp->tx_ring = NULL;
  2508. kfree(bp->rx_ring);
  2509. bp->rx_ring = NULL;
  2510. kfree(bp->bnapi);
  2511. bp->bnapi = NULL;
  2512. } else {
  2513. bnxt_clear_ring_indices(bp);
  2514. }
  2515. }
  2516. static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
  2517. {
  2518. int i, j, rc, size, arr_size;
  2519. void *bnapi;
  2520. if (irq_re_init) {
  2521. /* Allocate bnapi mem pointer array and mem block for
  2522. * all queues
  2523. */
  2524. arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) *
  2525. bp->cp_nr_rings);
  2526. size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi));
  2527. bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL);
  2528. if (!bnapi)
  2529. return -ENOMEM;
  2530. bp->bnapi = bnapi;
  2531. bnapi += arr_size;
  2532. for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) {
  2533. bp->bnapi[i] = bnapi;
  2534. bp->bnapi[i]->index = i;
  2535. bp->bnapi[i]->bp = bp;
  2536. }
  2537. bp->rx_ring = kcalloc(bp->rx_nr_rings,
  2538. sizeof(struct bnxt_rx_ring_info),
  2539. GFP_KERNEL);
  2540. if (!bp->rx_ring)
  2541. return -ENOMEM;
  2542. for (i = 0; i < bp->rx_nr_rings; i++) {
  2543. bp->rx_ring[i].bnapi = bp->bnapi[i];
  2544. bp->bnapi[i]->rx_ring = &bp->rx_ring[i];
  2545. }
  2546. bp->tx_ring = kcalloc(bp->tx_nr_rings,
  2547. sizeof(struct bnxt_tx_ring_info),
  2548. GFP_KERNEL);
  2549. if (!bp->tx_ring)
  2550. return -ENOMEM;
  2551. bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
  2552. GFP_KERNEL);
  2553. if (!bp->tx_ring_map)
  2554. return -ENOMEM;
  2555. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  2556. j = 0;
  2557. else
  2558. j = bp->rx_nr_rings;
  2559. for (i = 0; i < bp->tx_nr_rings; i++, j++) {
  2560. bp->tx_ring[i].bnapi = bp->bnapi[j];
  2561. bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
  2562. bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i;
  2563. if (i >= bp->tx_nr_rings_xdp) {
  2564. bp->tx_ring[i].txq_index = i -
  2565. bp->tx_nr_rings_xdp;
  2566. bp->bnapi[j]->tx_int = bnxt_tx_int;
  2567. } else {
  2568. bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP;
  2569. bp->bnapi[j]->tx_int = bnxt_tx_int_xdp;
  2570. }
  2571. }
  2572. rc = bnxt_alloc_stats(bp);
  2573. if (rc)
  2574. goto alloc_mem_err;
  2575. rc = bnxt_alloc_ntp_fltrs(bp);
  2576. if (rc)
  2577. goto alloc_mem_err;
  2578. rc = bnxt_alloc_vnics(bp);
  2579. if (rc)
  2580. goto alloc_mem_err;
  2581. }
  2582. bnxt_init_ring_struct(bp);
  2583. rc = bnxt_alloc_rx_rings(bp);
  2584. if (rc)
  2585. goto alloc_mem_err;
  2586. rc = bnxt_alloc_tx_rings(bp);
  2587. if (rc)
  2588. goto alloc_mem_err;
  2589. rc = bnxt_alloc_cp_rings(bp);
  2590. if (rc)
  2591. goto alloc_mem_err;
  2592. bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG |
  2593. BNXT_VNIC_UCAST_FLAG;
  2594. rc = bnxt_alloc_vnic_attributes(bp);
  2595. if (rc)
  2596. goto alloc_mem_err;
  2597. return 0;
  2598. alloc_mem_err:
  2599. bnxt_free_mem(bp, true);
  2600. return rc;
  2601. }
  2602. static void bnxt_disable_int(struct bnxt *bp)
  2603. {
  2604. int i;
  2605. if (!bp->bnapi)
  2606. return;
  2607. for (i = 0; i < bp->cp_nr_rings; i++) {
  2608. struct bnxt_napi *bnapi = bp->bnapi[i];
  2609. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2610. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  2611. if (ring->fw_ring_id != INVALID_HW_RING_ID)
  2612. BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
  2613. }
  2614. }
  2615. static void bnxt_disable_int_sync(struct bnxt *bp)
  2616. {
  2617. int i;
  2618. atomic_inc(&bp->intr_sem);
  2619. bnxt_disable_int(bp);
  2620. for (i = 0; i < bp->cp_nr_rings; i++)
  2621. synchronize_irq(bp->irq_tbl[i].vector);
  2622. }
  2623. static void bnxt_enable_int(struct bnxt *bp)
  2624. {
  2625. int i;
  2626. atomic_set(&bp->intr_sem, 0);
  2627. for (i = 0; i < bp->cp_nr_rings; i++) {
  2628. struct bnxt_napi *bnapi = bp->bnapi[i];
  2629. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  2630. BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons);
  2631. }
  2632. }
  2633. void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type,
  2634. u16 cmpl_ring, u16 target_id)
  2635. {
  2636. struct input *req = request;
  2637. req->req_type = cpu_to_le16(req_type);
  2638. req->cmpl_ring = cpu_to_le16(cmpl_ring);
  2639. req->target_id = cpu_to_le16(target_id);
  2640. req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);
  2641. }
  2642. static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len,
  2643. int timeout, bool silent)
  2644. {
  2645. int i, intr_process, rc, tmo_count;
  2646. struct input *req = msg;
  2647. u32 *data = msg;
  2648. __le32 *resp_len, *valid;
  2649. u16 cp_ring_id, len = 0;
  2650. struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr;
  2651. req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++);
  2652. memset(resp, 0, PAGE_SIZE);
  2653. cp_ring_id = le16_to_cpu(req->cmpl_ring);
  2654. intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1;
  2655. /* Write request msg to hwrm channel */
  2656. __iowrite32_copy(bp->bar0, data, msg_len / 4);
  2657. for (i = msg_len; i < BNXT_HWRM_MAX_REQ_LEN; i += 4)
  2658. writel(0, bp->bar0 + i);
  2659. /* currently supports only one outstanding message */
  2660. if (intr_process)
  2661. bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id);
  2662. /* Ring channel doorbell */
  2663. writel(1, bp->bar0 + 0x100);
  2664. if (!timeout)
  2665. timeout = DFLT_HWRM_CMD_TIMEOUT;
  2666. i = 0;
  2667. tmo_count = timeout * 40;
  2668. if (intr_process) {
  2669. /* Wait until hwrm response cmpl interrupt is processed */
  2670. while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID &&
  2671. i++ < tmo_count) {
  2672. usleep_range(25, 40);
  2673. }
  2674. if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) {
  2675. netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n",
  2676. le16_to_cpu(req->req_type));
  2677. return -1;
  2678. }
  2679. } else {
  2680. /* Check if response len is updated */
  2681. resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET;
  2682. for (i = 0; i < tmo_count; i++) {
  2683. len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >>
  2684. HWRM_RESP_LEN_SFT;
  2685. if (len)
  2686. break;
  2687. usleep_range(25, 40);
  2688. }
  2689. if (i >= tmo_count) {
  2690. netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n",
  2691. timeout, le16_to_cpu(req->req_type),
  2692. le16_to_cpu(req->seq_id), len);
  2693. return -1;
  2694. }
  2695. /* Last word of resp contains valid bit */
  2696. valid = bp->hwrm_cmd_resp_addr + len - 4;
  2697. for (i = 0; i < 5; i++) {
  2698. if (le32_to_cpu(*valid) & HWRM_RESP_VALID_MASK)
  2699. break;
  2700. udelay(1);
  2701. }
  2702. if (i >= 5) {
  2703. netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n",
  2704. timeout, le16_to_cpu(req->req_type),
  2705. le16_to_cpu(req->seq_id), len, *valid);
  2706. return -1;
  2707. }
  2708. }
  2709. rc = le16_to_cpu(resp->error_code);
  2710. if (rc && !silent)
  2711. netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n",
  2712. le16_to_cpu(resp->req_type),
  2713. le16_to_cpu(resp->seq_id), rc);
  2714. return rc;
  2715. }
  2716. int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
  2717. {
  2718. return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false);
  2719. }
  2720. int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout)
  2721. {
  2722. int rc;
  2723. mutex_lock(&bp->hwrm_cmd_lock);
  2724. rc = _hwrm_send_message(bp, msg, msg_len, timeout);
  2725. mutex_unlock(&bp->hwrm_cmd_lock);
  2726. return rc;
  2727. }
  2728. int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len,
  2729. int timeout)
  2730. {
  2731. int rc;
  2732. mutex_lock(&bp->hwrm_cmd_lock);
  2733. rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true);
  2734. mutex_unlock(&bp->hwrm_cmd_lock);
  2735. return rc;
  2736. }
  2737. int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap,
  2738. int bmap_size)
  2739. {
  2740. struct hwrm_func_drv_rgtr_input req = {0};
  2741. DECLARE_BITMAP(async_events_bmap, 256);
  2742. u32 *events = (u32 *)async_events_bmap;
  2743. int i;
  2744. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
  2745. req.enables =
  2746. cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
  2747. memset(async_events_bmap, 0, sizeof(async_events_bmap));
  2748. for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++)
  2749. __set_bit(bnxt_async_events_arr[i], async_events_bmap);
  2750. if (bmap && bmap_size) {
  2751. for (i = 0; i < bmap_size; i++) {
  2752. if (test_bit(i, bmap))
  2753. __set_bit(i, async_events_bmap);
  2754. }
  2755. }
  2756. for (i = 0; i < 8; i++)
  2757. req.async_event_fwd[i] |= cpu_to_le32(events[i]);
  2758. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2759. }
  2760. static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
  2761. {
  2762. struct hwrm_func_drv_rgtr_input req = {0};
  2763. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1);
  2764. req.enables =
  2765. cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
  2766. FUNC_DRV_RGTR_REQ_ENABLES_VER);
  2767. req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
  2768. req.ver_maj = DRV_VER_MAJ;
  2769. req.ver_min = DRV_VER_MIN;
  2770. req.ver_upd = DRV_VER_UPD;
  2771. if (BNXT_PF(bp)) {
  2772. DECLARE_BITMAP(vf_req_snif_bmap, 256);
  2773. u32 *data = (u32 *)vf_req_snif_bmap;
  2774. int i;
  2775. memset(vf_req_snif_bmap, 0, sizeof(vf_req_snif_bmap));
  2776. for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++)
  2777. __set_bit(bnxt_vf_req_snif[i], vf_req_snif_bmap);
  2778. for (i = 0; i < 8; i++)
  2779. req.vf_req_fwd[i] = cpu_to_le32(data[i]);
  2780. req.enables |=
  2781. cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
  2782. }
  2783. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2784. }
  2785. static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
  2786. {
  2787. struct hwrm_func_drv_unrgtr_input req = {0};
  2788. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
  2789. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2790. }
  2791. static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
  2792. {
  2793. u32 rc = 0;
  2794. struct hwrm_tunnel_dst_port_free_input req = {0};
  2795. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1);
  2796. req.tunnel_type = tunnel_type;
  2797. switch (tunnel_type) {
  2798. case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN:
  2799. req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id;
  2800. break;
  2801. case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE:
  2802. req.tunnel_dst_port_id = bp->nge_fw_dst_port_id;
  2803. break;
  2804. default:
  2805. break;
  2806. }
  2807. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2808. if (rc)
  2809. netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n",
  2810. rc);
  2811. return rc;
  2812. }
  2813. static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
  2814. u8 tunnel_type)
  2815. {
  2816. u32 rc = 0;
  2817. struct hwrm_tunnel_dst_port_alloc_input req = {0};
  2818. struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
  2819. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1);
  2820. req.tunnel_type = tunnel_type;
  2821. req.tunnel_dst_port_val = port;
  2822. mutex_lock(&bp->hwrm_cmd_lock);
  2823. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2824. if (rc) {
  2825. netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n",
  2826. rc);
  2827. goto err_out;
  2828. }
  2829. switch (tunnel_type) {
  2830. case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
  2831. bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
  2832. break;
  2833. case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
  2834. bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
  2835. break;
  2836. default:
  2837. break;
  2838. }
  2839. err_out:
  2840. mutex_unlock(&bp->hwrm_cmd_lock);
  2841. return rc;
  2842. }
  2843. static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id)
  2844. {
  2845. struct hwrm_cfa_l2_set_rx_mask_input req = {0};
  2846. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  2847. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1);
  2848. req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
  2849. req.num_mc_entries = cpu_to_le32(vnic->mc_list_count);
  2850. req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
  2851. req.mask = cpu_to_le32(vnic->rx_mask);
  2852. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2853. }
  2854. #ifdef CONFIG_RFS_ACCEL
  2855. static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
  2856. struct bnxt_ntuple_filter *fltr)
  2857. {
  2858. struct hwrm_cfa_ntuple_filter_free_input req = {0};
  2859. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1);
  2860. req.ntuple_filter_id = fltr->filter_id;
  2861. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2862. }
  2863. #define BNXT_NTP_FLTR_FLAGS \
  2864. (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \
  2865. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \
  2866. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \
  2867. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \
  2868. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \
  2869. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \
  2870. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \
  2871. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \
  2872. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \
  2873. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \
  2874. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \
  2875. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \
  2876. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \
  2877. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID)
  2878. #define BNXT_NTP_TUNNEL_FLTR_FLAG \
  2879. CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE
  2880. static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
  2881. struct bnxt_ntuple_filter *fltr)
  2882. {
  2883. int rc = 0;
  2884. struct hwrm_cfa_ntuple_filter_alloc_input req = {0};
  2885. struct hwrm_cfa_ntuple_filter_alloc_output *resp =
  2886. bp->hwrm_cmd_resp_addr;
  2887. struct flow_keys *keys = &fltr->fkeys;
  2888. struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1];
  2889. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1);
  2890. req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx];
  2891. req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS);
  2892. req.ethertype = htons(ETH_P_IP);
  2893. memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN);
  2894. req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4;
  2895. req.ip_protocol = keys->basic.ip_proto;
  2896. if (keys->basic.n_proto == htons(ETH_P_IPV6)) {
  2897. int i;
  2898. req.ethertype = htons(ETH_P_IPV6);
  2899. req.ip_addr_type =
  2900. CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6;
  2901. *(struct in6_addr *)&req.src_ipaddr[0] =
  2902. keys->addrs.v6addrs.src;
  2903. *(struct in6_addr *)&req.dst_ipaddr[0] =
  2904. keys->addrs.v6addrs.dst;
  2905. for (i = 0; i < 4; i++) {
  2906. req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
  2907. req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff);
  2908. }
  2909. } else {
  2910. req.src_ipaddr[0] = keys->addrs.v4addrs.src;
  2911. req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
  2912. req.dst_ipaddr[0] = keys->addrs.v4addrs.dst;
  2913. req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff);
  2914. }
  2915. if (keys->control.flags & FLOW_DIS_ENCAPSULATION) {
  2916. req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG);
  2917. req.tunnel_type =
  2918. CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL;
  2919. }
  2920. req.src_port = keys->ports.src;
  2921. req.src_port_mask = cpu_to_be16(0xffff);
  2922. req.dst_port = keys->ports.dst;
  2923. req.dst_port_mask = cpu_to_be16(0xffff);
  2924. req.dst_id = cpu_to_le16(vnic->fw_vnic_id);
  2925. mutex_lock(&bp->hwrm_cmd_lock);
  2926. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2927. if (!rc)
  2928. fltr->filter_id = resp->ntuple_filter_id;
  2929. mutex_unlock(&bp->hwrm_cmd_lock);
  2930. return rc;
  2931. }
  2932. #endif
  2933. static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx,
  2934. u8 *mac_addr)
  2935. {
  2936. u32 rc = 0;
  2937. struct hwrm_cfa_l2_filter_alloc_input req = {0};
  2938. struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
  2939. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1);
  2940. req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
  2941. if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
  2942. req.flags |=
  2943. cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
  2944. req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id);
  2945. req.enables =
  2946. cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
  2947. CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
  2948. CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
  2949. memcpy(req.l2_addr, mac_addr, ETH_ALEN);
  2950. req.l2_addr_mask[0] = 0xff;
  2951. req.l2_addr_mask[1] = 0xff;
  2952. req.l2_addr_mask[2] = 0xff;
  2953. req.l2_addr_mask[3] = 0xff;
  2954. req.l2_addr_mask[4] = 0xff;
  2955. req.l2_addr_mask[5] = 0xff;
  2956. mutex_lock(&bp->hwrm_cmd_lock);
  2957. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  2958. if (!rc)
  2959. bp->vnic_info[vnic_id].fw_l2_filter_id[idx] =
  2960. resp->l2_filter_id;
  2961. mutex_unlock(&bp->hwrm_cmd_lock);
  2962. return rc;
  2963. }
  2964. static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp)
  2965. {
  2966. u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */
  2967. int rc = 0;
  2968. /* Any associated ntuple filters will also be cleared by firmware. */
  2969. mutex_lock(&bp->hwrm_cmd_lock);
  2970. for (i = 0; i < num_of_vnics; i++) {
  2971. struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
  2972. for (j = 0; j < vnic->uc_filter_count; j++) {
  2973. struct hwrm_cfa_l2_filter_free_input req = {0};
  2974. bnxt_hwrm_cmd_hdr_init(bp, &req,
  2975. HWRM_CFA_L2_FILTER_FREE, -1, -1);
  2976. req.l2_filter_id = vnic->fw_l2_filter_id[j];
  2977. rc = _hwrm_send_message(bp, &req, sizeof(req),
  2978. HWRM_CMD_TIMEOUT);
  2979. }
  2980. vnic->uc_filter_count = 0;
  2981. }
  2982. mutex_unlock(&bp->hwrm_cmd_lock);
  2983. return rc;
  2984. }
  2985. static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags)
  2986. {
  2987. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  2988. struct hwrm_vnic_tpa_cfg_input req = {0};
  2989. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1);
  2990. if (tpa_flags) {
  2991. u16 mss = bp->dev->mtu - 40;
  2992. u32 nsegs, n, segs = 0, flags;
  2993. flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
  2994. VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
  2995. VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
  2996. VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
  2997. VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
  2998. if (tpa_flags & BNXT_FLAG_GRO)
  2999. flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
  3000. req.flags = cpu_to_le32(flags);
  3001. req.enables =
  3002. cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
  3003. VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
  3004. VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
  3005. /* Number of segs are log2 units, and first packet is not
  3006. * included as part of this units.
  3007. */
  3008. if (mss <= BNXT_RX_PAGE_SIZE) {
  3009. n = BNXT_RX_PAGE_SIZE / mss;
  3010. nsegs = (MAX_SKB_FRAGS - 1) * n;
  3011. } else {
  3012. n = mss / BNXT_RX_PAGE_SIZE;
  3013. if (mss & (BNXT_RX_PAGE_SIZE - 1))
  3014. n++;
  3015. nsegs = (MAX_SKB_FRAGS - n) / n;
  3016. }
  3017. segs = ilog2(nsegs);
  3018. req.max_agg_segs = cpu_to_le16(segs);
  3019. req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX);
  3020. req.min_agg_len = cpu_to_le32(512);
  3021. }
  3022. req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
  3023. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3024. }
  3025. static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss)
  3026. {
  3027. u32 i, j, max_rings;
  3028. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  3029. struct hwrm_vnic_rss_cfg_input req = {0};
  3030. if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID)
  3031. return 0;
  3032. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1);
  3033. if (set_rss) {
  3034. req.hash_type = cpu_to_le32(bp->rss_hash_cfg);
  3035. if (vnic->flags & BNXT_VNIC_RSS_FLAG) {
  3036. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  3037. max_rings = bp->rx_nr_rings - 1;
  3038. else
  3039. max_rings = bp->rx_nr_rings;
  3040. } else {
  3041. max_rings = 1;
  3042. }
  3043. /* Fill the RSS indirection table with ring group ids */
  3044. for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) {
  3045. if (j == max_rings)
  3046. j = 0;
  3047. vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]);
  3048. }
  3049. req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
  3050. req.hash_key_tbl_addr =
  3051. cpu_to_le64(vnic->rss_hash_key_dma_addr);
  3052. }
  3053. req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
  3054. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3055. }
  3056. static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id)
  3057. {
  3058. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  3059. struct hwrm_vnic_plcmodes_cfg_input req = {0};
  3060. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1);
  3061. req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT |
  3062. VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
  3063. VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
  3064. req.enables =
  3065. cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID |
  3066. VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
  3067. /* thresholds not implemented in firmware yet */
  3068. req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
  3069. req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
  3070. req.vnic_id = cpu_to_le32(vnic->fw_vnic_id);
  3071. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3072. }
  3073. static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id,
  3074. u16 ctx_idx)
  3075. {
  3076. struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0};
  3077. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1);
  3078. req.rss_cos_lb_ctx_id =
  3079. cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]);
  3080. hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3081. bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
  3082. }
  3083. static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp)
  3084. {
  3085. int i, j;
  3086. for (i = 0; i < bp->nr_vnics; i++) {
  3087. struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
  3088. for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) {
  3089. if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID)
  3090. bnxt_hwrm_vnic_ctx_free_one(bp, i, j);
  3091. }
  3092. }
  3093. bp->rsscos_nr_ctxs = 0;
  3094. }
  3095. static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx)
  3096. {
  3097. int rc;
  3098. struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0};
  3099. struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
  3100. bp->hwrm_cmd_resp_addr;
  3101. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1,
  3102. -1);
  3103. mutex_lock(&bp->hwrm_cmd_lock);
  3104. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3105. if (!rc)
  3106. bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] =
  3107. le16_to_cpu(resp->rss_cos_lb_ctx_id);
  3108. mutex_unlock(&bp->hwrm_cmd_lock);
  3109. return rc;
  3110. }
  3111. int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id)
  3112. {
  3113. unsigned int ring = 0, grp_idx;
  3114. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  3115. struct hwrm_vnic_cfg_input req = {0};
  3116. u16 def_vlan = 0;
  3117. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1);
  3118. req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP);
  3119. /* Only RSS support for now TBD: COS & LB */
  3120. if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) {
  3121. req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
  3122. req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
  3123. VNIC_CFG_REQ_ENABLES_MRU);
  3124. } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) {
  3125. req.rss_rule =
  3126. cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]);
  3127. req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE |
  3128. VNIC_CFG_REQ_ENABLES_MRU);
  3129. req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE);
  3130. } else {
  3131. req.rss_rule = cpu_to_le16(0xffff);
  3132. }
  3133. if (BNXT_CHIP_TYPE_NITRO_A0(bp) &&
  3134. (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) {
  3135. req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]);
  3136. req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE);
  3137. } else {
  3138. req.cos_rule = cpu_to_le16(0xffff);
  3139. }
  3140. if (vnic->flags & BNXT_VNIC_RSS_FLAG)
  3141. ring = 0;
  3142. else if (vnic->flags & BNXT_VNIC_RFS_FLAG)
  3143. ring = vnic_id - 1;
  3144. else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp))
  3145. ring = bp->rx_nr_rings - 1;
  3146. grp_idx = bp->rx_ring[ring].bnapi->index;
  3147. req.vnic_id = cpu_to_le16(vnic->fw_vnic_id);
  3148. req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id);
  3149. req.lb_rule = cpu_to_le16(0xffff);
  3150. req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN +
  3151. VLAN_HLEN);
  3152. #ifdef CONFIG_BNXT_SRIOV
  3153. if (BNXT_VF(bp))
  3154. def_vlan = bp->vf.vlan;
  3155. #endif
  3156. if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan)
  3157. req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
  3158. if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP))
  3159. req.flags |=
  3160. cpu_to_le32(VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE);
  3161. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3162. }
  3163. static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id)
  3164. {
  3165. u32 rc = 0;
  3166. if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) {
  3167. struct hwrm_vnic_free_input req = {0};
  3168. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1);
  3169. req.vnic_id =
  3170. cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id);
  3171. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3172. if (rc)
  3173. return rc;
  3174. bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID;
  3175. }
  3176. return rc;
  3177. }
  3178. static void bnxt_hwrm_vnic_free(struct bnxt *bp)
  3179. {
  3180. u16 i;
  3181. for (i = 0; i < bp->nr_vnics; i++)
  3182. bnxt_hwrm_vnic_free_one(bp, i);
  3183. }
  3184. static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id,
  3185. unsigned int start_rx_ring_idx,
  3186. unsigned int nr_rings)
  3187. {
  3188. int rc = 0;
  3189. unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings;
  3190. struct hwrm_vnic_alloc_input req = {0};
  3191. struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
  3192. /* map ring groups to this vnic */
  3193. for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) {
  3194. grp_idx = bp->rx_ring[i].bnapi->index;
  3195. if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) {
  3196. netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n",
  3197. j, nr_rings);
  3198. break;
  3199. }
  3200. bp->vnic_info[vnic_id].fw_grp_ids[j] =
  3201. bp->grp_info[grp_idx].fw_grp_id;
  3202. }
  3203. bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID;
  3204. bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID;
  3205. if (vnic_id == 0)
  3206. req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
  3207. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1);
  3208. mutex_lock(&bp->hwrm_cmd_lock);
  3209. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3210. if (!rc)
  3211. bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id);
  3212. mutex_unlock(&bp->hwrm_cmd_lock);
  3213. return rc;
  3214. }
  3215. static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
  3216. {
  3217. struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
  3218. struct hwrm_vnic_qcaps_input req = {0};
  3219. int rc;
  3220. if (bp->hwrm_spec_code < 0x10600)
  3221. return 0;
  3222. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1);
  3223. mutex_lock(&bp->hwrm_cmd_lock);
  3224. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3225. if (!rc) {
  3226. if (resp->flags &
  3227. cpu_to_le32(VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP))
  3228. bp->flags |= BNXT_FLAG_NEW_RSS_CAP;
  3229. }
  3230. mutex_unlock(&bp->hwrm_cmd_lock);
  3231. return rc;
  3232. }
  3233. static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp)
  3234. {
  3235. u16 i;
  3236. u32 rc = 0;
  3237. mutex_lock(&bp->hwrm_cmd_lock);
  3238. for (i = 0; i < bp->rx_nr_rings; i++) {
  3239. struct hwrm_ring_grp_alloc_input req = {0};
  3240. struct hwrm_ring_grp_alloc_output *resp =
  3241. bp->hwrm_cmd_resp_addr;
  3242. unsigned int grp_idx = bp->rx_ring[i].bnapi->index;
  3243. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1);
  3244. req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id);
  3245. req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id);
  3246. req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id);
  3247. req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx);
  3248. rc = _hwrm_send_message(bp, &req, sizeof(req),
  3249. HWRM_CMD_TIMEOUT);
  3250. if (rc)
  3251. break;
  3252. bp->grp_info[grp_idx].fw_grp_id =
  3253. le32_to_cpu(resp->ring_group_id);
  3254. }
  3255. mutex_unlock(&bp->hwrm_cmd_lock);
  3256. return rc;
  3257. }
  3258. static int bnxt_hwrm_ring_grp_free(struct bnxt *bp)
  3259. {
  3260. u16 i;
  3261. u32 rc = 0;
  3262. struct hwrm_ring_grp_free_input req = {0};
  3263. if (!bp->grp_info)
  3264. return 0;
  3265. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1);
  3266. mutex_lock(&bp->hwrm_cmd_lock);
  3267. for (i = 0; i < bp->cp_nr_rings; i++) {
  3268. if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID)
  3269. continue;
  3270. req.ring_group_id =
  3271. cpu_to_le32(bp->grp_info[i].fw_grp_id);
  3272. rc = _hwrm_send_message(bp, &req, sizeof(req),
  3273. HWRM_CMD_TIMEOUT);
  3274. if (rc)
  3275. break;
  3276. bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID;
  3277. }
  3278. mutex_unlock(&bp->hwrm_cmd_lock);
  3279. return rc;
  3280. }
  3281. static int hwrm_ring_alloc_send_msg(struct bnxt *bp,
  3282. struct bnxt_ring_struct *ring,
  3283. u32 ring_type, u32 map_index,
  3284. u32 stats_ctx_id)
  3285. {
  3286. int rc = 0, err = 0;
  3287. struct hwrm_ring_alloc_input req = {0};
  3288. struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
  3289. u16 ring_id;
  3290. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1);
  3291. req.enables = 0;
  3292. if (ring->nr_pages > 1) {
  3293. req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map);
  3294. /* Page size is in log2 units */
  3295. req.page_size = BNXT_PAGE_SHIFT;
  3296. req.page_tbl_depth = 1;
  3297. } else {
  3298. req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]);
  3299. }
  3300. req.fbo = 0;
  3301. /* Association of ring index with doorbell index and MSIX number */
  3302. req.logical_id = cpu_to_le16(map_index);
  3303. switch (ring_type) {
  3304. case HWRM_RING_ALLOC_TX:
  3305. req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
  3306. /* Association of transmit ring with completion ring */
  3307. req.cmpl_ring_id =
  3308. cpu_to_le16(bp->grp_info[map_index].cp_fw_ring_id);
  3309. req.length = cpu_to_le32(bp->tx_ring_mask + 1);
  3310. req.stat_ctx_id = cpu_to_le32(stats_ctx_id);
  3311. req.queue_id = cpu_to_le16(ring->queue_id);
  3312. break;
  3313. case HWRM_RING_ALLOC_RX:
  3314. req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
  3315. req.length = cpu_to_le32(bp->rx_ring_mask + 1);
  3316. break;
  3317. case HWRM_RING_ALLOC_AGG:
  3318. req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
  3319. req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1);
  3320. break;
  3321. case HWRM_RING_ALLOC_CMPL:
  3322. req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
  3323. req.length = cpu_to_le32(bp->cp_ring_mask + 1);
  3324. if (bp->flags & BNXT_FLAG_USING_MSIX)
  3325. req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
  3326. break;
  3327. default:
  3328. netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n",
  3329. ring_type);
  3330. return -1;
  3331. }
  3332. mutex_lock(&bp->hwrm_cmd_lock);
  3333. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3334. err = le16_to_cpu(resp->error_code);
  3335. ring_id = le16_to_cpu(resp->ring_id);
  3336. mutex_unlock(&bp->hwrm_cmd_lock);
  3337. if (rc || err) {
  3338. switch (ring_type) {
  3339. case RING_FREE_REQ_RING_TYPE_L2_CMPL:
  3340. netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n",
  3341. rc, err);
  3342. return -1;
  3343. case RING_FREE_REQ_RING_TYPE_RX:
  3344. netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n",
  3345. rc, err);
  3346. return -1;
  3347. case RING_FREE_REQ_RING_TYPE_TX:
  3348. netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n",
  3349. rc, err);
  3350. return -1;
  3351. default:
  3352. netdev_err(bp->dev, "Invalid ring\n");
  3353. return -1;
  3354. }
  3355. }
  3356. ring->fw_ring_id = ring_id;
  3357. return rc;
  3358. }
  3359. static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
  3360. {
  3361. int rc;
  3362. if (BNXT_PF(bp)) {
  3363. struct hwrm_func_cfg_input req = {0};
  3364. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
  3365. req.fid = cpu_to_le16(0xffff);
  3366. req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
  3367. req.async_event_cr = cpu_to_le16(idx);
  3368. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3369. } else {
  3370. struct hwrm_func_vf_cfg_input req = {0};
  3371. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1);
  3372. req.enables =
  3373. cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
  3374. req.async_event_cr = cpu_to_le16(idx);
  3375. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3376. }
  3377. return rc;
  3378. }
  3379. static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
  3380. {
  3381. int i, rc = 0;
  3382. for (i = 0; i < bp->cp_nr_rings; i++) {
  3383. struct bnxt_napi *bnapi = bp->bnapi[i];
  3384. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3385. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  3386. cpr->cp_doorbell = bp->bar1 + i * 0x80;
  3387. rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i,
  3388. INVALID_STATS_CTX_ID);
  3389. if (rc)
  3390. goto err_out;
  3391. BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
  3392. bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
  3393. if (!i) {
  3394. rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id);
  3395. if (rc)
  3396. netdev_warn(bp->dev, "Failed to set async event completion ring.\n");
  3397. }
  3398. }
  3399. for (i = 0; i < bp->tx_nr_rings; i++) {
  3400. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  3401. struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
  3402. u32 map_idx = txr->bnapi->index;
  3403. u16 fw_stats_ctx = bp->grp_info[map_idx].fw_stats_ctx;
  3404. rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX,
  3405. map_idx, fw_stats_ctx);
  3406. if (rc)
  3407. goto err_out;
  3408. txr->tx_doorbell = bp->bar1 + map_idx * 0x80;
  3409. }
  3410. for (i = 0; i < bp->rx_nr_rings; i++) {
  3411. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  3412. struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
  3413. u32 map_idx = rxr->bnapi->index;
  3414. rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX,
  3415. map_idx, INVALID_STATS_CTX_ID);
  3416. if (rc)
  3417. goto err_out;
  3418. rxr->rx_doorbell = bp->bar1 + map_idx * 0x80;
  3419. writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
  3420. bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id;
  3421. }
  3422. if (bp->flags & BNXT_FLAG_AGG_RINGS) {
  3423. for (i = 0; i < bp->rx_nr_rings; i++) {
  3424. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  3425. struct bnxt_ring_struct *ring =
  3426. &rxr->rx_agg_ring_struct;
  3427. u32 grp_idx = rxr->bnapi->index;
  3428. u32 map_idx = grp_idx + bp->rx_nr_rings;
  3429. rc = hwrm_ring_alloc_send_msg(bp, ring,
  3430. HWRM_RING_ALLOC_AGG,
  3431. map_idx,
  3432. INVALID_STATS_CTX_ID);
  3433. if (rc)
  3434. goto err_out;
  3435. rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80;
  3436. writel(DB_KEY_RX | rxr->rx_agg_prod,
  3437. rxr->rx_agg_doorbell);
  3438. bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id;
  3439. }
  3440. }
  3441. err_out:
  3442. return rc;
  3443. }
  3444. static int hwrm_ring_free_send_msg(struct bnxt *bp,
  3445. struct bnxt_ring_struct *ring,
  3446. u32 ring_type, int cmpl_ring_id)
  3447. {
  3448. int rc;
  3449. struct hwrm_ring_free_input req = {0};
  3450. struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
  3451. u16 error_code;
  3452. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1);
  3453. req.ring_type = ring_type;
  3454. req.ring_id = cpu_to_le16(ring->fw_ring_id);
  3455. mutex_lock(&bp->hwrm_cmd_lock);
  3456. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3457. error_code = le16_to_cpu(resp->error_code);
  3458. mutex_unlock(&bp->hwrm_cmd_lock);
  3459. if (rc || error_code) {
  3460. switch (ring_type) {
  3461. case RING_FREE_REQ_RING_TYPE_L2_CMPL:
  3462. netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n",
  3463. rc);
  3464. return rc;
  3465. case RING_FREE_REQ_RING_TYPE_RX:
  3466. netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n",
  3467. rc);
  3468. return rc;
  3469. case RING_FREE_REQ_RING_TYPE_TX:
  3470. netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n",
  3471. rc);
  3472. return rc;
  3473. default:
  3474. netdev_err(bp->dev, "Invalid ring\n");
  3475. return -1;
  3476. }
  3477. }
  3478. return 0;
  3479. }
  3480. static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
  3481. {
  3482. int i;
  3483. if (!bp->bnapi)
  3484. return;
  3485. for (i = 0; i < bp->tx_nr_rings; i++) {
  3486. struct bnxt_tx_ring_info *txr = &bp->tx_ring[i];
  3487. struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
  3488. u32 grp_idx = txr->bnapi->index;
  3489. u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
  3490. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  3491. hwrm_ring_free_send_msg(bp, ring,
  3492. RING_FREE_REQ_RING_TYPE_TX,
  3493. close_path ? cmpl_ring_id :
  3494. INVALID_HW_RING_ID);
  3495. ring->fw_ring_id = INVALID_HW_RING_ID;
  3496. }
  3497. }
  3498. for (i = 0; i < bp->rx_nr_rings; i++) {
  3499. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  3500. struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
  3501. u32 grp_idx = rxr->bnapi->index;
  3502. u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
  3503. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  3504. hwrm_ring_free_send_msg(bp, ring,
  3505. RING_FREE_REQ_RING_TYPE_RX,
  3506. close_path ? cmpl_ring_id :
  3507. INVALID_HW_RING_ID);
  3508. ring->fw_ring_id = INVALID_HW_RING_ID;
  3509. bp->grp_info[grp_idx].rx_fw_ring_id =
  3510. INVALID_HW_RING_ID;
  3511. }
  3512. }
  3513. for (i = 0; i < bp->rx_nr_rings; i++) {
  3514. struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];
  3515. struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
  3516. u32 grp_idx = rxr->bnapi->index;
  3517. u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id;
  3518. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  3519. hwrm_ring_free_send_msg(bp, ring,
  3520. RING_FREE_REQ_RING_TYPE_RX,
  3521. close_path ? cmpl_ring_id :
  3522. INVALID_HW_RING_ID);
  3523. ring->fw_ring_id = INVALID_HW_RING_ID;
  3524. bp->grp_info[grp_idx].agg_fw_ring_id =
  3525. INVALID_HW_RING_ID;
  3526. }
  3527. }
  3528. /* The completion rings are about to be freed. After that the
  3529. * IRQ doorbell will not work anymore. So we need to disable
  3530. * IRQ here.
  3531. */
  3532. bnxt_disable_int_sync(bp);
  3533. for (i = 0; i < bp->cp_nr_rings; i++) {
  3534. struct bnxt_napi *bnapi = bp->bnapi[i];
  3535. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3536. struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
  3537. if (ring->fw_ring_id != INVALID_HW_RING_ID) {
  3538. hwrm_ring_free_send_msg(bp, ring,
  3539. RING_FREE_REQ_RING_TYPE_L2_CMPL,
  3540. INVALID_HW_RING_ID);
  3541. ring->fw_ring_id = INVALID_HW_RING_ID;
  3542. bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
  3543. }
  3544. }
  3545. }
  3546. /* Caller must hold bp->hwrm_cmd_lock */
  3547. int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings)
  3548. {
  3549. struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
  3550. struct hwrm_func_qcfg_input req = {0};
  3551. int rc;
  3552. if (bp->hwrm_spec_code < 0x10601)
  3553. return 0;
  3554. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
  3555. req.fid = cpu_to_le16(fid);
  3556. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3557. if (!rc)
  3558. *tx_rings = le16_to_cpu(resp->alloc_tx_rings);
  3559. return rc;
  3560. }
  3561. static int bnxt_hwrm_reserve_tx_rings(struct bnxt *bp, int *tx_rings)
  3562. {
  3563. struct hwrm_func_cfg_input req = {0};
  3564. int rc;
  3565. if (bp->hwrm_spec_code < 0x10601)
  3566. return 0;
  3567. if (BNXT_VF(bp))
  3568. return 0;
  3569. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1);
  3570. req.fid = cpu_to_le16(0xffff);
  3571. req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS);
  3572. req.num_tx_rings = cpu_to_le16(*tx_rings);
  3573. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3574. if (rc)
  3575. return rc;
  3576. mutex_lock(&bp->hwrm_cmd_lock);
  3577. rc = __bnxt_hwrm_get_tx_rings(bp, 0xffff, tx_rings);
  3578. mutex_unlock(&bp->hwrm_cmd_lock);
  3579. return rc;
  3580. }
  3581. static void bnxt_hwrm_set_coal_params(struct bnxt *bp, u32 max_bufs,
  3582. u32 buf_tmrs, u16 flags,
  3583. struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
  3584. {
  3585. req->flags = cpu_to_le16(flags);
  3586. req->num_cmpl_dma_aggr = cpu_to_le16((u16)max_bufs);
  3587. req->num_cmpl_dma_aggr_during_int = cpu_to_le16(max_bufs >> 16);
  3588. req->cmpl_aggr_dma_tmr = cpu_to_le16((u16)buf_tmrs);
  3589. req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(buf_tmrs >> 16);
  3590. /* Minimum time between 2 interrupts set to buf_tmr x 2 */
  3591. req->int_lat_tmr_min = cpu_to_le16((u16)buf_tmrs * 2);
  3592. req->int_lat_tmr_max = cpu_to_le16((u16)buf_tmrs * 4);
  3593. req->num_cmpl_aggr_int = cpu_to_le16((u16)max_bufs * 4);
  3594. }
  3595. int bnxt_hwrm_set_coal(struct bnxt *bp)
  3596. {
  3597. int i, rc = 0;
  3598. struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0},
  3599. req_tx = {0}, *req;
  3600. u16 max_buf, max_buf_irq;
  3601. u16 buf_tmr, buf_tmr_irq;
  3602. u32 flags;
  3603. bnxt_hwrm_cmd_hdr_init(bp, &req_rx,
  3604. HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
  3605. bnxt_hwrm_cmd_hdr_init(bp, &req_tx,
  3606. HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1);
  3607. /* Each rx completion (2 records) should be DMAed immediately.
  3608. * DMA 1/4 of the completion buffers at a time.
  3609. */
  3610. max_buf = min_t(u16, bp->rx_coal_bufs / 4, 2);
  3611. /* max_buf must not be zero */
  3612. max_buf = clamp_t(u16, max_buf, 1, 63);
  3613. max_buf_irq = clamp_t(u16, bp->rx_coal_bufs_irq, 1, 63);
  3614. buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks);
  3615. /* buf timer set to 1/4 of interrupt timer */
  3616. buf_tmr = max_t(u16, buf_tmr / 4, 1);
  3617. buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->rx_coal_ticks_irq);
  3618. buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
  3619. flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
  3620. /* RING_IDLE generates more IRQs for lower latency. Enable it only
  3621. * if coal_ticks is less than 25 us.
  3622. */
  3623. if (bp->rx_coal_ticks < 25)
  3624. flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE;
  3625. bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
  3626. buf_tmr_irq << 16 | buf_tmr, flags, &req_rx);
  3627. /* max_buf must not be zero */
  3628. max_buf = clamp_t(u16, bp->tx_coal_bufs, 1, 63);
  3629. max_buf_irq = clamp_t(u16, bp->tx_coal_bufs_irq, 1, 63);
  3630. buf_tmr = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks);
  3631. /* buf timer set to 1/4 of interrupt timer */
  3632. buf_tmr = max_t(u16, buf_tmr / 4, 1);
  3633. buf_tmr_irq = BNXT_USEC_TO_COAL_TIMER(bp->tx_coal_ticks_irq);
  3634. buf_tmr_irq = max_t(u16, buf_tmr_irq, 1);
  3635. flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET;
  3636. bnxt_hwrm_set_coal_params(bp, max_buf_irq << 16 | max_buf,
  3637. buf_tmr_irq << 16 | buf_tmr, flags, &req_tx);
  3638. mutex_lock(&bp->hwrm_cmd_lock);
  3639. for (i = 0; i < bp->cp_nr_rings; i++) {
  3640. struct bnxt_napi *bnapi = bp->bnapi[i];
  3641. req = &req_rx;
  3642. if (!bnapi->rx_ring)
  3643. req = &req_tx;
  3644. req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id);
  3645. rc = _hwrm_send_message(bp, req, sizeof(*req),
  3646. HWRM_CMD_TIMEOUT);
  3647. if (rc)
  3648. break;
  3649. }
  3650. mutex_unlock(&bp->hwrm_cmd_lock);
  3651. return rc;
  3652. }
  3653. static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp)
  3654. {
  3655. int rc = 0, i;
  3656. struct hwrm_stat_ctx_free_input req = {0};
  3657. if (!bp->bnapi)
  3658. return 0;
  3659. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  3660. return 0;
  3661. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1);
  3662. mutex_lock(&bp->hwrm_cmd_lock);
  3663. for (i = 0; i < bp->cp_nr_rings; i++) {
  3664. struct bnxt_napi *bnapi = bp->bnapi[i];
  3665. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3666. if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
  3667. req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id);
  3668. rc = _hwrm_send_message(bp, &req, sizeof(req),
  3669. HWRM_CMD_TIMEOUT);
  3670. if (rc)
  3671. break;
  3672. cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
  3673. }
  3674. }
  3675. mutex_unlock(&bp->hwrm_cmd_lock);
  3676. return rc;
  3677. }
  3678. static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
  3679. {
  3680. int rc = 0, i;
  3681. struct hwrm_stat_ctx_alloc_input req = {0};
  3682. struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
  3683. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  3684. return 0;
  3685. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1);
  3686. req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000);
  3687. mutex_lock(&bp->hwrm_cmd_lock);
  3688. for (i = 0; i < bp->cp_nr_rings; i++) {
  3689. struct bnxt_napi *bnapi = bp->bnapi[i];
  3690. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  3691. req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map);
  3692. rc = _hwrm_send_message(bp, &req, sizeof(req),
  3693. HWRM_CMD_TIMEOUT);
  3694. if (rc)
  3695. break;
  3696. cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
  3697. bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
  3698. }
  3699. mutex_unlock(&bp->hwrm_cmd_lock);
  3700. return rc;
  3701. }
  3702. static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
  3703. {
  3704. struct hwrm_func_qcfg_input req = {0};
  3705. struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
  3706. int rc;
  3707. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1);
  3708. req.fid = cpu_to_le16(0xffff);
  3709. mutex_lock(&bp->hwrm_cmd_lock);
  3710. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3711. if (rc)
  3712. goto func_qcfg_exit;
  3713. #ifdef CONFIG_BNXT_SRIOV
  3714. if (BNXT_VF(bp)) {
  3715. struct bnxt_vf_info *vf = &bp->vf;
  3716. vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK;
  3717. }
  3718. #endif
  3719. if (BNXT_PF(bp)) {
  3720. u16 flags = le16_to_cpu(resp->flags);
  3721. if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED |
  3722. FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED))
  3723. bp->flags |= BNXT_FLAG_FW_LLDP_AGENT;
  3724. if (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)
  3725. bp->flags |= BNXT_FLAG_MULTI_HOST;
  3726. }
  3727. switch (resp->port_partition_type) {
  3728. case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0:
  3729. case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5:
  3730. case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0:
  3731. bp->port_partition_type = resp->port_partition_type;
  3732. break;
  3733. }
  3734. func_qcfg_exit:
  3735. mutex_unlock(&bp->hwrm_cmd_lock);
  3736. return rc;
  3737. }
  3738. static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
  3739. {
  3740. int rc = 0;
  3741. struct hwrm_func_qcaps_input req = {0};
  3742. struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
  3743. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1);
  3744. req.fid = cpu_to_le16(0xffff);
  3745. mutex_lock(&bp->hwrm_cmd_lock);
  3746. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3747. if (rc)
  3748. goto hwrm_func_qcaps_exit;
  3749. if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED))
  3750. bp->flags |= BNXT_FLAG_ROCEV1_CAP;
  3751. if (resp->flags & cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED))
  3752. bp->flags |= BNXT_FLAG_ROCEV2_CAP;
  3753. bp->tx_push_thresh = 0;
  3754. if (resp->flags &
  3755. cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED))
  3756. bp->tx_push_thresh = BNXT_TX_PUSH_THRESH;
  3757. if (BNXT_PF(bp)) {
  3758. struct bnxt_pf_info *pf = &bp->pf;
  3759. pf->fw_fid = le16_to_cpu(resp->fid);
  3760. pf->port_id = le16_to_cpu(resp->port_id);
  3761. bp->dev->dev_port = pf->port_id;
  3762. memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
  3763. memcpy(bp->dev->dev_addr, pf->mac_addr, ETH_ALEN);
  3764. pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
  3765. pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
  3766. pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
  3767. pf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
  3768. pf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
  3769. if (!pf->max_hw_ring_grps)
  3770. pf->max_hw_ring_grps = pf->max_tx_rings;
  3771. pf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
  3772. pf->max_vnics = le16_to_cpu(resp->max_vnics);
  3773. pf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
  3774. pf->first_vf_id = le16_to_cpu(resp->first_vf_id);
  3775. pf->max_vfs = le16_to_cpu(resp->max_vfs);
  3776. pf->max_encap_records = le32_to_cpu(resp->max_encap_records);
  3777. pf->max_decap_records = le32_to_cpu(resp->max_decap_records);
  3778. pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows);
  3779. pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows);
  3780. pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows);
  3781. pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows);
  3782. if (resp->flags &
  3783. cpu_to_le32(FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED))
  3784. bp->flags |= BNXT_FLAG_WOL_CAP;
  3785. } else {
  3786. #ifdef CONFIG_BNXT_SRIOV
  3787. struct bnxt_vf_info *vf = &bp->vf;
  3788. vf->fw_fid = le16_to_cpu(resp->fid);
  3789. vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
  3790. vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
  3791. vf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
  3792. vf->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
  3793. vf->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps);
  3794. if (!vf->max_hw_ring_grps)
  3795. vf->max_hw_ring_grps = vf->max_tx_rings;
  3796. vf->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
  3797. vf->max_vnics = le16_to_cpu(resp->max_vnics);
  3798. vf->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
  3799. memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN);
  3800. mutex_unlock(&bp->hwrm_cmd_lock);
  3801. if (is_valid_ether_addr(vf->mac_addr)) {
  3802. /* overwrite netdev dev_adr with admin VF MAC */
  3803. memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
  3804. } else {
  3805. eth_hw_addr_random(bp->dev);
  3806. rc = bnxt_approve_mac(bp, bp->dev->dev_addr);
  3807. }
  3808. return rc;
  3809. #endif
  3810. }
  3811. hwrm_func_qcaps_exit:
  3812. mutex_unlock(&bp->hwrm_cmd_lock);
  3813. return rc;
  3814. }
  3815. static int bnxt_hwrm_func_reset(struct bnxt *bp)
  3816. {
  3817. struct hwrm_func_reset_input req = {0};
  3818. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1);
  3819. req.enables = 0;
  3820. return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT);
  3821. }
  3822. static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
  3823. {
  3824. int rc = 0;
  3825. struct hwrm_queue_qportcfg_input req = {0};
  3826. struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
  3827. u8 i, *qptr;
  3828. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1);
  3829. mutex_lock(&bp->hwrm_cmd_lock);
  3830. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3831. if (rc)
  3832. goto qportcfg_exit;
  3833. if (!resp->max_configurable_queues) {
  3834. rc = -EINVAL;
  3835. goto qportcfg_exit;
  3836. }
  3837. bp->max_tc = resp->max_configurable_queues;
  3838. bp->max_lltc = resp->max_configurable_lossless_queues;
  3839. if (bp->max_tc > BNXT_MAX_QUEUE)
  3840. bp->max_tc = BNXT_MAX_QUEUE;
  3841. if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
  3842. bp->max_tc = 1;
  3843. if (bp->max_lltc > bp->max_tc)
  3844. bp->max_lltc = bp->max_tc;
  3845. qptr = &resp->queue_id0;
  3846. for (i = 0; i < bp->max_tc; i++) {
  3847. bp->q_info[i].queue_id = *qptr++;
  3848. bp->q_info[i].queue_profile = *qptr++;
  3849. }
  3850. qportcfg_exit:
  3851. mutex_unlock(&bp->hwrm_cmd_lock);
  3852. return rc;
  3853. }
  3854. static int bnxt_hwrm_ver_get(struct bnxt *bp)
  3855. {
  3856. int rc;
  3857. struct hwrm_ver_get_input req = {0};
  3858. struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
  3859. bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
  3860. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1);
  3861. req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
  3862. req.hwrm_intf_min = HWRM_VERSION_MINOR;
  3863. req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
  3864. mutex_lock(&bp->hwrm_cmd_lock);
  3865. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3866. if (rc)
  3867. goto hwrm_ver_get_exit;
  3868. memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
  3869. bp->hwrm_spec_code = resp->hwrm_intf_maj << 16 |
  3870. resp->hwrm_intf_min << 8 | resp->hwrm_intf_upd;
  3871. if (resp->hwrm_intf_maj < 1) {
  3872. netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n",
  3873. resp->hwrm_intf_maj, resp->hwrm_intf_min,
  3874. resp->hwrm_intf_upd);
  3875. netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n");
  3876. }
  3877. snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d/%d.%d.%d",
  3878. resp->hwrm_fw_maj, resp->hwrm_fw_min, resp->hwrm_fw_bld,
  3879. resp->hwrm_intf_maj, resp->hwrm_intf_min, resp->hwrm_intf_upd);
  3880. bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
  3881. if (!bp->hwrm_cmd_timeout)
  3882. bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
  3883. if (resp->hwrm_intf_maj >= 1)
  3884. bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
  3885. bp->chip_num = le16_to_cpu(resp->chip_num);
  3886. if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev &&
  3887. !resp->chip_metal)
  3888. bp->flags |= BNXT_FLAG_CHIP_NITRO_A0;
  3889. hwrm_ver_get_exit:
  3890. mutex_unlock(&bp->hwrm_cmd_lock);
  3891. return rc;
  3892. }
  3893. int bnxt_hwrm_fw_set_time(struct bnxt *bp)
  3894. {
  3895. #if IS_ENABLED(CONFIG_RTC_LIB)
  3896. struct hwrm_fw_set_time_input req = {0};
  3897. struct rtc_time tm;
  3898. struct timeval tv;
  3899. if (bp->hwrm_spec_code < 0x10400)
  3900. return -EOPNOTSUPP;
  3901. do_gettimeofday(&tv);
  3902. rtc_time_to_tm(tv.tv_sec, &tm);
  3903. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1);
  3904. req.year = cpu_to_le16(1900 + tm.tm_year);
  3905. req.month = 1 + tm.tm_mon;
  3906. req.day = tm.tm_mday;
  3907. req.hour = tm.tm_hour;
  3908. req.minute = tm.tm_min;
  3909. req.second = tm.tm_sec;
  3910. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3911. #else
  3912. return -EOPNOTSUPP;
  3913. #endif
  3914. }
  3915. static int bnxt_hwrm_port_qstats(struct bnxt *bp)
  3916. {
  3917. int rc;
  3918. struct bnxt_pf_info *pf = &bp->pf;
  3919. struct hwrm_port_qstats_input req = {0};
  3920. if (!(bp->flags & BNXT_FLAG_PORT_STATS))
  3921. return 0;
  3922. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1);
  3923. req.port_id = cpu_to_le16(pf->port_id);
  3924. req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map);
  3925. req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map);
  3926. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  3927. return rc;
  3928. }
  3929. static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp)
  3930. {
  3931. if (bp->vxlan_port_cnt) {
  3932. bnxt_hwrm_tunnel_dst_port_free(
  3933. bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
  3934. }
  3935. bp->vxlan_port_cnt = 0;
  3936. if (bp->nge_port_cnt) {
  3937. bnxt_hwrm_tunnel_dst_port_free(
  3938. bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
  3939. }
  3940. bp->nge_port_cnt = 0;
  3941. }
  3942. static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa)
  3943. {
  3944. int rc, i;
  3945. u32 tpa_flags = 0;
  3946. if (set_tpa)
  3947. tpa_flags = bp->flags & BNXT_FLAG_TPA;
  3948. for (i = 0; i < bp->nr_vnics; i++) {
  3949. rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags);
  3950. if (rc) {
  3951. netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n",
  3952. i, rc);
  3953. return rc;
  3954. }
  3955. }
  3956. return 0;
  3957. }
  3958. static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp)
  3959. {
  3960. int i;
  3961. for (i = 0; i < bp->nr_vnics; i++)
  3962. bnxt_hwrm_vnic_set_rss(bp, i, false);
  3963. }
  3964. static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path,
  3965. bool irq_re_init)
  3966. {
  3967. if (bp->vnic_info) {
  3968. bnxt_hwrm_clear_vnic_filter(bp);
  3969. /* clear all RSS setting before free vnic ctx */
  3970. bnxt_hwrm_clear_vnic_rss(bp);
  3971. bnxt_hwrm_vnic_ctx_free(bp);
  3972. /* before free the vnic, undo the vnic tpa settings */
  3973. if (bp->flags & BNXT_FLAG_TPA)
  3974. bnxt_set_tpa(bp, false);
  3975. bnxt_hwrm_vnic_free(bp);
  3976. }
  3977. bnxt_hwrm_ring_free(bp, close_path);
  3978. bnxt_hwrm_ring_grp_free(bp);
  3979. if (irq_re_init) {
  3980. bnxt_hwrm_stat_ctx_free(bp);
  3981. bnxt_hwrm_free_tunnel_ports(bp);
  3982. }
  3983. }
  3984. static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id)
  3985. {
  3986. struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
  3987. int rc;
  3988. if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG)
  3989. goto skip_rss_ctx;
  3990. /* allocate context for vnic */
  3991. rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0);
  3992. if (rc) {
  3993. netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
  3994. vnic_id, rc);
  3995. goto vnic_setup_err;
  3996. }
  3997. bp->rsscos_nr_ctxs++;
  3998. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  3999. rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1);
  4000. if (rc) {
  4001. netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n",
  4002. vnic_id, rc);
  4003. goto vnic_setup_err;
  4004. }
  4005. bp->rsscos_nr_ctxs++;
  4006. }
  4007. skip_rss_ctx:
  4008. /* configure default vnic, ring grp */
  4009. rc = bnxt_hwrm_vnic_cfg(bp, vnic_id);
  4010. if (rc) {
  4011. netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n",
  4012. vnic_id, rc);
  4013. goto vnic_setup_err;
  4014. }
  4015. /* Enable RSS hashing on vnic */
  4016. rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true);
  4017. if (rc) {
  4018. netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n",
  4019. vnic_id, rc);
  4020. goto vnic_setup_err;
  4021. }
  4022. if (bp->flags & BNXT_FLAG_AGG_RINGS) {
  4023. rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id);
  4024. if (rc) {
  4025. netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n",
  4026. vnic_id, rc);
  4027. }
  4028. }
  4029. vnic_setup_err:
  4030. return rc;
  4031. }
  4032. static int bnxt_alloc_rfs_vnics(struct bnxt *bp)
  4033. {
  4034. #ifdef CONFIG_RFS_ACCEL
  4035. int i, rc = 0;
  4036. for (i = 0; i < bp->rx_nr_rings; i++) {
  4037. struct bnxt_vnic_info *vnic;
  4038. u16 vnic_id = i + 1;
  4039. u16 ring_id = i;
  4040. if (vnic_id >= bp->nr_vnics)
  4041. break;
  4042. vnic = &bp->vnic_info[vnic_id];
  4043. vnic->flags |= BNXT_VNIC_RFS_FLAG;
  4044. if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
  4045. vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG;
  4046. rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1);
  4047. if (rc) {
  4048. netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n",
  4049. vnic_id, rc);
  4050. break;
  4051. }
  4052. rc = bnxt_setup_vnic(bp, vnic_id);
  4053. if (rc)
  4054. break;
  4055. }
  4056. return rc;
  4057. #else
  4058. return 0;
  4059. #endif
  4060. }
  4061. /* Allow PF and VF with default VLAN to be in promiscuous mode */
  4062. static bool bnxt_promisc_ok(struct bnxt *bp)
  4063. {
  4064. #ifdef CONFIG_BNXT_SRIOV
  4065. if (BNXT_VF(bp) && !bp->vf.vlan)
  4066. return false;
  4067. #endif
  4068. return true;
  4069. }
  4070. static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
  4071. {
  4072. unsigned int rc = 0;
  4073. rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1);
  4074. if (rc) {
  4075. netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
  4076. rc);
  4077. return rc;
  4078. }
  4079. rc = bnxt_hwrm_vnic_cfg(bp, 1);
  4080. if (rc) {
  4081. netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n",
  4082. rc);
  4083. return rc;
  4084. }
  4085. return rc;
  4086. }
  4087. static int bnxt_cfg_rx_mode(struct bnxt *);
  4088. static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
  4089. static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
  4090. {
  4091. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  4092. int rc = 0;
  4093. unsigned int rx_nr_rings = bp->rx_nr_rings;
  4094. if (irq_re_init) {
  4095. rc = bnxt_hwrm_stat_ctx_alloc(bp);
  4096. if (rc) {
  4097. netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n",
  4098. rc);
  4099. goto err_out;
  4100. }
  4101. }
  4102. rc = bnxt_hwrm_ring_alloc(bp);
  4103. if (rc) {
  4104. netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc);
  4105. goto err_out;
  4106. }
  4107. rc = bnxt_hwrm_ring_grp_alloc(bp);
  4108. if (rc) {
  4109. netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc);
  4110. goto err_out;
  4111. }
  4112. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  4113. rx_nr_rings--;
  4114. /* default vnic 0 */
  4115. rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings);
  4116. if (rc) {
  4117. netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc);
  4118. goto err_out;
  4119. }
  4120. rc = bnxt_setup_vnic(bp, 0);
  4121. if (rc)
  4122. goto err_out;
  4123. if (bp->flags & BNXT_FLAG_RFS) {
  4124. rc = bnxt_alloc_rfs_vnics(bp);
  4125. if (rc)
  4126. goto err_out;
  4127. }
  4128. if (bp->flags & BNXT_FLAG_TPA) {
  4129. rc = bnxt_set_tpa(bp, true);
  4130. if (rc)
  4131. goto err_out;
  4132. }
  4133. if (BNXT_VF(bp))
  4134. bnxt_update_vf_mac(bp);
  4135. /* Filter for default vnic 0 */
  4136. rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr);
  4137. if (rc) {
  4138. netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc);
  4139. goto err_out;
  4140. }
  4141. vnic->uc_filter_count = 1;
  4142. vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
  4143. if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
  4144. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  4145. if (bp->dev->flags & IFF_ALLMULTI) {
  4146. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  4147. vnic->mc_list_count = 0;
  4148. } else {
  4149. u32 mask = 0;
  4150. bnxt_mc_list_updated(bp, &mask);
  4151. vnic->rx_mask |= mask;
  4152. }
  4153. rc = bnxt_cfg_rx_mode(bp);
  4154. if (rc)
  4155. goto err_out;
  4156. rc = bnxt_hwrm_set_coal(bp);
  4157. if (rc)
  4158. netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n",
  4159. rc);
  4160. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  4161. rc = bnxt_setup_nitroa0_vnic(bp);
  4162. if (rc)
  4163. netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n",
  4164. rc);
  4165. }
  4166. if (BNXT_VF(bp)) {
  4167. bnxt_hwrm_func_qcfg(bp);
  4168. netdev_update_features(bp->dev);
  4169. }
  4170. return 0;
  4171. err_out:
  4172. bnxt_hwrm_resource_free(bp, 0, true);
  4173. return rc;
  4174. }
  4175. static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init)
  4176. {
  4177. bnxt_hwrm_resource_free(bp, 1, irq_re_init);
  4178. return 0;
  4179. }
  4180. static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init)
  4181. {
  4182. bnxt_init_cp_rings(bp);
  4183. bnxt_init_rx_rings(bp);
  4184. bnxt_init_tx_rings(bp);
  4185. bnxt_init_ring_grps(bp, irq_re_init);
  4186. bnxt_init_vnics(bp);
  4187. return bnxt_init_chip(bp, irq_re_init);
  4188. }
  4189. static int bnxt_set_real_num_queues(struct bnxt *bp)
  4190. {
  4191. int rc;
  4192. struct net_device *dev = bp->dev;
  4193. rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings -
  4194. bp->tx_nr_rings_xdp);
  4195. if (rc)
  4196. return rc;
  4197. rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings);
  4198. if (rc)
  4199. return rc;
  4200. #ifdef CONFIG_RFS_ACCEL
  4201. if (bp->flags & BNXT_FLAG_RFS)
  4202. dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings);
  4203. #endif
  4204. return rc;
  4205. }
  4206. static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
  4207. bool shared)
  4208. {
  4209. int _rx = *rx, _tx = *tx;
  4210. if (shared) {
  4211. *rx = min_t(int, _rx, max);
  4212. *tx = min_t(int, _tx, max);
  4213. } else {
  4214. if (max < 2)
  4215. return -ENOMEM;
  4216. while (_rx + _tx > max) {
  4217. if (_rx > _tx && _rx > 1)
  4218. _rx--;
  4219. else if (_tx > 1)
  4220. _tx--;
  4221. }
  4222. *rx = _rx;
  4223. *tx = _tx;
  4224. }
  4225. return 0;
  4226. }
  4227. static void bnxt_setup_msix(struct bnxt *bp)
  4228. {
  4229. const int len = sizeof(bp->irq_tbl[0].name);
  4230. struct net_device *dev = bp->dev;
  4231. int tcs, i;
  4232. tcs = netdev_get_num_tc(dev);
  4233. if (tcs > 1) {
  4234. int i, off, count;
  4235. for (i = 0; i < tcs; i++) {
  4236. count = bp->tx_nr_rings_per_tc;
  4237. off = i * count;
  4238. netdev_set_tc_queue(dev, i, count, off);
  4239. }
  4240. }
  4241. for (i = 0; i < bp->cp_nr_rings; i++) {
  4242. char *attr;
  4243. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  4244. attr = "TxRx";
  4245. else if (i < bp->rx_nr_rings)
  4246. attr = "rx";
  4247. else
  4248. attr = "tx";
  4249. snprintf(bp->irq_tbl[i].name, len, "%s-%s-%d", dev->name, attr,
  4250. i);
  4251. bp->irq_tbl[i].handler = bnxt_msix;
  4252. }
  4253. }
  4254. static void bnxt_setup_inta(struct bnxt *bp)
  4255. {
  4256. const int len = sizeof(bp->irq_tbl[0].name);
  4257. if (netdev_get_num_tc(bp->dev))
  4258. netdev_reset_tc(bp->dev);
  4259. snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx",
  4260. 0);
  4261. bp->irq_tbl[0].handler = bnxt_inta;
  4262. }
  4263. static int bnxt_setup_int_mode(struct bnxt *bp)
  4264. {
  4265. int rc;
  4266. if (bp->flags & BNXT_FLAG_USING_MSIX)
  4267. bnxt_setup_msix(bp);
  4268. else
  4269. bnxt_setup_inta(bp);
  4270. rc = bnxt_set_real_num_queues(bp);
  4271. return rc;
  4272. }
  4273. #ifdef CONFIG_RFS_ACCEL
  4274. static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp)
  4275. {
  4276. #if defined(CONFIG_BNXT_SRIOV)
  4277. if (BNXT_VF(bp))
  4278. return bp->vf.max_rsscos_ctxs;
  4279. #endif
  4280. return bp->pf.max_rsscos_ctxs;
  4281. }
  4282. static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp)
  4283. {
  4284. #if defined(CONFIG_BNXT_SRIOV)
  4285. if (BNXT_VF(bp))
  4286. return bp->vf.max_vnics;
  4287. #endif
  4288. return bp->pf.max_vnics;
  4289. }
  4290. #endif
  4291. unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp)
  4292. {
  4293. #if defined(CONFIG_BNXT_SRIOV)
  4294. if (BNXT_VF(bp))
  4295. return bp->vf.max_stat_ctxs;
  4296. #endif
  4297. return bp->pf.max_stat_ctxs;
  4298. }
  4299. void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max)
  4300. {
  4301. #if defined(CONFIG_BNXT_SRIOV)
  4302. if (BNXT_VF(bp))
  4303. bp->vf.max_stat_ctxs = max;
  4304. else
  4305. #endif
  4306. bp->pf.max_stat_ctxs = max;
  4307. }
  4308. unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp)
  4309. {
  4310. #if defined(CONFIG_BNXT_SRIOV)
  4311. if (BNXT_VF(bp))
  4312. return bp->vf.max_cp_rings;
  4313. #endif
  4314. return bp->pf.max_cp_rings;
  4315. }
  4316. void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
  4317. {
  4318. #if defined(CONFIG_BNXT_SRIOV)
  4319. if (BNXT_VF(bp))
  4320. bp->vf.max_cp_rings = max;
  4321. else
  4322. #endif
  4323. bp->pf.max_cp_rings = max;
  4324. }
  4325. static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
  4326. {
  4327. #if defined(CONFIG_BNXT_SRIOV)
  4328. if (BNXT_VF(bp))
  4329. return min_t(unsigned int, bp->vf.max_irqs,
  4330. bp->vf.max_cp_rings);
  4331. #endif
  4332. return min_t(unsigned int, bp->pf.max_irqs, bp->pf.max_cp_rings);
  4333. }
  4334. void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
  4335. {
  4336. #if defined(CONFIG_BNXT_SRIOV)
  4337. if (BNXT_VF(bp))
  4338. bp->vf.max_irqs = max_irqs;
  4339. else
  4340. #endif
  4341. bp->pf.max_irqs = max_irqs;
  4342. }
  4343. static int bnxt_init_msix(struct bnxt *bp)
  4344. {
  4345. int i, total_vecs, rc = 0, min = 1;
  4346. struct msix_entry *msix_ent;
  4347. total_vecs = bnxt_get_max_func_irqs(bp);
  4348. msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL);
  4349. if (!msix_ent)
  4350. return -ENOMEM;
  4351. for (i = 0; i < total_vecs; i++) {
  4352. msix_ent[i].entry = i;
  4353. msix_ent[i].vector = 0;
  4354. }
  4355. if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
  4356. min = 2;
  4357. total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
  4358. if (total_vecs < 0) {
  4359. rc = -ENODEV;
  4360. goto msix_setup_exit;
  4361. }
  4362. bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL);
  4363. if (bp->irq_tbl) {
  4364. for (i = 0; i < total_vecs; i++)
  4365. bp->irq_tbl[i].vector = msix_ent[i].vector;
  4366. bp->total_irqs = total_vecs;
  4367. /* Trim rings based upon num of vectors allocated */
  4368. rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
  4369. total_vecs, min == 1);
  4370. if (rc)
  4371. goto msix_setup_exit;
  4372. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  4373. bp->cp_nr_rings = (min == 1) ?
  4374. max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
  4375. bp->tx_nr_rings + bp->rx_nr_rings;
  4376. } else {
  4377. rc = -ENOMEM;
  4378. goto msix_setup_exit;
  4379. }
  4380. bp->flags |= BNXT_FLAG_USING_MSIX;
  4381. kfree(msix_ent);
  4382. return 0;
  4383. msix_setup_exit:
  4384. netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc);
  4385. kfree(bp->irq_tbl);
  4386. bp->irq_tbl = NULL;
  4387. pci_disable_msix(bp->pdev);
  4388. kfree(msix_ent);
  4389. return rc;
  4390. }
  4391. static int bnxt_init_inta(struct bnxt *bp)
  4392. {
  4393. bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL);
  4394. if (!bp->irq_tbl)
  4395. return -ENOMEM;
  4396. bp->total_irqs = 1;
  4397. bp->rx_nr_rings = 1;
  4398. bp->tx_nr_rings = 1;
  4399. bp->cp_nr_rings = 1;
  4400. bp->tx_nr_rings_per_tc = bp->tx_nr_rings;
  4401. bp->flags |= BNXT_FLAG_SHARED_RINGS;
  4402. bp->irq_tbl[0].vector = bp->pdev->irq;
  4403. return 0;
  4404. }
  4405. static int bnxt_init_int_mode(struct bnxt *bp)
  4406. {
  4407. int rc = 0;
  4408. if (bp->flags & BNXT_FLAG_MSIX_CAP)
  4409. rc = bnxt_init_msix(bp);
  4410. if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) {
  4411. /* fallback to INTA */
  4412. rc = bnxt_init_inta(bp);
  4413. }
  4414. return rc;
  4415. }
  4416. static void bnxt_clear_int_mode(struct bnxt *bp)
  4417. {
  4418. if (bp->flags & BNXT_FLAG_USING_MSIX)
  4419. pci_disable_msix(bp->pdev);
  4420. kfree(bp->irq_tbl);
  4421. bp->irq_tbl = NULL;
  4422. bp->flags &= ~BNXT_FLAG_USING_MSIX;
  4423. }
  4424. static void bnxt_free_irq(struct bnxt *bp)
  4425. {
  4426. struct bnxt_irq *irq;
  4427. int i;
  4428. #ifdef CONFIG_RFS_ACCEL
  4429. free_irq_cpu_rmap(bp->dev->rx_cpu_rmap);
  4430. bp->dev->rx_cpu_rmap = NULL;
  4431. #endif
  4432. if (!bp->irq_tbl)
  4433. return;
  4434. for (i = 0; i < bp->cp_nr_rings; i++) {
  4435. irq = &bp->irq_tbl[i];
  4436. if (irq->requested)
  4437. free_irq(irq->vector, bp->bnapi[i]);
  4438. irq->requested = 0;
  4439. }
  4440. }
  4441. static int bnxt_request_irq(struct bnxt *bp)
  4442. {
  4443. int i, j, rc = 0;
  4444. unsigned long flags = 0;
  4445. #ifdef CONFIG_RFS_ACCEL
  4446. struct cpu_rmap *rmap = bp->dev->rx_cpu_rmap;
  4447. #endif
  4448. if (!(bp->flags & BNXT_FLAG_USING_MSIX))
  4449. flags = IRQF_SHARED;
  4450. for (i = 0, j = 0; i < bp->cp_nr_rings; i++) {
  4451. struct bnxt_irq *irq = &bp->irq_tbl[i];
  4452. #ifdef CONFIG_RFS_ACCEL
  4453. if (rmap && bp->bnapi[i]->rx_ring) {
  4454. rc = irq_cpu_rmap_add(rmap, irq->vector);
  4455. if (rc)
  4456. netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n",
  4457. j);
  4458. j++;
  4459. }
  4460. #endif
  4461. rc = request_irq(irq->vector, irq->handler, flags, irq->name,
  4462. bp->bnapi[i]);
  4463. if (rc)
  4464. break;
  4465. irq->requested = 1;
  4466. }
  4467. return rc;
  4468. }
  4469. static void bnxt_del_napi(struct bnxt *bp)
  4470. {
  4471. int i;
  4472. if (!bp->bnapi)
  4473. return;
  4474. for (i = 0; i < bp->cp_nr_rings; i++) {
  4475. struct bnxt_napi *bnapi = bp->bnapi[i];
  4476. napi_hash_del(&bnapi->napi);
  4477. netif_napi_del(&bnapi->napi);
  4478. }
  4479. /* We called napi_hash_del() before netif_napi_del(), we need
  4480. * to respect an RCU grace period before freeing napi structures.
  4481. */
  4482. synchronize_net();
  4483. }
  4484. static void bnxt_init_napi(struct bnxt *bp)
  4485. {
  4486. int i;
  4487. unsigned int cp_nr_rings = bp->cp_nr_rings;
  4488. struct bnxt_napi *bnapi;
  4489. if (bp->flags & BNXT_FLAG_USING_MSIX) {
  4490. if (BNXT_CHIP_TYPE_NITRO_A0(bp))
  4491. cp_nr_rings--;
  4492. for (i = 0; i < cp_nr_rings; i++) {
  4493. bnapi = bp->bnapi[i];
  4494. netif_napi_add(bp->dev, &bnapi->napi,
  4495. bnxt_poll, 64);
  4496. }
  4497. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  4498. bnapi = bp->bnapi[cp_nr_rings];
  4499. netif_napi_add(bp->dev, &bnapi->napi,
  4500. bnxt_poll_nitroa0, 64);
  4501. }
  4502. } else {
  4503. bnapi = bp->bnapi[0];
  4504. netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
  4505. }
  4506. }
  4507. static void bnxt_disable_napi(struct bnxt *bp)
  4508. {
  4509. int i;
  4510. if (!bp->bnapi)
  4511. return;
  4512. for (i = 0; i < bp->cp_nr_rings; i++)
  4513. napi_disable(&bp->bnapi[i]->napi);
  4514. }
  4515. static void bnxt_enable_napi(struct bnxt *bp)
  4516. {
  4517. int i;
  4518. for (i = 0; i < bp->cp_nr_rings; i++) {
  4519. bp->bnapi[i]->in_reset = false;
  4520. napi_enable(&bp->bnapi[i]->napi);
  4521. }
  4522. }
  4523. void bnxt_tx_disable(struct bnxt *bp)
  4524. {
  4525. int i;
  4526. struct bnxt_tx_ring_info *txr;
  4527. struct netdev_queue *txq;
  4528. if (bp->tx_ring) {
  4529. for (i = 0; i < bp->tx_nr_rings; i++) {
  4530. txr = &bp->tx_ring[i];
  4531. txq = netdev_get_tx_queue(bp->dev, i);
  4532. txr->dev_state = BNXT_DEV_STATE_CLOSING;
  4533. }
  4534. }
  4535. /* Stop all TX queues */
  4536. netif_tx_disable(bp->dev);
  4537. netif_carrier_off(bp->dev);
  4538. }
  4539. void bnxt_tx_enable(struct bnxt *bp)
  4540. {
  4541. int i;
  4542. struct bnxt_tx_ring_info *txr;
  4543. struct netdev_queue *txq;
  4544. for (i = 0; i < bp->tx_nr_rings; i++) {
  4545. txr = &bp->tx_ring[i];
  4546. txq = netdev_get_tx_queue(bp->dev, i);
  4547. txr->dev_state = 0;
  4548. }
  4549. netif_tx_wake_all_queues(bp->dev);
  4550. if (bp->link_info.link_up)
  4551. netif_carrier_on(bp->dev);
  4552. }
  4553. static void bnxt_report_link(struct bnxt *bp)
  4554. {
  4555. if (bp->link_info.link_up) {
  4556. const char *duplex;
  4557. const char *flow_ctrl;
  4558. u32 speed;
  4559. u16 fec;
  4560. netif_carrier_on(bp->dev);
  4561. if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL)
  4562. duplex = "full";
  4563. else
  4564. duplex = "half";
  4565. if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH)
  4566. flow_ctrl = "ON - receive & transmit";
  4567. else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX)
  4568. flow_ctrl = "ON - transmit";
  4569. else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX)
  4570. flow_ctrl = "ON - receive";
  4571. else
  4572. flow_ctrl = "none";
  4573. speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed);
  4574. netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n",
  4575. speed, duplex, flow_ctrl);
  4576. if (bp->flags & BNXT_FLAG_EEE_CAP)
  4577. netdev_info(bp->dev, "EEE is %s\n",
  4578. bp->eee.eee_active ? "active" :
  4579. "not active");
  4580. fec = bp->link_info.fec_cfg;
  4581. if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED))
  4582. netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n",
  4583. (fec & BNXT_FEC_AUTONEG) ? "on" : "off",
  4584. (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" :
  4585. (fec & BNXT_FEC_ENC_RS) ? "RS" : "None");
  4586. } else {
  4587. netif_carrier_off(bp->dev);
  4588. netdev_err(bp->dev, "NIC Link is Down\n");
  4589. }
  4590. }
  4591. static int bnxt_hwrm_phy_qcaps(struct bnxt *bp)
  4592. {
  4593. int rc = 0;
  4594. struct hwrm_port_phy_qcaps_input req = {0};
  4595. struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
  4596. struct bnxt_link_info *link_info = &bp->link_info;
  4597. if (bp->hwrm_spec_code < 0x10201)
  4598. return 0;
  4599. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
  4600. mutex_lock(&bp->hwrm_cmd_lock);
  4601. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4602. if (rc)
  4603. goto hwrm_phy_qcaps_exit;
  4604. if (resp->eee_supported & PORT_PHY_QCAPS_RESP_EEE_SUPPORTED) {
  4605. struct ethtool_eee *eee = &bp->eee;
  4606. u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode);
  4607. bp->flags |= BNXT_FLAG_EEE_CAP;
  4608. eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
  4609. bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) &
  4610. PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK;
  4611. bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) &
  4612. PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK;
  4613. }
  4614. if (resp->supported_speeds_auto_mode)
  4615. link_info->support_auto_speeds =
  4616. le16_to_cpu(resp->supported_speeds_auto_mode);
  4617. hwrm_phy_qcaps_exit:
  4618. mutex_unlock(&bp->hwrm_cmd_lock);
  4619. return rc;
  4620. }
  4621. static int bnxt_update_link(struct bnxt *bp, bool chng_link_state)
  4622. {
  4623. int rc = 0;
  4624. struct bnxt_link_info *link_info = &bp->link_info;
  4625. struct hwrm_port_phy_qcfg_input req = {0};
  4626. struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
  4627. u8 link_up = link_info->link_up;
  4628. u16 diff;
  4629. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1);
  4630. mutex_lock(&bp->hwrm_cmd_lock);
  4631. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4632. if (rc) {
  4633. mutex_unlock(&bp->hwrm_cmd_lock);
  4634. return rc;
  4635. }
  4636. memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
  4637. link_info->phy_link_status = resp->link;
  4638. link_info->duplex = resp->duplex;
  4639. link_info->pause = resp->pause;
  4640. link_info->auto_mode = resp->auto_mode;
  4641. link_info->auto_pause_setting = resp->auto_pause;
  4642. link_info->lp_pause = resp->link_partner_adv_pause;
  4643. link_info->force_pause_setting = resp->force_pause;
  4644. link_info->duplex_setting = resp->duplex;
  4645. if (link_info->phy_link_status == BNXT_LINK_LINK)
  4646. link_info->link_speed = le16_to_cpu(resp->link_speed);
  4647. else
  4648. link_info->link_speed = 0;
  4649. link_info->force_link_speed = le16_to_cpu(resp->force_link_speed);
  4650. link_info->support_speeds = le16_to_cpu(resp->support_speeds);
  4651. link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask);
  4652. link_info->lp_auto_link_speeds =
  4653. le16_to_cpu(resp->link_partner_adv_speeds);
  4654. link_info->preemphasis = le32_to_cpu(resp->preemphasis);
  4655. link_info->phy_ver[0] = resp->phy_maj;
  4656. link_info->phy_ver[1] = resp->phy_min;
  4657. link_info->phy_ver[2] = resp->phy_bld;
  4658. link_info->media_type = resp->media_type;
  4659. link_info->phy_type = resp->phy_type;
  4660. link_info->transceiver = resp->xcvr_pkg_type;
  4661. link_info->phy_addr = resp->eee_config_phy_addr &
  4662. PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
  4663. link_info->module_status = resp->module_status;
  4664. if (bp->flags & BNXT_FLAG_EEE_CAP) {
  4665. struct ethtool_eee *eee = &bp->eee;
  4666. u16 fw_speeds;
  4667. eee->eee_active = 0;
  4668. if (resp->eee_config_phy_addr &
  4669. PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) {
  4670. eee->eee_active = 1;
  4671. fw_speeds = le16_to_cpu(
  4672. resp->link_partner_adv_eee_link_speed_mask);
  4673. eee->lp_advertised =
  4674. _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
  4675. }
  4676. /* Pull initial EEE config */
  4677. if (!chng_link_state) {
  4678. if (resp->eee_config_phy_addr &
  4679. PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED)
  4680. eee->eee_enabled = 1;
  4681. fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask);
  4682. eee->advertised =
  4683. _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0);
  4684. if (resp->eee_config_phy_addr &
  4685. PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) {
  4686. __le32 tmr;
  4687. eee->tx_lpi_enabled = 1;
  4688. tmr = resp->xcvr_identifier_type_tx_lpi_timer;
  4689. eee->tx_lpi_timer = le32_to_cpu(tmr) &
  4690. PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK;
  4691. }
  4692. }
  4693. }
  4694. link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED;
  4695. if (bp->hwrm_spec_code >= 0x10504)
  4696. link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
  4697. /* TODO: need to add more logic to report VF link */
  4698. if (chng_link_state) {
  4699. if (link_info->phy_link_status == BNXT_LINK_LINK)
  4700. link_info->link_up = 1;
  4701. else
  4702. link_info->link_up = 0;
  4703. if (link_up != link_info->link_up)
  4704. bnxt_report_link(bp);
  4705. } else {
  4706. /* alwasy link down if not require to update link state */
  4707. link_info->link_up = 0;
  4708. }
  4709. mutex_unlock(&bp->hwrm_cmd_lock);
  4710. diff = link_info->support_auto_speeds ^ link_info->advertising;
  4711. if ((link_info->support_auto_speeds | diff) !=
  4712. link_info->support_auto_speeds) {
  4713. /* An advertised speed is no longer supported, so we need to
  4714. * update the advertisement settings. Caller holds RTNL
  4715. * so we can modify link settings.
  4716. */
  4717. link_info->advertising = link_info->support_auto_speeds;
  4718. if (link_info->autoneg & BNXT_AUTONEG_SPEED)
  4719. bnxt_hwrm_set_link_setting(bp, true, false);
  4720. }
  4721. return 0;
  4722. }
  4723. static void bnxt_get_port_module_status(struct bnxt *bp)
  4724. {
  4725. struct bnxt_link_info *link_info = &bp->link_info;
  4726. struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp;
  4727. u8 module_status;
  4728. if (bnxt_update_link(bp, true))
  4729. return;
  4730. module_status = link_info->module_status;
  4731. switch (module_status) {
  4732. case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX:
  4733. case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN:
  4734. case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG:
  4735. netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n",
  4736. bp->pf.port_id);
  4737. if (bp->hwrm_spec_code >= 0x10201) {
  4738. netdev_warn(bp->dev, "Module part number %s\n",
  4739. resp->phy_vendor_partnumber);
  4740. }
  4741. if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX)
  4742. netdev_warn(bp->dev, "TX is disabled\n");
  4743. if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN)
  4744. netdev_warn(bp->dev, "SFP+ module is shutdown\n");
  4745. }
  4746. }
  4747. static void
  4748. bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
  4749. {
  4750. if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) {
  4751. if (bp->hwrm_spec_code >= 0x10201)
  4752. req->auto_pause =
  4753. PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
  4754. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
  4755. req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX;
  4756. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
  4757. req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX;
  4758. req->enables |=
  4759. cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
  4760. } else {
  4761. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX)
  4762. req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX;
  4763. if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX)
  4764. req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX;
  4765. req->enables |=
  4766. cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE);
  4767. if (bp->hwrm_spec_code >= 0x10201) {
  4768. req->auto_pause = req->force_pause;
  4769. req->enables |= cpu_to_le32(
  4770. PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE);
  4771. }
  4772. }
  4773. }
  4774. static void bnxt_hwrm_set_link_common(struct bnxt *bp,
  4775. struct hwrm_port_phy_cfg_input *req)
  4776. {
  4777. u8 autoneg = bp->link_info.autoneg;
  4778. u16 fw_link_speed = bp->link_info.req_link_speed;
  4779. u16 advertising = bp->link_info.advertising;
  4780. if (autoneg & BNXT_AUTONEG_SPEED) {
  4781. req->auto_mode |=
  4782. PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK;
  4783. req->enables |= cpu_to_le32(
  4784. PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK);
  4785. req->auto_link_speed_mask = cpu_to_le16(advertising);
  4786. req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE);
  4787. req->flags |=
  4788. cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG);
  4789. } else {
  4790. req->force_link_speed = cpu_to_le16(fw_link_speed);
  4791. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE);
  4792. }
  4793. /* tell chimp that the setting takes effect immediately */
  4794. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
  4795. }
  4796. int bnxt_hwrm_set_pause(struct bnxt *bp)
  4797. {
  4798. struct hwrm_port_phy_cfg_input req = {0};
  4799. int rc;
  4800. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
  4801. bnxt_hwrm_set_pause_common(bp, &req);
  4802. if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
  4803. bp->link_info.force_link_chng)
  4804. bnxt_hwrm_set_link_common(bp, &req);
  4805. mutex_lock(&bp->hwrm_cmd_lock);
  4806. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4807. if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
  4808. /* since changing of pause setting doesn't trigger any link
  4809. * change event, the driver needs to update the current pause
  4810. * result upon successfully return of the phy_cfg command
  4811. */
  4812. bp->link_info.pause =
  4813. bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl;
  4814. bp->link_info.auto_pause_setting = 0;
  4815. if (!bp->link_info.force_link_chng)
  4816. bnxt_report_link(bp);
  4817. }
  4818. bp->link_info.force_link_chng = false;
  4819. mutex_unlock(&bp->hwrm_cmd_lock);
  4820. return rc;
  4821. }
  4822. static void bnxt_hwrm_set_eee(struct bnxt *bp,
  4823. struct hwrm_port_phy_cfg_input *req)
  4824. {
  4825. struct ethtool_eee *eee = &bp->eee;
  4826. if (eee->eee_enabled) {
  4827. u16 eee_speeds;
  4828. u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE;
  4829. if (eee->tx_lpi_enabled)
  4830. flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE;
  4831. else
  4832. flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE;
  4833. req->flags |= cpu_to_le32(flags);
  4834. eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised);
  4835. req->eee_link_speed_mask = cpu_to_le16(eee_speeds);
  4836. req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer);
  4837. } else {
  4838. req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE);
  4839. }
  4840. }
  4841. int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee)
  4842. {
  4843. struct hwrm_port_phy_cfg_input req = {0};
  4844. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
  4845. if (set_pause)
  4846. bnxt_hwrm_set_pause_common(bp, &req);
  4847. bnxt_hwrm_set_link_common(bp, &req);
  4848. if (set_eee)
  4849. bnxt_hwrm_set_eee(bp, &req);
  4850. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4851. }
  4852. static int bnxt_hwrm_shutdown_link(struct bnxt *bp)
  4853. {
  4854. struct hwrm_port_phy_cfg_input req = {0};
  4855. if (!BNXT_SINGLE_PF(bp))
  4856. return 0;
  4857. if (pci_num_vf(bp->pdev))
  4858. return 0;
  4859. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
  4860. req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
  4861. return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4862. }
  4863. static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
  4864. {
  4865. struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
  4866. struct hwrm_port_led_qcaps_input req = {0};
  4867. struct bnxt_pf_info *pf = &bp->pf;
  4868. int rc;
  4869. if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601)
  4870. return 0;
  4871. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1);
  4872. req.port_id = cpu_to_le16(pf->port_id);
  4873. mutex_lock(&bp->hwrm_cmd_lock);
  4874. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4875. if (rc) {
  4876. mutex_unlock(&bp->hwrm_cmd_lock);
  4877. return rc;
  4878. }
  4879. if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
  4880. int i;
  4881. bp->num_leds = resp->num_leds;
  4882. memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) *
  4883. bp->num_leds);
  4884. for (i = 0; i < bp->num_leds; i++) {
  4885. struct bnxt_led_info *led = &bp->leds[i];
  4886. __le16 caps = led->led_state_caps;
  4887. if (!led->led_group_id ||
  4888. !BNXT_LED_ALT_BLINK_CAP(caps)) {
  4889. bp->num_leds = 0;
  4890. break;
  4891. }
  4892. }
  4893. }
  4894. mutex_unlock(&bp->hwrm_cmd_lock);
  4895. return 0;
  4896. }
  4897. int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp)
  4898. {
  4899. struct hwrm_wol_filter_alloc_input req = {0};
  4900. struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
  4901. int rc;
  4902. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1);
  4903. req.port_id = cpu_to_le16(bp->pf.port_id);
  4904. req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT;
  4905. req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS);
  4906. memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN);
  4907. mutex_lock(&bp->hwrm_cmd_lock);
  4908. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4909. if (!rc)
  4910. bp->wol_filter_id = resp->wol_filter_id;
  4911. mutex_unlock(&bp->hwrm_cmd_lock);
  4912. return rc;
  4913. }
  4914. int bnxt_hwrm_free_wol_fltr(struct bnxt *bp)
  4915. {
  4916. struct hwrm_wol_filter_free_input req = {0};
  4917. int rc;
  4918. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1);
  4919. req.port_id = cpu_to_le16(bp->pf.port_id);
  4920. req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID);
  4921. req.wol_filter_id = bp->wol_filter_id;
  4922. rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4923. return rc;
  4924. }
  4925. static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle)
  4926. {
  4927. struct hwrm_wol_filter_qcfg_input req = {0};
  4928. struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
  4929. u16 next_handle = 0;
  4930. int rc;
  4931. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1);
  4932. req.port_id = cpu_to_le16(bp->pf.port_id);
  4933. req.handle = cpu_to_le16(handle);
  4934. mutex_lock(&bp->hwrm_cmd_lock);
  4935. rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
  4936. if (!rc) {
  4937. next_handle = le16_to_cpu(resp->next_handle);
  4938. if (next_handle != 0) {
  4939. if (resp->wol_type ==
  4940. WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) {
  4941. bp->wol = 1;
  4942. bp->wol_filter_id = resp->wol_filter_id;
  4943. }
  4944. }
  4945. }
  4946. mutex_unlock(&bp->hwrm_cmd_lock);
  4947. return next_handle;
  4948. }
  4949. static void bnxt_get_wol_settings(struct bnxt *bp)
  4950. {
  4951. u16 handle = 0;
  4952. if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP))
  4953. return;
  4954. do {
  4955. handle = bnxt_hwrm_get_wol_fltrs(bp, handle);
  4956. } while (handle && handle != 0xffff);
  4957. }
  4958. static bool bnxt_eee_config_ok(struct bnxt *bp)
  4959. {
  4960. struct ethtool_eee *eee = &bp->eee;
  4961. struct bnxt_link_info *link_info = &bp->link_info;
  4962. if (!(bp->flags & BNXT_FLAG_EEE_CAP))
  4963. return true;
  4964. if (eee->eee_enabled) {
  4965. u32 advertising =
  4966. _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
  4967. if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
  4968. eee->eee_enabled = 0;
  4969. return false;
  4970. }
  4971. if (eee->advertised & ~advertising) {
  4972. eee->advertised = advertising & eee->supported;
  4973. return false;
  4974. }
  4975. }
  4976. return true;
  4977. }
  4978. static int bnxt_update_phy_setting(struct bnxt *bp)
  4979. {
  4980. int rc;
  4981. bool update_link = false;
  4982. bool update_pause = false;
  4983. bool update_eee = false;
  4984. struct bnxt_link_info *link_info = &bp->link_info;
  4985. rc = bnxt_update_link(bp, true);
  4986. if (rc) {
  4987. netdev_err(bp->dev, "failed to update link (rc: %x)\n",
  4988. rc);
  4989. return rc;
  4990. }
  4991. if (!BNXT_SINGLE_PF(bp))
  4992. return 0;
  4993. if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
  4994. (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) !=
  4995. link_info->req_flow_ctrl)
  4996. update_pause = true;
  4997. if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) &&
  4998. link_info->force_pause_setting != link_info->req_flow_ctrl)
  4999. update_pause = true;
  5000. if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
  5001. if (BNXT_AUTO_MODE(link_info->auto_mode))
  5002. update_link = true;
  5003. if (link_info->req_link_speed != link_info->force_link_speed)
  5004. update_link = true;
  5005. if (link_info->req_duplex != link_info->duplex_setting)
  5006. update_link = true;
  5007. } else {
  5008. if (link_info->auto_mode == BNXT_LINK_AUTO_NONE)
  5009. update_link = true;
  5010. if (link_info->advertising != link_info->auto_link_speeds)
  5011. update_link = true;
  5012. }
  5013. /* The last close may have shutdown the link, so need to call
  5014. * PHY_CFG to bring it back up.
  5015. */
  5016. if (!netif_carrier_ok(bp->dev))
  5017. update_link = true;
  5018. if (!bnxt_eee_config_ok(bp))
  5019. update_eee = true;
  5020. if (update_link)
  5021. rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee);
  5022. else if (update_pause)
  5023. rc = bnxt_hwrm_set_pause(bp);
  5024. if (rc) {
  5025. netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n",
  5026. rc);
  5027. return rc;
  5028. }
  5029. return rc;
  5030. }
  5031. /* Common routine to pre-map certain register block to different GRC window.
  5032. * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows
  5033. * in PF and 3 windows in VF that can be customized to map in different
  5034. * register blocks.
  5035. */
  5036. static void bnxt_preset_reg_win(struct bnxt *bp)
  5037. {
  5038. if (BNXT_PF(bp)) {
  5039. /* CAG registers map to GRC window #4 */
  5040. writel(BNXT_CAG_REG_BASE,
  5041. bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12);
  5042. }
  5043. }
  5044. static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  5045. {
  5046. int rc = 0;
  5047. bnxt_preset_reg_win(bp);
  5048. netif_carrier_off(bp->dev);
  5049. if (irq_re_init) {
  5050. rc = bnxt_setup_int_mode(bp);
  5051. if (rc) {
  5052. netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n",
  5053. rc);
  5054. return rc;
  5055. }
  5056. }
  5057. if ((bp->flags & BNXT_FLAG_RFS) &&
  5058. !(bp->flags & BNXT_FLAG_USING_MSIX)) {
  5059. /* disable RFS if falling back to INTA */
  5060. bp->dev->hw_features &= ~NETIF_F_NTUPLE;
  5061. bp->flags &= ~BNXT_FLAG_RFS;
  5062. }
  5063. rc = bnxt_alloc_mem(bp, irq_re_init);
  5064. if (rc) {
  5065. netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
  5066. goto open_err_free_mem;
  5067. }
  5068. if (irq_re_init) {
  5069. bnxt_init_napi(bp);
  5070. rc = bnxt_request_irq(bp);
  5071. if (rc) {
  5072. netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc);
  5073. goto open_err;
  5074. }
  5075. }
  5076. bnxt_enable_napi(bp);
  5077. rc = bnxt_init_nic(bp, irq_re_init);
  5078. if (rc) {
  5079. netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
  5080. goto open_err;
  5081. }
  5082. if (link_re_init) {
  5083. rc = bnxt_update_phy_setting(bp);
  5084. if (rc)
  5085. netdev_warn(bp->dev, "failed to update phy settings\n");
  5086. }
  5087. if (irq_re_init)
  5088. udp_tunnel_get_rx_info(bp->dev);
  5089. set_bit(BNXT_STATE_OPEN, &bp->state);
  5090. bnxt_enable_int(bp);
  5091. /* Enable TX queues */
  5092. bnxt_tx_enable(bp);
  5093. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5094. /* Poll link status and check for SFP+ module status */
  5095. bnxt_get_port_module_status(bp);
  5096. return 0;
  5097. open_err:
  5098. bnxt_disable_napi(bp);
  5099. bnxt_del_napi(bp);
  5100. open_err_free_mem:
  5101. bnxt_free_skbs(bp);
  5102. bnxt_free_irq(bp);
  5103. bnxt_free_mem(bp, true);
  5104. return rc;
  5105. }
  5106. /* rtnl_lock held */
  5107. int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  5108. {
  5109. int rc = 0;
  5110. rc = __bnxt_open_nic(bp, irq_re_init, link_re_init);
  5111. if (rc) {
  5112. netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc);
  5113. dev_close(bp->dev);
  5114. }
  5115. return rc;
  5116. }
  5117. /* rtnl_lock held, open the NIC half way by allocating all resources, but
  5118. * NAPI, IRQ, and TX are not enabled. This is mainly used for offline
  5119. * self tests.
  5120. */
  5121. int bnxt_half_open_nic(struct bnxt *bp)
  5122. {
  5123. int rc = 0;
  5124. rc = bnxt_alloc_mem(bp, false);
  5125. if (rc) {
  5126. netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
  5127. goto half_open_err;
  5128. }
  5129. rc = bnxt_init_nic(bp, false);
  5130. if (rc) {
  5131. netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
  5132. goto half_open_err;
  5133. }
  5134. return 0;
  5135. half_open_err:
  5136. bnxt_free_skbs(bp);
  5137. bnxt_free_mem(bp, false);
  5138. dev_close(bp->dev);
  5139. return rc;
  5140. }
  5141. /* rtnl_lock held, this call can only be made after a previous successful
  5142. * call to bnxt_half_open_nic().
  5143. */
  5144. void bnxt_half_close_nic(struct bnxt *bp)
  5145. {
  5146. bnxt_hwrm_resource_free(bp, false, false);
  5147. bnxt_free_skbs(bp);
  5148. bnxt_free_mem(bp, false);
  5149. }
  5150. static int bnxt_open(struct net_device *dev)
  5151. {
  5152. struct bnxt *bp = netdev_priv(dev);
  5153. return __bnxt_open_nic(bp, true, true);
  5154. }
  5155. int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
  5156. {
  5157. int rc = 0;
  5158. #ifdef CONFIG_BNXT_SRIOV
  5159. if (bp->sriov_cfg) {
  5160. rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait,
  5161. !bp->sriov_cfg,
  5162. BNXT_SRIOV_CFG_WAIT_TMO);
  5163. if (rc)
  5164. netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n");
  5165. }
  5166. #endif
  5167. /* Change device state to avoid TX queue wake up's */
  5168. bnxt_tx_disable(bp);
  5169. clear_bit(BNXT_STATE_OPEN, &bp->state);
  5170. smp_mb__after_atomic();
  5171. while (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state))
  5172. msleep(20);
  5173. /* Flush rings and and disable interrupts */
  5174. bnxt_shutdown_nic(bp, irq_re_init);
  5175. /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */
  5176. bnxt_disable_napi(bp);
  5177. del_timer_sync(&bp->timer);
  5178. bnxt_free_skbs(bp);
  5179. if (irq_re_init) {
  5180. bnxt_free_irq(bp);
  5181. bnxt_del_napi(bp);
  5182. }
  5183. bnxt_free_mem(bp, irq_re_init);
  5184. return rc;
  5185. }
  5186. static int bnxt_close(struct net_device *dev)
  5187. {
  5188. struct bnxt *bp = netdev_priv(dev);
  5189. bnxt_close_nic(bp, true, true);
  5190. bnxt_hwrm_shutdown_link(bp);
  5191. return 0;
  5192. }
  5193. /* rtnl_lock held */
  5194. static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  5195. {
  5196. switch (cmd) {
  5197. case SIOCGMIIPHY:
  5198. /* fallthru */
  5199. case SIOCGMIIREG: {
  5200. if (!netif_running(dev))
  5201. return -EAGAIN;
  5202. return 0;
  5203. }
  5204. case SIOCSMIIREG:
  5205. if (!netif_running(dev))
  5206. return -EAGAIN;
  5207. return 0;
  5208. default:
  5209. /* do nothing */
  5210. break;
  5211. }
  5212. return -EOPNOTSUPP;
  5213. }
  5214. static void
  5215. bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
  5216. {
  5217. u32 i;
  5218. struct bnxt *bp = netdev_priv(dev);
  5219. if (!bp->bnapi)
  5220. return;
  5221. /* TODO check if we need to synchronize with bnxt_close path */
  5222. for (i = 0; i < bp->cp_nr_rings; i++) {
  5223. struct bnxt_napi *bnapi = bp->bnapi[i];
  5224. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5225. struct ctx_hw_stats *hw_stats = cpr->hw_stats;
  5226. stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts);
  5227. stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts);
  5228. stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts);
  5229. stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts);
  5230. stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts);
  5231. stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts);
  5232. stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes);
  5233. stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes);
  5234. stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes);
  5235. stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes);
  5236. stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes);
  5237. stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes);
  5238. stats->rx_missed_errors +=
  5239. le64_to_cpu(hw_stats->rx_discard_pkts);
  5240. stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts);
  5241. stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts);
  5242. }
  5243. if (bp->flags & BNXT_FLAG_PORT_STATS) {
  5244. struct rx_port_stats *rx = bp->hw_rx_port_stats;
  5245. struct tx_port_stats *tx = bp->hw_tx_port_stats;
  5246. stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames);
  5247. stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames);
  5248. stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) +
  5249. le64_to_cpu(rx->rx_ovrsz_frames) +
  5250. le64_to_cpu(rx->rx_runt_frames);
  5251. stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) +
  5252. le64_to_cpu(rx->rx_jbr_frames);
  5253. stats->collisions = le64_to_cpu(tx->tx_total_collisions);
  5254. stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns);
  5255. stats->tx_errors = le64_to_cpu(tx->tx_err);
  5256. }
  5257. }
  5258. static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
  5259. {
  5260. struct net_device *dev = bp->dev;
  5261. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  5262. struct netdev_hw_addr *ha;
  5263. u8 *haddr;
  5264. int mc_count = 0;
  5265. bool update = false;
  5266. int off = 0;
  5267. netdev_for_each_mc_addr(ha, dev) {
  5268. if (mc_count >= BNXT_MAX_MC_ADDRS) {
  5269. *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  5270. vnic->mc_list_count = 0;
  5271. return false;
  5272. }
  5273. haddr = ha->addr;
  5274. if (!ether_addr_equal(haddr, vnic->mc_list + off)) {
  5275. memcpy(vnic->mc_list + off, haddr, ETH_ALEN);
  5276. update = true;
  5277. }
  5278. off += ETH_ALEN;
  5279. mc_count++;
  5280. }
  5281. if (mc_count)
  5282. *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST;
  5283. if (mc_count != vnic->mc_list_count) {
  5284. vnic->mc_list_count = mc_count;
  5285. update = true;
  5286. }
  5287. return update;
  5288. }
  5289. static bool bnxt_uc_list_updated(struct bnxt *bp)
  5290. {
  5291. struct net_device *dev = bp->dev;
  5292. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  5293. struct netdev_hw_addr *ha;
  5294. int off = 0;
  5295. if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
  5296. return true;
  5297. netdev_for_each_uc_addr(ha, dev) {
  5298. if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
  5299. return true;
  5300. off += ETH_ALEN;
  5301. }
  5302. return false;
  5303. }
  5304. static void bnxt_set_rx_mode(struct net_device *dev)
  5305. {
  5306. struct bnxt *bp = netdev_priv(dev);
  5307. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  5308. u32 mask = vnic->rx_mask;
  5309. bool mc_update = false;
  5310. bool uc_update;
  5311. if (!netif_running(dev))
  5312. return;
  5313. mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS |
  5314. CFA_L2_SET_RX_MASK_REQ_MASK_MCAST |
  5315. CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST);
  5316. if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp))
  5317. mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  5318. uc_update = bnxt_uc_list_updated(bp);
  5319. if (dev->flags & IFF_ALLMULTI) {
  5320. mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
  5321. vnic->mc_list_count = 0;
  5322. } else {
  5323. mc_update = bnxt_mc_list_updated(bp, &mask);
  5324. }
  5325. if (mask != vnic->rx_mask || uc_update || mc_update) {
  5326. vnic->rx_mask = mask;
  5327. set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event);
  5328. schedule_work(&bp->sp_task);
  5329. }
  5330. }
  5331. static int bnxt_cfg_rx_mode(struct bnxt *bp)
  5332. {
  5333. struct net_device *dev = bp->dev;
  5334. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  5335. struct netdev_hw_addr *ha;
  5336. int i, off = 0, rc;
  5337. bool uc_update;
  5338. netif_addr_lock_bh(dev);
  5339. uc_update = bnxt_uc_list_updated(bp);
  5340. netif_addr_unlock_bh(dev);
  5341. if (!uc_update)
  5342. goto skip_uc;
  5343. mutex_lock(&bp->hwrm_cmd_lock);
  5344. for (i = 1; i < vnic->uc_filter_count; i++) {
  5345. struct hwrm_cfa_l2_filter_free_input req = {0};
  5346. bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1,
  5347. -1);
  5348. req.l2_filter_id = vnic->fw_l2_filter_id[i];
  5349. rc = _hwrm_send_message(bp, &req, sizeof(req),
  5350. HWRM_CMD_TIMEOUT);
  5351. }
  5352. mutex_unlock(&bp->hwrm_cmd_lock);
  5353. vnic->uc_filter_count = 1;
  5354. netif_addr_lock_bh(dev);
  5355. if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
  5356. vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
  5357. } else {
  5358. netdev_for_each_uc_addr(ha, dev) {
  5359. memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
  5360. off += ETH_ALEN;
  5361. vnic->uc_filter_count++;
  5362. }
  5363. }
  5364. netif_addr_unlock_bh(dev);
  5365. for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) {
  5366. rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off);
  5367. if (rc) {
  5368. netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n",
  5369. rc);
  5370. vnic->uc_filter_count = i;
  5371. return rc;
  5372. }
  5373. }
  5374. skip_uc:
  5375. rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0);
  5376. if (rc)
  5377. netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n",
  5378. rc);
  5379. return rc;
  5380. }
  5381. /* If the chip and firmware supports RFS */
  5382. static bool bnxt_rfs_supported(struct bnxt *bp)
  5383. {
  5384. if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
  5385. return true;
  5386. if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
  5387. return true;
  5388. return false;
  5389. }
  5390. /* If runtime conditions support RFS */
  5391. static bool bnxt_rfs_capable(struct bnxt *bp)
  5392. {
  5393. #ifdef CONFIG_RFS_ACCEL
  5394. int vnics, max_vnics, max_rss_ctxs;
  5395. if (!(bp->flags & BNXT_FLAG_MSIX_CAP))
  5396. return false;
  5397. vnics = 1 + bp->rx_nr_rings;
  5398. max_vnics = bnxt_get_max_func_vnics(bp);
  5399. max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp);
  5400. /* RSS contexts not a limiting factor */
  5401. if (bp->flags & BNXT_FLAG_NEW_RSS_CAP)
  5402. max_rss_ctxs = max_vnics;
  5403. if (vnics > max_vnics || vnics > max_rss_ctxs) {
  5404. netdev_warn(bp->dev,
  5405. "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n",
  5406. min(max_rss_ctxs - 1, max_vnics - 1));
  5407. return false;
  5408. }
  5409. return true;
  5410. #else
  5411. return false;
  5412. #endif
  5413. }
  5414. static netdev_features_t bnxt_fix_features(struct net_device *dev,
  5415. netdev_features_t features)
  5416. {
  5417. struct bnxt *bp = netdev_priv(dev);
  5418. if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp))
  5419. features &= ~NETIF_F_NTUPLE;
  5420. /* Both CTAG and STAG VLAN accelaration on the RX side have to be
  5421. * turned on or off together.
  5422. */
  5423. if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) !=
  5424. (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) {
  5425. if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
  5426. features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
  5427. NETIF_F_HW_VLAN_STAG_RX);
  5428. else
  5429. features |= NETIF_F_HW_VLAN_CTAG_RX |
  5430. NETIF_F_HW_VLAN_STAG_RX;
  5431. }
  5432. #ifdef CONFIG_BNXT_SRIOV
  5433. if (BNXT_VF(bp)) {
  5434. if (bp->vf.vlan) {
  5435. features &= ~(NETIF_F_HW_VLAN_CTAG_RX |
  5436. NETIF_F_HW_VLAN_STAG_RX);
  5437. }
  5438. }
  5439. #endif
  5440. return features;
  5441. }
  5442. static int bnxt_set_features(struct net_device *dev, netdev_features_t features)
  5443. {
  5444. struct bnxt *bp = netdev_priv(dev);
  5445. u32 flags = bp->flags;
  5446. u32 changes;
  5447. int rc = 0;
  5448. bool re_init = false;
  5449. bool update_tpa = false;
  5450. flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS;
  5451. if ((features & NETIF_F_GRO) && !BNXT_CHIP_TYPE_NITRO_A0(bp))
  5452. flags |= BNXT_FLAG_GRO;
  5453. if (features & NETIF_F_LRO)
  5454. flags |= BNXT_FLAG_LRO;
  5455. if (bp->flags & BNXT_FLAG_NO_AGG_RINGS)
  5456. flags &= ~BNXT_FLAG_TPA;
  5457. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  5458. flags |= BNXT_FLAG_STRIP_VLAN;
  5459. if (features & NETIF_F_NTUPLE)
  5460. flags |= BNXT_FLAG_RFS;
  5461. changes = flags ^ bp->flags;
  5462. if (changes & BNXT_FLAG_TPA) {
  5463. update_tpa = true;
  5464. if ((bp->flags & BNXT_FLAG_TPA) == 0 ||
  5465. (flags & BNXT_FLAG_TPA) == 0)
  5466. re_init = true;
  5467. }
  5468. if (changes & ~BNXT_FLAG_TPA)
  5469. re_init = true;
  5470. if (flags != bp->flags) {
  5471. u32 old_flags = bp->flags;
  5472. bp->flags = flags;
  5473. if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
  5474. if (update_tpa)
  5475. bnxt_set_ring_params(bp);
  5476. return rc;
  5477. }
  5478. if (re_init) {
  5479. bnxt_close_nic(bp, false, false);
  5480. if (update_tpa)
  5481. bnxt_set_ring_params(bp);
  5482. return bnxt_open_nic(bp, false, false);
  5483. }
  5484. if (update_tpa) {
  5485. rc = bnxt_set_tpa(bp,
  5486. (flags & BNXT_FLAG_TPA) ?
  5487. true : false);
  5488. if (rc)
  5489. bp->flags = old_flags;
  5490. }
  5491. }
  5492. return rc;
  5493. }
  5494. static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi)
  5495. {
  5496. struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
  5497. int i = bnapi->index;
  5498. if (!txr)
  5499. return;
  5500. netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n",
  5501. i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod,
  5502. txr->tx_cons);
  5503. }
  5504. static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi)
  5505. {
  5506. struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
  5507. int i = bnapi->index;
  5508. if (!rxr)
  5509. return;
  5510. 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",
  5511. i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod,
  5512. rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod,
  5513. rxr->rx_sw_agg_prod);
  5514. }
  5515. static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi)
  5516. {
  5517. struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
  5518. int i = bnapi->index;
  5519. netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n",
  5520. i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons);
  5521. }
  5522. static void bnxt_dbg_dump_states(struct bnxt *bp)
  5523. {
  5524. int i;
  5525. struct bnxt_napi *bnapi;
  5526. for (i = 0; i < bp->cp_nr_rings; i++) {
  5527. bnapi = bp->bnapi[i];
  5528. if (netif_msg_drv(bp)) {
  5529. bnxt_dump_tx_sw_state(bnapi);
  5530. bnxt_dump_rx_sw_state(bnapi);
  5531. bnxt_dump_cp_sw_state(bnapi);
  5532. }
  5533. }
  5534. }
  5535. static void bnxt_reset_task(struct bnxt *bp, bool silent)
  5536. {
  5537. if (!silent)
  5538. bnxt_dbg_dump_states(bp);
  5539. if (netif_running(bp->dev)) {
  5540. int rc;
  5541. if (!silent)
  5542. bnxt_ulp_stop(bp);
  5543. bnxt_close_nic(bp, false, false);
  5544. rc = bnxt_open_nic(bp, false, false);
  5545. if (!silent && !rc)
  5546. bnxt_ulp_start(bp);
  5547. }
  5548. }
  5549. static void bnxt_tx_timeout(struct net_device *dev)
  5550. {
  5551. struct bnxt *bp = netdev_priv(dev);
  5552. netdev_err(bp->dev, "TX timeout detected, starting reset task!\n");
  5553. set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event);
  5554. schedule_work(&bp->sp_task);
  5555. }
  5556. #ifdef CONFIG_NET_POLL_CONTROLLER
  5557. static void bnxt_poll_controller(struct net_device *dev)
  5558. {
  5559. struct bnxt *bp = netdev_priv(dev);
  5560. int i;
  5561. for (i = 0; i < bp->cp_nr_rings; i++) {
  5562. struct bnxt_irq *irq = &bp->irq_tbl[i];
  5563. disable_irq(irq->vector);
  5564. irq->handler(irq->vector, bp->bnapi[i]);
  5565. enable_irq(irq->vector);
  5566. }
  5567. }
  5568. #endif
  5569. static void bnxt_timer(unsigned long data)
  5570. {
  5571. struct bnxt *bp = (struct bnxt *)data;
  5572. struct net_device *dev = bp->dev;
  5573. if (!netif_running(dev))
  5574. return;
  5575. if (atomic_read(&bp->intr_sem) != 0)
  5576. goto bnxt_restart_timer;
  5577. if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS)) {
  5578. set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event);
  5579. schedule_work(&bp->sp_task);
  5580. }
  5581. bnxt_restart_timer:
  5582. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5583. }
  5584. static void bnxt_rtnl_lock_sp(struct bnxt *bp)
  5585. {
  5586. /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK
  5587. * set. If the device is being closed, bnxt_close() may be holding
  5588. * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we
  5589. * must clear BNXT_STATE_IN_SP_TASK before holding rtnl().
  5590. */
  5591. clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  5592. rtnl_lock();
  5593. }
  5594. static void bnxt_rtnl_unlock_sp(struct bnxt *bp)
  5595. {
  5596. set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  5597. rtnl_unlock();
  5598. }
  5599. /* Only called from bnxt_sp_task() */
  5600. static void bnxt_reset(struct bnxt *bp, bool silent)
  5601. {
  5602. bnxt_rtnl_lock_sp(bp);
  5603. if (test_bit(BNXT_STATE_OPEN, &bp->state))
  5604. bnxt_reset_task(bp, silent);
  5605. bnxt_rtnl_unlock_sp(bp);
  5606. }
  5607. static void bnxt_cfg_ntp_filters(struct bnxt *);
  5608. static void bnxt_sp_task(struct work_struct *work)
  5609. {
  5610. struct bnxt *bp = container_of(work, struct bnxt, sp_task);
  5611. set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  5612. smp_mb__after_atomic();
  5613. if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
  5614. clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  5615. return;
  5616. }
  5617. if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
  5618. bnxt_cfg_rx_mode(bp);
  5619. if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
  5620. bnxt_cfg_ntp_filters(bp);
  5621. if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
  5622. bnxt_hwrm_exec_fwd_req(bp);
  5623. if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) {
  5624. bnxt_hwrm_tunnel_dst_port_alloc(
  5625. bp, bp->vxlan_port,
  5626. TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
  5627. }
  5628. if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) {
  5629. bnxt_hwrm_tunnel_dst_port_free(
  5630. bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
  5631. }
  5632. if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) {
  5633. bnxt_hwrm_tunnel_dst_port_alloc(
  5634. bp, bp->nge_port,
  5635. TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
  5636. }
  5637. if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) {
  5638. bnxt_hwrm_tunnel_dst_port_free(
  5639. bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE);
  5640. }
  5641. if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event))
  5642. bnxt_hwrm_port_qstats(bp);
  5643. /* These functions below will clear BNXT_STATE_IN_SP_TASK. They
  5644. * must be the last functions to be called before exiting.
  5645. */
  5646. if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) {
  5647. int rc = 0;
  5648. if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT,
  5649. &bp->sp_event))
  5650. bnxt_hwrm_phy_qcaps(bp);
  5651. bnxt_rtnl_lock_sp(bp);
  5652. if (test_bit(BNXT_STATE_OPEN, &bp->state))
  5653. rc = bnxt_update_link(bp, true);
  5654. bnxt_rtnl_unlock_sp(bp);
  5655. if (rc)
  5656. netdev_err(bp->dev, "SP task can't update link (rc: %x)\n",
  5657. rc);
  5658. }
  5659. if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) {
  5660. bnxt_rtnl_lock_sp(bp);
  5661. if (test_bit(BNXT_STATE_OPEN, &bp->state))
  5662. bnxt_get_port_module_status(bp);
  5663. bnxt_rtnl_unlock_sp(bp);
  5664. }
  5665. if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
  5666. bnxt_reset(bp, false);
  5667. if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event))
  5668. bnxt_reset(bp, true);
  5669. smp_mb__before_atomic();
  5670. clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
  5671. }
  5672. /* Under rtnl_lock */
  5673. int bnxt_reserve_rings(struct bnxt *bp, int tx, int rx, int tcs, int tx_xdp)
  5674. {
  5675. int max_rx, max_tx, tx_sets = 1;
  5676. int tx_rings_needed;
  5677. bool sh = true;
  5678. int rc;
  5679. if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
  5680. sh = false;
  5681. if (tcs)
  5682. tx_sets = tcs;
  5683. rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
  5684. if (rc)
  5685. return rc;
  5686. if (max_rx < rx)
  5687. return -ENOMEM;
  5688. tx_rings_needed = tx * tx_sets + tx_xdp;
  5689. if (max_tx < tx_rings_needed)
  5690. return -ENOMEM;
  5691. if (bnxt_hwrm_reserve_tx_rings(bp, &tx_rings_needed) ||
  5692. tx_rings_needed < (tx * tx_sets + tx_xdp))
  5693. return -ENOMEM;
  5694. return 0;
  5695. }
  5696. static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev)
  5697. {
  5698. if (bp->bar2) {
  5699. pci_iounmap(pdev, bp->bar2);
  5700. bp->bar2 = NULL;
  5701. }
  5702. if (bp->bar1) {
  5703. pci_iounmap(pdev, bp->bar1);
  5704. bp->bar1 = NULL;
  5705. }
  5706. if (bp->bar0) {
  5707. pci_iounmap(pdev, bp->bar0);
  5708. bp->bar0 = NULL;
  5709. }
  5710. }
  5711. static void bnxt_cleanup_pci(struct bnxt *bp)
  5712. {
  5713. bnxt_unmap_bars(bp, bp->pdev);
  5714. pci_release_regions(bp->pdev);
  5715. pci_disable_device(bp->pdev);
  5716. }
  5717. static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
  5718. {
  5719. int rc;
  5720. struct bnxt *bp = netdev_priv(dev);
  5721. SET_NETDEV_DEV(dev, &pdev->dev);
  5722. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  5723. rc = pci_enable_device(pdev);
  5724. if (rc) {
  5725. dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n");
  5726. goto init_err;
  5727. }
  5728. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  5729. dev_err(&pdev->dev,
  5730. "Cannot find PCI device base address, aborting\n");
  5731. rc = -ENODEV;
  5732. goto init_err_disable;
  5733. }
  5734. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  5735. if (rc) {
  5736. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n");
  5737. goto init_err_disable;
  5738. }
  5739. if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 &&
  5740. dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
  5741. dev_err(&pdev->dev, "System does not support DMA, aborting\n");
  5742. goto init_err_disable;
  5743. }
  5744. pci_set_master(pdev);
  5745. bp->dev = dev;
  5746. bp->pdev = pdev;
  5747. bp->bar0 = pci_ioremap_bar(pdev, 0);
  5748. if (!bp->bar0) {
  5749. dev_err(&pdev->dev, "Cannot map device registers, aborting\n");
  5750. rc = -ENOMEM;
  5751. goto init_err_release;
  5752. }
  5753. bp->bar1 = pci_ioremap_bar(pdev, 2);
  5754. if (!bp->bar1) {
  5755. dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n");
  5756. rc = -ENOMEM;
  5757. goto init_err_release;
  5758. }
  5759. bp->bar2 = pci_ioremap_bar(pdev, 4);
  5760. if (!bp->bar2) {
  5761. dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n");
  5762. rc = -ENOMEM;
  5763. goto init_err_release;
  5764. }
  5765. pci_enable_pcie_error_reporting(pdev);
  5766. INIT_WORK(&bp->sp_task, bnxt_sp_task);
  5767. spin_lock_init(&bp->ntp_fltr_lock);
  5768. bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE;
  5769. bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE;
  5770. /* tick values in micro seconds */
  5771. bp->rx_coal_ticks = 12;
  5772. bp->rx_coal_bufs = 30;
  5773. bp->rx_coal_ticks_irq = 1;
  5774. bp->rx_coal_bufs_irq = 2;
  5775. bp->tx_coal_ticks = 25;
  5776. bp->tx_coal_bufs = 30;
  5777. bp->tx_coal_ticks_irq = 2;
  5778. bp->tx_coal_bufs_irq = 2;
  5779. bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
  5780. init_timer(&bp->timer);
  5781. bp->timer.data = (unsigned long)bp;
  5782. bp->timer.function = bnxt_timer;
  5783. bp->current_interval = BNXT_TIMER_INTERVAL;
  5784. clear_bit(BNXT_STATE_OPEN, &bp->state);
  5785. return 0;
  5786. init_err_release:
  5787. bnxt_unmap_bars(bp, pdev);
  5788. pci_release_regions(pdev);
  5789. init_err_disable:
  5790. pci_disable_device(pdev);
  5791. init_err:
  5792. return rc;
  5793. }
  5794. /* rtnl_lock held */
  5795. static int bnxt_change_mac_addr(struct net_device *dev, void *p)
  5796. {
  5797. struct sockaddr *addr = p;
  5798. struct bnxt *bp = netdev_priv(dev);
  5799. int rc = 0;
  5800. if (!is_valid_ether_addr(addr->sa_data))
  5801. return -EADDRNOTAVAIL;
  5802. rc = bnxt_approve_mac(bp, addr->sa_data);
  5803. if (rc)
  5804. return rc;
  5805. if (ether_addr_equal(addr->sa_data, dev->dev_addr))
  5806. return 0;
  5807. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  5808. if (netif_running(dev)) {
  5809. bnxt_close_nic(bp, false, false);
  5810. rc = bnxt_open_nic(bp, false, false);
  5811. }
  5812. return rc;
  5813. }
  5814. /* rtnl_lock held */
  5815. static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
  5816. {
  5817. struct bnxt *bp = netdev_priv(dev);
  5818. if (netif_running(dev))
  5819. bnxt_close_nic(bp, false, false);
  5820. dev->mtu = new_mtu;
  5821. bnxt_set_ring_params(bp);
  5822. if (netif_running(dev))
  5823. return bnxt_open_nic(bp, false, false);
  5824. return 0;
  5825. }
  5826. int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
  5827. {
  5828. struct bnxt *bp = netdev_priv(dev);
  5829. bool sh = false;
  5830. int rc;
  5831. if (tc > bp->max_tc) {
  5832. netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
  5833. tc, bp->max_tc);
  5834. return -EINVAL;
  5835. }
  5836. if (netdev_get_num_tc(dev) == tc)
  5837. return 0;
  5838. if (bp->flags & BNXT_FLAG_SHARED_RINGS)
  5839. sh = true;
  5840. rc = bnxt_reserve_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings,
  5841. tc, bp->tx_nr_rings_xdp);
  5842. if (rc)
  5843. return rc;
  5844. /* Needs to close the device and do hw resource re-allocations */
  5845. if (netif_running(bp->dev))
  5846. bnxt_close_nic(bp, true, false);
  5847. if (tc) {
  5848. bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc;
  5849. netdev_set_num_tc(dev, tc);
  5850. } else {
  5851. bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
  5852. netdev_reset_tc(dev);
  5853. }
  5854. bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
  5855. bp->tx_nr_rings + bp->rx_nr_rings;
  5856. bp->num_stat_ctxs = bp->cp_nr_rings;
  5857. if (netif_running(bp->dev))
  5858. return bnxt_open_nic(bp, true, false);
  5859. return 0;
  5860. }
  5861. static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
  5862. struct tc_to_netdev *ntc)
  5863. {
  5864. if (ntc->type != TC_SETUP_MQPRIO)
  5865. return -EINVAL;
  5866. ntc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  5867. return bnxt_setup_mq_tc(dev, ntc->mqprio->num_tc);
  5868. }
  5869. #ifdef CONFIG_RFS_ACCEL
  5870. static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1,
  5871. struct bnxt_ntuple_filter *f2)
  5872. {
  5873. struct flow_keys *keys1 = &f1->fkeys;
  5874. struct flow_keys *keys2 = &f2->fkeys;
  5875. if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src &&
  5876. keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst &&
  5877. keys1->ports.ports == keys2->ports.ports &&
  5878. keys1->basic.ip_proto == keys2->basic.ip_proto &&
  5879. keys1->basic.n_proto == keys2->basic.n_proto &&
  5880. keys1->control.flags == keys2->control.flags &&
  5881. ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) &&
  5882. ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr))
  5883. return true;
  5884. return false;
  5885. }
  5886. static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
  5887. u16 rxq_index, u32 flow_id)
  5888. {
  5889. struct bnxt *bp = netdev_priv(dev);
  5890. struct bnxt_ntuple_filter *fltr, *new_fltr;
  5891. struct flow_keys *fkeys;
  5892. struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb);
  5893. int rc = 0, idx, bit_id, l2_idx = 0;
  5894. struct hlist_head *head;
  5895. if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) {
  5896. struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
  5897. int off = 0, j;
  5898. netif_addr_lock_bh(dev);
  5899. for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) {
  5900. if (ether_addr_equal(eth->h_dest,
  5901. vnic->uc_list + off)) {
  5902. l2_idx = j + 1;
  5903. break;
  5904. }
  5905. }
  5906. netif_addr_unlock_bh(dev);
  5907. if (!l2_idx)
  5908. return -EINVAL;
  5909. }
  5910. new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC);
  5911. if (!new_fltr)
  5912. return -ENOMEM;
  5913. fkeys = &new_fltr->fkeys;
  5914. if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) {
  5915. rc = -EPROTONOSUPPORT;
  5916. goto err_free;
  5917. }
  5918. if ((fkeys->basic.n_proto != htons(ETH_P_IP) &&
  5919. fkeys->basic.n_proto != htons(ETH_P_IPV6)) ||
  5920. ((fkeys->basic.ip_proto != IPPROTO_TCP) &&
  5921. (fkeys->basic.ip_proto != IPPROTO_UDP))) {
  5922. rc = -EPROTONOSUPPORT;
  5923. goto err_free;
  5924. }
  5925. if (fkeys->basic.n_proto == htons(ETH_P_IPV6) &&
  5926. bp->hwrm_spec_code < 0x10601) {
  5927. rc = -EPROTONOSUPPORT;
  5928. goto err_free;
  5929. }
  5930. if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) &&
  5931. bp->hwrm_spec_code < 0x10601) {
  5932. rc = -EPROTONOSUPPORT;
  5933. goto err_free;
  5934. }
  5935. memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN);
  5936. memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN);
  5937. idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK;
  5938. head = &bp->ntp_fltr_hash_tbl[idx];
  5939. rcu_read_lock();
  5940. hlist_for_each_entry_rcu(fltr, head, hash) {
  5941. if (bnxt_fltr_match(fltr, new_fltr)) {
  5942. rcu_read_unlock();
  5943. rc = 0;
  5944. goto err_free;
  5945. }
  5946. }
  5947. rcu_read_unlock();
  5948. spin_lock_bh(&bp->ntp_fltr_lock);
  5949. bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
  5950. BNXT_NTP_FLTR_MAX_FLTR, 0);
  5951. if (bit_id < 0) {
  5952. spin_unlock_bh(&bp->ntp_fltr_lock);
  5953. rc = -ENOMEM;
  5954. goto err_free;
  5955. }
  5956. new_fltr->sw_id = (u16)bit_id;
  5957. new_fltr->flow_id = flow_id;
  5958. new_fltr->l2_fltr_idx = l2_idx;
  5959. new_fltr->rxq = rxq_index;
  5960. hlist_add_head_rcu(&new_fltr->hash, head);
  5961. bp->ntp_fltr_count++;
  5962. spin_unlock_bh(&bp->ntp_fltr_lock);
  5963. set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event);
  5964. schedule_work(&bp->sp_task);
  5965. return new_fltr->sw_id;
  5966. err_free:
  5967. kfree(new_fltr);
  5968. return rc;
  5969. }
  5970. static void bnxt_cfg_ntp_filters(struct bnxt *bp)
  5971. {
  5972. int i;
  5973. for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
  5974. struct hlist_head *head;
  5975. struct hlist_node *tmp;
  5976. struct bnxt_ntuple_filter *fltr;
  5977. int rc;
  5978. head = &bp->ntp_fltr_hash_tbl[i];
  5979. hlist_for_each_entry_safe(fltr, tmp, head, hash) {
  5980. bool del = false;
  5981. if (test_bit(BNXT_FLTR_VALID, &fltr->state)) {
  5982. if (rps_may_expire_flow(bp->dev, fltr->rxq,
  5983. fltr->flow_id,
  5984. fltr->sw_id)) {
  5985. bnxt_hwrm_cfa_ntuple_filter_free(bp,
  5986. fltr);
  5987. del = true;
  5988. }
  5989. } else {
  5990. rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp,
  5991. fltr);
  5992. if (rc)
  5993. del = true;
  5994. else
  5995. set_bit(BNXT_FLTR_VALID, &fltr->state);
  5996. }
  5997. if (del) {
  5998. spin_lock_bh(&bp->ntp_fltr_lock);
  5999. hlist_del_rcu(&fltr->hash);
  6000. bp->ntp_fltr_count--;
  6001. spin_unlock_bh(&bp->ntp_fltr_lock);
  6002. synchronize_rcu();
  6003. clear_bit(fltr->sw_id, bp->ntp_fltr_bmap);
  6004. kfree(fltr);
  6005. }
  6006. }
  6007. }
  6008. if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event))
  6009. netdev_info(bp->dev, "Receive PF driver unload event!");
  6010. }
  6011. #else
  6012. static void bnxt_cfg_ntp_filters(struct bnxt *bp)
  6013. {
  6014. }
  6015. #endif /* CONFIG_RFS_ACCEL */
  6016. static void bnxt_udp_tunnel_add(struct net_device *dev,
  6017. struct udp_tunnel_info *ti)
  6018. {
  6019. struct bnxt *bp = netdev_priv(dev);
  6020. if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
  6021. return;
  6022. if (!netif_running(dev))
  6023. return;
  6024. switch (ti->type) {
  6025. case UDP_TUNNEL_TYPE_VXLAN:
  6026. if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port)
  6027. return;
  6028. bp->vxlan_port_cnt++;
  6029. if (bp->vxlan_port_cnt == 1) {
  6030. bp->vxlan_port = ti->port;
  6031. set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event);
  6032. schedule_work(&bp->sp_task);
  6033. }
  6034. break;
  6035. case UDP_TUNNEL_TYPE_GENEVE:
  6036. if (bp->nge_port_cnt && bp->nge_port != ti->port)
  6037. return;
  6038. bp->nge_port_cnt++;
  6039. if (bp->nge_port_cnt == 1) {
  6040. bp->nge_port = ti->port;
  6041. set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event);
  6042. }
  6043. break;
  6044. default:
  6045. return;
  6046. }
  6047. schedule_work(&bp->sp_task);
  6048. }
  6049. static void bnxt_udp_tunnel_del(struct net_device *dev,
  6050. struct udp_tunnel_info *ti)
  6051. {
  6052. struct bnxt *bp = netdev_priv(dev);
  6053. if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET)
  6054. return;
  6055. if (!netif_running(dev))
  6056. return;
  6057. switch (ti->type) {
  6058. case UDP_TUNNEL_TYPE_VXLAN:
  6059. if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port)
  6060. return;
  6061. bp->vxlan_port_cnt--;
  6062. if (bp->vxlan_port_cnt != 0)
  6063. return;
  6064. set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event);
  6065. break;
  6066. case UDP_TUNNEL_TYPE_GENEVE:
  6067. if (!bp->nge_port_cnt || bp->nge_port != ti->port)
  6068. return;
  6069. bp->nge_port_cnt--;
  6070. if (bp->nge_port_cnt != 0)
  6071. return;
  6072. set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event);
  6073. break;
  6074. default:
  6075. return;
  6076. }
  6077. schedule_work(&bp->sp_task);
  6078. }
  6079. static const struct net_device_ops bnxt_netdev_ops = {
  6080. .ndo_open = bnxt_open,
  6081. .ndo_start_xmit = bnxt_start_xmit,
  6082. .ndo_stop = bnxt_close,
  6083. .ndo_get_stats64 = bnxt_get_stats64,
  6084. .ndo_set_rx_mode = bnxt_set_rx_mode,
  6085. .ndo_do_ioctl = bnxt_ioctl,
  6086. .ndo_validate_addr = eth_validate_addr,
  6087. .ndo_set_mac_address = bnxt_change_mac_addr,
  6088. .ndo_change_mtu = bnxt_change_mtu,
  6089. .ndo_fix_features = bnxt_fix_features,
  6090. .ndo_set_features = bnxt_set_features,
  6091. .ndo_tx_timeout = bnxt_tx_timeout,
  6092. #ifdef CONFIG_BNXT_SRIOV
  6093. .ndo_get_vf_config = bnxt_get_vf_config,
  6094. .ndo_set_vf_mac = bnxt_set_vf_mac,
  6095. .ndo_set_vf_vlan = bnxt_set_vf_vlan,
  6096. .ndo_set_vf_rate = bnxt_set_vf_bw,
  6097. .ndo_set_vf_link_state = bnxt_set_vf_link_state,
  6098. .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk,
  6099. #endif
  6100. #ifdef CONFIG_NET_POLL_CONTROLLER
  6101. .ndo_poll_controller = bnxt_poll_controller,
  6102. #endif
  6103. .ndo_setup_tc = bnxt_setup_tc,
  6104. #ifdef CONFIG_RFS_ACCEL
  6105. .ndo_rx_flow_steer = bnxt_rx_flow_steer,
  6106. #endif
  6107. .ndo_udp_tunnel_add = bnxt_udp_tunnel_add,
  6108. .ndo_udp_tunnel_del = bnxt_udp_tunnel_del,
  6109. .ndo_xdp = bnxt_xdp,
  6110. };
  6111. static void bnxt_remove_one(struct pci_dev *pdev)
  6112. {
  6113. struct net_device *dev = pci_get_drvdata(pdev);
  6114. struct bnxt *bp = netdev_priv(dev);
  6115. if (BNXT_PF(bp))
  6116. bnxt_sriov_disable(bp);
  6117. pci_disable_pcie_error_reporting(pdev);
  6118. unregister_netdev(dev);
  6119. cancel_work_sync(&bp->sp_task);
  6120. bp->sp_event = 0;
  6121. bnxt_clear_int_mode(bp);
  6122. bnxt_hwrm_func_drv_unrgtr(bp);
  6123. bnxt_free_hwrm_resources(bp);
  6124. bnxt_ethtool_free(bp);
  6125. bnxt_dcb_free(bp);
  6126. kfree(bp->edev);
  6127. bp->edev = NULL;
  6128. if (bp->xdp_prog)
  6129. bpf_prog_put(bp->xdp_prog);
  6130. bnxt_cleanup_pci(bp);
  6131. free_netdev(dev);
  6132. }
  6133. static int bnxt_probe_phy(struct bnxt *bp)
  6134. {
  6135. int rc = 0;
  6136. struct bnxt_link_info *link_info = &bp->link_info;
  6137. rc = bnxt_hwrm_phy_qcaps(bp);
  6138. if (rc) {
  6139. netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n",
  6140. rc);
  6141. return rc;
  6142. }
  6143. rc = bnxt_update_link(bp, false);
  6144. if (rc) {
  6145. netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n",
  6146. rc);
  6147. return rc;
  6148. }
  6149. /* Older firmware does not have supported_auto_speeds, so assume
  6150. * that all supported speeds can be autonegotiated.
  6151. */
  6152. if (link_info->auto_link_speeds && !link_info->support_auto_speeds)
  6153. link_info->support_auto_speeds = link_info->support_speeds;
  6154. /*initialize the ethool setting copy with NVM settings */
  6155. if (BNXT_AUTO_MODE(link_info->auto_mode)) {
  6156. link_info->autoneg = BNXT_AUTONEG_SPEED;
  6157. if (bp->hwrm_spec_code >= 0x10201) {
  6158. if (link_info->auto_pause_setting &
  6159. PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE)
  6160. link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
  6161. } else {
  6162. link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
  6163. }
  6164. link_info->advertising = link_info->auto_link_speeds;
  6165. } else {
  6166. link_info->req_link_speed = link_info->force_link_speed;
  6167. link_info->req_duplex = link_info->duplex_setting;
  6168. }
  6169. if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
  6170. link_info->req_flow_ctrl =
  6171. link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH;
  6172. else
  6173. link_info->req_flow_ctrl = link_info->force_pause_setting;
  6174. return rc;
  6175. }
  6176. static int bnxt_get_max_irq(struct pci_dev *pdev)
  6177. {
  6178. u16 ctrl;
  6179. if (!pdev->msix_cap)
  6180. return 1;
  6181. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
  6182. return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1;
  6183. }
  6184. static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
  6185. int *max_cp)
  6186. {
  6187. int max_ring_grps = 0;
  6188. #ifdef CONFIG_BNXT_SRIOV
  6189. if (!BNXT_PF(bp)) {
  6190. *max_tx = bp->vf.max_tx_rings;
  6191. *max_rx = bp->vf.max_rx_rings;
  6192. *max_cp = min_t(int, bp->vf.max_irqs, bp->vf.max_cp_rings);
  6193. *max_cp = min_t(int, *max_cp, bp->vf.max_stat_ctxs);
  6194. max_ring_grps = bp->vf.max_hw_ring_grps;
  6195. } else
  6196. #endif
  6197. {
  6198. *max_tx = bp->pf.max_tx_rings;
  6199. *max_rx = bp->pf.max_rx_rings;
  6200. *max_cp = min_t(int, bp->pf.max_irqs, bp->pf.max_cp_rings);
  6201. *max_cp = min_t(int, *max_cp, bp->pf.max_stat_ctxs);
  6202. max_ring_grps = bp->pf.max_hw_ring_grps;
  6203. }
  6204. if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) {
  6205. *max_cp -= 1;
  6206. *max_rx -= 2;
  6207. }
  6208. if (bp->flags & BNXT_FLAG_AGG_RINGS)
  6209. *max_rx >>= 1;
  6210. *max_rx = min_t(int, *max_rx, max_ring_grps);
  6211. }
  6212. int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared)
  6213. {
  6214. int rx, tx, cp;
  6215. _bnxt_get_max_rings(bp, &rx, &tx, &cp);
  6216. if (!rx || !tx || !cp)
  6217. return -ENOMEM;
  6218. *max_rx = rx;
  6219. *max_tx = tx;
  6220. return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared);
  6221. }
  6222. static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx,
  6223. bool shared)
  6224. {
  6225. int rc;
  6226. rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
  6227. if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
  6228. /* Not enough rings, try disabling agg rings. */
  6229. bp->flags &= ~BNXT_FLAG_AGG_RINGS;
  6230. rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared);
  6231. if (rc)
  6232. return rc;
  6233. bp->flags |= BNXT_FLAG_NO_AGG_RINGS;
  6234. bp->dev->hw_features &= ~NETIF_F_LRO;
  6235. bp->dev->features &= ~NETIF_F_LRO;
  6236. bnxt_set_ring_params(bp);
  6237. }
  6238. if (bp->flags & BNXT_FLAG_ROCE_CAP) {
  6239. int max_cp, max_stat, max_irq;
  6240. /* Reserve minimum resources for RoCE */
  6241. max_cp = bnxt_get_max_func_cp_rings(bp);
  6242. max_stat = bnxt_get_max_func_stat_ctxs(bp);
  6243. max_irq = bnxt_get_max_func_irqs(bp);
  6244. if (max_cp <= BNXT_MIN_ROCE_CP_RINGS ||
  6245. max_irq <= BNXT_MIN_ROCE_CP_RINGS ||
  6246. max_stat <= BNXT_MIN_ROCE_STAT_CTXS)
  6247. return 0;
  6248. max_cp -= BNXT_MIN_ROCE_CP_RINGS;
  6249. max_irq -= BNXT_MIN_ROCE_CP_RINGS;
  6250. max_stat -= BNXT_MIN_ROCE_STAT_CTXS;
  6251. max_cp = min_t(int, max_cp, max_irq);
  6252. max_cp = min_t(int, max_cp, max_stat);
  6253. rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared);
  6254. if (rc)
  6255. rc = 0;
  6256. }
  6257. return rc;
  6258. }
  6259. static int bnxt_set_dflt_rings(struct bnxt *bp)
  6260. {
  6261. int dflt_rings, max_rx_rings, max_tx_rings, rc;
  6262. bool sh = true;
  6263. if (sh)
  6264. bp->flags |= BNXT_FLAG_SHARED_RINGS;
  6265. dflt_rings = netif_get_num_default_rss_queues();
  6266. rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh);
  6267. if (rc)
  6268. return rc;
  6269. bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
  6270. bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
  6271. rc = bnxt_hwrm_reserve_tx_rings(bp, &bp->tx_nr_rings_per_tc);
  6272. if (rc)
  6273. netdev_warn(bp->dev, "Unable to reserve tx rings\n");
  6274. bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
  6275. bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
  6276. bp->tx_nr_rings + bp->rx_nr_rings;
  6277. bp->num_stat_ctxs = bp->cp_nr_rings;
  6278. if (BNXT_CHIP_TYPE_NITRO_A0(bp)) {
  6279. bp->rx_nr_rings++;
  6280. bp->cp_nr_rings++;
  6281. }
  6282. return rc;
  6283. }
  6284. void bnxt_restore_pf_fw_resources(struct bnxt *bp)
  6285. {
  6286. ASSERT_RTNL();
  6287. bnxt_hwrm_func_qcaps(bp);
  6288. bnxt_subtract_ulp_resources(bp, BNXT_ROCE_ULP);
  6289. }
  6290. static void bnxt_parse_log_pcie_link(struct bnxt *bp)
  6291. {
  6292. enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
  6293. enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
  6294. if (pcie_get_minimum_link(bp->pdev, &speed, &width) ||
  6295. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN)
  6296. netdev_info(bp->dev, "Failed to determine PCIe Link Info\n");
  6297. else
  6298. netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n",
  6299. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
  6300. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
  6301. speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
  6302. "Unknown", width);
  6303. }
  6304. static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  6305. {
  6306. static int version_printed;
  6307. struct net_device *dev;
  6308. struct bnxt *bp;
  6309. int rc, max_irqs;
  6310. if (pci_is_bridge(pdev))
  6311. return -ENODEV;
  6312. if (version_printed++ == 0)
  6313. pr_info("%s", version);
  6314. max_irqs = bnxt_get_max_irq(pdev);
  6315. dev = alloc_etherdev_mq(sizeof(*bp), max_irqs);
  6316. if (!dev)
  6317. return -ENOMEM;
  6318. bp = netdev_priv(dev);
  6319. if (bnxt_vf_pciid(ent->driver_data))
  6320. bp->flags |= BNXT_FLAG_VF;
  6321. if (pdev->msix_cap)
  6322. bp->flags |= BNXT_FLAG_MSIX_CAP;
  6323. rc = bnxt_init_board(pdev, dev);
  6324. if (rc < 0)
  6325. goto init_err_free;
  6326. dev->netdev_ops = &bnxt_netdev_ops;
  6327. dev->watchdog_timeo = BNXT_TX_TIMEOUT;
  6328. dev->ethtool_ops = &bnxt_ethtool_ops;
  6329. pci_set_drvdata(pdev, dev);
  6330. rc = bnxt_alloc_hwrm_resources(bp);
  6331. if (rc)
  6332. goto init_err_pci_clean;
  6333. mutex_init(&bp->hwrm_cmd_lock);
  6334. rc = bnxt_hwrm_ver_get(bp);
  6335. if (rc)
  6336. goto init_err_pci_clean;
  6337. rc = bnxt_hwrm_func_reset(bp);
  6338. if (rc)
  6339. goto init_err_pci_clean;
  6340. bnxt_hwrm_fw_set_time(bp);
  6341. dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  6342. NETIF_F_TSO | NETIF_F_TSO6 |
  6343. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
  6344. NETIF_F_GSO_IPXIP4 |
  6345. NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
  6346. NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH |
  6347. NETIF_F_RXCSUM | NETIF_F_GRO;
  6348. if (!BNXT_CHIP_TYPE_NITRO_A0(bp))
  6349. dev->hw_features |= NETIF_F_LRO;
  6350. dev->hw_enc_features =
  6351. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  6352. NETIF_F_TSO | NETIF_F_TSO6 |
  6353. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
  6354. NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM |
  6355. NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL;
  6356. dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM |
  6357. NETIF_F_GSO_GRE_CSUM;
  6358. dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA;
  6359. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
  6360. NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX;
  6361. dev->features |= dev->hw_features | NETIF_F_HIGHDMA;
  6362. dev->priv_flags |= IFF_UNICAST_FLT;
  6363. /* MTU range: 60 - 9500 */
  6364. dev->min_mtu = ETH_ZLEN;
  6365. dev->max_mtu = BNXT_MAX_MTU;
  6366. #ifdef CONFIG_BNXT_SRIOV
  6367. init_waitqueue_head(&bp->sriov_cfg_wait);
  6368. #endif
  6369. bp->gro_func = bnxt_gro_func_5730x;
  6370. if (BNXT_CHIP_NUM_57X1X(bp->chip_num))
  6371. bp->gro_func = bnxt_gro_func_5731x;
  6372. rc = bnxt_hwrm_func_drv_rgtr(bp);
  6373. if (rc)
  6374. goto init_err_pci_clean;
  6375. rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0);
  6376. if (rc)
  6377. goto init_err_pci_clean;
  6378. bp->ulp_probe = bnxt_ulp_probe;
  6379. /* Get the MAX capabilities for this function */
  6380. rc = bnxt_hwrm_func_qcaps(bp);
  6381. if (rc) {
  6382. netdev_err(bp->dev, "hwrm query capability failure rc: %x\n",
  6383. rc);
  6384. rc = -1;
  6385. goto init_err_pci_clean;
  6386. }
  6387. rc = bnxt_hwrm_queue_qportcfg(bp);
  6388. if (rc) {
  6389. netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n",
  6390. rc);
  6391. rc = -1;
  6392. goto init_err_pci_clean;
  6393. }
  6394. bnxt_hwrm_func_qcfg(bp);
  6395. bnxt_hwrm_port_led_qcaps(bp);
  6396. bnxt_ethtool_init(bp);
  6397. bnxt_dcb_init(bp);
  6398. bnxt_set_rx_skb_mode(bp, false);
  6399. bnxt_set_tpa_flags(bp);
  6400. bnxt_set_ring_params(bp);
  6401. bnxt_set_max_func_irqs(bp, max_irqs);
  6402. rc = bnxt_set_dflt_rings(bp);
  6403. if (rc) {
  6404. netdev_err(bp->dev, "Not enough rings available.\n");
  6405. rc = -ENOMEM;
  6406. goto init_err_pci_clean;
  6407. }
  6408. /* Default RSS hash cfg. */
  6409. bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 |
  6410. VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 |
  6411. VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 |
  6412. VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
  6413. if (!BNXT_CHIP_NUM_57X0X(bp->chip_num) &&
  6414. !BNXT_CHIP_TYPE_NITRO_A0(bp) &&
  6415. bp->hwrm_spec_code >= 0x10501) {
  6416. bp->flags |= BNXT_FLAG_UDP_RSS_CAP;
  6417. bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 |
  6418. VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
  6419. }
  6420. bnxt_hwrm_vnic_qcaps(bp);
  6421. if (bnxt_rfs_supported(bp)) {
  6422. dev->hw_features |= NETIF_F_NTUPLE;
  6423. if (bnxt_rfs_capable(bp)) {
  6424. bp->flags |= BNXT_FLAG_RFS;
  6425. dev->features |= NETIF_F_NTUPLE;
  6426. }
  6427. }
  6428. if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX)
  6429. bp->flags |= BNXT_FLAG_STRIP_VLAN;
  6430. rc = bnxt_probe_phy(bp);
  6431. if (rc)
  6432. goto init_err_pci_clean;
  6433. rc = bnxt_init_int_mode(bp);
  6434. if (rc)
  6435. goto init_err_pci_clean;
  6436. bnxt_get_wol_settings(bp);
  6437. if (bp->flags & BNXT_FLAG_WOL_CAP)
  6438. device_set_wakeup_enable(&pdev->dev, bp->wol);
  6439. else
  6440. device_set_wakeup_capable(&pdev->dev, false);
  6441. rc = register_netdev(dev);
  6442. if (rc)
  6443. goto init_err_clr_int;
  6444. netdev_info(dev, "%s found at mem %lx, node addr %pM\n",
  6445. board_info[ent->driver_data].name,
  6446. (long)pci_resource_start(pdev, 0), dev->dev_addr);
  6447. bnxt_parse_log_pcie_link(bp);
  6448. return 0;
  6449. init_err_clr_int:
  6450. bnxt_clear_int_mode(bp);
  6451. init_err_pci_clean:
  6452. bnxt_cleanup_pci(bp);
  6453. init_err_free:
  6454. free_netdev(dev);
  6455. return rc;
  6456. }
  6457. static void bnxt_shutdown(struct pci_dev *pdev)
  6458. {
  6459. struct net_device *dev = pci_get_drvdata(pdev);
  6460. struct bnxt *bp;
  6461. if (!dev)
  6462. return;
  6463. rtnl_lock();
  6464. bp = netdev_priv(dev);
  6465. if (!bp)
  6466. goto shutdown_exit;
  6467. if (netif_running(dev))
  6468. dev_close(dev);
  6469. if (system_state == SYSTEM_POWER_OFF) {
  6470. bnxt_clear_int_mode(bp);
  6471. pci_wake_from_d3(pdev, bp->wol);
  6472. pci_set_power_state(pdev, PCI_D3hot);
  6473. }
  6474. shutdown_exit:
  6475. rtnl_unlock();
  6476. }
  6477. #ifdef CONFIG_PM_SLEEP
  6478. static int bnxt_suspend(struct device *device)
  6479. {
  6480. struct pci_dev *pdev = to_pci_dev(device);
  6481. struct net_device *dev = pci_get_drvdata(pdev);
  6482. struct bnxt *bp = netdev_priv(dev);
  6483. int rc = 0;
  6484. rtnl_lock();
  6485. if (netif_running(dev)) {
  6486. netif_device_detach(dev);
  6487. rc = bnxt_close(dev);
  6488. }
  6489. bnxt_hwrm_func_drv_unrgtr(bp);
  6490. rtnl_unlock();
  6491. return rc;
  6492. }
  6493. static int bnxt_resume(struct device *device)
  6494. {
  6495. struct pci_dev *pdev = to_pci_dev(device);
  6496. struct net_device *dev = pci_get_drvdata(pdev);
  6497. struct bnxt *bp = netdev_priv(dev);
  6498. int rc = 0;
  6499. rtnl_lock();
  6500. if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) {
  6501. rc = -ENODEV;
  6502. goto resume_exit;
  6503. }
  6504. rc = bnxt_hwrm_func_reset(bp);
  6505. if (rc) {
  6506. rc = -EBUSY;
  6507. goto resume_exit;
  6508. }
  6509. bnxt_get_wol_settings(bp);
  6510. if (netif_running(dev)) {
  6511. rc = bnxt_open(dev);
  6512. if (!rc)
  6513. netif_device_attach(dev);
  6514. }
  6515. resume_exit:
  6516. rtnl_unlock();
  6517. return rc;
  6518. }
  6519. static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume);
  6520. #define BNXT_PM_OPS (&bnxt_pm_ops)
  6521. #else
  6522. #define BNXT_PM_OPS NULL
  6523. #endif /* CONFIG_PM_SLEEP */
  6524. /**
  6525. * bnxt_io_error_detected - called when PCI error is detected
  6526. * @pdev: Pointer to PCI device
  6527. * @state: The current pci connection state
  6528. *
  6529. * This function is called after a PCI bus error affecting
  6530. * this device has been detected.
  6531. */
  6532. static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
  6533. pci_channel_state_t state)
  6534. {
  6535. struct net_device *netdev = pci_get_drvdata(pdev);
  6536. struct bnxt *bp = netdev_priv(netdev);
  6537. netdev_info(netdev, "PCI I/O error detected\n");
  6538. rtnl_lock();
  6539. netif_device_detach(netdev);
  6540. bnxt_ulp_stop(bp);
  6541. if (state == pci_channel_io_perm_failure) {
  6542. rtnl_unlock();
  6543. return PCI_ERS_RESULT_DISCONNECT;
  6544. }
  6545. if (netif_running(netdev))
  6546. bnxt_close(netdev);
  6547. pci_disable_device(pdev);
  6548. rtnl_unlock();
  6549. /* Request a slot slot reset. */
  6550. return PCI_ERS_RESULT_NEED_RESET;
  6551. }
  6552. /**
  6553. * bnxt_io_slot_reset - called after the pci bus has been reset.
  6554. * @pdev: Pointer to PCI device
  6555. *
  6556. * Restart the card from scratch, as if from a cold-boot.
  6557. * At this point, the card has exprienced a hard reset,
  6558. * followed by fixups by BIOS, and has its config space
  6559. * set up identically to what it was at cold boot.
  6560. */
  6561. static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
  6562. {
  6563. struct net_device *netdev = pci_get_drvdata(pdev);
  6564. struct bnxt *bp = netdev_priv(netdev);
  6565. int err = 0;
  6566. pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT;
  6567. netdev_info(bp->dev, "PCI Slot Reset\n");
  6568. rtnl_lock();
  6569. if (pci_enable_device(pdev)) {
  6570. dev_err(&pdev->dev,
  6571. "Cannot re-enable PCI device after reset.\n");
  6572. } else {
  6573. pci_set_master(pdev);
  6574. err = bnxt_hwrm_func_reset(bp);
  6575. if (!err && netif_running(netdev))
  6576. err = bnxt_open(netdev);
  6577. if (!err) {
  6578. result = PCI_ERS_RESULT_RECOVERED;
  6579. bnxt_ulp_start(bp);
  6580. }
  6581. }
  6582. if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev))
  6583. dev_close(netdev);
  6584. rtnl_unlock();
  6585. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  6586. if (err) {
  6587. dev_err(&pdev->dev,
  6588. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  6589. err); /* non-fatal, continue */
  6590. }
  6591. return PCI_ERS_RESULT_RECOVERED;
  6592. }
  6593. /**
  6594. * bnxt_io_resume - called when traffic can start flowing again.
  6595. * @pdev: Pointer to PCI device
  6596. *
  6597. * This callback is called when the error recovery driver tells
  6598. * us that its OK to resume normal operation.
  6599. */
  6600. static void bnxt_io_resume(struct pci_dev *pdev)
  6601. {
  6602. struct net_device *netdev = pci_get_drvdata(pdev);
  6603. rtnl_lock();
  6604. netif_device_attach(netdev);
  6605. rtnl_unlock();
  6606. }
  6607. static const struct pci_error_handlers bnxt_err_handler = {
  6608. .error_detected = bnxt_io_error_detected,
  6609. .slot_reset = bnxt_io_slot_reset,
  6610. .resume = bnxt_io_resume
  6611. };
  6612. static struct pci_driver bnxt_pci_driver = {
  6613. .name = DRV_MODULE_NAME,
  6614. .id_table = bnxt_pci_tbl,
  6615. .probe = bnxt_init_one,
  6616. .remove = bnxt_remove_one,
  6617. .shutdown = bnxt_shutdown,
  6618. .driver.pm = BNXT_PM_OPS,
  6619. .err_handler = &bnxt_err_handler,
  6620. #if defined(CONFIG_BNXT_SRIOV)
  6621. .sriov_configure = bnxt_sriov_configure,
  6622. #endif
  6623. };
  6624. module_pci_driver(bnxt_pci_driver);