i40e_main.c 395 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2017 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include <linux/etherdevice.h>
  27. #include <linux/of_net.h>
  28. #include <linux/pci.h>
  29. #include <linux/bpf.h>
  30. /* Local includes */
  31. #include "i40e.h"
  32. #include "i40e_diag.h"
  33. #include <net/udp_tunnel.h>
  34. /* All i40e tracepoints are defined by the include below, which
  35. * must be included exactly once across the whole kernel with
  36. * CREATE_TRACE_POINTS defined
  37. */
  38. #define CREATE_TRACE_POINTS
  39. #include "i40e_trace.h"
  40. const char i40e_driver_name[] = "i40e";
  41. static const char i40e_driver_string[] =
  42. "Intel(R) Ethernet Connection XL710 Network Driver";
  43. #define DRV_KERN "-k"
  44. #define DRV_VERSION_MAJOR 2
  45. #define DRV_VERSION_MINOR 3
  46. #define DRV_VERSION_BUILD 2
  47. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  48. __stringify(DRV_VERSION_MINOR) "." \
  49. __stringify(DRV_VERSION_BUILD) DRV_KERN
  50. const char i40e_driver_version_str[] = DRV_VERSION;
  51. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  52. /* a bit of forward declarations */
  53. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  54. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired);
  55. static int i40e_add_vsi(struct i40e_vsi *vsi);
  56. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  57. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  58. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  59. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  60. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  61. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired);
  62. static int i40e_reset(struct i40e_pf *pf);
  63. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired);
  64. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  65. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  66. static int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  67. struct i40e_cloud_filter *filter,
  68. bool add);
  69. static int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  70. struct i40e_cloud_filter *filter,
  71. bool add);
  72. static int i40e_get_capabilities(struct i40e_pf *pf,
  73. enum i40e_admin_queue_opc list_type);
  74. /* i40e_pci_tbl - PCI Device ID Table
  75. *
  76. * Last entry must be all 0s
  77. *
  78. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  79. * Class, Class Mask, private data (not used) }
  80. */
  81. static const struct pci_device_id i40e_pci_tbl[] = {
  82. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  83. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  84. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  85. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  86. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  87. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  88. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  89. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  90. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  91. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  92. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  93. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  94. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  95. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  96. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  97. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  98. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  99. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  100. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  101. /* required last entry */
  102. {0, }
  103. };
  104. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  105. #define I40E_MAX_VF_COUNT 128
  106. static int debug = -1;
  107. module_param(debug, uint, 0);
  108. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  109. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  110. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  111. MODULE_LICENSE("GPL");
  112. MODULE_VERSION(DRV_VERSION);
  113. static struct workqueue_struct *i40e_wq;
  114. /**
  115. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  116. * @hw: pointer to the HW structure
  117. * @mem: ptr to mem struct to fill out
  118. * @size: size of memory requested
  119. * @alignment: what to align the allocation to
  120. **/
  121. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  122. u64 size, u32 alignment)
  123. {
  124. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  125. mem->size = ALIGN(size, alignment);
  126. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  127. &mem->pa, GFP_KERNEL);
  128. if (!mem->va)
  129. return -ENOMEM;
  130. return 0;
  131. }
  132. /**
  133. * i40e_free_dma_mem_d - OS specific memory free for shared code
  134. * @hw: pointer to the HW structure
  135. * @mem: ptr to mem struct to free
  136. **/
  137. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  138. {
  139. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  140. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  141. mem->va = NULL;
  142. mem->pa = 0;
  143. mem->size = 0;
  144. return 0;
  145. }
  146. /**
  147. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  148. * @hw: pointer to the HW structure
  149. * @mem: ptr to mem struct to fill out
  150. * @size: size of memory requested
  151. **/
  152. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  153. u32 size)
  154. {
  155. mem->size = size;
  156. mem->va = kzalloc(size, GFP_KERNEL);
  157. if (!mem->va)
  158. return -ENOMEM;
  159. return 0;
  160. }
  161. /**
  162. * i40e_free_virt_mem_d - OS specific memory free for shared code
  163. * @hw: pointer to the HW structure
  164. * @mem: ptr to mem struct to free
  165. **/
  166. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  167. {
  168. /* it's ok to kfree a NULL pointer */
  169. kfree(mem->va);
  170. mem->va = NULL;
  171. mem->size = 0;
  172. return 0;
  173. }
  174. /**
  175. * i40e_get_lump - find a lump of free generic resource
  176. * @pf: board private structure
  177. * @pile: the pile of resource to search
  178. * @needed: the number of items needed
  179. * @id: an owner id to stick on the items assigned
  180. *
  181. * Returns the base item index of the lump, or negative for error
  182. *
  183. * The search_hint trick and lack of advanced fit-finding only work
  184. * because we're highly likely to have all the same size lump requests.
  185. * Linear search time and any fragmentation should be minimal.
  186. **/
  187. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  188. u16 needed, u16 id)
  189. {
  190. int ret = -ENOMEM;
  191. int i, j;
  192. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  193. dev_info(&pf->pdev->dev,
  194. "param err: pile=%p needed=%d id=0x%04x\n",
  195. pile, needed, id);
  196. return -EINVAL;
  197. }
  198. /* start the linear search with an imperfect hint */
  199. i = pile->search_hint;
  200. while (i < pile->num_entries) {
  201. /* skip already allocated entries */
  202. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  203. i++;
  204. continue;
  205. }
  206. /* do we have enough in this lump? */
  207. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  208. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  209. break;
  210. }
  211. if (j == needed) {
  212. /* there was enough, so assign it to the requestor */
  213. for (j = 0; j < needed; j++)
  214. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  215. ret = i;
  216. pile->search_hint = i + j;
  217. break;
  218. }
  219. /* not enough, so skip over it and continue looking */
  220. i += j;
  221. }
  222. return ret;
  223. }
  224. /**
  225. * i40e_put_lump - return a lump of generic resource
  226. * @pile: the pile of resource to search
  227. * @index: the base item index
  228. * @id: the owner id of the items assigned
  229. *
  230. * Returns the count of items in the lump
  231. **/
  232. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  233. {
  234. int valid_id = (id | I40E_PILE_VALID_BIT);
  235. int count = 0;
  236. int i;
  237. if (!pile || index >= pile->num_entries)
  238. return -EINVAL;
  239. for (i = index;
  240. i < pile->num_entries && pile->list[i] == valid_id;
  241. i++) {
  242. pile->list[i] = 0;
  243. count++;
  244. }
  245. if (count && index < pile->search_hint)
  246. pile->search_hint = index;
  247. return count;
  248. }
  249. /**
  250. * i40e_find_vsi_from_id - searches for the vsi with the given id
  251. * @pf - the pf structure to search for the vsi
  252. * @id - id of the vsi it is searching for
  253. **/
  254. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  255. {
  256. int i;
  257. for (i = 0; i < pf->num_alloc_vsi; i++)
  258. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  259. return pf->vsi[i];
  260. return NULL;
  261. }
  262. /**
  263. * i40e_service_event_schedule - Schedule the service task to wake up
  264. * @pf: board private structure
  265. *
  266. * If not already scheduled, this puts the task into the work queue
  267. **/
  268. void i40e_service_event_schedule(struct i40e_pf *pf)
  269. {
  270. if (!test_bit(__I40E_DOWN, pf->state) &&
  271. !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  272. queue_work(i40e_wq, &pf->service_task);
  273. }
  274. /**
  275. * i40e_tx_timeout - Respond to a Tx Hang
  276. * @netdev: network interface device structure
  277. *
  278. * If any port has noticed a Tx timeout, it is likely that the whole
  279. * device is munged, not just the one netdev port, so go for the full
  280. * reset.
  281. **/
  282. static void i40e_tx_timeout(struct net_device *netdev)
  283. {
  284. struct i40e_netdev_priv *np = netdev_priv(netdev);
  285. struct i40e_vsi *vsi = np->vsi;
  286. struct i40e_pf *pf = vsi->back;
  287. struct i40e_ring *tx_ring = NULL;
  288. unsigned int i, hung_queue = 0;
  289. u32 head, val;
  290. pf->tx_timeout_count++;
  291. /* find the stopped queue the same way the stack does */
  292. for (i = 0; i < netdev->num_tx_queues; i++) {
  293. struct netdev_queue *q;
  294. unsigned long trans_start;
  295. q = netdev_get_tx_queue(netdev, i);
  296. trans_start = q->trans_start;
  297. if (netif_xmit_stopped(q) &&
  298. time_after(jiffies,
  299. (trans_start + netdev->watchdog_timeo))) {
  300. hung_queue = i;
  301. break;
  302. }
  303. }
  304. if (i == netdev->num_tx_queues) {
  305. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  306. } else {
  307. /* now that we have an index, find the tx_ring struct */
  308. for (i = 0; i < vsi->num_queue_pairs; i++) {
  309. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  310. if (hung_queue ==
  311. vsi->tx_rings[i]->queue_index) {
  312. tx_ring = vsi->tx_rings[i];
  313. break;
  314. }
  315. }
  316. }
  317. }
  318. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  319. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  320. else if (time_before(jiffies,
  321. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  322. return; /* don't do any new action before the next timeout */
  323. if (tx_ring) {
  324. head = i40e_get_head(tx_ring);
  325. /* Read interrupt register */
  326. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  327. val = rd32(&pf->hw,
  328. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  329. tx_ring->vsi->base_vector - 1));
  330. else
  331. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  332. netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
  333. vsi->seid, hung_queue, tx_ring->next_to_clean,
  334. head, tx_ring->next_to_use,
  335. readl(tx_ring->tail), val);
  336. }
  337. pf->tx_timeout_last_recovery = jiffies;
  338. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  339. pf->tx_timeout_recovery_level, hung_queue);
  340. switch (pf->tx_timeout_recovery_level) {
  341. case 1:
  342. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  343. break;
  344. case 2:
  345. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  346. break;
  347. case 3:
  348. set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  349. break;
  350. default:
  351. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  352. break;
  353. }
  354. i40e_service_event_schedule(pf);
  355. pf->tx_timeout_recovery_level++;
  356. }
  357. /**
  358. * i40e_get_vsi_stats_struct - Get System Network Statistics
  359. * @vsi: the VSI we care about
  360. *
  361. * Returns the address of the device statistics structure.
  362. * The statistics are actually updated from the service task.
  363. **/
  364. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  365. {
  366. return &vsi->net_stats;
  367. }
  368. /**
  369. * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
  370. * @ring: Tx ring to get statistics from
  371. * @stats: statistics entry to be updated
  372. **/
  373. static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,
  374. struct rtnl_link_stats64 *stats)
  375. {
  376. u64 bytes, packets;
  377. unsigned int start;
  378. do {
  379. start = u64_stats_fetch_begin_irq(&ring->syncp);
  380. packets = ring->stats.packets;
  381. bytes = ring->stats.bytes;
  382. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  383. stats->tx_packets += packets;
  384. stats->tx_bytes += bytes;
  385. }
  386. /**
  387. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  388. * @netdev: network interface device structure
  389. *
  390. * Returns the address of the device statistics structure.
  391. * The statistics are actually updated from the service task.
  392. **/
  393. static void i40e_get_netdev_stats_struct(struct net_device *netdev,
  394. struct rtnl_link_stats64 *stats)
  395. {
  396. struct i40e_netdev_priv *np = netdev_priv(netdev);
  397. struct i40e_ring *tx_ring, *rx_ring;
  398. struct i40e_vsi *vsi = np->vsi;
  399. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  400. int i;
  401. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  402. return;
  403. if (!vsi->tx_rings)
  404. return;
  405. rcu_read_lock();
  406. for (i = 0; i < vsi->num_queue_pairs; i++) {
  407. u64 bytes, packets;
  408. unsigned int start;
  409. tx_ring = READ_ONCE(vsi->tx_rings[i]);
  410. if (!tx_ring)
  411. continue;
  412. i40e_get_netdev_stats_struct_tx(tx_ring, stats);
  413. rx_ring = &tx_ring[1];
  414. do {
  415. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  416. packets = rx_ring->stats.packets;
  417. bytes = rx_ring->stats.bytes;
  418. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  419. stats->rx_packets += packets;
  420. stats->rx_bytes += bytes;
  421. if (i40e_enabled_xdp_vsi(vsi))
  422. i40e_get_netdev_stats_struct_tx(&rx_ring[1], stats);
  423. }
  424. rcu_read_unlock();
  425. /* following stats updated by i40e_watchdog_subtask() */
  426. stats->multicast = vsi_stats->multicast;
  427. stats->tx_errors = vsi_stats->tx_errors;
  428. stats->tx_dropped = vsi_stats->tx_dropped;
  429. stats->rx_errors = vsi_stats->rx_errors;
  430. stats->rx_dropped = vsi_stats->rx_dropped;
  431. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  432. stats->rx_length_errors = vsi_stats->rx_length_errors;
  433. }
  434. /**
  435. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  436. * @vsi: the VSI to have its stats reset
  437. **/
  438. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  439. {
  440. struct rtnl_link_stats64 *ns;
  441. int i;
  442. if (!vsi)
  443. return;
  444. ns = i40e_get_vsi_stats_struct(vsi);
  445. memset(ns, 0, sizeof(*ns));
  446. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  447. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  448. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  449. if (vsi->rx_rings && vsi->rx_rings[0]) {
  450. for (i = 0; i < vsi->num_queue_pairs; i++) {
  451. memset(&vsi->rx_rings[i]->stats, 0,
  452. sizeof(vsi->rx_rings[i]->stats));
  453. memset(&vsi->rx_rings[i]->rx_stats, 0,
  454. sizeof(vsi->rx_rings[i]->rx_stats));
  455. memset(&vsi->tx_rings[i]->stats, 0,
  456. sizeof(vsi->tx_rings[i]->stats));
  457. memset(&vsi->tx_rings[i]->tx_stats, 0,
  458. sizeof(vsi->tx_rings[i]->tx_stats));
  459. }
  460. }
  461. vsi->stat_offsets_loaded = false;
  462. }
  463. /**
  464. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  465. * @pf: the PF to be reset
  466. **/
  467. void i40e_pf_reset_stats(struct i40e_pf *pf)
  468. {
  469. int i;
  470. memset(&pf->stats, 0, sizeof(pf->stats));
  471. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  472. pf->stat_offsets_loaded = false;
  473. for (i = 0; i < I40E_MAX_VEB; i++) {
  474. if (pf->veb[i]) {
  475. memset(&pf->veb[i]->stats, 0,
  476. sizeof(pf->veb[i]->stats));
  477. memset(&pf->veb[i]->stats_offsets, 0,
  478. sizeof(pf->veb[i]->stats_offsets));
  479. pf->veb[i]->stat_offsets_loaded = false;
  480. }
  481. }
  482. pf->hw_csum_rx_error = 0;
  483. }
  484. /**
  485. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  486. * @hw: ptr to the hardware info
  487. * @hireg: the high 32 bit reg to read
  488. * @loreg: the low 32 bit reg to read
  489. * @offset_loaded: has the initial offset been loaded yet
  490. * @offset: ptr to current offset value
  491. * @stat: ptr to the stat
  492. *
  493. * Since the device stats are not reset at PFReset, they likely will not
  494. * be zeroed when the driver starts. We'll save the first values read
  495. * and use them as offsets to be subtracted from the raw values in order
  496. * to report stats that count from zero. In the process, we also manage
  497. * the potential roll-over.
  498. **/
  499. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  500. bool offset_loaded, u64 *offset, u64 *stat)
  501. {
  502. u64 new_data;
  503. if (hw->device_id == I40E_DEV_ID_QEMU) {
  504. new_data = rd32(hw, loreg);
  505. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  506. } else {
  507. new_data = rd64(hw, loreg);
  508. }
  509. if (!offset_loaded)
  510. *offset = new_data;
  511. if (likely(new_data >= *offset))
  512. *stat = new_data - *offset;
  513. else
  514. *stat = (new_data + BIT_ULL(48)) - *offset;
  515. *stat &= 0xFFFFFFFFFFFFULL;
  516. }
  517. /**
  518. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  519. * @hw: ptr to the hardware info
  520. * @reg: the hw reg to read
  521. * @offset_loaded: has the initial offset been loaded yet
  522. * @offset: ptr to current offset value
  523. * @stat: ptr to the stat
  524. **/
  525. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  526. bool offset_loaded, u64 *offset, u64 *stat)
  527. {
  528. u32 new_data;
  529. new_data = rd32(hw, reg);
  530. if (!offset_loaded)
  531. *offset = new_data;
  532. if (likely(new_data >= *offset))
  533. *stat = (u32)(new_data - *offset);
  534. else
  535. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  536. }
  537. /**
  538. * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
  539. * @hw: ptr to the hardware info
  540. * @reg: the hw reg to read and clear
  541. * @stat: ptr to the stat
  542. **/
  543. static void i40e_stat_update_and_clear32(struct i40e_hw *hw, u32 reg, u64 *stat)
  544. {
  545. u32 new_data = rd32(hw, reg);
  546. wr32(hw, reg, 1); /* must write a nonzero value to clear register */
  547. *stat += new_data;
  548. }
  549. /**
  550. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  551. * @vsi: the VSI to be updated
  552. **/
  553. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  554. {
  555. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  556. struct i40e_pf *pf = vsi->back;
  557. struct i40e_hw *hw = &pf->hw;
  558. struct i40e_eth_stats *oes;
  559. struct i40e_eth_stats *es; /* device's eth stats */
  560. es = &vsi->eth_stats;
  561. oes = &vsi->eth_stats_offsets;
  562. /* Gather up the stats that the hw collects */
  563. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  564. vsi->stat_offsets_loaded,
  565. &oes->tx_errors, &es->tx_errors);
  566. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  567. vsi->stat_offsets_loaded,
  568. &oes->rx_discards, &es->rx_discards);
  569. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  570. vsi->stat_offsets_loaded,
  571. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  572. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  573. vsi->stat_offsets_loaded,
  574. &oes->tx_errors, &es->tx_errors);
  575. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  576. I40E_GLV_GORCL(stat_idx),
  577. vsi->stat_offsets_loaded,
  578. &oes->rx_bytes, &es->rx_bytes);
  579. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  580. I40E_GLV_UPRCL(stat_idx),
  581. vsi->stat_offsets_loaded,
  582. &oes->rx_unicast, &es->rx_unicast);
  583. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  584. I40E_GLV_MPRCL(stat_idx),
  585. vsi->stat_offsets_loaded,
  586. &oes->rx_multicast, &es->rx_multicast);
  587. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  588. I40E_GLV_BPRCL(stat_idx),
  589. vsi->stat_offsets_loaded,
  590. &oes->rx_broadcast, &es->rx_broadcast);
  591. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  592. I40E_GLV_GOTCL(stat_idx),
  593. vsi->stat_offsets_loaded,
  594. &oes->tx_bytes, &es->tx_bytes);
  595. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  596. I40E_GLV_UPTCL(stat_idx),
  597. vsi->stat_offsets_loaded,
  598. &oes->tx_unicast, &es->tx_unicast);
  599. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  600. I40E_GLV_MPTCL(stat_idx),
  601. vsi->stat_offsets_loaded,
  602. &oes->tx_multicast, &es->tx_multicast);
  603. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  604. I40E_GLV_BPTCL(stat_idx),
  605. vsi->stat_offsets_loaded,
  606. &oes->tx_broadcast, &es->tx_broadcast);
  607. vsi->stat_offsets_loaded = true;
  608. }
  609. /**
  610. * i40e_update_veb_stats - Update Switch component statistics
  611. * @veb: the VEB being updated
  612. **/
  613. static void i40e_update_veb_stats(struct i40e_veb *veb)
  614. {
  615. struct i40e_pf *pf = veb->pf;
  616. struct i40e_hw *hw = &pf->hw;
  617. struct i40e_eth_stats *oes;
  618. struct i40e_eth_stats *es; /* device's eth stats */
  619. struct i40e_veb_tc_stats *veb_oes;
  620. struct i40e_veb_tc_stats *veb_es;
  621. int i, idx = 0;
  622. idx = veb->stats_idx;
  623. es = &veb->stats;
  624. oes = &veb->stats_offsets;
  625. veb_es = &veb->tc_stats;
  626. veb_oes = &veb->tc_stats_offsets;
  627. /* Gather up the stats that the hw collects */
  628. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  629. veb->stat_offsets_loaded,
  630. &oes->tx_discards, &es->tx_discards);
  631. if (hw->revision_id > 0)
  632. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  633. veb->stat_offsets_loaded,
  634. &oes->rx_unknown_protocol,
  635. &es->rx_unknown_protocol);
  636. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  637. veb->stat_offsets_loaded,
  638. &oes->rx_bytes, &es->rx_bytes);
  639. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  640. veb->stat_offsets_loaded,
  641. &oes->rx_unicast, &es->rx_unicast);
  642. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  643. veb->stat_offsets_loaded,
  644. &oes->rx_multicast, &es->rx_multicast);
  645. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  646. veb->stat_offsets_loaded,
  647. &oes->rx_broadcast, &es->rx_broadcast);
  648. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  649. veb->stat_offsets_loaded,
  650. &oes->tx_bytes, &es->tx_bytes);
  651. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  652. veb->stat_offsets_loaded,
  653. &oes->tx_unicast, &es->tx_unicast);
  654. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  655. veb->stat_offsets_loaded,
  656. &oes->tx_multicast, &es->tx_multicast);
  657. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  658. veb->stat_offsets_loaded,
  659. &oes->tx_broadcast, &es->tx_broadcast);
  660. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  661. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  662. I40E_GLVEBTC_RPCL(i, idx),
  663. veb->stat_offsets_loaded,
  664. &veb_oes->tc_rx_packets[i],
  665. &veb_es->tc_rx_packets[i]);
  666. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  667. I40E_GLVEBTC_RBCL(i, idx),
  668. veb->stat_offsets_loaded,
  669. &veb_oes->tc_rx_bytes[i],
  670. &veb_es->tc_rx_bytes[i]);
  671. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  672. I40E_GLVEBTC_TPCL(i, idx),
  673. veb->stat_offsets_loaded,
  674. &veb_oes->tc_tx_packets[i],
  675. &veb_es->tc_tx_packets[i]);
  676. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  677. I40E_GLVEBTC_TBCL(i, idx),
  678. veb->stat_offsets_loaded,
  679. &veb_oes->tc_tx_bytes[i],
  680. &veb_es->tc_tx_bytes[i]);
  681. }
  682. veb->stat_offsets_loaded = true;
  683. }
  684. /**
  685. * i40e_update_vsi_stats - Update the vsi statistics counters.
  686. * @vsi: the VSI to be updated
  687. *
  688. * There are a few instances where we store the same stat in a
  689. * couple of different structs. This is partly because we have
  690. * the netdev stats that need to be filled out, which is slightly
  691. * different from the "eth_stats" defined by the chip and used in
  692. * VF communications. We sort it out here.
  693. **/
  694. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  695. {
  696. struct i40e_pf *pf = vsi->back;
  697. struct rtnl_link_stats64 *ons;
  698. struct rtnl_link_stats64 *ns; /* netdev stats */
  699. struct i40e_eth_stats *oes;
  700. struct i40e_eth_stats *es; /* device's eth stats */
  701. u32 tx_restart, tx_busy;
  702. struct i40e_ring *p;
  703. u32 rx_page, rx_buf;
  704. u64 bytes, packets;
  705. unsigned int start;
  706. u64 tx_linearize;
  707. u64 tx_force_wb;
  708. u64 rx_p, rx_b;
  709. u64 tx_p, tx_b;
  710. u16 q;
  711. if (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  712. test_bit(__I40E_CONFIG_BUSY, pf->state))
  713. return;
  714. ns = i40e_get_vsi_stats_struct(vsi);
  715. ons = &vsi->net_stats_offsets;
  716. es = &vsi->eth_stats;
  717. oes = &vsi->eth_stats_offsets;
  718. /* Gather up the netdev and vsi stats that the driver collects
  719. * on the fly during packet processing
  720. */
  721. rx_b = rx_p = 0;
  722. tx_b = tx_p = 0;
  723. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  724. rx_page = 0;
  725. rx_buf = 0;
  726. rcu_read_lock();
  727. for (q = 0; q < vsi->num_queue_pairs; q++) {
  728. /* locate Tx ring */
  729. p = READ_ONCE(vsi->tx_rings[q]);
  730. do {
  731. start = u64_stats_fetch_begin_irq(&p->syncp);
  732. packets = p->stats.packets;
  733. bytes = p->stats.bytes;
  734. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  735. tx_b += bytes;
  736. tx_p += packets;
  737. tx_restart += p->tx_stats.restart_queue;
  738. tx_busy += p->tx_stats.tx_busy;
  739. tx_linearize += p->tx_stats.tx_linearize;
  740. tx_force_wb += p->tx_stats.tx_force_wb;
  741. /* Rx queue is part of the same block as Tx queue */
  742. p = &p[1];
  743. do {
  744. start = u64_stats_fetch_begin_irq(&p->syncp);
  745. packets = p->stats.packets;
  746. bytes = p->stats.bytes;
  747. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  748. rx_b += bytes;
  749. rx_p += packets;
  750. rx_buf += p->rx_stats.alloc_buff_failed;
  751. rx_page += p->rx_stats.alloc_page_failed;
  752. }
  753. rcu_read_unlock();
  754. vsi->tx_restart = tx_restart;
  755. vsi->tx_busy = tx_busy;
  756. vsi->tx_linearize = tx_linearize;
  757. vsi->tx_force_wb = tx_force_wb;
  758. vsi->rx_page_failed = rx_page;
  759. vsi->rx_buf_failed = rx_buf;
  760. ns->rx_packets = rx_p;
  761. ns->rx_bytes = rx_b;
  762. ns->tx_packets = tx_p;
  763. ns->tx_bytes = tx_b;
  764. /* update netdev stats from eth stats */
  765. i40e_update_eth_stats(vsi);
  766. ons->tx_errors = oes->tx_errors;
  767. ns->tx_errors = es->tx_errors;
  768. ons->multicast = oes->rx_multicast;
  769. ns->multicast = es->rx_multicast;
  770. ons->rx_dropped = oes->rx_discards;
  771. ns->rx_dropped = es->rx_discards;
  772. ons->tx_dropped = oes->tx_discards;
  773. ns->tx_dropped = es->tx_discards;
  774. /* pull in a couple PF stats if this is the main vsi */
  775. if (vsi == pf->vsi[pf->lan_vsi]) {
  776. ns->rx_crc_errors = pf->stats.crc_errors;
  777. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  778. ns->rx_length_errors = pf->stats.rx_length_errors;
  779. }
  780. }
  781. /**
  782. * i40e_update_pf_stats - Update the PF statistics counters.
  783. * @pf: the PF to be updated
  784. **/
  785. static void i40e_update_pf_stats(struct i40e_pf *pf)
  786. {
  787. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  788. struct i40e_hw_port_stats *nsd = &pf->stats;
  789. struct i40e_hw *hw = &pf->hw;
  790. u32 val;
  791. int i;
  792. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  793. I40E_GLPRT_GORCL(hw->port),
  794. pf->stat_offsets_loaded,
  795. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  796. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  797. I40E_GLPRT_GOTCL(hw->port),
  798. pf->stat_offsets_loaded,
  799. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  800. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  801. pf->stat_offsets_loaded,
  802. &osd->eth.rx_discards,
  803. &nsd->eth.rx_discards);
  804. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  805. I40E_GLPRT_UPRCL(hw->port),
  806. pf->stat_offsets_loaded,
  807. &osd->eth.rx_unicast,
  808. &nsd->eth.rx_unicast);
  809. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  810. I40E_GLPRT_MPRCL(hw->port),
  811. pf->stat_offsets_loaded,
  812. &osd->eth.rx_multicast,
  813. &nsd->eth.rx_multicast);
  814. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  815. I40E_GLPRT_BPRCL(hw->port),
  816. pf->stat_offsets_loaded,
  817. &osd->eth.rx_broadcast,
  818. &nsd->eth.rx_broadcast);
  819. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  820. I40E_GLPRT_UPTCL(hw->port),
  821. pf->stat_offsets_loaded,
  822. &osd->eth.tx_unicast,
  823. &nsd->eth.tx_unicast);
  824. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  825. I40E_GLPRT_MPTCL(hw->port),
  826. pf->stat_offsets_loaded,
  827. &osd->eth.tx_multicast,
  828. &nsd->eth.tx_multicast);
  829. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  830. I40E_GLPRT_BPTCL(hw->port),
  831. pf->stat_offsets_loaded,
  832. &osd->eth.tx_broadcast,
  833. &nsd->eth.tx_broadcast);
  834. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  835. pf->stat_offsets_loaded,
  836. &osd->tx_dropped_link_down,
  837. &nsd->tx_dropped_link_down);
  838. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  839. pf->stat_offsets_loaded,
  840. &osd->crc_errors, &nsd->crc_errors);
  841. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  842. pf->stat_offsets_loaded,
  843. &osd->illegal_bytes, &nsd->illegal_bytes);
  844. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  845. pf->stat_offsets_loaded,
  846. &osd->mac_local_faults,
  847. &nsd->mac_local_faults);
  848. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  849. pf->stat_offsets_loaded,
  850. &osd->mac_remote_faults,
  851. &nsd->mac_remote_faults);
  852. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  853. pf->stat_offsets_loaded,
  854. &osd->rx_length_errors,
  855. &nsd->rx_length_errors);
  856. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  857. pf->stat_offsets_loaded,
  858. &osd->link_xon_rx, &nsd->link_xon_rx);
  859. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  860. pf->stat_offsets_loaded,
  861. &osd->link_xon_tx, &nsd->link_xon_tx);
  862. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  863. pf->stat_offsets_loaded,
  864. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  865. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  866. pf->stat_offsets_loaded,
  867. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  868. for (i = 0; i < 8; i++) {
  869. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  870. pf->stat_offsets_loaded,
  871. &osd->priority_xoff_rx[i],
  872. &nsd->priority_xoff_rx[i]);
  873. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  874. pf->stat_offsets_loaded,
  875. &osd->priority_xon_rx[i],
  876. &nsd->priority_xon_rx[i]);
  877. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  878. pf->stat_offsets_loaded,
  879. &osd->priority_xon_tx[i],
  880. &nsd->priority_xon_tx[i]);
  881. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  882. pf->stat_offsets_loaded,
  883. &osd->priority_xoff_tx[i],
  884. &nsd->priority_xoff_tx[i]);
  885. i40e_stat_update32(hw,
  886. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  887. pf->stat_offsets_loaded,
  888. &osd->priority_xon_2_xoff[i],
  889. &nsd->priority_xon_2_xoff[i]);
  890. }
  891. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  892. I40E_GLPRT_PRC64L(hw->port),
  893. pf->stat_offsets_loaded,
  894. &osd->rx_size_64, &nsd->rx_size_64);
  895. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  896. I40E_GLPRT_PRC127L(hw->port),
  897. pf->stat_offsets_loaded,
  898. &osd->rx_size_127, &nsd->rx_size_127);
  899. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  900. I40E_GLPRT_PRC255L(hw->port),
  901. pf->stat_offsets_loaded,
  902. &osd->rx_size_255, &nsd->rx_size_255);
  903. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  904. I40E_GLPRT_PRC511L(hw->port),
  905. pf->stat_offsets_loaded,
  906. &osd->rx_size_511, &nsd->rx_size_511);
  907. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  908. I40E_GLPRT_PRC1023L(hw->port),
  909. pf->stat_offsets_loaded,
  910. &osd->rx_size_1023, &nsd->rx_size_1023);
  911. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  912. I40E_GLPRT_PRC1522L(hw->port),
  913. pf->stat_offsets_loaded,
  914. &osd->rx_size_1522, &nsd->rx_size_1522);
  915. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  916. I40E_GLPRT_PRC9522L(hw->port),
  917. pf->stat_offsets_loaded,
  918. &osd->rx_size_big, &nsd->rx_size_big);
  919. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  920. I40E_GLPRT_PTC64L(hw->port),
  921. pf->stat_offsets_loaded,
  922. &osd->tx_size_64, &nsd->tx_size_64);
  923. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  924. I40E_GLPRT_PTC127L(hw->port),
  925. pf->stat_offsets_loaded,
  926. &osd->tx_size_127, &nsd->tx_size_127);
  927. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  928. I40E_GLPRT_PTC255L(hw->port),
  929. pf->stat_offsets_loaded,
  930. &osd->tx_size_255, &nsd->tx_size_255);
  931. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  932. I40E_GLPRT_PTC511L(hw->port),
  933. pf->stat_offsets_loaded,
  934. &osd->tx_size_511, &nsd->tx_size_511);
  935. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  936. I40E_GLPRT_PTC1023L(hw->port),
  937. pf->stat_offsets_loaded,
  938. &osd->tx_size_1023, &nsd->tx_size_1023);
  939. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  940. I40E_GLPRT_PTC1522L(hw->port),
  941. pf->stat_offsets_loaded,
  942. &osd->tx_size_1522, &nsd->tx_size_1522);
  943. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  944. I40E_GLPRT_PTC9522L(hw->port),
  945. pf->stat_offsets_loaded,
  946. &osd->tx_size_big, &nsd->tx_size_big);
  947. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  948. pf->stat_offsets_loaded,
  949. &osd->rx_undersize, &nsd->rx_undersize);
  950. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  951. pf->stat_offsets_loaded,
  952. &osd->rx_fragments, &nsd->rx_fragments);
  953. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  954. pf->stat_offsets_loaded,
  955. &osd->rx_oversize, &nsd->rx_oversize);
  956. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  957. pf->stat_offsets_loaded,
  958. &osd->rx_jabber, &nsd->rx_jabber);
  959. /* FDIR stats */
  960. i40e_stat_update_and_clear32(hw,
  961. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw->pf_id)),
  962. &nsd->fd_atr_match);
  963. i40e_stat_update_and_clear32(hw,
  964. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw->pf_id)),
  965. &nsd->fd_sb_match);
  966. i40e_stat_update_and_clear32(hw,
  967. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw->pf_id)),
  968. &nsd->fd_atr_tunnel_match);
  969. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  970. nsd->tx_lpi_status =
  971. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  972. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  973. nsd->rx_lpi_status =
  974. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  975. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  976. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  977. pf->stat_offsets_loaded,
  978. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  979. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  980. pf->stat_offsets_loaded,
  981. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  982. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  983. !(pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED))
  984. nsd->fd_sb_status = true;
  985. else
  986. nsd->fd_sb_status = false;
  987. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  988. !(pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED))
  989. nsd->fd_atr_status = true;
  990. else
  991. nsd->fd_atr_status = false;
  992. pf->stat_offsets_loaded = true;
  993. }
  994. /**
  995. * i40e_update_stats - Update the various statistics counters.
  996. * @vsi: the VSI to be updated
  997. *
  998. * Update the various stats for this VSI and its related entities.
  999. **/
  1000. void i40e_update_stats(struct i40e_vsi *vsi)
  1001. {
  1002. struct i40e_pf *pf = vsi->back;
  1003. if (vsi == pf->vsi[pf->lan_vsi])
  1004. i40e_update_pf_stats(pf);
  1005. i40e_update_vsi_stats(vsi);
  1006. }
  1007. /**
  1008. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1009. * @vsi: the VSI to be searched
  1010. * @macaddr: the MAC address
  1011. * @vlan: the vlan
  1012. *
  1013. * Returns ptr to the filter object or NULL
  1014. **/
  1015. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1016. const u8 *macaddr, s16 vlan)
  1017. {
  1018. struct i40e_mac_filter *f;
  1019. u64 key;
  1020. if (!vsi || !macaddr)
  1021. return NULL;
  1022. key = i40e_addr_to_hkey(macaddr);
  1023. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1024. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1025. (vlan == f->vlan))
  1026. return f;
  1027. }
  1028. return NULL;
  1029. }
  1030. /**
  1031. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1032. * @vsi: the VSI to be searched
  1033. * @macaddr: the MAC address we are searching for
  1034. *
  1035. * Returns the first filter with the provided MAC address or NULL if
  1036. * MAC address was not found
  1037. **/
  1038. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1039. {
  1040. struct i40e_mac_filter *f;
  1041. u64 key;
  1042. if (!vsi || !macaddr)
  1043. return NULL;
  1044. key = i40e_addr_to_hkey(macaddr);
  1045. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1046. if ((ether_addr_equal(macaddr, f->macaddr)))
  1047. return f;
  1048. }
  1049. return NULL;
  1050. }
  1051. /**
  1052. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1053. * @vsi: the VSI to be searched
  1054. *
  1055. * Returns true if VSI is in vlan mode or false otherwise
  1056. **/
  1057. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1058. {
  1059. /* If we have a PVID, always operate in VLAN mode */
  1060. if (vsi->info.pvid)
  1061. return true;
  1062. /* We need to operate in VLAN mode whenever we have any filters with
  1063. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1064. * time, incurring search cost repeatedly. However, we can notice two
  1065. * things:
  1066. *
  1067. * 1) the only place where we can gain a VLAN filter is in
  1068. * i40e_add_filter.
  1069. *
  1070. * 2) the only place where filters are actually removed is in
  1071. * i40e_sync_filters_subtask.
  1072. *
  1073. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1074. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1075. * we have to perform the full search after deleting filters in
  1076. * i40e_sync_filters_subtask, but we already have to search
  1077. * filters here and can perform the check at the same time. This
  1078. * results in avoiding embedding a loop for VLAN mode inside another
  1079. * loop over all the filters, and should maintain correctness as noted
  1080. * above.
  1081. */
  1082. return vsi->has_vlan_filter;
  1083. }
  1084. /**
  1085. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1086. * @vsi: the VSI to configure
  1087. * @tmp_add_list: list of filters ready to be added
  1088. * @tmp_del_list: list of filters ready to be deleted
  1089. * @vlan_filters: the number of active VLAN filters
  1090. *
  1091. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1092. * behave as expected. If we have any active VLAN filters remaining or about
  1093. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1094. * so that they only match against untagged traffic. If we no longer have any
  1095. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1096. * so that they match against both tagged and untagged traffic. In this way,
  1097. * we ensure that we correctly receive the desired traffic. This ensures that
  1098. * when we have an active VLAN we will receive only untagged traffic and
  1099. * traffic matching active VLANs. If we have no active VLANs then we will
  1100. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1101. *
  1102. * Finally, in a similar fashion, this function also corrects filters when
  1103. * there is an active PVID assigned to this VSI.
  1104. *
  1105. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1106. *
  1107. * This function is only expected to be called from within
  1108. * i40e_sync_vsi_filters.
  1109. *
  1110. * NOTE: This function expects to be called while under the
  1111. * mac_filter_hash_lock
  1112. */
  1113. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1114. struct hlist_head *tmp_add_list,
  1115. struct hlist_head *tmp_del_list,
  1116. int vlan_filters)
  1117. {
  1118. s16 pvid = le16_to_cpu(vsi->info.pvid);
  1119. struct i40e_mac_filter *f, *add_head;
  1120. struct i40e_new_mac_filter *new;
  1121. struct hlist_node *h;
  1122. int bkt, new_vlan;
  1123. /* To determine if a particular filter needs to be replaced we
  1124. * have the three following conditions:
  1125. *
  1126. * a) if we have a PVID assigned, then all filters which are
  1127. * not marked as VLAN=PVID must be replaced with filters that
  1128. * are.
  1129. * b) otherwise, if we have any active VLANS, all filters
  1130. * which are marked as VLAN=-1 must be replaced with
  1131. * filters marked as VLAN=0
  1132. * c) finally, if we do not have any active VLANS, all filters
  1133. * which are marked as VLAN=0 must be replaced with filters
  1134. * marked as VLAN=-1
  1135. */
  1136. /* Update the filters about to be added in place */
  1137. hlist_for_each_entry(new, tmp_add_list, hlist) {
  1138. if (pvid && new->f->vlan != pvid)
  1139. new->f->vlan = pvid;
  1140. else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
  1141. new->f->vlan = 0;
  1142. else if (!vlan_filters && new->f->vlan == 0)
  1143. new->f->vlan = I40E_VLAN_ANY;
  1144. }
  1145. /* Update the remaining active filters */
  1146. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1147. /* Combine the checks for whether a filter needs to be changed
  1148. * and then determine the new VLAN inside the if block, in
  1149. * order to avoid duplicating code for adding the new filter
  1150. * then deleting the old filter.
  1151. */
  1152. if ((pvid && f->vlan != pvid) ||
  1153. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1154. (!vlan_filters && f->vlan == 0)) {
  1155. /* Determine the new vlan we will be adding */
  1156. if (pvid)
  1157. new_vlan = pvid;
  1158. else if (vlan_filters)
  1159. new_vlan = 0;
  1160. else
  1161. new_vlan = I40E_VLAN_ANY;
  1162. /* Create the new filter */
  1163. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1164. if (!add_head)
  1165. return -ENOMEM;
  1166. /* Create a temporary i40e_new_mac_filter */
  1167. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  1168. if (!new)
  1169. return -ENOMEM;
  1170. new->f = add_head;
  1171. new->state = add_head->state;
  1172. /* Add the new filter to the tmp list */
  1173. hlist_add_head(&new->hlist, tmp_add_list);
  1174. /* Put the original filter into the delete list */
  1175. f->state = I40E_FILTER_REMOVE;
  1176. hash_del(&f->hlist);
  1177. hlist_add_head(&f->hlist, tmp_del_list);
  1178. }
  1179. }
  1180. vsi->has_vlan_filter = !!vlan_filters;
  1181. return 0;
  1182. }
  1183. /**
  1184. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1185. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1186. * @macaddr: the MAC address
  1187. *
  1188. * Remove whatever filter the firmware set up so the driver can manage
  1189. * its own filtering intelligently.
  1190. **/
  1191. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1192. {
  1193. struct i40e_aqc_remove_macvlan_element_data element;
  1194. struct i40e_pf *pf = vsi->back;
  1195. /* Only appropriate for the PF main VSI */
  1196. if (vsi->type != I40E_VSI_MAIN)
  1197. return;
  1198. memset(&element, 0, sizeof(element));
  1199. ether_addr_copy(element.mac_addr, macaddr);
  1200. element.vlan_tag = 0;
  1201. /* Ignore error returns, some firmware does it this way... */
  1202. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1203. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1204. memset(&element, 0, sizeof(element));
  1205. ether_addr_copy(element.mac_addr, macaddr);
  1206. element.vlan_tag = 0;
  1207. /* ...and some firmware does it this way. */
  1208. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1209. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1210. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1211. }
  1212. /**
  1213. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1214. * @vsi: the VSI to be searched
  1215. * @macaddr: the MAC address
  1216. * @vlan: the vlan
  1217. *
  1218. * Returns ptr to the filter object or NULL when no memory available.
  1219. *
  1220. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1221. * being held.
  1222. **/
  1223. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1224. const u8 *macaddr, s16 vlan)
  1225. {
  1226. struct i40e_mac_filter *f;
  1227. u64 key;
  1228. if (!vsi || !macaddr)
  1229. return NULL;
  1230. f = i40e_find_filter(vsi, macaddr, vlan);
  1231. if (!f) {
  1232. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1233. if (!f)
  1234. return NULL;
  1235. /* Update the boolean indicating if we need to function in
  1236. * VLAN mode.
  1237. */
  1238. if (vlan >= 0)
  1239. vsi->has_vlan_filter = true;
  1240. ether_addr_copy(f->macaddr, macaddr);
  1241. f->vlan = vlan;
  1242. /* If we're in overflow promisc mode, set the state directly
  1243. * to failed, so we don't bother to try sending the filter
  1244. * to the hardware.
  1245. */
  1246. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state))
  1247. f->state = I40E_FILTER_FAILED;
  1248. else
  1249. f->state = I40E_FILTER_NEW;
  1250. INIT_HLIST_NODE(&f->hlist);
  1251. key = i40e_addr_to_hkey(macaddr);
  1252. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1253. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1254. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1255. }
  1256. /* If we're asked to add a filter that has been marked for removal, it
  1257. * is safe to simply restore it to active state. __i40e_del_filter
  1258. * will have simply deleted any filters which were previously marked
  1259. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1260. * previously been ACTIVE. Since we haven't yet run the sync filters
  1261. * task, just restore this filter to the ACTIVE state so that the
  1262. * sync task leaves it in place
  1263. */
  1264. if (f->state == I40E_FILTER_REMOVE)
  1265. f->state = I40E_FILTER_ACTIVE;
  1266. return f;
  1267. }
  1268. /**
  1269. * __i40e_del_filter - Remove a specific filter from the VSI
  1270. * @vsi: VSI to remove from
  1271. * @f: the filter to remove from the list
  1272. *
  1273. * This function should be called instead of i40e_del_filter only if you know
  1274. * the exact filter you will remove already, such as via i40e_find_filter or
  1275. * i40e_find_mac.
  1276. *
  1277. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1278. * being held.
  1279. * ANOTHER NOTE: This function MUST be called from within the context of
  1280. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1281. * instead of list_for_each_entry().
  1282. **/
  1283. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1284. {
  1285. if (!f)
  1286. return;
  1287. /* If the filter was never added to firmware then we can just delete it
  1288. * directly and we don't want to set the status to remove or else an
  1289. * admin queue command will unnecessarily fire.
  1290. */
  1291. if ((f->state == I40E_FILTER_FAILED) ||
  1292. (f->state == I40E_FILTER_NEW)) {
  1293. hash_del(&f->hlist);
  1294. kfree(f);
  1295. } else {
  1296. f->state = I40E_FILTER_REMOVE;
  1297. }
  1298. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1299. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1300. }
  1301. /**
  1302. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1303. * @vsi: the VSI to be searched
  1304. * @macaddr: the MAC address
  1305. * @vlan: the VLAN
  1306. *
  1307. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1308. * being held.
  1309. * ANOTHER NOTE: This function MUST be called from within the context of
  1310. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1311. * instead of list_for_each_entry().
  1312. **/
  1313. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1314. {
  1315. struct i40e_mac_filter *f;
  1316. if (!vsi || !macaddr)
  1317. return;
  1318. f = i40e_find_filter(vsi, macaddr, vlan);
  1319. __i40e_del_filter(vsi, f);
  1320. }
  1321. /**
  1322. * i40e_add_mac_filter - Add a MAC filter for all active VLANs
  1323. * @vsi: the VSI to be searched
  1324. * @macaddr: the mac address to be filtered
  1325. *
  1326. * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
  1327. * go through all the macvlan filters and add a macvlan filter for each
  1328. * unique vlan that already exists. If a PVID has been assigned, instead only
  1329. * add the macaddr to that VLAN.
  1330. *
  1331. * Returns last filter added on success, else NULL
  1332. **/
  1333. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1334. const u8 *macaddr)
  1335. {
  1336. struct i40e_mac_filter *f, *add = NULL;
  1337. struct hlist_node *h;
  1338. int bkt;
  1339. if (vsi->info.pvid)
  1340. return i40e_add_filter(vsi, macaddr,
  1341. le16_to_cpu(vsi->info.pvid));
  1342. if (!i40e_is_vsi_in_vlan(vsi))
  1343. return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
  1344. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1345. if (f->state == I40E_FILTER_REMOVE)
  1346. continue;
  1347. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1348. if (!add)
  1349. return NULL;
  1350. }
  1351. return add;
  1352. }
  1353. /**
  1354. * i40e_del_mac_filter - Remove a MAC filter from all VLANs
  1355. * @vsi: the VSI to be searched
  1356. * @macaddr: the mac address to be removed
  1357. *
  1358. * Removes a given MAC address from a VSI regardless of what VLAN it has been
  1359. * associated with.
  1360. *
  1361. * Returns 0 for success, or error
  1362. **/
  1363. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
  1364. {
  1365. struct i40e_mac_filter *f;
  1366. struct hlist_node *h;
  1367. bool found = false;
  1368. int bkt;
  1369. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1370. "Missing mac_filter_hash_lock\n");
  1371. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1372. if (ether_addr_equal(macaddr, f->macaddr)) {
  1373. __i40e_del_filter(vsi, f);
  1374. found = true;
  1375. }
  1376. }
  1377. if (found)
  1378. return 0;
  1379. else
  1380. return -ENOENT;
  1381. }
  1382. /**
  1383. * i40e_set_mac - NDO callback to set mac address
  1384. * @netdev: network interface device structure
  1385. * @p: pointer to an address structure
  1386. *
  1387. * Returns 0 on success, negative on failure
  1388. **/
  1389. static int i40e_set_mac(struct net_device *netdev, void *p)
  1390. {
  1391. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1392. struct i40e_vsi *vsi = np->vsi;
  1393. struct i40e_pf *pf = vsi->back;
  1394. struct i40e_hw *hw = &pf->hw;
  1395. struct sockaddr *addr = p;
  1396. if (!is_valid_ether_addr(addr->sa_data))
  1397. return -EADDRNOTAVAIL;
  1398. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1399. netdev_info(netdev, "already using mac address %pM\n",
  1400. addr->sa_data);
  1401. return 0;
  1402. }
  1403. if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
  1404. test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
  1405. return -EADDRNOTAVAIL;
  1406. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1407. netdev_info(netdev, "returning to hw mac address %pM\n",
  1408. hw->mac.addr);
  1409. else
  1410. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1411. /* Copy the address first, so that we avoid a possible race with
  1412. * .set_rx_mode(). If we copy after changing the address in the filter
  1413. * list, we might open ourselves to a narrow race window where
  1414. * .set_rx_mode could delete our dev_addr filter and prevent traffic
  1415. * from passing.
  1416. */
  1417. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1418. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1419. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1420. i40e_add_mac_filter(vsi, addr->sa_data);
  1421. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1422. if (vsi->type == I40E_VSI_MAIN) {
  1423. i40e_status ret;
  1424. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1425. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1426. addr->sa_data, NULL);
  1427. if (ret)
  1428. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1429. i40e_stat_str(hw, ret),
  1430. i40e_aq_str(hw, hw->aq.asq_last_status));
  1431. }
  1432. /* schedule our worker thread which will take care of
  1433. * applying the new filter changes
  1434. */
  1435. i40e_service_event_schedule(vsi->back);
  1436. return 0;
  1437. }
  1438. /**
  1439. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  1440. * @vsi: vsi structure
  1441. * @seed: RSS hash seed
  1442. **/
  1443. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1444. u8 *lut, u16 lut_size)
  1445. {
  1446. struct i40e_pf *pf = vsi->back;
  1447. struct i40e_hw *hw = &pf->hw;
  1448. int ret = 0;
  1449. if (seed) {
  1450. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  1451. (struct i40e_aqc_get_set_rss_key_data *)seed;
  1452. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  1453. if (ret) {
  1454. dev_info(&pf->pdev->dev,
  1455. "Cannot set RSS key, err %s aq_err %s\n",
  1456. i40e_stat_str(hw, ret),
  1457. i40e_aq_str(hw, hw->aq.asq_last_status));
  1458. return ret;
  1459. }
  1460. }
  1461. if (lut) {
  1462. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  1463. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  1464. if (ret) {
  1465. dev_info(&pf->pdev->dev,
  1466. "Cannot set RSS lut, err %s aq_err %s\n",
  1467. i40e_stat_str(hw, ret),
  1468. i40e_aq_str(hw, hw->aq.asq_last_status));
  1469. return ret;
  1470. }
  1471. }
  1472. return ret;
  1473. }
  1474. /**
  1475. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  1476. * @vsi: VSI structure
  1477. **/
  1478. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  1479. {
  1480. struct i40e_pf *pf = vsi->back;
  1481. u8 seed[I40E_HKEY_ARRAY_SIZE];
  1482. u8 *lut;
  1483. int ret;
  1484. if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
  1485. return 0;
  1486. if (!vsi->rss_size)
  1487. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  1488. vsi->num_queue_pairs);
  1489. if (!vsi->rss_size)
  1490. return -EINVAL;
  1491. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  1492. if (!lut)
  1493. return -ENOMEM;
  1494. /* Use the user configured hash keys and lookup table if there is one,
  1495. * otherwise use default
  1496. */
  1497. if (vsi->rss_lut_user)
  1498. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  1499. else
  1500. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  1501. if (vsi->rss_hkey_user)
  1502. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  1503. else
  1504. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  1505. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  1506. kfree(lut);
  1507. return ret;
  1508. }
  1509. /**
  1510. * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
  1511. * @vsi: the VSI being configured,
  1512. * @ctxt: VSI context structure
  1513. * @enabled_tc: number of traffic classes to enable
  1514. *
  1515. * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
  1516. **/
  1517. static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi,
  1518. struct i40e_vsi_context *ctxt,
  1519. u8 enabled_tc)
  1520. {
  1521. u16 qcount = 0, max_qcount, qmap, sections = 0;
  1522. int i, override_q, pow, num_qps, ret;
  1523. u8 netdev_tc = 0, offset = 0;
  1524. if (vsi->type != I40E_VSI_MAIN)
  1525. return -EINVAL;
  1526. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1527. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1528. vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc;
  1529. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1530. num_qps = vsi->mqprio_qopt.qopt.count[0];
  1531. /* find the next higher power-of-2 of num queue pairs */
  1532. pow = ilog2(num_qps);
  1533. if (!is_power_of_2(num_qps))
  1534. pow++;
  1535. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1536. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1537. /* Setup queue offset/count for all TCs for given VSI */
  1538. max_qcount = vsi->mqprio_qopt.qopt.count[0];
  1539. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1540. /* See if the given TC is enabled for the given VSI */
  1541. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1542. offset = vsi->mqprio_qopt.qopt.offset[i];
  1543. qcount = vsi->mqprio_qopt.qopt.count[i];
  1544. if (qcount > max_qcount)
  1545. max_qcount = qcount;
  1546. vsi->tc_config.tc_info[i].qoffset = offset;
  1547. vsi->tc_config.tc_info[i].qcount = qcount;
  1548. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1549. } else {
  1550. /* TC is not enabled so set the offset to
  1551. * default queue and allocate one queue
  1552. * for the given TC.
  1553. */
  1554. vsi->tc_config.tc_info[i].qoffset = 0;
  1555. vsi->tc_config.tc_info[i].qcount = 1;
  1556. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1557. }
  1558. }
  1559. /* Set actual Tx/Rx queue pairs */
  1560. vsi->num_queue_pairs = offset + qcount;
  1561. /* Setup queue TC[0].qmap for given VSI context */
  1562. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  1563. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1564. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1565. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1566. /* Reconfigure RSS for main VSI with max queue count */
  1567. vsi->rss_size = max_qcount;
  1568. ret = i40e_vsi_config_rss(vsi);
  1569. if (ret) {
  1570. dev_info(&vsi->back->pdev->dev,
  1571. "Failed to reconfig rss for num_queues (%u)\n",
  1572. max_qcount);
  1573. return ret;
  1574. }
  1575. vsi->reconfig_rss = true;
  1576. dev_dbg(&vsi->back->pdev->dev,
  1577. "Reconfigured rss with num_queues (%u)\n", max_qcount);
  1578. /* Find queue count available for channel VSIs and starting offset
  1579. * for channel VSIs
  1580. */
  1581. override_q = vsi->mqprio_qopt.qopt.count[0];
  1582. if (override_q && override_q < vsi->num_queue_pairs) {
  1583. vsi->cnt_q_avail = vsi->num_queue_pairs - override_q;
  1584. vsi->next_base_queue = override_q;
  1585. }
  1586. return 0;
  1587. }
  1588. /**
  1589. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1590. * @vsi: the VSI being setup
  1591. * @ctxt: VSI context structure
  1592. * @enabled_tc: Enabled TCs bitmap
  1593. * @is_add: True if called before Add VSI
  1594. *
  1595. * Setup VSI queue mapping for enabled traffic classes.
  1596. **/
  1597. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1598. struct i40e_vsi_context *ctxt,
  1599. u8 enabled_tc,
  1600. bool is_add)
  1601. {
  1602. struct i40e_pf *pf = vsi->back;
  1603. u16 sections = 0;
  1604. u8 netdev_tc = 0;
  1605. u16 numtc = 0;
  1606. u16 qcount;
  1607. u8 offset;
  1608. u16 qmap;
  1609. int i;
  1610. u16 num_tc_qps = 0;
  1611. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1612. offset = 0;
  1613. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1614. /* Find numtc from enabled TC bitmap */
  1615. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1616. if (enabled_tc & BIT(i)) /* TC is enabled */
  1617. numtc++;
  1618. }
  1619. if (!numtc) {
  1620. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1621. numtc = 1;
  1622. }
  1623. } else {
  1624. /* At least TC0 is enabled in non-DCB, non-MQPRIO case */
  1625. numtc = 1;
  1626. }
  1627. vsi->tc_config.numtc = numtc;
  1628. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1629. /* Number of queues per enabled TC */
  1630. qcount = vsi->alloc_queue_pairs;
  1631. num_tc_qps = qcount / numtc;
  1632. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1633. /* Setup queue offset/count for all TCs for given VSI */
  1634. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1635. /* See if the given TC is enabled for the given VSI */
  1636. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1637. /* TC is enabled */
  1638. int pow, num_qps;
  1639. switch (vsi->type) {
  1640. case I40E_VSI_MAIN:
  1641. qcount = min_t(int, pf->alloc_rss_size,
  1642. num_tc_qps);
  1643. break;
  1644. case I40E_VSI_FDIR:
  1645. case I40E_VSI_SRIOV:
  1646. case I40E_VSI_VMDQ2:
  1647. default:
  1648. qcount = num_tc_qps;
  1649. WARN_ON(i != 0);
  1650. break;
  1651. }
  1652. vsi->tc_config.tc_info[i].qoffset = offset;
  1653. vsi->tc_config.tc_info[i].qcount = qcount;
  1654. /* find the next higher power-of-2 of num queue pairs */
  1655. num_qps = qcount;
  1656. pow = 0;
  1657. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1658. pow++;
  1659. num_qps >>= 1;
  1660. }
  1661. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1662. qmap =
  1663. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1664. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1665. offset += qcount;
  1666. } else {
  1667. /* TC is not enabled so set the offset to
  1668. * default queue and allocate one queue
  1669. * for the given TC.
  1670. */
  1671. vsi->tc_config.tc_info[i].qoffset = 0;
  1672. vsi->tc_config.tc_info[i].qcount = 1;
  1673. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1674. qmap = 0;
  1675. }
  1676. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1677. }
  1678. /* Set actual Tx/Rx queue pairs */
  1679. vsi->num_queue_pairs = offset;
  1680. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1681. if (vsi->req_queue_pairs > 0)
  1682. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1683. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1684. vsi->num_queue_pairs = pf->num_lan_msix;
  1685. }
  1686. /* Scheduler section valid can only be set for ADD VSI */
  1687. if (is_add) {
  1688. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1689. ctxt->info.up_enable_bits = enabled_tc;
  1690. }
  1691. if (vsi->type == I40E_VSI_SRIOV) {
  1692. ctxt->info.mapping_flags |=
  1693. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1694. for (i = 0; i < vsi->num_queue_pairs; i++)
  1695. ctxt->info.queue_mapping[i] =
  1696. cpu_to_le16(vsi->base_queue + i);
  1697. } else {
  1698. ctxt->info.mapping_flags |=
  1699. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1700. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1701. }
  1702. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1703. }
  1704. /**
  1705. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1706. * @netdev: the netdevice
  1707. * @addr: address to add
  1708. *
  1709. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1710. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1711. */
  1712. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1713. {
  1714. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1715. struct i40e_vsi *vsi = np->vsi;
  1716. if (i40e_add_mac_filter(vsi, addr))
  1717. return 0;
  1718. else
  1719. return -ENOMEM;
  1720. }
  1721. /**
  1722. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1723. * @netdev: the netdevice
  1724. * @addr: address to add
  1725. *
  1726. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1727. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1728. */
  1729. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1730. {
  1731. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1732. struct i40e_vsi *vsi = np->vsi;
  1733. /* Under some circumstances, we might receive a request to delete
  1734. * our own device address from our uc list. Because we store the
  1735. * device address in the VSI's MAC/VLAN filter list, we need to ignore
  1736. * such requests and not delete our device address from this list.
  1737. */
  1738. if (ether_addr_equal(addr, netdev->dev_addr))
  1739. return 0;
  1740. i40e_del_mac_filter(vsi, addr);
  1741. return 0;
  1742. }
  1743. /**
  1744. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1745. * @netdev: network interface device structure
  1746. **/
  1747. static void i40e_set_rx_mode(struct net_device *netdev)
  1748. {
  1749. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1750. struct i40e_vsi *vsi = np->vsi;
  1751. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1752. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1753. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1754. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1755. /* check for other flag changes */
  1756. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1757. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1758. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1759. }
  1760. }
  1761. /**
  1762. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1763. * @vsi: Pointer to VSI struct
  1764. * @from: Pointer to list which contains MAC filter entries - changes to
  1765. * those entries needs to be undone.
  1766. *
  1767. * MAC filter entries from this list were slated for deletion.
  1768. **/
  1769. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1770. struct hlist_head *from)
  1771. {
  1772. struct i40e_mac_filter *f;
  1773. struct hlist_node *h;
  1774. hlist_for_each_entry_safe(f, h, from, hlist) {
  1775. u64 key = i40e_addr_to_hkey(f->macaddr);
  1776. /* Move the element back into MAC filter list*/
  1777. hlist_del(&f->hlist);
  1778. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1779. }
  1780. }
  1781. /**
  1782. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1783. * @vsi: Pointer to vsi struct
  1784. * @from: Pointer to list which contains MAC filter entries - changes to
  1785. * those entries needs to be undone.
  1786. *
  1787. * MAC filter entries from this list were slated for addition.
  1788. **/
  1789. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
  1790. struct hlist_head *from)
  1791. {
  1792. struct i40e_new_mac_filter *new;
  1793. struct hlist_node *h;
  1794. hlist_for_each_entry_safe(new, h, from, hlist) {
  1795. /* We can simply free the wrapper structure */
  1796. hlist_del(&new->hlist);
  1797. kfree(new);
  1798. }
  1799. }
  1800. /**
  1801. * i40e_next_entry - Get the next non-broadcast filter from a list
  1802. * @next: pointer to filter in list
  1803. *
  1804. * Returns the next non-broadcast filter in the list. Required so that we
  1805. * ignore broadcast filters within the list, since these are not handled via
  1806. * the normal firmware update path.
  1807. */
  1808. static
  1809. struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
  1810. {
  1811. hlist_for_each_entry_continue(next, hlist) {
  1812. if (!is_broadcast_ether_addr(next->f->macaddr))
  1813. return next;
  1814. }
  1815. return NULL;
  1816. }
  1817. /**
  1818. * i40e_update_filter_state - Update filter state based on return data
  1819. * from firmware
  1820. * @count: Number of filters added
  1821. * @add_list: return data from fw
  1822. * @head: pointer to first filter in current batch
  1823. *
  1824. * MAC filter entries from list were slated to be added to device. Returns
  1825. * number of successful filters. Note that 0 does NOT mean success!
  1826. **/
  1827. static int
  1828. i40e_update_filter_state(int count,
  1829. struct i40e_aqc_add_macvlan_element_data *add_list,
  1830. struct i40e_new_mac_filter *add_head)
  1831. {
  1832. int retval = 0;
  1833. int i;
  1834. for (i = 0; i < count; i++) {
  1835. /* Always check status of each filter. We don't need to check
  1836. * the firmware return status because we pre-set the filter
  1837. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1838. * request to the adminq. Thus, if it no longer matches then
  1839. * we know the filter is active.
  1840. */
  1841. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1842. add_head->state = I40E_FILTER_FAILED;
  1843. } else {
  1844. add_head->state = I40E_FILTER_ACTIVE;
  1845. retval++;
  1846. }
  1847. add_head = i40e_next_filter(add_head);
  1848. if (!add_head)
  1849. break;
  1850. }
  1851. return retval;
  1852. }
  1853. /**
  1854. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1855. * @vsi: ptr to the VSI
  1856. * @vsi_name: name to display in messages
  1857. * @list: the list of filters to send to firmware
  1858. * @num_del: the number of filters to delete
  1859. * @retval: Set to -EIO on failure to delete
  1860. *
  1861. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1862. * *retval instead of a return value so that success does not force ret_val to
  1863. * be set to 0. This ensures that a sequence of calls to this function
  1864. * preserve the previous value of *retval on successful delete.
  1865. */
  1866. static
  1867. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1868. struct i40e_aqc_remove_macvlan_element_data *list,
  1869. int num_del, int *retval)
  1870. {
  1871. struct i40e_hw *hw = &vsi->back->hw;
  1872. i40e_status aq_ret;
  1873. int aq_err;
  1874. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1875. aq_err = hw->aq.asq_last_status;
  1876. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1877. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1878. *retval = -EIO;
  1879. dev_info(&vsi->back->pdev->dev,
  1880. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1881. vsi_name, i40e_stat_str(hw, aq_ret),
  1882. i40e_aq_str(hw, aq_err));
  1883. }
  1884. }
  1885. /**
  1886. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1887. * @vsi: ptr to the VSI
  1888. * @vsi_name: name to display in messages
  1889. * @list: the list of filters to send to firmware
  1890. * @add_head: Position in the add hlist
  1891. * @num_add: the number of filters to add
  1892. * @promisc_change: set to true on exit if promiscuous mode was forced on
  1893. *
  1894. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1895. * promisc_changed to true if the firmware has run out of space for more
  1896. * filters.
  1897. */
  1898. static
  1899. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1900. struct i40e_aqc_add_macvlan_element_data *list,
  1901. struct i40e_new_mac_filter *add_head,
  1902. int num_add, bool *promisc_changed)
  1903. {
  1904. struct i40e_hw *hw = &vsi->back->hw;
  1905. int aq_err, fcnt;
  1906. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1907. aq_err = hw->aq.asq_last_status;
  1908. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1909. if (fcnt != num_add) {
  1910. *promisc_changed = true;
  1911. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1912. dev_warn(&vsi->back->pdev->dev,
  1913. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1914. i40e_aq_str(hw, aq_err),
  1915. vsi_name);
  1916. }
  1917. }
  1918. /**
  1919. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1920. * @vsi: pointer to the VSI
  1921. * @f: filter data
  1922. *
  1923. * This function sets or clears the promiscuous broadcast flags for VLAN
  1924. * filters in order to properly receive broadcast frames. Assumes that only
  1925. * broadcast filters are passed.
  1926. *
  1927. * Returns status indicating success or failure;
  1928. **/
  1929. static i40e_status
  1930. i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1931. struct i40e_mac_filter *f)
  1932. {
  1933. bool enable = f->state == I40E_FILTER_NEW;
  1934. struct i40e_hw *hw = &vsi->back->hw;
  1935. i40e_status aq_ret;
  1936. if (f->vlan == I40E_VLAN_ANY) {
  1937. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1938. vsi->seid,
  1939. enable,
  1940. NULL);
  1941. } else {
  1942. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1943. vsi->seid,
  1944. enable,
  1945. f->vlan,
  1946. NULL);
  1947. }
  1948. if (aq_ret)
  1949. dev_warn(&vsi->back->pdev->dev,
  1950. "Error %s setting broadcast promiscuous mode on %s\n",
  1951. i40e_aq_str(hw, hw->aq.asq_last_status),
  1952. vsi_name);
  1953. return aq_ret;
  1954. }
  1955. /**
  1956. * i40e_set_promiscuous - set promiscuous mode
  1957. * @pf: board private structure
  1958. * @promisc: promisc on or off
  1959. *
  1960. * There are different ways of setting promiscuous mode on a PF depending on
  1961. * what state/environment we're in. This identifies and sets it appropriately.
  1962. * Returns 0 on success.
  1963. **/
  1964. static int i40e_set_promiscuous(struct i40e_pf *pf, bool promisc)
  1965. {
  1966. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1967. struct i40e_hw *hw = &pf->hw;
  1968. i40e_status aq_ret;
  1969. if (vsi->type == I40E_VSI_MAIN &&
  1970. pf->lan_veb != I40E_NO_VEB &&
  1971. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1972. /* set defport ON for Main VSI instead of true promisc
  1973. * this way we will get all unicast/multicast and VLAN
  1974. * promisc behavior but will not get VF or VMDq traffic
  1975. * replicated on the Main VSI.
  1976. */
  1977. if (promisc)
  1978. aq_ret = i40e_aq_set_default_vsi(hw,
  1979. vsi->seid,
  1980. NULL);
  1981. else
  1982. aq_ret = i40e_aq_clear_default_vsi(hw,
  1983. vsi->seid,
  1984. NULL);
  1985. if (aq_ret) {
  1986. dev_info(&pf->pdev->dev,
  1987. "Set default VSI failed, err %s, aq_err %s\n",
  1988. i40e_stat_str(hw, aq_ret),
  1989. i40e_aq_str(hw, hw->aq.asq_last_status));
  1990. }
  1991. } else {
  1992. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1993. hw,
  1994. vsi->seid,
  1995. promisc, NULL,
  1996. true);
  1997. if (aq_ret) {
  1998. dev_info(&pf->pdev->dev,
  1999. "set unicast promisc failed, err %s, aq_err %s\n",
  2000. i40e_stat_str(hw, aq_ret),
  2001. i40e_aq_str(hw, hw->aq.asq_last_status));
  2002. }
  2003. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  2004. hw,
  2005. vsi->seid,
  2006. promisc, NULL);
  2007. if (aq_ret) {
  2008. dev_info(&pf->pdev->dev,
  2009. "set multicast promisc failed, err %s, aq_err %s\n",
  2010. i40e_stat_str(hw, aq_ret),
  2011. i40e_aq_str(hw, hw->aq.asq_last_status));
  2012. }
  2013. }
  2014. if (!aq_ret)
  2015. pf->cur_promisc = promisc;
  2016. return aq_ret;
  2017. }
  2018. /**
  2019. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  2020. * @vsi: ptr to the VSI
  2021. *
  2022. * Push any outstanding VSI filter changes through the AdminQ.
  2023. *
  2024. * Returns 0 or error value
  2025. **/
  2026. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  2027. {
  2028. struct hlist_head tmp_add_list, tmp_del_list;
  2029. struct i40e_mac_filter *f;
  2030. struct i40e_new_mac_filter *new, *add_head = NULL;
  2031. struct i40e_hw *hw = &vsi->back->hw;
  2032. unsigned int failed_filters = 0;
  2033. unsigned int vlan_filters = 0;
  2034. bool promisc_changed = false;
  2035. char vsi_name[16] = "PF";
  2036. int filter_list_len = 0;
  2037. i40e_status aq_ret = 0;
  2038. u32 changed_flags = 0;
  2039. struct hlist_node *h;
  2040. struct i40e_pf *pf;
  2041. int num_add = 0;
  2042. int num_del = 0;
  2043. int retval = 0;
  2044. u16 cmd_flags;
  2045. int list_size;
  2046. int bkt;
  2047. /* empty array typed pointers, kcalloc later */
  2048. struct i40e_aqc_add_macvlan_element_data *add_list;
  2049. struct i40e_aqc_remove_macvlan_element_data *del_list;
  2050. while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
  2051. usleep_range(1000, 2000);
  2052. pf = vsi->back;
  2053. if (vsi->netdev) {
  2054. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  2055. vsi->current_netdev_flags = vsi->netdev->flags;
  2056. }
  2057. INIT_HLIST_HEAD(&tmp_add_list);
  2058. INIT_HLIST_HEAD(&tmp_del_list);
  2059. if (vsi->type == I40E_VSI_SRIOV)
  2060. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  2061. else if (vsi->type != I40E_VSI_MAIN)
  2062. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  2063. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  2064. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  2065. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2066. /* Create a list of filters to delete. */
  2067. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2068. if (f->state == I40E_FILTER_REMOVE) {
  2069. /* Move the element into temporary del_list */
  2070. hash_del(&f->hlist);
  2071. hlist_add_head(&f->hlist, &tmp_del_list);
  2072. /* Avoid counting removed filters */
  2073. continue;
  2074. }
  2075. if (f->state == I40E_FILTER_NEW) {
  2076. /* Create a temporary i40e_new_mac_filter */
  2077. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  2078. if (!new)
  2079. goto err_no_memory_locked;
  2080. /* Store pointer to the real filter */
  2081. new->f = f;
  2082. new->state = f->state;
  2083. /* Add it to the hash list */
  2084. hlist_add_head(&new->hlist, &tmp_add_list);
  2085. }
  2086. /* Count the number of active (current and new) VLAN
  2087. * filters we have now. Does not count filters which
  2088. * are marked for deletion.
  2089. */
  2090. if (f->vlan > 0)
  2091. vlan_filters++;
  2092. }
  2093. retval = i40e_correct_mac_vlan_filters(vsi,
  2094. &tmp_add_list,
  2095. &tmp_del_list,
  2096. vlan_filters);
  2097. if (retval)
  2098. goto err_no_memory_locked;
  2099. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2100. }
  2101. /* Now process 'del_list' outside the lock */
  2102. if (!hlist_empty(&tmp_del_list)) {
  2103. filter_list_len = hw->aq.asq_buf_size /
  2104. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2105. list_size = filter_list_len *
  2106. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2107. del_list = kzalloc(list_size, GFP_ATOMIC);
  2108. if (!del_list)
  2109. goto err_no_memory;
  2110. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  2111. cmd_flags = 0;
  2112. /* handle broadcast filters by updating the broadcast
  2113. * promiscuous flag and release filter list.
  2114. */
  2115. if (is_broadcast_ether_addr(f->macaddr)) {
  2116. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  2117. hlist_del(&f->hlist);
  2118. kfree(f);
  2119. continue;
  2120. }
  2121. /* add to delete list */
  2122. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  2123. if (f->vlan == I40E_VLAN_ANY) {
  2124. del_list[num_del].vlan_tag = 0;
  2125. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  2126. } else {
  2127. del_list[num_del].vlan_tag =
  2128. cpu_to_le16((u16)(f->vlan));
  2129. }
  2130. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  2131. del_list[num_del].flags = cmd_flags;
  2132. num_del++;
  2133. /* flush a full buffer */
  2134. if (num_del == filter_list_len) {
  2135. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2136. num_del, &retval);
  2137. memset(del_list, 0, list_size);
  2138. num_del = 0;
  2139. }
  2140. /* Release memory for MAC filter entries which were
  2141. * synced up with HW.
  2142. */
  2143. hlist_del(&f->hlist);
  2144. kfree(f);
  2145. }
  2146. if (num_del) {
  2147. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2148. num_del, &retval);
  2149. }
  2150. kfree(del_list);
  2151. del_list = NULL;
  2152. }
  2153. if (!hlist_empty(&tmp_add_list)) {
  2154. /* Do all the adds now. */
  2155. filter_list_len = hw->aq.asq_buf_size /
  2156. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2157. list_size = filter_list_len *
  2158. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2159. add_list = kzalloc(list_size, GFP_ATOMIC);
  2160. if (!add_list)
  2161. goto err_no_memory;
  2162. num_add = 0;
  2163. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2164. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2165. vsi->state)) {
  2166. new->state = I40E_FILTER_FAILED;
  2167. continue;
  2168. }
  2169. /* handle broadcast filters by updating the broadcast
  2170. * promiscuous flag instead of adding a MAC filter.
  2171. */
  2172. if (is_broadcast_ether_addr(new->f->macaddr)) {
  2173. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  2174. new->f))
  2175. new->state = I40E_FILTER_FAILED;
  2176. else
  2177. new->state = I40E_FILTER_ACTIVE;
  2178. continue;
  2179. }
  2180. /* add to add array */
  2181. if (num_add == 0)
  2182. add_head = new;
  2183. cmd_flags = 0;
  2184. ether_addr_copy(add_list[num_add].mac_addr,
  2185. new->f->macaddr);
  2186. if (new->f->vlan == I40E_VLAN_ANY) {
  2187. add_list[num_add].vlan_tag = 0;
  2188. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2189. } else {
  2190. add_list[num_add].vlan_tag =
  2191. cpu_to_le16((u16)(new->f->vlan));
  2192. }
  2193. add_list[num_add].queue_number = 0;
  2194. /* set invalid match method for later detection */
  2195. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2196. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2197. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2198. num_add++;
  2199. /* flush a full buffer */
  2200. if (num_add == filter_list_len) {
  2201. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2202. add_head, num_add,
  2203. &promisc_changed);
  2204. memset(add_list, 0, list_size);
  2205. num_add = 0;
  2206. }
  2207. }
  2208. if (num_add) {
  2209. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2210. num_add, &promisc_changed);
  2211. }
  2212. /* Now move all of the filters from the temp add list back to
  2213. * the VSI's list.
  2214. */
  2215. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2216. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2217. /* Only update the state if we're still NEW */
  2218. if (new->f->state == I40E_FILTER_NEW)
  2219. new->f->state = new->state;
  2220. hlist_del(&new->hlist);
  2221. kfree(new);
  2222. }
  2223. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2224. kfree(add_list);
  2225. add_list = NULL;
  2226. }
  2227. /* Determine the number of active and failed filters. */
  2228. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2229. vsi->active_filters = 0;
  2230. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2231. if (f->state == I40E_FILTER_ACTIVE)
  2232. vsi->active_filters++;
  2233. else if (f->state == I40E_FILTER_FAILED)
  2234. failed_filters++;
  2235. }
  2236. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2237. /* If promiscuous mode has changed, we need to calculate a new
  2238. * threshold for when we are safe to exit
  2239. */
  2240. if (promisc_changed)
  2241. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2242. /* Check if we are able to exit overflow promiscuous mode. We can
  2243. * safely exit if we didn't just enter, we no longer have any failed
  2244. * filters, and we have reduced filters below the threshold value.
  2245. */
  2246. if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) &&
  2247. !promisc_changed && !failed_filters &&
  2248. (vsi->active_filters < vsi->promisc_threshold)) {
  2249. dev_info(&pf->pdev->dev,
  2250. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2251. vsi_name);
  2252. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2253. promisc_changed = true;
  2254. vsi->promisc_threshold = 0;
  2255. }
  2256. /* if the VF is not trusted do not do promisc */
  2257. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2258. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2259. goto out;
  2260. }
  2261. /* check for changes in promiscuous modes */
  2262. if (changed_flags & IFF_ALLMULTI) {
  2263. bool cur_multipromisc;
  2264. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2265. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2266. vsi->seid,
  2267. cur_multipromisc,
  2268. NULL);
  2269. if (aq_ret) {
  2270. retval = i40e_aq_rc_to_posix(aq_ret,
  2271. hw->aq.asq_last_status);
  2272. dev_info(&pf->pdev->dev,
  2273. "set multi promisc failed on %s, err %s aq_err %s\n",
  2274. vsi_name,
  2275. i40e_stat_str(hw, aq_ret),
  2276. i40e_aq_str(hw, hw->aq.asq_last_status));
  2277. }
  2278. }
  2279. if ((changed_flags & IFF_PROMISC) || promisc_changed) {
  2280. bool cur_promisc;
  2281. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2282. test_bit(__I40E_VSI_OVERFLOW_PROMISC,
  2283. vsi->state));
  2284. aq_ret = i40e_set_promiscuous(pf, cur_promisc);
  2285. if (aq_ret) {
  2286. retval = i40e_aq_rc_to_posix(aq_ret,
  2287. hw->aq.asq_last_status);
  2288. dev_info(&pf->pdev->dev,
  2289. "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
  2290. cur_promisc ? "on" : "off",
  2291. vsi_name,
  2292. i40e_stat_str(hw, aq_ret),
  2293. i40e_aq_str(hw, hw->aq.asq_last_status));
  2294. }
  2295. }
  2296. out:
  2297. /* if something went wrong then set the changed flag so we try again */
  2298. if (retval)
  2299. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2300. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2301. return retval;
  2302. err_no_memory:
  2303. /* Restore elements on the temporary add and delete lists */
  2304. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2305. err_no_memory_locked:
  2306. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2307. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2308. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2309. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2310. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2311. return -ENOMEM;
  2312. }
  2313. /**
  2314. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2315. * @pf: board private structure
  2316. **/
  2317. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2318. {
  2319. int v;
  2320. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2321. return;
  2322. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2323. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2324. if (pf->vsi[v] &&
  2325. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2326. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2327. if (ret) {
  2328. /* come back and try again later */
  2329. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2330. break;
  2331. }
  2332. }
  2333. }
  2334. }
  2335. /**
  2336. * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  2337. * @vsi: the vsi
  2338. **/
  2339. static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
  2340. {
  2341. if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2342. return I40E_RXBUFFER_2048;
  2343. else
  2344. return I40E_RXBUFFER_3072;
  2345. }
  2346. /**
  2347. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2348. * @netdev: network interface device structure
  2349. * @new_mtu: new value for maximum frame size
  2350. *
  2351. * Returns 0 on success, negative on failure
  2352. **/
  2353. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2354. {
  2355. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2356. struct i40e_vsi *vsi = np->vsi;
  2357. struct i40e_pf *pf = vsi->back;
  2358. if (i40e_enabled_xdp_vsi(vsi)) {
  2359. int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2360. if (frame_size > i40e_max_xdp_frame_size(vsi))
  2361. return -EINVAL;
  2362. }
  2363. netdev_info(netdev, "changing MTU from %d to %d\n",
  2364. netdev->mtu, new_mtu);
  2365. netdev->mtu = new_mtu;
  2366. if (netif_running(netdev))
  2367. i40e_vsi_reinit_locked(vsi);
  2368. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  2369. I40E_FLAG_CLIENT_L2_CHANGE);
  2370. return 0;
  2371. }
  2372. /**
  2373. * i40e_ioctl - Access the hwtstamp interface
  2374. * @netdev: network interface device structure
  2375. * @ifr: interface request data
  2376. * @cmd: ioctl command
  2377. **/
  2378. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2379. {
  2380. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2381. struct i40e_pf *pf = np->vsi->back;
  2382. switch (cmd) {
  2383. case SIOCGHWTSTAMP:
  2384. return i40e_ptp_get_ts_config(pf, ifr);
  2385. case SIOCSHWTSTAMP:
  2386. return i40e_ptp_set_ts_config(pf, ifr);
  2387. default:
  2388. return -EOPNOTSUPP;
  2389. }
  2390. }
  2391. /**
  2392. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2393. * @vsi: the vsi being adjusted
  2394. **/
  2395. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2396. {
  2397. struct i40e_vsi_context ctxt;
  2398. i40e_status ret;
  2399. if ((vsi->info.valid_sections &
  2400. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2401. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2402. return; /* already enabled */
  2403. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2404. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2405. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2406. ctxt.seid = vsi->seid;
  2407. ctxt.info = vsi->info;
  2408. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2409. if (ret) {
  2410. dev_info(&vsi->back->pdev->dev,
  2411. "update vlan stripping failed, err %s aq_err %s\n",
  2412. i40e_stat_str(&vsi->back->hw, ret),
  2413. i40e_aq_str(&vsi->back->hw,
  2414. vsi->back->hw.aq.asq_last_status));
  2415. }
  2416. }
  2417. /**
  2418. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2419. * @vsi: the vsi being adjusted
  2420. **/
  2421. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2422. {
  2423. struct i40e_vsi_context ctxt;
  2424. i40e_status ret;
  2425. if ((vsi->info.valid_sections &
  2426. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2427. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2428. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2429. return; /* already disabled */
  2430. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2431. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2432. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2433. ctxt.seid = vsi->seid;
  2434. ctxt.info = vsi->info;
  2435. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2436. if (ret) {
  2437. dev_info(&vsi->back->pdev->dev,
  2438. "update vlan stripping failed, err %s aq_err %s\n",
  2439. i40e_stat_str(&vsi->back->hw, ret),
  2440. i40e_aq_str(&vsi->back->hw,
  2441. vsi->back->hw.aq.asq_last_status));
  2442. }
  2443. }
  2444. /**
  2445. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2446. * @netdev: network interface to be adjusted
  2447. * @features: netdev features to test if VLAN offload is enabled or not
  2448. **/
  2449. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2450. {
  2451. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2452. struct i40e_vsi *vsi = np->vsi;
  2453. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2454. i40e_vlan_stripping_enable(vsi);
  2455. else
  2456. i40e_vlan_stripping_disable(vsi);
  2457. }
  2458. /**
  2459. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2460. * @vsi: the vsi being configured
  2461. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2462. *
  2463. * This is a helper function for adding a new MAC/VLAN filter with the
  2464. * specified VLAN for each existing MAC address already in the hash table.
  2465. * This function does *not* perform any accounting to update filters based on
  2466. * VLAN mode.
  2467. *
  2468. * NOTE: this function expects to be called while under the
  2469. * mac_filter_hash_lock
  2470. **/
  2471. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2472. {
  2473. struct i40e_mac_filter *f, *add_f;
  2474. struct hlist_node *h;
  2475. int bkt;
  2476. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2477. if (f->state == I40E_FILTER_REMOVE)
  2478. continue;
  2479. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2480. if (!add_f) {
  2481. dev_info(&vsi->back->pdev->dev,
  2482. "Could not add vlan filter %d for %pM\n",
  2483. vid, f->macaddr);
  2484. return -ENOMEM;
  2485. }
  2486. }
  2487. return 0;
  2488. }
  2489. /**
  2490. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2491. * @vsi: the VSI being configured
  2492. * @vid: VLAN id to be added
  2493. **/
  2494. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2495. {
  2496. int err;
  2497. if (vsi->info.pvid)
  2498. return -EINVAL;
  2499. /* The network stack will attempt to add VID=0, with the intention to
  2500. * receive priority tagged packets with a VLAN of 0. Our HW receives
  2501. * these packets by default when configured to receive untagged
  2502. * packets, so we don't need to add a filter for this case.
  2503. * Additionally, HW interprets adding a VID=0 filter as meaning to
  2504. * receive *only* tagged traffic and stops receiving untagged traffic.
  2505. * Thus, we do not want to actually add a filter for VID=0
  2506. */
  2507. if (!vid)
  2508. return 0;
  2509. /* Locked once because all functions invoked below iterates list*/
  2510. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2511. err = i40e_add_vlan_all_mac(vsi, vid);
  2512. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2513. if (err)
  2514. return err;
  2515. /* schedule our worker thread which will take care of
  2516. * applying the new filter changes
  2517. */
  2518. i40e_service_event_schedule(vsi->back);
  2519. return 0;
  2520. }
  2521. /**
  2522. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2523. * @vsi: the vsi being configured
  2524. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2525. *
  2526. * This function should be used to remove all VLAN filters which match the
  2527. * given VID. It does not schedule the service event and does not take the
  2528. * mac_filter_hash_lock so it may be combined with other operations under
  2529. * a single invocation of the mac_filter_hash_lock.
  2530. *
  2531. * NOTE: this function expects to be called while under the
  2532. * mac_filter_hash_lock
  2533. */
  2534. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2535. {
  2536. struct i40e_mac_filter *f;
  2537. struct hlist_node *h;
  2538. int bkt;
  2539. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2540. if (f->vlan == vid)
  2541. __i40e_del_filter(vsi, f);
  2542. }
  2543. }
  2544. /**
  2545. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2546. * @vsi: the VSI being configured
  2547. * @vid: VLAN id to be removed
  2548. **/
  2549. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2550. {
  2551. if (!vid || vsi->info.pvid)
  2552. return;
  2553. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2554. i40e_rm_vlan_all_mac(vsi, vid);
  2555. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2556. /* schedule our worker thread which will take care of
  2557. * applying the new filter changes
  2558. */
  2559. i40e_service_event_schedule(vsi->back);
  2560. }
  2561. /**
  2562. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2563. * @netdev: network interface to be adjusted
  2564. * @vid: vlan id to be added
  2565. *
  2566. * net_device_ops implementation for adding vlan ids
  2567. **/
  2568. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2569. __always_unused __be16 proto, u16 vid)
  2570. {
  2571. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2572. struct i40e_vsi *vsi = np->vsi;
  2573. int ret = 0;
  2574. if (vid >= VLAN_N_VID)
  2575. return -EINVAL;
  2576. ret = i40e_vsi_add_vlan(vsi, vid);
  2577. if (!ret)
  2578. set_bit(vid, vsi->active_vlans);
  2579. return ret;
  2580. }
  2581. /**
  2582. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2583. * @netdev: network interface to be adjusted
  2584. * @vid: vlan id to be removed
  2585. *
  2586. * net_device_ops implementation for removing vlan ids
  2587. **/
  2588. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2589. __always_unused __be16 proto, u16 vid)
  2590. {
  2591. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2592. struct i40e_vsi *vsi = np->vsi;
  2593. /* return code is ignored as there is nothing a user
  2594. * can do about failure to remove and a log message was
  2595. * already printed from the other function
  2596. */
  2597. i40e_vsi_kill_vlan(vsi, vid);
  2598. clear_bit(vid, vsi->active_vlans);
  2599. return 0;
  2600. }
  2601. /**
  2602. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2603. * @vsi: the vsi being brought back up
  2604. **/
  2605. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2606. {
  2607. u16 vid;
  2608. if (!vsi->netdev)
  2609. return;
  2610. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2611. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2612. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2613. vid);
  2614. }
  2615. /**
  2616. * i40e_vsi_add_pvid - Add pvid for the VSI
  2617. * @vsi: the vsi being adjusted
  2618. * @vid: the vlan id to set as a PVID
  2619. **/
  2620. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2621. {
  2622. struct i40e_vsi_context ctxt;
  2623. i40e_status ret;
  2624. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2625. vsi->info.pvid = cpu_to_le16(vid);
  2626. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2627. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2628. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2629. ctxt.seid = vsi->seid;
  2630. ctxt.info = vsi->info;
  2631. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2632. if (ret) {
  2633. dev_info(&vsi->back->pdev->dev,
  2634. "add pvid failed, err %s aq_err %s\n",
  2635. i40e_stat_str(&vsi->back->hw, ret),
  2636. i40e_aq_str(&vsi->back->hw,
  2637. vsi->back->hw.aq.asq_last_status));
  2638. return -ENOENT;
  2639. }
  2640. return 0;
  2641. }
  2642. /**
  2643. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2644. * @vsi: the vsi being adjusted
  2645. *
  2646. * Just use the vlan_rx_register() service to put it back to normal
  2647. **/
  2648. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2649. {
  2650. i40e_vlan_stripping_disable(vsi);
  2651. vsi->info.pvid = 0;
  2652. }
  2653. /**
  2654. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2655. * @vsi: ptr to the VSI
  2656. *
  2657. * If this function returns with an error, then it's possible one or
  2658. * more of the rings is populated (while the rest are not). It is the
  2659. * callers duty to clean those orphaned rings.
  2660. *
  2661. * Return 0 on success, negative on failure
  2662. **/
  2663. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2664. {
  2665. int i, err = 0;
  2666. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2667. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2668. if (!i40e_enabled_xdp_vsi(vsi))
  2669. return err;
  2670. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2671. err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
  2672. return err;
  2673. }
  2674. /**
  2675. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2676. * @vsi: ptr to the VSI
  2677. *
  2678. * Free VSI's transmit software resources
  2679. **/
  2680. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2681. {
  2682. int i;
  2683. if (vsi->tx_rings) {
  2684. for (i = 0; i < vsi->num_queue_pairs; i++)
  2685. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2686. i40e_free_tx_resources(vsi->tx_rings[i]);
  2687. }
  2688. if (vsi->xdp_rings) {
  2689. for (i = 0; i < vsi->num_queue_pairs; i++)
  2690. if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
  2691. i40e_free_tx_resources(vsi->xdp_rings[i]);
  2692. }
  2693. }
  2694. /**
  2695. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2696. * @vsi: ptr to the VSI
  2697. *
  2698. * If this function returns with an error, then it's possible one or
  2699. * more of the rings is populated (while the rest are not). It is the
  2700. * callers duty to clean those orphaned rings.
  2701. *
  2702. * Return 0 on success, negative on failure
  2703. **/
  2704. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2705. {
  2706. int i, err = 0;
  2707. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2708. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2709. return err;
  2710. }
  2711. /**
  2712. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2713. * @vsi: ptr to the VSI
  2714. *
  2715. * Free all receive software resources
  2716. **/
  2717. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2718. {
  2719. int i;
  2720. if (!vsi->rx_rings)
  2721. return;
  2722. for (i = 0; i < vsi->num_queue_pairs; i++)
  2723. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2724. i40e_free_rx_resources(vsi->rx_rings[i]);
  2725. }
  2726. /**
  2727. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2728. * @ring: The Tx ring to configure
  2729. *
  2730. * This enables/disables XPS for a given Tx descriptor ring
  2731. * based on the TCs enabled for the VSI that ring belongs to.
  2732. **/
  2733. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2734. {
  2735. int cpu;
  2736. if (!ring->q_vector || !ring->netdev || ring->ch)
  2737. return;
  2738. /* We only initialize XPS once, so as not to overwrite user settings */
  2739. if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
  2740. return;
  2741. cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
  2742. netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
  2743. ring->queue_index);
  2744. }
  2745. /**
  2746. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2747. * @ring: The Tx ring to configure
  2748. *
  2749. * Configure the Tx descriptor ring in the HMC context.
  2750. **/
  2751. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2752. {
  2753. struct i40e_vsi *vsi = ring->vsi;
  2754. u16 pf_q = vsi->base_queue + ring->queue_index;
  2755. struct i40e_hw *hw = &vsi->back->hw;
  2756. struct i40e_hmc_obj_txq tx_ctx;
  2757. i40e_status err = 0;
  2758. u32 qtx_ctl = 0;
  2759. /* some ATR related tx ring init */
  2760. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2761. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2762. ring->atr_count = 0;
  2763. } else {
  2764. ring->atr_sample_rate = 0;
  2765. }
  2766. /* configure XPS */
  2767. i40e_config_xps_tx_ring(ring);
  2768. /* clear the context structure first */
  2769. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2770. tx_ctx.new_context = 1;
  2771. tx_ctx.base = (ring->dma / 128);
  2772. tx_ctx.qlen = ring->count;
  2773. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2774. I40E_FLAG_FD_ATR_ENABLED));
  2775. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2776. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2777. if (vsi->type != I40E_VSI_FDIR)
  2778. tx_ctx.head_wb_ena = 1;
  2779. tx_ctx.head_wb_addr = ring->dma +
  2780. (ring->count * sizeof(struct i40e_tx_desc));
  2781. /* As part of VSI creation/update, FW allocates certain
  2782. * Tx arbitration queue sets for each TC enabled for
  2783. * the VSI. The FW returns the handles to these queue
  2784. * sets as part of the response buffer to Add VSI,
  2785. * Update VSI, etc. AQ commands. It is expected that
  2786. * these queue set handles be associated with the Tx
  2787. * queues by the driver as part of the TX queue context
  2788. * initialization. This has to be done regardless of
  2789. * DCB as by default everything is mapped to TC0.
  2790. */
  2791. if (ring->ch)
  2792. tx_ctx.rdylist =
  2793. le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
  2794. else
  2795. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2796. tx_ctx.rdylist_act = 0;
  2797. /* clear the context in the HMC */
  2798. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2799. if (err) {
  2800. dev_info(&vsi->back->pdev->dev,
  2801. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2802. ring->queue_index, pf_q, err);
  2803. return -ENOMEM;
  2804. }
  2805. /* set the context in the HMC */
  2806. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2807. if (err) {
  2808. dev_info(&vsi->back->pdev->dev,
  2809. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2810. ring->queue_index, pf_q, err);
  2811. return -ENOMEM;
  2812. }
  2813. /* Now associate this queue with this PCI function */
  2814. if (ring->ch) {
  2815. if (ring->ch->type == I40E_VSI_VMDQ2)
  2816. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2817. else
  2818. return -EINVAL;
  2819. qtx_ctl |= (ring->ch->vsi_number <<
  2820. I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2821. I40E_QTX_CTL_VFVM_INDX_MASK;
  2822. } else {
  2823. if (vsi->type == I40E_VSI_VMDQ2) {
  2824. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2825. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2826. I40E_QTX_CTL_VFVM_INDX_MASK;
  2827. } else {
  2828. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2829. }
  2830. }
  2831. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2832. I40E_QTX_CTL_PF_INDX_MASK);
  2833. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2834. i40e_flush(hw);
  2835. /* cache tail off for easier writes later */
  2836. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2837. return 0;
  2838. }
  2839. /**
  2840. * i40e_configure_rx_ring - Configure a receive ring context
  2841. * @ring: The Rx ring to configure
  2842. *
  2843. * Configure the Rx descriptor ring in the HMC context.
  2844. **/
  2845. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2846. {
  2847. struct i40e_vsi *vsi = ring->vsi;
  2848. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2849. u16 pf_q = vsi->base_queue + ring->queue_index;
  2850. struct i40e_hw *hw = &vsi->back->hw;
  2851. struct i40e_hmc_obj_rxq rx_ctx;
  2852. i40e_status err = 0;
  2853. bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
  2854. /* clear the context structure first */
  2855. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2856. ring->rx_buf_len = vsi->rx_buf_len;
  2857. rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
  2858. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2859. rx_ctx.base = (ring->dma / 128);
  2860. rx_ctx.qlen = ring->count;
  2861. /* use 32 byte descriptors */
  2862. rx_ctx.dsize = 1;
  2863. /* descriptor type is always zero
  2864. * rx_ctx.dtype = 0;
  2865. */
  2866. rx_ctx.hsplit_0 = 0;
  2867. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2868. if (hw->revision_id == 0)
  2869. rx_ctx.lrxqthresh = 0;
  2870. else
  2871. rx_ctx.lrxqthresh = 1;
  2872. rx_ctx.crcstrip = 1;
  2873. rx_ctx.l2tsel = 1;
  2874. /* this controls whether VLAN is stripped from inner headers */
  2875. rx_ctx.showiv = 0;
  2876. /* set the prefena field to 1 because the manual says to */
  2877. rx_ctx.prefena = 1;
  2878. /* clear the context in the HMC */
  2879. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2880. if (err) {
  2881. dev_info(&vsi->back->pdev->dev,
  2882. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2883. ring->queue_index, pf_q, err);
  2884. return -ENOMEM;
  2885. }
  2886. /* set the context in the HMC */
  2887. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2888. if (err) {
  2889. dev_info(&vsi->back->pdev->dev,
  2890. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2891. ring->queue_index, pf_q, err);
  2892. return -ENOMEM;
  2893. }
  2894. /* configure Rx buffer alignment */
  2895. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2896. clear_ring_build_skb_enabled(ring);
  2897. else
  2898. set_ring_build_skb_enabled(ring);
  2899. /* cache tail for quicker writes, and clear the reg before use */
  2900. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2901. writel(0, ring->tail);
  2902. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2903. return 0;
  2904. }
  2905. /**
  2906. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2907. * @vsi: VSI structure describing this set of rings and resources
  2908. *
  2909. * Configure the Tx VSI for operation.
  2910. **/
  2911. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2912. {
  2913. int err = 0;
  2914. u16 i;
  2915. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2916. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2917. if (!i40e_enabled_xdp_vsi(vsi))
  2918. return err;
  2919. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2920. err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
  2921. return err;
  2922. }
  2923. /**
  2924. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2925. * @vsi: the VSI being configured
  2926. *
  2927. * Configure the Rx VSI for operation.
  2928. **/
  2929. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2930. {
  2931. int err = 0;
  2932. u16 i;
  2933. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
  2934. vsi->max_frame = I40E_MAX_RXBUFFER;
  2935. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2936. #if (PAGE_SIZE < 8192)
  2937. } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
  2938. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  2939. vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2940. vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2941. #endif
  2942. } else {
  2943. vsi->max_frame = I40E_MAX_RXBUFFER;
  2944. vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
  2945. I40E_RXBUFFER_2048;
  2946. }
  2947. /* set up individual rings */
  2948. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2949. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2950. return err;
  2951. }
  2952. /**
  2953. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2954. * @vsi: ptr to the VSI
  2955. **/
  2956. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2957. {
  2958. struct i40e_ring *tx_ring, *rx_ring;
  2959. u16 qoffset, qcount;
  2960. int i, n;
  2961. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2962. /* Reset the TC information */
  2963. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2964. rx_ring = vsi->rx_rings[i];
  2965. tx_ring = vsi->tx_rings[i];
  2966. rx_ring->dcb_tc = 0;
  2967. tx_ring->dcb_tc = 0;
  2968. }
  2969. return;
  2970. }
  2971. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2972. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2973. continue;
  2974. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2975. qcount = vsi->tc_config.tc_info[n].qcount;
  2976. for (i = qoffset; i < (qoffset + qcount); i++) {
  2977. rx_ring = vsi->rx_rings[i];
  2978. tx_ring = vsi->tx_rings[i];
  2979. rx_ring->dcb_tc = n;
  2980. tx_ring->dcb_tc = n;
  2981. }
  2982. }
  2983. }
  2984. /**
  2985. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2986. * @vsi: ptr to the VSI
  2987. **/
  2988. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2989. {
  2990. if (vsi->netdev)
  2991. i40e_set_rx_mode(vsi->netdev);
  2992. }
  2993. /**
  2994. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2995. * @vsi: Pointer to the targeted VSI
  2996. *
  2997. * This function replays the hlist on the hw where all the SB Flow Director
  2998. * filters were saved.
  2999. **/
  3000. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  3001. {
  3002. struct i40e_fdir_filter *filter;
  3003. struct i40e_pf *pf = vsi->back;
  3004. struct hlist_node *node;
  3005. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  3006. return;
  3007. /* Reset FDir counters as we're replaying all existing filters */
  3008. pf->fd_tcp4_filter_cnt = 0;
  3009. pf->fd_udp4_filter_cnt = 0;
  3010. pf->fd_sctp4_filter_cnt = 0;
  3011. pf->fd_ip4_filter_cnt = 0;
  3012. hlist_for_each_entry_safe(filter, node,
  3013. &pf->fdir_filter_list, fdir_node) {
  3014. i40e_add_del_fdir(vsi, filter, true);
  3015. }
  3016. }
  3017. /**
  3018. * i40e_vsi_configure - Set up the VSI for action
  3019. * @vsi: the VSI being configured
  3020. **/
  3021. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  3022. {
  3023. int err;
  3024. i40e_set_vsi_rx_mode(vsi);
  3025. i40e_restore_vlan(vsi);
  3026. i40e_vsi_config_dcb_rings(vsi);
  3027. err = i40e_vsi_configure_tx(vsi);
  3028. if (!err)
  3029. err = i40e_vsi_configure_rx(vsi);
  3030. return err;
  3031. }
  3032. /**
  3033. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  3034. * @vsi: the VSI being configured
  3035. **/
  3036. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  3037. {
  3038. bool has_xdp = i40e_enabled_xdp_vsi(vsi);
  3039. struct i40e_pf *pf = vsi->back;
  3040. struct i40e_hw *hw = &pf->hw;
  3041. u16 vector;
  3042. int i, q;
  3043. u32 qp;
  3044. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  3045. * and PFINT_LNKLSTn registers, e.g.:
  3046. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  3047. */
  3048. qp = vsi->base_queue;
  3049. vector = vsi->base_vector;
  3050. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  3051. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  3052. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3053. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  3054. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3055. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  3056. q_vector->rx.itr);
  3057. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  3058. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3059. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  3060. q_vector->tx.itr);
  3061. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  3062. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  3063. /* Linked list for the queuepairs assigned to this vector */
  3064. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  3065. for (q = 0; q < q_vector->num_ringpairs; q++) {
  3066. u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
  3067. u32 val;
  3068. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3069. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3070. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  3071. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  3072. (I40E_QUEUE_TYPE_TX <<
  3073. I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  3074. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3075. if (has_xdp) {
  3076. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3077. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3078. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3079. (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3080. (I40E_QUEUE_TYPE_TX <<
  3081. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3082. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3083. }
  3084. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3085. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3086. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3087. ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3088. (I40E_QUEUE_TYPE_RX <<
  3089. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3090. /* Terminate the linked list */
  3091. if (q == (q_vector->num_ringpairs - 1))
  3092. val |= (I40E_QUEUE_END_OF_LIST <<
  3093. I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3094. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3095. qp++;
  3096. }
  3097. }
  3098. i40e_flush(hw);
  3099. }
  3100. /**
  3101. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3102. * @hw: ptr to the hardware info
  3103. **/
  3104. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3105. {
  3106. struct i40e_hw *hw = &pf->hw;
  3107. u32 val;
  3108. /* clear things first */
  3109. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3110. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3111. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3112. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3113. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3114. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3115. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3116. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3117. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3118. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3119. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3120. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3121. if (pf->flags & I40E_FLAG_PTP)
  3122. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3123. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3124. /* SW_ITR_IDX = 0, but don't change INTENA */
  3125. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3126. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3127. /* OTHER_ITR_IDX = 0 */
  3128. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3129. }
  3130. /**
  3131. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3132. * @vsi: the VSI being configured
  3133. **/
  3134. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3135. {
  3136. u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
  3137. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3138. struct i40e_pf *pf = vsi->back;
  3139. struct i40e_hw *hw = &pf->hw;
  3140. u32 val;
  3141. /* set the ITR configuration */
  3142. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3143. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  3144. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3145. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  3146. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  3147. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3148. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  3149. i40e_enable_misc_int_causes(pf);
  3150. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3151. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3152. /* Associate the queue pair to the vector and enable the queue int */
  3153. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3154. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3155. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  3156. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3157. wr32(hw, I40E_QINT_RQCTL(0), val);
  3158. if (i40e_enabled_xdp_vsi(vsi)) {
  3159. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3160. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
  3161. (I40E_QUEUE_TYPE_TX
  3162. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3163. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3164. }
  3165. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3166. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3167. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3168. wr32(hw, I40E_QINT_TQCTL(0), val);
  3169. i40e_flush(hw);
  3170. }
  3171. /**
  3172. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3173. * @pf: board private structure
  3174. **/
  3175. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3176. {
  3177. struct i40e_hw *hw = &pf->hw;
  3178. wr32(hw, I40E_PFINT_DYN_CTL0,
  3179. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3180. i40e_flush(hw);
  3181. }
  3182. /**
  3183. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3184. * @pf: board private structure
  3185. **/
  3186. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  3187. {
  3188. struct i40e_hw *hw = &pf->hw;
  3189. u32 val;
  3190. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3191. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  3192. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3193. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3194. i40e_flush(hw);
  3195. }
  3196. /**
  3197. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3198. * @irq: interrupt number
  3199. * @data: pointer to a q_vector
  3200. **/
  3201. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3202. {
  3203. struct i40e_q_vector *q_vector = data;
  3204. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3205. return IRQ_HANDLED;
  3206. napi_schedule_irqoff(&q_vector->napi);
  3207. return IRQ_HANDLED;
  3208. }
  3209. /**
  3210. * i40e_irq_affinity_notify - Callback for affinity changes
  3211. * @notify: context as to what irq was changed
  3212. * @mask: the new affinity mask
  3213. *
  3214. * This is a callback function used by the irq_set_affinity_notifier function
  3215. * so that we may register to receive changes to the irq affinity masks.
  3216. **/
  3217. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3218. const cpumask_t *mask)
  3219. {
  3220. struct i40e_q_vector *q_vector =
  3221. container_of(notify, struct i40e_q_vector, affinity_notify);
  3222. cpumask_copy(&q_vector->affinity_mask, mask);
  3223. }
  3224. /**
  3225. * i40e_irq_affinity_release - Callback for affinity notifier release
  3226. * @ref: internal core kernel usage
  3227. *
  3228. * This is a callback function used by the irq_set_affinity_notifier function
  3229. * to inform the current notification subscriber that they will no longer
  3230. * receive notifications.
  3231. **/
  3232. static void i40e_irq_affinity_release(struct kref *ref) {}
  3233. /**
  3234. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3235. * @vsi: the VSI being configured
  3236. * @basename: name for the vector
  3237. *
  3238. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3239. **/
  3240. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3241. {
  3242. int q_vectors = vsi->num_q_vectors;
  3243. struct i40e_pf *pf = vsi->back;
  3244. int base = vsi->base_vector;
  3245. int rx_int_idx = 0;
  3246. int tx_int_idx = 0;
  3247. int vector, err;
  3248. int irq_num;
  3249. int cpu;
  3250. for (vector = 0; vector < q_vectors; vector++) {
  3251. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3252. irq_num = pf->msix_entries[base + vector].vector;
  3253. if (q_vector->tx.ring && q_vector->rx.ring) {
  3254. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3255. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3256. tx_int_idx++;
  3257. } else if (q_vector->rx.ring) {
  3258. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3259. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3260. } else if (q_vector->tx.ring) {
  3261. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3262. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3263. } else {
  3264. /* skip this unused q_vector */
  3265. continue;
  3266. }
  3267. err = request_irq(irq_num,
  3268. vsi->irq_handler,
  3269. 0,
  3270. q_vector->name,
  3271. q_vector);
  3272. if (err) {
  3273. dev_info(&pf->pdev->dev,
  3274. "MSIX request_irq failed, error: %d\n", err);
  3275. goto free_queue_irqs;
  3276. }
  3277. /* register for affinity change notifications */
  3278. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3279. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3280. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3281. /* Spread affinity hints out across online CPUs.
  3282. *
  3283. * get_cpu_mask returns a static constant mask with
  3284. * a permanent lifetime so it's ok to pass to
  3285. * irq_set_affinity_hint without making a copy.
  3286. */
  3287. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  3288. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  3289. }
  3290. vsi->irqs_ready = true;
  3291. return 0;
  3292. free_queue_irqs:
  3293. while (vector) {
  3294. vector--;
  3295. irq_num = pf->msix_entries[base + vector].vector;
  3296. irq_set_affinity_notifier(irq_num, NULL);
  3297. irq_set_affinity_hint(irq_num, NULL);
  3298. free_irq(irq_num, &vsi->q_vectors[vector]);
  3299. }
  3300. return err;
  3301. }
  3302. /**
  3303. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3304. * @vsi: the VSI being un-configured
  3305. **/
  3306. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3307. {
  3308. struct i40e_pf *pf = vsi->back;
  3309. struct i40e_hw *hw = &pf->hw;
  3310. int base = vsi->base_vector;
  3311. int i;
  3312. /* disable interrupt causation from each queue */
  3313. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3314. u32 val;
  3315. val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
  3316. val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  3317. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
  3318. val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
  3319. val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  3320. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
  3321. if (!i40e_enabled_xdp_vsi(vsi))
  3322. continue;
  3323. wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
  3324. }
  3325. /* disable each interrupt */
  3326. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3327. for (i = vsi->base_vector;
  3328. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3329. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3330. i40e_flush(hw);
  3331. for (i = 0; i < vsi->num_q_vectors; i++)
  3332. synchronize_irq(pf->msix_entries[i + base].vector);
  3333. } else {
  3334. /* Legacy and MSI mode - this stops all interrupt handling */
  3335. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3336. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3337. i40e_flush(hw);
  3338. synchronize_irq(pf->pdev->irq);
  3339. }
  3340. }
  3341. /**
  3342. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3343. * @vsi: the VSI being configured
  3344. **/
  3345. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3346. {
  3347. struct i40e_pf *pf = vsi->back;
  3348. int i;
  3349. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3350. for (i = 0; i < vsi->num_q_vectors; i++)
  3351. i40e_irq_dynamic_enable(vsi, i);
  3352. } else {
  3353. i40e_irq_dynamic_enable_icr0(pf);
  3354. }
  3355. i40e_flush(&pf->hw);
  3356. return 0;
  3357. }
  3358. /**
  3359. * i40e_free_misc_vector - Free the vector that handles non-queue events
  3360. * @pf: board private structure
  3361. **/
  3362. static void i40e_free_misc_vector(struct i40e_pf *pf)
  3363. {
  3364. /* Disable ICR 0 */
  3365. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3366. i40e_flush(&pf->hw);
  3367. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3368. synchronize_irq(pf->msix_entries[0].vector);
  3369. free_irq(pf->msix_entries[0].vector, pf);
  3370. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  3371. }
  3372. }
  3373. /**
  3374. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3375. * @irq: interrupt number
  3376. * @data: pointer to a q_vector
  3377. *
  3378. * This is the handler used for all MSI/Legacy interrupts, and deals
  3379. * with both queue and non-queue interrupts. This is also used in
  3380. * MSIX mode to handle the non-queue interrupts.
  3381. **/
  3382. static irqreturn_t i40e_intr(int irq, void *data)
  3383. {
  3384. struct i40e_pf *pf = (struct i40e_pf *)data;
  3385. struct i40e_hw *hw = &pf->hw;
  3386. irqreturn_t ret = IRQ_NONE;
  3387. u32 icr0, icr0_remaining;
  3388. u32 val, ena_mask;
  3389. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3390. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3391. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3392. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3393. goto enable_intr;
  3394. /* if interrupt but no bits showing, must be SWINT */
  3395. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3396. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3397. pf->sw_int_count++;
  3398. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3399. (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3400. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3401. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3402. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  3403. }
  3404. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3405. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3406. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3407. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3408. /* We do not have a way to disarm Queue causes while leaving
  3409. * interrupt enabled for all other causes, ideally
  3410. * interrupt should be disabled while we are in NAPI but
  3411. * this is not a performance path and napi_schedule()
  3412. * can deal with rescheduling.
  3413. */
  3414. if (!test_bit(__I40E_DOWN, pf->state))
  3415. napi_schedule_irqoff(&q_vector->napi);
  3416. }
  3417. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3418. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3419. set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  3420. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3421. }
  3422. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3423. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3424. set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  3425. }
  3426. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3427. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3428. set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3429. }
  3430. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3431. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  3432. set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  3433. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3434. val = rd32(hw, I40E_GLGEN_RSTAT);
  3435. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3436. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3437. if (val == I40E_RESET_CORER) {
  3438. pf->corer_count++;
  3439. } else if (val == I40E_RESET_GLOBR) {
  3440. pf->globr_count++;
  3441. } else if (val == I40E_RESET_EMPR) {
  3442. pf->empr_count++;
  3443. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
  3444. }
  3445. }
  3446. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3447. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3448. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3449. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3450. rd32(hw, I40E_PFHMC_ERRORINFO),
  3451. rd32(hw, I40E_PFHMC_ERRORDATA));
  3452. }
  3453. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3454. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3455. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3456. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3457. i40e_ptp_tx_hwtstamp(pf);
  3458. }
  3459. }
  3460. /* If a critical error is pending we have no choice but to reset the
  3461. * device.
  3462. * Report and mask out any remaining unexpected interrupts.
  3463. */
  3464. icr0_remaining = icr0 & ena_mask;
  3465. if (icr0_remaining) {
  3466. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3467. icr0_remaining);
  3468. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3469. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3470. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3471. dev_info(&pf->pdev->dev, "device will be reset\n");
  3472. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  3473. i40e_service_event_schedule(pf);
  3474. }
  3475. ena_mask &= ~icr0_remaining;
  3476. }
  3477. ret = IRQ_HANDLED;
  3478. enable_intr:
  3479. /* re-enable interrupt causes */
  3480. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3481. if (!test_bit(__I40E_DOWN, pf->state)) {
  3482. i40e_service_event_schedule(pf);
  3483. i40e_irq_dynamic_enable_icr0(pf);
  3484. }
  3485. return ret;
  3486. }
  3487. /**
  3488. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3489. * @tx_ring: tx ring to clean
  3490. * @budget: how many cleans we're allowed
  3491. *
  3492. * Returns true if there's any budget left (e.g. the clean is finished)
  3493. **/
  3494. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3495. {
  3496. struct i40e_vsi *vsi = tx_ring->vsi;
  3497. u16 i = tx_ring->next_to_clean;
  3498. struct i40e_tx_buffer *tx_buf;
  3499. struct i40e_tx_desc *tx_desc;
  3500. tx_buf = &tx_ring->tx_bi[i];
  3501. tx_desc = I40E_TX_DESC(tx_ring, i);
  3502. i -= tx_ring->count;
  3503. do {
  3504. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3505. /* if next_to_watch is not set then there is no work pending */
  3506. if (!eop_desc)
  3507. break;
  3508. /* prevent any other reads prior to eop_desc */
  3509. smp_rmb();
  3510. /* if the descriptor isn't done, no work yet to do */
  3511. if (!(eop_desc->cmd_type_offset_bsz &
  3512. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3513. break;
  3514. /* clear next_to_watch to prevent false hangs */
  3515. tx_buf->next_to_watch = NULL;
  3516. tx_desc->buffer_addr = 0;
  3517. tx_desc->cmd_type_offset_bsz = 0;
  3518. /* move past filter desc */
  3519. tx_buf++;
  3520. tx_desc++;
  3521. i++;
  3522. if (unlikely(!i)) {
  3523. i -= tx_ring->count;
  3524. tx_buf = tx_ring->tx_bi;
  3525. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3526. }
  3527. /* unmap skb header data */
  3528. dma_unmap_single(tx_ring->dev,
  3529. dma_unmap_addr(tx_buf, dma),
  3530. dma_unmap_len(tx_buf, len),
  3531. DMA_TO_DEVICE);
  3532. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3533. kfree(tx_buf->raw_buf);
  3534. tx_buf->raw_buf = NULL;
  3535. tx_buf->tx_flags = 0;
  3536. tx_buf->next_to_watch = NULL;
  3537. dma_unmap_len_set(tx_buf, len, 0);
  3538. tx_desc->buffer_addr = 0;
  3539. tx_desc->cmd_type_offset_bsz = 0;
  3540. /* move us past the eop_desc for start of next FD desc */
  3541. tx_buf++;
  3542. tx_desc++;
  3543. i++;
  3544. if (unlikely(!i)) {
  3545. i -= tx_ring->count;
  3546. tx_buf = tx_ring->tx_bi;
  3547. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3548. }
  3549. /* update budget accounting */
  3550. budget--;
  3551. } while (likely(budget));
  3552. i += tx_ring->count;
  3553. tx_ring->next_to_clean = i;
  3554. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3555. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3556. return budget > 0;
  3557. }
  3558. /**
  3559. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3560. * @irq: interrupt number
  3561. * @data: pointer to a q_vector
  3562. **/
  3563. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3564. {
  3565. struct i40e_q_vector *q_vector = data;
  3566. struct i40e_vsi *vsi;
  3567. if (!q_vector->tx.ring)
  3568. return IRQ_HANDLED;
  3569. vsi = q_vector->tx.ring->vsi;
  3570. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3571. return IRQ_HANDLED;
  3572. }
  3573. /**
  3574. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3575. * @vsi: the VSI being configured
  3576. * @v_idx: vector index
  3577. * @qp_idx: queue pair index
  3578. **/
  3579. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3580. {
  3581. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3582. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3583. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3584. tx_ring->q_vector = q_vector;
  3585. tx_ring->next = q_vector->tx.ring;
  3586. q_vector->tx.ring = tx_ring;
  3587. q_vector->tx.count++;
  3588. /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
  3589. if (i40e_enabled_xdp_vsi(vsi)) {
  3590. struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
  3591. xdp_ring->q_vector = q_vector;
  3592. xdp_ring->next = q_vector->tx.ring;
  3593. q_vector->tx.ring = xdp_ring;
  3594. q_vector->tx.count++;
  3595. }
  3596. rx_ring->q_vector = q_vector;
  3597. rx_ring->next = q_vector->rx.ring;
  3598. q_vector->rx.ring = rx_ring;
  3599. q_vector->rx.count++;
  3600. }
  3601. /**
  3602. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3603. * @vsi: the VSI being configured
  3604. *
  3605. * This function maps descriptor rings to the queue-specific vectors
  3606. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3607. * one vector per queue pair, but on a constrained vector budget, we
  3608. * group the queue pairs as "efficiently" as possible.
  3609. **/
  3610. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3611. {
  3612. int qp_remaining = vsi->num_queue_pairs;
  3613. int q_vectors = vsi->num_q_vectors;
  3614. int num_ringpairs;
  3615. int v_start = 0;
  3616. int qp_idx = 0;
  3617. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3618. * group them so there are multiple queues per vector.
  3619. * It is also important to go through all the vectors available to be
  3620. * sure that if we don't use all the vectors, that the remaining vectors
  3621. * are cleared. This is especially important when decreasing the
  3622. * number of queues in use.
  3623. */
  3624. for (; v_start < q_vectors; v_start++) {
  3625. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3626. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3627. q_vector->num_ringpairs = num_ringpairs;
  3628. q_vector->reg_idx = q_vector->v_idx + vsi->base_vector - 1;
  3629. q_vector->rx.count = 0;
  3630. q_vector->tx.count = 0;
  3631. q_vector->rx.ring = NULL;
  3632. q_vector->tx.ring = NULL;
  3633. while (num_ringpairs--) {
  3634. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3635. qp_idx++;
  3636. qp_remaining--;
  3637. }
  3638. }
  3639. }
  3640. /**
  3641. * i40e_vsi_request_irq - Request IRQ from the OS
  3642. * @vsi: the VSI being configured
  3643. * @basename: name for the vector
  3644. **/
  3645. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3646. {
  3647. struct i40e_pf *pf = vsi->back;
  3648. int err;
  3649. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3650. err = i40e_vsi_request_irq_msix(vsi, basename);
  3651. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3652. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3653. pf->int_name, pf);
  3654. else
  3655. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3656. pf->int_name, pf);
  3657. if (err)
  3658. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3659. return err;
  3660. }
  3661. #ifdef CONFIG_NET_POLL_CONTROLLER
  3662. /**
  3663. * i40e_netpoll - A Polling 'interrupt' handler
  3664. * @netdev: network interface device structure
  3665. *
  3666. * This is used by netconsole to send skbs without having to re-enable
  3667. * interrupts. It's not called while the normal interrupt routine is executing.
  3668. **/
  3669. static void i40e_netpoll(struct net_device *netdev)
  3670. {
  3671. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3672. struct i40e_vsi *vsi = np->vsi;
  3673. struct i40e_pf *pf = vsi->back;
  3674. int i;
  3675. /* if interface is down do nothing */
  3676. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  3677. return;
  3678. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3679. for (i = 0; i < vsi->num_q_vectors; i++)
  3680. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3681. } else {
  3682. i40e_intr(pf->pdev->irq, netdev);
  3683. }
  3684. }
  3685. #endif
  3686. #define I40E_QTX_ENA_WAIT_COUNT 50
  3687. /**
  3688. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3689. * @pf: the PF being configured
  3690. * @pf_q: the PF queue
  3691. * @enable: enable or disable state of the queue
  3692. *
  3693. * This routine will wait for the given Tx queue of the PF to reach the
  3694. * enabled or disabled state.
  3695. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3696. * multiple retries; else will return 0 in case of success.
  3697. **/
  3698. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3699. {
  3700. int i;
  3701. u32 tx_reg;
  3702. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3703. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3704. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3705. break;
  3706. usleep_range(10, 20);
  3707. }
  3708. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3709. return -ETIMEDOUT;
  3710. return 0;
  3711. }
  3712. /**
  3713. * i40e_control_tx_q - Start or stop a particular Tx queue
  3714. * @pf: the PF structure
  3715. * @pf_q: the PF queue to configure
  3716. * @enable: start or stop the queue
  3717. *
  3718. * This function enables or disables a single queue. Note that any delay
  3719. * required after the operation is expected to be handled by the caller of
  3720. * this function.
  3721. **/
  3722. static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3723. {
  3724. struct i40e_hw *hw = &pf->hw;
  3725. u32 tx_reg;
  3726. int i;
  3727. /* warn the TX unit of coming changes */
  3728. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3729. if (!enable)
  3730. usleep_range(10, 20);
  3731. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3732. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3733. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3734. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3735. break;
  3736. usleep_range(1000, 2000);
  3737. }
  3738. /* Skip if the queue is already in the requested state */
  3739. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3740. return;
  3741. /* turn on/off the queue */
  3742. if (enable) {
  3743. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3744. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3745. } else {
  3746. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3747. }
  3748. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3749. }
  3750. /**
  3751. * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
  3752. * @seid: VSI SEID
  3753. * @pf: the PF structure
  3754. * @pf_q: the PF queue to configure
  3755. * @is_xdp: true if the queue is used for XDP
  3756. * @enable: start or stop the queue
  3757. **/
  3758. static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
  3759. bool is_xdp, bool enable)
  3760. {
  3761. int ret;
  3762. i40e_control_tx_q(pf, pf_q, enable);
  3763. /* wait for the change to finish */
  3764. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3765. if (ret) {
  3766. dev_info(&pf->pdev->dev,
  3767. "VSI seid %d %sTx ring %d %sable timeout\n",
  3768. seid, (is_xdp ? "XDP " : ""), pf_q,
  3769. (enable ? "en" : "dis"));
  3770. }
  3771. return ret;
  3772. }
  3773. /**
  3774. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3775. * @vsi: the VSI being configured
  3776. * @enable: start or stop the rings
  3777. **/
  3778. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3779. {
  3780. struct i40e_pf *pf = vsi->back;
  3781. int i, pf_q, ret = 0;
  3782. pf_q = vsi->base_queue;
  3783. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3784. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3785. pf_q,
  3786. false /*is xdp*/, enable);
  3787. if (ret)
  3788. break;
  3789. if (!i40e_enabled_xdp_vsi(vsi))
  3790. continue;
  3791. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3792. pf_q + vsi->alloc_queue_pairs,
  3793. true /*is xdp*/, enable);
  3794. if (ret)
  3795. break;
  3796. }
  3797. return ret;
  3798. }
  3799. /**
  3800. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3801. * @pf: the PF being configured
  3802. * @pf_q: the PF queue
  3803. * @enable: enable or disable state of the queue
  3804. *
  3805. * This routine will wait for the given Rx queue of the PF to reach the
  3806. * enabled or disabled state.
  3807. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3808. * multiple retries; else will return 0 in case of success.
  3809. **/
  3810. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3811. {
  3812. int i;
  3813. u32 rx_reg;
  3814. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3815. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3816. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3817. break;
  3818. usleep_range(10, 20);
  3819. }
  3820. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3821. return -ETIMEDOUT;
  3822. return 0;
  3823. }
  3824. /**
  3825. * i40e_control_rx_q - Start or stop a particular Rx queue
  3826. * @pf: the PF structure
  3827. * @pf_q: the PF queue to configure
  3828. * @enable: start or stop the queue
  3829. *
  3830. * This function enables or disables a single queue. Note that any delay
  3831. * required after the operation is expected to be handled by the caller of
  3832. * this function.
  3833. **/
  3834. static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3835. {
  3836. struct i40e_hw *hw = &pf->hw;
  3837. u32 rx_reg;
  3838. int i;
  3839. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3840. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3841. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3842. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3843. break;
  3844. usleep_range(1000, 2000);
  3845. }
  3846. /* Skip if the queue is already in the requested state */
  3847. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3848. return;
  3849. /* turn on/off the queue */
  3850. if (enable)
  3851. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3852. else
  3853. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3854. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3855. }
  3856. /**
  3857. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3858. * @vsi: the VSI being configured
  3859. * @enable: start or stop the rings
  3860. **/
  3861. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3862. {
  3863. struct i40e_pf *pf = vsi->back;
  3864. int i, pf_q, ret = 0;
  3865. pf_q = vsi->base_queue;
  3866. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3867. i40e_control_rx_q(pf, pf_q, enable);
  3868. /* wait for the change to finish */
  3869. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3870. if (ret) {
  3871. dev_info(&pf->pdev->dev,
  3872. "VSI seid %d Rx ring %d %sable timeout\n",
  3873. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3874. break;
  3875. }
  3876. }
  3877. /* Due to HW errata, on Rx disable only, the register can indicate done
  3878. * before it really is. Needs 50ms to be sure
  3879. */
  3880. if (!enable)
  3881. mdelay(50);
  3882. return ret;
  3883. }
  3884. /**
  3885. * i40e_vsi_start_rings - Start a VSI's rings
  3886. * @vsi: the VSI being configured
  3887. **/
  3888. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3889. {
  3890. int ret = 0;
  3891. /* do rx first for enable and last for disable */
  3892. ret = i40e_vsi_control_rx(vsi, true);
  3893. if (ret)
  3894. return ret;
  3895. ret = i40e_vsi_control_tx(vsi, true);
  3896. return ret;
  3897. }
  3898. /**
  3899. * i40e_vsi_stop_rings - Stop a VSI's rings
  3900. * @vsi: the VSI being configured
  3901. **/
  3902. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3903. {
  3904. /* When port TX is suspended, don't wait */
  3905. if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
  3906. return i40e_vsi_stop_rings_no_wait(vsi);
  3907. /* do rx first for enable and last for disable
  3908. * Ignore return value, we need to shutdown whatever we can
  3909. */
  3910. i40e_vsi_control_tx(vsi, false);
  3911. i40e_vsi_control_rx(vsi, false);
  3912. }
  3913. /**
  3914. * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
  3915. * @vsi: the VSI being shutdown
  3916. *
  3917. * This function stops all the rings for a VSI but does not delay to verify
  3918. * that rings have been disabled. It is expected that the caller is shutting
  3919. * down multiple VSIs at once and will delay together for all the VSIs after
  3920. * initiating the shutdown. This is particularly useful for shutting down lots
  3921. * of VFs together. Otherwise, a large delay can be incurred while configuring
  3922. * each VSI in serial.
  3923. **/
  3924. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
  3925. {
  3926. struct i40e_pf *pf = vsi->back;
  3927. int i, pf_q;
  3928. pf_q = vsi->base_queue;
  3929. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3930. i40e_control_tx_q(pf, pf_q, false);
  3931. i40e_control_rx_q(pf, pf_q, false);
  3932. }
  3933. }
  3934. /**
  3935. * i40e_vsi_free_irq - Free the irq association with the OS
  3936. * @vsi: the VSI being configured
  3937. **/
  3938. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3939. {
  3940. struct i40e_pf *pf = vsi->back;
  3941. struct i40e_hw *hw = &pf->hw;
  3942. int base = vsi->base_vector;
  3943. u32 val, qp;
  3944. int i;
  3945. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3946. if (!vsi->q_vectors)
  3947. return;
  3948. if (!vsi->irqs_ready)
  3949. return;
  3950. vsi->irqs_ready = false;
  3951. for (i = 0; i < vsi->num_q_vectors; i++) {
  3952. int irq_num;
  3953. u16 vector;
  3954. vector = i + base;
  3955. irq_num = pf->msix_entries[vector].vector;
  3956. /* free only the irqs that were actually requested */
  3957. if (!vsi->q_vectors[i] ||
  3958. !vsi->q_vectors[i]->num_ringpairs)
  3959. continue;
  3960. /* clear the affinity notifier in the IRQ descriptor */
  3961. irq_set_affinity_notifier(irq_num, NULL);
  3962. /* remove our suggested affinity mask for this IRQ */
  3963. irq_set_affinity_hint(irq_num, NULL);
  3964. synchronize_irq(irq_num);
  3965. free_irq(irq_num, vsi->q_vectors[i]);
  3966. /* Tear down the interrupt queue link list
  3967. *
  3968. * We know that they come in pairs and always
  3969. * the Rx first, then the Tx. To clear the
  3970. * link list, stick the EOL value into the
  3971. * next_q field of the registers.
  3972. */
  3973. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3974. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3975. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3976. val |= I40E_QUEUE_END_OF_LIST
  3977. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3978. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3979. while (qp != I40E_QUEUE_END_OF_LIST) {
  3980. u32 next;
  3981. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3982. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3983. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3984. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3985. I40E_QINT_RQCTL_INTEVENT_MASK);
  3986. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3987. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3988. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3989. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3990. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3991. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3992. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3993. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3994. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3995. I40E_QINT_TQCTL_INTEVENT_MASK);
  3996. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3997. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3998. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3999. qp = next;
  4000. }
  4001. }
  4002. } else {
  4003. free_irq(pf->pdev->irq, pf);
  4004. val = rd32(hw, I40E_PFINT_LNKLST0);
  4005. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  4006. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  4007. val |= I40E_QUEUE_END_OF_LIST
  4008. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  4009. wr32(hw, I40E_PFINT_LNKLST0, val);
  4010. val = rd32(hw, I40E_QINT_RQCTL(qp));
  4011. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  4012. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  4013. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  4014. I40E_QINT_RQCTL_INTEVENT_MASK);
  4015. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  4016. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  4017. wr32(hw, I40E_QINT_RQCTL(qp), val);
  4018. val = rd32(hw, I40E_QINT_TQCTL(qp));
  4019. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  4020. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  4021. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  4022. I40E_QINT_TQCTL_INTEVENT_MASK);
  4023. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  4024. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  4025. wr32(hw, I40E_QINT_TQCTL(qp), val);
  4026. }
  4027. }
  4028. /**
  4029. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  4030. * @vsi: the VSI being configured
  4031. * @v_idx: Index of vector to be freed
  4032. *
  4033. * This function frees the memory allocated to the q_vector. In addition if
  4034. * NAPI is enabled it will delete any references to the NAPI struct prior
  4035. * to freeing the q_vector.
  4036. **/
  4037. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  4038. {
  4039. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  4040. struct i40e_ring *ring;
  4041. if (!q_vector)
  4042. return;
  4043. /* disassociate q_vector from rings */
  4044. i40e_for_each_ring(ring, q_vector->tx)
  4045. ring->q_vector = NULL;
  4046. i40e_for_each_ring(ring, q_vector->rx)
  4047. ring->q_vector = NULL;
  4048. /* only VSI w/ an associated netdev is set up w/ NAPI */
  4049. if (vsi->netdev)
  4050. netif_napi_del(&q_vector->napi);
  4051. vsi->q_vectors[v_idx] = NULL;
  4052. kfree_rcu(q_vector, rcu);
  4053. }
  4054. /**
  4055. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  4056. * @vsi: the VSI being un-configured
  4057. *
  4058. * This frees the memory allocated to the q_vectors and
  4059. * deletes references to the NAPI struct.
  4060. **/
  4061. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  4062. {
  4063. int v_idx;
  4064. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  4065. i40e_free_q_vector(vsi, v_idx);
  4066. }
  4067. /**
  4068. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  4069. * @pf: board private structure
  4070. **/
  4071. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  4072. {
  4073. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  4074. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4075. pci_disable_msix(pf->pdev);
  4076. kfree(pf->msix_entries);
  4077. pf->msix_entries = NULL;
  4078. kfree(pf->irq_pile);
  4079. pf->irq_pile = NULL;
  4080. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  4081. pci_disable_msi(pf->pdev);
  4082. }
  4083. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  4084. }
  4085. /**
  4086. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4087. * @pf: board private structure
  4088. *
  4089. * We go through and clear interrupt specific resources and reset the structure
  4090. * to pre-load conditions
  4091. **/
  4092. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  4093. {
  4094. int i;
  4095. i40e_free_misc_vector(pf);
  4096. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  4097. I40E_IWARP_IRQ_PILE_ID);
  4098. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  4099. for (i = 0; i < pf->num_alloc_vsi; i++)
  4100. if (pf->vsi[i])
  4101. i40e_vsi_free_q_vectors(pf->vsi[i]);
  4102. i40e_reset_interrupt_capability(pf);
  4103. }
  4104. /**
  4105. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  4106. * @vsi: the VSI being configured
  4107. **/
  4108. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  4109. {
  4110. int q_idx;
  4111. if (!vsi->netdev)
  4112. return;
  4113. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4114. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4115. if (q_vector->rx.ring || q_vector->tx.ring)
  4116. napi_enable(&q_vector->napi);
  4117. }
  4118. }
  4119. /**
  4120. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  4121. * @vsi: the VSI being configured
  4122. **/
  4123. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  4124. {
  4125. int q_idx;
  4126. if (!vsi->netdev)
  4127. return;
  4128. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4129. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4130. if (q_vector->rx.ring || q_vector->tx.ring)
  4131. napi_disable(&q_vector->napi);
  4132. }
  4133. }
  4134. /**
  4135. * i40e_vsi_close - Shut down a VSI
  4136. * @vsi: the vsi to be quelled
  4137. **/
  4138. static void i40e_vsi_close(struct i40e_vsi *vsi)
  4139. {
  4140. struct i40e_pf *pf = vsi->back;
  4141. if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
  4142. i40e_down(vsi);
  4143. i40e_vsi_free_irq(vsi);
  4144. i40e_vsi_free_tx_resources(vsi);
  4145. i40e_vsi_free_rx_resources(vsi);
  4146. vsi->current_netdev_flags = 0;
  4147. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4148. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  4149. pf->flags |= I40E_FLAG_CLIENT_RESET;
  4150. }
  4151. /**
  4152. * i40e_quiesce_vsi - Pause a given VSI
  4153. * @vsi: the VSI being paused
  4154. **/
  4155. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  4156. {
  4157. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  4158. return;
  4159. set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
  4160. if (vsi->netdev && netif_running(vsi->netdev))
  4161. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  4162. else
  4163. i40e_vsi_close(vsi);
  4164. }
  4165. /**
  4166. * i40e_unquiesce_vsi - Resume a given VSI
  4167. * @vsi: the VSI being resumed
  4168. **/
  4169. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  4170. {
  4171. if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
  4172. return;
  4173. if (vsi->netdev && netif_running(vsi->netdev))
  4174. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  4175. else
  4176. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  4177. }
  4178. /**
  4179. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  4180. * @pf: the PF
  4181. **/
  4182. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  4183. {
  4184. int v;
  4185. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4186. if (pf->vsi[v])
  4187. i40e_quiesce_vsi(pf->vsi[v]);
  4188. }
  4189. }
  4190. /**
  4191. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  4192. * @pf: the PF
  4193. **/
  4194. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  4195. {
  4196. int v;
  4197. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4198. if (pf->vsi[v])
  4199. i40e_unquiesce_vsi(pf->vsi[v]);
  4200. }
  4201. }
  4202. /**
  4203. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  4204. * @vsi: the VSI being configured
  4205. *
  4206. * Wait until all queues on a given VSI have been disabled.
  4207. **/
  4208. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4209. {
  4210. struct i40e_pf *pf = vsi->back;
  4211. int i, pf_q, ret;
  4212. pf_q = vsi->base_queue;
  4213. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4214. /* Check and wait for the Tx queue */
  4215. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4216. if (ret) {
  4217. dev_info(&pf->pdev->dev,
  4218. "VSI seid %d Tx ring %d disable timeout\n",
  4219. vsi->seid, pf_q);
  4220. return ret;
  4221. }
  4222. if (!i40e_enabled_xdp_vsi(vsi))
  4223. goto wait_rx;
  4224. /* Check and wait for the XDP Tx queue */
  4225. ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
  4226. false);
  4227. if (ret) {
  4228. dev_info(&pf->pdev->dev,
  4229. "VSI seid %d XDP Tx ring %d disable timeout\n",
  4230. vsi->seid, pf_q);
  4231. return ret;
  4232. }
  4233. wait_rx:
  4234. /* Check and wait for the Rx queue */
  4235. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4236. if (ret) {
  4237. dev_info(&pf->pdev->dev,
  4238. "VSI seid %d Rx ring %d disable timeout\n",
  4239. vsi->seid, pf_q);
  4240. return ret;
  4241. }
  4242. }
  4243. return 0;
  4244. }
  4245. #ifdef CONFIG_I40E_DCB
  4246. /**
  4247. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4248. * @pf: the PF
  4249. *
  4250. * This function waits for the queues to be in disabled state for all the
  4251. * VSIs that are managed by this PF.
  4252. **/
  4253. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4254. {
  4255. int v, ret = 0;
  4256. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4257. if (pf->vsi[v]) {
  4258. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4259. if (ret)
  4260. break;
  4261. }
  4262. }
  4263. return ret;
  4264. }
  4265. #endif
  4266. /**
  4267. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4268. * @pf: pointer to PF
  4269. *
  4270. * Get TC map for ISCSI PF type that will include iSCSI TC
  4271. * and LAN TC.
  4272. **/
  4273. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4274. {
  4275. struct i40e_dcb_app_priority_table app;
  4276. struct i40e_hw *hw = &pf->hw;
  4277. u8 enabled_tc = 1; /* TC0 is always enabled */
  4278. u8 tc, i;
  4279. /* Get the iSCSI APP TLV */
  4280. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4281. for (i = 0; i < dcbcfg->numapps; i++) {
  4282. app = dcbcfg->app[i];
  4283. if (app.selector == I40E_APP_SEL_TCPIP &&
  4284. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4285. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4286. enabled_tc |= BIT(tc);
  4287. break;
  4288. }
  4289. }
  4290. return enabled_tc;
  4291. }
  4292. /**
  4293. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4294. * @dcbcfg: the corresponding DCBx configuration structure
  4295. *
  4296. * Return the number of TCs from given DCBx configuration
  4297. **/
  4298. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4299. {
  4300. int i, tc_unused = 0;
  4301. u8 num_tc = 0;
  4302. u8 ret = 0;
  4303. /* Scan the ETS Config Priority Table to find
  4304. * traffic class enabled for a given priority
  4305. * and create a bitmask of enabled TCs
  4306. */
  4307. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4308. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4309. /* Now scan the bitmask to check for
  4310. * contiguous TCs starting with TC0
  4311. */
  4312. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4313. if (num_tc & BIT(i)) {
  4314. if (!tc_unused) {
  4315. ret++;
  4316. } else {
  4317. pr_err("Non-contiguous TC - Disabling DCB\n");
  4318. return 1;
  4319. }
  4320. } else {
  4321. tc_unused = 1;
  4322. }
  4323. }
  4324. /* There is always at least TC0 */
  4325. if (!ret)
  4326. ret = 1;
  4327. return ret;
  4328. }
  4329. /**
  4330. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4331. * @dcbcfg: the corresponding DCBx configuration structure
  4332. *
  4333. * Query the current DCB configuration and return the number of
  4334. * traffic classes enabled from the given DCBX config
  4335. **/
  4336. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4337. {
  4338. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4339. u8 enabled_tc = 1;
  4340. u8 i;
  4341. for (i = 0; i < num_tc; i++)
  4342. enabled_tc |= BIT(i);
  4343. return enabled_tc;
  4344. }
  4345. /**
  4346. * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
  4347. * @pf: PF being queried
  4348. *
  4349. * Query the current MQPRIO configuration and return the number of
  4350. * traffic classes enabled.
  4351. **/
  4352. static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
  4353. {
  4354. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  4355. u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
  4356. u8 enabled_tc = 1, i;
  4357. for (i = 1; i < num_tc; i++)
  4358. enabled_tc |= BIT(i);
  4359. return enabled_tc;
  4360. }
  4361. /**
  4362. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4363. * @pf: PF being queried
  4364. *
  4365. * Return number of traffic classes enabled for the given PF
  4366. **/
  4367. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4368. {
  4369. struct i40e_hw *hw = &pf->hw;
  4370. u8 i, enabled_tc = 1;
  4371. u8 num_tc = 0;
  4372. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4373. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4374. return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
  4375. /* If neither MQPRIO nor DCB is enabled, then always use single TC */
  4376. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4377. return 1;
  4378. /* SFP mode will be enabled for all TCs on port */
  4379. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4380. return i40e_dcb_get_num_tc(dcbcfg);
  4381. /* MFP mode return count of enabled TCs for this PF */
  4382. if (pf->hw.func_caps.iscsi)
  4383. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4384. else
  4385. return 1; /* Only TC0 */
  4386. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4387. if (enabled_tc & BIT(i))
  4388. num_tc++;
  4389. }
  4390. return num_tc;
  4391. }
  4392. /**
  4393. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4394. * @pf: PF being queried
  4395. *
  4396. * Return a bitmap for enabled traffic classes for this PF.
  4397. **/
  4398. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4399. {
  4400. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4401. return i40e_mqprio_get_enabled_tc(pf);
  4402. /* If neither MQPRIO nor DCB is enabled for this PF then just return
  4403. * default TC
  4404. */
  4405. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4406. return I40E_DEFAULT_TRAFFIC_CLASS;
  4407. /* SFP mode we want PF to be enabled for all TCs */
  4408. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4409. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4410. /* MFP enabled and iSCSI PF type */
  4411. if (pf->hw.func_caps.iscsi)
  4412. return i40e_get_iscsi_tc_map(pf);
  4413. else
  4414. return I40E_DEFAULT_TRAFFIC_CLASS;
  4415. }
  4416. /**
  4417. * i40e_vsi_get_bw_info - Query VSI BW Information
  4418. * @vsi: the VSI being queried
  4419. *
  4420. * Returns 0 on success, negative value on failure
  4421. **/
  4422. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4423. {
  4424. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4425. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4426. struct i40e_pf *pf = vsi->back;
  4427. struct i40e_hw *hw = &pf->hw;
  4428. i40e_status ret;
  4429. u32 tc_bw_max;
  4430. int i;
  4431. /* Get the VSI level BW configuration */
  4432. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4433. if (ret) {
  4434. dev_info(&pf->pdev->dev,
  4435. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4436. i40e_stat_str(&pf->hw, ret),
  4437. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4438. return -EINVAL;
  4439. }
  4440. /* Get the VSI level BW configuration per TC */
  4441. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4442. NULL);
  4443. if (ret) {
  4444. dev_info(&pf->pdev->dev,
  4445. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4446. i40e_stat_str(&pf->hw, ret),
  4447. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4448. return -EINVAL;
  4449. }
  4450. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4451. dev_info(&pf->pdev->dev,
  4452. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4453. bw_config.tc_valid_bits,
  4454. bw_ets_config.tc_valid_bits);
  4455. /* Still continuing */
  4456. }
  4457. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4458. vsi->bw_max_quanta = bw_config.max_bw;
  4459. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4460. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4461. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4462. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4463. vsi->bw_ets_limit_credits[i] =
  4464. le16_to_cpu(bw_ets_config.credits[i]);
  4465. /* 3 bits out of 4 for each TC */
  4466. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4467. }
  4468. return 0;
  4469. }
  4470. /**
  4471. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4472. * @vsi: the VSI being configured
  4473. * @enabled_tc: TC bitmap
  4474. * @bw_credits: BW shared credits per TC
  4475. *
  4476. * Returns 0 on success, negative value on failure
  4477. **/
  4478. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4479. u8 *bw_share)
  4480. {
  4481. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4482. i40e_status ret;
  4483. int i;
  4484. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO)
  4485. return 0;
  4486. if (!vsi->mqprio_qopt.qopt.hw) {
  4487. ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
  4488. if (ret)
  4489. dev_info(&vsi->back->pdev->dev,
  4490. "Failed to reset tx rate for vsi->seid %u\n",
  4491. vsi->seid);
  4492. return ret;
  4493. }
  4494. bw_data.tc_valid_bits = enabled_tc;
  4495. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4496. bw_data.tc_bw_credits[i] = bw_share[i];
  4497. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4498. NULL);
  4499. if (ret) {
  4500. dev_info(&vsi->back->pdev->dev,
  4501. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4502. vsi->back->hw.aq.asq_last_status);
  4503. return -EINVAL;
  4504. }
  4505. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4506. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4507. return 0;
  4508. }
  4509. /**
  4510. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4511. * @vsi: the VSI being configured
  4512. * @enabled_tc: TC map to be enabled
  4513. *
  4514. **/
  4515. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4516. {
  4517. struct net_device *netdev = vsi->netdev;
  4518. struct i40e_pf *pf = vsi->back;
  4519. struct i40e_hw *hw = &pf->hw;
  4520. u8 netdev_tc = 0;
  4521. int i;
  4522. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4523. if (!netdev)
  4524. return;
  4525. if (!enabled_tc) {
  4526. netdev_reset_tc(netdev);
  4527. return;
  4528. }
  4529. /* Set up actual enabled TCs on the VSI */
  4530. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4531. return;
  4532. /* set per TC queues for the VSI */
  4533. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4534. /* Only set TC queues for enabled tcs
  4535. *
  4536. * e.g. For a VSI that has TC0 and TC3 enabled the
  4537. * enabled_tc bitmap would be 0x00001001; the driver
  4538. * will set the numtc for netdev as 2 that will be
  4539. * referenced by the netdev layer as TC 0 and 1.
  4540. */
  4541. if (vsi->tc_config.enabled_tc & BIT(i))
  4542. netdev_set_tc_queue(netdev,
  4543. vsi->tc_config.tc_info[i].netdev_tc,
  4544. vsi->tc_config.tc_info[i].qcount,
  4545. vsi->tc_config.tc_info[i].qoffset);
  4546. }
  4547. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4548. return;
  4549. /* Assign UP2TC map for the VSI */
  4550. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4551. /* Get the actual TC# for the UP */
  4552. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4553. /* Get the mapped netdev TC# for the UP */
  4554. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4555. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4556. }
  4557. }
  4558. /**
  4559. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4560. * @vsi: the VSI being configured
  4561. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4562. **/
  4563. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4564. struct i40e_vsi_context *ctxt)
  4565. {
  4566. /* copy just the sections touched not the entire info
  4567. * since not all sections are valid as returned by
  4568. * update vsi params
  4569. */
  4570. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4571. memcpy(&vsi->info.queue_mapping,
  4572. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4573. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4574. sizeof(vsi->info.tc_mapping));
  4575. }
  4576. /**
  4577. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4578. * @vsi: VSI to be configured
  4579. * @enabled_tc: TC bitmap
  4580. *
  4581. * This configures a particular VSI for TCs that are mapped to the
  4582. * given TC bitmap. It uses default bandwidth share for TCs across
  4583. * VSIs to configure TC for a particular VSI.
  4584. *
  4585. * NOTE:
  4586. * It is expected that the VSI queues have been quisced before calling
  4587. * this function.
  4588. **/
  4589. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4590. {
  4591. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4592. struct i40e_pf *pf = vsi->back;
  4593. struct i40e_hw *hw = &pf->hw;
  4594. struct i40e_vsi_context ctxt;
  4595. int ret = 0;
  4596. int i;
  4597. /* Check if enabled_tc is same as existing or new TCs */
  4598. if (vsi->tc_config.enabled_tc == enabled_tc &&
  4599. vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
  4600. return ret;
  4601. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4602. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4603. if (enabled_tc & BIT(i))
  4604. bw_share[i] = 1;
  4605. }
  4606. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4607. if (ret) {
  4608. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4609. dev_info(&pf->pdev->dev,
  4610. "Failed configuring TC map %d for VSI %d\n",
  4611. enabled_tc, vsi->seid);
  4612. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid,
  4613. &bw_config, NULL);
  4614. if (ret) {
  4615. dev_info(&pf->pdev->dev,
  4616. "Failed querying vsi bw info, err %s aq_err %s\n",
  4617. i40e_stat_str(hw, ret),
  4618. i40e_aq_str(hw, hw->aq.asq_last_status));
  4619. goto out;
  4620. }
  4621. if ((bw_config.tc_valid_bits & enabled_tc) != enabled_tc) {
  4622. u8 valid_tc = bw_config.tc_valid_bits & enabled_tc;
  4623. if (!valid_tc)
  4624. valid_tc = bw_config.tc_valid_bits;
  4625. /* Always enable TC0, no matter what */
  4626. valid_tc |= 1;
  4627. dev_info(&pf->pdev->dev,
  4628. "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
  4629. enabled_tc, bw_config.tc_valid_bits, valid_tc);
  4630. enabled_tc = valid_tc;
  4631. }
  4632. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4633. if (ret) {
  4634. dev_err(&pf->pdev->dev,
  4635. "Unable to configure TC map %d for VSI %d\n",
  4636. enabled_tc, vsi->seid);
  4637. goto out;
  4638. }
  4639. }
  4640. /* Update Queue Pairs Mapping for currently enabled UPs */
  4641. ctxt.seid = vsi->seid;
  4642. ctxt.pf_num = vsi->back->hw.pf_id;
  4643. ctxt.vf_num = 0;
  4644. ctxt.uplink_seid = vsi->uplink_seid;
  4645. ctxt.info = vsi->info;
  4646. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
  4647. ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
  4648. if (ret)
  4649. goto out;
  4650. } else {
  4651. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4652. }
  4653. /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
  4654. * queues changed.
  4655. */
  4656. if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
  4657. vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
  4658. vsi->num_queue_pairs);
  4659. ret = i40e_vsi_config_rss(vsi);
  4660. if (ret) {
  4661. dev_info(&vsi->back->pdev->dev,
  4662. "Failed to reconfig rss for num_queues\n");
  4663. return ret;
  4664. }
  4665. vsi->reconfig_rss = false;
  4666. }
  4667. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4668. ctxt.info.valid_sections |=
  4669. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4670. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4671. }
  4672. /* Update the VSI after updating the VSI queue-mapping
  4673. * information
  4674. */
  4675. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  4676. if (ret) {
  4677. dev_info(&pf->pdev->dev,
  4678. "Update vsi tc config failed, err %s aq_err %s\n",
  4679. i40e_stat_str(hw, ret),
  4680. i40e_aq_str(hw, hw->aq.asq_last_status));
  4681. goto out;
  4682. }
  4683. /* update the local VSI info with updated queue map */
  4684. i40e_vsi_update_queue_map(vsi, &ctxt);
  4685. vsi->info.valid_sections = 0;
  4686. /* Update current VSI BW information */
  4687. ret = i40e_vsi_get_bw_info(vsi);
  4688. if (ret) {
  4689. dev_info(&pf->pdev->dev,
  4690. "Failed updating vsi bw info, err %s aq_err %s\n",
  4691. i40e_stat_str(hw, ret),
  4692. i40e_aq_str(hw, hw->aq.asq_last_status));
  4693. goto out;
  4694. }
  4695. /* Update the netdev TC setup */
  4696. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4697. out:
  4698. return ret;
  4699. }
  4700. /**
  4701. * i40e_get_link_speed - Returns link speed for the interface
  4702. * @vsi: VSI to be configured
  4703. *
  4704. **/
  4705. int i40e_get_link_speed(struct i40e_vsi *vsi)
  4706. {
  4707. struct i40e_pf *pf = vsi->back;
  4708. switch (pf->hw.phy.link_info.link_speed) {
  4709. case I40E_LINK_SPEED_40GB:
  4710. return 40000;
  4711. case I40E_LINK_SPEED_25GB:
  4712. return 25000;
  4713. case I40E_LINK_SPEED_20GB:
  4714. return 20000;
  4715. case I40E_LINK_SPEED_10GB:
  4716. return 10000;
  4717. case I40E_LINK_SPEED_1GB:
  4718. return 1000;
  4719. default:
  4720. return -EINVAL;
  4721. }
  4722. }
  4723. /**
  4724. * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
  4725. * @vsi: VSI to be configured
  4726. * @seid: seid of the channel/VSI
  4727. * @max_tx_rate: max TX rate to be configured as BW limit
  4728. *
  4729. * Helper function to set BW limit for a given VSI
  4730. **/
  4731. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
  4732. {
  4733. struct i40e_pf *pf = vsi->back;
  4734. u64 credits = 0;
  4735. int speed = 0;
  4736. int ret = 0;
  4737. speed = i40e_get_link_speed(vsi);
  4738. if (max_tx_rate > speed) {
  4739. dev_err(&pf->pdev->dev,
  4740. "Invalid max tx rate %llu specified for VSI seid %d.",
  4741. max_tx_rate, seid);
  4742. return -EINVAL;
  4743. }
  4744. if (max_tx_rate && max_tx_rate < 50) {
  4745. dev_warn(&pf->pdev->dev,
  4746. "Setting max tx rate to minimum usable value of 50Mbps.\n");
  4747. max_tx_rate = 50;
  4748. }
  4749. /* Tx rate credits are in values of 50Mbps, 0 is disabled */
  4750. credits = max_tx_rate;
  4751. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  4752. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
  4753. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  4754. if (ret)
  4755. dev_err(&pf->pdev->dev,
  4756. "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
  4757. max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
  4758. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4759. return ret;
  4760. }
  4761. /**
  4762. * i40e_remove_queue_channels - Remove queue channels for the TCs
  4763. * @vsi: VSI to be configured
  4764. *
  4765. * Remove queue channels for the TCs
  4766. **/
  4767. static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
  4768. {
  4769. enum i40e_admin_queue_err last_aq_status;
  4770. struct i40e_cloud_filter *cfilter;
  4771. struct i40e_channel *ch, *ch_tmp;
  4772. struct i40e_pf *pf = vsi->back;
  4773. struct hlist_node *node;
  4774. int ret, i;
  4775. /* Reset rss size that was stored when reconfiguring rss for
  4776. * channel VSIs with non-power-of-2 queue count.
  4777. */
  4778. vsi->current_rss_size = 0;
  4779. /* perform cleanup for channels if they exist */
  4780. if (list_empty(&vsi->ch_list))
  4781. return;
  4782. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4783. struct i40e_vsi *p_vsi;
  4784. list_del(&ch->list);
  4785. p_vsi = ch->parent_vsi;
  4786. if (!p_vsi || !ch->initialized) {
  4787. kfree(ch);
  4788. continue;
  4789. }
  4790. /* Reset queue contexts */
  4791. for (i = 0; i < ch->num_queue_pairs; i++) {
  4792. struct i40e_ring *tx_ring, *rx_ring;
  4793. u16 pf_q;
  4794. pf_q = ch->base_queue + i;
  4795. tx_ring = vsi->tx_rings[pf_q];
  4796. tx_ring->ch = NULL;
  4797. rx_ring = vsi->rx_rings[pf_q];
  4798. rx_ring->ch = NULL;
  4799. }
  4800. /* Reset BW configured for this VSI via mqprio */
  4801. ret = i40e_set_bw_limit(vsi, ch->seid, 0);
  4802. if (ret)
  4803. dev_info(&vsi->back->pdev->dev,
  4804. "Failed to reset tx rate for ch->seid %u\n",
  4805. ch->seid);
  4806. /* delete cloud filters associated with this channel */
  4807. hlist_for_each_entry_safe(cfilter, node,
  4808. &pf->cloud_filter_list, cloud_node) {
  4809. if (cfilter->seid != ch->seid)
  4810. continue;
  4811. hash_del(&cfilter->cloud_node);
  4812. if (cfilter->dst_port)
  4813. ret = i40e_add_del_cloud_filter_big_buf(vsi,
  4814. cfilter,
  4815. false);
  4816. else
  4817. ret = i40e_add_del_cloud_filter(vsi, cfilter,
  4818. false);
  4819. last_aq_status = pf->hw.aq.asq_last_status;
  4820. if (ret)
  4821. dev_info(&pf->pdev->dev,
  4822. "Failed to delete cloud filter, err %s aq_err %s\n",
  4823. i40e_stat_str(&pf->hw, ret),
  4824. i40e_aq_str(&pf->hw, last_aq_status));
  4825. kfree(cfilter);
  4826. }
  4827. /* delete VSI from FW */
  4828. ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
  4829. NULL);
  4830. if (ret)
  4831. dev_err(&vsi->back->pdev->dev,
  4832. "unable to remove channel (%d) for parent VSI(%d)\n",
  4833. ch->seid, p_vsi->seid);
  4834. kfree(ch);
  4835. }
  4836. INIT_LIST_HEAD(&vsi->ch_list);
  4837. }
  4838. /**
  4839. * i40e_is_any_channel - channel exist or not
  4840. * @vsi: ptr to VSI to which channels are associated with
  4841. *
  4842. * Returns true or false if channel(s) exist for associated VSI or not
  4843. **/
  4844. static bool i40e_is_any_channel(struct i40e_vsi *vsi)
  4845. {
  4846. struct i40e_channel *ch, *ch_tmp;
  4847. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4848. if (ch->initialized)
  4849. return true;
  4850. }
  4851. return false;
  4852. }
  4853. /**
  4854. * i40e_get_max_queues_for_channel
  4855. * @vsi: ptr to VSI to which channels are associated with
  4856. *
  4857. * Helper function which returns max value among the queue counts set on the
  4858. * channels/TCs created.
  4859. **/
  4860. static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
  4861. {
  4862. struct i40e_channel *ch, *ch_tmp;
  4863. int max = 0;
  4864. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4865. if (!ch->initialized)
  4866. continue;
  4867. if (ch->num_queue_pairs > max)
  4868. max = ch->num_queue_pairs;
  4869. }
  4870. return max;
  4871. }
  4872. /**
  4873. * i40e_validate_num_queues - validate num_queues w.r.t channel
  4874. * @pf: ptr to PF device
  4875. * @num_queues: number of queues
  4876. * @vsi: the parent VSI
  4877. * @reconfig_rss: indicates should the RSS be reconfigured or not
  4878. *
  4879. * This function validates number of queues in the context of new channel
  4880. * which is being established and determines if RSS should be reconfigured
  4881. * or not for parent VSI.
  4882. **/
  4883. static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
  4884. struct i40e_vsi *vsi, bool *reconfig_rss)
  4885. {
  4886. int max_ch_queues;
  4887. if (!reconfig_rss)
  4888. return -EINVAL;
  4889. *reconfig_rss = false;
  4890. if (vsi->current_rss_size) {
  4891. if (num_queues > vsi->current_rss_size) {
  4892. dev_dbg(&pf->pdev->dev,
  4893. "Error: num_queues (%d) > vsi's current_size(%d)\n",
  4894. num_queues, vsi->current_rss_size);
  4895. return -EINVAL;
  4896. } else if ((num_queues < vsi->current_rss_size) &&
  4897. (!is_power_of_2(num_queues))) {
  4898. dev_dbg(&pf->pdev->dev,
  4899. "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
  4900. num_queues, vsi->current_rss_size);
  4901. return -EINVAL;
  4902. }
  4903. }
  4904. if (!is_power_of_2(num_queues)) {
  4905. /* Find the max num_queues configured for channel if channel
  4906. * exist.
  4907. * if channel exist, then enforce 'num_queues' to be more than
  4908. * max ever queues configured for channel.
  4909. */
  4910. max_ch_queues = i40e_get_max_queues_for_channel(vsi);
  4911. if (num_queues < max_ch_queues) {
  4912. dev_dbg(&pf->pdev->dev,
  4913. "Error: num_queues (%d) < max queues configured for channel(%d)\n",
  4914. num_queues, max_ch_queues);
  4915. return -EINVAL;
  4916. }
  4917. *reconfig_rss = true;
  4918. }
  4919. return 0;
  4920. }
  4921. /**
  4922. * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
  4923. * @vsi: the VSI being setup
  4924. * @rss_size: size of RSS, accordingly LUT gets reprogrammed
  4925. *
  4926. * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
  4927. **/
  4928. static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
  4929. {
  4930. struct i40e_pf *pf = vsi->back;
  4931. u8 seed[I40E_HKEY_ARRAY_SIZE];
  4932. struct i40e_hw *hw = &pf->hw;
  4933. int local_rss_size;
  4934. u8 *lut;
  4935. int ret;
  4936. if (!vsi->rss_size)
  4937. return -EINVAL;
  4938. if (rss_size > vsi->rss_size)
  4939. return -EINVAL;
  4940. local_rss_size = min_t(int, vsi->rss_size, rss_size);
  4941. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  4942. if (!lut)
  4943. return -ENOMEM;
  4944. /* Ignoring user configured lut if there is one */
  4945. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
  4946. /* Use user configured hash key if there is one, otherwise
  4947. * use default.
  4948. */
  4949. if (vsi->rss_hkey_user)
  4950. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  4951. else
  4952. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  4953. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  4954. if (ret) {
  4955. dev_info(&pf->pdev->dev,
  4956. "Cannot set RSS lut, err %s aq_err %s\n",
  4957. i40e_stat_str(hw, ret),
  4958. i40e_aq_str(hw, hw->aq.asq_last_status));
  4959. kfree(lut);
  4960. return ret;
  4961. }
  4962. kfree(lut);
  4963. /* Do the update w.r.t. storing rss_size */
  4964. if (!vsi->orig_rss_size)
  4965. vsi->orig_rss_size = vsi->rss_size;
  4966. vsi->current_rss_size = local_rss_size;
  4967. return ret;
  4968. }
  4969. /**
  4970. * i40e_channel_setup_queue_map - Setup a channel queue map
  4971. * @pf: ptr to PF device
  4972. * @vsi: the VSI being setup
  4973. * @ctxt: VSI context structure
  4974. * @ch: ptr to channel structure
  4975. *
  4976. * Setup queue map for a specific channel
  4977. **/
  4978. static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
  4979. struct i40e_vsi_context *ctxt,
  4980. struct i40e_channel *ch)
  4981. {
  4982. u16 qcount, qmap, sections = 0;
  4983. u8 offset = 0;
  4984. int pow;
  4985. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  4986. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  4987. qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
  4988. ch->num_queue_pairs = qcount;
  4989. /* find the next higher power-of-2 of num queue pairs */
  4990. pow = ilog2(qcount);
  4991. if (!is_power_of_2(qcount))
  4992. pow++;
  4993. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  4994. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  4995. /* Setup queue TC[0].qmap for given VSI context */
  4996. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  4997. ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
  4998. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  4999. ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
  5000. ctxt->info.valid_sections |= cpu_to_le16(sections);
  5001. }
  5002. /**
  5003. * i40e_add_channel - add a channel by adding VSI
  5004. * @pf: ptr to PF device
  5005. * @uplink_seid: underlying HW switching element (VEB) ID
  5006. * @ch: ptr to channel structure
  5007. *
  5008. * Add a channel (VSI) using add_vsi and queue_map
  5009. **/
  5010. static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
  5011. struct i40e_channel *ch)
  5012. {
  5013. struct i40e_hw *hw = &pf->hw;
  5014. struct i40e_vsi_context ctxt;
  5015. u8 enabled_tc = 0x1; /* TC0 enabled */
  5016. int ret;
  5017. if (ch->type != I40E_VSI_VMDQ2) {
  5018. dev_info(&pf->pdev->dev,
  5019. "add new vsi failed, ch->type %d\n", ch->type);
  5020. return -EINVAL;
  5021. }
  5022. memset(&ctxt, 0, sizeof(ctxt));
  5023. ctxt.pf_num = hw->pf_id;
  5024. ctxt.vf_num = 0;
  5025. ctxt.uplink_seid = uplink_seid;
  5026. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  5027. if (ch->type == I40E_VSI_VMDQ2)
  5028. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  5029. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
  5030. ctxt.info.valid_sections |=
  5031. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5032. ctxt.info.switch_id =
  5033. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5034. }
  5035. /* Set queue map for a given VSI context */
  5036. i40e_channel_setup_queue_map(pf, &ctxt, ch);
  5037. /* Now time to create VSI */
  5038. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5039. if (ret) {
  5040. dev_info(&pf->pdev->dev,
  5041. "add new vsi failed, err %s aq_err %s\n",
  5042. i40e_stat_str(&pf->hw, ret),
  5043. i40e_aq_str(&pf->hw,
  5044. pf->hw.aq.asq_last_status));
  5045. return -ENOENT;
  5046. }
  5047. /* Success, update channel */
  5048. ch->enabled_tc = enabled_tc;
  5049. ch->seid = ctxt.seid;
  5050. ch->vsi_number = ctxt.vsi_number;
  5051. ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
  5052. /* copy just the sections touched not the entire info
  5053. * since not all sections are valid as returned by
  5054. * update vsi params
  5055. */
  5056. ch->info.mapping_flags = ctxt.info.mapping_flags;
  5057. memcpy(&ch->info.queue_mapping,
  5058. &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
  5059. memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
  5060. sizeof(ctxt.info.tc_mapping));
  5061. return 0;
  5062. }
  5063. static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
  5064. u8 *bw_share)
  5065. {
  5066. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  5067. i40e_status ret;
  5068. int i;
  5069. bw_data.tc_valid_bits = ch->enabled_tc;
  5070. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5071. bw_data.tc_bw_credits[i] = bw_share[i];
  5072. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
  5073. &bw_data, NULL);
  5074. if (ret) {
  5075. dev_info(&vsi->back->pdev->dev,
  5076. "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
  5077. vsi->back->hw.aq.asq_last_status, ch->seid);
  5078. return -EINVAL;
  5079. }
  5080. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5081. ch->info.qs_handle[i] = bw_data.qs_handles[i];
  5082. return 0;
  5083. }
  5084. /**
  5085. * i40e_channel_config_tx_ring - config TX ring associated with new channel
  5086. * @pf: ptr to PF device
  5087. * @vsi: the VSI being setup
  5088. * @ch: ptr to channel structure
  5089. *
  5090. * Configure TX rings associated with channel (VSI) since queues are being
  5091. * from parent VSI.
  5092. **/
  5093. static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
  5094. struct i40e_vsi *vsi,
  5095. struct i40e_channel *ch)
  5096. {
  5097. i40e_status ret;
  5098. int i;
  5099. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  5100. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  5101. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5102. if (ch->enabled_tc & BIT(i))
  5103. bw_share[i] = 1;
  5104. }
  5105. /* configure BW for new VSI */
  5106. ret = i40e_channel_config_bw(vsi, ch, bw_share);
  5107. if (ret) {
  5108. dev_info(&vsi->back->pdev->dev,
  5109. "Failed configuring TC map %d for channel (seid %u)\n",
  5110. ch->enabled_tc, ch->seid);
  5111. return ret;
  5112. }
  5113. for (i = 0; i < ch->num_queue_pairs; i++) {
  5114. struct i40e_ring *tx_ring, *rx_ring;
  5115. u16 pf_q;
  5116. pf_q = ch->base_queue + i;
  5117. /* Get to TX ring ptr of main VSI, for re-setup TX queue
  5118. * context
  5119. */
  5120. tx_ring = vsi->tx_rings[pf_q];
  5121. tx_ring->ch = ch;
  5122. /* Get the RX ring ptr */
  5123. rx_ring = vsi->rx_rings[pf_q];
  5124. rx_ring->ch = ch;
  5125. }
  5126. return 0;
  5127. }
  5128. /**
  5129. * i40e_setup_hw_channel - setup new channel
  5130. * @pf: ptr to PF device
  5131. * @vsi: the VSI being setup
  5132. * @ch: ptr to channel structure
  5133. * @uplink_seid: underlying HW switching element (VEB) ID
  5134. * @type: type of channel to be created (VMDq2/VF)
  5135. *
  5136. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5137. * and configures TX rings accordingly
  5138. **/
  5139. static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
  5140. struct i40e_vsi *vsi,
  5141. struct i40e_channel *ch,
  5142. u16 uplink_seid, u8 type)
  5143. {
  5144. int ret;
  5145. ch->initialized = false;
  5146. ch->base_queue = vsi->next_base_queue;
  5147. ch->type = type;
  5148. /* Proceed with creation of channel (VMDq2) VSI */
  5149. ret = i40e_add_channel(pf, uplink_seid, ch);
  5150. if (ret) {
  5151. dev_info(&pf->pdev->dev,
  5152. "failed to add_channel using uplink_seid %u\n",
  5153. uplink_seid);
  5154. return ret;
  5155. }
  5156. /* Mark the successful creation of channel */
  5157. ch->initialized = true;
  5158. /* Reconfigure TX queues using QTX_CTL register */
  5159. ret = i40e_channel_config_tx_ring(pf, vsi, ch);
  5160. if (ret) {
  5161. dev_info(&pf->pdev->dev,
  5162. "failed to configure TX rings for channel %u\n",
  5163. ch->seid);
  5164. return ret;
  5165. }
  5166. /* update 'next_base_queue' */
  5167. vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
  5168. dev_dbg(&pf->pdev->dev,
  5169. "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
  5170. ch->seid, ch->vsi_number, ch->stat_counter_idx,
  5171. ch->num_queue_pairs,
  5172. vsi->next_base_queue);
  5173. return ret;
  5174. }
  5175. /**
  5176. * i40e_setup_channel - setup new channel using uplink element
  5177. * @pf: ptr to PF device
  5178. * @type: type of channel to be created (VMDq2/VF)
  5179. * @uplink_seid: underlying HW switching element (VEB) ID
  5180. * @ch: ptr to channel structure
  5181. *
  5182. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5183. * and uplink switching element (uplink_seid)
  5184. **/
  5185. static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
  5186. struct i40e_channel *ch)
  5187. {
  5188. u8 vsi_type;
  5189. u16 seid;
  5190. int ret;
  5191. if (vsi->type == I40E_VSI_MAIN) {
  5192. vsi_type = I40E_VSI_VMDQ2;
  5193. } else {
  5194. dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
  5195. vsi->type);
  5196. return false;
  5197. }
  5198. /* underlying switching element */
  5199. seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5200. /* create channel (VSI), configure TX rings */
  5201. ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
  5202. if (ret) {
  5203. dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
  5204. return false;
  5205. }
  5206. return ch->initialized ? true : false;
  5207. }
  5208. /**
  5209. * i40e_validate_and_set_switch_mode - sets up switch mode correctly
  5210. * @vsi: ptr to VSI which has PF backing
  5211. *
  5212. * Sets up switch mode correctly if it needs to be changed and perform
  5213. * what are allowed modes.
  5214. **/
  5215. static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
  5216. {
  5217. u8 mode;
  5218. struct i40e_pf *pf = vsi->back;
  5219. struct i40e_hw *hw = &pf->hw;
  5220. int ret;
  5221. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
  5222. if (ret)
  5223. return -EINVAL;
  5224. if (hw->dev_caps.switch_mode) {
  5225. /* if switch mode is set, support mode2 (non-tunneled for
  5226. * cloud filter) for now
  5227. */
  5228. u32 switch_mode = hw->dev_caps.switch_mode &
  5229. I40E_SWITCH_MODE_MASK;
  5230. if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
  5231. if (switch_mode == I40E_CLOUD_FILTER_MODE2)
  5232. return 0;
  5233. dev_err(&pf->pdev->dev,
  5234. "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
  5235. hw->dev_caps.switch_mode);
  5236. return -EINVAL;
  5237. }
  5238. }
  5239. /* Set Bit 7 to be valid */
  5240. mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
  5241. /* Set L4type for TCP support */
  5242. mode |= I40E_AQ_SET_SWITCH_L4_TYPE_TCP;
  5243. /* Set cloud filter mode */
  5244. mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
  5245. /* Prep mode field for set_switch_config */
  5246. ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
  5247. pf->last_sw_conf_valid_flags,
  5248. mode, NULL);
  5249. if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
  5250. dev_err(&pf->pdev->dev,
  5251. "couldn't set switch config bits, err %s aq_err %s\n",
  5252. i40e_stat_str(hw, ret),
  5253. i40e_aq_str(hw,
  5254. hw->aq.asq_last_status));
  5255. return ret;
  5256. }
  5257. /**
  5258. * i40e_create_queue_channel - function to create channel
  5259. * @vsi: VSI to be configured
  5260. * @ch: ptr to channel (it contains channel specific params)
  5261. *
  5262. * This function creates channel (VSI) using num_queues specified by user,
  5263. * reconfigs RSS if needed.
  5264. **/
  5265. int i40e_create_queue_channel(struct i40e_vsi *vsi,
  5266. struct i40e_channel *ch)
  5267. {
  5268. struct i40e_pf *pf = vsi->back;
  5269. bool reconfig_rss;
  5270. int err;
  5271. if (!ch)
  5272. return -EINVAL;
  5273. if (!ch->num_queue_pairs) {
  5274. dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
  5275. ch->num_queue_pairs);
  5276. return -EINVAL;
  5277. }
  5278. /* validate user requested num_queues for channel */
  5279. err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
  5280. &reconfig_rss);
  5281. if (err) {
  5282. dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
  5283. ch->num_queue_pairs);
  5284. return -EINVAL;
  5285. }
  5286. /* By default we are in VEPA mode, if this is the first VF/VMDq
  5287. * VSI to be added switch to VEB mode.
  5288. */
  5289. if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
  5290. (!i40e_is_any_channel(vsi))) {
  5291. if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
  5292. dev_dbg(&pf->pdev->dev,
  5293. "Failed to create channel. Override queues (%u) not power of 2\n",
  5294. vsi->tc_config.tc_info[0].qcount);
  5295. return -EINVAL;
  5296. }
  5297. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  5298. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  5299. if (vsi->type == I40E_VSI_MAIN) {
  5300. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  5301. i40e_do_reset(pf, I40E_PF_RESET_FLAG,
  5302. true);
  5303. else
  5304. i40e_do_reset_safe(pf,
  5305. I40E_PF_RESET_FLAG);
  5306. }
  5307. }
  5308. /* now onwards for main VSI, number of queues will be value
  5309. * of TC0's queue count
  5310. */
  5311. }
  5312. /* By this time, vsi->cnt_q_avail shall be set to non-zero and
  5313. * it should be more than num_queues
  5314. */
  5315. if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
  5316. dev_dbg(&pf->pdev->dev,
  5317. "Error: cnt_q_avail (%u) less than num_queues %d\n",
  5318. vsi->cnt_q_avail, ch->num_queue_pairs);
  5319. return -EINVAL;
  5320. }
  5321. /* reconfig_rss only if vsi type is MAIN_VSI */
  5322. if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
  5323. err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
  5324. if (err) {
  5325. dev_info(&pf->pdev->dev,
  5326. "Error: unable to reconfig rss for num_queues (%u)\n",
  5327. ch->num_queue_pairs);
  5328. return -EINVAL;
  5329. }
  5330. }
  5331. if (!i40e_setup_channel(pf, vsi, ch)) {
  5332. dev_info(&pf->pdev->dev, "Failed to setup channel\n");
  5333. return -EINVAL;
  5334. }
  5335. dev_info(&pf->pdev->dev,
  5336. "Setup channel (id:%u) utilizing num_queues %d\n",
  5337. ch->seid, ch->num_queue_pairs);
  5338. /* configure VSI for BW limit */
  5339. if (ch->max_tx_rate) {
  5340. u64 credits = ch->max_tx_rate;
  5341. if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
  5342. return -EINVAL;
  5343. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5344. dev_dbg(&pf->pdev->dev,
  5345. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5346. ch->max_tx_rate,
  5347. credits,
  5348. ch->seid);
  5349. }
  5350. /* in case of VF, this will be main SRIOV VSI */
  5351. ch->parent_vsi = vsi;
  5352. /* and update main_vsi's count for queue_available to use */
  5353. vsi->cnt_q_avail -= ch->num_queue_pairs;
  5354. return 0;
  5355. }
  5356. /**
  5357. * i40e_configure_queue_channels - Add queue channel for the given TCs
  5358. * @vsi: VSI to be configured
  5359. *
  5360. * Configures queue channel mapping to the given TCs
  5361. **/
  5362. static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
  5363. {
  5364. struct i40e_channel *ch;
  5365. u64 max_rate = 0;
  5366. int ret = 0, i;
  5367. /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
  5368. vsi->tc_seid_map[0] = vsi->seid;
  5369. for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5370. if (vsi->tc_config.enabled_tc & BIT(i)) {
  5371. ch = kzalloc(sizeof(*ch), GFP_KERNEL);
  5372. if (!ch) {
  5373. ret = -ENOMEM;
  5374. goto err_free;
  5375. }
  5376. INIT_LIST_HEAD(&ch->list);
  5377. ch->num_queue_pairs =
  5378. vsi->tc_config.tc_info[i].qcount;
  5379. ch->base_queue =
  5380. vsi->tc_config.tc_info[i].qoffset;
  5381. /* Bandwidth limit through tc interface is in bytes/s,
  5382. * change to Mbit/s
  5383. */
  5384. max_rate = vsi->mqprio_qopt.max_rate[i];
  5385. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5386. ch->max_tx_rate = max_rate;
  5387. list_add_tail(&ch->list, &vsi->ch_list);
  5388. ret = i40e_create_queue_channel(vsi, ch);
  5389. if (ret) {
  5390. dev_err(&vsi->back->pdev->dev,
  5391. "Failed creating queue channel with TC%d: queues %d\n",
  5392. i, ch->num_queue_pairs);
  5393. goto err_free;
  5394. }
  5395. vsi->tc_seid_map[i] = ch->seid;
  5396. }
  5397. }
  5398. return ret;
  5399. err_free:
  5400. i40e_remove_queue_channels(vsi);
  5401. return ret;
  5402. }
  5403. /**
  5404. * i40e_veb_config_tc - Configure TCs for given VEB
  5405. * @veb: given VEB
  5406. * @enabled_tc: TC bitmap
  5407. *
  5408. * Configures given TC bitmap for VEB (switching) element
  5409. **/
  5410. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  5411. {
  5412. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  5413. struct i40e_pf *pf = veb->pf;
  5414. int ret = 0;
  5415. int i;
  5416. /* No TCs or already enabled TCs just return */
  5417. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  5418. return ret;
  5419. bw_data.tc_valid_bits = enabled_tc;
  5420. /* bw_data.absolute_credits is not set (relative) */
  5421. /* Enable ETS TCs with equal BW Share for now */
  5422. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5423. if (enabled_tc & BIT(i))
  5424. bw_data.tc_bw_share_credits[i] = 1;
  5425. }
  5426. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  5427. &bw_data, NULL);
  5428. if (ret) {
  5429. dev_info(&pf->pdev->dev,
  5430. "VEB bw config failed, err %s aq_err %s\n",
  5431. i40e_stat_str(&pf->hw, ret),
  5432. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5433. goto out;
  5434. }
  5435. /* Update the BW information */
  5436. ret = i40e_veb_get_bw_info(veb);
  5437. if (ret) {
  5438. dev_info(&pf->pdev->dev,
  5439. "Failed getting veb bw config, err %s aq_err %s\n",
  5440. i40e_stat_str(&pf->hw, ret),
  5441. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5442. }
  5443. out:
  5444. return ret;
  5445. }
  5446. #ifdef CONFIG_I40E_DCB
  5447. /**
  5448. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  5449. * @pf: PF struct
  5450. *
  5451. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  5452. * the caller would've quiesce all the VSIs before calling
  5453. * this function
  5454. **/
  5455. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  5456. {
  5457. u8 tc_map = 0;
  5458. int ret;
  5459. u8 v;
  5460. /* Enable the TCs available on PF to all VEBs */
  5461. tc_map = i40e_pf_get_tc_map(pf);
  5462. for (v = 0; v < I40E_MAX_VEB; v++) {
  5463. if (!pf->veb[v])
  5464. continue;
  5465. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  5466. if (ret) {
  5467. dev_info(&pf->pdev->dev,
  5468. "Failed configuring TC for VEB seid=%d\n",
  5469. pf->veb[v]->seid);
  5470. /* Will try to configure as many components */
  5471. }
  5472. }
  5473. /* Update each VSI */
  5474. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5475. if (!pf->vsi[v])
  5476. continue;
  5477. /* - Enable all TCs for the LAN VSI
  5478. * - For all others keep them at TC0 for now
  5479. */
  5480. if (v == pf->lan_vsi)
  5481. tc_map = i40e_pf_get_tc_map(pf);
  5482. else
  5483. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  5484. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  5485. if (ret) {
  5486. dev_info(&pf->pdev->dev,
  5487. "Failed configuring TC for VSI seid=%d\n",
  5488. pf->vsi[v]->seid);
  5489. /* Will try to configure as many components */
  5490. } else {
  5491. /* Re-configure VSI vectors based on updated TC map */
  5492. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  5493. if (pf->vsi[v]->netdev)
  5494. i40e_dcbnl_set_all(pf->vsi[v]);
  5495. }
  5496. }
  5497. }
  5498. /**
  5499. * i40e_resume_port_tx - Resume port Tx
  5500. * @pf: PF struct
  5501. *
  5502. * Resume a port's Tx and issue a PF reset in case of failure to
  5503. * resume.
  5504. **/
  5505. static int i40e_resume_port_tx(struct i40e_pf *pf)
  5506. {
  5507. struct i40e_hw *hw = &pf->hw;
  5508. int ret;
  5509. ret = i40e_aq_resume_port_tx(hw, NULL);
  5510. if (ret) {
  5511. dev_info(&pf->pdev->dev,
  5512. "Resume Port Tx failed, err %s aq_err %s\n",
  5513. i40e_stat_str(&pf->hw, ret),
  5514. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5515. /* Schedule PF reset to recover */
  5516. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  5517. i40e_service_event_schedule(pf);
  5518. }
  5519. return ret;
  5520. }
  5521. /**
  5522. * i40e_init_pf_dcb - Initialize DCB configuration
  5523. * @pf: PF being configured
  5524. *
  5525. * Query the current DCB configuration and cache it
  5526. * in the hardware structure
  5527. **/
  5528. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  5529. {
  5530. struct i40e_hw *hw = &pf->hw;
  5531. int err = 0;
  5532. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
  5533. * Also do not enable DCBx if FW LLDP agent is disabled
  5534. */
  5535. if ((pf->hw_features & I40E_HW_NO_DCB_SUPPORT) ||
  5536. (pf->flags & I40E_FLAG_DISABLE_FW_LLDP))
  5537. goto out;
  5538. /* Get the initial DCB configuration */
  5539. err = i40e_init_dcb(hw);
  5540. if (!err) {
  5541. /* Device/Function is not DCBX capable */
  5542. if ((!hw->func_caps.dcb) ||
  5543. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  5544. dev_info(&pf->pdev->dev,
  5545. "DCBX offload is not supported or is disabled for this PF.\n");
  5546. } else {
  5547. /* When status is not DISABLED then DCBX in FW */
  5548. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  5549. DCB_CAP_DCBX_VER_IEEE;
  5550. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  5551. /* Enable DCB tagging only when more than one TC
  5552. * or explicitly disable if only one TC
  5553. */
  5554. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5555. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5556. else
  5557. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5558. dev_dbg(&pf->pdev->dev,
  5559. "DCBX offload is supported for this PF.\n");
  5560. }
  5561. } else if (pf->hw.aq.asq_last_status == I40E_AQ_RC_EPERM) {
  5562. dev_info(&pf->pdev->dev, "FW LLDP disabled for this PF.\n");
  5563. pf->flags |= I40E_FLAG_DISABLE_FW_LLDP;
  5564. } else {
  5565. dev_info(&pf->pdev->dev,
  5566. "Query for DCB configuration failed, err %s aq_err %s\n",
  5567. i40e_stat_str(&pf->hw, err),
  5568. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5569. }
  5570. out:
  5571. return err;
  5572. }
  5573. #endif /* CONFIG_I40E_DCB */
  5574. #define SPEED_SIZE 14
  5575. #define FC_SIZE 8
  5576. /**
  5577. * i40e_print_link_message - print link up or down
  5578. * @vsi: the VSI for which link needs a message
  5579. */
  5580. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  5581. {
  5582. enum i40e_aq_link_speed new_speed;
  5583. struct i40e_pf *pf = vsi->back;
  5584. char *speed = "Unknown";
  5585. char *fc = "Unknown";
  5586. char *fec = "";
  5587. char *req_fec = "";
  5588. char *an = "";
  5589. new_speed = pf->hw.phy.link_info.link_speed;
  5590. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  5591. return;
  5592. vsi->current_isup = isup;
  5593. vsi->current_speed = new_speed;
  5594. if (!isup) {
  5595. netdev_info(vsi->netdev, "NIC Link is Down\n");
  5596. return;
  5597. }
  5598. /* Warn user if link speed on NPAR enabled partition is not at
  5599. * least 10GB
  5600. */
  5601. if (pf->hw.func_caps.npar_enable &&
  5602. (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  5603. pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  5604. netdev_warn(vsi->netdev,
  5605. "The partition detected link speed that is less than 10Gbps\n");
  5606. switch (pf->hw.phy.link_info.link_speed) {
  5607. case I40E_LINK_SPEED_40GB:
  5608. speed = "40 G";
  5609. break;
  5610. case I40E_LINK_SPEED_20GB:
  5611. speed = "20 G";
  5612. break;
  5613. case I40E_LINK_SPEED_25GB:
  5614. speed = "25 G";
  5615. break;
  5616. case I40E_LINK_SPEED_10GB:
  5617. speed = "10 G";
  5618. break;
  5619. case I40E_LINK_SPEED_1GB:
  5620. speed = "1000 M";
  5621. break;
  5622. case I40E_LINK_SPEED_100MB:
  5623. speed = "100 M";
  5624. break;
  5625. default:
  5626. break;
  5627. }
  5628. switch (pf->hw.fc.current_mode) {
  5629. case I40E_FC_FULL:
  5630. fc = "RX/TX";
  5631. break;
  5632. case I40E_FC_TX_PAUSE:
  5633. fc = "TX";
  5634. break;
  5635. case I40E_FC_RX_PAUSE:
  5636. fc = "RX";
  5637. break;
  5638. default:
  5639. fc = "None";
  5640. break;
  5641. }
  5642. if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  5643. req_fec = ", Requested FEC: None";
  5644. fec = ", FEC: None";
  5645. an = ", Autoneg: False";
  5646. if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  5647. an = ", Autoneg: True";
  5648. if (pf->hw.phy.link_info.fec_info &
  5649. I40E_AQ_CONFIG_FEC_KR_ENA)
  5650. fec = ", FEC: CL74 FC-FEC/BASE-R";
  5651. else if (pf->hw.phy.link_info.fec_info &
  5652. I40E_AQ_CONFIG_FEC_RS_ENA)
  5653. fec = ", FEC: CL108 RS-FEC";
  5654. /* 'CL108 RS-FEC' should be displayed when RS is requested, or
  5655. * both RS and FC are requested
  5656. */
  5657. if (vsi->back->hw.phy.link_info.req_fec_info &
  5658. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
  5659. if (vsi->back->hw.phy.link_info.req_fec_info &
  5660. I40E_AQ_REQUEST_FEC_RS)
  5661. req_fec = ", Requested FEC: CL108 RS-FEC";
  5662. else
  5663. req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R";
  5664. }
  5665. }
  5666. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
  5667. speed, req_fec, fec, an, fc);
  5668. }
  5669. /**
  5670. * i40e_up_complete - Finish the last steps of bringing up a connection
  5671. * @vsi: the VSI being configured
  5672. **/
  5673. static int i40e_up_complete(struct i40e_vsi *vsi)
  5674. {
  5675. struct i40e_pf *pf = vsi->back;
  5676. int err;
  5677. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5678. i40e_vsi_configure_msix(vsi);
  5679. else
  5680. i40e_configure_msi_and_legacy(vsi);
  5681. /* start rings */
  5682. err = i40e_vsi_start_rings(vsi);
  5683. if (err)
  5684. return err;
  5685. clear_bit(__I40E_VSI_DOWN, vsi->state);
  5686. i40e_napi_enable_all(vsi);
  5687. i40e_vsi_enable_irq(vsi);
  5688. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  5689. (vsi->netdev)) {
  5690. i40e_print_link_message(vsi, true);
  5691. netif_tx_start_all_queues(vsi->netdev);
  5692. netif_carrier_on(vsi->netdev);
  5693. }
  5694. /* replay FDIR SB filters */
  5695. if (vsi->type == I40E_VSI_FDIR) {
  5696. /* reset fd counters */
  5697. pf->fd_add_err = 0;
  5698. pf->fd_atr_cnt = 0;
  5699. i40e_fdir_filter_restore(vsi);
  5700. }
  5701. /* On the next run of the service_task, notify any clients of the new
  5702. * opened netdev
  5703. */
  5704. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  5705. i40e_service_event_schedule(pf);
  5706. return 0;
  5707. }
  5708. /**
  5709. * i40e_vsi_reinit_locked - Reset the VSI
  5710. * @vsi: the VSI being configured
  5711. *
  5712. * Rebuild the ring structs after some configuration
  5713. * has changed, e.g. MTU size.
  5714. **/
  5715. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  5716. {
  5717. struct i40e_pf *pf = vsi->back;
  5718. WARN_ON(in_interrupt());
  5719. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
  5720. usleep_range(1000, 2000);
  5721. i40e_down(vsi);
  5722. i40e_up(vsi);
  5723. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  5724. }
  5725. /**
  5726. * i40e_up - Bring the connection back up after being down
  5727. * @vsi: the VSI being configured
  5728. **/
  5729. int i40e_up(struct i40e_vsi *vsi)
  5730. {
  5731. int err;
  5732. err = i40e_vsi_configure(vsi);
  5733. if (!err)
  5734. err = i40e_up_complete(vsi);
  5735. return err;
  5736. }
  5737. /**
  5738. * i40e_down - Shutdown the connection processing
  5739. * @vsi: the VSI being stopped
  5740. **/
  5741. void i40e_down(struct i40e_vsi *vsi)
  5742. {
  5743. int i;
  5744. /* It is assumed that the caller of this function
  5745. * sets the vsi->state __I40E_VSI_DOWN bit.
  5746. */
  5747. if (vsi->netdev) {
  5748. netif_carrier_off(vsi->netdev);
  5749. netif_tx_disable(vsi->netdev);
  5750. }
  5751. i40e_vsi_disable_irq(vsi);
  5752. i40e_vsi_stop_rings(vsi);
  5753. i40e_napi_disable_all(vsi);
  5754. for (i = 0; i < vsi->num_queue_pairs; i++) {
  5755. i40e_clean_tx_ring(vsi->tx_rings[i]);
  5756. if (i40e_enabled_xdp_vsi(vsi))
  5757. i40e_clean_tx_ring(vsi->xdp_rings[i]);
  5758. i40e_clean_rx_ring(vsi->rx_rings[i]);
  5759. }
  5760. }
  5761. /**
  5762. * i40e_validate_mqprio_qopt- validate queue mapping info
  5763. * @vsi: the VSI being configured
  5764. * @mqprio_qopt: queue parametrs
  5765. **/
  5766. static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
  5767. struct tc_mqprio_qopt_offload *mqprio_qopt)
  5768. {
  5769. u64 sum_max_rate = 0;
  5770. u64 max_rate = 0;
  5771. int i;
  5772. if (mqprio_qopt->qopt.offset[0] != 0 ||
  5773. mqprio_qopt->qopt.num_tc < 1 ||
  5774. mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
  5775. return -EINVAL;
  5776. for (i = 0; ; i++) {
  5777. if (!mqprio_qopt->qopt.count[i])
  5778. return -EINVAL;
  5779. if (mqprio_qopt->min_rate[i]) {
  5780. dev_err(&vsi->back->pdev->dev,
  5781. "Invalid min tx rate (greater than 0) specified\n");
  5782. return -EINVAL;
  5783. }
  5784. max_rate = mqprio_qopt->max_rate[i];
  5785. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5786. sum_max_rate += max_rate;
  5787. if (i >= mqprio_qopt->qopt.num_tc - 1)
  5788. break;
  5789. if (mqprio_qopt->qopt.offset[i + 1] !=
  5790. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
  5791. return -EINVAL;
  5792. }
  5793. if (vsi->num_queue_pairs <
  5794. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
  5795. return -EINVAL;
  5796. }
  5797. if (sum_max_rate > i40e_get_link_speed(vsi)) {
  5798. dev_err(&vsi->back->pdev->dev,
  5799. "Invalid max tx rate specified\n");
  5800. return -EINVAL;
  5801. }
  5802. return 0;
  5803. }
  5804. /**
  5805. * i40e_vsi_set_default_tc_config - set default values for tc configuration
  5806. * @vsi: the VSI being configured
  5807. **/
  5808. static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
  5809. {
  5810. u16 qcount;
  5811. int i;
  5812. /* Only TC0 is enabled */
  5813. vsi->tc_config.numtc = 1;
  5814. vsi->tc_config.enabled_tc = 1;
  5815. qcount = min_t(int, vsi->alloc_queue_pairs,
  5816. i40e_pf_get_max_q_per_tc(vsi->back));
  5817. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5818. /* For the TC that is not enabled set the offset to to default
  5819. * queue and allocate one queue for the given TC.
  5820. */
  5821. vsi->tc_config.tc_info[i].qoffset = 0;
  5822. if (i == 0)
  5823. vsi->tc_config.tc_info[i].qcount = qcount;
  5824. else
  5825. vsi->tc_config.tc_info[i].qcount = 1;
  5826. vsi->tc_config.tc_info[i].netdev_tc = 0;
  5827. }
  5828. }
  5829. /**
  5830. * i40e_setup_tc - configure multiple traffic classes
  5831. * @netdev: net device to configure
  5832. * @type_data: tc offload data
  5833. **/
  5834. static int i40e_setup_tc(struct net_device *netdev, void *type_data)
  5835. {
  5836. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  5837. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5838. struct i40e_vsi *vsi = np->vsi;
  5839. struct i40e_pf *pf = vsi->back;
  5840. u8 enabled_tc = 0, num_tc, hw;
  5841. bool need_reset = false;
  5842. int ret = -EINVAL;
  5843. u16 mode;
  5844. int i;
  5845. num_tc = mqprio_qopt->qopt.num_tc;
  5846. hw = mqprio_qopt->qopt.hw;
  5847. mode = mqprio_qopt->mode;
  5848. if (!hw) {
  5849. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5850. memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
  5851. goto config_tc;
  5852. }
  5853. /* Check if MFP enabled */
  5854. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5855. netdev_info(netdev,
  5856. "Configuring TC not supported in MFP mode\n");
  5857. return ret;
  5858. }
  5859. switch (mode) {
  5860. case TC_MQPRIO_MODE_DCB:
  5861. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5862. /* Check if DCB enabled to continue */
  5863. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  5864. netdev_info(netdev,
  5865. "DCB is not enabled for adapter\n");
  5866. return ret;
  5867. }
  5868. /* Check whether tc count is within enabled limit */
  5869. if (num_tc > i40e_pf_get_num_tc(pf)) {
  5870. netdev_info(netdev,
  5871. "TC count greater than enabled on link for adapter\n");
  5872. return ret;
  5873. }
  5874. break;
  5875. case TC_MQPRIO_MODE_CHANNEL:
  5876. if (pf->flags & I40E_FLAG_DCB_ENABLED) {
  5877. netdev_info(netdev,
  5878. "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
  5879. return ret;
  5880. }
  5881. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5882. return ret;
  5883. ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
  5884. if (ret)
  5885. return ret;
  5886. memcpy(&vsi->mqprio_qopt, mqprio_qopt,
  5887. sizeof(*mqprio_qopt));
  5888. pf->flags |= I40E_FLAG_TC_MQPRIO;
  5889. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5890. break;
  5891. default:
  5892. return -EINVAL;
  5893. }
  5894. config_tc:
  5895. /* Generate TC map for number of tc requested */
  5896. for (i = 0; i < num_tc; i++)
  5897. enabled_tc |= BIT(i);
  5898. /* Requesting same TC configuration as already enabled */
  5899. if (enabled_tc == vsi->tc_config.enabled_tc &&
  5900. mode != TC_MQPRIO_MODE_CHANNEL)
  5901. return 0;
  5902. /* Quiesce VSI queues */
  5903. i40e_quiesce_vsi(vsi);
  5904. if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
  5905. i40e_remove_queue_channels(vsi);
  5906. /* Configure VSI for enabled TCs */
  5907. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  5908. if (ret) {
  5909. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  5910. vsi->seid);
  5911. need_reset = true;
  5912. goto exit;
  5913. }
  5914. if (pf->flags & I40E_FLAG_TC_MQPRIO) {
  5915. if (vsi->mqprio_qopt.max_rate[0]) {
  5916. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  5917. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  5918. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  5919. if (!ret) {
  5920. u64 credits = max_tx_rate;
  5921. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5922. dev_dbg(&vsi->back->pdev->dev,
  5923. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5924. max_tx_rate,
  5925. credits,
  5926. vsi->seid);
  5927. } else {
  5928. need_reset = true;
  5929. goto exit;
  5930. }
  5931. }
  5932. ret = i40e_configure_queue_channels(vsi);
  5933. if (ret) {
  5934. netdev_info(netdev,
  5935. "Failed configuring queue channels\n");
  5936. need_reset = true;
  5937. goto exit;
  5938. }
  5939. }
  5940. exit:
  5941. /* Reset the configuration data to defaults, only TC0 is enabled */
  5942. if (need_reset) {
  5943. i40e_vsi_set_default_tc_config(vsi);
  5944. need_reset = false;
  5945. }
  5946. /* Unquiesce VSI */
  5947. i40e_unquiesce_vsi(vsi);
  5948. return ret;
  5949. }
  5950. /**
  5951. * i40e_set_cld_element - sets cloud filter element data
  5952. * @filter: cloud filter rule
  5953. * @cld: ptr to cloud filter element data
  5954. *
  5955. * This is helper function to copy data into cloud filter element
  5956. **/
  5957. static inline void
  5958. i40e_set_cld_element(struct i40e_cloud_filter *filter,
  5959. struct i40e_aqc_cloud_filters_element_data *cld)
  5960. {
  5961. int i, j;
  5962. u32 ipa;
  5963. memset(cld, 0, sizeof(*cld));
  5964. ether_addr_copy(cld->outer_mac, filter->dst_mac);
  5965. ether_addr_copy(cld->inner_mac, filter->src_mac);
  5966. if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
  5967. return;
  5968. if (filter->n_proto == ETH_P_IPV6) {
  5969. #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
  5970. for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
  5971. i++, j += 2) {
  5972. ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
  5973. ipa = cpu_to_le32(ipa);
  5974. memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
  5975. }
  5976. } else {
  5977. ipa = be32_to_cpu(filter->dst_ipv4);
  5978. memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
  5979. }
  5980. cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
  5981. /* tenant_id is not supported by FW now, once the support is enabled
  5982. * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
  5983. */
  5984. if (filter->tenant_id)
  5985. return;
  5986. }
  5987. /**
  5988. * i40e_add_del_cloud_filter - Add/del cloud filter
  5989. * @vsi: pointer to VSI
  5990. * @filter: cloud filter rule
  5991. * @add: if true, add, if false, delete
  5992. *
  5993. * Add or delete a cloud filter for a specific flow spec.
  5994. * Returns 0 if the filter were successfully added.
  5995. **/
  5996. static int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  5997. struct i40e_cloud_filter *filter, bool add)
  5998. {
  5999. struct i40e_aqc_cloud_filters_element_data cld_filter;
  6000. struct i40e_pf *pf = vsi->back;
  6001. int ret;
  6002. static const u16 flag_table[128] = {
  6003. [I40E_CLOUD_FILTER_FLAGS_OMAC] =
  6004. I40E_AQC_ADD_CLOUD_FILTER_OMAC,
  6005. [I40E_CLOUD_FILTER_FLAGS_IMAC] =
  6006. I40E_AQC_ADD_CLOUD_FILTER_IMAC,
  6007. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
  6008. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
  6009. [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
  6010. I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
  6011. [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
  6012. I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
  6013. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
  6014. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
  6015. [I40E_CLOUD_FILTER_FLAGS_IIP] =
  6016. I40E_AQC_ADD_CLOUD_FILTER_IIP,
  6017. };
  6018. if (filter->flags >= ARRAY_SIZE(flag_table))
  6019. return I40E_ERR_CONFIG;
  6020. /* copy element needed to add cloud filter from filter */
  6021. i40e_set_cld_element(filter, &cld_filter);
  6022. if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
  6023. cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
  6024. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
  6025. if (filter->n_proto == ETH_P_IPV6)
  6026. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6027. I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6028. else
  6029. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6030. I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6031. if (add)
  6032. ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
  6033. &cld_filter, 1);
  6034. else
  6035. ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
  6036. &cld_filter, 1);
  6037. if (ret)
  6038. dev_dbg(&pf->pdev->dev,
  6039. "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
  6040. add ? "add" : "delete", filter->dst_port, ret,
  6041. pf->hw.aq.asq_last_status);
  6042. else
  6043. dev_info(&pf->pdev->dev,
  6044. "%s cloud filter for VSI: %d\n",
  6045. add ? "Added" : "Deleted", filter->seid);
  6046. return ret;
  6047. }
  6048. /**
  6049. * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
  6050. * @vsi: pointer to VSI
  6051. * @filter: cloud filter rule
  6052. * @add: if true, add, if false, delete
  6053. *
  6054. * Add or delete a cloud filter for a specific flow spec using big buffer.
  6055. * Returns 0 if the filter were successfully added.
  6056. **/
  6057. static int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  6058. struct i40e_cloud_filter *filter,
  6059. bool add)
  6060. {
  6061. struct i40e_aqc_cloud_filters_element_bb cld_filter;
  6062. struct i40e_pf *pf = vsi->back;
  6063. int ret;
  6064. /* Both (src/dst) valid mac_addr are not supported */
  6065. if ((is_valid_ether_addr(filter->dst_mac) &&
  6066. is_valid_ether_addr(filter->src_mac)) ||
  6067. (is_multicast_ether_addr(filter->dst_mac) &&
  6068. is_multicast_ether_addr(filter->src_mac)))
  6069. return -EOPNOTSUPP;
  6070. /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
  6071. * ports are not supported via big buffer now.
  6072. */
  6073. if (!filter->dst_port || filter->ip_proto == IPPROTO_UDP)
  6074. return -EOPNOTSUPP;
  6075. /* adding filter using src_port/src_ip is not supported at this stage */
  6076. if (filter->src_port || filter->src_ipv4 ||
  6077. !ipv6_addr_any(&filter->ip.v6.src_ip6))
  6078. return -EOPNOTSUPP;
  6079. /* copy element needed to add cloud filter from filter */
  6080. i40e_set_cld_element(filter, &cld_filter.element);
  6081. if (is_valid_ether_addr(filter->dst_mac) ||
  6082. is_valid_ether_addr(filter->src_mac) ||
  6083. is_multicast_ether_addr(filter->dst_mac) ||
  6084. is_multicast_ether_addr(filter->src_mac)) {
  6085. /* MAC + IP : unsupported mode */
  6086. if (filter->dst_ipv4)
  6087. return -EOPNOTSUPP;
  6088. /* since we validated that L4 port must be valid before
  6089. * we get here, start with respective "flags" value
  6090. * and update if vlan is present or not
  6091. */
  6092. cld_filter.element.flags =
  6093. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
  6094. if (filter->vlan_id) {
  6095. cld_filter.element.flags =
  6096. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
  6097. }
  6098. } else if (filter->dst_ipv4 ||
  6099. !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
  6100. cld_filter.element.flags =
  6101. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
  6102. if (filter->n_proto == ETH_P_IPV6)
  6103. cld_filter.element.flags |=
  6104. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6105. else
  6106. cld_filter.element.flags |=
  6107. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6108. } else {
  6109. dev_err(&pf->pdev->dev,
  6110. "either mac or ip has to be valid for cloud filter\n");
  6111. return -EINVAL;
  6112. }
  6113. /* Now copy L4 port in Byte 6..7 in general fields */
  6114. cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
  6115. be16_to_cpu(filter->dst_port);
  6116. if (add) {
  6117. /* Validate current device switch mode, change if necessary */
  6118. ret = i40e_validate_and_set_switch_mode(vsi);
  6119. if (ret) {
  6120. dev_err(&pf->pdev->dev,
  6121. "failed to set switch mode, ret %d\n",
  6122. ret);
  6123. return ret;
  6124. }
  6125. ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
  6126. &cld_filter, 1);
  6127. } else {
  6128. ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
  6129. &cld_filter, 1);
  6130. }
  6131. if (ret)
  6132. dev_dbg(&pf->pdev->dev,
  6133. "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
  6134. add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
  6135. else
  6136. dev_info(&pf->pdev->dev,
  6137. "%s cloud filter for VSI: %d, L4 port: %d\n",
  6138. add ? "add" : "delete", filter->seid,
  6139. ntohs(filter->dst_port));
  6140. return ret;
  6141. }
  6142. /**
  6143. * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
  6144. * @vsi: Pointer to VSI
  6145. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6146. * @filter: Pointer to cloud filter structure
  6147. *
  6148. **/
  6149. static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
  6150. struct tc_cls_flower_offload *f,
  6151. struct i40e_cloud_filter *filter)
  6152. {
  6153. u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
  6154. struct i40e_pf *pf = vsi->back;
  6155. u8 field_flags = 0;
  6156. if (f->dissector->used_keys &
  6157. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  6158. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  6159. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  6160. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  6161. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  6162. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  6163. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  6164. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  6165. dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
  6166. f->dissector->used_keys);
  6167. return -EOPNOTSUPP;
  6168. }
  6169. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  6170. struct flow_dissector_key_keyid *key =
  6171. skb_flow_dissector_target(f->dissector,
  6172. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6173. f->key);
  6174. struct flow_dissector_key_keyid *mask =
  6175. skb_flow_dissector_target(f->dissector,
  6176. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6177. f->mask);
  6178. if (mask->keyid != 0)
  6179. field_flags |= I40E_CLOUD_FIELD_TEN_ID;
  6180. filter->tenant_id = be32_to_cpu(key->keyid);
  6181. }
  6182. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  6183. struct flow_dissector_key_basic *key =
  6184. skb_flow_dissector_target(f->dissector,
  6185. FLOW_DISSECTOR_KEY_BASIC,
  6186. f->key);
  6187. struct flow_dissector_key_basic *mask =
  6188. skb_flow_dissector_target(f->dissector,
  6189. FLOW_DISSECTOR_KEY_BASIC,
  6190. f->mask);
  6191. n_proto_key = ntohs(key->n_proto);
  6192. n_proto_mask = ntohs(mask->n_proto);
  6193. if (n_proto_key == ETH_P_ALL) {
  6194. n_proto_key = 0;
  6195. n_proto_mask = 0;
  6196. }
  6197. filter->n_proto = n_proto_key & n_proto_mask;
  6198. filter->ip_proto = key->ip_proto;
  6199. }
  6200. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  6201. struct flow_dissector_key_eth_addrs *key =
  6202. skb_flow_dissector_target(f->dissector,
  6203. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6204. f->key);
  6205. struct flow_dissector_key_eth_addrs *mask =
  6206. skb_flow_dissector_target(f->dissector,
  6207. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6208. f->mask);
  6209. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  6210. if (!is_zero_ether_addr(mask->dst)) {
  6211. if (is_broadcast_ether_addr(mask->dst)) {
  6212. field_flags |= I40E_CLOUD_FIELD_OMAC;
  6213. } else {
  6214. dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
  6215. mask->dst);
  6216. return I40E_ERR_CONFIG;
  6217. }
  6218. }
  6219. if (!is_zero_ether_addr(mask->src)) {
  6220. if (is_broadcast_ether_addr(mask->src)) {
  6221. field_flags |= I40E_CLOUD_FIELD_IMAC;
  6222. } else {
  6223. dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
  6224. mask->src);
  6225. return I40E_ERR_CONFIG;
  6226. }
  6227. }
  6228. ether_addr_copy(filter->dst_mac, key->dst);
  6229. ether_addr_copy(filter->src_mac, key->src);
  6230. }
  6231. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  6232. struct flow_dissector_key_vlan *key =
  6233. skb_flow_dissector_target(f->dissector,
  6234. FLOW_DISSECTOR_KEY_VLAN,
  6235. f->key);
  6236. struct flow_dissector_key_vlan *mask =
  6237. skb_flow_dissector_target(f->dissector,
  6238. FLOW_DISSECTOR_KEY_VLAN,
  6239. f->mask);
  6240. if (mask->vlan_id) {
  6241. if (mask->vlan_id == VLAN_VID_MASK) {
  6242. field_flags |= I40E_CLOUD_FIELD_IVLAN;
  6243. } else {
  6244. dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
  6245. mask->vlan_id);
  6246. return I40E_ERR_CONFIG;
  6247. }
  6248. }
  6249. filter->vlan_id = cpu_to_be16(key->vlan_id);
  6250. }
  6251. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  6252. struct flow_dissector_key_control *key =
  6253. skb_flow_dissector_target(f->dissector,
  6254. FLOW_DISSECTOR_KEY_CONTROL,
  6255. f->key);
  6256. addr_type = key->addr_type;
  6257. }
  6258. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  6259. struct flow_dissector_key_ipv4_addrs *key =
  6260. skb_flow_dissector_target(f->dissector,
  6261. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6262. f->key);
  6263. struct flow_dissector_key_ipv4_addrs *mask =
  6264. skb_flow_dissector_target(f->dissector,
  6265. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6266. f->mask);
  6267. if (mask->dst) {
  6268. if (mask->dst == cpu_to_be32(0xffffffff)) {
  6269. field_flags |= I40E_CLOUD_FIELD_IIP;
  6270. } else {
  6271. mask->dst = be32_to_cpu(mask->dst);
  6272. dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4\n",
  6273. &mask->dst);
  6274. return I40E_ERR_CONFIG;
  6275. }
  6276. }
  6277. if (mask->src) {
  6278. if (mask->src == cpu_to_be32(0xffffffff)) {
  6279. field_flags |= I40E_CLOUD_FIELD_IIP;
  6280. } else {
  6281. mask->src = be32_to_cpu(mask->src);
  6282. dev_err(&pf->pdev->dev, "Bad ip src mask %pI4\n",
  6283. &mask->src);
  6284. return I40E_ERR_CONFIG;
  6285. }
  6286. }
  6287. if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
  6288. dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
  6289. return I40E_ERR_CONFIG;
  6290. }
  6291. filter->dst_ipv4 = key->dst;
  6292. filter->src_ipv4 = key->src;
  6293. }
  6294. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  6295. struct flow_dissector_key_ipv6_addrs *key =
  6296. skb_flow_dissector_target(f->dissector,
  6297. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6298. f->key);
  6299. struct flow_dissector_key_ipv6_addrs *mask =
  6300. skb_flow_dissector_target(f->dissector,
  6301. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6302. f->mask);
  6303. /* src and dest IPV6 address should not be LOOPBACK
  6304. * (0:0:0:0:0:0:0:1), which can be represented as ::1
  6305. */
  6306. if (ipv6_addr_loopback(&key->dst) ||
  6307. ipv6_addr_loopback(&key->src)) {
  6308. dev_err(&pf->pdev->dev,
  6309. "Bad ipv6, addr is LOOPBACK\n");
  6310. return I40E_ERR_CONFIG;
  6311. }
  6312. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  6313. field_flags |= I40E_CLOUD_FIELD_IIP;
  6314. memcpy(&filter->src_ipv6, &key->src.s6_addr32,
  6315. sizeof(filter->src_ipv6));
  6316. memcpy(&filter->dst_ipv6, &key->dst.s6_addr32,
  6317. sizeof(filter->dst_ipv6));
  6318. }
  6319. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  6320. struct flow_dissector_key_ports *key =
  6321. skb_flow_dissector_target(f->dissector,
  6322. FLOW_DISSECTOR_KEY_PORTS,
  6323. f->key);
  6324. struct flow_dissector_key_ports *mask =
  6325. skb_flow_dissector_target(f->dissector,
  6326. FLOW_DISSECTOR_KEY_PORTS,
  6327. f->mask);
  6328. if (mask->src) {
  6329. if (mask->src == cpu_to_be16(0xffff)) {
  6330. field_flags |= I40E_CLOUD_FIELD_IIP;
  6331. } else {
  6332. dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
  6333. be16_to_cpu(mask->src));
  6334. return I40E_ERR_CONFIG;
  6335. }
  6336. }
  6337. if (mask->dst) {
  6338. if (mask->dst == cpu_to_be16(0xffff)) {
  6339. field_flags |= I40E_CLOUD_FIELD_IIP;
  6340. } else {
  6341. dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
  6342. be16_to_cpu(mask->dst));
  6343. return I40E_ERR_CONFIG;
  6344. }
  6345. }
  6346. filter->dst_port = key->dst;
  6347. filter->src_port = key->src;
  6348. switch (filter->ip_proto) {
  6349. case IPPROTO_TCP:
  6350. case IPPROTO_UDP:
  6351. break;
  6352. default:
  6353. dev_err(&pf->pdev->dev,
  6354. "Only UDP and TCP transport are supported\n");
  6355. return -EINVAL;
  6356. }
  6357. }
  6358. filter->flags = field_flags;
  6359. return 0;
  6360. }
  6361. /**
  6362. * i40e_handle_tclass: Forward to a traffic class on the device
  6363. * @vsi: Pointer to VSI
  6364. * @tc: traffic class index on the device
  6365. * @filter: Pointer to cloud filter structure
  6366. *
  6367. **/
  6368. static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
  6369. struct i40e_cloud_filter *filter)
  6370. {
  6371. struct i40e_channel *ch, *ch_tmp;
  6372. /* direct to a traffic class on the same device */
  6373. if (tc == 0) {
  6374. filter->seid = vsi->seid;
  6375. return 0;
  6376. } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
  6377. if (!filter->dst_port) {
  6378. dev_err(&vsi->back->pdev->dev,
  6379. "Specify destination port to direct to traffic class that is not default\n");
  6380. return -EINVAL;
  6381. }
  6382. if (list_empty(&vsi->ch_list))
  6383. return -EINVAL;
  6384. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
  6385. list) {
  6386. if (ch->seid == vsi->tc_seid_map[tc])
  6387. filter->seid = ch->seid;
  6388. }
  6389. return 0;
  6390. }
  6391. dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
  6392. return -EINVAL;
  6393. }
  6394. /**
  6395. * i40e_configure_clsflower - Configure tc flower filters
  6396. * @vsi: Pointer to VSI
  6397. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6398. *
  6399. **/
  6400. static int i40e_configure_clsflower(struct i40e_vsi *vsi,
  6401. struct tc_cls_flower_offload *cls_flower)
  6402. {
  6403. int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
  6404. struct i40e_cloud_filter *filter = NULL;
  6405. struct i40e_pf *pf = vsi->back;
  6406. int err = 0;
  6407. if (tc < 0) {
  6408. dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
  6409. return -EOPNOTSUPP;
  6410. }
  6411. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  6412. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  6413. return -EBUSY;
  6414. if (pf->fdir_pf_active_filters ||
  6415. (!hlist_empty(&pf->fdir_filter_list))) {
  6416. dev_err(&vsi->back->pdev->dev,
  6417. "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
  6418. return -EINVAL;
  6419. }
  6420. if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
  6421. dev_err(&vsi->back->pdev->dev,
  6422. "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
  6423. vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6424. vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6425. }
  6426. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  6427. if (!filter)
  6428. return -ENOMEM;
  6429. filter->cookie = cls_flower->cookie;
  6430. err = i40e_parse_cls_flower(vsi, cls_flower, filter);
  6431. if (err < 0)
  6432. goto err;
  6433. err = i40e_handle_tclass(vsi, tc, filter);
  6434. if (err < 0)
  6435. goto err;
  6436. /* Add cloud filter */
  6437. if (filter->dst_port)
  6438. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
  6439. else
  6440. err = i40e_add_del_cloud_filter(vsi, filter, true);
  6441. if (err) {
  6442. dev_err(&pf->pdev->dev,
  6443. "Failed to add cloud filter, err %s\n",
  6444. i40e_stat_str(&pf->hw, err));
  6445. goto err;
  6446. }
  6447. /* add filter to the ordered list */
  6448. INIT_HLIST_NODE(&filter->cloud_node);
  6449. hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
  6450. pf->num_cloud_filters++;
  6451. return err;
  6452. err:
  6453. kfree(filter);
  6454. return err;
  6455. }
  6456. /**
  6457. * i40e_find_cloud_filter - Find the could filter in the list
  6458. * @vsi: Pointer to VSI
  6459. * @cookie: filter specific cookie
  6460. *
  6461. **/
  6462. static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
  6463. unsigned long *cookie)
  6464. {
  6465. struct i40e_cloud_filter *filter = NULL;
  6466. struct hlist_node *node2;
  6467. hlist_for_each_entry_safe(filter, node2,
  6468. &vsi->back->cloud_filter_list, cloud_node)
  6469. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  6470. return filter;
  6471. return NULL;
  6472. }
  6473. /**
  6474. * i40e_delete_clsflower - Remove tc flower filters
  6475. * @vsi: Pointer to VSI
  6476. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6477. *
  6478. **/
  6479. static int i40e_delete_clsflower(struct i40e_vsi *vsi,
  6480. struct tc_cls_flower_offload *cls_flower)
  6481. {
  6482. struct i40e_cloud_filter *filter = NULL;
  6483. struct i40e_pf *pf = vsi->back;
  6484. int err = 0;
  6485. filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
  6486. if (!filter)
  6487. return -EINVAL;
  6488. hash_del(&filter->cloud_node);
  6489. if (filter->dst_port)
  6490. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
  6491. else
  6492. err = i40e_add_del_cloud_filter(vsi, filter, false);
  6493. kfree(filter);
  6494. if (err) {
  6495. dev_err(&pf->pdev->dev,
  6496. "Failed to delete cloud filter, err %s\n",
  6497. i40e_stat_str(&pf->hw, err));
  6498. return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6499. }
  6500. pf->num_cloud_filters--;
  6501. if (!pf->num_cloud_filters)
  6502. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6503. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6504. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6505. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6506. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6507. }
  6508. return 0;
  6509. }
  6510. /**
  6511. * i40e_setup_tc_cls_flower - flower classifier offloads
  6512. * @netdev: net device to configure
  6513. * @type_data: offload data
  6514. **/
  6515. static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
  6516. struct tc_cls_flower_offload *cls_flower)
  6517. {
  6518. struct i40e_vsi *vsi = np->vsi;
  6519. switch (cls_flower->command) {
  6520. case TC_CLSFLOWER_REPLACE:
  6521. return i40e_configure_clsflower(vsi, cls_flower);
  6522. case TC_CLSFLOWER_DESTROY:
  6523. return i40e_delete_clsflower(vsi, cls_flower);
  6524. case TC_CLSFLOWER_STATS:
  6525. return -EOPNOTSUPP;
  6526. default:
  6527. return -EINVAL;
  6528. }
  6529. }
  6530. static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  6531. void *cb_priv)
  6532. {
  6533. struct i40e_netdev_priv *np = cb_priv;
  6534. if (!tc_cls_can_offload_and_chain0(np->vsi->netdev, type_data))
  6535. return -EOPNOTSUPP;
  6536. switch (type) {
  6537. case TC_SETUP_CLSFLOWER:
  6538. return i40e_setup_tc_cls_flower(np, type_data);
  6539. default:
  6540. return -EOPNOTSUPP;
  6541. }
  6542. }
  6543. static int i40e_setup_tc_block(struct net_device *dev,
  6544. struct tc_block_offload *f)
  6545. {
  6546. struct i40e_netdev_priv *np = netdev_priv(dev);
  6547. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  6548. return -EOPNOTSUPP;
  6549. switch (f->command) {
  6550. case TC_BLOCK_BIND:
  6551. return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
  6552. np, np);
  6553. case TC_BLOCK_UNBIND:
  6554. tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
  6555. return 0;
  6556. default:
  6557. return -EOPNOTSUPP;
  6558. }
  6559. }
  6560. static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  6561. void *type_data)
  6562. {
  6563. switch (type) {
  6564. case TC_SETUP_QDISC_MQPRIO:
  6565. return i40e_setup_tc(netdev, type_data);
  6566. case TC_SETUP_BLOCK:
  6567. return i40e_setup_tc_block(netdev, type_data);
  6568. default:
  6569. return -EOPNOTSUPP;
  6570. }
  6571. }
  6572. /**
  6573. * i40e_open - Called when a network interface is made active
  6574. * @netdev: network interface device structure
  6575. *
  6576. * The open entry point is called when a network interface is made
  6577. * active by the system (IFF_UP). At this point all resources needed
  6578. * for transmit and receive operations are allocated, the interrupt
  6579. * handler is registered with the OS, the netdev watchdog subtask is
  6580. * enabled, and the stack is notified that the interface is ready.
  6581. *
  6582. * Returns 0 on success, negative value on failure
  6583. **/
  6584. int i40e_open(struct net_device *netdev)
  6585. {
  6586. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6587. struct i40e_vsi *vsi = np->vsi;
  6588. struct i40e_pf *pf = vsi->back;
  6589. int err;
  6590. /* disallow open during test or if eeprom is broken */
  6591. if (test_bit(__I40E_TESTING, pf->state) ||
  6592. test_bit(__I40E_BAD_EEPROM, pf->state))
  6593. return -EBUSY;
  6594. netif_carrier_off(netdev);
  6595. err = i40e_vsi_open(vsi);
  6596. if (err)
  6597. return err;
  6598. /* configure global TSO hardware offload settings */
  6599. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  6600. TCP_FLAG_FIN) >> 16);
  6601. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  6602. TCP_FLAG_FIN |
  6603. TCP_FLAG_CWR) >> 16);
  6604. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  6605. udp_tunnel_get_rx_info(netdev);
  6606. return 0;
  6607. }
  6608. /**
  6609. * i40e_vsi_open -
  6610. * @vsi: the VSI to open
  6611. *
  6612. * Finish initialization of the VSI.
  6613. *
  6614. * Returns 0 on success, negative value on failure
  6615. *
  6616. * Note: expects to be called while under rtnl_lock()
  6617. **/
  6618. int i40e_vsi_open(struct i40e_vsi *vsi)
  6619. {
  6620. struct i40e_pf *pf = vsi->back;
  6621. char int_name[I40E_INT_NAME_STR_LEN];
  6622. int err;
  6623. /* allocate descriptors */
  6624. err = i40e_vsi_setup_tx_resources(vsi);
  6625. if (err)
  6626. goto err_setup_tx;
  6627. err = i40e_vsi_setup_rx_resources(vsi);
  6628. if (err)
  6629. goto err_setup_rx;
  6630. err = i40e_vsi_configure(vsi);
  6631. if (err)
  6632. goto err_setup_rx;
  6633. if (vsi->netdev) {
  6634. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  6635. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  6636. err = i40e_vsi_request_irq(vsi, int_name);
  6637. if (err)
  6638. goto err_setup_rx;
  6639. /* Notify the stack of the actual queue counts. */
  6640. err = netif_set_real_num_tx_queues(vsi->netdev,
  6641. vsi->num_queue_pairs);
  6642. if (err)
  6643. goto err_set_queues;
  6644. err = netif_set_real_num_rx_queues(vsi->netdev,
  6645. vsi->num_queue_pairs);
  6646. if (err)
  6647. goto err_set_queues;
  6648. } else if (vsi->type == I40E_VSI_FDIR) {
  6649. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  6650. dev_driver_string(&pf->pdev->dev),
  6651. dev_name(&pf->pdev->dev));
  6652. err = i40e_vsi_request_irq(vsi, int_name);
  6653. } else {
  6654. err = -EINVAL;
  6655. goto err_setup_rx;
  6656. }
  6657. err = i40e_up_complete(vsi);
  6658. if (err)
  6659. goto err_up_complete;
  6660. return 0;
  6661. err_up_complete:
  6662. i40e_down(vsi);
  6663. err_set_queues:
  6664. i40e_vsi_free_irq(vsi);
  6665. err_setup_rx:
  6666. i40e_vsi_free_rx_resources(vsi);
  6667. err_setup_tx:
  6668. i40e_vsi_free_tx_resources(vsi);
  6669. if (vsi == pf->vsi[pf->lan_vsi])
  6670. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  6671. return err;
  6672. }
  6673. /**
  6674. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  6675. * @pf: Pointer to PF
  6676. *
  6677. * This function destroys the hlist where all the Flow Director
  6678. * filters were saved.
  6679. **/
  6680. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  6681. {
  6682. struct i40e_fdir_filter *filter;
  6683. struct i40e_flex_pit *pit_entry, *tmp;
  6684. struct hlist_node *node2;
  6685. hlist_for_each_entry_safe(filter, node2,
  6686. &pf->fdir_filter_list, fdir_node) {
  6687. hlist_del(&filter->fdir_node);
  6688. kfree(filter);
  6689. }
  6690. list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
  6691. list_del(&pit_entry->list);
  6692. kfree(pit_entry);
  6693. }
  6694. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  6695. list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
  6696. list_del(&pit_entry->list);
  6697. kfree(pit_entry);
  6698. }
  6699. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  6700. pf->fdir_pf_active_filters = 0;
  6701. pf->fd_tcp4_filter_cnt = 0;
  6702. pf->fd_udp4_filter_cnt = 0;
  6703. pf->fd_sctp4_filter_cnt = 0;
  6704. pf->fd_ip4_filter_cnt = 0;
  6705. /* Reprogram the default input set for TCP/IPv4 */
  6706. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  6707. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6708. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6709. /* Reprogram the default input set for UDP/IPv4 */
  6710. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
  6711. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6712. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6713. /* Reprogram the default input set for SCTP/IPv4 */
  6714. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
  6715. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6716. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6717. /* Reprogram the default input set for Other/IPv4 */
  6718. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
  6719. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6720. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
  6721. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6722. }
  6723. /**
  6724. * i40e_cloud_filter_exit - Cleans up the cloud filters
  6725. * @pf: Pointer to PF
  6726. *
  6727. * This function destroys the hlist where all the cloud filters
  6728. * were saved.
  6729. **/
  6730. static void i40e_cloud_filter_exit(struct i40e_pf *pf)
  6731. {
  6732. struct i40e_cloud_filter *cfilter;
  6733. struct hlist_node *node;
  6734. hlist_for_each_entry_safe(cfilter, node,
  6735. &pf->cloud_filter_list, cloud_node) {
  6736. hlist_del(&cfilter->cloud_node);
  6737. kfree(cfilter);
  6738. }
  6739. pf->num_cloud_filters = 0;
  6740. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6741. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6742. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6743. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6744. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6745. }
  6746. }
  6747. /**
  6748. * i40e_close - Disables a network interface
  6749. * @netdev: network interface device structure
  6750. *
  6751. * The close entry point is called when an interface is de-activated
  6752. * by the OS. The hardware is still under the driver's control, but
  6753. * this netdev interface is disabled.
  6754. *
  6755. * Returns 0, this is not allowed to fail
  6756. **/
  6757. int i40e_close(struct net_device *netdev)
  6758. {
  6759. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6760. struct i40e_vsi *vsi = np->vsi;
  6761. i40e_vsi_close(vsi);
  6762. return 0;
  6763. }
  6764. /**
  6765. * i40e_do_reset - Start a PF or Core Reset sequence
  6766. * @pf: board private structure
  6767. * @reset_flags: which reset is requested
  6768. * @lock_acquired: indicates whether or not the lock has been acquired
  6769. * before this function was called.
  6770. *
  6771. * The essential difference in resets is that the PF Reset
  6772. * doesn't clear the packet buffers, doesn't reset the PE
  6773. * firmware, and doesn't bother the other PFs on the chip.
  6774. **/
  6775. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
  6776. {
  6777. u32 val;
  6778. WARN_ON(in_interrupt());
  6779. /* do the biggest reset indicated */
  6780. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  6781. /* Request a Global Reset
  6782. *
  6783. * This will start the chip's countdown to the actual full
  6784. * chip reset event, and a warning interrupt to be sent
  6785. * to all PFs, including the requestor. Our handler
  6786. * for the warning interrupt will deal with the shutdown
  6787. * and recovery of the switch setup.
  6788. */
  6789. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  6790. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6791. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  6792. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6793. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  6794. /* Request a Core Reset
  6795. *
  6796. * Same as Global Reset, except does *not* include the MAC/PHY
  6797. */
  6798. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  6799. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6800. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  6801. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6802. i40e_flush(&pf->hw);
  6803. } else if (reset_flags & I40E_PF_RESET_FLAG) {
  6804. /* Request a PF Reset
  6805. *
  6806. * Resets only the PF-specific registers
  6807. *
  6808. * This goes directly to the tear-down and rebuild of
  6809. * the switch, since we need to do all the recovery as
  6810. * for the Core Reset.
  6811. */
  6812. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  6813. i40e_handle_reset_warning(pf, lock_acquired);
  6814. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  6815. int v;
  6816. /* Find the VSI(s) that requested a re-init */
  6817. dev_info(&pf->pdev->dev,
  6818. "VSI reinit requested\n");
  6819. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6820. struct i40e_vsi *vsi = pf->vsi[v];
  6821. if (vsi != NULL &&
  6822. test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
  6823. vsi->state))
  6824. i40e_vsi_reinit_locked(pf->vsi[v]);
  6825. }
  6826. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  6827. int v;
  6828. /* Find the VSI(s) that needs to be brought down */
  6829. dev_info(&pf->pdev->dev, "VSI down requested\n");
  6830. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6831. struct i40e_vsi *vsi = pf->vsi[v];
  6832. if (vsi != NULL &&
  6833. test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
  6834. vsi->state)) {
  6835. set_bit(__I40E_VSI_DOWN, vsi->state);
  6836. i40e_down(vsi);
  6837. }
  6838. }
  6839. } else {
  6840. dev_info(&pf->pdev->dev,
  6841. "bad reset request 0x%08x\n", reset_flags);
  6842. }
  6843. }
  6844. #ifdef CONFIG_I40E_DCB
  6845. /**
  6846. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  6847. * @pf: board private structure
  6848. * @old_cfg: current DCB config
  6849. * @new_cfg: new DCB config
  6850. **/
  6851. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  6852. struct i40e_dcbx_config *old_cfg,
  6853. struct i40e_dcbx_config *new_cfg)
  6854. {
  6855. bool need_reconfig = false;
  6856. /* Check if ETS configuration has changed */
  6857. if (memcmp(&new_cfg->etscfg,
  6858. &old_cfg->etscfg,
  6859. sizeof(new_cfg->etscfg))) {
  6860. /* If Priority Table has changed reconfig is needed */
  6861. if (memcmp(&new_cfg->etscfg.prioritytable,
  6862. &old_cfg->etscfg.prioritytable,
  6863. sizeof(new_cfg->etscfg.prioritytable))) {
  6864. need_reconfig = true;
  6865. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  6866. }
  6867. if (memcmp(&new_cfg->etscfg.tcbwtable,
  6868. &old_cfg->etscfg.tcbwtable,
  6869. sizeof(new_cfg->etscfg.tcbwtable)))
  6870. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  6871. if (memcmp(&new_cfg->etscfg.tsatable,
  6872. &old_cfg->etscfg.tsatable,
  6873. sizeof(new_cfg->etscfg.tsatable)))
  6874. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  6875. }
  6876. /* Check if PFC configuration has changed */
  6877. if (memcmp(&new_cfg->pfc,
  6878. &old_cfg->pfc,
  6879. sizeof(new_cfg->pfc))) {
  6880. need_reconfig = true;
  6881. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  6882. }
  6883. /* Check if APP Table has changed */
  6884. if (memcmp(&new_cfg->app,
  6885. &old_cfg->app,
  6886. sizeof(new_cfg->app))) {
  6887. need_reconfig = true;
  6888. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  6889. }
  6890. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  6891. return need_reconfig;
  6892. }
  6893. /**
  6894. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  6895. * @pf: board private structure
  6896. * @e: event info posted on ARQ
  6897. **/
  6898. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  6899. struct i40e_arq_event_info *e)
  6900. {
  6901. struct i40e_aqc_lldp_get_mib *mib =
  6902. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  6903. struct i40e_hw *hw = &pf->hw;
  6904. struct i40e_dcbx_config tmp_dcbx_cfg;
  6905. bool need_reconfig = false;
  6906. int ret = 0;
  6907. u8 type;
  6908. /* Not DCB capable or capability disabled */
  6909. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  6910. return ret;
  6911. /* Ignore if event is not for Nearest Bridge */
  6912. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  6913. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  6914. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  6915. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  6916. return ret;
  6917. /* Check MIB Type and return if event for Remote MIB update */
  6918. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  6919. dev_dbg(&pf->pdev->dev,
  6920. "LLDP event mib type %s\n", type ? "remote" : "local");
  6921. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  6922. /* Update the remote cached instance and return */
  6923. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  6924. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  6925. &hw->remote_dcbx_config);
  6926. goto exit;
  6927. }
  6928. /* Store the old configuration */
  6929. tmp_dcbx_cfg = hw->local_dcbx_config;
  6930. /* Reset the old DCBx configuration data */
  6931. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  6932. /* Get updated DCBX data from firmware */
  6933. ret = i40e_get_dcb_config(&pf->hw);
  6934. if (ret) {
  6935. dev_info(&pf->pdev->dev,
  6936. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  6937. i40e_stat_str(&pf->hw, ret),
  6938. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6939. goto exit;
  6940. }
  6941. /* No change detected in DCBX configs */
  6942. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  6943. sizeof(tmp_dcbx_cfg))) {
  6944. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  6945. goto exit;
  6946. }
  6947. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  6948. &hw->local_dcbx_config);
  6949. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  6950. if (!need_reconfig)
  6951. goto exit;
  6952. /* Enable DCB tagging only when more than one TC */
  6953. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  6954. pf->flags |= I40E_FLAG_DCB_ENABLED;
  6955. else
  6956. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6957. set_bit(__I40E_PORT_SUSPENDED, pf->state);
  6958. /* Reconfiguration needed quiesce all VSIs */
  6959. i40e_pf_quiesce_all_vsi(pf);
  6960. /* Changes in configuration update VEB/VSI */
  6961. i40e_dcb_reconfigure(pf);
  6962. ret = i40e_resume_port_tx(pf);
  6963. clear_bit(__I40E_PORT_SUSPENDED, pf->state);
  6964. /* In case of error no point in resuming VSIs */
  6965. if (ret)
  6966. goto exit;
  6967. /* Wait for the PF's queues to be disabled */
  6968. ret = i40e_pf_wait_queues_disabled(pf);
  6969. if (ret) {
  6970. /* Schedule PF reset to recover */
  6971. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  6972. i40e_service_event_schedule(pf);
  6973. } else {
  6974. i40e_pf_unquiesce_all_vsi(pf);
  6975. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  6976. I40E_FLAG_CLIENT_L2_CHANGE);
  6977. }
  6978. exit:
  6979. return ret;
  6980. }
  6981. #endif /* CONFIG_I40E_DCB */
  6982. /**
  6983. * i40e_do_reset_safe - Protected reset path for userland calls.
  6984. * @pf: board private structure
  6985. * @reset_flags: which reset is requested
  6986. *
  6987. **/
  6988. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  6989. {
  6990. rtnl_lock();
  6991. i40e_do_reset(pf, reset_flags, true);
  6992. rtnl_unlock();
  6993. }
  6994. /**
  6995. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  6996. * @pf: board private structure
  6997. * @e: event info posted on ARQ
  6998. *
  6999. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  7000. * and VF queues
  7001. **/
  7002. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  7003. struct i40e_arq_event_info *e)
  7004. {
  7005. struct i40e_aqc_lan_overflow *data =
  7006. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  7007. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  7008. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  7009. struct i40e_hw *hw = &pf->hw;
  7010. struct i40e_vf *vf;
  7011. u16 vf_id;
  7012. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  7013. queue, qtx_ctl);
  7014. /* Queue belongs to VF, find the VF and issue VF reset */
  7015. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  7016. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  7017. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  7018. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  7019. vf_id -= hw->func_caps.vf_base_id;
  7020. vf = &pf->vf[vf_id];
  7021. i40e_vc_notify_vf_reset(vf);
  7022. /* Allow VF to process pending reset notification */
  7023. msleep(20);
  7024. i40e_reset_vf(vf, false);
  7025. }
  7026. }
  7027. /**
  7028. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  7029. * @pf: board private structure
  7030. **/
  7031. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  7032. {
  7033. u32 val, fcnt_prog;
  7034. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7035. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  7036. return fcnt_prog;
  7037. }
  7038. /**
  7039. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  7040. * @pf: board private structure
  7041. **/
  7042. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  7043. {
  7044. u32 val, fcnt_prog;
  7045. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7046. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  7047. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  7048. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  7049. return fcnt_prog;
  7050. }
  7051. /**
  7052. * i40e_get_global_fd_count - Get total FD filters programmed on device
  7053. * @pf: board private structure
  7054. **/
  7055. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  7056. {
  7057. u32 val, fcnt_prog;
  7058. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  7059. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  7060. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  7061. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  7062. return fcnt_prog;
  7063. }
  7064. /**
  7065. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  7066. * @pf: board private structure
  7067. **/
  7068. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  7069. {
  7070. struct i40e_fdir_filter *filter;
  7071. u32 fcnt_prog, fcnt_avail;
  7072. struct hlist_node *node;
  7073. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7074. return;
  7075. /* Check if we have enough room to re-enable FDir SB capability. */
  7076. fcnt_prog = i40e_get_global_fd_count(pf);
  7077. fcnt_avail = pf->fdir_pf_filter_count;
  7078. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  7079. (pf->fd_add_err == 0) ||
  7080. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  7081. if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED) {
  7082. pf->flags &= ~I40E_FLAG_FD_SB_AUTO_DISABLED;
  7083. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7084. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7085. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  7086. }
  7087. }
  7088. /* We should wait for even more space before re-enabling ATR.
  7089. * Additionally, we cannot enable ATR as long as we still have TCP SB
  7090. * rules active.
  7091. */
  7092. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
  7093. (pf->fd_tcp4_filter_cnt == 0)) {
  7094. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  7095. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7096. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7097. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7098. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  7099. }
  7100. }
  7101. /* if hw had a problem adding a filter, delete it */
  7102. if (pf->fd_inv > 0) {
  7103. hlist_for_each_entry_safe(filter, node,
  7104. &pf->fdir_filter_list, fdir_node) {
  7105. if (filter->fd_id == pf->fd_inv) {
  7106. hlist_del(&filter->fdir_node);
  7107. kfree(filter);
  7108. pf->fdir_pf_active_filters--;
  7109. pf->fd_inv = 0;
  7110. }
  7111. }
  7112. }
  7113. }
  7114. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  7115. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  7116. /**
  7117. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  7118. * @pf: board private structure
  7119. **/
  7120. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  7121. {
  7122. unsigned long min_flush_time;
  7123. int flush_wait_retry = 50;
  7124. bool disable_atr = false;
  7125. int fd_room;
  7126. int reg;
  7127. if (!time_after(jiffies, pf->fd_flush_timestamp +
  7128. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  7129. return;
  7130. /* If the flush is happening too quick and we have mostly SB rules we
  7131. * should not re-enable ATR for some time.
  7132. */
  7133. min_flush_time = pf->fd_flush_timestamp +
  7134. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  7135. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  7136. if (!(time_after(jiffies, min_flush_time)) &&
  7137. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  7138. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7139. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  7140. disable_atr = true;
  7141. }
  7142. pf->fd_flush_timestamp = jiffies;
  7143. pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7144. /* flush all filters */
  7145. wr32(&pf->hw, I40E_PFQF_CTL_1,
  7146. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  7147. i40e_flush(&pf->hw);
  7148. pf->fd_flush_cnt++;
  7149. pf->fd_add_err = 0;
  7150. do {
  7151. /* Check FD flush status every 5-6msec */
  7152. usleep_range(5000, 6000);
  7153. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  7154. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  7155. break;
  7156. } while (flush_wait_retry--);
  7157. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  7158. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  7159. } else {
  7160. /* replay sideband filters */
  7161. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  7162. if (!disable_atr && !pf->fd_tcp4_filter_cnt)
  7163. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  7164. clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  7165. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7166. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  7167. }
  7168. }
  7169. /**
  7170. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  7171. * @pf: board private structure
  7172. **/
  7173. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  7174. {
  7175. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  7176. }
  7177. /* We can see up to 256 filter programming desc in transit if the filters are
  7178. * being applied really fast; before we see the first
  7179. * filter miss error on Rx queue 0. Accumulating enough error messages before
  7180. * reacting will make sure we don't cause flush too often.
  7181. */
  7182. #define I40E_MAX_FD_PROGRAM_ERROR 256
  7183. /**
  7184. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  7185. * @pf: board private structure
  7186. **/
  7187. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  7188. {
  7189. /* if interface is down do nothing */
  7190. if (test_bit(__I40E_DOWN, pf->state))
  7191. return;
  7192. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7193. i40e_fdir_flush_and_replay(pf);
  7194. i40e_fdir_check_and_reenable(pf);
  7195. }
  7196. /**
  7197. * i40e_vsi_link_event - notify VSI of a link event
  7198. * @vsi: vsi to be notified
  7199. * @link_up: link up or down
  7200. **/
  7201. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  7202. {
  7203. if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
  7204. return;
  7205. switch (vsi->type) {
  7206. case I40E_VSI_MAIN:
  7207. if (!vsi->netdev || !vsi->netdev_registered)
  7208. break;
  7209. if (link_up) {
  7210. netif_carrier_on(vsi->netdev);
  7211. netif_tx_wake_all_queues(vsi->netdev);
  7212. } else {
  7213. netif_carrier_off(vsi->netdev);
  7214. netif_tx_stop_all_queues(vsi->netdev);
  7215. }
  7216. break;
  7217. case I40E_VSI_SRIOV:
  7218. case I40E_VSI_VMDQ2:
  7219. case I40E_VSI_CTRL:
  7220. case I40E_VSI_IWARP:
  7221. case I40E_VSI_MIRROR:
  7222. default:
  7223. /* there is no notification for other VSIs */
  7224. break;
  7225. }
  7226. }
  7227. /**
  7228. * i40e_veb_link_event - notify elements on the veb of a link event
  7229. * @veb: veb to be notified
  7230. * @link_up: link up or down
  7231. **/
  7232. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  7233. {
  7234. struct i40e_pf *pf;
  7235. int i;
  7236. if (!veb || !veb->pf)
  7237. return;
  7238. pf = veb->pf;
  7239. /* depth first... */
  7240. for (i = 0; i < I40E_MAX_VEB; i++)
  7241. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  7242. i40e_veb_link_event(pf->veb[i], link_up);
  7243. /* ... now the local VSIs */
  7244. for (i = 0; i < pf->num_alloc_vsi; i++)
  7245. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  7246. i40e_vsi_link_event(pf->vsi[i], link_up);
  7247. }
  7248. /**
  7249. * i40e_link_event - Update netif_carrier status
  7250. * @pf: board private structure
  7251. **/
  7252. static void i40e_link_event(struct i40e_pf *pf)
  7253. {
  7254. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7255. u8 new_link_speed, old_link_speed;
  7256. i40e_status status;
  7257. bool new_link, old_link;
  7258. /* save off old link status information */
  7259. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  7260. /* set this to force the get_link_status call to refresh state */
  7261. pf->hw.phy.get_link_info = true;
  7262. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  7263. status = i40e_get_link_status(&pf->hw, &new_link);
  7264. /* On success, disable temp link polling */
  7265. if (status == I40E_SUCCESS) {
  7266. if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
  7267. pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
  7268. } else {
  7269. /* Enable link polling temporarily until i40e_get_link_status
  7270. * returns I40E_SUCCESS
  7271. */
  7272. pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
  7273. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  7274. status);
  7275. return;
  7276. }
  7277. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  7278. new_link_speed = pf->hw.phy.link_info.link_speed;
  7279. if (new_link == old_link &&
  7280. new_link_speed == old_link_speed &&
  7281. (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  7282. new_link == netif_carrier_ok(vsi->netdev)))
  7283. return;
  7284. i40e_print_link_message(vsi, new_link);
  7285. /* Notify the base of the switch tree connected to
  7286. * the link. Floating VEBs are not notified.
  7287. */
  7288. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7289. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  7290. else
  7291. i40e_vsi_link_event(vsi, new_link);
  7292. if (pf->vf)
  7293. i40e_vc_notify_link_state(pf);
  7294. if (pf->flags & I40E_FLAG_PTP)
  7295. i40e_ptp_set_increment(pf);
  7296. }
  7297. /**
  7298. * i40e_watchdog_subtask - periodic checks not using event driven response
  7299. * @pf: board private structure
  7300. **/
  7301. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  7302. {
  7303. int i;
  7304. /* if interface is down do nothing */
  7305. if (test_bit(__I40E_DOWN, pf->state) ||
  7306. test_bit(__I40E_CONFIG_BUSY, pf->state))
  7307. return;
  7308. /* make sure we don't do these things too often */
  7309. if (time_before(jiffies, (pf->service_timer_previous +
  7310. pf->service_timer_period)))
  7311. return;
  7312. pf->service_timer_previous = jiffies;
  7313. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  7314. (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
  7315. i40e_link_event(pf);
  7316. /* Update the stats for active netdevs so the network stack
  7317. * can look at updated numbers whenever it cares to
  7318. */
  7319. for (i = 0; i < pf->num_alloc_vsi; i++)
  7320. if (pf->vsi[i] && pf->vsi[i]->netdev)
  7321. i40e_update_stats(pf->vsi[i]);
  7322. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  7323. /* Update the stats for the active switching components */
  7324. for (i = 0; i < I40E_MAX_VEB; i++)
  7325. if (pf->veb[i])
  7326. i40e_update_veb_stats(pf->veb[i]);
  7327. }
  7328. i40e_ptp_rx_hang(pf);
  7329. i40e_ptp_tx_hang(pf);
  7330. }
  7331. /**
  7332. * i40e_reset_subtask - Set up for resetting the device and driver
  7333. * @pf: board private structure
  7334. **/
  7335. static void i40e_reset_subtask(struct i40e_pf *pf)
  7336. {
  7337. u32 reset_flags = 0;
  7338. if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
  7339. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  7340. clear_bit(__I40E_REINIT_REQUESTED, pf->state);
  7341. }
  7342. if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
  7343. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  7344. clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7345. }
  7346. if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
  7347. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  7348. clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  7349. }
  7350. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
  7351. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  7352. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  7353. }
  7354. if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
  7355. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  7356. clear_bit(__I40E_DOWN_REQUESTED, pf->state);
  7357. }
  7358. /* If there's a recovery already waiting, it takes
  7359. * precedence before starting a new reset sequence.
  7360. */
  7361. if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
  7362. i40e_prep_for_reset(pf, false);
  7363. i40e_reset(pf);
  7364. i40e_rebuild(pf, false, false);
  7365. }
  7366. /* If we're already down or resetting, just bail */
  7367. if (reset_flags &&
  7368. !test_bit(__I40E_DOWN, pf->state) &&
  7369. !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
  7370. i40e_do_reset(pf, reset_flags, false);
  7371. }
  7372. }
  7373. /**
  7374. * i40e_handle_link_event - Handle link event
  7375. * @pf: board private structure
  7376. * @e: event info posted on ARQ
  7377. **/
  7378. static void i40e_handle_link_event(struct i40e_pf *pf,
  7379. struct i40e_arq_event_info *e)
  7380. {
  7381. struct i40e_aqc_get_link_status *status =
  7382. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  7383. /* Do a new status request to re-enable LSE reporting
  7384. * and load new status information into the hw struct
  7385. * This completely ignores any state information
  7386. * in the ARQ event info, instead choosing to always
  7387. * issue the AQ update link status command.
  7388. */
  7389. i40e_link_event(pf);
  7390. /* Check if module meets thermal requirements */
  7391. if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
  7392. dev_err(&pf->pdev->dev,
  7393. "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
  7394. dev_err(&pf->pdev->dev,
  7395. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7396. } else {
  7397. /* check for unqualified module, if link is down, suppress
  7398. * the message if link was forced to be down.
  7399. */
  7400. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  7401. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  7402. (!(status->link_info & I40E_AQ_LINK_UP)) &&
  7403. (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
  7404. dev_err(&pf->pdev->dev,
  7405. "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
  7406. dev_err(&pf->pdev->dev,
  7407. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7408. }
  7409. }
  7410. }
  7411. /**
  7412. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  7413. * @pf: board private structure
  7414. **/
  7415. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  7416. {
  7417. struct i40e_arq_event_info event;
  7418. struct i40e_hw *hw = &pf->hw;
  7419. u16 pending, i = 0;
  7420. i40e_status ret;
  7421. u16 opcode;
  7422. u32 oldval;
  7423. u32 val;
  7424. /* Do not run clean AQ when PF reset fails */
  7425. if (test_bit(__I40E_RESET_FAILED, pf->state))
  7426. return;
  7427. /* check for error indications */
  7428. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  7429. oldval = val;
  7430. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  7431. if (hw->debug_mask & I40E_DEBUG_AQ)
  7432. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  7433. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  7434. }
  7435. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  7436. if (hw->debug_mask & I40E_DEBUG_AQ)
  7437. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  7438. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  7439. pf->arq_overflows++;
  7440. }
  7441. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  7442. if (hw->debug_mask & I40E_DEBUG_AQ)
  7443. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  7444. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  7445. }
  7446. if (oldval != val)
  7447. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  7448. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  7449. oldval = val;
  7450. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  7451. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7452. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  7453. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  7454. }
  7455. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  7456. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7457. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  7458. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  7459. }
  7460. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  7461. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7462. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  7463. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  7464. }
  7465. if (oldval != val)
  7466. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  7467. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  7468. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  7469. if (!event.msg_buf)
  7470. return;
  7471. do {
  7472. ret = i40e_clean_arq_element(hw, &event, &pending);
  7473. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  7474. break;
  7475. else if (ret) {
  7476. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  7477. break;
  7478. }
  7479. opcode = le16_to_cpu(event.desc.opcode);
  7480. switch (opcode) {
  7481. case i40e_aqc_opc_get_link_status:
  7482. i40e_handle_link_event(pf, &event);
  7483. break;
  7484. case i40e_aqc_opc_send_msg_to_pf:
  7485. ret = i40e_vc_process_vf_msg(pf,
  7486. le16_to_cpu(event.desc.retval),
  7487. le32_to_cpu(event.desc.cookie_high),
  7488. le32_to_cpu(event.desc.cookie_low),
  7489. event.msg_buf,
  7490. event.msg_len);
  7491. break;
  7492. case i40e_aqc_opc_lldp_update_mib:
  7493. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  7494. #ifdef CONFIG_I40E_DCB
  7495. rtnl_lock();
  7496. ret = i40e_handle_lldp_event(pf, &event);
  7497. rtnl_unlock();
  7498. #endif /* CONFIG_I40E_DCB */
  7499. break;
  7500. case i40e_aqc_opc_event_lan_overflow:
  7501. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  7502. i40e_handle_lan_overflow_event(pf, &event);
  7503. break;
  7504. case i40e_aqc_opc_send_msg_to_peer:
  7505. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  7506. break;
  7507. case i40e_aqc_opc_nvm_erase:
  7508. case i40e_aqc_opc_nvm_update:
  7509. case i40e_aqc_opc_oem_post_update:
  7510. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  7511. "ARQ NVM operation 0x%04x completed\n",
  7512. opcode);
  7513. break;
  7514. default:
  7515. dev_info(&pf->pdev->dev,
  7516. "ARQ: Unknown event 0x%04x ignored\n",
  7517. opcode);
  7518. break;
  7519. }
  7520. } while (i++ < pf->adminq_work_limit);
  7521. if (i < pf->adminq_work_limit)
  7522. clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  7523. /* re-enable Admin queue interrupt cause */
  7524. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  7525. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  7526. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  7527. i40e_flush(hw);
  7528. kfree(event.msg_buf);
  7529. }
  7530. /**
  7531. * i40e_verify_eeprom - make sure eeprom is good to use
  7532. * @pf: board private structure
  7533. **/
  7534. static void i40e_verify_eeprom(struct i40e_pf *pf)
  7535. {
  7536. int err;
  7537. err = i40e_diag_eeprom_test(&pf->hw);
  7538. if (err) {
  7539. /* retry in case of garbage read */
  7540. err = i40e_diag_eeprom_test(&pf->hw);
  7541. if (err) {
  7542. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  7543. err);
  7544. set_bit(__I40E_BAD_EEPROM, pf->state);
  7545. }
  7546. }
  7547. if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
  7548. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  7549. clear_bit(__I40E_BAD_EEPROM, pf->state);
  7550. }
  7551. }
  7552. /**
  7553. * i40e_enable_pf_switch_lb
  7554. * @pf: pointer to the PF structure
  7555. *
  7556. * enable switch loop back or die - no point in a return value
  7557. **/
  7558. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  7559. {
  7560. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7561. struct i40e_vsi_context ctxt;
  7562. int ret;
  7563. ctxt.seid = pf->main_vsi_seid;
  7564. ctxt.pf_num = pf->hw.pf_id;
  7565. ctxt.vf_num = 0;
  7566. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7567. if (ret) {
  7568. dev_info(&pf->pdev->dev,
  7569. "couldn't get PF vsi config, err %s aq_err %s\n",
  7570. i40e_stat_str(&pf->hw, ret),
  7571. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7572. return;
  7573. }
  7574. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7575. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7576. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7577. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7578. if (ret) {
  7579. dev_info(&pf->pdev->dev,
  7580. "update vsi switch failed, err %s aq_err %s\n",
  7581. i40e_stat_str(&pf->hw, ret),
  7582. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7583. }
  7584. }
  7585. /**
  7586. * i40e_disable_pf_switch_lb
  7587. * @pf: pointer to the PF structure
  7588. *
  7589. * disable switch loop back or die - no point in a return value
  7590. **/
  7591. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  7592. {
  7593. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7594. struct i40e_vsi_context ctxt;
  7595. int ret;
  7596. ctxt.seid = pf->main_vsi_seid;
  7597. ctxt.pf_num = pf->hw.pf_id;
  7598. ctxt.vf_num = 0;
  7599. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7600. if (ret) {
  7601. dev_info(&pf->pdev->dev,
  7602. "couldn't get PF vsi config, err %s aq_err %s\n",
  7603. i40e_stat_str(&pf->hw, ret),
  7604. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7605. return;
  7606. }
  7607. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7608. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7609. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7610. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7611. if (ret) {
  7612. dev_info(&pf->pdev->dev,
  7613. "update vsi switch failed, err %s aq_err %s\n",
  7614. i40e_stat_str(&pf->hw, ret),
  7615. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7616. }
  7617. }
  7618. /**
  7619. * i40e_config_bridge_mode - Configure the HW bridge mode
  7620. * @veb: pointer to the bridge instance
  7621. *
  7622. * Configure the loop back mode for the LAN VSI that is downlink to the
  7623. * specified HW bridge instance. It is expected this function is called
  7624. * when a new HW bridge is instantiated.
  7625. **/
  7626. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  7627. {
  7628. struct i40e_pf *pf = veb->pf;
  7629. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  7630. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  7631. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7632. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  7633. i40e_disable_pf_switch_lb(pf);
  7634. else
  7635. i40e_enable_pf_switch_lb(pf);
  7636. }
  7637. /**
  7638. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  7639. * @veb: pointer to the VEB instance
  7640. *
  7641. * This is a recursive function that first builds the attached VSIs then
  7642. * recurses in to build the next layer of VEB. We track the connections
  7643. * through our own index numbers because the seid's from the HW could
  7644. * change across the reset.
  7645. **/
  7646. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  7647. {
  7648. struct i40e_vsi *ctl_vsi = NULL;
  7649. struct i40e_pf *pf = veb->pf;
  7650. int v, veb_idx;
  7651. int ret;
  7652. /* build VSI that owns this VEB, temporarily attached to base VEB */
  7653. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  7654. if (pf->vsi[v] &&
  7655. pf->vsi[v]->veb_idx == veb->idx &&
  7656. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  7657. ctl_vsi = pf->vsi[v];
  7658. break;
  7659. }
  7660. }
  7661. if (!ctl_vsi) {
  7662. dev_info(&pf->pdev->dev,
  7663. "missing owner VSI for veb_idx %d\n", veb->idx);
  7664. ret = -ENOENT;
  7665. goto end_reconstitute;
  7666. }
  7667. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  7668. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7669. ret = i40e_add_vsi(ctl_vsi);
  7670. if (ret) {
  7671. dev_info(&pf->pdev->dev,
  7672. "rebuild of veb_idx %d owner VSI failed: %d\n",
  7673. veb->idx, ret);
  7674. goto end_reconstitute;
  7675. }
  7676. i40e_vsi_reset_stats(ctl_vsi);
  7677. /* create the VEB in the switch and move the VSI onto the VEB */
  7678. ret = i40e_add_veb(veb, ctl_vsi);
  7679. if (ret)
  7680. goto end_reconstitute;
  7681. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  7682. veb->bridge_mode = BRIDGE_MODE_VEB;
  7683. else
  7684. veb->bridge_mode = BRIDGE_MODE_VEPA;
  7685. i40e_config_bridge_mode(veb);
  7686. /* create the remaining VSIs attached to this VEB */
  7687. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7688. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  7689. continue;
  7690. if (pf->vsi[v]->veb_idx == veb->idx) {
  7691. struct i40e_vsi *vsi = pf->vsi[v];
  7692. vsi->uplink_seid = veb->seid;
  7693. ret = i40e_add_vsi(vsi);
  7694. if (ret) {
  7695. dev_info(&pf->pdev->dev,
  7696. "rebuild of vsi_idx %d failed: %d\n",
  7697. v, ret);
  7698. goto end_reconstitute;
  7699. }
  7700. i40e_vsi_reset_stats(vsi);
  7701. }
  7702. }
  7703. /* create any VEBs attached to this VEB - RECURSION */
  7704. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7705. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  7706. pf->veb[veb_idx]->uplink_seid = veb->seid;
  7707. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  7708. if (ret)
  7709. break;
  7710. }
  7711. }
  7712. end_reconstitute:
  7713. return ret;
  7714. }
  7715. /**
  7716. * i40e_get_capabilities - get info about the HW
  7717. * @pf: the PF struct
  7718. **/
  7719. static int i40e_get_capabilities(struct i40e_pf *pf,
  7720. enum i40e_admin_queue_opc list_type)
  7721. {
  7722. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  7723. u16 data_size;
  7724. int buf_len;
  7725. int err;
  7726. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  7727. do {
  7728. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  7729. if (!cap_buf)
  7730. return -ENOMEM;
  7731. /* this loads the data into the hw struct for us */
  7732. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  7733. &data_size, list_type,
  7734. NULL);
  7735. /* data loaded, buffer no longer needed */
  7736. kfree(cap_buf);
  7737. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  7738. /* retry with a larger buffer */
  7739. buf_len = data_size;
  7740. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  7741. dev_info(&pf->pdev->dev,
  7742. "capability discovery failed, err %s aq_err %s\n",
  7743. i40e_stat_str(&pf->hw, err),
  7744. i40e_aq_str(&pf->hw,
  7745. pf->hw.aq.asq_last_status));
  7746. return -ENODEV;
  7747. }
  7748. } while (err);
  7749. if (pf->hw.debug_mask & I40E_DEBUG_USER) {
  7750. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7751. dev_info(&pf->pdev->dev,
  7752. "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n",
  7753. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  7754. pf->hw.func_caps.num_msix_vectors,
  7755. pf->hw.func_caps.num_msix_vectors_vf,
  7756. pf->hw.func_caps.fd_filters_guaranteed,
  7757. pf->hw.func_caps.fd_filters_best_effort,
  7758. pf->hw.func_caps.num_tx_qp,
  7759. pf->hw.func_caps.num_vsis);
  7760. } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
  7761. dev_info(&pf->pdev->dev,
  7762. "switch_mode=0x%04x, function_valid=0x%08x\n",
  7763. pf->hw.dev_caps.switch_mode,
  7764. pf->hw.dev_caps.valid_functions);
  7765. dev_info(&pf->pdev->dev,
  7766. "SR-IOV=%d, num_vfs for all function=%u\n",
  7767. pf->hw.dev_caps.sr_iov_1_1,
  7768. pf->hw.dev_caps.num_vfs);
  7769. dev_info(&pf->pdev->dev,
  7770. "num_vsis=%u, num_rx:%u, num_tx=%u\n",
  7771. pf->hw.dev_caps.num_vsis,
  7772. pf->hw.dev_caps.num_rx_qp,
  7773. pf->hw.dev_caps.num_tx_qp);
  7774. }
  7775. }
  7776. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7777. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  7778. + pf->hw.func_caps.num_vfs)
  7779. if (pf->hw.revision_id == 0 &&
  7780. pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
  7781. dev_info(&pf->pdev->dev,
  7782. "got num_vsis %d, setting num_vsis to %d\n",
  7783. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  7784. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  7785. }
  7786. }
  7787. return 0;
  7788. }
  7789. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  7790. /**
  7791. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  7792. * @pf: board private structure
  7793. **/
  7794. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  7795. {
  7796. struct i40e_vsi *vsi;
  7797. /* quick workaround for an NVM issue that leaves a critical register
  7798. * uninitialized
  7799. */
  7800. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  7801. static const u32 hkey[] = {
  7802. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  7803. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  7804. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  7805. 0x95b3a76d};
  7806. int i;
  7807. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  7808. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  7809. }
  7810. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7811. return;
  7812. /* find existing VSI and see if it needs configuring */
  7813. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7814. /* create a new VSI if none exists */
  7815. if (!vsi) {
  7816. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  7817. pf->vsi[pf->lan_vsi]->seid, 0);
  7818. if (!vsi) {
  7819. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  7820. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7821. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  7822. return;
  7823. }
  7824. }
  7825. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  7826. }
  7827. /**
  7828. * i40e_fdir_teardown - release the Flow Director resources
  7829. * @pf: board private structure
  7830. **/
  7831. static void i40e_fdir_teardown(struct i40e_pf *pf)
  7832. {
  7833. struct i40e_vsi *vsi;
  7834. i40e_fdir_filter_exit(pf);
  7835. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7836. if (vsi)
  7837. i40e_vsi_release(vsi);
  7838. }
  7839. /**
  7840. * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
  7841. * @vsi: PF main vsi
  7842. * @seid: seid of main or channel VSIs
  7843. *
  7844. * Rebuilds cloud filters associated with main VSI and channel VSIs if they
  7845. * existed before reset
  7846. **/
  7847. static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
  7848. {
  7849. struct i40e_cloud_filter *cfilter;
  7850. struct i40e_pf *pf = vsi->back;
  7851. struct hlist_node *node;
  7852. i40e_status ret;
  7853. /* Add cloud filters back if they exist */
  7854. hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
  7855. cloud_node) {
  7856. if (cfilter->seid != seid)
  7857. continue;
  7858. if (cfilter->dst_port)
  7859. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  7860. true);
  7861. else
  7862. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  7863. if (ret) {
  7864. dev_dbg(&pf->pdev->dev,
  7865. "Failed to rebuild cloud filter, err %s aq_err %s\n",
  7866. i40e_stat_str(&pf->hw, ret),
  7867. i40e_aq_str(&pf->hw,
  7868. pf->hw.aq.asq_last_status));
  7869. return ret;
  7870. }
  7871. }
  7872. return 0;
  7873. }
  7874. /**
  7875. * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
  7876. * @vsi: PF main vsi
  7877. *
  7878. * Rebuilds channel VSIs if they existed before reset
  7879. **/
  7880. static int i40e_rebuild_channels(struct i40e_vsi *vsi)
  7881. {
  7882. struct i40e_channel *ch, *ch_tmp;
  7883. i40e_status ret;
  7884. if (list_empty(&vsi->ch_list))
  7885. return 0;
  7886. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  7887. if (!ch->initialized)
  7888. break;
  7889. /* Proceed with creation of channel (VMDq2) VSI */
  7890. ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
  7891. if (ret) {
  7892. dev_info(&vsi->back->pdev->dev,
  7893. "failed to rebuild channels using uplink_seid %u\n",
  7894. vsi->uplink_seid);
  7895. return ret;
  7896. }
  7897. /* Reconfigure TX queues using QTX_CTL register */
  7898. ret = i40e_channel_config_tx_ring(vsi->back, vsi, ch);
  7899. if (ret) {
  7900. dev_info(&vsi->back->pdev->dev,
  7901. "failed to configure TX rings for channel %u\n",
  7902. ch->seid);
  7903. return ret;
  7904. }
  7905. /* update 'next_base_queue' */
  7906. vsi->next_base_queue = vsi->next_base_queue +
  7907. ch->num_queue_pairs;
  7908. if (ch->max_tx_rate) {
  7909. u64 credits = ch->max_tx_rate;
  7910. if (i40e_set_bw_limit(vsi, ch->seid,
  7911. ch->max_tx_rate))
  7912. return -EINVAL;
  7913. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  7914. dev_dbg(&vsi->back->pdev->dev,
  7915. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  7916. ch->max_tx_rate,
  7917. credits,
  7918. ch->seid);
  7919. }
  7920. ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
  7921. if (ret) {
  7922. dev_dbg(&vsi->back->pdev->dev,
  7923. "Failed to rebuild cloud filters for channel VSI %u\n",
  7924. ch->seid);
  7925. return ret;
  7926. }
  7927. }
  7928. return 0;
  7929. }
  7930. /**
  7931. * i40e_prep_for_reset - prep for the core to reset
  7932. * @pf: board private structure
  7933. * @lock_acquired: indicates whether or not the lock has been acquired
  7934. * before this function was called.
  7935. *
  7936. * Close up the VFs and other things in prep for PF Reset.
  7937. **/
  7938. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
  7939. {
  7940. struct i40e_hw *hw = &pf->hw;
  7941. i40e_status ret = 0;
  7942. u32 v;
  7943. clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  7944. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  7945. return;
  7946. if (i40e_check_asq_alive(&pf->hw))
  7947. i40e_vc_notify_reset(pf);
  7948. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  7949. /* quiesce the VSIs and their queues that are not already DOWN */
  7950. /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
  7951. if (!lock_acquired)
  7952. rtnl_lock();
  7953. i40e_pf_quiesce_all_vsi(pf);
  7954. if (!lock_acquired)
  7955. rtnl_unlock();
  7956. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7957. if (pf->vsi[v])
  7958. pf->vsi[v]->seid = 0;
  7959. }
  7960. i40e_shutdown_adminq(&pf->hw);
  7961. /* call shutdown HMC */
  7962. if (hw->hmc.hmc_obj) {
  7963. ret = i40e_shutdown_lan_hmc(hw);
  7964. if (ret)
  7965. dev_warn(&pf->pdev->dev,
  7966. "shutdown_lan_hmc failed: %d\n", ret);
  7967. }
  7968. }
  7969. /**
  7970. * i40e_send_version - update firmware with driver version
  7971. * @pf: PF struct
  7972. */
  7973. static void i40e_send_version(struct i40e_pf *pf)
  7974. {
  7975. struct i40e_driver_version dv;
  7976. dv.major_version = DRV_VERSION_MAJOR;
  7977. dv.minor_version = DRV_VERSION_MINOR;
  7978. dv.build_version = DRV_VERSION_BUILD;
  7979. dv.subbuild_version = 0;
  7980. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  7981. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  7982. }
  7983. /**
  7984. * i40e_get_oem_version - get OEM specific version information
  7985. * @hw: pointer to the hardware structure
  7986. **/
  7987. static void i40e_get_oem_version(struct i40e_hw *hw)
  7988. {
  7989. u16 block_offset = 0xffff;
  7990. u16 block_length = 0;
  7991. u16 capabilities = 0;
  7992. u16 gen_snap = 0;
  7993. u16 release = 0;
  7994. #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
  7995. #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
  7996. #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
  7997. #define I40E_NVM_OEM_GEN_OFFSET 0x02
  7998. #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
  7999. #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
  8000. #define I40E_NVM_OEM_LENGTH 3
  8001. /* Check if pointer to OEM version block is valid. */
  8002. i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
  8003. if (block_offset == 0xffff)
  8004. return;
  8005. /* Check if OEM version block has correct length. */
  8006. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
  8007. &block_length);
  8008. if (block_length < I40E_NVM_OEM_LENGTH)
  8009. return;
  8010. /* Check if OEM version format is as expected. */
  8011. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
  8012. &capabilities);
  8013. if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
  8014. return;
  8015. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
  8016. &gen_snap);
  8017. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
  8018. &release);
  8019. hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
  8020. hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
  8021. }
  8022. /**
  8023. * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
  8024. * @pf: board private structure
  8025. **/
  8026. static int i40e_reset(struct i40e_pf *pf)
  8027. {
  8028. struct i40e_hw *hw = &pf->hw;
  8029. i40e_status ret;
  8030. ret = i40e_pf_reset(hw);
  8031. if (ret) {
  8032. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  8033. set_bit(__I40E_RESET_FAILED, pf->state);
  8034. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8035. } else {
  8036. pf->pfr_count++;
  8037. }
  8038. return ret;
  8039. }
  8040. /**
  8041. * i40e_rebuild - rebuild using a saved config
  8042. * @pf: board private structure
  8043. * @reinit: if the Main VSI needs to re-initialized.
  8044. * @lock_acquired: indicates whether or not the lock has been acquired
  8045. * before this function was called.
  8046. **/
  8047. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
  8048. {
  8049. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  8050. struct i40e_hw *hw = &pf->hw;
  8051. u8 set_fc_aq_fail = 0;
  8052. i40e_status ret;
  8053. u32 val;
  8054. int v;
  8055. if (test_bit(__I40E_DOWN, pf->state))
  8056. goto clear_recovery;
  8057. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  8058. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  8059. ret = i40e_init_adminq(&pf->hw);
  8060. if (ret) {
  8061. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  8062. i40e_stat_str(&pf->hw, ret),
  8063. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8064. goto clear_recovery;
  8065. }
  8066. i40e_get_oem_version(&pf->hw);
  8067. /* re-verify the eeprom if we just had an EMP reset */
  8068. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
  8069. i40e_verify_eeprom(pf);
  8070. i40e_clear_pxe_mode(hw);
  8071. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  8072. if (ret)
  8073. goto end_core_reset;
  8074. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  8075. hw->func_caps.num_rx_qp, 0, 0);
  8076. if (ret) {
  8077. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  8078. goto end_core_reset;
  8079. }
  8080. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  8081. if (ret) {
  8082. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  8083. goto end_core_reset;
  8084. }
  8085. /* Enable FW to write a default DCB config on link-up */
  8086. i40e_aq_set_dcb_parameters(hw, true, NULL);
  8087. #ifdef CONFIG_I40E_DCB
  8088. ret = i40e_init_pf_dcb(pf);
  8089. if (ret) {
  8090. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  8091. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  8092. /* Continue without DCB enabled */
  8093. }
  8094. #endif /* CONFIG_I40E_DCB */
  8095. /* do basic switch setup */
  8096. if (!lock_acquired)
  8097. rtnl_lock();
  8098. ret = i40e_setup_pf_switch(pf, reinit);
  8099. if (ret)
  8100. goto end_unlock;
  8101. /* The driver only wants link up/down and module qualification
  8102. * reports from firmware. Note the negative logic.
  8103. */
  8104. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  8105. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  8106. I40E_AQ_EVENT_MEDIA_NA |
  8107. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  8108. if (ret)
  8109. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  8110. i40e_stat_str(&pf->hw, ret),
  8111. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8112. /* make sure our flow control settings are restored */
  8113. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  8114. if (ret)
  8115. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  8116. i40e_stat_str(&pf->hw, ret),
  8117. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8118. /* Rebuild the VSIs and VEBs that existed before reset.
  8119. * They are still in our local switch element arrays, so only
  8120. * need to rebuild the switch model in the HW.
  8121. *
  8122. * If there were VEBs but the reconstitution failed, we'll try
  8123. * try to recover minimal use by getting the basic PF VSI working.
  8124. */
  8125. if (vsi->uplink_seid != pf->mac_seid) {
  8126. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  8127. /* find the one VEB connected to the MAC, and find orphans */
  8128. for (v = 0; v < I40E_MAX_VEB; v++) {
  8129. if (!pf->veb[v])
  8130. continue;
  8131. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  8132. pf->veb[v]->uplink_seid == 0) {
  8133. ret = i40e_reconstitute_veb(pf->veb[v]);
  8134. if (!ret)
  8135. continue;
  8136. /* If Main VEB failed, we're in deep doodoo,
  8137. * so give up rebuilding the switch and set up
  8138. * for minimal rebuild of PF VSI.
  8139. * If orphan failed, we'll report the error
  8140. * but try to keep going.
  8141. */
  8142. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  8143. dev_info(&pf->pdev->dev,
  8144. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  8145. ret);
  8146. vsi->uplink_seid = pf->mac_seid;
  8147. break;
  8148. } else if (pf->veb[v]->uplink_seid == 0) {
  8149. dev_info(&pf->pdev->dev,
  8150. "rebuild of orphan VEB failed: %d\n",
  8151. ret);
  8152. }
  8153. }
  8154. }
  8155. }
  8156. if (vsi->uplink_seid == pf->mac_seid) {
  8157. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  8158. /* no VEB, so rebuild only the Main VSI */
  8159. ret = i40e_add_vsi(vsi);
  8160. if (ret) {
  8161. dev_info(&pf->pdev->dev,
  8162. "rebuild of Main VSI failed: %d\n", ret);
  8163. goto end_unlock;
  8164. }
  8165. }
  8166. if (vsi->mqprio_qopt.max_rate[0]) {
  8167. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  8168. u64 credits = 0;
  8169. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  8170. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  8171. if (ret)
  8172. goto end_unlock;
  8173. credits = max_tx_rate;
  8174. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  8175. dev_dbg(&vsi->back->pdev->dev,
  8176. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  8177. max_tx_rate,
  8178. credits,
  8179. vsi->seid);
  8180. }
  8181. ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
  8182. if (ret)
  8183. goto end_unlock;
  8184. /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
  8185. * for this main VSI if they exist
  8186. */
  8187. ret = i40e_rebuild_channels(vsi);
  8188. if (ret)
  8189. goto end_unlock;
  8190. /* Reconfigure hardware for allowing smaller MSS in the case
  8191. * of TSO, so that we avoid the MDD being fired and causing
  8192. * a reset in the case of small MSS+TSO.
  8193. */
  8194. #define I40E_REG_MSS 0x000E64DC
  8195. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  8196. #define I40E_64BYTE_MSS 0x400000
  8197. val = rd32(hw, I40E_REG_MSS);
  8198. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  8199. val &= ~I40E_REG_MSS_MIN_MASK;
  8200. val |= I40E_64BYTE_MSS;
  8201. wr32(hw, I40E_REG_MSS, val);
  8202. }
  8203. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  8204. msleep(75);
  8205. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  8206. if (ret)
  8207. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  8208. i40e_stat_str(&pf->hw, ret),
  8209. i40e_aq_str(&pf->hw,
  8210. pf->hw.aq.asq_last_status));
  8211. }
  8212. /* reinit the misc interrupt */
  8213. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8214. ret = i40e_setup_misc_vector(pf);
  8215. /* Add a filter to drop all Flow control frames from any VSI from being
  8216. * transmitted. By doing so we stop a malicious VF from sending out
  8217. * PAUSE or PFC frames and potentially controlling traffic for other
  8218. * PF/VF VSIs.
  8219. * The FW can still send Flow control frames if enabled.
  8220. */
  8221. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  8222. pf->main_vsi_seid);
  8223. /* restart the VSIs that were rebuilt and running before the reset */
  8224. i40e_pf_unquiesce_all_vsi(pf);
  8225. /* Release the RTNL lock before we start resetting VFs */
  8226. if (!lock_acquired)
  8227. rtnl_unlock();
  8228. /* Restore promiscuous settings */
  8229. ret = i40e_set_promiscuous(pf, pf->cur_promisc);
  8230. if (ret)
  8231. dev_warn(&pf->pdev->dev,
  8232. "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
  8233. pf->cur_promisc ? "on" : "off",
  8234. i40e_stat_str(&pf->hw, ret),
  8235. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8236. i40e_reset_all_vfs(pf, true);
  8237. /* tell the firmware that we're starting */
  8238. i40e_send_version(pf);
  8239. /* We've already released the lock, so don't do it again */
  8240. goto end_core_reset;
  8241. end_unlock:
  8242. if (!lock_acquired)
  8243. rtnl_unlock();
  8244. end_core_reset:
  8245. clear_bit(__I40E_RESET_FAILED, pf->state);
  8246. clear_recovery:
  8247. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8248. }
  8249. /**
  8250. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  8251. * @pf: board private structure
  8252. * @reinit: if the Main VSI needs to re-initialized.
  8253. * @lock_acquired: indicates whether or not the lock has been acquired
  8254. * before this function was called.
  8255. **/
  8256. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
  8257. bool lock_acquired)
  8258. {
  8259. int ret;
  8260. /* Now we wait for GRST to settle out.
  8261. * We don't have to delete the VEBs or VSIs from the hw switch
  8262. * because the reset will make them disappear.
  8263. */
  8264. ret = i40e_reset(pf);
  8265. if (!ret)
  8266. i40e_rebuild(pf, reinit, lock_acquired);
  8267. }
  8268. /**
  8269. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  8270. * @pf: board private structure
  8271. *
  8272. * Close up the VFs and other things in prep for a Core Reset,
  8273. * then get ready to rebuild the world.
  8274. * @lock_acquired: indicates whether or not the lock has been acquired
  8275. * before this function was called.
  8276. **/
  8277. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
  8278. {
  8279. i40e_prep_for_reset(pf, lock_acquired);
  8280. i40e_reset_and_rebuild(pf, false, lock_acquired);
  8281. }
  8282. /**
  8283. * i40e_handle_mdd_event
  8284. * @pf: pointer to the PF structure
  8285. *
  8286. * Called from the MDD irq handler to identify possibly malicious vfs
  8287. **/
  8288. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  8289. {
  8290. struct i40e_hw *hw = &pf->hw;
  8291. bool mdd_detected = false;
  8292. bool pf_mdd_detected = false;
  8293. struct i40e_vf *vf;
  8294. u32 reg;
  8295. int i;
  8296. if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
  8297. return;
  8298. /* find what triggered the MDD event */
  8299. reg = rd32(hw, I40E_GL_MDET_TX);
  8300. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  8301. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  8302. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  8303. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  8304. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  8305. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  8306. I40E_GL_MDET_TX_EVENT_SHIFT;
  8307. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  8308. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  8309. pf->hw.func_caps.base_queue;
  8310. if (netif_msg_tx_err(pf))
  8311. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  8312. event, queue, pf_num, vf_num);
  8313. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  8314. mdd_detected = true;
  8315. }
  8316. reg = rd32(hw, I40E_GL_MDET_RX);
  8317. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  8318. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  8319. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  8320. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  8321. I40E_GL_MDET_RX_EVENT_SHIFT;
  8322. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  8323. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  8324. pf->hw.func_caps.base_queue;
  8325. if (netif_msg_rx_err(pf))
  8326. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  8327. event, queue, func);
  8328. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  8329. mdd_detected = true;
  8330. }
  8331. if (mdd_detected) {
  8332. reg = rd32(hw, I40E_PF_MDET_TX);
  8333. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  8334. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  8335. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  8336. pf_mdd_detected = true;
  8337. }
  8338. reg = rd32(hw, I40E_PF_MDET_RX);
  8339. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  8340. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  8341. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  8342. pf_mdd_detected = true;
  8343. }
  8344. /* Queue belongs to the PF, initiate a reset */
  8345. if (pf_mdd_detected) {
  8346. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  8347. i40e_service_event_schedule(pf);
  8348. }
  8349. }
  8350. /* see if one of the VFs needs its hand slapped */
  8351. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  8352. vf = &(pf->vf[i]);
  8353. reg = rd32(hw, I40E_VP_MDET_TX(i));
  8354. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  8355. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  8356. vf->num_mdd_events++;
  8357. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  8358. i);
  8359. }
  8360. reg = rd32(hw, I40E_VP_MDET_RX(i));
  8361. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  8362. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  8363. vf->num_mdd_events++;
  8364. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  8365. i);
  8366. }
  8367. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  8368. dev_info(&pf->pdev->dev,
  8369. "Too many MDD events on VF %d, disabled\n", i);
  8370. dev_info(&pf->pdev->dev,
  8371. "Use PF Control I/F to re-enable the VF\n");
  8372. set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
  8373. }
  8374. }
  8375. /* re-enable mdd interrupt cause */
  8376. clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  8377. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  8378. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  8379. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  8380. i40e_flush(hw);
  8381. }
  8382. static const char *i40e_tunnel_name(struct i40e_udp_port_config *port)
  8383. {
  8384. switch (port->type) {
  8385. case UDP_TUNNEL_TYPE_VXLAN:
  8386. return "vxlan";
  8387. case UDP_TUNNEL_TYPE_GENEVE:
  8388. return "geneve";
  8389. default:
  8390. return "unknown";
  8391. }
  8392. }
  8393. /**
  8394. * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
  8395. * @pf: board private structure
  8396. **/
  8397. static void i40e_sync_udp_filters(struct i40e_pf *pf)
  8398. {
  8399. int i;
  8400. /* loop through and set pending bit for all active UDP filters */
  8401. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8402. if (pf->udp_ports[i].port)
  8403. pf->pending_udp_bitmap |= BIT_ULL(i);
  8404. }
  8405. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  8406. }
  8407. /**
  8408. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  8409. * @pf: board private structure
  8410. **/
  8411. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  8412. {
  8413. struct i40e_hw *hw = &pf->hw;
  8414. i40e_status ret;
  8415. u16 port;
  8416. int i;
  8417. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  8418. return;
  8419. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  8420. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8421. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  8422. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  8423. port = pf->udp_ports[i].port;
  8424. if (port)
  8425. ret = i40e_aq_add_udp_tunnel(hw, port,
  8426. pf->udp_ports[i].type,
  8427. NULL, NULL);
  8428. else
  8429. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  8430. if (ret) {
  8431. dev_info(&pf->pdev->dev,
  8432. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  8433. i40e_tunnel_name(&pf->udp_ports[i]),
  8434. port ? "add" : "delete",
  8435. port, i,
  8436. i40e_stat_str(&pf->hw, ret),
  8437. i40e_aq_str(&pf->hw,
  8438. pf->hw.aq.asq_last_status));
  8439. pf->udp_ports[i].port = 0;
  8440. }
  8441. }
  8442. }
  8443. }
  8444. /**
  8445. * i40e_service_task - Run the driver's async subtasks
  8446. * @work: pointer to work_struct containing our data
  8447. **/
  8448. static void i40e_service_task(struct work_struct *work)
  8449. {
  8450. struct i40e_pf *pf = container_of(work,
  8451. struct i40e_pf,
  8452. service_task);
  8453. unsigned long start_time = jiffies;
  8454. /* don't bother with service tasks if a reset is in progress */
  8455. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  8456. return;
  8457. if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
  8458. return;
  8459. i40e_detect_recover_hung(pf->vsi[pf->lan_vsi]);
  8460. i40e_sync_filters_subtask(pf);
  8461. i40e_reset_subtask(pf);
  8462. i40e_handle_mdd_event(pf);
  8463. i40e_vc_process_vflr_event(pf);
  8464. i40e_watchdog_subtask(pf);
  8465. i40e_fdir_reinit_subtask(pf);
  8466. if (pf->flags & I40E_FLAG_CLIENT_RESET) {
  8467. /* Client subtask will reopen next time through. */
  8468. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
  8469. pf->flags &= ~I40E_FLAG_CLIENT_RESET;
  8470. } else {
  8471. i40e_client_subtask(pf);
  8472. if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) {
  8473. i40e_notify_client_of_l2_param_changes(
  8474. pf->vsi[pf->lan_vsi]);
  8475. pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE;
  8476. }
  8477. }
  8478. i40e_sync_filters_subtask(pf);
  8479. i40e_sync_udp_filters_subtask(pf);
  8480. i40e_clean_adminq_subtask(pf);
  8481. /* flush memory to make sure state is correct before next watchdog */
  8482. smp_mb__before_atomic();
  8483. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  8484. /* If the tasks have taken longer than one timer cycle or there
  8485. * is more work to be done, reschedule the service task now
  8486. * rather than wait for the timer to tick again.
  8487. */
  8488. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  8489. test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
  8490. test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
  8491. test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
  8492. i40e_service_event_schedule(pf);
  8493. }
  8494. /**
  8495. * i40e_service_timer - timer callback
  8496. * @data: pointer to PF struct
  8497. **/
  8498. static void i40e_service_timer(struct timer_list *t)
  8499. {
  8500. struct i40e_pf *pf = from_timer(pf, t, service_timer);
  8501. mod_timer(&pf->service_timer,
  8502. round_jiffies(jiffies + pf->service_timer_period));
  8503. i40e_service_event_schedule(pf);
  8504. }
  8505. /**
  8506. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  8507. * @vsi: the VSI being configured
  8508. **/
  8509. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  8510. {
  8511. struct i40e_pf *pf = vsi->back;
  8512. switch (vsi->type) {
  8513. case I40E_VSI_MAIN:
  8514. vsi->alloc_queue_pairs = pf->num_lan_qps;
  8515. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8516. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8517. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8518. vsi->num_q_vectors = pf->num_lan_msix;
  8519. else
  8520. vsi->num_q_vectors = 1;
  8521. break;
  8522. case I40E_VSI_FDIR:
  8523. vsi->alloc_queue_pairs = 1;
  8524. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  8525. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8526. vsi->num_q_vectors = pf->num_fdsb_msix;
  8527. break;
  8528. case I40E_VSI_VMDQ2:
  8529. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  8530. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8531. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8532. vsi->num_q_vectors = pf->num_vmdq_msix;
  8533. break;
  8534. case I40E_VSI_SRIOV:
  8535. vsi->alloc_queue_pairs = pf->num_vf_qps;
  8536. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8537. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8538. break;
  8539. default:
  8540. WARN_ON(1);
  8541. return -ENODATA;
  8542. }
  8543. return 0;
  8544. }
  8545. /**
  8546. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  8547. * @vsi: VSI pointer
  8548. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  8549. *
  8550. * On error: returns error code (negative)
  8551. * On success: returns 0
  8552. **/
  8553. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  8554. {
  8555. struct i40e_ring **next_rings;
  8556. int size;
  8557. int ret = 0;
  8558. /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
  8559. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
  8560. (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
  8561. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  8562. if (!vsi->tx_rings)
  8563. return -ENOMEM;
  8564. next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
  8565. if (i40e_enabled_xdp_vsi(vsi)) {
  8566. vsi->xdp_rings = next_rings;
  8567. next_rings += vsi->alloc_queue_pairs;
  8568. }
  8569. vsi->rx_rings = next_rings;
  8570. if (alloc_qvectors) {
  8571. /* allocate memory for q_vector pointers */
  8572. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  8573. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  8574. if (!vsi->q_vectors) {
  8575. ret = -ENOMEM;
  8576. goto err_vectors;
  8577. }
  8578. }
  8579. return ret;
  8580. err_vectors:
  8581. kfree(vsi->tx_rings);
  8582. return ret;
  8583. }
  8584. /**
  8585. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  8586. * @pf: board private structure
  8587. * @type: type of VSI
  8588. *
  8589. * On error: returns error code (negative)
  8590. * On success: returns vsi index in PF (positive)
  8591. **/
  8592. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  8593. {
  8594. int ret = -ENODEV;
  8595. struct i40e_vsi *vsi;
  8596. int vsi_idx;
  8597. int i;
  8598. /* Need to protect the allocation of the VSIs at the PF level */
  8599. mutex_lock(&pf->switch_mutex);
  8600. /* VSI list may be fragmented if VSI creation/destruction has
  8601. * been happening. We can afford to do a quick scan to look
  8602. * for any free VSIs in the list.
  8603. *
  8604. * find next empty vsi slot, looping back around if necessary
  8605. */
  8606. i = pf->next_vsi;
  8607. while (i < pf->num_alloc_vsi && pf->vsi[i])
  8608. i++;
  8609. if (i >= pf->num_alloc_vsi) {
  8610. i = 0;
  8611. while (i < pf->next_vsi && pf->vsi[i])
  8612. i++;
  8613. }
  8614. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  8615. vsi_idx = i; /* Found one! */
  8616. } else {
  8617. ret = -ENODEV;
  8618. goto unlock_pf; /* out of VSI slots! */
  8619. }
  8620. pf->next_vsi = ++i;
  8621. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  8622. if (!vsi) {
  8623. ret = -ENOMEM;
  8624. goto unlock_pf;
  8625. }
  8626. vsi->type = type;
  8627. vsi->back = pf;
  8628. set_bit(__I40E_VSI_DOWN, vsi->state);
  8629. vsi->flags = 0;
  8630. vsi->idx = vsi_idx;
  8631. vsi->int_rate_limit = 0;
  8632. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  8633. pf->rss_table_size : 64;
  8634. vsi->netdev_registered = false;
  8635. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  8636. hash_init(vsi->mac_filter_hash);
  8637. vsi->irqs_ready = false;
  8638. ret = i40e_set_num_rings_in_vsi(vsi);
  8639. if (ret)
  8640. goto err_rings;
  8641. ret = i40e_vsi_alloc_arrays(vsi, true);
  8642. if (ret)
  8643. goto err_rings;
  8644. /* Setup default MSIX irq handler for VSI */
  8645. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  8646. /* Initialize VSI lock */
  8647. spin_lock_init(&vsi->mac_filter_hash_lock);
  8648. pf->vsi[vsi_idx] = vsi;
  8649. ret = vsi_idx;
  8650. goto unlock_pf;
  8651. err_rings:
  8652. pf->next_vsi = i - 1;
  8653. kfree(vsi);
  8654. unlock_pf:
  8655. mutex_unlock(&pf->switch_mutex);
  8656. return ret;
  8657. }
  8658. /**
  8659. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  8660. * @type: VSI pointer
  8661. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  8662. *
  8663. * On error: returns error code (negative)
  8664. * On success: returns 0
  8665. **/
  8666. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  8667. {
  8668. /* free the ring and vector containers */
  8669. if (free_qvectors) {
  8670. kfree(vsi->q_vectors);
  8671. vsi->q_vectors = NULL;
  8672. }
  8673. kfree(vsi->tx_rings);
  8674. vsi->tx_rings = NULL;
  8675. vsi->rx_rings = NULL;
  8676. vsi->xdp_rings = NULL;
  8677. }
  8678. /**
  8679. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  8680. * and lookup table
  8681. * @vsi: Pointer to VSI structure
  8682. */
  8683. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  8684. {
  8685. if (!vsi)
  8686. return;
  8687. kfree(vsi->rss_hkey_user);
  8688. vsi->rss_hkey_user = NULL;
  8689. kfree(vsi->rss_lut_user);
  8690. vsi->rss_lut_user = NULL;
  8691. }
  8692. /**
  8693. * i40e_vsi_clear - Deallocate the VSI provided
  8694. * @vsi: the VSI being un-configured
  8695. **/
  8696. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  8697. {
  8698. struct i40e_pf *pf;
  8699. if (!vsi)
  8700. return 0;
  8701. if (!vsi->back)
  8702. goto free_vsi;
  8703. pf = vsi->back;
  8704. mutex_lock(&pf->switch_mutex);
  8705. if (!pf->vsi[vsi->idx]) {
  8706. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  8707. vsi->idx, vsi->idx, vsi, vsi->type);
  8708. goto unlock_vsi;
  8709. }
  8710. if (pf->vsi[vsi->idx] != vsi) {
  8711. dev_err(&pf->pdev->dev,
  8712. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  8713. pf->vsi[vsi->idx]->idx,
  8714. pf->vsi[vsi->idx],
  8715. pf->vsi[vsi->idx]->type,
  8716. vsi->idx, vsi, vsi->type);
  8717. goto unlock_vsi;
  8718. }
  8719. /* updates the PF for this cleared vsi */
  8720. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8721. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  8722. i40e_vsi_free_arrays(vsi, true);
  8723. i40e_clear_rss_config_user(vsi);
  8724. pf->vsi[vsi->idx] = NULL;
  8725. if (vsi->idx < pf->next_vsi)
  8726. pf->next_vsi = vsi->idx;
  8727. unlock_vsi:
  8728. mutex_unlock(&pf->switch_mutex);
  8729. free_vsi:
  8730. kfree(vsi);
  8731. return 0;
  8732. }
  8733. /**
  8734. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  8735. * @vsi: the VSI being cleaned
  8736. **/
  8737. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  8738. {
  8739. int i;
  8740. if (vsi->tx_rings && vsi->tx_rings[0]) {
  8741. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8742. kfree_rcu(vsi->tx_rings[i], rcu);
  8743. vsi->tx_rings[i] = NULL;
  8744. vsi->rx_rings[i] = NULL;
  8745. if (vsi->xdp_rings)
  8746. vsi->xdp_rings[i] = NULL;
  8747. }
  8748. }
  8749. }
  8750. /**
  8751. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  8752. * @vsi: the VSI being configured
  8753. **/
  8754. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  8755. {
  8756. int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
  8757. struct i40e_pf *pf = vsi->back;
  8758. struct i40e_ring *ring;
  8759. /* Set basic values in the rings to be used later during open() */
  8760. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8761. /* allocate space for both Tx and Rx in one shot */
  8762. ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
  8763. if (!ring)
  8764. goto err_out;
  8765. ring->queue_index = i;
  8766. ring->reg_idx = vsi->base_queue + i;
  8767. ring->ring_active = false;
  8768. ring->vsi = vsi;
  8769. ring->netdev = vsi->netdev;
  8770. ring->dev = &pf->pdev->dev;
  8771. ring->count = vsi->num_desc;
  8772. ring->size = 0;
  8773. ring->dcb_tc = 0;
  8774. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8775. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8776. ring->tx_itr_setting = pf->tx_itr_default;
  8777. vsi->tx_rings[i] = ring++;
  8778. if (!i40e_enabled_xdp_vsi(vsi))
  8779. goto setup_rx;
  8780. ring->queue_index = vsi->alloc_queue_pairs + i;
  8781. ring->reg_idx = vsi->base_queue + ring->queue_index;
  8782. ring->ring_active = false;
  8783. ring->vsi = vsi;
  8784. ring->netdev = NULL;
  8785. ring->dev = &pf->pdev->dev;
  8786. ring->count = vsi->num_desc;
  8787. ring->size = 0;
  8788. ring->dcb_tc = 0;
  8789. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8790. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8791. set_ring_xdp(ring);
  8792. ring->tx_itr_setting = pf->tx_itr_default;
  8793. vsi->xdp_rings[i] = ring++;
  8794. setup_rx:
  8795. ring->queue_index = i;
  8796. ring->reg_idx = vsi->base_queue + i;
  8797. ring->ring_active = false;
  8798. ring->vsi = vsi;
  8799. ring->netdev = vsi->netdev;
  8800. ring->dev = &pf->pdev->dev;
  8801. ring->count = vsi->num_desc;
  8802. ring->size = 0;
  8803. ring->dcb_tc = 0;
  8804. ring->rx_itr_setting = pf->rx_itr_default;
  8805. vsi->rx_rings[i] = ring;
  8806. }
  8807. return 0;
  8808. err_out:
  8809. i40e_vsi_clear_rings(vsi);
  8810. return -ENOMEM;
  8811. }
  8812. /**
  8813. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  8814. * @pf: board private structure
  8815. * @vectors: the number of MSI-X vectors to request
  8816. *
  8817. * Returns the number of vectors reserved, or error
  8818. **/
  8819. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  8820. {
  8821. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  8822. I40E_MIN_MSIX, vectors);
  8823. if (vectors < 0) {
  8824. dev_info(&pf->pdev->dev,
  8825. "MSI-X vector reservation failed: %d\n", vectors);
  8826. vectors = 0;
  8827. }
  8828. return vectors;
  8829. }
  8830. /**
  8831. * i40e_init_msix - Setup the MSIX capability
  8832. * @pf: board private structure
  8833. *
  8834. * Work with the OS to set up the MSIX vectors needed.
  8835. *
  8836. * Returns the number of vectors reserved or negative on failure
  8837. **/
  8838. static int i40e_init_msix(struct i40e_pf *pf)
  8839. {
  8840. struct i40e_hw *hw = &pf->hw;
  8841. int cpus, extra_vectors;
  8842. int vectors_left;
  8843. int v_budget, i;
  8844. int v_actual;
  8845. int iwarp_requested = 0;
  8846. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8847. return -ENODEV;
  8848. /* The number of vectors we'll request will be comprised of:
  8849. * - Add 1 for "other" cause for Admin Queue events, etc.
  8850. * - The number of LAN queue pairs
  8851. * - Queues being used for RSS.
  8852. * We don't need as many as max_rss_size vectors.
  8853. * use rss_size instead in the calculation since that
  8854. * is governed by number of cpus in the system.
  8855. * - assumes symmetric Tx/Rx pairing
  8856. * - The number of VMDq pairs
  8857. * - The CPU count within the NUMA node if iWARP is enabled
  8858. * Once we count this up, try the request.
  8859. *
  8860. * If we can't get what we want, we'll simplify to nearly nothing
  8861. * and try again. If that still fails, we punt.
  8862. */
  8863. vectors_left = hw->func_caps.num_msix_vectors;
  8864. v_budget = 0;
  8865. /* reserve one vector for miscellaneous handler */
  8866. if (vectors_left) {
  8867. v_budget++;
  8868. vectors_left--;
  8869. }
  8870. /* reserve some vectors for the main PF traffic queues. Initially we
  8871. * only reserve at most 50% of the available vectors, in the case that
  8872. * the number of online CPUs is large. This ensures that we can enable
  8873. * extra features as well. Once we've enabled the other features, we
  8874. * will use any remaining vectors to reach as close as we can to the
  8875. * number of online CPUs.
  8876. */
  8877. cpus = num_online_cpus();
  8878. pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
  8879. vectors_left -= pf->num_lan_msix;
  8880. /* reserve one vector for sideband flow director */
  8881. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  8882. if (vectors_left) {
  8883. pf->num_fdsb_msix = 1;
  8884. v_budget++;
  8885. vectors_left--;
  8886. } else {
  8887. pf->num_fdsb_msix = 0;
  8888. }
  8889. }
  8890. /* can we reserve enough for iWARP? */
  8891. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  8892. iwarp_requested = pf->num_iwarp_msix;
  8893. if (!vectors_left)
  8894. pf->num_iwarp_msix = 0;
  8895. else if (vectors_left < pf->num_iwarp_msix)
  8896. pf->num_iwarp_msix = 1;
  8897. v_budget += pf->num_iwarp_msix;
  8898. vectors_left -= pf->num_iwarp_msix;
  8899. }
  8900. /* any vectors left over go for VMDq support */
  8901. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  8902. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  8903. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  8904. if (!vectors_left) {
  8905. pf->num_vmdq_msix = 0;
  8906. pf->num_vmdq_qps = 0;
  8907. } else {
  8908. /* if we're short on vectors for what's desired, we limit
  8909. * the queues per vmdq. If this is still more than are
  8910. * available, the user will need to change the number of
  8911. * queues/vectors used by the PF later with the ethtool
  8912. * channels command
  8913. */
  8914. if (vmdq_vecs < vmdq_vecs_wanted)
  8915. pf->num_vmdq_qps = 1;
  8916. pf->num_vmdq_msix = pf->num_vmdq_qps;
  8917. v_budget += vmdq_vecs;
  8918. vectors_left -= vmdq_vecs;
  8919. }
  8920. }
  8921. /* On systems with a large number of SMP cores, we previously limited
  8922. * the number of vectors for num_lan_msix to be at most 50% of the
  8923. * available vectors, to allow for other features. Now, we add back
  8924. * the remaining vectors. However, we ensure that the total
  8925. * num_lan_msix will not exceed num_online_cpus(). To do this, we
  8926. * calculate the number of vectors we can add without going over the
  8927. * cap of CPUs. For systems with a small number of CPUs this will be
  8928. * zero.
  8929. */
  8930. extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
  8931. pf->num_lan_msix += extra_vectors;
  8932. vectors_left -= extra_vectors;
  8933. WARN(vectors_left < 0,
  8934. "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
  8935. v_budget += pf->num_lan_msix;
  8936. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  8937. GFP_KERNEL);
  8938. if (!pf->msix_entries)
  8939. return -ENOMEM;
  8940. for (i = 0; i < v_budget; i++)
  8941. pf->msix_entries[i].entry = i;
  8942. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  8943. if (v_actual < I40E_MIN_MSIX) {
  8944. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  8945. kfree(pf->msix_entries);
  8946. pf->msix_entries = NULL;
  8947. pci_disable_msix(pf->pdev);
  8948. return -ENODEV;
  8949. } else if (v_actual == I40E_MIN_MSIX) {
  8950. /* Adjust for minimal MSIX use */
  8951. pf->num_vmdq_vsis = 0;
  8952. pf->num_vmdq_qps = 0;
  8953. pf->num_lan_qps = 1;
  8954. pf->num_lan_msix = 1;
  8955. } else if (v_actual != v_budget) {
  8956. /* If we have limited resources, we will start with no vectors
  8957. * for the special features and then allocate vectors to some
  8958. * of these features based on the policy and at the end disable
  8959. * the features that did not get any vectors.
  8960. */
  8961. int vec;
  8962. dev_info(&pf->pdev->dev,
  8963. "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
  8964. v_actual, v_budget);
  8965. /* reserve the misc vector */
  8966. vec = v_actual - 1;
  8967. /* Scale vector usage down */
  8968. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  8969. pf->num_vmdq_vsis = 1;
  8970. pf->num_vmdq_qps = 1;
  8971. /* partition out the remaining vectors */
  8972. switch (vec) {
  8973. case 2:
  8974. pf->num_lan_msix = 1;
  8975. break;
  8976. case 3:
  8977. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  8978. pf->num_lan_msix = 1;
  8979. pf->num_iwarp_msix = 1;
  8980. } else {
  8981. pf->num_lan_msix = 2;
  8982. }
  8983. break;
  8984. default:
  8985. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  8986. pf->num_iwarp_msix = min_t(int, (vec / 3),
  8987. iwarp_requested);
  8988. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  8989. I40E_DEFAULT_NUM_VMDQ_VSI);
  8990. } else {
  8991. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  8992. I40E_DEFAULT_NUM_VMDQ_VSI);
  8993. }
  8994. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  8995. pf->num_fdsb_msix = 1;
  8996. vec--;
  8997. }
  8998. pf->num_lan_msix = min_t(int,
  8999. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  9000. pf->num_lan_msix);
  9001. pf->num_lan_qps = pf->num_lan_msix;
  9002. break;
  9003. }
  9004. }
  9005. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  9006. (pf->num_fdsb_msix == 0)) {
  9007. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  9008. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9009. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9010. }
  9011. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9012. (pf->num_vmdq_msix == 0)) {
  9013. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  9014. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  9015. }
  9016. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  9017. (pf->num_iwarp_msix == 0)) {
  9018. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  9019. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9020. }
  9021. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  9022. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  9023. pf->num_lan_msix,
  9024. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  9025. pf->num_fdsb_msix,
  9026. pf->num_iwarp_msix);
  9027. return v_actual;
  9028. }
  9029. /**
  9030. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  9031. * @vsi: the VSI being configured
  9032. * @v_idx: index of the vector in the vsi struct
  9033. * @cpu: cpu to be used on affinity_mask
  9034. *
  9035. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  9036. **/
  9037. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  9038. {
  9039. struct i40e_q_vector *q_vector;
  9040. /* allocate q_vector */
  9041. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  9042. if (!q_vector)
  9043. return -ENOMEM;
  9044. q_vector->vsi = vsi;
  9045. q_vector->v_idx = v_idx;
  9046. cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
  9047. if (vsi->netdev)
  9048. netif_napi_add(vsi->netdev, &q_vector->napi,
  9049. i40e_napi_poll, NAPI_POLL_WEIGHT);
  9050. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  9051. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  9052. /* tie q_vector and vsi together */
  9053. vsi->q_vectors[v_idx] = q_vector;
  9054. return 0;
  9055. }
  9056. /**
  9057. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  9058. * @vsi: the VSI being configured
  9059. *
  9060. * We allocate one q_vector per queue interrupt. If allocation fails we
  9061. * return -ENOMEM.
  9062. **/
  9063. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  9064. {
  9065. struct i40e_pf *pf = vsi->back;
  9066. int err, v_idx, num_q_vectors, current_cpu;
  9067. /* if not MSIX, give the one vector only to the LAN VSI */
  9068. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  9069. num_q_vectors = vsi->num_q_vectors;
  9070. else if (vsi == pf->vsi[pf->lan_vsi])
  9071. num_q_vectors = 1;
  9072. else
  9073. return -EINVAL;
  9074. current_cpu = cpumask_first(cpu_online_mask);
  9075. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  9076. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  9077. if (err)
  9078. goto err_out;
  9079. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  9080. if (unlikely(current_cpu >= nr_cpu_ids))
  9081. current_cpu = cpumask_first(cpu_online_mask);
  9082. }
  9083. return 0;
  9084. err_out:
  9085. while (v_idx--)
  9086. i40e_free_q_vector(vsi, v_idx);
  9087. return err;
  9088. }
  9089. /**
  9090. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  9091. * @pf: board private structure to initialize
  9092. **/
  9093. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  9094. {
  9095. int vectors = 0;
  9096. ssize_t size;
  9097. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9098. vectors = i40e_init_msix(pf);
  9099. if (vectors < 0) {
  9100. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  9101. I40E_FLAG_IWARP_ENABLED |
  9102. I40E_FLAG_RSS_ENABLED |
  9103. I40E_FLAG_DCB_CAPABLE |
  9104. I40E_FLAG_DCB_ENABLED |
  9105. I40E_FLAG_SRIOV_ENABLED |
  9106. I40E_FLAG_FD_SB_ENABLED |
  9107. I40E_FLAG_FD_ATR_ENABLED |
  9108. I40E_FLAG_VMDQ_ENABLED);
  9109. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9110. /* rework the queue expectations without MSIX */
  9111. i40e_determine_queue_usage(pf);
  9112. }
  9113. }
  9114. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9115. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  9116. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  9117. vectors = pci_enable_msi(pf->pdev);
  9118. if (vectors < 0) {
  9119. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  9120. vectors);
  9121. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  9122. }
  9123. vectors = 1; /* one MSI or Legacy vector */
  9124. }
  9125. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  9126. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  9127. /* set up vector assignment tracking */
  9128. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  9129. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  9130. if (!pf->irq_pile)
  9131. return -ENOMEM;
  9132. pf->irq_pile->num_entries = vectors;
  9133. pf->irq_pile->search_hint = 0;
  9134. /* track first vector for misc interrupts, ignore return */
  9135. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  9136. return 0;
  9137. }
  9138. /**
  9139. * i40e_restore_interrupt_scheme - Restore the interrupt scheme
  9140. * @pf: private board data structure
  9141. *
  9142. * Restore the interrupt scheme that was cleared when we suspended the
  9143. * device. This should be called during resume to re-allocate the q_vectors
  9144. * and reacquire IRQs.
  9145. */
  9146. static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
  9147. {
  9148. int err, i;
  9149. /* We cleared the MSI and MSI-X flags when disabling the old interrupt
  9150. * scheme. We need to re-enabled them here in order to attempt to
  9151. * re-acquire the MSI or MSI-X vectors
  9152. */
  9153. pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  9154. err = i40e_init_interrupt_scheme(pf);
  9155. if (err)
  9156. return err;
  9157. /* Now that we've re-acquired IRQs, we need to remap the vectors and
  9158. * rings together again.
  9159. */
  9160. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9161. if (pf->vsi[i]) {
  9162. err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
  9163. if (err)
  9164. goto err_unwind;
  9165. i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
  9166. }
  9167. }
  9168. err = i40e_setup_misc_vector(pf);
  9169. if (err)
  9170. goto err_unwind;
  9171. return 0;
  9172. err_unwind:
  9173. while (i--) {
  9174. if (pf->vsi[i])
  9175. i40e_vsi_free_q_vectors(pf->vsi[i]);
  9176. }
  9177. return err;
  9178. }
  9179. /**
  9180. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  9181. * @pf: board private structure
  9182. *
  9183. * This sets up the handler for MSIX 0, which is used to manage the
  9184. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  9185. * when in MSI or Legacy interrupt mode.
  9186. **/
  9187. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  9188. {
  9189. struct i40e_hw *hw = &pf->hw;
  9190. int err = 0;
  9191. /* Only request the IRQ once, the first time through. */
  9192. if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
  9193. err = request_irq(pf->msix_entries[0].vector,
  9194. i40e_intr, 0, pf->int_name, pf);
  9195. if (err) {
  9196. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  9197. dev_info(&pf->pdev->dev,
  9198. "request_irq for %s failed: %d\n",
  9199. pf->int_name, err);
  9200. return -EFAULT;
  9201. }
  9202. }
  9203. i40e_enable_misc_int_causes(pf);
  9204. /* associate no queues to the misc vector */
  9205. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  9206. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  9207. i40e_flush(hw);
  9208. i40e_irq_dynamic_enable_icr0(pf);
  9209. return err;
  9210. }
  9211. /**
  9212. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  9213. * @vsi: Pointer to vsi structure
  9214. * @seed: Buffter to store the hash keys
  9215. * @lut: Buffer to store the lookup table entries
  9216. * @lut_size: Size of buffer to store the lookup table entries
  9217. *
  9218. * Return 0 on success, negative on failure
  9219. */
  9220. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  9221. u8 *lut, u16 lut_size)
  9222. {
  9223. struct i40e_pf *pf = vsi->back;
  9224. struct i40e_hw *hw = &pf->hw;
  9225. int ret = 0;
  9226. if (seed) {
  9227. ret = i40e_aq_get_rss_key(hw, vsi->id,
  9228. (struct i40e_aqc_get_set_rss_key_data *)seed);
  9229. if (ret) {
  9230. dev_info(&pf->pdev->dev,
  9231. "Cannot get RSS key, err %s aq_err %s\n",
  9232. i40e_stat_str(&pf->hw, ret),
  9233. i40e_aq_str(&pf->hw,
  9234. pf->hw.aq.asq_last_status));
  9235. return ret;
  9236. }
  9237. }
  9238. if (lut) {
  9239. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  9240. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  9241. if (ret) {
  9242. dev_info(&pf->pdev->dev,
  9243. "Cannot get RSS lut, err %s aq_err %s\n",
  9244. i40e_stat_str(&pf->hw, ret),
  9245. i40e_aq_str(&pf->hw,
  9246. pf->hw.aq.asq_last_status));
  9247. return ret;
  9248. }
  9249. }
  9250. return ret;
  9251. }
  9252. /**
  9253. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  9254. * @vsi: Pointer to vsi structure
  9255. * @seed: RSS hash seed
  9256. * @lut: Lookup table
  9257. * @lut_size: Lookup table size
  9258. *
  9259. * Returns 0 on success, negative on failure
  9260. **/
  9261. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  9262. const u8 *lut, u16 lut_size)
  9263. {
  9264. struct i40e_pf *pf = vsi->back;
  9265. struct i40e_hw *hw = &pf->hw;
  9266. u16 vf_id = vsi->vf_id;
  9267. u8 i;
  9268. /* Fill out hash function seed */
  9269. if (seed) {
  9270. u32 *seed_dw = (u32 *)seed;
  9271. if (vsi->type == I40E_VSI_MAIN) {
  9272. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9273. wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  9274. } else if (vsi->type == I40E_VSI_SRIOV) {
  9275. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  9276. wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
  9277. } else {
  9278. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  9279. }
  9280. }
  9281. if (lut) {
  9282. u32 *lut_dw = (u32 *)lut;
  9283. if (vsi->type == I40E_VSI_MAIN) {
  9284. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9285. return -EINVAL;
  9286. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9287. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  9288. } else if (vsi->type == I40E_VSI_SRIOV) {
  9289. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  9290. return -EINVAL;
  9291. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9292. wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
  9293. } else {
  9294. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9295. }
  9296. }
  9297. i40e_flush(hw);
  9298. return 0;
  9299. }
  9300. /**
  9301. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  9302. * @vsi: Pointer to VSI structure
  9303. * @seed: Buffer to store the keys
  9304. * @lut: Buffer to store the lookup table entries
  9305. * @lut_size: Size of buffer to store the lookup table entries
  9306. *
  9307. * Returns 0 on success, negative on failure
  9308. */
  9309. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  9310. u8 *lut, u16 lut_size)
  9311. {
  9312. struct i40e_pf *pf = vsi->back;
  9313. struct i40e_hw *hw = &pf->hw;
  9314. u16 i;
  9315. if (seed) {
  9316. u32 *seed_dw = (u32 *)seed;
  9317. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9318. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  9319. }
  9320. if (lut) {
  9321. u32 *lut_dw = (u32 *)lut;
  9322. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9323. return -EINVAL;
  9324. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9325. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  9326. }
  9327. return 0;
  9328. }
  9329. /**
  9330. * i40e_config_rss - Configure RSS keys and lut
  9331. * @vsi: Pointer to VSI structure
  9332. * @seed: RSS hash seed
  9333. * @lut: Lookup table
  9334. * @lut_size: Lookup table size
  9335. *
  9336. * Returns 0 on success, negative on failure
  9337. */
  9338. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9339. {
  9340. struct i40e_pf *pf = vsi->back;
  9341. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9342. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  9343. else
  9344. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  9345. }
  9346. /**
  9347. * i40e_get_rss - Get RSS keys and lut
  9348. * @vsi: Pointer to VSI structure
  9349. * @seed: Buffer to store the keys
  9350. * @lut: Buffer to store the lookup table entries
  9351. * lut_size: Size of buffer to store the lookup table entries
  9352. *
  9353. * Returns 0 on success, negative on failure
  9354. */
  9355. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9356. {
  9357. struct i40e_pf *pf = vsi->back;
  9358. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9359. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  9360. else
  9361. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  9362. }
  9363. /**
  9364. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  9365. * @pf: Pointer to board private structure
  9366. * @lut: Lookup table
  9367. * @rss_table_size: Lookup table size
  9368. * @rss_size: Range of queue number for hashing
  9369. */
  9370. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  9371. u16 rss_table_size, u16 rss_size)
  9372. {
  9373. u16 i;
  9374. for (i = 0; i < rss_table_size; i++)
  9375. lut[i] = i % rss_size;
  9376. }
  9377. /**
  9378. * i40e_pf_config_rss - Prepare for RSS if used
  9379. * @pf: board private structure
  9380. **/
  9381. static int i40e_pf_config_rss(struct i40e_pf *pf)
  9382. {
  9383. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9384. u8 seed[I40E_HKEY_ARRAY_SIZE];
  9385. u8 *lut;
  9386. struct i40e_hw *hw = &pf->hw;
  9387. u32 reg_val;
  9388. u64 hena;
  9389. int ret;
  9390. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  9391. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  9392. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  9393. hena |= i40e_pf_get_default_rss_hena(pf);
  9394. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  9395. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  9396. /* Determine the RSS table size based on the hardware capabilities */
  9397. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  9398. reg_val = (pf->rss_table_size == 512) ?
  9399. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  9400. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  9401. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  9402. /* Determine the RSS size of the VSI */
  9403. if (!vsi->rss_size) {
  9404. u16 qcount;
  9405. /* If the firmware does something weird during VSI init, we
  9406. * could end up with zero TCs. Check for that to avoid
  9407. * divide-by-zero. It probably won't pass traffic, but it also
  9408. * won't panic.
  9409. */
  9410. qcount = vsi->num_queue_pairs /
  9411. (vsi->tc_config.numtc ? vsi->tc_config.numtc : 1);
  9412. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9413. }
  9414. if (!vsi->rss_size)
  9415. return -EINVAL;
  9416. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  9417. if (!lut)
  9418. return -ENOMEM;
  9419. /* Use user configured lut if there is one, otherwise use default */
  9420. if (vsi->rss_lut_user)
  9421. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  9422. else
  9423. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  9424. /* Use user configured hash key if there is one, otherwise
  9425. * use default.
  9426. */
  9427. if (vsi->rss_hkey_user)
  9428. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  9429. else
  9430. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  9431. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  9432. kfree(lut);
  9433. return ret;
  9434. }
  9435. /**
  9436. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  9437. * @pf: board private structure
  9438. * @queue_count: the requested queue count for rss.
  9439. *
  9440. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  9441. * count which may be different from the requested queue count.
  9442. * Note: expects to be called while under rtnl_lock()
  9443. **/
  9444. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  9445. {
  9446. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9447. int new_rss_size;
  9448. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  9449. return 0;
  9450. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  9451. if (queue_count != vsi->num_queue_pairs) {
  9452. u16 qcount;
  9453. vsi->req_queue_pairs = queue_count;
  9454. i40e_prep_for_reset(pf, true);
  9455. pf->alloc_rss_size = new_rss_size;
  9456. i40e_reset_and_rebuild(pf, true, true);
  9457. /* Discard the user configured hash keys and lut, if less
  9458. * queues are enabled.
  9459. */
  9460. if (queue_count < vsi->rss_size) {
  9461. i40e_clear_rss_config_user(vsi);
  9462. dev_dbg(&pf->pdev->dev,
  9463. "discard user configured hash keys and lut\n");
  9464. }
  9465. /* Reset vsi->rss_size, as number of enabled queues changed */
  9466. qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
  9467. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9468. i40e_pf_config_rss(pf);
  9469. }
  9470. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  9471. vsi->req_queue_pairs, pf->rss_size_max);
  9472. return pf->alloc_rss_size;
  9473. }
  9474. /**
  9475. * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
  9476. * @pf: board private structure
  9477. **/
  9478. i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
  9479. {
  9480. i40e_status status;
  9481. bool min_valid, max_valid;
  9482. u32 max_bw, min_bw;
  9483. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  9484. &min_valid, &max_valid);
  9485. if (!status) {
  9486. if (min_valid)
  9487. pf->min_bw = min_bw;
  9488. if (max_valid)
  9489. pf->max_bw = max_bw;
  9490. }
  9491. return status;
  9492. }
  9493. /**
  9494. * i40e_set_partition_bw_setting - Set BW settings for this PF partition
  9495. * @pf: board private structure
  9496. **/
  9497. i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
  9498. {
  9499. struct i40e_aqc_configure_partition_bw_data bw_data;
  9500. i40e_status status;
  9501. /* Set the valid bit for this PF */
  9502. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  9503. bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
  9504. bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
  9505. /* Set the new bandwidths */
  9506. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  9507. return status;
  9508. }
  9509. /**
  9510. * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
  9511. * @pf: board private structure
  9512. **/
  9513. i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
  9514. {
  9515. /* Commit temporary BW setting to permanent NVM image */
  9516. enum i40e_admin_queue_err last_aq_status;
  9517. i40e_status ret;
  9518. u16 nvm_word;
  9519. if (pf->hw.partition_id != 1) {
  9520. dev_info(&pf->pdev->dev,
  9521. "Commit BW only works on partition 1! This is partition %d",
  9522. pf->hw.partition_id);
  9523. ret = I40E_NOT_SUPPORTED;
  9524. goto bw_commit_out;
  9525. }
  9526. /* Acquire NVM for read access */
  9527. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  9528. last_aq_status = pf->hw.aq.asq_last_status;
  9529. if (ret) {
  9530. dev_info(&pf->pdev->dev,
  9531. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  9532. i40e_stat_str(&pf->hw, ret),
  9533. i40e_aq_str(&pf->hw, last_aq_status));
  9534. goto bw_commit_out;
  9535. }
  9536. /* Read word 0x10 of NVM - SW compatibility word 1 */
  9537. ret = i40e_aq_read_nvm(&pf->hw,
  9538. I40E_SR_NVM_CONTROL_WORD,
  9539. 0x10, sizeof(nvm_word), &nvm_word,
  9540. false, NULL);
  9541. /* Save off last admin queue command status before releasing
  9542. * the NVM
  9543. */
  9544. last_aq_status = pf->hw.aq.asq_last_status;
  9545. i40e_release_nvm(&pf->hw);
  9546. if (ret) {
  9547. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  9548. i40e_stat_str(&pf->hw, ret),
  9549. i40e_aq_str(&pf->hw, last_aq_status));
  9550. goto bw_commit_out;
  9551. }
  9552. /* Wait a bit for NVM release to complete */
  9553. msleep(50);
  9554. /* Acquire NVM for write access */
  9555. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  9556. last_aq_status = pf->hw.aq.asq_last_status;
  9557. if (ret) {
  9558. dev_info(&pf->pdev->dev,
  9559. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  9560. i40e_stat_str(&pf->hw, ret),
  9561. i40e_aq_str(&pf->hw, last_aq_status));
  9562. goto bw_commit_out;
  9563. }
  9564. /* Write it back out unchanged to initiate update NVM,
  9565. * which will force a write of the shadow (alt) RAM to
  9566. * the NVM - thus storing the bandwidth values permanently.
  9567. */
  9568. ret = i40e_aq_update_nvm(&pf->hw,
  9569. I40E_SR_NVM_CONTROL_WORD,
  9570. 0x10, sizeof(nvm_word),
  9571. &nvm_word, true, 0, NULL);
  9572. /* Save off last admin queue command status before releasing
  9573. * the NVM
  9574. */
  9575. last_aq_status = pf->hw.aq.asq_last_status;
  9576. i40e_release_nvm(&pf->hw);
  9577. if (ret)
  9578. dev_info(&pf->pdev->dev,
  9579. "BW settings NOT SAVED, err %s aq_err %s\n",
  9580. i40e_stat_str(&pf->hw, ret),
  9581. i40e_aq_str(&pf->hw, last_aq_status));
  9582. bw_commit_out:
  9583. return ret;
  9584. }
  9585. /**
  9586. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  9587. * @pf: board private structure to initialize
  9588. *
  9589. * i40e_sw_init initializes the Adapter private data structure.
  9590. * Fields are initialized based on PCI device information and
  9591. * OS network device settings (MTU size).
  9592. **/
  9593. static int i40e_sw_init(struct i40e_pf *pf)
  9594. {
  9595. int err = 0;
  9596. int size;
  9597. /* Set default capability flags */
  9598. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  9599. I40E_FLAG_MSI_ENABLED |
  9600. I40E_FLAG_MSIX_ENABLED;
  9601. /* Set default ITR */
  9602. pf->rx_itr_default = I40E_ITR_RX_DEF;
  9603. pf->tx_itr_default = I40E_ITR_TX_DEF;
  9604. /* Depending on PF configurations, it is possible that the RSS
  9605. * maximum might end up larger than the available queues
  9606. */
  9607. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  9608. pf->alloc_rss_size = 1;
  9609. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  9610. pf->rss_size_max = min_t(int, pf->rss_size_max,
  9611. pf->hw.func_caps.num_tx_qp);
  9612. if (pf->hw.func_caps.rss) {
  9613. pf->flags |= I40E_FLAG_RSS_ENABLED;
  9614. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  9615. num_online_cpus());
  9616. }
  9617. /* MFP mode enabled */
  9618. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  9619. pf->flags |= I40E_FLAG_MFP_ENABLED;
  9620. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  9621. if (i40e_get_partition_bw_setting(pf)) {
  9622. dev_warn(&pf->pdev->dev,
  9623. "Could not get partition bw settings\n");
  9624. } else {
  9625. dev_info(&pf->pdev->dev,
  9626. "Partition BW Min = %8.8x, Max = %8.8x\n",
  9627. pf->min_bw, pf->max_bw);
  9628. /* nudge the Tx scheduler */
  9629. i40e_set_partition_bw_setting(pf);
  9630. }
  9631. }
  9632. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  9633. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  9634. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  9635. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  9636. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  9637. pf->hw.num_partitions > 1)
  9638. dev_info(&pf->pdev->dev,
  9639. "Flow Director Sideband mode Disabled in MFP mode\n");
  9640. else
  9641. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9642. pf->fdir_pf_filter_count =
  9643. pf->hw.func_caps.fd_filters_guaranteed;
  9644. pf->hw.fdir_shared_filter_count =
  9645. pf->hw.func_caps.fd_filters_best_effort;
  9646. }
  9647. if (pf->hw.mac.type == I40E_MAC_X722) {
  9648. pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
  9649. I40E_HW_128_QP_RSS_CAPABLE |
  9650. I40E_HW_ATR_EVICT_CAPABLE |
  9651. I40E_HW_WB_ON_ITR_CAPABLE |
  9652. I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  9653. I40E_HW_NO_PCI_LINK_CHECK |
  9654. I40E_HW_USE_SET_LLDP_MIB |
  9655. I40E_HW_GENEVE_OFFLOAD_CAPABLE |
  9656. I40E_HW_PTP_L4_CAPABLE |
  9657. I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
  9658. I40E_HW_OUTER_UDP_CSUM_CAPABLE);
  9659. #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
  9660. if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
  9661. I40E_FDEVICT_PCTYPE_DEFAULT) {
  9662. dev_warn(&pf->pdev->dev,
  9663. "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
  9664. pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
  9665. }
  9666. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  9667. ((pf->hw.aq.api_maj_ver == 1) &&
  9668. (pf->hw.aq.api_min_ver > 4))) {
  9669. /* Supported in FW API version higher than 1.4 */
  9670. pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
  9671. }
  9672. /* Enable HW ATR eviction if possible */
  9673. if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
  9674. pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
  9675. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9676. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  9677. (pf->hw.aq.fw_maj_ver < 4))) {
  9678. pf->hw_features |= I40E_HW_RESTART_AUTONEG;
  9679. /* No DCB support for FW < v4.33 */
  9680. pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
  9681. }
  9682. /* Disable FW LLDP if FW < v4.3 */
  9683. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9684. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  9685. (pf->hw.aq.fw_maj_ver < 4)))
  9686. pf->hw_features |= I40E_HW_STOP_FW_LLDP;
  9687. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  9688. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9689. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  9690. (pf->hw.aq.fw_maj_ver >= 5)))
  9691. pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
  9692. /* Enable PTP L4 if FW > v6.0 */
  9693. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9694. pf->hw.aq.fw_maj_ver >= 6)
  9695. pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
  9696. if (pf->hw.func_caps.vmdq && num_online_cpus() != 1) {
  9697. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  9698. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  9699. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  9700. }
  9701. if (pf->hw.func_caps.iwarp && num_online_cpus() != 1) {
  9702. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  9703. /* IWARP needs one extra vector for CQP just like MISC.*/
  9704. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  9705. }
  9706. #ifdef CONFIG_PCI_IOV
  9707. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  9708. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  9709. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  9710. pf->num_req_vfs = min_t(int,
  9711. pf->hw.func_caps.num_vfs,
  9712. I40E_MAX_VF_COUNT);
  9713. }
  9714. #endif /* CONFIG_PCI_IOV */
  9715. pf->eeprom_version = 0xDEAD;
  9716. pf->lan_veb = I40E_NO_VEB;
  9717. pf->lan_vsi = I40E_NO_VSI;
  9718. /* By default FW has this off for performance reasons */
  9719. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  9720. /* set up queue assignment tracking */
  9721. size = sizeof(struct i40e_lump_tracking)
  9722. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  9723. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  9724. if (!pf->qp_pile) {
  9725. err = -ENOMEM;
  9726. goto sw_init_done;
  9727. }
  9728. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  9729. pf->qp_pile->search_hint = 0;
  9730. pf->tx_timeout_recovery_level = 1;
  9731. mutex_init(&pf->switch_mutex);
  9732. sw_init_done:
  9733. return err;
  9734. }
  9735. /**
  9736. * i40e_set_ntuple - set the ntuple feature flag and take action
  9737. * @pf: board private structure to initialize
  9738. * @features: the feature set that the stack is suggesting
  9739. *
  9740. * returns a bool to indicate if reset needs to happen
  9741. **/
  9742. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  9743. {
  9744. bool need_reset = false;
  9745. /* Check if Flow Director n-tuple support was enabled or disabled. If
  9746. * the state changed, we need to reset.
  9747. */
  9748. if (features & NETIF_F_NTUPLE) {
  9749. /* Enable filters and mark for reset */
  9750. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  9751. need_reset = true;
  9752. /* enable FD_SB only if there is MSI-X vector and no cloud
  9753. * filters exist
  9754. */
  9755. if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
  9756. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9757. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  9758. }
  9759. } else {
  9760. /* turn off filters, mark for reset and clear SW filter list */
  9761. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9762. need_reset = true;
  9763. i40e_fdir_filter_exit(pf);
  9764. }
  9765. pf->flags &= ~(I40E_FLAG_FD_SB_ENABLED |
  9766. I40E_FLAG_FD_SB_AUTO_DISABLED);
  9767. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9768. /* reset fd counters */
  9769. pf->fd_add_err = 0;
  9770. pf->fd_atr_cnt = 0;
  9771. /* if ATR was auto disabled it can be re-enabled. */
  9772. if (pf->flags & I40E_FLAG_FD_ATR_AUTO_DISABLED) {
  9773. pf->flags &= ~I40E_FLAG_FD_ATR_AUTO_DISABLED;
  9774. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  9775. (I40E_DEBUG_FD & pf->hw.debug_mask))
  9776. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  9777. }
  9778. }
  9779. return need_reset;
  9780. }
  9781. /**
  9782. * i40e_clear_rss_lut - clear the rx hash lookup table
  9783. * @vsi: the VSI being configured
  9784. **/
  9785. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  9786. {
  9787. struct i40e_pf *pf = vsi->back;
  9788. struct i40e_hw *hw = &pf->hw;
  9789. u16 vf_id = vsi->vf_id;
  9790. u8 i;
  9791. if (vsi->type == I40E_VSI_MAIN) {
  9792. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9793. wr32(hw, I40E_PFQF_HLUT(i), 0);
  9794. } else if (vsi->type == I40E_VSI_SRIOV) {
  9795. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9796. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  9797. } else {
  9798. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9799. }
  9800. }
  9801. /**
  9802. * i40e_set_features - set the netdev feature flags
  9803. * @netdev: ptr to the netdev being adjusted
  9804. * @features: the feature set that the stack is suggesting
  9805. * Note: expects to be called while under rtnl_lock()
  9806. **/
  9807. static int i40e_set_features(struct net_device *netdev,
  9808. netdev_features_t features)
  9809. {
  9810. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9811. struct i40e_vsi *vsi = np->vsi;
  9812. struct i40e_pf *pf = vsi->back;
  9813. bool need_reset;
  9814. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  9815. i40e_pf_config_rss(pf);
  9816. else if (!(features & NETIF_F_RXHASH) &&
  9817. netdev->features & NETIF_F_RXHASH)
  9818. i40e_clear_rss_lut(vsi);
  9819. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  9820. i40e_vlan_stripping_enable(vsi);
  9821. else
  9822. i40e_vlan_stripping_disable(vsi);
  9823. if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
  9824. dev_err(&pf->pdev->dev,
  9825. "Offloaded tc filters active, can't turn hw_tc_offload off");
  9826. return -EINVAL;
  9827. }
  9828. need_reset = i40e_set_ntuple(pf, features);
  9829. if (need_reset)
  9830. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  9831. return 0;
  9832. }
  9833. /**
  9834. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  9835. * @pf: board private structure
  9836. * @port: The UDP port to look up
  9837. *
  9838. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  9839. **/
  9840. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
  9841. {
  9842. u8 i;
  9843. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  9844. if (pf->udp_ports[i].port == port)
  9845. return i;
  9846. }
  9847. return i;
  9848. }
  9849. /**
  9850. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  9851. * @netdev: This physical port's netdev
  9852. * @ti: Tunnel endpoint information
  9853. **/
  9854. static void i40e_udp_tunnel_add(struct net_device *netdev,
  9855. struct udp_tunnel_info *ti)
  9856. {
  9857. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9858. struct i40e_vsi *vsi = np->vsi;
  9859. struct i40e_pf *pf = vsi->back;
  9860. u16 port = ntohs(ti->port);
  9861. u8 next_idx;
  9862. u8 idx;
  9863. idx = i40e_get_udp_port_idx(pf, port);
  9864. /* Check if port already exists */
  9865. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9866. netdev_info(netdev, "port %d already offloaded\n", port);
  9867. return;
  9868. }
  9869. /* Now check if there is space to add the new port */
  9870. next_idx = i40e_get_udp_port_idx(pf, 0);
  9871. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9872. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  9873. port);
  9874. return;
  9875. }
  9876. switch (ti->type) {
  9877. case UDP_TUNNEL_TYPE_VXLAN:
  9878. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  9879. break;
  9880. case UDP_TUNNEL_TYPE_GENEVE:
  9881. if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE))
  9882. return;
  9883. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  9884. break;
  9885. default:
  9886. return;
  9887. }
  9888. /* New port: add it and mark its index in the bitmap */
  9889. pf->udp_ports[next_idx].port = port;
  9890. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  9891. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  9892. }
  9893. /**
  9894. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  9895. * @netdev: This physical port's netdev
  9896. * @ti: Tunnel endpoint information
  9897. **/
  9898. static void i40e_udp_tunnel_del(struct net_device *netdev,
  9899. struct udp_tunnel_info *ti)
  9900. {
  9901. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9902. struct i40e_vsi *vsi = np->vsi;
  9903. struct i40e_pf *pf = vsi->back;
  9904. u16 port = ntohs(ti->port);
  9905. u8 idx;
  9906. idx = i40e_get_udp_port_idx(pf, port);
  9907. /* Check if port already exists */
  9908. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  9909. goto not_found;
  9910. switch (ti->type) {
  9911. case UDP_TUNNEL_TYPE_VXLAN:
  9912. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  9913. goto not_found;
  9914. break;
  9915. case UDP_TUNNEL_TYPE_GENEVE:
  9916. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  9917. goto not_found;
  9918. break;
  9919. default:
  9920. goto not_found;
  9921. }
  9922. /* if port exists, set it to 0 (mark for deletion)
  9923. * and make it pending
  9924. */
  9925. pf->udp_ports[idx].port = 0;
  9926. pf->pending_udp_bitmap |= BIT_ULL(idx);
  9927. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  9928. return;
  9929. not_found:
  9930. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  9931. port);
  9932. }
  9933. static int i40e_get_phys_port_id(struct net_device *netdev,
  9934. struct netdev_phys_item_id *ppid)
  9935. {
  9936. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9937. struct i40e_pf *pf = np->vsi->back;
  9938. struct i40e_hw *hw = &pf->hw;
  9939. if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
  9940. return -EOPNOTSUPP;
  9941. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  9942. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  9943. return 0;
  9944. }
  9945. /**
  9946. * i40e_ndo_fdb_add - add an entry to the hardware database
  9947. * @ndm: the input from the stack
  9948. * @tb: pointer to array of nladdr (unused)
  9949. * @dev: the net device pointer
  9950. * @addr: the MAC address entry being added
  9951. * @flags: instructions from stack about fdb operation
  9952. */
  9953. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  9954. struct net_device *dev,
  9955. const unsigned char *addr, u16 vid,
  9956. u16 flags)
  9957. {
  9958. struct i40e_netdev_priv *np = netdev_priv(dev);
  9959. struct i40e_pf *pf = np->vsi->back;
  9960. int err = 0;
  9961. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  9962. return -EOPNOTSUPP;
  9963. if (vid) {
  9964. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  9965. return -EINVAL;
  9966. }
  9967. /* Hardware does not support aging addresses so if a
  9968. * ndm_state is given only allow permanent addresses
  9969. */
  9970. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  9971. netdev_info(dev, "FDB only supports static addresses\n");
  9972. return -EINVAL;
  9973. }
  9974. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  9975. err = dev_uc_add_excl(dev, addr);
  9976. else if (is_multicast_ether_addr(addr))
  9977. err = dev_mc_add_excl(dev, addr);
  9978. else
  9979. err = -EINVAL;
  9980. /* Only return duplicate errors if NLM_F_EXCL is set */
  9981. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  9982. err = 0;
  9983. return err;
  9984. }
  9985. /**
  9986. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  9987. * @dev: the netdev being configured
  9988. * @nlh: RTNL message
  9989. *
  9990. * Inserts a new hardware bridge if not already created and
  9991. * enables the bridging mode requested (VEB or VEPA). If the
  9992. * hardware bridge has already been inserted and the request
  9993. * is to change the mode then that requires a PF reset to
  9994. * allow rebuild of the components with required hardware
  9995. * bridge mode enabled.
  9996. *
  9997. * Note: expects to be called while under rtnl_lock()
  9998. **/
  9999. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  10000. struct nlmsghdr *nlh,
  10001. u16 flags)
  10002. {
  10003. struct i40e_netdev_priv *np = netdev_priv(dev);
  10004. struct i40e_vsi *vsi = np->vsi;
  10005. struct i40e_pf *pf = vsi->back;
  10006. struct i40e_veb *veb = NULL;
  10007. struct nlattr *attr, *br_spec;
  10008. int i, rem;
  10009. /* Only for PF VSI for now */
  10010. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10011. return -EOPNOTSUPP;
  10012. /* Find the HW bridge for PF VSI */
  10013. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10014. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10015. veb = pf->veb[i];
  10016. }
  10017. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  10018. nla_for_each_nested(attr, br_spec, rem) {
  10019. __u16 mode;
  10020. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  10021. continue;
  10022. mode = nla_get_u16(attr);
  10023. if ((mode != BRIDGE_MODE_VEPA) &&
  10024. (mode != BRIDGE_MODE_VEB))
  10025. return -EINVAL;
  10026. /* Insert a new HW bridge */
  10027. if (!veb) {
  10028. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10029. vsi->tc_config.enabled_tc);
  10030. if (veb) {
  10031. veb->bridge_mode = mode;
  10032. i40e_config_bridge_mode(veb);
  10033. } else {
  10034. /* No Bridge HW offload available */
  10035. return -ENOENT;
  10036. }
  10037. break;
  10038. } else if (mode != veb->bridge_mode) {
  10039. /* Existing HW bridge but different mode needs reset */
  10040. veb->bridge_mode = mode;
  10041. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  10042. if (mode == BRIDGE_MODE_VEB)
  10043. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  10044. else
  10045. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10046. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  10047. break;
  10048. }
  10049. }
  10050. return 0;
  10051. }
  10052. /**
  10053. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  10054. * @skb: skb buff
  10055. * @pid: process id
  10056. * @seq: RTNL message seq #
  10057. * @dev: the netdev being configured
  10058. * @filter_mask: unused
  10059. * @nlflags: netlink flags passed in
  10060. *
  10061. * Return the mode in which the hardware bridge is operating in
  10062. * i.e VEB or VEPA.
  10063. **/
  10064. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  10065. struct net_device *dev,
  10066. u32 __always_unused filter_mask,
  10067. int nlflags)
  10068. {
  10069. struct i40e_netdev_priv *np = netdev_priv(dev);
  10070. struct i40e_vsi *vsi = np->vsi;
  10071. struct i40e_pf *pf = vsi->back;
  10072. struct i40e_veb *veb = NULL;
  10073. int i;
  10074. /* Only for PF VSI for now */
  10075. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10076. return -EOPNOTSUPP;
  10077. /* Find the HW bridge for the PF VSI */
  10078. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10079. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10080. veb = pf->veb[i];
  10081. }
  10082. if (!veb)
  10083. return 0;
  10084. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  10085. 0, 0, nlflags, filter_mask, NULL);
  10086. }
  10087. /**
  10088. * i40e_features_check - Validate encapsulated packet conforms to limits
  10089. * @skb: skb buff
  10090. * @dev: This physical port's netdev
  10091. * @features: Offload features that the stack believes apply
  10092. **/
  10093. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  10094. struct net_device *dev,
  10095. netdev_features_t features)
  10096. {
  10097. size_t len;
  10098. /* No point in doing any of this if neither checksum nor GSO are
  10099. * being requested for this frame. We can rule out both by just
  10100. * checking for CHECKSUM_PARTIAL
  10101. */
  10102. if (skb->ip_summed != CHECKSUM_PARTIAL)
  10103. return features;
  10104. /* We cannot support GSO if the MSS is going to be less than
  10105. * 64 bytes. If it is then we need to drop support for GSO.
  10106. */
  10107. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  10108. features &= ~NETIF_F_GSO_MASK;
  10109. /* MACLEN can support at most 63 words */
  10110. len = skb_network_header(skb) - skb->data;
  10111. if (len & ~(63 * 2))
  10112. goto out_err;
  10113. /* IPLEN and EIPLEN can support at most 127 dwords */
  10114. len = skb_transport_header(skb) - skb_network_header(skb);
  10115. if (len & ~(127 * 4))
  10116. goto out_err;
  10117. if (skb->encapsulation) {
  10118. /* L4TUNLEN can support 127 words */
  10119. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  10120. if (len & ~(127 * 2))
  10121. goto out_err;
  10122. /* IPLEN can support at most 127 dwords */
  10123. len = skb_inner_transport_header(skb) -
  10124. skb_inner_network_header(skb);
  10125. if (len & ~(127 * 4))
  10126. goto out_err;
  10127. }
  10128. /* No need to validate L4LEN as TCP is the only protocol with a
  10129. * a flexible value and we support all possible values supported
  10130. * by TCP, which is at most 15 dwords
  10131. */
  10132. return features;
  10133. out_err:
  10134. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  10135. }
  10136. /**
  10137. * i40e_xdp_setup - add/remove an XDP program
  10138. * @vsi: VSI to changed
  10139. * @prog: XDP program
  10140. **/
  10141. static int i40e_xdp_setup(struct i40e_vsi *vsi,
  10142. struct bpf_prog *prog)
  10143. {
  10144. int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  10145. struct i40e_pf *pf = vsi->back;
  10146. struct bpf_prog *old_prog;
  10147. bool need_reset;
  10148. int i;
  10149. /* Don't allow frames that span over multiple buffers */
  10150. if (frame_size > vsi->rx_buf_len)
  10151. return -EINVAL;
  10152. if (!i40e_enabled_xdp_vsi(vsi) && !prog)
  10153. return 0;
  10154. /* When turning XDP on->off/off->on we reset and rebuild the rings. */
  10155. need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
  10156. if (need_reset)
  10157. i40e_prep_for_reset(pf, true);
  10158. old_prog = xchg(&vsi->xdp_prog, prog);
  10159. if (need_reset)
  10160. i40e_reset_and_rebuild(pf, true, true);
  10161. for (i = 0; i < vsi->num_queue_pairs; i++)
  10162. WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
  10163. if (old_prog)
  10164. bpf_prog_put(old_prog);
  10165. return 0;
  10166. }
  10167. /**
  10168. * i40e_xdp - implements ndo_bpf for i40e
  10169. * @dev: netdevice
  10170. * @xdp: XDP command
  10171. **/
  10172. static int i40e_xdp(struct net_device *dev,
  10173. struct netdev_bpf *xdp)
  10174. {
  10175. struct i40e_netdev_priv *np = netdev_priv(dev);
  10176. struct i40e_vsi *vsi = np->vsi;
  10177. if (vsi->type != I40E_VSI_MAIN)
  10178. return -EINVAL;
  10179. switch (xdp->command) {
  10180. case XDP_SETUP_PROG:
  10181. return i40e_xdp_setup(vsi, xdp->prog);
  10182. case XDP_QUERY_PROG:
  10183. xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
  10184. xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
  10185. return 0;
  10186. default:
  10187. return -EINVAL;
  10188. }
  10189. }
  10190. static const struct net_device_ops i40e_netdev_ops = {
  10191. .ndo_open = i40e_open,
  10192. .ndo_stop = i40e_close,
  10193. .ndo_start_xmit = i40e_lan_xmit_frame,
  10194. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  10195. .ndo_set_rx_mode = i40e_set_rx_mode,
  10196. .ndo_validate_addr = eth_validate_addr,
  10197. .ndo_set_mac_address = i40e_set_mac,
  10198. .ndo_change_mtu = i40e_change_mtu,
  10199. .ndo_do_ioctl = i40e_ioctl,
  10200. .ndo_tx_timeout = i40e_tx_timeout,
  10201. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  10202. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  10203. #ifdef CONFIG_NET_POLL_CONTROLLER
  10204. .ndo_poll_controller = i40e_netpoll,
  10205. #endif
  10206. .ndo_setup_tc = __i40e_setup_tc,
  10207. .ndo_set_features = i40e_set_features,
  10208. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  10209. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  10210. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  10211. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  10212. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  10213. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  10214. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  10215. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  10216. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  10217. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  10218. .ndo_fdb_add = i40e_ndo_fdb_add,
  10219. .ndo_features_check = i40e_features_check,
  10220. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  10221. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  10222. .ndo_bpf = i40e_xdp,
  10223. };
  10224. /**
  10225. * i40e_config_netdev - Setup the netdev flags
  10226. * @vsi: the VSI being configured
  10227. *
  10228. * Returns 0 on success, negative value on failure
  10229. **/
  10230. static int i40e_config_netdev(struct i40e_vsi *vsi)
  10231. {
  10232. struct i40e_pf *pf = vsi->back;
  10233. struct i40e_hw *hw = &pf->hw;
  10234. struct i40e_netdev_priv *np;
  10235. struct net_device *netdev;
  10236. u8 broadcast[ETH_ALEN];
  10237. u8 mac_addr[ETH_ALEN];
  10238. int etherdev_size;
  10239. netdev_features_t hw_enc_features;
  10240. netdev_features_t hw_features;
  10241. etherdev_size = sizeof(struct i40e_netdev_priv);
  10242. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  10243. if (!netdev)
  10244. return -ENOMEM;
  10245. vsi->netdev = netdev;
  10246. np = netdev_priv(netdev);
  10247. np->vsi = vsi;
  10248. hw_enc_features = NETIF_F_SG |
  10249. NETIF_F_IP_CSUM |
  10250. NETIF_F_IPV6_CSUM |
  10251. NETIF_F_HIGHDMA |
  10252. NETIF_F_SOFT_FEATURES |
  10253. NETIF_F_TSO |
  10254. NETIF_F_TSO_ECN |
  10255. NETIF_F_TSO6 |
  10256. NETIF_F_GSO_GRE |
  10257. NETIF_F_GSO_GRE_CSUM |
  10258. NETIF_F_GSO_PARTIAL |
  10259. NETIF_F_GSO_UDP_TUNNEL |
  10260. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  10261. NETIF_F_SCTP_CRC |
  10262. NETIF_F_RXHASH |
  10263. NETIF_F_RXCSUM |
  10264. 0;
  10265. if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
  10266. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  10267. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  10268. netdev->hw_enc_features |= hw_enc_features;
  10269. /* record features VLANs can make use of */
  10270. netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
  10271. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  10272. netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
  10273. hw_features = hw_enc_features |
  10274. NETIF_F_HW_VLAN_CTAG_TX |
  10275. NETIF_F_HW_VLAN_CTAG_RX;
  10276. netdev->hw_features |= hw_features;
  10277. netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  10278. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  10279. if (vsi->type == I40E_VSI_MAIN) {
  10280. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  10281. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  10282. /* The following steps are necessary for two reasons. First,
  10283. * some older NVM configurations load a default MAC-VLAN
  10284. * filter that will accept any tagged packet, and we want to
  10285. * replace this with a normal filter. Additionally, it is
  10286. * possible our MAC address was provided by the platform using
  10287. * Open Firmware or similar.
  10288. *
  10289. * Thus, we need to remove the default filter and install one
  10290. * specific to the MAC address.
  10291. */
  10292. i40e_rm_default_mac_filter(vsi, mac_addr);
  10293. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10294. i40e_add_mac_filter(vsi, mac_addr);
  10295. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10296. } else {
  10297. /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
  10298. * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
  10299. * the end, which is 4 bytes long, so force truncation of the
  10300. * original name by IFNAMSIZ - 4
  10301. */
  10302. snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
  10303. IFNAMSIZ - 4,
  10304. pf->vsi[pf->lan_vsi]->netdev->name);
  10305. random_ether_addr(mac_addr);
  10306. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10307. i40e_add_mac_filter(vsi, mac_addr);
  10308. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10309. }
  10310. /* Add the broadcast filter so that we initially will receive
  10311. * broadcast packets. Note that when a new VLAN is first added the
  10312. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  10313. * specific filters as part of transitioning into "vlan" operation.
  10314. * When more VLANs are added, the driver will copy each existing MAC
  10315. * filter and add it for the new VLAN.
  10316. *
  10317. * Broadcast filters are handled specially by
  10318. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  10319. * promiscuous bit instead of adding this directly as a MAC/VLAN
  10320. * filter. The subtask will update the correct broadcast promiscuous
  10321. * bits as VLANs become active or inactive.
  10322. */
  10323. eth_broadcast_addr(broadcast);
  10324. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10325. i40e_add_mac_filter(vsi, broadcast);
  10326. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10327. ether_addr_copy(netdev->dev_addr, mac_addr);
  10328. ether_addr_copy(netdev->perm_addr, mac_addr);
  10329. netdev->priv_flags |= IFF_UNICAST_FLT;
  10330. netdev->priv_flags |= IFF_SUPP_NOFCS;
  10331. /* Setup netdev TC information */
  10332. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  10333. netdev->netdev_ops = &i40e_netdev_ops;
  10334. netdev->watchdog_timeo = 5 * HZ;
  10335. i40e_set_ethtool_ops(netdev);
  10336. /* MTU range: 68 - 9706 */
  10337. netdev->min_mtu = ETH_MIN_MTU;
  10338. netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
  10339. return 0;
  10340. }
  10341. /**
  10342. * i40e_vsi_delete - Delete a VSI from the switch
  10343. * @vsi: the VSI being removed
  10344. *
  10345. * Returns 0 on success, negative value on failure
  10346. **/
  10347. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  10348. {
  10349. /* remove default VSI is not allowed */
  10350. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  10351. return;
  10352. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  10353. }
  10354. /**
  10355. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  10356. * @vsi: the VSI being queried
  10357. *
  10358. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  10359. **/
  10360. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  10361. {
  10362. struct i40e_veb *veb;
  10363. struct i40e_pf *pf = vsi->back;
  10364. /* Uplink is not a bridge so default to VEB */
  10365. if (vsi->veb_idx == I40E_NO_VEB)
  10366. return 1;
  10367. veb = pf->veb[vsi->veb_idx];
  10368. if (!veb) {
  10369. dev_info(&pf->pdev->dev,
  10370. "There is no veb associated with the bridge\n");
  10371. return -ENOENT;
  10372. }
  10373. /* Uplink is a bridge in VEPA mode */
  10374. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  10375. return 0;
  10376. } else {
  10377. /* Uplink is a bridge in VEB mode */
  10378. return 1;
  10379. }
  10380. /* VEPA is now default bridge, so return 0 */
  10381. return 0;
  10382. }
  10383. /**
  10384. * i40e_add_vsi - Add a VSI to the switch
  10385. * @vsi: the VSI being configured
  10386. *
  10387. * This initializes a VSI context depending on the VSI type to be added and
  10388. * passes it down to the add_vsi aq command.
  10389. **/
  10390. static int i40e_add_vsi(struct i40e_vsi *vsi)
  10391. {
  10392. int ret = -ENODEV;
  10393. struct i40e_pf *pf = vsi->back;
  10394. struct i40e_hw *hw = &pf->hw;
  10395. struct i40e_vsi_context ctxt;
  10396. struct i40e_mac_filter *f;
  10397. struct hlist_node *h;
  10398. int bkt;
  10399. u8 enabled_tc = 0x1; /* TC0 enabled */
  10400. int f_count = 0;
  10401. memset(&ctxt, 0, sizeof(ctxt));
  10402. switch (vsi->type) {
  10403. case I40E_VSI_MAIN:
  10404. /* The PF's main VSI is already setup as part of the
  10405. * device initialization, so we'll not bother with
  10406. * the add_vsi call, but we will retrieve the current
  10407. * VSI context.
  10408. */
  10409. ctxt.seid = pf->main_vsi_seid;
  10410. ctxt.pf_num = pf->hw.pf_id;
  10411. ctxt.vf_num = 0;
  10412. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  10413. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10414. if (ret) {
  10415. dev_info(&pf->pdev->dev,
  10416. "couldn't get PF vsi config, err %s aq_err %s\n",
  10417. i40e_stat_str(&pf->hw, ret),
  10418. i40e_aq_str(&pf->hw,
  10419. pf->hw.aq.asq_last_status));
  10420. return -ENOENT;
  10421. }
  10422. vsi->info = ctxt.info;
  10423. vsi->info.valid_sections = 0;
  10424. vsi->seid = ctxt.seid;
  10425. vsi->id = ctxt.vsi_number;
  10426. enabled_tc = i40e_pf_get_tc_map(pf);
  10427. /* Source pruning is enabled by default, so the flag is
  10428. * negative logic - if it's set, we need to fiddle with
  10429. * the VSI to disable source pruning.
  10430. */
  10431. if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
  10432. memset(&ctxt, 0, sizeof(ctxt));
  10433. ctxt.seid = pf->main_vsi_seid;
  10434. ctxt.pf_num = pf->hw.pf_id;
  10435. ctxt.vf_num = 0;
  10436. ctxt.info.valid_sections |=
  10437. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10438. ctxt.info.switch_id =
  10439. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  10440. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10441. if (ret) {
  10442. dev_info(&pf->pdev->dev,
  10443. "update vsi failed, err %s aq_err %s\n",
  10444. i40e_stat_str(&pf->hw, ret),
  10445. i40e_aq_str(&pf->hw,
  10446. pf->hw.aq.asq_last_status));
  10447. ret = -ENOENT;
  10448. goto err;
  10449. }
  10450. }
  10451. /* MFP mode setup queue map and update VSI */
  10452. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  10453. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  10454. memset(&ctxt, 0, sizeof(ctxt));
  10455. ctxt.seid = pf->main_vsi_seid;
  10456. ctxt.pf_num = pf->hw.pf_id;
  10457. ctxt.vf_num = 0;
  10458. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  10459. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10460. if (ret) {
  10461. dev_info(&pf->pdev->dev,
  10462. "update vsi failed, err %s aq_err %s\n",
  10463. i40e_stat_str(&pf->hw, ret),
  10464. i40e_aq_str(&pf->hw,
  10465. pf->hw.aq.asq_last_status));
  10466. ret = -ENOENT;
  10467. goto err;
  10468. }
  10469. /* update the local VSI info queue map */
  10470. i40e_vsi_update_queue_map(vsi, &ctxt);
  10471. vsi->info.valid_sections = 0;
  10472. } else {
  10473. /* Default/Main VSI is only enabled for TC0
  10474. * reconfigure it to enable all TCs that are
  10475. * available on the port in SFP mode.
  10476. * For MFP case the iSCSI PF would use this
  10477. * flow to enable LAN+iSCSI TC.
  10478. */
  10479. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  10480. if (ret) {
  10481. /* Single TC condition is not fatal,
  10482. * message and continue
  10483. */
  10484. dev_info(&pf->pdev->dev,
  10485. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  10486. enabled_tc,
  10487. i40e_stat_str(&pf->hw, ret),
  10488. i40e_aq_str(&pf->hw,
  10489. pf->hw.aq.asq_last_status));
  10490. }
  10491. }
  10492. break;
  10493. case I40E_VSI_FDIR:
  10494. ctxt.pf_num = hw->pf_id;
  10495. ctxt.vf_num = 0;
  10496. ctxt.uplink_seid = vsi->uplink_seid;
  10497. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10498. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10499. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  10500. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  10501. ctxt.info.valid_sections |=
  10502. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10503. ctxt.info.switch_id =
  10504. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10505. }
  10506. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10507. break;
  10508. case I40E_VSI_VMDQ2:
  10509. ctxt.pf_num = hw->pf_id;
  10510. ctxt.vf_num = 0;
  10511. ctxt.uplink_seid = vsi->uplink_seid;
  10512. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10513. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  10514. /* This VSI is connected to VEB so the switch_id
  10515. * should be set to zero by default.
  10516. */
  10517. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10518. ctxt.info.valid_sections |=
  10519. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10520. ctxt.info.switch_id =
  10521. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10522. }
  10523. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10524. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10525. break;
  10526. case I40E_VSI_SRIOV:
  10527. ctxt.pf_num = hw->pf_id;
  10528. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  10529. ctxt.uplink_seid = vsi->uplink_seid;
  10530. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10531. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  10532. /* This VSI is connected to VEB so the switch_id
  10533. * should be set to zero by default.
  10534. */
  10535. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10536. ctxt.info.valid_sections |=
  10537. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10538. ctxt.info.switch_id =
  10539. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10540. }
  10541. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  10542. ctxt.info.valid_sections |=
  10543. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  10544. ctxt.info.queueing_opt_flags |=
  10545. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  10546. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  10547. }
  10548. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  10549. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  10550. if (pf->vf[vsi->vf_id].spoofchk) {
  10551. ctxt.info.valid_sections |=
  10552. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  10553. ctxt.info.sec_flags |=
  10554. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  10555. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  10556. }
  10557. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10558. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10559. break;
  10560. case I40E_VSI_IWARP:
  10561. /* send down message to iWARP */
  10562. break;
  10563. default:
  10564. return -ENODEV;
  10565. }
  10566. if (vsi->type != I40E_VSI_MAIN) {
  10567. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  10568. if (ret) {
  10569. dev_info(&vsi->back->pdev->dev,
  10570. "add vsi failed, err %s aq_err %s\n",
  10571. i40e_stat_str(&pf->hw, ret),
  10572. i40e_aq_str(&pf->hw,
  10573. pf->hw.aq.asq_last_status));
  10574. ret = -ENOENT;
  10575. goto err;
  10576. }
  10577. vsi->info = ctxt.info;
  10578. vsi->info.valid_sections = 0;
  10579. vsi->seid = ctxt.seid;
  10580. vsi->id = ctxt.vsi_number;
  10581. }
  10582. vsi->active_filters = 0;
  10583. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  10584. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10585. /* If macvlan filters already exist, force them to get loaded */
  10586. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  10587. f->state = I40E_FILTER_NEW;
  10588. f_count++;
  10589. }
  10590. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10591. if (f_count) {
  10592. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  10593. pf->flags |= I40E_FLAG_FILTER_SYNC;
  10594. }
  10595. /* Update VSI BW information */
  10596. ret = i40e_vsi_get_bw_info(vsi);
  10597. if (ret) {
  10598. dev_info(&pf->pdev->dev,
  10599. "couldn't get vsi bw info, err %s aq_err %s\n",
  10600. i40e_stat_str(&pf->hw, ret),
  10601. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10602. /* VSI is already added so not tearing that up */
  10603. ret = 0;
  10604. }
  10605. err:
  10606. return ret;
  10607. }
  10608. /**
  10609. * i40e_vsi_release - Delete a VSI and free its resources
  10610. * @vsi: the VSI being removed
  10611. *
  10612. * Returns 0 on success or < 0 on error
  10613. **/
  10614. int i40e_vsi_release(struct i40e_vsi *vsi)
  10615. {
  10616. struct i40e_mac_filter *f;
  10617. struct hlist_node *h;
  10618. struct i40e_veb *veb = NULL;
  10619. struct i40e_pf *pf;
  10620. u16 uplink_seid;
  10621. int i, n, bkt;
  10622. pf = vsi->back;
  10623. /* release of a VEB-owner or last VSI is not allowed */
  10624. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  10625. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  10626. vsi->seid, vsi->uplink_seid);
  10627. return -ENODEV;
  10628. }
  10629. if (vsi == pf->vsi[pf->lan_vsi] &&
  10630. !test_bit(__I40E_DOWN, pf->state)) {
  10631. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  10632. return -ENODEV;
  10633. }
  10634. uplink_seid = vsi->uplink_seid;
  10635. if (vsi->type != I40E_VSI_SRIOV) {
  10636. if (vsi->netdev_registered) {
  10637. vsi->netdev_registered = false;
  10638. if (vsi->netdev) {
  10639. /* results in a call to i40e_close() */
  10640. unregister_netdev(vsi->netdev);
  10641. }
  10642. } else {
  10643. i40e_vsi_close(vsi);
  10644. }
  10645. i40e_vsi_disable_irq(vsi);
  10646. }
  10647. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10648. /* clear the sync flag on all filters */
  10649. if (vsi->netdev) {
  10650. __dev_uc_unsync(vsi->netdev, NULL);
  10651. __dev_mc_unsync(vsi->netdev, NULL);
  10652. }
  10653. /* make sure any remaining filters are marked for deletion */
  10654. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  10655. __i40e_del_filter(vsi, f);
  10656. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10657. i40e_sync_vsi_filters(vsi);
  10658. i40e_vsi_delete(vsi);
  10659. i40e_vsi_free_q_vectors(vsi);
  10660. if (vsi->netdev) {
  10661. free_netdev(vsi->netdev);
  10662. vsi->netdev = NULL;
  10663. }
  10664. i40e_vsi_clear_rings(vsi);
  10665. i40e_vsi_clear(vsi);
  10666. /* If this was the last thing on the VEB, except for the
  10667. * controlling VSI, remove the VEB, which puts the controlling
  10668. * VSI onto the next level down in the switch.
  10669. *
  10670. * Well, okay, there's one more exception here: don't remove
  10671. * the orphan VEBs yet. We'll wait for an explicit remove request
  10672. * from up the network stack.
  10673. */
  10674. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  10675. if (pf->vsi[i] &&
  10676. pf->vsi[i]->uplink_seid == uplink_seid &&
  10677. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  10678. n++; /* count the VSIs */
  10679. }
  10680. }
  10681. for (i = 0; i < I40E_MAX_VEB; i++) {
  10682. if (!pf->veb[i])
  10683. continue;
  10684. if (pf->veb[i]->uplink_seid == uplink_seid)
  10685. n++; /* count the VEBs */
  10686. if (pf->veb[i]->seid == uplink_seid)
  10687. veb = pf->veb[i];
  10688. }
  10689. if (n == 0 && veb && veb->uplink_seid != 0)
  10690. i40e_veb_release(veb);
  10691. return 0;
  10692. }
  10693. /**
  10694. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  10695. * @vsi: ptr to the VSI
  10696. *
  10697. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  10698. * corresponding SW VSI structure and initializes num_queue_pairs for the
  10699. * newly allocated VSI.
  10700. *
  10701. * Returns 0 on success or negative on failure
  10702. **/
  10703. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  10704. {
  10705. int ret = -ENOENT;
  10706. struct i40e_pf *pf = vsi->back;
  10707. if (vsi->q_vectors[0]) {
  10708. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  10709. vsi->seid);
  10710. return -EEXIST;
  10711. }
  10712. if (vsi->base_vector) {
  10713. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  10714. vsi->seid, vsi->base_vector);
  10715. return -EEXIST;
  10716. }
  10717. ret = i40e_vsi_alloc_q_vectors(vsi);
  10718. if (ret) {
  10719. dev_info(&pf->pdev->dev,
  10720. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  10721. vsi->num_q_vectors, vsi->seid, ret);
  10722. vsi->num_q_vectors = 0;
  10723. goto vector_setup_out;
  10724. }
  10725. /* In Legacy mode, we do not have to get any other vector since we
  10726. * piggyback on the misc/ICR0 for queue interrupts.
  10727. */
  10728. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  10729. return ret;
  10730. if (vsi->num_q_vectors)
  10731. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  10732. vsi->num_q_vectors, vsi->idx);
  10733. if (vsi->base_vector < 0) {
  10734. dev_info(&pf->pdev->dev,
  10735. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  10736. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  10737. i40e_vsi_free_q_vectors(vsi);
  10738. ret = -ENOENT;
  10739. goto vector_setup_out;
  10740. }
  10741. vector_setup_out:
  10742. return ret;
  10743. }
  10744. /**
  10745. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  10746. * @vsi: pointer to the vsi.
  10747. *
  10748. * This re-allocates a vsi's queue resources.
  10749. *
  10750. * Returns pointer to the successfully allocated and configured VSI sw struct
  10751. * on success, otherwise returns NULL on failure.
  10752. **/
  10753. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  10754. {
  10755. u16 alloc_queue_pairs;
  10756. struct i40e_pf *pf;
  10757. u8 enabled_tc;
  10758. int ret;
  10759. if (!vsi)
  10760. return NULL;
  10761. pf = vsi->back;
  10762. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  10763. i40e_vsi_clear_rings(vsi);
  10764. i40e_vsi_free_arrays(vsi, false);
  10765. i40e_set_num_rings_in_vsi(vsi);
  10766. ret = i40e_vsi_alloc_arrays(vsi, false);
  10767. if (ret)
  10768. goto err_vsi;
  10769. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10770. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10771. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10772. if (ret < 0) {
  10773. dev_info(&pf->pdev->dev,
  10774. "failed to get tracking for %d queues for VSI %d err %d\n",
  10775. alloc_queue_pairs, vsi->seid, ret);
  10776. goto err_vsi;
  10777. }
  10778. vsi->base_queue = ret;
  10779. /* Update the FW view of the VSI. Force a reset of TC and queue
  10780. * layout configurations.
  10781. */
  10782. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  10783. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  10784. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  10785. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  10786. if (vsi->type == I40E_VSI_MAIN)
  10787. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  10788. /* assign it some queues */
  10789. ret = i40e_alloc_rings(vsi);
  10790. if (ret)
  10791. goto err_rings;
  10792. /* map all of the rings to the q_vectors */
  10793. i40e_vsi_map_rings_to_vectors(vsi);
  10794. return vsi;
  10795. err_rings:
  10796. i40e_vsi_free_q_vectors(vsi);
  10797. if (vsi->netdev_registered) {
  10798. vsi->netdev_registered = false;
  10799. unregister_netdev(vsi->netdev);
  10800. free_netdev(vsi->netdev);
  10801. vsi->netdev = NULL;
  10802. }
  10803. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10804. err_vsi:
  10805. i40e_vsi_clear(vsi);
  10806. return NULL;
  10807. }
  10808. /**
  10809. * i40e_vsi_setup - Set up a VSI by a given type
  10810. * @pf: board private structure
  10811. * @type: VSI type
  10812. * @uplink_seid: the switch element to link to
  10813. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  10814. *
  10815. * This allocates the sw VSI structure and its queue resources, then add a VSI
  10816. * to the identified VEB.
  10817. *
  10818. * Returns pointer to the successfully allocated and configure VSI sw struct on
  10819. * success, otherwise returns NULL on failure.
  10820. **/
  10821. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  10822. u16 uplink_seid, u32 param1)
  10823. {
  10824. struct i40e_vsi *vsi = NULL;
  10825. struct i40e_veb *veb = NULL;
  10826. u16 alloc_queue_pairs;
  10827. int ret, i;
  10828. int v_idx;
  10829. /* The requested uplink_seid must be either
  10830. * - the PF's port seid
  10831. * no VEB is needed because this is the PF
  10832. * or this is a Flow Director special case VSI
  10833. * - seid of an existing VEB
  10834. * - seid of a VSI that owns an existing VEB
  10835. * - seid of a VSI that doesn't own a VEB
  10836. * a new VEB is created and the VSI becomes the owner
  10837. * - seid of the PF VSI, which is what creates the first VEB
  10838. * this is a special case of the previous
  10839. *
  10840. * Find which uplink_seid we were given and create a new VEB if needed
  10841. */
  10842. for (i = 0; i < I40E_MAX_VEB; i++) {
  10843. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  10844. veb = pf->veb[i];
  10845. break;
  10846. }
  10847. }
  10848. if (!veb && uplink_seid != pf->mac_seid) {
  10849. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10850. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  10851. vsi = pf->vsi[i];
  10852. break;
  10853. }
  10854. }
  10855. if (!vsi) {
  10856. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  10857. uplink_seid);
  10858. return NULL;
  10859. }
  10860. if (vsi->uplink_seid == pf->mac_seid)
  10861. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  10862. vsi->tc_config.enabled_tc);
  10863. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  10864. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10865. vsi->tc_config.enabled_tc);
  10866. if (veb) {
  10867. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  10868. dev_info(&vsi->back->pdev->dev,
  10869. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  10870. return NULL;
  10871. }
  10872. /* We come up by default in VEPA mode if SRIOV is not
  10873. * already enabled, in which case we can't force VEPA
  10874. * mode.
  10875. */
  10876. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  10877. veb->bridge_mode = BRIDGE_MODE_VEPA;
  10878. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10879. }
  10880. i40e_config_bridge_mode(veb);
  10881. }
  10882. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10883. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10884. veb = pf->veb[i];
  10885. }
  10886. if (!veb) {
  10887. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  10888. return NULL;
  10889. }
  10890. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  10891. uplink_seid = veb->seid;
  10892. }
  10893. /* get vsi sw struct */
  10894. v_idx = i40e_vsi_mem_alloc(pf, type);
  10895. if (v_idx < 0)
  10896. goto err_alloc;
  10897. vsi = pf->vsi[v_idx];
  10898. if (!vsi)
  10899. goto err_alloc;
  10900. vsi->type = type;
  10901. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  10902. if (type == I40E_VSI_MAIN)
  10903. pf->lan_vsi = v_idx;
  10904. else if (type == I40E_VSI_SRIOV)
  10905. vsi->vf_id = param1;
  10906. /* assign it some queues */
  10907. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10908. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10909. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10910. if (ret < 0) {
  10911. dev_info(&pf->pdev->dev,
  10912. "failed to get tracking for %d queues for VSI %d err=%d\n",
  10913. alloc_queue_pairs, vsi->seid, ret);
  10914. goto err_vsi;
  10915. }
  10916. vsi->base_queue = ret;
  10917. /* get a VSI from the hardware */
  10918. vsi->uplink_seid = uplink_seid;
  10919. ret = i40e_add_vsi(vsi);
  10920. if (ret)
  10921. goto err_vsi;
  10922. switch (vsi->type) {
  10923. /* setup the netdev if needed */
  10924. case I40E_VSI_MAIN:
  10925. case I40E_VSI_VMDQ2:
  10926. ret = i40e_config_netdev(vsi);
  10927. if (ret)
  10928. goto err_netdev;
  10929. ret = register_netdev(vsi->netdev);
  10930. if (ret)
  10931. goto err_netdev;
  10932. vsi->netdev_registered = true;
  10933. netif_carrier_off(vsi->netdev);
  10934. #ifdef CONFIG_I40E_DCB
  10935. /* Setup DCB netlink interface */
  10936. i40e_dcbnl_setup(vsi);
  10937. #endif /* CONFIG_I40E_DCB */
  10938. /* fall through */
  10939. case I40E_VSI_FDIR:
  10940. /* set up vectors and rings if needed */
  10941. ret = i40e_vsi_setup_vectors(vsi);
  10942. if (ret)
  10943. goto err_msix;
  10944. ret = i40e_alloc_rings(vsi);
  10945. if (ret)
  10946. goto err_rings;
  10947. /* map all of the rings to the q_vectors */
  10948. i40e_vsi_map_rings_to_vectors(vsi);
  10949. i40e_vsi_reset_stats(vsi);
  10950. break;
  10951. default:
  10952. /* no netdev or rings for the other VSI types */
  10953. break;
  10954. }
  10955. if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
  10956. (vsi->type == I40E_VSI_VMDQ2)) {
  10957. ret = i40e_vsi_config_rss(vsi);
  10958. }
  10959. return vsi;
  10960. err_rings:
  10961. i40e_vsi_free_q_vectors(vsi);
  10962. err_msix:
  10963. if (vsi->netdev_registered) {
  10964. vsi->netdev_registered = false;
  10965. unregister_netdev(vsi->netdev);
  10966. free_netdev(vsi->netdev);
  10967. vsi->netdev = NULL;
  10968. }
  10969. err_netdev:
  10970. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10971. err_vsi:
  10972. i40e_vsi_clear(vsi);
  10973. err_alloc:
  10974. return NULL;
  10975. }
  10976. /**
  10977. * i40e_veb_get_bw_info - Query VEB BW information
  10978. * @veb: the veb to query
  10979. *
  10980. * Query the Tx scheduler BW configuration data for given VEB
  10981. **/
  10982. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  10983. {
  10984. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  10985. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  10986. struct i40e_pf *pf = veb->pf;
  10987. struct i40e_hw *hw = &pf->hw;
  10988. u32 tc_bw_max;
  10989. int ret = 0;
  10990. int i;
  10991. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  10992. &bw_data, NULL);
  10993. if (ret) {
  10994. dev_info(&pf->pdev->dev,
  10995. "query veb bw config failed, err %s aq_err %s\n",
  10996. i40e_stat_str(&pf->hw, ret),
  10997. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  10998. goto out;
  10999. }
  11000. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  11001. &ets_data, NULL);
  11002. if (ret) {
  11003. dev_info(&pf->pdev->dev,
  11004. "query veb bw ets config failed, err %s aq_err %s\n",
  11005. i40e_stat_str(&pf->hw, ret),
  11006. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11007. goto out;
  11008. }
  11009. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  11010. veb->bw_max_quanta = ets_data.tc_bw_max;
  11011. veb->is_abs_credits = bw_data.absolute_credits_enable;
  11012. veb->enabled_tc = ets_data.tc_valid_bits;
  11013. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  11014. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  11015. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  11016. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  11017. veb->bw_tc_limit_credits[i] =
  11018. le16_to_cpu(bw_data.tc_bw_limits[i]);
  11019. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  11020. }
  11021. out:
  11022. return ret;
  11023. }
  11024. /**
  11025. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  11026. * @pf: board private structure
  11027. *
  11028. * On error: returns error code (negative)
  11029. * On success: returns vsi index in PF (positive)
  11030. **/
  11031. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  11032. {
  11033. int ret = -ENOENT;
  11034. struct i40e_veb *veb;
  11035. int i;
  11036. /* Need to protect the allocation of switch elements at the PF level */
  11037. mutex_lock(&pf->switch_mutex);
  11038. /* VEB list may be fragmented if VEB creation/destruction has
  11039. * been happening. We can afford to do a quick scan to look
  11040. * for any free slots in the list.
  11041. *
  11042. * find next empty veb slot, looping back around if necessary
  11043. */
  11044. i = 0;
  11045. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  11046. i++;
  11047. if (i >= I40E_MAX_VEB) {
  11048. ret = -ENOMEM;
  11049. goto err_alloc_veb; /* out of VEB slots! */
  11050. }
  11051. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  11052. if (!veb) {
  11053. ret = -ENOMEM;
  11054. goto err_alloc_veb;
  11055. }
  11056. veb->pf = pf;
  11057. veb->idx = i;
  11058. veb->enabled_tc = 1;
  11059. pf->veb[i] = veb;
  11060. ret = i;
  11061. err_alloc_veb:
  11062. mutex_unlock(&pf->switch_mutex);
  11063. return ret;
  11064. }
  11065. /**
  11066. * i40e_switch_branch_release - Delete a branch of the switch tree
  11067. * @branch: where to start deleting
  11068. *
  11069. * This uses recursion to find the tips of the branch to be
  11070. * removed, deleting until we get back to and can delete this VEB.
  11071. **/
  11072. static void i40e_switch_branch_release(struct i40e_veb *branch)
  11073. {
  11074. struct i40e_pf *pf = branch->pf;
  11075. u16 branch_seid = branch->seid;
  11076. u16 veb_idx = branch->idx;
  11077. int i;
  11078. /* release any VEBs on this VEB - RECURSION */
  11079. for (i = 0; i < I40E_MAX_VEB; i++) {
  11080. if (!pf->veb[i])
  11081. continue;
  11082. if (pf->veb[i]->uplink_seid == branch->seid)
  11083. i40e_switch_branch_release(pf->veb[i]);
  11084. }
  11085. /* Release the VSIs on this VEB, but not the owner VSI.
  11086. *
  11087. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  11088. * the VEB itself, so don't use (*branch) after this loop.
  11089. */
  11090. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11091. if (!pf->vsi[i])
  11092. continue;
  11093. if (pf->vsi[i]->uplink_seid == branch_seid &&
  11094. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  11095. i40e_vsi_release(pf->vsi[i]);
  11096. }
  11097. }
  11098. /* There's one corner case where the VEB might not have been
  11099. * removed, so double check it here and remove it if needed.
  11100. * This case happens if the veb was created from the debugfs
  11101. * commands and no VSIs were added to it.
  11102. */
  11103. if (pf->veb[veb_idx])
  11104. i40e_veb_release(pf->veb[veb_idx]);
  11105. }
  11106. /**
  11107. * i40e_veb_clear - remove veb struct
  11108. * @veb: the veb to remove
  11109. **/
  11110. static void i40e_veb_clear(struct i40e_veb *veb)
  11111. {
  11112. if (!veb)
  11113. return;
  11114. if (veb->pf) {
  11115. struct i40e_pf *pf = veb->pf;
  11116. mutex_lock(&pf->switch_mutex);
  11117. if (pf->veb[veb->idx] == veb)
  11118. pf->veb[veb->idx] = NULL;
  11119. mutex_unlock(&pf->switch_mutex);
  11120. }
  11121. kfree(veb);
  11122. }
  11123. /**
  11124. * i40e_veb_release - Delete a VEB and free its resources
  11125. * @veb: the VEB being removed
  11126. **/
  11127. void i40e_veb_release(struct i40e_veb *veb)
  11128. {
  11129. struct i40e_vsi *vsi = NULL;
  11130. struct i40e_pf *pf;
  11131. int i, n = 0;
  11132. pf = veb->pf;
  11133. /* find the remaining VSI and check for extras */
  11134. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11135. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  11136. n++;
  11137. vsi = pf->vsi[i];
  11138. }
  11139. }
  11140. if (n != 1) {
  11141. dev_info(&pf->pdev->dev,
  11142. "can't remove VEB %d with %d VSIs left\n",
  11143. veb->seid, n);
  11144. return;
  11145. }
  11146. /* move the remaining VSI to uplink veb */
  11147. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  11148. if (veb->uplink_seid) {
  11149. vsi->uplink_seid = veb->uplink_seid;
  11150. if (veb->uplink_seid == pf->mac_seid)
  11151. vsi->veb_idx = I40E_NO_VEB;
  11152. else
  11153. vsi->veb_idx = veb->veb_idx;
  11154. } else {
  11155. /* floating VEB */
  11156. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  11157. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  11158. }
  11159. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11160. i40e_veb_clear(veb);
  11161. }
  11162. /**
  11163. * i40e_add_veb - create the VEB in the switch
  11164. * @veb: the VEB to be instantiated
  11165. * @vsi: the controlling VSI
  11166. **/
  11167. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  11168. {
  11169. struct i40e_pf *pf = veb->pf;
  11170. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  11171. int ret;
  11172. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  11173. veb->enabled_tc, false,
  11174. &veb->seid, enable_stats, NULL);
  11175. /* get a VEB from the hardware */
  11176. if (ret) {
  11177. dev_info(&pf->pdev->dev,
  11178. "couldn't add VEB, err %s aq_err %s\n",
  11179. i40e_stat_str(&pf->hw, ret),
  11180. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11181. return -EPERM;
  11182. }
  11183. /* get statistics counter */
  11184. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  11185. &veb->stats_idx, NULL, NULL, NULL);
  11186. if (ret) {
  11187. dev_info(&pf->pdev->dev,
  11188. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  11189. i40e_stat_str(&pf->hw, ret),
  11190. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11191. return -EPERM;
  11192. }
  11193. ret = i40e_veb_get_bw_info(veb);
  11194. if (ret) {
  11195. dev_info(&pf->pdev->dev,
  11196. "couldn't get VEB bw info, err %s aq_err %s\n",
  11197. i40e_stat_str(&pf->hw, ret),
  11198. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11199. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11200. return -ENOENT;
  11201. }
  11202. vsi->uplink_seid = veb->seid;
  11203. vsi->veb_idx = veb->idx;
  11204. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  11205. return 0;
  11206. }
  11207. /**
  11208. * i40e_veb_setup - Set up a VEB
  11209. * @pf: board private structure
  11210. * @flags: VEB setup flags
  11211. * @uplink_seid: the switch element to link to
  11212. * @vsi_seid: the initial VSI seid
  11213. * @enabled_tc: Enabled TC bit-map
  11214. *
  11215. * This allocates the sw VEB structure and links it into the switch
  11216. * It is possible and legal for this to be a duplicate of an already
  11217. * existing VEB. It is also possible for both uplink and vsi seids
  11218. * to be zero, in order to create a floating VEB.
  11219. *
  11220. * Returns pointer to the successfully allocated VEB sw struct on
  11221. * success, otherwise returns NULL on failure.
  11222. **/
  11223. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  11224. u16 uplink_seid, u16 vsi_seid,
  11225. u8 enabled_tc)
  11226. {
  11227. struct i40e_veb *veb, *uplink_veb = NULL;
  11228. int vsi_idx, veb_idx;
  11229. int ret;
  11230. /* if one seid is 0, the other must be 0 to create a floating relay */
  11231. if ((uplink_seid == 0 || vsi_seid == 0) &&
  11232. (uplink_seid + vsi_seid != 0)) {
  11233. dev_info(&pf->pdev->dev,
  11234. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  11235. uplink_seid, vsi_seid);
  11236. return NULL;
  11237. }
  11238. /* make sure there is such a vsi and uplink */
  11239. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  11240. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  11241. break;
  11242. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  11243. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  11244. vsi_seid);
  11245. return NULL;
  11246. }
  11247. if (uplink_seid && uplink_seid != pf->mac_seid) {
  11248. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  11249. if (pf->veb[veb_idx] &&
  11250. pf->veb[veb_idx]->seid == uplink_seid) {
  11251. uplink_veb = pf->veb[veb_idx];
  11252. break;
  11253. }
  11254. }
  11255. if (!uplink_veb) {
  11256. dev_info(&pf->pdev->dev,
  11257. "uplink seid %d not found\n", uplink_seid);
  11258. return NULL;
  11259. }
  11260. }
  11261. /* get veb sw struct */
  11262. veb_idx = i40e_veb_mem_alloc(pf);
  11263. if (veb_idx < 0)
  11264. goto err_alloc;
  11265. veb = pf->veb[veb_idx];
  11266. veb->flags = flags;
  11267. veb->uplink_seid = uplink_seid;
  11268. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  11269. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  11270. /* create the VEB in the switch */
  11271. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  11272. if (ret)
  11273. goto err_veb;
  11274. if (vsi_idx == pf->lan_vsi)
  11275. pf->lan_veb = veb->idx;
  11276. return veb;
  11277. err_veb:
  11278. i40e_veb_clear(veb);
  11279. err_alloc:
  11280. return NULL;
  11281. }
  11282. /**
  11283. * i40e_setup_pf_switch_element - set PF vars based on switch type
  11284. * @pf: board private structure
  11285. * @ele: element we are building info from
  11286. * @num_reported: total number of elements
  11287. * @printconfig: should we print the contents
  11288. *
  11289. * helper function to assist in extracting a few useful SEID values.
  11290. **/
  11291. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  11292. struct i40e_aqc_switch_config_element_resp *ele,
  11293. u16 num_reported, bool printconfig)
  11294. {
  11295. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  11296. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  11297. u8 element_type = ele->element_type;
  11298. u16 seid = le16_to_cpu(ele->seid);
  11299. if (printconfig)
  11300. dev_info(&pf->pdev->dev,
  11301. "type=%d seid=%d uplink=%d downlink=%d\n",
  11302. element_type, seid, uplink_seid, downlink_seid);
  11303. switch (element_type) {
  11304. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  11305. pf->mac_seid = seid;
  11306. break;
  11307. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  11308. /* Main VEB? */
  11309. if (uplink_seid != pf->mac_seid)
  11310. break;
  11311. if (pf->lan_veb == I40E_NO_VEB) {
  11312. int v;
  11313. /* find existing or else empty VEB */
  11314. for (v = 0; v < I40E_MAX_VEB; v++) {
  11315. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  11316. pf->lan_veb = v;
  11317. break;
  11318. }
  11319. }
  11320. if (pf->lan_veb == I40E_NO_VEB) {
  11321. v = i40e_veb_mem_alloc(pf);
  11322. if (v < 0)
  11323. break;
  11324. pf->lan_veb = v;
  11325. }
  11326. }
  11327. pf->veb[pf->lan_veb]->seid = seid;
  11328. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  11329. pf->veb[pf->lan_veb]->pf = pf;
  11330. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  11331. break;
  11332. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  11333. if (num_reported != 1)
  11334. break;
  11335. /* This is immediately after a reset so we can assume this is
  11336. * the PF's VSI
  11337. */
  11338. pf->mac_seid = uplink_seid;
  11339. pf->pf_seid = downlink_seid;
  11340. pf->main_vsi_seid = seid;
  11341. if (printconfig)
  11342. dev_info(&pf->pdev->dev,
  11343. "pf_seid=%d main_vsi_seid=%d\n",
  11344. pf->pf_seid, pf->main_vsi_seid);
  11345. break;
  11346. case I40E_SWITCH_ELEMENT_TYPE_PF:
  11347. case I40E_SWITCH_ELEMENT_TYPE_VF:
  11348. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  11349. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  11350. case I40E_SWITCH_ELEMENT_TYPE_PE:
  11351. case I40E_SWITCH_ELEMENT_TYPE_PA:
  11352. /* ignore these for now */
  11353. break;
  11354. default:
  11355. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  11356. element_type, seid);
  11357. break;
  11358. }
  11359. }
  11360. /**
  11361. * i40e_fetch_switch_configuration - Get switch config from firmware
  11362. * @pf: board private structure
  11363. * @printconfig: should we print the contents
  11364. *
  11365. * Get the current switch configuration from the device and
  11366. * extract a few useful SEID values.
  11367. **/
  11368. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  11369. {
  11370. struct i40e_aqc_get_switch_config_resp *sw_config;
  11371. u16 next_seid = 0;
  11372. int ret = 0;
  11373. u8 *aq_buf;
  11374. int i;
  11375. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  11376. if (!aq_buf)
  11377. return -ENOMEM;
  11378. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  11379. do {
  11380. u16 num_reported, num_total;
  11381. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  11382. I40E_AQ_LARGE_BUF,
  11383. &next_seid, NULL);
  11384. if (ret) {
  11385. dev_info(&pf->pdev->dev,
  11386. "get switch config failed err %s aq_err %s\n",
  11387. i40e_stat_str(&pf->hw, ret),
  11388. i40e_aq_str(&pf->hw,
  11389. pf->hw.aq.asq_last_status));
  11390. kfree(aq_buf);
  11391. return -ENOENT;
  11392. }
  11393. num_reported = le16_to_cpu(sw_config->header.num_reported);
  11394. num_total = le16_to_cpu(sw_config->header.num_total);
  11395. if (printconfig)
  11396. dev_info(&pf->pdev->dev,
  11397. "header: %d reported %d total\n",
  11398. num_reported, num_total);
  11399. for (i = 0; i < num_reported; i++) {
  11400. struct i40e_aqc_switch_config_element_resp *ele =
  11401. &sw_config->element[i];
  11402. i40e_setup_pf_switch_element(pf, ele, num_reported,
  11403. printconfig);
  11404. }
  11405. } while (next_seid != 0);
  11406. kfree(aq_buf);
  11407. return ret;
  11408. }
  11409. /**
  11410. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  11411. * @pf: board private structure
  11412. * @reinit: if the Main VSI needs to re-initialized.
  11413. *
  11414. * Returns 0 on success, negative value on failure
  11415. **/
  11416. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  11417. {
  11418. u16 flags = 0;
  11419. int ret;
  11420. /* find out what's out there already */
  11421. ret = i40e_fetch_switch_configuration(pf, false);
  11422. if (ret) {
  11423. dev_info(&pf->pdev->dev,
  11424. "couldn't fetch switch config, err %s aq_err %s\n",
  11425. i40e_stat_str(&pf->hw, ret),
  11426. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11427. return ret;
  11428. }
  11429. i40e_pf_reset_stats(pf);
  11430. /* set the switch config bit for the whole device to
  11431. * support limited promisc or true promisc
  11432. * when user requests promisc. The default is limited
  11433. * promisc.
  11434. */
  11435. if ((pf->hw.pf_id == 0) &&
  11436. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  11437. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11438. pf->last_sw_conf_flags = flags;
  11439. }
  11440. if (pf->hw.pf_id == 0) {
  11441. u16 valid_flags;
  11442. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11443. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
  11444. NULL);
  11445. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  11446. dev_info(&pf->pdev->dev,
  11447. "couldn't set switch config bits, err %s aq_err %s\n",
  11448. i40e_stat_str(&pf->hw, ret),
  11449. i40e_aq_str(&pf->hw,
  11450. pf->hw.aq.asq_last_status));
  11451. /* not a fatal problem, just keep going */
  11452. }
  11453. pf->last_sw_conf_valid_flags = valid_flags;
  11454. }
  11455. /* first time setup */
  11456. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  11457. struct i40e_vsi *vsi = NULL;
  11458. u16 uplink_seid;
  11459. /* Set up the PF VSI associated with the PF's main VSI
  11460. * that is already in the HW switch
  11461. */
  11462. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  11463. uplink_seid = pf->veb[pf->lan_veb]->seid;
  11464. else
  11465. uplink_seid = pf->mac_seid;
  11466. if (pf->lan_vsi == I40E_NO_VSI)
  11467. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  11468. else if (reinit)
  11469. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  11470. if (!vsi) {
  11471. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  11472. i40e_cloud_filter_exit(pf);
  11473. i40e_fdir_teardown(pf);
  11474. return -EAGAIN;
  11475. }
  11476. } else {
  11477. /* force a reset of TC and queue layout configurations */
  11478. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  11479. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  11480. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  11481. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  11482. }
  11483. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  11484. i40e_fdir_sb_setup(pf);
  11485. /* Setup static PF queue filter control settings */
  11486. ret = i40e_setup_pf_filter_control(pf);
  11487. if (ret) {
  11488. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  11489. ret);
  11490. /* Failure here should not stop continuing other steps */
  11491. }
  11492. /* enable RSS in the HW, even for only one queue, as the stack can use
  11493. * the hash
  11494. */
  11495. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  11496. i40e_pf_config_rss(pf);
  11497. /* fill in link information and enable LSE reporting */
  11498. i40e_link_event(pf);
  11499. /* Initialize user-specific link properties */
  11500. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  11501. I40E_AQ_AN_COMPLETED) ? true : false);
  11502. i40e_ptp_init(pf);
  11503. /* repopulate tunnel port filters */
  11504. i40e_sync_udp_filters(pf);
  11505. return ret;
  11506. }
  11507. /**
  11508. * i40e_determine_queue_usage - Work out queue distribution
  11509. * @pf: board private structure
  11510. **/
  11511. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  11512. {
  11513. int queues_left;
  11514. int q_max;
  11515. pf->num_lan_qps = 0;
  11516. /* Find the max queues to be put into basic use. We'll always be
  11517. * using TC0, whether or not DCB is running, and TC0 will get the
  11518. * big RSS set.
  11519. */
  11520. queues_left = pf->hw.func_caps.num_tx_qp;
  11521. if ((queues_left == 1) ||
  11522. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  11523. /* one qp for PF, no queues for anything else */
  11524. queues_left = 0;
  11525. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11526. /* make sure all the fancies are disabled */
  11527. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11528. I40E_FLAG_IWARP_ENABLED |
  11529. I40E_FLAG_FD_SB_ENABLED |
  11530. I40E_FLAG_FD_ATR_ENABLED |
  11531. I40E_FLAG_DCB_CAPABLE |
  11532. I40E_FLAG_DCB_ENABLED |
  11533. I40E_FLAG_SRIOV_ENABLED |
  11534. I40E_FLAG_VMDQ_ENABLED);
  11535. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11536. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  11537. I40E_FLAG_FD_SB_ENABLED |
  11538. I40E_FLAG_FD_ATR_ENABLED |
  11539. I40E_FLAG_DCB_CAPABLE))) {
  11540. /* one qp for PF */
  11541. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11542. queues_left -= pf->num_lan_qps;
  11543. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11544. I40E_FLAG_IWARP_ENABLED |
  11545. I40E_FLAG_FD_SB_ENABLED |
  11546. I40E_FLAG_FD_ATR_ENABLED |
  11547. I40E_FLAG_DCB_ENABLED |
  11548. I40E_FLAG_VMDQ_ENABLED);
  11549. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11550. } else {
  11551. /* Not enough queues for all TCs */
  11552. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  11553. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  11554. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  11555. I40E_FLAG_DCB_ENABLED);
  11556. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  11557. }
  11558. /* limit lan qps to the smaller of qps, cpus or msix */
  11559. q_max = max_t(int, pf->rss_size_max, num_online_cpus());
  11560. q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
  11561. q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
  11562. pf->num_lan_qps = q_max;
  11563. queues_left -= pf->num_lan_qps;
  11564. }
  11565. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11566. if (queues_left > 1) {
  11567. queues_left -= 1; /* save 1 queue for FD */
  11568. } else {
  11569. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  11570. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11571. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  11572. }
  11573. }
  11574. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11575. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  11576. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  11577. (queues_left / pf->num_vf_qps));
  11578. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  11579. }
  11580. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  11581. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  11582. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  11583. (queues_left / pf->num_vmdq_qps));
  11584. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  11585. }
  11586. pf->queues_left = queues_left;
  11587. dev_dbg(&pf->pdev->dev,
  11588. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  11589. pf->hw.func_caps.num_tx_qp,
  11590. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  11591. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  11592. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  11593. queues_left);
  11594. }
  11595. /**
  11596. * i40e_setup_pf_filter_control - Setup PF static filter control
  11597. * @pf: PF to be setup
  11598. *
  11599. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  11600. * settings. If PE/FCoE are enabled then it will also set the per PF
  11601. * based filter sizes required for them. It also enables Flow director,
  11602. * ethertype and macvlan type filter settings for the pf.
  11603. *
  11604. * Returns 0 on success, negative on failure
  11605. **/
  11606. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  11607. {
  11608. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  11609. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  11610. /* Flow Director is enabled */
  11611. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  11612. settings->enable_fdir = true;
  11613. /* Ethtype and MACVLAN filters enabled for PF */
  11614. settings->enable_ethtype = true;
  11615. settings->enable_macvlan = true;
  11616. if (i40e_set_filter_control(&pf->hw, settings))
  11617. return -ENOENT;
  11618. return 0;
  11619. }
  11620. #define INFO_STRING_LEN 255
  11621. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  11622. static void i40e_print_features(struct i40e_pf *pf)
  11623. {
  11624. struct i40e_hw *hw = &pf->hw;
  11625. char *buf;
  11626. int i;
  11627. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  11628. if (!buf)
  11629. return;
  11630. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  11631. #ifdef CONFIG_PCI_IOV
  11632. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  11633. #endif
  11634. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  11635. pf->hw.func_caps.num_vsis,
  11636. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  11637. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  11638. i += snprintf(&buf[i], REMAIN(i), " RSS");
  11639. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  11640. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  11641. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11642. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  11643. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  11644. }
  11645. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  11646. i += snprintf(&buf[i], REMAIN(i), " DCB");
  11647. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  11648. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  11649. if (pf->flags & I40E_FLAG_PTP)
  11650. i += snprintf(&buf[i], REMAIN(i), " PTP");
  11651. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  11652. i += snprintf(&buf[i], REMAIN(i), " VEB");
  11653. else
  11654. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  11655. dev_info(&pf->pdev->dev, "%s\n", buf);
  11656. kfree(buf);
  11657. WARN_ON(i > INFO_STRING_LEN);
  11658. }
  11659. /**
  11660. * i40e_get_platform_mac_addr - get platform-specific MAC address
  11661. * @pdev: PCI device information struct
  11662. * @pf: board private structure
  11663. *
  11664. * Look up the MAC address for the device. First we'll try
  11665. * eth_platform_get_mac_address, which will check Open Firmware, or arch
  11666. * specific fallback. Otherwise, we'll default to the stored value in
  11667. * firmware.
  11668. **/
  11669. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  11670. {
  11671. if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  11672. i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
  11673. }
  11674. /**
  11675. * i40e_probe - Device initialization routine
  11676. * @pdev: PCI device information struct
  11677. * @ent: entry in i40e_pci_tbl
  11678. *
  11679. * i40e_probe initializes a PF identified by a pci_dev structure.
  11680. * The OS initialization, configuring of the PF private structure,
  11681. * and a hardware reset occur.
  11682. *
  11683. * Returns 0 on success, negative on failure
  11684. **/
  11685. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11686. {
  11687. struct i40e_aq_get_phy_abilities_resp abilities;
  11688. struct i40e_pf *pf;
  11689. struct i40e_hw *hw;
  11690. static u16 pfs_found;
  11691. u16 wol_nvm_bits;
  11692. u16 link_status;
  11693. int err;
  11694. u32 val;
  11695. u32 i;
  11696. u8 set_fc_aq_fail;
  11697. err = pci_enable_device_mem(pdev);
  11698. if (err)
  11699. return err;
  11700. /* set up for high or low dma */
  11701. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  11702. if (err) {
  11703. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  11704. if (err) {
  11705. dev_err(&pdev->dev,
  11706. "DMA configuration failed: 0x%x\n", err);
  11707. goto err_dma;
  11708. }
  11709. }
  11710. /* set up pci connections */
  11711. err = pci_request_mem_regions(pdev, i40e_driver_name);
  11712. if (err) {
  11713. dev_info(&pdev->dev,
  11714. "pci_request_selected_regions failed %d\n", err);
  11715. goto err_pci_reg;
  11716. }
  11717. pci_enable_pcie_error_reporting(pdev);
  11718. pci_set_master(pdev);
  11719. /* Now that we have a PCI connection, we need to do the
  11720. * low level device setup. This is primarily setting up
  11721. * the Admin Queue structures and then querying for the
  11722. * device's current profile information.
  11723. */
  11724. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  11725. if (!pf) {
  11726. err = -ENOMEM;
  11727. goto err_pf_alloc;
  11728. }
  11729. pf->next_vsi = 0;
  11730. pf->pdev = pdev;
  11731. set_bit(__I40E_DOWN, pf->state);
  11732. hw = &pf->hw;
  11733. hw->back = pf;
  11734. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  11735. I40E_MAX_CSR_SPACE);
  11736. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  11737. if (!hw->hw_addr) {
  11738. err = -EIO;
  11739. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  11740. (unsigned int)pci_resource_start(pdev, 0),
  11741. pf->ioremap_len, err);
  11742. goto err_ioremap;
  11743. }
  11744. hw->vendor_id = pdev->vendor;
  11745. hw->device_id = pdev->device;
  11746. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  11747. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  11748. hw->subsystem_device_id = pdev->subsystem_device;
  11749. hw->bus.device = PCI_SLOT(pdev->devfn);
  11750. hw->bus.func = PCI_FUNC(pdev->devfn);
  11751. hw->bus.bus_id = pdev->bus->number;
  11752. pf->instance = pfs_found;
  11753. /* Select something other than the 802.1ad ethertype for the
  11754. * switch to use internally and drop on ingress.
  11755. */
  11756. hw->switch_tag = 0xffff;
  11757. hw->first_tag = ETH_P_8021AD;
  11758. hw->second_tag = ETH_P_8021Q;
  11759. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  11760. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  11761. /* set up the locks for the AQ, do this only once in probe
  11762. * and destroy them only once in remove
  11763. */
  11764. mutex_init(&hw->aq.asq_mutex);
  11765. mutex_init(&hw->aq.arq_mutex);
  11766. pf->msg_enable = netif_msg_init(debug,
  11767. NETIF_MSG_DRV |
  11768. NETIF_MSG_PROBE |
  11769. NETIF_MSG_LINK);
  11770. if (debug < -1)
  11771. pf->hw.debug_mask = debug;
  11772. /* do a special CORER for clearing PXE mode once at init */
  11773. if (hw->revision_id == 0 &&
  11774. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  11775. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  11776. i40e_flush(hw);
  11777. msleep(200);
  11778. pf->corer_count++;
  11779. i40e_clear_pxe_mode(hw);
  11780. }
  11781. /* Reset here to make sure all is clean and to define PF 'n' */
  11782. i40e_clear_hw(hw);
  11783. err = i40e_pf_reset(hw);
  11784. if (err) {
  11785. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  11786. goto err_pf_reset;
  11787. }
  11788. pf->pfr_count++;
  11789. hw->aq.num_arq_entries = I40E_AQ_LEN;
  11790. hw->aq.num_asq_entries = I40E_AQ_LEN;
  11791. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11792. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11793. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  11794. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  11795. "%s-%s:misc",
  11796. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  11797. err = i40e_init_shared_code(hw);
  11798. if (err) {
  11799. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  11800. err);
  11801. goto err_pf_reset;
  11802. }
  11803. /* set up a default setting for link flow control */
  11804. pf->hw.fc.requested_mode = I40E_FC_NONE;
  11805. err = i40e_init_adminq(hw);
  11806. if (err) {
  11807. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  11808. dev_info(&pdev->dev,
  11809. "The driver for the device stopped because the NVM image is newer than expected. You must install the most recent version of the network driver.\n");
  11810. else
  11811. dev_info(&pdev->dev,
  11812. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  11813. goto err_pf_reset;
  11814. }
  11815. i40e_get_oem_version(hw);
  11816. /* provide nvm, fw, api versions */
  11817. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  11818. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  11819. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  11820. i40e_nvm_version_str(hw));
  11821. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  11822. hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
  11823. dev_info(&pdev->dev,
  11824. "The driver for the device detected a newer version of the NVM image than expected. Please install the most recent version of the network driver.\n");
  11825. else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
  11826. dev_info(&pdev->dev,
  11827. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  11828. i40e_verify_eeprom(pf);
  11829. /* Rev 0 hardware was never productized */
  11830. if (hw->revision_id < 1)
  11831. dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n");
  11832. i40e_clear_pxe_mode(hw);
  11833. err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  11834. if (err)
  11835. goto err_adminq_setup;
  11836. err = i40e_sw_init(pf);
  11837. if (err) {
  11838. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  11839. goto err_sw_init;
  11840. }
  11841. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  11842. hw->func_caps.num_rx_qp, 0, 0);
  11843. if (err) {
  11844. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  11845. goto err_init_lan_hmc;
  11846. }
  11847. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  11848. if (err) {
  11849. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  11850. err = -ENOENT;
  11851. goto err_configure_lan_hmc;
  11852. }
  11853. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  11854. * Ignore error return codes because if it was already disabled via
  11855. * hardware settings this will fail
  11856. */
  11857. if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
  11858. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  11859. i40e_aq_stop_lldp(hw, true, NULL);
  11860. }
  11861. /* allow a platform config to override the HW addr */
  11862. i40e_get_platform_mac_addr(pdev, pf);
  11863. if (!is_valid_ether_addr(hw->mac.addr)) {
  11864. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  11865. err = -EIO;
  11866. goto err_mac_addr;
  11867. }
  11868. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  11869. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  11870. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  11871. if (is_valid_ether_addr(hw->mac.port_addr))
  11872. pf->hw_features |= I40E_HW_PORT_ID_VALID;
  11873. pci_set_drvdata(pdev, pf);
  11874. pci_save_state(pdev);
  11875. /* Enable FW to write default DCB config on link-up */
  11876. i40e_aq_set_dcb_parameters(hw, true, NULL);
  11877. #ifdef CONFIG_I40E_DCB
  11878. err = i40e_init_pf_dcb(pf);
  11879. if (err) {
  11880. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  11881. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  11882. /* Continue without DCB enabled */
  11883. }
  11884. #endif /* CONFIG_I40E_DCB */
  11885. /* set up periodic task facility */
  11886. timer_setup(&pf->service_timer, i40e_service_timer, 0);
  11887. pf->service_timer_period = HZ;
  11888. INIT_WORK(&pf->service_task, i40e_service_task);
  11889. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  11890. /* NVM bit on means WoL disabled for the port */
  11891. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  11892. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  11893. pf->wol_en = false;
  11894. else
  11895. pf->wol_en = true;
  11896. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  11897. /* set up the main switch operations */
  11898. i40e_determine_queue_usage(pf);
  11899. err = i40e_init_interrupt_scheme(pf);
  11900. if (err)
  11901. goto err_switch_setup;
  11902. /* The number of VSIs reported by the FW is the minimum guaranteed
  11903. * to us; HW supports far more and we share the remaining pool with
  11904. * the other PFs. We allocate space for more than the guarantee with
  11905. * the understanding that we might not get them all later.
  11906. */
  11907. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  11908. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  11909. else
  11910. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  11911. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  11912. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  11913. GFP_KERNEL);
  11914. if (!pf->vsi) {
  11915. err = -ENOMEM;
  11916. goto err_switch_setup;
  11917. }
  11918. #ifdef CONFIG_PCI_IOV
  11919. /* prep for VF support */
  11920. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11921. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  11922. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  11923. if (pci_num_vf(pdev))
  11924. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  11925. }
  11926. #endif
  11927. err = i40e_setup_pf_switch(pf, false);
  11928. if (err) {
  11929. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  11930. goto err_vsis;
  11931. }
  11932. INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
  11933. /* Make sure flow control is set according to current settings */
  11934. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  11935. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  11936. dev_dbg(&pf->pdev->dev,
  11937. "Set fc with err %s aq_err %s on get_phy_cap\n",
  11938. i40e_stat_str(hw, err),
  11939. i40e_aq_str(hw, hw->aq.asq_last_status));
  11940. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  11941. dev_dbg(&pf->pdev->dev,
  11942. "Set fc with err %s aq_err %s on set_phy_config\n",
  11943. i40e_stat_str(hw, err),
  11944. i40e_aq_str(hw, hw->aq.asq_last_status));
  11945. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  11946. dev_dbg(&pf->pdev->dev,
  11947. "Set fc with err %s aq_err %s on get_link_info\n",
  11948. i40e_stat_str(hw, err),
  11949. i40e_aq_str(hw, hw->aq.asq_last_status));
  11950. /* if FDIR VSI was set up, start it now */
  11951. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11952. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  11953. i40e_vsi_open(pf->vsi[i]);
  11954. break;
  11955. }
  11956. }
  11957. /* The driver only wants link up/down and module qualification
  11958. * reports from firmware. Note the negative logic.
  11959. */
  11960. err = i40e_aq_set_phy_int_mask(&pf->hw,
  11961. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  11962. I40E_AQ_EVENT_MEDIA_NA |
  11963. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  11964. if (err)
  11965. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  11966. i40e_stat_str(&pf->hw, err),
  11967. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11968. /* Reconfigure hardware for allowing smaller MSS in the case
  11969. * of TSO, so that we avoid the MDD being fired and causing
  11970. * a reset in the case of small MSS+TSO.
  11971. */
  11972. val = rd32(hw, I40E_REG_MSS);
  11973. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  11974. val &= ~I40E_REG_MSS_MIN_MASK;
  11975. val |= I40E_64BYTE_MSS;
  11976. wr32(hw, I40E_REG_MSS, val);
  11977. }
  11978. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  11979. msleep(75);
  11980. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  11981. if (err)
  11982. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  11983. i40e_stat_str(&pf->hw, err),
  11984. i40e_aq_str(&pf->hw,
  11985. pf->hw.aq.asq_last_status));
  11986. }
  11987. /* The main driver is (mostly) up and happy. We need to set this state
  11988. * before setting up the misc vector or we get a race and the vector
  11989. * ends up disabled forever.
  11990. */
  11991. clear_bit(__I40E_DOWN, pf->state);
  11992. /* In case of MSIX we are going to setup the misc vector right here
  11993. * to handle admin queue events etc. In case of legacy and MSI
  11994. * the misc functionality and queue processing is combined in
  11995. * the same vector and that gets setup at open.
  11996. */
  11997. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  11998. err = i40e_setup_misc_vector(pf);
  11999. if (err) {
  12000. dev_info(&pdev->dev,
  12001. "setup of misc vector failed: %d\n", err);
  12002. goto err_vsis;
  12003. }
  12004. }
  12005. #ifdef CONFIG_PCI_IOV
  12006. /* prep for VF support */
  12007. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12008. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12009. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12010. /* disable link interrupts for VFs */
  12011. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  12012. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  12013. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  12014. i40e_flush(hw);
  12015. if (pci_num_vf(pdev)) {
  12016. dev_info(&pdev->dev,
  12017. "Active VFs found, allocating resources.\n");
  12018. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  12019. if (err)
  12020. dev_info(&pdev->dev,
  12021. "Error %d allocating resources for existing VFs\n",
  12022. err);
  12023. }
  12024. }
  12025. #endif /* CONFIG_PCI_IOV */
  12026. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12027. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  12028. pf->num_iwarp_msix,
  12029. I40E_IWARP_IRQ_PILE_ID);
  12030. if (pf->iwarp_base_vector < 0) {
  12031. dev_info(&pdev->dev,
  12032. "failed to get tracking for %d vectors for IWARP err=%d\n",
  12033. pf->num_iwarp_msix, pf->iwarp_base_vector);
  12034. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  12035. }
  12036. }
  12037. i40e_dbg_pf_init(pf);
  12038. /* tell the firmware that we're starting */
  12039. i40e_send_version(pf);
  12040. /* since everything's happy, start the service_task timer */
  12041. mod_timer(&pf->service_timer,
  12042. round_jiffies(jiffies + pf->service_timer_period));
  12043. /* add this PF to client device list and launch a client service task */
  12044. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12045. err = i40e_lan_add_device(pf);
  12046. if (err)
  12047. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  12048. err);
  12049. }
  12050. #define PCI_SPEED_SIZE 8
  12051. #define PCI_WIDTH_SIZE 8
  12052. /* Devices on the IOSF bus do not have this information
  12053. * and will report PCI Gen 1 x 1 by default so don't bother
  12054. * checking them.
  12055. */
  12056. if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
  12057. char speed[PCI_SPEED_SIZE] = "Unknown";
  12058. char width[PCI_WIDTH_SIZE] = "Unknown";
  12059. /* Get the negotiated link width and speed from PCI config
  12060. * space
  12061. */
  12062. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  12063. &link_status);
  12064. i40e_set_pci_config_data(hw, link_status);
  12065. switch (hw->bus.speed) {
  12066. case i40e_bus_speed_8000:
  12067. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  12068. case i40e_bus_speed_5000:
  12069. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  12070. case i40e_bus_speed_2500:
  12071. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  12072. default:
  12073. break;
  12074. }
  12075. switch (hw->bus.width) {
  12076. case i40e_bus_width_pcie_x8:
  12077. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  12078. case i40e_bus_width_pcie_x4:
  12079. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  12080. case i40e_bus_width_pcie_x2:
  12081. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  12082. case i40e_bus_width_pcie_x1:
  12083. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  12084. default:
  12085. break;
  12086. }
  12087. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  12088. speed, width);
  12089. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  12090. hw->bus.speed < i40e_bus_speed_8000) {
  12091. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  12092. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  12093. }
  12094. }
  12095. /* get the requested speeds from the fw */
  12096. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  12097. if (err)
  12098. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  12099. i40e_stat_str(&pf->hw, err),
  12100. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12101. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  12102. /* get the supported phy types from the fw */
  12103. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  12104. if (err)
  12105. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  12106. i40e_stat_str(&pf->hw, err),
  12107. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12108. /* Add a filter to drop all Flow control frames from any VSI from being
  12109. * transmitted. By doing so we stop a malicious VF from sending out
  12110. * PAUSE or PFC frames and potentially controlling traffic for other
  12111. * PF/VF VSIs.
  12112. * The FW can still send Flow control frames if enabled.
  12113. */
  12114. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  12115. pf->main_vsi_seid);
  12116. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  12117. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  12118. pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
  12119. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  12120. pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
  12121. /* print a string summarizing features */
  12122. i40e_print_features(pf);
  12123. return 0;
  12124. /* Unwind what we've done if something failed in the setup */
  12125. err_vsis:
  12126. set_bit(__I40E_DOWN, pf->state);
  12127. i40e_clear_interrupt_scheme(pf);
  12128. kfree(pf->vsi);
  12129. err_switch_setup:
  12130. i40e_reset_interrupt_capability(pf);
  12131. del_timer_sync(&pf->service_timer);
  12132. err_mac_addr:
  12133. err_configure_lan_hmc:
  12134. (void)i40e_shutdown_lan_hmc(hw);
  12135. err_init_lan_hmc:
  12136. kfree(pf->qp_pile);
  12137. err_sw_init:
  12138. err_adminq_setup:
  12139. err_pf_reset:
  12140. iounmap(hw->hw_addr);
  12141. err_ioremap:
  12142. kfree(pf);
  12143. err_pf_alloc:
  12144. pci_disable_pcie_error_reporting(pdev);
  12145. pci_release_mem_regions(pdev);
  12146. err_pci_reg:
  12147. err_dma:
  12148. pci_disable_device(pdev);
  12149. return err;
  12150. }
  12151. /**
  12152. * i40e_remove - Device removal routine
  12153. * @pdev: PCI device information struct
  12154. *
  12155. * i40e_remove is called by the PCI subsystem to alert the driver
  12156. * that is should release a PCI device. This could be caused by a
  12157. * Hot-Plug event, or because the driver is going to be removed from
  12158. * memory.
  12159. **/
  12160. static void i40e_remove(struct pci_dev *pdev)
  12161. {
  12162. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12163. struct i40e_hw *hw = &pf->hw;
  12164. i40e_status ret_code;
  12165. int i;
  12166. i40e_dbg_pf_exit(pf);
  12167. i40e_ptp_stop(pf);
  12168. /* Disable RSS in hw */
  12169. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  12170. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  12171. /* no more scheduling of any task */
  12172. set_bit(__I40E_SUSPENDED, pf->state);
  12173. set_bit(__I40E_DOWN, pf->state);
  12174. if (pf->service_timer.function)
  12175. del_timer_sync(&pf->service_timer);
  12176. if (pf->service_task.func)
  12177. cancel_work_sync(&pf->service_task);
  12178. /* Client close must be called explicitly here because the timer
  12179. * has been stopped.
  12180. */
  12181. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12182. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  12183. i40e_free_vfs(pf);
  12184. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  12185. }
  12186. i40e_fdir_teardown(pf);
  12187. /* If there is a switch structure or any orphans, remove them.
  12188. * This will leave only the PF's VSI remaining.
  12189. */
  12190. for (i = 0; i < I40E_MAX_VEB; i++) {
  12191. if (!pf->veb[i])
  12192. continue;
  12193. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  12194. pf->veb[i]->uplink_seid == 0)
  12195. i40e_switch_branch_release(pf->veb[i]);
  12196. }
  12197. /* Now we can shutdown the PF's VSI, just before we kill
  12198. * adminq and hmc.
  12199. */
  12200. if (pf->vsi[pf->lan_vsi])
  12201. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  12202. i40e_cloud_filter_exit(pf);
  12203. /* remove attached clients */
  12204. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12205. ret_code = i40e_lan_del_device(pf);
  12206. if (ret_code)
  12207. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  12208. ret_code);
  12209. }
  12210. /* shutdown and destroy the HMC */
  12211. if (hw->hmc.hmc_obj) {
  12212. ret_code = i40e_shutdown_lan_hmc(hw);
  12213. if (ret_code)
  12214. dev_warn(&pdev->dev,
  12215. "Failed to destroy the HMC resources: %d\n",
  12216. ret_code);
  12217. }
  12218. /* shutdown the adminq */
  12219. i40e_shutdown_adminq(hw);
  12220. /* destroy the locks only once, here */
  12221. mutex_destroy(&hw->aq.arq_mutex);
  12222. mutex_destroy(&hw->aq.asq_mutex);
  12223. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  12224. i40e_clear_interrupt_scheme(pf);
  12225. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12226. if (pf->vsi[i]) {
  12227. i40e_vsi_clear_rings(pf->vsi[i]);
  12228. i40e_vsi_clear(pf->vsi[i]);
  12229. pf->vsi[i] = NULL;
  12230. }
  12231. }
  12232. for (i = 0; i < I40E_MAX_VEB; i++) {
  12233. kfree(pf->veb[i]);
  12234. pf->veb[i] = NULL;
  12235. }
  12236. kfree(pf->qp_pile);
  12237. kfree(pf->vsi);
  12238. iounmap(hw->hw_addr);
  12239. kfree(pf);
  12240. pci_release_mem_regions(pdev);
  12241. pci_disable_pcie_error_reporting(pdev);
  12242. pci_disable_device(pdev);
  12243. }
  12244. /**
  12245. * i40e_pci_error_detected - warning that something funky happened in PCI land
  12246. * @pdev: PCI device information struct
  12247. *
  12248. * Called to warn that something happened and the error handling steps
  12249. * are in progress. Allows the driver to quiesce things, be ready for
  12250. * remediation.
  12251. **/
  12252. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  12253. enum pci_channel_state error)
  12254. {
  12255. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12256. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  12257. if (!pf) {
  12258. dev_info(&pdev->dev,
  12259. "Cannot recover - error happened during device probe\n");
  12260. return PCI_ERS_RESULT_DISCONNECT;
  12261. }
  12262. /* shutdown all operations */
  12263. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12264. i40e_prep_for_reset(pf, false);
  12265. /* Request a slot reset */
  12266. return PCI_ERS_RESULT_NEED_RESET;
  12267. }
  12268. /**
  12269. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  12270. * @pdev: PCI device information struct
  12271. *
  12272. * Called to find if the driver can work with the device now that
  12273. * the pci slot has been reset. If a basic connection seems good
  12274. * (registers are readable and have sane content) then return a
  12275. * happy little PCI_ERS_RESULT_xxx.
  12276. **/
  12277. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  12278. {
  12279. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12280. pci_ers_result_t result;
  12281. int err;
  12282. u32 reg;
  12283. dev_dbg(&pdev->dev, "%s\n", __func__);
  12284. if (pci_enable_device_mem(pdev)) {
  12285. dev_info(&pdev->dev,
  12286. "Cannot re-enable PCI device after reset.\n");
  12287. result = PCI_ERS_RESULT_DISCONNECT;
  12288. } else {
  12289. pci_set_master(pdev);
  12290. pci_restore_state(pdev);
  12291. pci_save_state(pdev);
  12292. pci_wake_from_d3(pdev, false);
  12293. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  12294. if (reg == 0)
  12295. result = PCI_ERS_RESULT_RECOVERED;
  12296. else
  12297. result = PCI_ERS_RESULT_DISCONNECT;
  12298. }
  12299. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  12300. if (err) {
  12301. dev_info(&pdev->dev,
  12302. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  12303. err);
  12304. /* non-fatal, continue */
  12305. }
  12306. return result;
  12307. }
  12308. /**
  12309. * i40e_pci_error_reset_prepare - prepare device driver for pci reset
  12310. * @pdev: PCI device information struct
  12311. */
  12312. static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
  12313. {
  12314. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12315. i40e_prep_for_reset(pf, false);
  12316. }
  12317. /**
  12318. * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
  12319. * @pdev: PCI device information struct
  12320. */
  12321. static void i40e_pci_error_reset_done(struct pci_dev *pdev)
  12322. {
  12323. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12324. i40e_reset_and_rebuild(pf, false, false);
  12325. }
  12326. /**
  12327. * i40e_pci_error_resume - restart operations after PCI error recovery
  12328. * @pdev: PCI device information struct
  12329. *
  12330. * Called to allow the driver to bring things back up after PCI error
  12331. * and/or reset recovery has finished.
  12332. **/
  12333. static void i40e_pci_error_resume(struct pci_dev *pdev)
  12334. {
  12335. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12336. dev_dbg(&pdev->dev, "%s\n", __func__);
  12337. if (test_bit(__I40E_SUSPENDED, pf->state))
  12338. return;
  12339. i40e_handle_reset_warning(pf, false);
  12340. }
  12341. /**
  12342. * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
  12343. * using the mac_address_write admin q function
  12344. * @pf: pointer to i40e_pf struct
  12345. **/
  12346. static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
  12347. {
  12348. struct i40e_hw *hw = &pf->hw;
  12349. i40e_status ret;
  12350. u8 mac_addr[6];
  12351. u16 flags = 0;
  12352. /* Get current MAC address in case it's an LAA */
  12353. if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
  12354. ether_addr_copy(mac_addr,
  12355. pf->vsi[pf->lan_vsi]->netdev->dev_addr);
  12356. } else {
  12357. dev_err(&pf->pdev->dev,
  12358. "Failed to retrieve MAC address; using default\n");
  12359. ether_addr_copy(mac_addr, hw->mac.addr);
  12360. }
  12361. /* The FW expects the mac address write cmd to first be called with
  12362. * one of these flags before calling it again with the multicast
  12363. * enable flags.
  12364. */
  12365. flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
  12366. if (hw->func_caps.flex10_enable && hw->partition_id != 1)
  12367. flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
  12368. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12369. if (ret) {
  12370. dev_err(&pf->pdev->dev,
  12371. "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
  12372. return;
  12373. }
  12374. flags = I40E_AQC_MC_MAG_EN
  12375. | I40E_AQC_WOL_PRESERVE_ON_PFR
  12376. | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
  12377. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12378. if (ret)
  12379. dev_err(&pf->pdev->dev,
  12380. "Failed to enable Multicast Magic Packet wake up\n");
  12381. }
  12382. /**
  12383. * i40e_shutdown - PCI callback for shutting down
  12384. * @pdev: PCI device information struct
  12385. **/
  12386. static void i40e_shutdown(struct pci_dev *pdev)
  12387. {
  12388. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12389. struct i40e_hw *hw = &pf->hw;
  12390. set_bit(__I40E_SUSPENDED, pf->state);
  12391. set_bit(__I40E_DOWN, pf->state);
  12392. rtnl_lock();
  12393. i40e_prep_for_reset(pf, true);
  12394. rtnl_unlock();
  12395. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12396. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12397. del_timer_sync(&pf->service_timer);
  12398. cancel_work_sync(&pf->service_task);
  12399. i40e_cloud_filter_exit(pf);
  12400. i40e_fdir_teardown(pf);
  12401. /* Client close must be called explicitly here because the timer
  12402. * has been stopped.
  12403. */
  12404. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12405. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12406. i40e_enable_mc_magic_wake(pf);
  12407. i40e_prep_for_reset(pf, false);
  12408. wr32(hw, I40E_PFPM_APM,
  12409. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12410. wr32(hw, I40E_PFPM_WUFC,
  12411. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12412. i40e_clear_interrupt_scheme(pf);
  12413. if (system_state == SYSTEM_POWER_OFF) {
  12414. pci_wake_from_d3(pdev, pf->wol_en);
  12415. pci_set_power_state(pdev, PCI_D3hot);
  12416. }
  12417. }
  12418. /**
  12419. * i40e_suspend - PM callback for moving to D3
  12420. * @dev: generic device information structure
  12421. **/
  12422. static int __maybe_unused i40e_suspend(struct device *dev)
  12423. {
  12424. struct pci_dev *pdev = to_pci_dev(dev);
  12425. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12426. struct i40e_hw *hw = &pf->hw;
  12427. /* If we're already suspended, then there is nothing to do */
  12428. if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
  12429. return 0;
  12430. set_bit(__I40E_DOWN, pf->state);
  12431. /* Ensure service task will not be running */
  12432. del_timer_sync(&pf->service_timer);
  12433. cancel_work_sync(&pf->service_task);
  12434. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12435. i40e_enable_mc_magic_wake(pf);
  12436. i40e_prep_for_reset(pf, false);
  12437. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12438. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12439. /* Clear the interrupt scheme and release our IRQs so that the system
  12440. * can safely hibernate even when there are a large number of CPUs.
  12441. * Otherwise hibernation might fail when mapping all the vectors back
  12442. * to CPU0.
  12443. */
  12444. i40e_clear_interrupt_scheme(pf);
  12445. return 0;
  12446. }
  12447. /**
  12448. * i40e_resume - PM callback for waking up from D3
  12449. * @dev: generic device information structure
  12450. **/
  12451. static int __maybe_unused i40e_resume(struct device *dev)
  12452. {
  12453. struct pci_dev *pdev = to_pci_dev(dev);
  12454. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12455. int err;
  12456. /* If we're not suspended, then there is nothing to do */
  12457. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12458. return 0;
  12459. /* We cleared the interrupt scheme when we suspended, so we need to
  12460. * restore it now to resume device functionality.
  12461. */
  12462. err = i40e_restore_interrupt_scheme(pf);
  12463. if (err) {
  12464. dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n",
  12465. err);
  12466. }
  12467. clear_bit(__I40E_DOWN, pf->state);
  12468. i40e_reset_and_rebuild(pf, false, false);
  12469. /* Clear suspended state last after everything is recovered */
  12470. clear_bit(__I40E_SUSPENDED, pf->state);
  12471. /* Restart the service task */
  12472. mod_timer(&pf->service_timer,
  12473. round_jiffies(jiffies + pf->service_timer_period));
  12474. return 0;
  12475. }
  12476. static const struct pci_error_handlers i40e_err_handler = {
  12477. .error_detected = i40e_pci_error_detected,
  12478. .slot_reset = i40e_pci_error_slot_reset,
  12479. .reset_prepare = i40e_pci_error_reset_prepare,
  12480. .reset_done = i40e_pci_error_reset_done,
  12481. .resume = i40e_pci_error_resume,
  12482. };
  12483. static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
  12484. static struct pci_driver i40e_driver = {
  12485. .name = i40e_driver_name,
  12486. .id_table = i40e_pci_tbl,
  12487. .probe = i40e_probe,
  12488. .remove = i40e_remove,
  12489. .driver = {
  12490. .pm = &i40e_pm_ops,
  12491. },
  12492. .shutdown = i40e_shutdown,
  12493. .err_handler = &i40e_err_handler,
  12494. .sriov_configure = i40e_pci_sriov_configure,
  12495. };
  12496. /**
  12497. * i40e_init_module - Driver registration routine
  12498. *
  12499. * i40e_init_module is the first routine called when the driver is
  12500. * loaded. All it does is register with the PCI subsystem.
  12501. **/
  12502. static int __init i40e_init_module(void)
  12503. {
  12504. pr_info("%s: %s - version %s\n", i40e_driver_name,
  12505. i40e_driver_string, i40e_driver_version_str);
  12506. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  12507. /* There is no need to throttle the number of active tasks because
  12508. * each device limits its own task using a state bit for scheduling
  12509. * the service task, and the device tasks do not interfere with each
  12510. * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
  12511. * since we need to be able to guarantee forward progress even under
  12512. * memory pressure.
  12513. */
  12514. i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
  12515. if (!i40e_wq) {
  12516. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  12517. return -ENOMEM;
  12518. }
  12519. i40e_dbg_init();
  12520. return pci_register_driver(&i40e_driver);
  12521. }
  12522. module_init(i40e_init_module);
  12523. /**
  12524. * i40e_exit_module - Driver exit cleanup routine
  12525. *
  12526. * i40e_exit_module is called just before the driver is removed
  12527. * from memory.
  12528. **/
  12529. static void __exit i40e_exit_module(void)
  12530. {
  12531. pci_unregister_driver(&i40e_driver);
  12532. destroy_workqueue(i40e_wq);
  12533. i40e_dbg_exit();
  12534. }
  12535. module_exit(i40e_exit_module);