i40e_main.c 398 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include <linux/etherdevice.h>
  4. #include <linux/of_net.h>
  5. #include <linux/pci.h>
  6. #include <linux/bpf.h>
  7. /* Local includes */
  8. #include "i40e.h"
  9. #include "i40e_diag.h"
  10. #include <net/udp_tunnel.h>
  11. /* All i40e tracepoints are defined by the include below, which
  12. * must be included exactly once across the whole kernel with
  13. * CREATE_TRACE_POINTS defined
  14. */
  15. #define CREATE_TRACE_POINTS
  16. #include "i40e_trace.h"
  17. const char i40e_driver_name[] = "i40e";
  18. static const char i40e_driver_string[] =
  19. "Intel(R) Ethernet Connection XL710 Network Driver";
  20. #define DRV_KERN "-k"
  21. #define DRV_VERSION_MAJOR 2
  22. #define DRV_VERSION_MINOR 3
  23. #define DRV_VERSION_BUILD 2
  24. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  25. __stringify(DRV_VERSION_MINOR) "." \
  26. __stringify(DRV_VERSION_BUILD) DRV_KERN
  27. const char i40e_driver_version_str[] = DRV_VERSION;
  28. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  29. /* a bit of forward declarations */
  30. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  31. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired);
  32. static int i40e_add_vsi(struct i40e_vsi *vsi);
  33. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  34. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  35. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  36. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  37. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  38. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired);
  39. static int i40e_reset(struct i40e_pf *pf);
  40. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired);
  41. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  42. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  43. static int i40e_get_capabilities(struct i40e_pf *pf,
  44. enum i40e_admin_queue_opc list_type);
  45. /* i40e_pci_tbl - PCI Device ID Table
  46. *
  47. * Last entry must be all 0s
  48. *
  49. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  50. * Class, Class Mask, private data (not used) }
  51. */
  52. static const struct pci_device_id i40e_pci_tbl[] = {
  53. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  54. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  55. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  56. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  57. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  58. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  59. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  60. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  61. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  62. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  63. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  71. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  72. /* required last entry */
  73. {0, }
  74. };
  75. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  76. #define I40E_MAX_VF_COUNT 128
  77. static int debug = -1;
  78. module_param(debug, uint, 0);
  79. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  80. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  81. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  82. MODULE_LICENSE("GPL");
  83. MODULE_VERSION(DRV_VERSION);
  84. static struct workqueue_struct *i40e_wq;
  85. /**
  86. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  87. * @hw: pointer to the HW structure
  88. * @mem: ptr to mem struct to fill out
  89. * @size: size of memory requested
  90. * @alignment: what to align the allocation to
  91. **/
  92. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  93. u64 size, u32 alignment)
  94. {
  95. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  96. mem->size = ALIGN(size, alignment);
  97. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  98. &mem->pa, GFP_KERNEL);
  99. if (!mem->va)
  100. return -ENOMEM;
  101. return 0;
  102. }
  103. /**
  104. * i40e_free_dma_mem_d - OS specific memory free for shared code
  105. * @hw: pointer to the HW structure
  106. * @mem: ptr to mem struct to free
  107. **/
  108. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  109. {
  110. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  111. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  112. mem->va = NULL;
  113. mem->pa = 0;
  114. mem->size = 0;
  115. return 0;
  116. }
  117. /**
  118. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  119. * @hw: pointer to the HW structure
  120. * @mem: ptr to mem struct to fill out
  121. * @size: size of memory requested
  122. **/
  123. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  124. u32 size)
  125. {
  126. mem->size = size;
  127. mem->va = kzalloc(size, GFP_KERNEL);
  128. if (!mem->va)
  129. return -ENOMEM;
  130. return 0;
  131. }
  132. /**
  133. * i40e_free_virt_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_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  138. {
  139. /* it's ok to kfree a NULL pointer */
  140. kfree(mem->va);
  141. mem->va = NULL;
  142. mem->size = 0;
  143. return 0;
  144. }
  145. /**
  146. * i40e_get_lump - find a lump of free generic resource
  147. * @pf: board private structure
  148. * @pile: the pile of resource to search
  149. * @needed: the number of items needed
  150. * @id: an owner id to stick on the items assigned
  151. *
  152. * Returns the base item index of the lump, or negative for error
  153. *
  154. * The search_hint trick and lack of advanced fit-finding only work
  155. * because we're highly likely to have all the same size lump requests.
  156. * Linear search time and any fragmentation should be minimal.
  157. **/
  158. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  159. u16 needed, u16 id)
  160. {
  161. int ret = -ENOMEM;
  162. int i, j;
  163. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  164. dev_info(&pf->pdev->dev,
  165. "param err: pile=%s needed=%d id=0x%04x\n",
  166. pile ? "<valid>" : "<null>", needed, id);
  167. return -EINVAL;
  168. }
  169. /* start the linear search with an imperfect hint */
  170. i = pile->search_hint;
  171. while (i < pile->num_entries) {
  172. /* skip already allocated entries */
  173. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  174. i++;
  175. continue;
  176. }
  177. /* do we have enough in this lump? */
  178. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  179. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  180. break;
  181. }
  182. if (j == needed) {
  183. /* there was enough, so assign it to the requestor */
  184. for (j = 0; j < needed; j++)
  185. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  186. ret = i;
  187. pile->search_hint = i + j;
  188. break;
  189. }
  190. /* not enough, so skip over it and continue looking */
  191. i += j;
  192. }
  193. return ret;
  194. }
  195. /**
  196. * i40e_put_lump - return a lump of generic resource
  197. * @pile: the pile of resource to search
  198. * @index: the base item index
  199. * @id: the owner id of the items assigned
  200. *
  201. * Returns the count of items in the lump
  202. **/
  203. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  204. {
  205. int valid_id = (id | I40E_PILE_VALID_BIT);
  206. int count = 0;
  207. int i;
  208. if (!pile || index >= pile->num_entries)
  209. return -EINVAL;
  210. for (i = index;
  211. i < pile->num_entries && pile->list[i] == valid_id;
  212. i++) {
  213. pile->list[i] = 0;
  214. count++;
  215. }
  216. if (count && index < pile->search_hint)
  217. pile->search_hint = index;
  218. return count;
  219. }
  220. /**
  221. * i40e_find_vsi_from_id - searches for the vsi with the given id
  222. * @pf: the pf structure to search for the vsi
  223. * @id: id of the vsi it is searching for
  224. **/
  225. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  226. {
  227. int i;
  228. for (i = 0; i < pf->num_alloc_vsi; i++)
  229. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  230. return pf->vsi[i];
  231. return NULL;
  232. }
  233. /**
  234. * i40e_service_event_schedule - Schedule the service task to wake up
  235. * @pf: board private structure
  236. *
  237. * If not already scheduled, this puts the task into the work queue
  238. **/
  239. void i40e_service_event_schedule(struct i40e_pf *pf)
  240. {
  241. if (!test_bit(__I40E_DOWN, pf->state) &&
  242. !test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  243. queue_work(i40e_wq, &pf->service_task);
  244. }
  245. /**
  246. * i40e_tx_timeout - Respond to a Tx Hang
  247. * @netdev: network interface device structure
  248. *
  249. * If any port has noticed a Tx timeout, it is likely that the whole
  250. * device is munged, not just the one netdev port, so go for the full
  251. * reset.
  252. **/
  253. static void i40e_tx_timeout(struct net_device *netdev)
  254. {
  255. struct i40e_netdev_priv *np = netdev_priv(netdev);
  256. struct i40e_vsi *vsi = np->vsi;
  257. struct i40e_pf *pf = vsi->back;
  258. struct i40e_ring *tx_ring = NULL;
  259. unsigned int i, hung_queue = 0;
  260. u32 head, val;
  261. pf->tx_timeout_count++;
  262. /* find the stopped queue the same way the stack does */
  263. for (i = 0; i < netdev->num_tx_queues; i++) {
  264. struct netdev_queue *q;
  265. unsigned long trans_start;
  266. q = netdev_get_tx_queue(netdev, i);
  267. trans_start = q->trans_start;
  268. if (netif_xmit_stopped(q) &&
  269. time_after(jiffies,
  270. (trans_start + netdev->watchdog_timeo))) {
  271. hung_queue = i;
  272. break;
  273. }
  274. }
  275. if (i == netdev->num_tx_queues) {
  276. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  277. } else {
  278. /* now that we have an index, find the tx_ring struct */
  279. for (i = 0; i < vsi->num_queue_pairs; i++) {
  280. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  281. if (hung_queue ==
  282. vsi->tx_rings[i]->queue_index) {
  283. tx_ring = vsi->tx_rings[i];
  284. break;
  285. }
  286. }
  287. }
  288. }
  289. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  290. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  291. else if (time_before(jiffies,
  292. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  293. return; /* don't do any new action before the next timeout */
  294. if (tx_ring) {
  295. head = i40e_get_head(tx_ring);
  296. /* Read interrupt register */
  297. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  298. val = rd32(&pf->hw,
  299. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  300. tx_ring->vsi->base_vector - 1));
  301. else
  302. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  303. 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",
  304. vsi->seid, hung_queue, tx_ring->next_to_clean,
  305. head, tx_ring->next_to_use,
  306. readl(tx_ring->tail), val);
  307. }
  308. pf->tx_timeout_last_recovery = jiffies;
  309. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  310. pf->tx_timeout_recovery_level, hung_queue);
  311. switch (pf->tx_timeout_recovery_level) {
  312. case 1:
  313. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  314. break;
  315. case 2:
  316. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  317. break;
  318. case 3:
  319. set_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  320. break;
  321. default:
  322. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  323. break;
  324. }
  325. i40e_service_event_schedule(pf);
  326. pf->tx_timeout_recovery_level++;
  327. }
  328. /**
  329. * i40e_get_vsi_stats_struct - Get System Network Statistics
  330. * @vsi: the VSI we care about
  331. *
  332. * Returns the address of the device statistics structure.
  333. * The statistics are actually updated from the service task.
  334. **/
  335. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  336. {
  337. return &vsi->net_stats;
  338. }
  339. /**
  340. * i40e_get_netdev_stats_struct_tx - populate stats from a Tx ring
  341. * @ring: Tx ring to get statistics from
  342. * @stats: statistics entry to be updated
  343. **/
  344. static void i40e_get_netdev_stats_struct_tx(struct i40e_ring *ring,
  345. struct rtnl_link_stats64 *stats)
  346. {
  347. u64 bytes, packets;
  348. unsigned int start;
  349. do {
  350. start = u64_stats_fetch_begin_irq(&ring->syncp);
  351. packets = ring->stats.packets;
  352. bytes = ring->stats.bytes;
  353. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  354. stats->tx_packets += packets;
  355. stats->tx_bytes += bytes;
  356. }
  357. /**
  358. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  359. * @netdev: network interface device structure
  360. * @stats: data structure to store statistics
  361. *
  362. * Returns the address of the device statistics structure.
  363. * The statistics are actually updated from the service task.
  364. **/
  365. static void i40e_get_netdev_stats_struct(struct net_device *netdev,
  366. struct rtnl_link_stats64 *stats)
  367. {
  368. struct i40e_netdev_priv *np = netdev_priv(netdev);
  369. struct i40e_ring *tx_ring, *rx_ring;
  370. struct i40e_vsi *vsi = np->vsi;
  371. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  372. int i;
  373. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  374. return;
  375. if (!vsi->tx_rings)
  376. return;
  377. rcu_read_lock();
  378. for (i = 0; i < vsi->num_queue_pairs; i++) {
  379. u64 bytes, packets;
  380. unsigned int start;
  381. tx_ring = READ_ONCE(vsi->tx_rings[i]);
  382. if (!tx_ring)
  383. continue;
  384. i40e_get_netdev_stats_struct_tx(tx_ring, stats);
  385. rx_ring = &tx_ring[1];
  386. do {
  387. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  388. packets = rx_ring->stats.packets;
  389. bytes = rx_ring->stats.bytes;
  390. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  391. stats->rx_packets += packets;
  392. stats->rx_bytes += bytes;
  393. if (i40e_enabled_xdp_vsi(vsi))
  394. i40e_get_netdev_stats_struct_tx(&rx_ring[1], stats);
  395. }
  396. rcu_read_unlock();
  397. /* following stats updated by i40e_watchdog_subtask() */
  398. stats->multicast = vsi_stats->multicast;
  399. stats->tx_errors = vsi_stats->tx_errors;
  400. stats->tx_dropped = vsi_stats->tx_dropped;
  401. stats->rx_errors = vsi_stats->rx_errors;
  402. stats->rx_dropped = vsi_stats->rx_dropped;
  403. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  404. stats->rx_length_errors = vsi_stats->rx_length_errors;
  405. }
  406. /**
  407. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  408. * @vsi: the VSI to have its stats reset
  409. **/
  410. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  411. {
  412. struct rtnl_link_stats64 *ns;
  413. int i;
  414. if (!vsi)
  415. return;
  416. ns = i40e_get_vsi_stats_struct(vsi);
  417. memset(ns, 0, sizeof(*ns));
  418. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  419. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  420. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  421. if (vsi->rx_rings && vsi->rx_rings[0]) {
  422. for (i = 0; i < vsi->num_queue_pairs; i++) {
  423. memset(&vsi->rx_rings[i]->stats, 0,
  424. sizeof(vsi->rx_rings[i]->stats));
  425. memset(&vsi->rx_rings[i]->rx_stats, 0,
  426. sizeof(vsi->rx_rings[i]->rx_stats));
  427. memset(&vsi->tx_rings[i]->stats, 0,
  428. sizeof(vsi->tx_rings[i]->stats));
  429. memset(&vsi->tx_rings[i]->tx_stats, 0,
  430. sizeof(vsi->tx_rings[i]->tx_stats));
  431. }
  432. }
  433. vsi->stat_offsets_loaded = false;
  434. }
  435. /**
  436. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  437. * @pf: the PF to be reset
  438. **/
  439. void i40e_pf_reset_stats(struct i40e_pf *pf)
  440. {
  441. int i;
  442. memset(&pf->stats, 0, sizeof(pf->stats));
  443. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  444. pf->stat_offsets_loaded = false;
  445. for (i = 0; i < I40E_MAX_VEB; i++) {
  446. if (pf->veb[i]) {
  447. memset(&pf->veb[i]->stats, 0,
  448. sizeof(pf->veb[i]->stats));
  449. memset(&pf->veb[i]->stats_offsets, 0,
  450. sizeof(pf->veb[i]->stats_offsets));
  451. pf->veb[i]->stat_offsets_loaded = false;
  452. }
  453. }
  454. pf->hw_csum_rx_error = 0;
  455. }
  456. /**
  457. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  458. * @hw: ptr to the hardware info
  459. * @hireg: the high 32 bit reg to read
  460. * @loreg: the low 32 bit reg to read
  461. * @offset_loaded: has the initial offset been loaded yet
  462. * @offset: ptr to current offset value
  463. * @stat: ptr to the stat
  464. *
  465. * Since the device stats are not reset at PFReset, they likely will not
  466. * be zeroed when the driver starts. We'll save the first values read
  467. * and use them as offsets to be subtracted from the raw values in order
  468. * to report stats that count from zero. In the process, we also manage
  469. * the potential roll-over.
  470. **/
  471. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  472. bool offset_loaded, u64 *offset, u64 *stat)
  473. {
  474. u64 new_data;
  475. if (hw->device_id == I40E_DEV_ID_QEMU) {
  476. new_data = rd32(hw, loreg);
  477. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  478. } else {
  479. new_data = rd64(hw, loreg);
  480. }
  481. if (!offset_loaded)
  482. *offset = new_data;
  483. if (likely(new_data >= *offset))
  484. *stat = new_data - *offset;
  485. else
  486. *stat = (new_data + BIT_ULL(48)) - *offset;
  487. *stat &= 0xFFFFFFFFFFFFULL;
  488. }
  489. /**
  490. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  491. * @hw: ptr to the hardware info
  492. * @reg: the hw reg to read
  493. * @offset_loaded: has the initial offset been loaded yet
  494. * @offset: ptr to current offset value
  495. * @stat: ptr to the stat
  496. **/
  497. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  498. bool offset_loaded, u64 *offset, u64 *stat)
  499. {
  500. u32 new_data;
  501. new_data = rd32(hw, reg);
  502. if (!offset_loaded)
  503. *offset = new_data;
  504. if (likely(new_data >= *offset))
  505. *stat = (u32)(new_data - *offset);
  506. else
  507. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  508. }
  509. /**
  510. * i40e_stat_update_and_clear32 - read and clear hw reg, update a 32 bit stat
  511. * @hw: ptr to the hardware info
  512. * @reg: the hw reg to read and clear
  513. * @stat: ptr to the stat
  514. **/
  515. static void i40e_stat_update_and_clear32(struct i40e_hw *hw, u32 reg, u64 *stat)
  516. {
  517. u32 new_data = rd32(hw, reg);
  518. wr32(hw, reg, 1); /* must write a nonzero value to clear register */
  519. *stat += new_data;
  520. }
  521. /**
  522. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  523. * @vsi: the VSI to be updated
  524. **/
  525. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  526. {
  527. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  528. struct i40e_pf *pf = vsi->back;
  529. struct i40e_hw *hw = &pf->hw;
  530. struct i40e_eth_stats *oes;
  531. struct i40e_eth_stats *es; /* device's eth stats */
  532. es = &vsi->eth_stats;
  533. oes = &vsi->eth_stats_offsets;
  534. /* Gather up the stats that the hw collects */
  535. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  536. vsi->stat_offsets_loaded,
  537. &oes->tx_errors, &es->tx_errors);
  538. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  539. vsi->stat_offsets_loaded,
  540. &oes->rx_discards, &es->rx_discards);
  541. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  542. vsi->stat_offsets_loaded,
  543. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  544. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  545. vsi->stat_offsets_loaded,
  546. &oes->tx_errors, &es->tx_errors);
  547. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  548. I40E_GLV_GORCL(stat_idx),
  549. vsi->stat_offsets_loaded,
  550. &oes->rx_bytes, &es->rx_bytes);
  551. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  552. I40E_GLV_UPRCL(stat_idx),
  553. vsi->stat_offsets_loaded,
  554. &oes->rx_unicast, &es->rx_unicast);
  555. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  556. I40E_GLV_MPRCL(stat_idx),
  557. vsi->stat_offsets_loaded,
  558. &oes->rx_multicast, &es->rx_multicast);
  559. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  560. I40E_GLV_BPRCL(stat_idx),
  561. vsi->stat_offsets_loaded,
  562. &oes->rx_broadcast, &es->rx_broadcast);
  563. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  564. I40E_GLV_GOTCL(stat_idx),
  565. vsi->stat_offsets_loaded,
  566. &oes->tx_bytes, &es->tx_bytes);
  567. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  568. I40E_GLV_UPTCL(stat_idx),
  569. vsi->stat_offsets_loaded,
  570. &oes->tx_unicast, &es->tx_unicast);
  571. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  572. I40E_GLV_MPTCL(stat_idx),
  573. vsi->stat_offsets_loaded,
  574. &oes->tx_multicast, &es->tx_multicast);
  575. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  576. I40E_GLV_BPTCL(stat_idx),
  577. vsi->stat_offsets_loaded,
  578. &oes->tx_broadcast, &es->tx_broadcast);
  579. vsi->stat_offsets_loaded = true;
  580. }
  581. /**
  582. * i40e_update_veb_stats - Update Switch component statistics
  583. * @veb: the VEB being updated
  584. **/
  585. static void i40e_update_veb_stats(struct i40e_veb *veb)
  586. {
  587. struct i40e_pf *pf = veb->pf;
  588. struct i40e_hw *hw = &pf->hw;
  589. struct i40e_eth_stats *oes;
  590. struct i40e_eth_stats *es; /* device's eth stats */
  591. struct i40e_veb_tc_stats *veb_oes;
  592. struct i40e_veb_tc_stats *veb_es;
  593. int i, idx = 0;
  594. idx = veb->stats_idx;
  595. es = &veb->stats;
  596. oes = &veb->stats_offsets;
  597. veb_es = &veb->tc_stats;
  598. veb_oes = &veb->tc_stats_offsets;
  599. /* Gather up the stats that the hw collects */
  600. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  601. veb->stat_offsets_loaded,
  602. &oes->tx_discards, &es->tx_discards);
  603. if (hw->revision_id > 0)
  604. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  605. veb->stat_offsets_loaded,
  606. &oes->rx_unknown_protocol,
  607. &es->rx_unknown_protocol);
  608. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  609. veb->stat_offsets_loaded,
  610. &oes->rx_bytes, &es->rx_bytes);
  611. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  612. veb->stat_offsets_loaded,
  613. &oes->rx_unicast, &es->rx_unicast);
  614. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  615. veb->stat_offsets_loaded,
  616. &oes->rx_multicast, &es->rx_multicast);
  617. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  618. veb->stat_offsets_loaded,
  619. &oes->rx_broadcast, &es->rx_broadcast);
  620. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  621. veb->stat_offsets_loaded,
  622. &oes->tx_bytes, &es->tx_bytes);
  623. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  624. veb->stat_offsets_loaded,
  625. &oes->tx_unicast, &es->tx_unicast);
  626. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  627. veb->stat_offsets_loaded,
  628. &oes->tx_multicast, &es->tx_multicast);
  629. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  630. veb->stat_offsets_loaded,
  631. &oes->tx_broadcast, &es->tx_broadcast);
  632. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  633. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  634. I40E_GLVEBTC_RPCL(i, idx),
  635. veb->stat_offsets_loaded,
  636. &veb_oes->tc_rx_packets[i],
  637. &veb_es->tc_rx_packets[i]);
  638. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  639. I40E_GLVEBTC_RBCL(i, idx),
  640. veb->stat_offsets_loaded,
  641. &veb_oes->tc_rx_bytes[i],
  642. &veb_es->tc_rx_bytes[i]);
  643. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  644. I40E_GLVEBTC_TPCL(i, idx),
  645. veb->stat_offsets_loaded,
  646. &veb_oes->tc_tx_packets[i],
  647. &veb_es->tc_tx_packets[i]);
  648. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  649. I40E_GLVEBTC_TBCL(i, idx),
  650. veb->stat_offsets_loaded,
  651. &veb_oes->tc_tx_bytes[i],
  652. &veb_es->tc_tx_bytes[i]);
  653. }
  654. veb->stat_offsets_loaded = true;
  655. }
  656. /**
  657. * i40e_update_vsi_stats - Update the vsi statistics counters.
  658. * @vsi: the VSI to be updated
  659. *
  660. * There are a few instances where we store the same stat in a
  661. * couple of different structs. This is partly because we have
  662. * the netdev stats that need to be filled out, which is slightly
  663. * different from the "eth_stats" defined by the chip and used in
  664. * VF communications. We sort it out here.
  665. **/
  666. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  667. {
  668. struct i40e_pf *pf = vsi->back;
  669. struct rtnl_link_stats64 *ons;
  670. struct rtnl_link_stats64 *ns; /* netdev stats */
  671. struct i40e_eth_stats *oes;
  672. struct i40e_eth_stats *es; /* device's eth stats */
  673. u32 tx_restart, tx_busy;
  674. struct i40e_ring *p;
  675. u32 rx_page, rx_buf;
  676. u64 bytes, packets;
  677. unsigned int start;
  678. u64 tx_linearize;
  679. u64 tx_force_wb;
  680. u64 rx_p, rx_b;
  681. u64 tx_p, tx_b;
  682. u16 q;
  683. if (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  684. test_bit(__I40E_CONFIG_BUSY, pf->state))
  685. return;
  686. ns = i40e_get_vsi_stats_struct(vsi);
  687. ons = &vsi->net_stats_offsets;
  688. es = &vsi->eth_stats;
  689. oes = &vsi->eth_stats_offsets;
  690. /* Gather up the netdev and vsi stats that the driver collects
  691. * on the fly during packet processing
  692. */
  693. rx_b = rx_p = 0;
  694. tx_b = tx_p = 0;
  695. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  696. rx_page = 0;
  697. rx_buf = 0;
  698. rcu_read_lock();
  699. for (q = 0; q < vsi->num_queue_pairs; q++) {
  700. /* locate Tx ring */
  701. p = READ_ONCE(vsi->tx_rings[q]);
  702. do {
  703. start = u64_stats_fetch_begin_irq(&p->syncp);
  704. packets = p->stats.packets;
  705. bytes = p->stats.bytes;
  706. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  707. tx_b += bytes;
  708. tx_p += packets;
  709. tx_restart += p->tx_stats.restart_queue;
  710. tx_busy += p->tx_stats.tx_busy;
  711. tx_linearize += p->tx_stats.tx_linearize;
  712. tx_force_wb += p->tx_stats.tx_force_wb;
  713. /* Rx queue is part of the same block as Tx queue */
  714. p = &p[1];
  715. do {
  716. start = u64_stats_fetch_begin_irq(&p->syncp);
  717. packets = p->stats.packets;
  718. bytes = p->stats.bytes;
  719. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  720. rx_b += bytes;
  721. rx_p += packets;
  722. rx_buf += p->rx_stats.alloc_buff_failed;
  723. rx_page += p->rx_stats.alloc_page_failed;
  724. }
  725. rcu_read_unlock();
  726. vsi->tx_restart = tx_restart;
  727. vsi->tx_busy = tx_busy;
  728. vsi->tx_linearize = tx_linearize;
  729. vsi->tx_force_wb = tx_force_wb;
  730. vsi->rx_page_failed = rx_page;
  731. vsi->rx_buf_failed = rx_buf;
  732. ns->rx_packets = rx_p;
  733. ns->rx_bytes = rx_b;
  734. ns->tx_packets = tx_p;
  735. ns->tx_bytes = tx_b;
  736. /* update netdev stats from eth stats */
  737. i40e_update_eth_stats(vsi);
  738. ons->tx_errors = oes->tx_errors;
  739. ns->tx_errors = es->tx_errors;
  740. ons->multicast = oes->rx_multicast;
  741. ns->multicast = es->rx_multicast;
  742. ons->rx_dropped = oes->rx_discards;
  743. ns->rx_dropped = es->rx_discards;
  744. ons->tx_dropped = oes->tx_discards;
  745. ns->tx_dropped = es->tx_discards;
  746. /* pull in a couple PF stats if this is the main vsi */
  747. if (vsi == pf->vsi[pf->lan_vsi]) {
  748. ns->rx_crc_errors = pf->stats.crc_errors;
  749. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  750. ns->rx_length_errors = pf->stats.rx_length_errors;
  751. }
  752. }
  753. /**
  754. * i40e_update_pf_stats - Update the PF statistics counters.
  755. * @pf: the PF to be updated
  756. **/
  757. static void i40e_update_pf_stats(struct i40e_pf *pf)
  758. {
  759. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  760. struct i40e_hw_port_stats *nsd = &pf->stats;
  761. struct i40e_hw *hw = &pf->hw;
  762. u32 val;
  763. int i;
  764. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  765. I40E_GLPRT_GORCL(hw->port),
  766. pf->stat_offsets_loaded,
  767. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  768. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  769. I40E_GLPRT_GOTCL(hw->port),
  770. pf->stat_offsets_loaded,
  771. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  772. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  773. pf->stat_offsets_loaded,
  774. &osd->eth.rx_discards,
  775. &nsd->eth.rx_discards);
  776. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  777. I40E_GLPRT_UPRCL(hw->port),
  778. pf->stat_offsets_loaded,
  779. &osd->eth.rx_unicast,
  780. &nsd->eth.rx_unicast);
  781. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  782. I40E_GLPRT_MPRCL(hw->port),
  783. pf->stat_offsets_loaded,
  784. &osd->eth.rx_multicast,
  785. &nsd->eth.rx_multicast);
  786. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  787. I40E_GLPRT_BPRCL(hw->port),
  788. pf->stat_offsets_loaded,
  789. &osd->eth.rx_broadcast,
  790. &nsd->eth.rx_broadcast);
  791. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  792. I40E_GLPRT_UPTCL(hw->port),
  793. pf->stat_offsets_loaded,
  794. &osd->eth.tx_unicast,
  795. &nsd->eth.tx_unicast);
  796. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  797. I40E_GLPRT_MPTCL(hw->port),
  798. pf->stat_offsets_loaded,
  799. &osd->eth.tx_multicast,
  800. &nsd->eth.tx_multicast);
  801. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  802. I40E_GLPRT_BPTCL(hw->port),
  803. pf->stat_offsets_loaded,
  804. &osd->eth.tx_broadcast,
  805. &nsd->eth.tx_broadcast);
  806. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  807. pf->stat_offsets_loaded,
  808. &osd->tx_dropped_link_down,
  809. &nsd->tx_dropped_link_down);
  810. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  811. pf->stat_offsets_loaded,
  812. &osd->crc_errors, &nsd->crc_errors);
  813. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  814. pf->stat_offsets_loaded,
  815. &osd->illegal_bytes, &nsd->illegal_bytes);
  816. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  817. pf->stat_offsets_loaded,
  818. &osd->mac_local_faults,
  819. &nsd->mac_local_faults);
  820. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  821. pf->stat_offsets_loaded,
  822. &osd->mac_remote_faults,
  823. &nsd->mac_remote_faults);
  824. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  825. pf->stat_offsets_loaded,
  826. &osd->rx_length_errors,
  827. &nsd->rx_length_errors);
  828. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  829. pf->stat_offsets_loaded,
  830. &osd->link_xon_rx, &nsd->link_xon_rx);
  831. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->link_xon_tx, &nsd->link_xon_tx);
  834. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  835. pf->stat_offsets_loaded,
  836. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  837. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  838. pf->stat_offsets_loaded,
  839. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  840. for (i = 0; i < 8; i++) {
  841. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  842. pf->stat_offsets_loaded,
  843. &osd->priority_xoff_rx[i],
  844. &nsd->priority_xoff_rx[i]);
  845. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  846. pf->stat_offsets_loaded,
  847. &osd->priority_xon_rx[i],
  848. &nsd->priority_xon_rx[i]);
  849. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  850. pf->stat_offsets_loaded,
  851. &osd->priority_xon_tx[i],
  852. &nsd->priority_xon_tx[i]);
  853. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  854. pf->stat_offsets_loaded,
  855. &osd->priority_xoff_tx[i],
  856. &nsd->priority_xoff_tx[i]);
  857. i40e_stat_update32(hw,
  858. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  859. pf->stat_offsets_loaded,
  860. &osd->priority_xon_2_xoff[i],
  861. &nsd->priority_xon_2_xoff[i]);
  862. }
  863. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  864. I40E_GLPRT_PRC64L(hw->port),
  865. pf->stat_offsets_loaded,
  866. &osd->rx_size_64, &nsd->rx_size_64);
  867. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  868. I40E_GLPRT_PRC127L(hw->port),
  869. pf->stat_offsets_loaded,
  870. &osd->rx_size_127, &nsd->rx_size_127);
  871. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  872. I40E_GLPRT_PRC255L(hw->port),
  873. pf->stat_offsets_loaded,
  874. &osd->rx_size_255, &nsd->rx_size_255);
  875. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  876. I40E_GLPRT_PRC511L(hw->port),
  877. pf->stat_offsets_loaded,
  878. &osd->rx_size_511, &nsd->rx_size_511);
  879. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  880. I40E_GLPRT_PRC1023L(hw->port),
  881. pf->stat_offsets_loaded,
  882. &osd->rx_size_1023, &nsd->rx_size_1023);
  883. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  884. I40E_GLPRT_PRC1522L(hw->port),
  885. pf->stat_offsets_loaded,
  886. &osd->rx_size_1522, &nsd->rx_size_1522);
  887. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  888. I40E_GLPRT_PRC9522L(hw->port),
  889. pf->stat_offsets_loaded,
  890. &osd->rx_size_big, &nsd->rx_size_big);
  891. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  892. I40E_GLPRT_PTC64L(hw->port),
  893. pf->stat_offsets_loaded,
  894. &osd->tx_size_64, &nsd->tx_size_64);
  895. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  896. I40E_GLPRT_PTC127L(hw->port),
  897. pf->stat_offsets_loaded,
  898. &osd->tx_size_127, &nsd->tx_size_127);
  899. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  900. I40E_GLPRT_PTC255L(hw->port),
  901. pf->stat_offsets_loaded,
  902. &osd->tx_size_255, &nsd->tx_size_255);
  903. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  904. I40E_GLPRT_PTC511L(hw->port),
  905. pf->stat_offsets_loaded,
  906. &osd->tx_size_511, &nsd->tx_size_511);
  907. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  908. I40E_GLPRT_PTC1023L(hw->port),
  909. pf->stat_offsets_loaded,
  910. &osd->tx_size_1023, &nsd->tx_size_1023);
  911. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  912. I40E_GLPRT_PTC1522L(hw->port),
  913. pf->stat_offsets_loaded,
  914. &osd->tx_size_1522, &nsd->tx_size_1522);
  915. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  916. I40E_GLPRT_PTC9522L(hw->port),
  917. pf->stat_offsets_loaded,
  918. &osd->tx_size_big, &nsd->tx_size_big);
  919. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  920. pf->stat_offsets_loaded,
  921. &osd->rx_undersize, &nsd->rx_undersize);
  922. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  923. pf->stat_offsets_loaded,
  924. &osd->rx_fragments, &nsd->rx_fragments);
  925. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  926. pf->stat_offsets_loaded,
  927. &osd->rx_oversize, &nsd->rx_oversize);
  928. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  929. pf->stat_offsets_loaded,
  930. &osd->rx_jabber, &nsd->rx_jabber);
  931. /* FDIR stats */
  932. i40e_stat_update_and_clear32(hw,
  933. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(hw->pf_id)),
  934. &nsd->fd_atr_match);
  935. i40e_stat_update_and_clear32(hw,
  936. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(hw->pf_id)),
  937. &nsd->fd_sb_match);
  938. i40e_stat_update_and_clear32(hw,
  939. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(hw->pf_id)),
  940. &nsd->fd_atr_tunnel_match);
  941. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  942. nsd->tx_lpi_status =
  943. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  944. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  945. nsd->rx_lpi_status =
  946. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  947. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  948. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  949. pf->stat_offsets_loaded,
  950. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  951. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  952. pf->stat_offsets_loaded,
  953. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  954. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  955. !test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
  956. nsd->fd_sb_status = true;
  957. else
  958. nsd->fd_sb_status = false;
  959. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  960. !test_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
  961. nsd->fd_atr_status = true;
  962. else
  963. nsd->fd_atr_status = false;
  964. pf->stat_offsets_loaded = true;
  965. }
  966. /**
  967. * i40e_update_stats - Update the various statistics counters.
  968. * @vsi: the VSI to be updated
  969. *
  970. * Update the various stats for this VSI and its related entities.
  971. **/
  972. void i40e_update_stats(struct i40e_vsi *vsi)
  973. {
  974. struct i40e_pf *pf = vsi->back;
  975. if (vsi == pf->vsi[pf->lan_vsi])
  976. i40e_update_pf_stats(pf);
  977. i40e_update_vsi_stats(vsi);
  978. }
  979. /**
  980. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  981. * @vsi: the VSI to be searched
  982. * @macaddr: the MAC address
  983. * @vlan: the vlan
  984. *
  985. * Returns ptr to the filter object or NULL
  986. **/
  987. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  988. const u8 *macaddr, s16 vlan)
  989. {
  990. struct i40e_mac_filter *f;
  991. u64 key;
  992. if (!vsi || !macaddr)
  993. return NULL;
  994. key = i40e_addr_to_hkey(macaddr);
  995. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  996. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  997. (vlan == f->vlan))
  998. return f;
  999. }
  1000. return NULL;
  1001. }
  1002. /**
  1003. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1004. * @vsi: the VSI to be searched
  1005. * @macaddr: the MAC address we are searching for
  1006. *
  1007. * Returns the first filter with the provided MAC address or NULL if
  1008. * MAC address was not found
  1009. **/
  1010. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1011. {
  1012. struct i40e_mac_filter *f;
  1013. u64 key;
  1014. if (!vsi || !macaddr)
  1015. return NULL;
  1016. key = i40e_addr_to_hkey(macaddr);
  1017. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1018. if ((ether_addr_equal(macaddr, f->macaddr)))
  1019. return f;
  1020. }
  1021. return NULL;
  1022. }
  1023. /**
  1024. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1025. * @vsi: the VSI to be searched
  1026. *
  1027. * Returns true if VSI is in vlan mode or false otherwise
  1028. **/
  1029. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1030. {
  1031. /* If we have a PVID, always operate in VLAN mode */
  1032. if (vsi->info.pvid)
  1033. return true;
  1034. /* We need to operate in VLAN mode whenever we have any filters with
  1035. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1036. * time, incurring search cost repeatedly. However, we can notice two
  1037. * things:
  1038. *
  1039. * 1) the only place where we can gain a VLAN filter is in
  1040. * i40e_add_filter.
  1041. *
  1042. * 2) the only place where filters are actually removed is in
  1043. * i40e_sync_filters_subtask.
  1044. *
  1045. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1046. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1047. * we have to perform the full search after deleting filters in
  1048. * i40e_sync_filters_subtask, but we already have to search
  1049. * filters here and can perform the check at the same time. This
  1050. * results in avoiding embedding a loop for VLAN mode inside another
  1051. * loop over all the filters, and should maintain correctness as noted
  1052. * above.
  1053. */
  1054. return vsi->has_vlan_filter;
  1055. }
  1056. /**
  1057. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1058. * @vsi: the VSI to configure
  1059. * @tmp_add_list: list of filters ready to be added
  1060. * @tmp_del_list: list of filters ready to be deleted
  1061. * @vlan_filters: the number of active VLAN filters
  1062. *
  1063. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1064. * behave as expected. If we have any active VLAN filters remaining or about
  1065. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1066. * so that they only match against untagged traffic. If we no longer have any
  1067. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1068. * so that they match against both tagged and untagged traffic. In this way,
  1069. * we ensure that we correctly receive the desired traffic. This ensures that
  1070. * when we have an active VLAN we will receive only untagged traffic and
  1071. * traffic matching active VLANs. If we have no active VLANs then we will
  1072. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1073. *
  1074. * Finally, in a similar fashion, this function also corrects filters when
  1075. * there is an active PVID assigned to this VSI.
  1076. *
  1077. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1078. *
  1079. * This function is only expected to be called from within
  1080. * i40e_sync_vsi_filters.
  1081. *
  1082. * NOTE: This function expects to be called while under the
  1083. * mac_filter_hash_lock
  1084. */
  1085. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1086. struct hlist_head *tmp_add_list,
  1087. struct hlist_head *tmp_del_list,
  1088. int vlan_filters)
  1089. {
  1090. s16 pvid = le16_to_cpu(vsi->info.pvid);
  1091. struct i40e_mac_filter *f, *add_head;
  1092. struct i40e_new_mac_filter *new;
  1093. struct hlist_node *h;
  1094. int bkt, new_vlan;
  1095. /* To determine if a particular filter needs to be replaced we
  1096. * have the three following conditions:
  1097. *
  1098. * a) if we have a PVID assigned, then all filters which are
  1099. * not marked as VLAN=PVID must be replaced with filters that
  1100. * are.
  1101. * b) otherwise, if we have any active VLANS, all filters
  1102. * which are marked as VLAN=-1 must be replaced with
  1103. * filters marked as VLAN=0
  1104. * c) finally, if we do not have any active VLANS, all filters
  1105. * which are marked as VLAN=0 must be replaced with filters
  1106. * marked as VLAN=-1
  1107. */
  1108. /* Update the filters about to be added in place */
  1109. hlist_for_each_entry(new, tmp_add_list, hlist) {
  1110. if (pvid && new->f->vlan != pvid)
  1111. new->f->vlan = pvid;
  1112. else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
  1113. new->f->vlan = 0;
  1114. else if (!vlan_filters && new->f->vlan == 0)
  1115. new->f->vlan = I40E_VLAN_ANY;
  1116. }
  1117. /* Update the remaining active filters */
  1118. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1119. /* Combine the checks for whether a filter needs to be changed
  1120. * and then determine the new VLAN inside the if block, in
  1121. * order to avoid duplicating code for adding the new filter
  1122. * then deleting the old filter.
  1123. */
  1124. if ((pvid && f->vlan != pvid) ||
  1125. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1126. (!vlan_filters && f->vlan == 0)) {
  1127. /* Determine the new vlan we will be adding */
  1128. if (pvid)
  1129. new_vlan = pvid;
  1130. else if (vlan_filters)
  1131. new_vlan = 0;
  1132. else
  1133. new_vlan = I40E_VLAN_ANY;
  1134. /* Create the new filter */
  1135. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1136. if (!add_head)
  1137. return -ENOMEM;
  1138. /* Create a temporary i40e_new_mac_filter */
  1139. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  1140. if (!new)
  1141. return -ENOMEM;
  1142. new->f = add_head;
  1143. new->state = add_head->state;
  1144. /* Add the new filter to the tmp list */
  1145. hlist_add_head(&new->hlist, tmp_add_list);
  1146. /* Put the original filter into the delete list */
  1147. f->state = I40E_FILTER_REMOVE;
  1148. hash_del(&f->hlist);
  1149. hlist_add_head(&f->hlist, tmp_del_list);
  1150. }
  1151. }
  1152. vsi->has_vlan_filter = !!vlan_filters;
  1153. return 0;
  1154. }
  1155. /**
  1156. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1157. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1158. * @macaddr: the MAC address
  1159. *
  1160. * Remove whatever filter the firmware set up so the driver can manage
  1161. * its own filtering intelligently.
  1162. **/
  1163. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1164. {
  1165. struct i40e_aqc_remove_macvlan_element_data element;
  1166. struct i40e_pf *pf = vsi->back;
  1167. /* Only appropriate for the PF main VSI */
  1168. if (vsi->type != I40E_VSI_MAIN)
  1169. return;
  1170. memset(&element, 0, sizeof(element));
  1171. ether_addr_copy(element.mac_addr, macaddr);
  1172. element.vlan_tag = 0;
  1173. /* Ignore error returns, some firmware does it this way... */
  1174. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1175. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1176. memset(&element, 0, sizeof(element));
  1177. ether_addr_copy(element.mac_addr, macaddr);
  1178. element.vlan_tag = 0;
  1179. /* ...and some firmware does it this way. */
  1180. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1181. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1182. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1183. }
  1184. /**
  1185. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1186. * @vsi: the VSI to be searched
  1187. * @macaddr: the MAC address
  1188. * @vlan: the vlan
  1189. *
  1190. * Returns ptr to the filter object or NULL when no memory available.
  1191. *
  1192. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1193. * being held.
  1194. **/
  1195. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1196. const u8 *macaddr, s16 vlan)
  1197. {
  1198. struct i40e_mac_filter *f;
  1199. u64 key;
  1200. if (!vsi || !macaddr)
  1201. return NULL;
  1202. f = i40e_find_filter(vsi, macaddr, vlan);
  1203. if (!f) {
  1204. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1205. if (!f)
  1206. return NULL;
  1207. /* Update the boolean indicating if we need to function in
  1208. * VLAN mode.
  1209. */
  1210. if (vlan >= 0)
  1211. vsi->has_vlan_filter = true;
  1212. ether_addr_copy(f->macaddr, macaddr);
  1213. f->vlan = vlan;
  1214. f->state = I40E_FILTER_NEW;
  1215. INIT_HLIST_NODE(&f->hlist);
  1216. key = i40e_addr_to_hkey(macaddr);
  1217. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1218. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1219. set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
  1220. }
  1221. /* If we're asked to add a filter that has been marked for removal, it
  1222. * is safe to simply restore it to active state. __i40e_del_filter
  1223. * will have simply deleted any filters which were previously marked
  1224. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1225. * previously been ACTIVE. Since we haven't yet run the sync filters
  1226. * task, just restore this filter to the ACTIVE state so that the
  1227. * sync task leaves it in place
  1228. */
  1229. if (f->state == I40E_FILTER_REMOVE)
  1230. f->state = I40E_FILTER_ACTIVE;
  1231. return f;
  1232. }
  1233. /**
  1234. * __i40e_del_filter - Remove a specific filter from the VSI
  1235. * @vsi: VSI to remove from
  1236. * @f: the filter to remove from the list
  1237. *
  1238. * This function should be called instead of i40e_del_filter only if you know
  1239. * the exact filter you will remove already, such as via i40e_find_filter or
  1240. * i40e_find_mac.
  1241. *
  1242. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1243. * being held.
  1244. * ANOTHER NOTE: This function MUST be called from within the context of
  1245. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1246. * instead of list_for_each_entry().
  1247. **/
  1248. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1249. {
  1250. if (!f)
  1251. return;
  1252. /* If the filter was never added to firmware then we can just delete it
  1253. * directly and we don't want to set the status to remove or else an
  1254. * admin queue command will unnecessarily fire.
  1255. */
  1256. if ((f->state == I40E_FILTER_FAILED) ||
  1257. (f->state == I40E_FILTER_NEW)) {
  1258. hash_del(&f->hlist);
  1259. kfree(f);
  1260. } else {
  1261. f->state = I40E_FILTER_REMOVE;
  1262. }
  1263. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1264. set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->state);
  1265. }
  1266. /**
  1267. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1268. * @vsi: the VSI to be searched
  1269. * @macaddr: the MAC address
  1270. * @vlan: the VLAN
  1271. *
  1272. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1273. * being held.
  1274. * ANOTHER NOTE: This function MUST be called from within the context of
  1275. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1276. * instead of list_for_each_entry().
  1277. **/
  1278. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1279. {
  1280. struct i40e_mac_filter *f;
  1281. if (!vsi || !macaddr)
  1282. return;
  1283. f = i40e_find_filter(vsi, macaddr, vlan);
  1284. __i40e_del_filter(vsi, f);
  1285. }
  1286. /**
  1287. * i40e_add_mac_filter - Add a MAC filter for all active VLANs
  1288. * @vsi: the VSI to be searched
  1289. * @macaddr: the mac address to be filtered
  1290. *
  1291. * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
  1292. * go through all the macvlan filters and add a macvlan filter for each
  1293. * unique vlan that already exists. If a PVID has been assigned, instead only
  1294. * add the macaddr to that VLAN.
  1295. *
  1296. * Returns last filter added on success, else NULL
  1297. **/
  1298. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1299. const u8 *macaddr)
  1300. {
  1301. struct i40e_mac_filter *f, *add = NULL;
  1302. struct hlist_node *h;
  1303. int bkt;
  1304. if (vsi->info.pvid)
  1305. return i40e_add_filter(vsi, macaddr,
  1306. le16_to_cpu(vsi->info.pvid));
  1307. if (!i40e_is_vsi_in_vlan(vsi))
  1308. return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
  1309. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1310. if (f->state == I40E_FILTER_REMOVE)
  1311. continue;
  1312. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1313. if (!add)
  1314. return NULL;
  1315. }
  1316. return add;
  1317. }
  1318. /**
  1319. * i40e_del_mac_filter - Remove a MAC filter from all VLANs
  1320. * @vsi: the VSI to be searched
  1321. * @macaddr: the mac address to be removed
  1322. *
  1323. * Removes a given MAC address from a VSI regardless of what VLAN it has been
  1324. * associated with.
  1325. *
  1326. * Returns 0 for success, or error
  1327. **/
  1328. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
  1329. {
  1330. struct i40e_mac_filter *f;
  1331. struct hlist_node *h;
  1332. bool found = false;
  1333. int bkt;
  1334. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1335. "Missing mac_filter_hash_lock\n");
  1336. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1337. if (ether_addr_equal(macaddr, f->macaddr)) {
  1338. __i40e_del_filter(vsi, f);
  1339. found = true;
  1340. }
  1341. }
  1342. if (found)
  1343. return 0;
  1344. else
  1345. return -ENOENT;
  1346. }
  1347. /**
  1348. * i40e_set_mac - NDO callback to set mac address
  1349. * @netdev: network interface device structure
  1350. * @p: pointer to an address structure
  1351. *
  1352. * Returns 0 on success, negative on failure
  1353. **/
  1354. static int i40e_set_mac(struct net_device *netdev, void *p)
  1355. {
  1356. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1357. struct i40e_vsi *vsi = np->vsi;
  1358. struct i40e_pf *pf = vsi->back;
  1359. struct i40e_hw *hw = &pf->hw;
  1360. struct sockaddr *addr = p;
  1361. if (!is_valid_ether_addr(addr->sa_data))
  1362. return -EADDRNOTAVAIL;
  1363. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1364. netdev_info(netdev, "already using mac address %pM\n",
  1365. addr->sa_data);
  1366. return 0;
  1367. }
  1368. if (test_bit(__I40E_VSI_DOWN, vsi->back->state) ||
  1369. test_bit(__I40E_RESET_RECOVERY_PENDING, vsi->back->state))
  1370. return -EADDRNOTAVAIL;
  1371. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1372. netdev_info(netdev, "returning to hw mac address %pM\n",
  1373. hw->mac.addr);
  1374. else
  1375. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1376. /* Copy the address first, so that we avoid a possible race with
  1377. * .set_rx_mode(). If we copy after changing the address in the filter
  1378. * list, we might open ourselves to a narrow race window where
  1379. * .set_rx_mode could delete our dev_addr filter and prevent traffic
  1380. * from passing.
  1381. */
  1382. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1383. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1384. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1385. i40e_add_mac_filter(vsi, addr->sa_data);
  1386. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1387. if (vsi->type == I40E_VSI_MAIN) {
  1388. i40e_status ret;
  1389. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1390. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1391. addr->sa_data, NULL);
  1392. if (ret)
  1393. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1394. i40e_stat_str(hw, ret),
  1395. i40e_aq_str(hw, hw->aq.asq_last_status));
  1396. }
  1397. /* schedule our worker thread which will take care of
  1398. * applying the new filter changes
  1399. */
  1400. i40e_service_event_schedule(vsi->back);
  1401. return 0;
  1402. }
  1403. /**
  1404. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  1405. * @vsi: vsi structure
  1406. * @seed: RSS hash seed
  1407. **/
  1408. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  1409. u8 *lut, u16 lut_size)
  1410. {
  1411. struct i40e_pf *pf = vsi->back;
  1412. struct i40e_hw *hw = &pf->hw;
  1413. int ret = 0;
  1414. if (seed) {
  1415. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  1416. (struct i40e_aqc_get_set_rss_key_data *)seed;
  1417. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  1418. if (ret) {
  1419. dev_info(&pf->pdev->dev,
  1420. "Cannot set RSS key, err %s aq_err %s\n",
  1421. i40e_stat_str(hw, ret),
  1422. i40e_aq_str(hw, hw->aq.asq_last_status));
  1423. return ret;
  1424. }
  1425. }
  1426. if (lut) {
  1427. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  1428. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  1429. if (ret) {
  1430. dev_info(&pf->pdev->dev,
  1431. "Cannot set RSS lut, err %s aq_err %s\n",
  1432. i40e_stat_str(hw, ret),
  1433. i40e_aq_str(hw, hw->aq.asq_last_status));
  1434. return ret;
  1435. }
  1436. }
  1437. return ret;
  1438. }
  1439. /**
  1440. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  1441. * @vsi: VSI structure
  1442. **/
  1443. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  1444. {
  1445. struct i40e_pf *pf = vsi->back;
  1446. u8 seed[I40E_HKEY_ARRAY_SIZE];
  1447. u8 *lut;
  1448. int ret;
  1449. if (!(pf->hw_features & I40E_HW_RSS_AQ_CAPABLE))
  1450. return 0;
  1451. if (!vsi->rss_size)
  1452. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  1453. vsi->num_queue_pairs);
  1454. if (!vsi->rss_size)
  1455. return -EINVAL;
  1456. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  1457. if (!lut)
  1458. return -ENOMEM;
  1459. /* Use the user configured hash keys and lookup table if there is one,
  1460. * otherwise use default
  1461. */
  1462. if (vsi->rss_lut_user)
  1463. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  1464. else
  1465. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  1466. if (vsi->rss_hkey_user)
  1467. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  1468. else
  1469. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  1470. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  1471. kfree(lut);
  1472. return ret;
  1473. }
  1474. /**
  1475. * i40e_vsi_setup_queue_map_mqprio - Prepares mqprio based tc_config
  1476. * @vsi: the VSI being configured,
  1477. * @ctxt: VSI context structure
  1478. * @enabled_tc: number of traffic classes to enable
  1479. *
  1480. * Prepares VSI tc_config to have queue configurations based on MQPRIO options.
  1481. **/
  1482. static int i40e_vsi_setup_queue_map_mqprio(struct i40e_vsi *vsi,
  1483. struct i40e_vsi_context *ctxt,
  1484. u8 enabled_tc)
  1485. {
  1486. u16 qcount = 0, max_qcount, qmap, sections = 0;
  1487. int i, override_q, pow, num_qps, ret;
  1488. u8 netdev_tc = 0, offset = 0;
  1489. if (vsi->type != I40E_VSI_MAIN)
  1490. return -EINVAL;
  1491. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1492. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1493. vsi->tc_config.numtc = vsi->mqprio_qopt.qopt.num_tc;
  1494. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1495. num_qps = vsi->mqprio_qopt.qopt.count[0];
  1496. /* find the next higher power-of-2 of num queue pairs */
  1497. pow = ilog2(num_qps);
  1498. if (!is_power_of_2(num_qps))
  1499. pow++;
  1500. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1501. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1502. /* Setup queue offset/count for all TCs for given VSI */
  1503. max_qcount = vsi->mqprio_qopt.qopt.count[0];
  1504. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1505. /* See if the given TC is enabled for the given VSI */
  1506. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1507. offset = vsi->mqprio_qopt.qopt.offset[i];
  1508. qcount = vsi->mqprio_qopt.qopt.count[i];
  1509. if (qcount > max_qcount)
  1510. max_qcount = qcount;
  1511. vsi->tc_config.tc_info[i].qoffset = offset;
  1512. vsi->tc_config.tc_info[i].qcount = qcount;
  1513. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1514. } else {
  1515. /* TC is not enabled so set the offset to
  1516. * default queue and allocate one queue
  1517. * for the given TC.
  1518. */
  1519. vsi->tc_config.tc_info[i].qoffset = 0;
  1520. vsi->tc_config.tc_info[i].qcount = 1;
  1521. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1522. }
  1523. }
  1524. /* Set actual Tx/Rx queue pairs */
  1525. vsi->num_queue_pairs = offset + qcount;
  1526. /* Setup queue TC[0].qmap for given VSI context */
  1527. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  1528. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1529. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1530. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1531. /* Reconfigure RSS for main VSI with max queue count */
  1532. vsi->rss_size = max_qcount;
  1533. ret = i40e_vsi_config_rss(vsi);
  1534. if (ret) {
  1535. dev_info(&vsi->back->pdev->dev,
  1536. "Failed to reconfig rss for num_queues (%u)\n",
  1537. max_qcount);
  1538. return ret;
  1539. }
  1540. vsi->reconfig_rss = true;
  1541. dev_dbg(&vsi->back->pdev->dev,
  1542. "Reconfigured rss with num_queues (%u)\n", max_qcount);
  1543. /* Find queue count available for channel VSIs and starting offset
  1544. * for channel VSIs
  1545. */
  1546. override_q = vsi->mqprio_qopt.qopt.count[0];
  1547. if (override_q && override_q < vsi->num_queue_pairs) {
  1548. vsi->cnt_q_avail = vsi->num_queue_pairs - override_q;
  1549. vsi->next_base_queue = override_q;
  1550. }
  1551. return 0;
  1552. }
  1553. /**
  1554. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1555. * @vsi: the VSI being setup
  1556. * @ctxt: VSI context structure
  1557. * @enabled_tc: Enabled TCs bitmap
  1558. * @is_add: True if called before Add VSI
  1559. *
  1560. * Setup VSI queue mapping for enabled traffic classes.
  1561. **/
  1562. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1563. struct i40e_vsi_context *ctxt,
  1564. u8 enabled_tc,
  1565. bool is_add)
  1566. {
  1567. struct i40e_pf *pf = vsi->back;
  1568. u16 sections = 0;
  1569. u8 netdev_tc = 0;
  1570. u16 numtc = 1;
  1571. u16 qcount;
  1572. u8 offset;
  1573. u16 qmap;
  1574. int i;
  1575. u16 num_tc_qps = 0;
  1576. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1577. offset = 0;
  1578. /* Number of queues per enabled TC */
  1579. num_tc_qps = vsi->alloc_queue_pairs;
  1580. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1581. /* Find numtc from enabled TC bitmap */
  1582. for (i = 0, numtc = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1583. if (enabled_tc & BIT(i)) /* TC is enabled */
  1584. numtc++;
  1585. }
  1586. if (!numtc) {
  1587. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1588. numtc = 1;
  1589. }
  1590. num_tc_qps = num_tc_qps / numtc;
  1591. num_tc_qps = min_t(int, num_tc_qps,
  1592. i40e_pf_get_max_q_per_tc(pf));
  1593. }
  1594. vsi->tc_config.numtc = numtc;
  1595. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1596. /* Do not allow use more TC queue pairs than MSI-X vectors exist */
  1597. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1598. num_tc_qps = min_t(int, num_tc_qps, pf->num_lan_msix);
  1599. /* Setup queue offset/count for all TCs for given VSI */
  1600. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1601. /* See if the given TC is enabled for the given VSI */
  1602. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1603. /* TC is enabled */
  1604. int pow, num_qps;
  1605. switch (vsi->type) {
  1606. case I40E_VSI_MAIN:
  1607. if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED |
  1608. I40E_FLAG_FD_ATR_ENABLED)) ||
  1609. vsi->tc_config.enabled_tc != 1) {
  1610. qcount = min_t(int, pf->alloc_rss_size,
  1611. num_tc_qps);
  1612. break;
  1613. }
  1614. case I40E_VSI_FDIR:
  1615. case I40E_VSI_SRIOV:
  1616. case I40E_VSI_VMDQ2:
  1617. default:
  1618. qcount = num_tc_qps;
  1619. WARN_ON(i != 0);
  1620. break;
  1621. }
  1622. vsi->tc_config.tc_info[i].qoffset = offset;
  1623. vsi->tc_config.tc_info[i].qcount = qcount;
  1624. /* find the next higher power-of-2 of num queue pairs */
  1625. num_qps = qcount;
  1626. pow = 0;
  1627. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1628. pow++;
  1629. num_qps >>= 1;
  1630. }
  1631. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1632. qmap =
  1633. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1634. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1635. offset += qcount;
  1636. } else {
  1637. /* TC is not enabled so set the offset to
  1638. * default queue and allocate one queue
  1639. * for the given TC.
  1640. */
  1641. vsi->tc_config.tc_info[i].qoffset = 0;
  1642. vsi->tc_config.tc_info[i].qcount = 1;
  1643. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1644. qmap = 0;
  1645. }
  1646. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1647. }
  1648. /* Set actual Tx/Rx queue pairs */
  1649. vsi->num_queue_pairs = offset;
  1650. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1651. if (vsi->req_queue_pairs > 0)
  1652. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1653. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1654. vsi->num_queue_pairs = pf->num_lan_msix;
  1655. }
  1656. /* Scheduler section valid can only be set for ADD VSI */
  1657. if (is_add) {
  1658. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1659. ctxt->info.up_enable_bits = enabled_tc;
  1660. }
  1661. if (vsi->type == I40E_VSI_SRIOV) {
  1662. ctxt->info.mapping_flags |=
  1663. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1664. for (i = 0; i < vsi->num_queue_pairs; i++)
  1665. ctxt->info.queue_mapping[i] =
  1666. cpu_to_le16(vsi->base_queue + i);
  1667. } else {
  1668. ctxt->info.mapping_flags |=
  1669. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1670. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1671. }
  1672. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1673. }
  1674. /**
  1675. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1676. * @netdev: the netdevice
  1677. * @addr: address to add
  1678. *
  1679. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1680. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1681. */
  1682. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1683. {
  1684. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1685. struct i40e_vsi *vsi = np->vsi;
  1686. if (i40e_add_mac_filter(vsi, addr))
  1687. return 0;
  1688. else
  1689. return -ENOMEM;
  1690. }
  1691. /**
  1692. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1693. * @netdev: the netdevice
  1694. * @addr: address to add
  1695. *
  1696. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1697. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1698. */
  1699. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1700. {
  1701. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1702. struct i40e_vsi *vsi = np->vsi;
  1703. /* Under some circumstances, we might receive a request to delete
  1704. * our own device address from our uc list. Because we store the
  1705. * device address in the VSI's MAC/VLAN filter list, we need to ignore
  1706. * such requests and not delete our device address from this list.
  1707. */
  1708. if (ether_addr_equal(addr, netdev->dev_addr))
  1709. return 0;
  1710. i40e_del_mac_filter(vsi, addr);
  1711. return 0;
  1712. }
  1713. /**
  1714. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1715. * @netdev: network interface device structure
  1716. **/
  1717. static void i40e_set_rx_mode(struct net_device *netdev)
  1718. {
  1719. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1720. struct i40e_vsi *vsi = np->vsi;
  1721. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1722. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1723. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1724. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1725. /* check for other flag changes */
  1726. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1727. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1728. set_bit(__I40E_MACVLAN_SYNC_PENDING, vsi->back->state);
  1729. }
  1730. }
  1731. /**
  1732. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1733. * @vsi: Pointer to VSI struct
  1734. * @from: Pointer to list which contains MAC filter entries - changes to
  1735. * those entries needs to be undone.
  1736. *
  1737. * MAC filter entries from this list were slated for deletion.
  1738. **/
  1739. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1740. struct hlist_head *from)
  1741. {
  1742. struct i40e_mac_filter *f;
  1743. struct hlist_node *h;
  1744. hlist_for_each_entry_safe(f, h, from, hlist) {
  1745. u64 key = i40e_addr_to_hkey(f->macaddr);
  1746. /* Move the element back into MAC filter list*/
  1747. hlist_del(&f->hlist);
  1748. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1749. }
  1750. }
  1751. /**
  1752. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1753. * @vsi: Pointer to vsi struct
  1754. * @from: Pointer to list which contains MAC filter entries - changes to
  1755. * those entries needs to be undone.
  1756. *
  1757. * MAC filter entries from this list were slated for addition.
  1758. **/
  1759. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
  1760. struct hlist_head *from)
  1761. {
  1762. struct i40e_new_mac_filter *new;
  1763. struct hlist_node *h;
  1764. hlist_for_each_entry_safe(new, h, from, hlist) {
  1765. /* We can simply free the wrapper structure */
  1766. hlist_del(&new->hlist);
  1767. kfree(new);
  1768. }
  1769. }
  1770. /**
  1771. * i40e_next_entry - Get the next non-broadcast filter from a list
  1772. * @next: pointer to filter in list
  1773. *
  1774. * Returns the next non-broadcast filter in the list. Required so that we
  1775. * ignore broadcast filters within the list, since these are not handled via
  1776. * the normal firmware update path.
  1777. */
  1778. static
  1779. struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
  1780. {
  1781. hlist_for_each_entry_continue(next, hlist) {
  1782. if (!is_broadcast_ether_addr(next->f->macaddr))
  1783. return next;
  1784. }
  1785. return NULL;
  1786. }
  1787. /**
  1788. * i40e_update_filter_state - Update filter state based on return data
  1789. * from firmware
  1790. * @count: Number of filters added
  1791. * @add_list: return data from fw
  1792. * @add_head: pointer to first filter in current batch
  1793. *
  1794. * MAC filter entries from list were slated to be added to device. Returns
  1795. * number of successful filters. Note that 0 does NOT mean success!
  1796. **/
  1797. static int
  1798. i40e_update_filter_state(int count,
  1799. struct i40e_aqc_add_macvlan_element_data *add_list,
  1800. struct i40e_new_mac_filter *add_head)
  1801. {
  1802. int retval = 0;
  1803. int i;
  1804. for (i = 0; i < count; i++) {
  1805. /* Always check status of each filter. We don't need to check
  1806. * the firmware return status because we pre-set the filter
  1807. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1808. * request to the adminq. Thus, if it no longer matches then
  1809. * we know the filter is active.
  1810. */
  1811. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1812. add_head->state = I40E_FILTER_FAILED;
  1813. } else {
  1814. add_head->state = I40E_FILTER_ACTIVE;
  1815. retval++;
  1816. }
  1817. add_head = i40e_next_filter(add_head);
  1818. if (!add_head)
  1819. break;
  1820. }
  1821. return retval;
  1822. }
  1823. /**
  1824. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1825. * @vsi: ptr to the VSI
  1826. * @vsi_name: name to display in messages
  1827. * @list: the list of filters to send to firmware
  1828. * @num_del: the number of filters to delete
  1829. * @retval: Set to -EIO on failure to delete
  1830. *
  1831. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1832. * *retval instead of a return value so that success does not force ret_val to
  1833. * be set to 0. This ensures that a sequence of calls to this function
  1834. * preserve the previous value of *retval on successful delete.
  1835. */
  1836. static
  1837. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1838. struct i40e_aqc_remove_macvlan_element_data *list,
  1839. int num_del, int *retval)
  1840. {
  1841. struct i40e_hw *hw = &vsi->back->hw;
  1842. i40e_status aq_ret;
  1843. int aq_err;
  1844. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1845. aq_err = hw->aq.asq_last_status;
  1846. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1847. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1848. *retval = -EIO;
  1849. dev_info(&vsi->back->pdev->dev,
  1850. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1851. vsi_name, i40e_stat_str(hw, aq_ret),
  1852. i40e_aq_str(hw, aq_err));
  1853. }
  1854. }
  1855. /**
  1856. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1857. * @vsi: ptr to the VSI
  1858. * @vsi_name: name to display in messages
  1859. * @list: the list of filters to send to firmware
  1860. * @add_head: Position in the add hlist
  1861. * @num_add: the number of filters to add
  1862. *
  1863. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1864. * __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
  1865. * space for more filters.
  1866. */
  1867. static
  1868. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1869. struct i40e_aqc_add_macvlan_element_data *list,
  1870. struct i40e_new_mac_filter *add_head,
  1871. int num_add)
  1872. {
  1873. struct i40e_hw *hw = &vsi->back->hw;
  1874. int aq_err, fcnt;
  1875. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1876. aq_err = hw->aq.asq_last_status;
  1877. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1878. if (fcnt != num_add) {
  1879. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1880. dev_warn(&vsi->back->pdev->dev,
  1881. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1882. i40e_aq_str(hw, aq_err),
  1883. vsi_name);
  1884. }
  1885. }
  1886. /**
  1887. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1888. * @vsi: pointer to the VSI
  1889. * @vsi_name: the VSI name
  1890. * @f: filter data
  1891. *
  1892. * This function sets or clears the promiscuous broadcast flags for VLAN
  1893. * filters in order to properly receive broadcast frames. Assumes that only
  1894. * broadcast filters are passed.
  1895. *
  1896. * Returns status indicating success or failure;
  1897. **/
  1898. static i40e_status
  1899. i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1900. struct i40e_mac_filter *f)
  1901. {
  1902. bool enable = f->state == I40E_FILTER_NEW;
  1903. struct i40e_hw *hw = &vsi->back->hw;
  1904. i40e_status aq_ret;
  1905. if (f->vlan == I40E_VLAN_ANY) {
  1906. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1907. vsi->seid,
  1908. enable,
  1909. NULL);
  1910. } else {
  1911. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1912. vsi->seid,
  1913. enable,
  1914. f->vlan,
  1915. NULL);
  1916. }
  1917. if (aq_ret) {
  1918. set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  1919. dev_warn(&vsi->back->pdev->dev,
  1920. "Error %s, forcing overflow promiscuous on %s\n",
  1921. i40e_aq_str(hw, hw->aq.asq_last_status),
  1922. vsi_name);
  1923. }
  1924. return aq_ret;
  1925. }
  1926. /**
  1927. * i40e_set_promiscuous - set promiscuous mode
  1928. * @pf: board private structure
  1929. * @promisc: promisc on or off
  1930. *
  1931. * There are different ways of setting promiscuous mode on a PF depending on
  1932. * what state/environment we're in. This identifies and sets it appropriately.
  1933. * Returns 0 on success.
  1934. **/
  1935. static int i40e_set_promiscuous(struct i40e_pf *pf, bool promisc)
  1936. {
  1937. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1938. struct i40e_hw *hw = &pf->hw;
  1939. i40e_status aq_ret;
  1940. if (vsi->type == I40E_VSI_MAIN &&
  1941. pf->lan_veb != I40E_NO_VEB &&
  1942. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1943. /* set defport ON for Main VSI instead of true promisc
  1944. * this way we will get all unicast/multicast and VLAN
  1945. * promisc behavior but will not get VF or VMDq traffic
  1946. * replicated on the Main VSI.
  1947. */
  1948. if (promisc)
  1949. aq_ret = i40e_aq_set_default_vsi(hw,
  1950. vsi->seid,
  1951. NULL);
  1952. else
  1953. aq_ret = i40e_aq_clear_default_vsi(hw,
  1954. vsi->seid,
  1955. NULL);
  1956. if (aq_ret) {
  1957. dev_info(&pf->pdev->dev,
  1958. "Set default VSI failed, err %s, aq_err %s\n",
  1959. i40e_stat_str(hw, aq_ret),
  1960. i40e_aq_str(hw, hw->aq.asq_last_status));
  1961. }
  1962. } else {
  1963. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1964. hw,
  1965. vsi->seid,
  1966. promisc, NULL,
  1967. true);
  1968. if (aq_ret) {
  1969. dev_info(&pf->pdev->dev,
  1970. "set unicast promisc failed, err %s, aq_err %s\n",
  1971. i40e_stat_str(hw, aq_ret),
  1972. i40e_aq_str(hw, hw->aq.asq_last_status));
  1973. }
  1974. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  1975. hw,
  1976. vsi->seid,
  1977. promisc, NULL);
  1978. if (aq_ret) {
  1979. dev_info(&pf->pdev->dev,
  1980. "set multicast promisc failed, err %s, aq_err %s\n",
  1981. i40e_stat_str(hw, aq_ret),
  1982. i40e_aq_str(hw, hw->aq.asq_last_status));
  1983. }
  1984. }
  1985. if (!aq_ret)
  1986. pf->cur_promisc = promisc;
  1987. return aq_ret;
  1988. }
  1989. /**
  1990. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1991. * @vsi: ptr to the VSI
  1992. *
  1993. * Push any outstanding VSI filter changes through the AdminQ.
  1994. *
  1995. * Returns 0 or error value
  1996. **/
  1997. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1998. {
  1999. struct hlist_head tmp_add_list, tmp_del_list;
  2000. struct i40e_mac_filter *f;
  2001. struct i40e_new_mac_filter *new, *add_head = NULL;
  2002. struct i40e_hw *hw = &vsi->back->hw;
  2003. bool old_overflow, new_overflow;
  2004. unsigned int failed_filters = 0;
  2005. unsigned int vlan_filters = 0;
  2006. char vsi_name[16] = "PF";
  2007. int filter_list_len = 0;
  2008. i40e_status aq_ret = 0;
  2009. u32 changed_flags = 0;
  2010. struct hlist_node *h;
  2011. struct i40e_pf *pf;
  2012. int num_add = 0;
  2013. int num_del = 0;
  2014. int retval = 0;
  2015. u16 cmd_flags;
  2016. int list_size;
  2017. int bkt;
  2018. /* empty array typed pointers, kcalloc later */
  2019. struct i40e_aqc_add_macvlan_element_data *add_list;
  2020. struct i40e_aqc_remove_macvlan_element_data *del_list;
  2021. while (test_and_set_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state))
  2022. usleep_range(1000, 2000);
  2023. pf = vsi->back;
  2024. old_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2025. if (vsi->netdev) {
  2026. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  2027. vsi->current_netdev_flags = vsi->netdev->flags;
  2028. }
  2029. INIT_HLIST_HEAD(&tmp_add_list);
  2030. INIT_HLIST_HEAD(&tmp_del_list);
  2031. if (vsi->type == I40E_VSI_SRIOV)
  2032. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  2033. else if (vsi->type != I40E_VSI_MAIN)
  2034. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  2035. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  2036. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  2037. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2038. /* Create a list of filters to delete. */
  2039. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2040. if (f->state == I40E_FILTER_REMOVE) {
  2041. /* Move the element into temporary del_list */
  2042. hash_del(&f->hlist);
  2043. hlist_add_head(&f->hlist, &tmp_del_list);
  2044. /* Avoid counting removed filters */
  2045. continue;
  2046. }
  2047. if (f->state == I40E_FILTER_NEW) {
  2048. /* Create a temporary i40e_new_mac_filter */
  2049. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  2050. if (!new)
  2051. goto err_no_memory_locked;
  2052. /* Store pointer to the real filter */
  2053. new->f = f;
  2054. new->state = f->state;
  2055. /* Add it to the hash list */
  2056. hlist_add_head(&new->hlist, &tmp_add_list);
  2057. }
  2058. /* Count the number of active (current and new) VLAN
  2059. * filters we have now. Does not count filters which
  2060. * are marked for deletion.
  2061. */
  2062. if (f->vlan > 0)
  2063. vlan_filters++;
  2064. }
  2065. retval = i40e_correct_mac_vlan_filters(vsi,
  2066. &tmp_add_list,
  2067. &tmp_del_list,
  2068. vlan_filters);
  2069. if (retval)
  2070. goto err_no_memory_locked;
  2071. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2072. }
  2073. /* Now process 'del_list' outside the lock */
  2074. if (!hlist_empty(&tmp_del_list)) {
  2075. filter_list_len = hw->aq.asq_buf_size /
  2076. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2077. list_size = filter_list_len *
  2078. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  2079. del_list = kzalloc(list_size, GFP_ATOMIC);
  2080. if (!del_list)
  2081. goto err_no_memory;
  2082. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  2083. cmd_flags = 0;
  2084. /* handle broadcast filters by updating the broadcast
  2085. * promiscuous flag and release filter list.
  2086. */
  2087. if (is_broadcast_ether_addr(f->macaddr)) {
  2088. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  2089. hlist_del(&f->hlist);
  2090. kfree(f);
  2091. continue;
  2092. }
  2093. /* add to delete list */
  2094. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  2095. if (f->vlan == I40E_VLAN_ANY) {
  2096. del_list[num_del].vlan_tag = 0;
  2097. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  2098. } else {
  2099. del_list[num_del].vlan_tag =
  2100. cpu_to_le16((u16)(f->vlan));
  2101. }
  2102. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  2103. del_list[num_del].flags = cmd_flags;
  2104. num_del++;
  2105. /* flush a full buffer */
  2106. if (num_del == filter_list_len) {
  2107. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2108. num_del, &retval);
  2109. memset(del_list, 0, list_size);
  2110. num_del = 0;
  2111. }
  2112. /* Release memory for MAC filter entries which were
  2113. * synced up with HW.
  2114. */
  2115. hlist_del(&f->hlist);
  2116. kfree(f);
  2117. }
  2118. if (num_del) {
  2119. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  2120. num_del, &retval);
  2121. }
  2122. kfree(del_list);
  2123. del_list = NULL;
  2124. }
  2125. if (!hlist_empty(&tmp_add_list)) {
  2126. /* Do all the adds now. */
  2127. filter_list_len = hw->aq.asq_buf_size /
  2128. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2129. list_size = filter_list_len *
  2130. sizeof(struct i40e_aqc_add_macvlan_element_data);
  2131. add_list = kzalloc(list_size, GFP_ATOMIC);
  2132. if (!add_list)
  2133. goto err_no_memory;
  2134. num_add = 0;
  2135. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2136. /* handle broadcast filters by updating the broadcast
  2137. * promiscuous flag instead of adding a MAC filter.
  2138. */
  2139. if (is_broadcast_ether_addr(new->f->macaddr)) {
  2140. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  2141. new->f))
  2142. new->state = I40E_FILTER_FAILED;
  2143. else
  2144. new->state = I40E_FILTER_ACTIVE;
  2145. continue;
  2146. }
  2147. /* add to add array */
  2148. if (num_add == 0)
  2149. add_head = new;
  2150. cmd_flags = 0;
  2151. ether_addr_copy(add_list[num_add].mac_addr,
  2152. new->f->macaddr);
  2153. if (new->f->vlan == I40E_VLAN_ANY) {
  2154. add_list[num_add].vlan_tag = 0;
  2155. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2156. } else {
  2157. add_list[num_add].vlan_tag =
  2158. cpu_to_le16((u16)(new->f->vlan));
  2159. }
  2160. add_list[num_add].queue_number = 0;
  2161. /* set invalid match method for later detection */
  2162. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2163. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2164. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2165. num_add++;
  2166. /* flush a full buffer */
  2167. if (num_add == filter_list_len) {
  2168. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2169. add_head, num_add);
  2170. memset(add_list, 0, list_size);
  2171. num_add = 0;
  2172. }
  2173. }
  2174. if (num_add) {
  2175. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2176. num_add);
  2177. }
  2178. /* Now move all of the filters from the temp add list back to
  2179. * the VSI's list.
  2180. */
  2181. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2182. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2183. /* Only update the state if we're still NEW */
  2184. if (new->f->state == I40E_FILTER_NEW)
  2185. new->f->state = new->state;
  2186. hlist_del(&new->hlist);
  2187. kfree(new);
  2188. }
  2189. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2190. kfree(add_list);
  2191. add_list = NULL;
  2192. }
  2193. /* Determine the number of active and failed filters. */
  2194. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2195. vsi->active_filters = 0;
  2196. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2197. if (f->state == I40E_FILTER_ACTIVE)
  2198. vsi->active_filters++;
  2199. else if (f->state == I40E_FILTER_FAILED)
  2200. failed_filters++;
  2201. }
  2202. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2203. /* Check if we are able to exit overflow promiscuous mode. We can
  2204. * safely exit if we didn't just enter, we no longer have any failed
  2205. * filters, and we have reduced filters below the threshold value.
  2206. */
  2207. if (old_overflow && !failed_filters &&
  2208. vsi->active_filters < vsi->promisc_threshold) {
  2209. dev_info(&pf->pdev->dev,
  2210. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2211. vsi_name);
  2212. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2213. vsi->promisc_threshold = 0;
  2214. }
  2215. /* if the VF is not trusted do not do promisc */
  2216. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2217. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2218. goto out;
  2219. }
  2220. new_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  2221. /* If we are entering overflow promiscuous, we need to calculate a new
  2222. * threshold for when we are safe to exit
  2223. */
  2224. if (!old_overflow && new_overflow)
  2225. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2226. /* check for changes in promiscuous modes */
  2227. if (changed_flags & IFF_ALLMULTI) {
  2228. bool cur_multipromisc;
  2229. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2230. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2231. vsi->seid,
  2232. cur_multipromisc,
  2233. NULL);
  2234. if (aq_ret) {
  2235. retval = i40e_aq_rc_to_posix(aq_ret,
  2236. hw->aq.asq_last_status);
  2237. dev_info(&pf->pdev->dev,
  2238. "set multi promisc failed on %s, err %s aq_err %s\n",
  2239. vsi_name,
  2240. i40e_stat_str(hw, aq_ret),
  2241. i40e_aq_str(hw, hw->aq.asq_last_status));
  2242. }
  2243. }
  2244. if ((changed_flags & IFF_PROMISC) || old_overflow != new_overflow) {
  2245. bool cur_promisc;
  2246. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2247. new_overflow);
  2248. aq_ret = i40e_set_promiscuous(pf, cur_promisc);
  2249. if (aq_ret) {
  2250. retval = i40e_aq_rc_to_posix(aq_ret,
  2251. hw->aq.asq_last_status);
  2252. dev_info(&pf->pdev->dev,
  2253. "Setting promiscuous %s failed on %s, err %s aq_err %s\n",
  2254. cur_promisc ? "on" : "off",
  2255. vsi_name,
  2256. i40e_stat_str(hw, aq_ret),
  2257. i40e_aq_str(hw, hw->aq.asq_last_status));
  2258. }
  2259. }
  2260. out:
  2261. /* if something went wrong then set the changed flag so we try again */
  2262. if (retval)
  2263. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2264. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2265. return retval;
  2266. err_no_memory:
  2267. /* Restore elements on the temporary add and delete lists */
  2268. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2269. err_no_memory_locked:
  2270. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2271. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2272. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2273. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2274. clear_bit(__I40E_VSI_SYNCING_FILTERS, vsi->state);
  2275. return -ENOMEM;
  2276. }
  2277. /**
  2278. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2279. * @pf: board private structure
  2280. **/
  2281. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2282. {
  2283. int v;
  2284. if (!pf)
  2285. return;
  2286. if (!test_and_clear_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state))
  2287. return;
  2288. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2289. if (pf->vsi[v] &&
  2290. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2291. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2292. if (ret) {
  2293. /* come back and try again later */
  2294. set_bit(__I40E_MACVLAN_SYNC_PENDING,
  2295. pf->state);
  2296. break;
  2297. }
  2298. }
  2299. }
  2300. }
  2301. /**
  2302. * i40e_max_xdp_frame_size - returns the maximum allowed frame size for XDP
  2303. * @vsi: the vsi
  2304. **/
  2305. static int i40e_max_xdp_frame_size(struct i40e_vsi *vsi)
  2306. {
  2307. if (PAGE_SIZE >= 8192 || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2308. return I40E_RXBUFFER_2048;
  2309. else
  2310. return I40E_RXBUFFER_3072;
  2311. }
  2312. /**
  2313. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2314. * @netdev: network interface device structure
  2315. * @new_mtu: new value for maximum frame size
  2316. *
  2317. * Returns 0 on success, negative on failure
  2318. **/
  2319. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2320. {
  2321. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2322. struct i40e_vsi *vsi = np->vsi;
  2323. struct i40e_pf *pf = vsi->back;
  2324. if (i40e_enabled_xdp_vsi(vsi)) {
  2325. int frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2326. if (frame_size > i40e_max_xdp_frame_size(vsi))
  2327. return -EINVAL;
  2328. }
  2329. netdev_info(netdev, "changing MTU from %d to %d\n",
  2330. netdev->mtu, new_mtu);
  2331. netdev->mtu = new_mtu;
  2332. if (netif_running(netdev))
  2333. i40e_vsi_reinit_locked(vsi);
  2334. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  2335. set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
  2336. return 0;
  2337. }
  2338. /**
  2339. * i40e_ioctl - Access the hwtstamp interface
  2340. * @netdev: network interface device structure
  2341. * @ifr: interface request data
  2342. * @cmd: ioctl command
  2343. **/
  2344. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2345. {
  2346. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2347. struct i40e_pf *pf = np->vsi->back;
  2348. switch (cmd) {
  2349. case SIOCGHWTSTAMP:
  2350. return i40e_ptp_get_ts_config(pf, ifr);
  2351. case SIOCSHWTSTAMP:
  2352. return i40e_ptp_set_ts_config(pf, ifr);
  2353. default:
  2354. return -EOPNOTSUPP;
  2355. }
  2356. }
  2357. /**
  2358. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2359. * @vsi: the vsi being adjusted
  2360. **/
  2361. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2362. {
  2363. struct i40e_vsi_context ctxt;
  2364. i40e_status ret;
  2365. if ((vsi->info.valid_sections &
  2366. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2367. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2368. return; /* already enabled */
  2369. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2370. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2371. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2372. ctxt.seid = vsi->seid;
  2373. ctxt.info = vsi->info;
  2374. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2375. if (ret) {
  2376. dev_info(&vsi->back->pdev->dev,
  2377. "update vlan stripping failed, err %s aq_err %s\n",
  2378. i40e_stat_str(&vsi->back->hw, ret),
  2379. i40e_aq_str(&vsi->back->hw,
  2380. vsi->back->hw.aq.asq_last_status));
  2381. }
  2382. }
  2383. /**
  2384. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2385. * @vsi: the vsi being adjusted
  2386. **/
  2387. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2388. {
  2389. struct i40e_vsi_context ctxt;
  2390. i40e_status ret;
  2391. if ((vsi->info.valid_sections &
  2392. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2393. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2394. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2395. return; /* already disabled */
  2396. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2397. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2398. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2399. ctxt.seid = vsi->seid;
  2400. ctxt.info = vsi->info;
  2401. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2402. if (ret) {
  2403. dev_info(&vsi->back->pdev->dev,
  2404. "update vlan stripping failed, err %s aq_err %s\n",
  2405. i40e_stat_str(&vsi->back->hw, ret),
  2406. i40e_aq_str(&vsi->back->hw,
  2407. vsi->back->hw.aq.asq_last_status));
  2408. }
  2409. }
  2410. /**
  2411. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2412. * @vsi: the vsi being configured
  2413. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2414. *
  2415. * This is a helper function for adding a new MAC/VLAN filter with the
  2416. * specified VLAN for each existing MAC address already in the hash table.
  2417. * This function does *not* perform any accounting to update filters based on
  2418. * VLAN mode.
  2419. *
  2420. * NOTE: this function expects to be called while under the
  2421. * mac_filter_hash_lock
  2422. **/
  2423. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2424. {
  2425. struct i40e_mac_filter *f, *add_f;
  2426. struct hlist_node *h;
  2427. int bkt;
  2428. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2429. if (f->state == I40E_FILTER_REMOVE)
  2430. continue;
  2431. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2432. if (!add_f) {
  2433. dev_info(&vsi->back->pdev->dev,
  2434. "Could not add vlan filter %d for %pM\n",
  2435. vid, f->macaddr);
  2436. return -ENOMEM;
  2437. }
  2438. }
  2439. return 0;
  2440. }
  2441. /**
  2442. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2443. * @vsi: the VSI being configured
  2444. * @vid: VLAN id to be added
  2445. **/
  2446. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2447. {
  2448. int err;
  2449. if (vsi->info.pvid)
  2450. return -EINVAL;
  2451. /* The network stack will attempt to add VID=0, with the intention to
  2452. * receive priority tagged packets with a VLAN of 0. Our HW receives
  2453. * these packets by default when configured to receive untagged
  2454. * packets, so we don't need to add a filter for this case.
  2455. * Additionally, HW interprets adding a VID=0 filter as meaning to
  2456. * receive *only* tagged traffic and stops receiving untagged traffic.
  2457. * Thus, we do not want to actually add a filter for VID=0
  2458. */
  2459. if (!vid)
  2460. return 0;
  2461. /* Locked once because all functions invoked below iterates list*/
  2462. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2463. err = i40e_add_vlan_all_mac(vsi, vid);
  2464. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2465. if (err)
  2466. return err;
  2467. /* schedule our worker thread which will take care of
  2468. * applying the new filter changes
  2469. */
  2470. i40e_service_event_schedule(vsi->back);
  2471. return 0;
  2472. }
  2473. /**
  2474. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2475. * @vsi: the vsi being configured
  2476. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2477. *
  2478. * This function should be used to remove all VLAN filters which match the
  2479. * given VID. It does not schedule the service event and does not take the
  2480. * mac_filter_hash_lock so it may be combined with other operations under
  2481. * a single invocation of the mac_filter_hash_lock.
  2482. *
  2483. * NOTE: this function expects to be called while under the
  2484. * mac_filter_hash_lock
  2485. */
  2486. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2487. {
  2488. struct i40e_mac_filter *f;
  2489. struct hlist_node *h;
  2490. int bkt;
  2491. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2492. if (f->vlan == vid)
  2493. __i40e_del_filter(vsi, f);
  2494. }
  2495. }
  2496. /**
  2497. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2498. * @vsi: the VSI being configured
  2499. * @vid: VLAN id to be removed
  2500. **/
  2501. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2502. {
  2503. if (!vid || vsi->info.pvid)
  2504. return;
  2505. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2506. i40e_rm_vlan_all_mac(vsi, vid);
  2507. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2508. /* schedule our worker thread which will take care of
  2509. * applying the new filter changes
  2510. */
  2511. i40e_service_event_schedule(vsi->back);
  2512. }
  2513. /**
  2514. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2515. * @netdev: network interface to be adjusted
  2516. * @proto: unused protocol value
  2517. * @vid: vlan id to be added
  2518. *
  2519. * net_device_ops implementation for adding vlan ids
  2520. **/
  2521. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2522. __always_unused __be16 proto, u16 vid)
  2523. {
  2524. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2525. struct i40e_vsi *vsi = np->vsi;
  2526. int ret = 0;
  2527. if (vid >= VLAN_N_VID)
  2528. return -EINVAL;
  2529. ret = i40e_vsi_add_vlan(vsi, vid);
  2530. if (!ret)
  2531. set_bit(vid, vsi->active_vlans);
  2532. return ret;
  2533. }
  2534. /**
  2535. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2536. * @netdev: network interface to be adjusted
  2537. * @proto: unused protocol value
  2538. * @vid: vlan id to be removed
  2539. *
  2540. * net_device_ops implementation for removing vlan ids
  2541. **/
  2542. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2543. __always_unused __be16 proto, u16 vid)
  2544. {
  2545. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2546. struct i40e_vsi *vsi = np->vsi;
  2547. /* return code is ignored as there is nothing a user
  2548. * can do about failure to remove and a log message was
  2549. * already printed from the other function
  2550. */
  2551. i40e_vsi_kill_vlan(vsi, vid);
  2552. clear_bit(vid, vsi->active_vlans);
  2553. return 0;
  2554. }
  2555. /**
  2556. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2557. * @vsi: the vsi being brought back up
  2558. **/
  2559. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2560. {
  2561. u16 vid;
  2562. if (!vsi->netdev)
  2563. return;
  2564. if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  2565. i40e_vlan_stripping_enable(vsi);
  2566. else
  2567. i40e_vlan_stripping_disable(vsi);
  2568. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2569. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2570. vid);
  2571. }
  2572. /**
  2573. * i40e_vsi_add_pvid - Add pvid for the VSI
  2574. * @vsi: the vsi being adjusted
  2575. * @vid: the vlan id to set as a PVID
  2576. **/
  2577. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2578. {
  2579. struct i40e_vsi_context ctxt;
  2580. i40e_status ret;
  2581. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2582. vsi->info.pvid = cpu_to_le16(vid);
  2583. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2584. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2585. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2586. ctxt.seid = vsi->seid;
  2587. ctxt.info = vsi->info;
  2588. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2589. if (ret) {
  2590. dev_info(&vsi->back->pdev->dev,
  2591. "add pvid failed, err %s aq_err %s\n",
  2592. i40e_stat_str(&vsi->back->hw, ret),
  2593. i40e_aq_str(&vsi->back->hw,
  2594. vsi->back->hw.aq.asq_last_status));
  2595. return -ENOENT;
  2596. }
  2597. return 0;
  2598. }
  2599. /**
  2600. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2601. * @vsi: the vsi being adjusted
  2602. *
  2603. * Just use the vlan_rx_register() service to put it back to normal
  2604. **/
  2605. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2606. {
  2607. i40e_vlan_stripping_disable(vsi);
  2608. vsi->info.pvid = 0;
  2609. }
  2610. /**
  2611. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2612. * @vsi: ptr to the VSI
  2613. *
  2614. * If this function returns with an error, then it's possible one or
  2615. * more of the rings is populated (while the rest are not). It is the
  2616. * callers duty to clean those orphaned rings.
  2617. *
  2618. * Return 0 on success, negative on failure
  2619. **/
  2620. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2621. {
  2622. int i, err = 0;
  2623. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2624. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2625. if (!i40e_enabled_xdp_vsi(vsi))
  2626. return err;
  2627. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2628. err = i40e_setup_tx_descriptors(vsi->xdp_rings[i]);
  2629. return err;
  2630. }
  2631. /**
  2632. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2633. * @vsi: ptr to the VSI
  2634. *
  2635. * Free VSI's transmit software resources
  2636. **/
  2637. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2638. {
  2639. int i;
  2640. if (vsi->tx_rings) {
  2641. for (i = 0; i < vsi->num_queue_pairs; i++)
  2642. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2643. i40e_free_tx_resources(vsi->tx_rings[i]);
  2644. }
  2645. if (vsi->xdp_rings) {
  2646. for (i = 0; i < vsi->num_queue_pairs; i++)
  2647. if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
  2648. i40e_free_tx_resources(vsi->xdp_rings[i]);
  2649. }
  2650. }
  2651. /**
  2652. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2653. * @vsi: ptr to the VSI
  2654. *
  2655. * If this function returns with an error, then it's possible one or
  2656. * more of the rings is populated (while the rest are not). It is the
  2657. * callers duty to clean those orphaned rings.
  2658. *
  2659. * Return 0 on success, negative on failure
  2660. **/
  2661. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2662. {
  2663. int i, err = 0;
  2664. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2665. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2666. return err;
  2667. }
  2668. /**
  2669. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2670. * @vsi: ptr to the VSI
  2671. *
  2672. * Free all receive software resources
  2673. **/
  2674. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2675. {
  2676. int i;
  2677. if (!vsi->rx_rings)
  2678. return;
  2679. for (i = 0; i < vsi->num_queue_pairs; i++)
  2680. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2681. i40e_free_rx_resources(vsi->rx_rings[i]);
  2682. }
  2683. /**
  2684. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2685. * @ring: The Tx ring to configure
  2686. *
  2687. * This enables/disables XPS for a given Tx descriptor ring
  2688. * based on the TCs enabled for the VSI that ring belongs to.
  2689. **/
  2690. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2691. {
  2692. int cpu;
  2693. if (!ring->q_vector || !ring->netdev || ring->ch)
  2694. return;
  2695. /* We only initialize XPS once, so as not to overwrite user settings */
  2696. if (test_and_set_bit(__I40E_TX_XPS_INIT_DONE, ring->state))
  2697. return;
  2698. cpu = cpumask_local_spread(ring->q_vector->v_idx, -1);
  2699. netif_set_xps_queue(ring->netdev, get_cpu_mask(cpu),
  2700. ring->queue_index);
  2701. }
  2702. /**
  2703. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2704. * @ring: The Tx ring to configure
  2705. *
  2706. * Configure the Tx descriptor ring in the HMC context.
  2707. **/
  2708. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2709. {
  2710. struct i40e_vsi *vsi = ring->vsi;
  2711. u16 pf_q = vsi->base_queue + ring->queue_index;
  2712. struct i40e_hw *hw = &vsi->back->hw;
  2713. struct i40e_hmc_obj_txq tx_ctx;
  2714. i40e_status err = 0;
  2715. u32 qtx_ctl = 0;
  2716. /* some ATR related tx ring init */
  2717. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2718. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2719. ring->atr_count = 0;
  2720. } else {
  2721. ring->atr_sample_rate = 0;
  2722. }
  2723. /* configure XPS */
  2724. i40e_config_xps_tx_ring(ring);
  2725. /* clear the context structure first */
  2726. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2727. tx_ctx.new_context = 1;
  2728. tx_ctx.base = (ring->dma / 128);
  2729. tx_ctx.qlen = ring->count;
  2730. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2731. I40E_FLAG_FD_ATR_ENABLED));
  2732. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2733. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2734. if (vsi->type != I40E_VSI_FDIR)
  2735. tx_ctx.head_wb_ena = 1;
  2736. tx_ctx.head_wb_addr = ring->dma +
  2737. (ring->count * sizeof(struct i40e_tx_desc));
  2738. /* As part of VSI creation/update, FW allocates certain
  2739. * Tx arbitration queue sets for each TC enabled for
  2740. * the VSI. The FW returns the handles to these queue
  2741. * sets as part of the response buffer to Add VSI,
  2742. * Update VSI, etc. AQ commands. It is expected that
  2743. * these queue set handles be associated with the Tx
  2744. * queues by the driver as part of the TX queue context
  2745. * initialization. This has to be done regardless of
  2746. * DCB as by default everything is mapped to TC0.
  2747. */
  2748. if (ring->ch)
  2749. tx_ctx.rdylist =
  2750. le16_to_cpu(ring->ch->info.qs_handle[ring->dcb_tc]);
  2751. else
  2752. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2753. tx_ctx.rdylist_act = 0;
  2754. /* clear the context in the HMC */
  2755. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2756. if (err) {
  2757. dev_info(&vsi->back->pdev->dev,
  2758. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2759. ring->queue_index, pf_q, err);
  2760. return -ENOMEM;
  2761. }
  2762. /* set the context in the HMC */
  2763. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2764. if (err) {
  2765. dev_info(&vsi->back->pdev->dev,
  2766. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2767. ring->queue_index, pf_q, err);
  2768. return -ENOMEM;
  2769. }
  2770. /* Now associate this queue with this PCI function */
  2771. if (ring->ch) {
  2772. if (ring->ch->type == I40E_VSI_VMDQ2)
  2773. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2774. else
  2775. return -EINVAL;
  2776. qtx_ctl |= (ring->ch->vsi_number <<
  2777. I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2778. I40E_QTX_CTL_VFVM_INDX_MASK;
  2779. } else {
  2780. if (vsi->type == I40E_VSI_VMDQ2) {
  2781. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2782. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2783. I40E_QTX_CTL_VFVM_INDX_MASK;
  2784. } else {
  2785. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2786. }
  2787. }
  2788. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2789. I40E_QTX_CTL_PF_INDX_MASK);
  2790. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2791. i40e_flush(hw);
  2792. /* cache tail off for easier writes later */
  2793. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2794. return 0;
  2795. }
  2796. /**
  2797. * i40e_configure_rx_ring - Configure a receive ring context
  2798. * @ring: The Rx ring to configure
  2799. *
  2800. * Configure the Rx descriptor ring in the HMC context.
  2801. **/
  2802. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2803. {
  2804. struct i40e_vsi *vsi = ring->vsi;
  2805. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2806. u16 pf_q = vsi->base_queue + ring->queue_index;
  2807. struct i40e_hw *hw = &vsi->back->hw;
  2808. struct i40e_hmc_obj_rxq rx_ctx;
  2809. i40e_status err = 0;
  2810. bitmap_zero(ring->state, __I40E_RING_STATE_NBITS);
  2811. /* clear the context structure first */
  2812. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2813. ring->rx_buf_len = vsi->rx_buf_len;
  2814. rx_ctx.dbuff = DIV_ROUND_UP(ring->rx_buf_len,
  2815. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2816. rx_ctx.base = (ring->dma / 128);
  2817. rx_ctx.qlen = ring->count;
  2818. /* use 32 byte descriptors */
  2819. rx_ctx.dsize = 1;
  2820. /* descriptor type is always zero
  2821. * rx_ctx.dtype = 0;
  2822. */
  2823. rx_ctx.hsplit_0 = 0;
  2824. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2825. if (hw->revision_id == 0)
  2826. rx_ctx.lrxqthresh = 0;
  2827. else
  2828. rx_ctx.lrxqthresh = 1;
  2829. rx_ctx.crcstrip = 1;
  2830. rx_ctx.l2tsel = 1;
  2831. /* this controls whether VLAN is stripped from inner headers */
  2832. rx_ctx.showiv = 0;
  2833. /* set the prefena field to 1 because the manual says to */
  2834. rx_ctx.prefena = 1;
  2835. /* clear the context in the HMC */
  2836. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2837. if (err) {
  2838. dev_info(&vsi->back->pdev->dev,
  2839. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2840. ring->queue_index, pf_q, err);
  2841. return -ENOMEM;
  2842. }
  2843. /* set the context in the HMC */
  2844. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2845. if (err) {
  2846. dev_info(&vsi->back->pdev->dev,
  2847. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2848. ring->queue_index, pf_q, err);
  2849. return -ENOMEM;
  2850. }
  2851. /* configure Rx buffer alignment */
  2852. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
  2853. clear_ring_build_skb_enabled(ring);
  2854. else
  2855. set_ring_build_skb_enabled(ring);
  2856. /* cache tail for quicker writes, and clear the reg before use */
  2857. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2858. writel(0, ring->tail);
  2859. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2860. return 0;
  2861. }
  2862. /**
  2863. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2864. * @vsi: VSI structure describing this set of rings and resources
  2865. *
  2866. * Configure the Tx VSI for operation.
  2867. **/
  2868. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2869. {
  2870. int err = 0;
  2871. u16 i;
  2872. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2873. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2874. if (!i40e_enabled_xdp_vsi(vsi))
  2875. return err;
  2876. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2877. err = i40e_configure_tx_ring(vsi->xdp_rings[i]);
  2878. return err;
  2879. }
  2880. /**
  2881. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2882. * @vsi: the VSI being configured
  2883. *
  2884. * Configure the Rx VSI for operation.
  2885. **/
  2886. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2887. {
  2888. int err = 0;
  2889. u16 i;
  2890. if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
  2891. vsi->max_frame = I40E_MAX_RXBUFFER;
  2892. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2893. #if (PAGE_SIZE < 8192)
  2894. } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
  2895. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  2896. vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2897. vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
  2898. #endif
  2899. } else {
  2900. vsi->max_frame = I40E_MAX_RXBUFFER;
  2901. vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
  2902. I40E_RXBUFFER_2048;
  2903. }
  2904. /* set up individual rings */
  2905. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2906. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2907. return err;
  2908. }
  2909. /**
  2910. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2911. * @vsi: ptr to the VSI
  2912. **/
  2913. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2914. {
  2915. struct i40e_ring *tx_ring, *rx_ring;
  2916. u16 qoffset, qcount;
  2917. int i, n;
  2918. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2919. /* Reset the TC information */
  2920. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2921. rx_ring = vsi->rx_rings[i];
  2922. tx_ring = vsi->tx_rings[i];
  2923. rx_ring->dcb_tc = 0;
  2924. tx_ring->dcb_tc = 0;
  2925. }
  2926. return;
  2927. }
  2928. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2929. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2930. continue;
  2931. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2932. qcount = vsi->tc_config.tc_info[n].qcount;
  2933. for (i = qoffset; i < (qoffset + qcount); i++) {
  2934. rx_ring = vsi->rx_rings[i];
  2935. tx_ring = vsi->tx_rings[i];
  2936. rx_ring->dcb_tc = n;
  2937. tx_ring->dcb_tc = n;
  2938. }
  2939. }
  2940. }
  2941. /**
  2942. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2943. * @vsi: ptr to the VSI
  2944. **/
  2945. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2946. {
  2947. if (vsi->netdev)
  2948. i40e_set_rx_mode(vsi->netdev);
  2949. }
  2950. /**
  2951. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2952. * @vsi: Pointer to the targeted VSI
  2953. *
  2954. * This function replays the hlist on the hw where all the SB Flow Director
  2955. * filters were saved.
  2956. **/
  2957. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2958. {
  2959. struct i40e_fdir_filter *filter;
  2960. struct i40e_pf *pf = vsi->back;
  2961. struct hlist_node *node;
  2962. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2963. return;
  2964. /* Reset FDir counters as we're replaying all existing filters */
  2965. pf->fd_tcp4_filter_cnt = 0;
  2966. pf->fd_udp4_filter_cnt = 0;
  2967. pf->fd_sctp4_filter_cnt = 0;
  2968. pf->fd_ip4_filter_cnt = 0;
  2969. hlist_for_each_entry_safe(filter, node,
  2970. &pf->fdir_filter_list, fdir_node) {
  2971. i40e_add_del_fdir(vsi, filter, true);
  2972. }
  2973. }
  2974. /**
  2975. * i40e_vsi_configure - Set up the VSI for action
  2976. * @vsi: the VSI being configured
  2977. **/
  2978. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2979. {
  2980. int err;
  2981. i40e_set_vsi_rx_mode(vsi);
  2982. i40e_restore_vlan(vsi);
  2983. i40e_vsi_config_dcb_rings(vsi);
  2984. err = i40e_vsi_configure_tx(vsi);
  2985. if (!err)
  2986. err = i40e_vsi_configure_rx(vsi);
  2987. return err;
  2988. }
  2989. /**
  2990. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2991. * @vsi: the VSI being configured
  2992. **/
  2993. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2994. {
  2995. bool has_xdp = i40e_enabled_xdp_vsi(vsi);
  2996. struct i40e_pf *pf = vsi->back;
  2997. struct i40e_hw *hw = &pf->hw;
  2998. u16 vector;
  2999. int i, q;
  3000. u32 qp;
  3001. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  3002. * and PFINT_LNKLSTn registers, e.g.:
  3003. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  3004. */
  3005. qp = vsi->base_queue;
  3006. vector = vsi->base_vector;
  3007. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  3008. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  3009. q_vector->rx.next_update = jiffies + 1;
  3010. q_vector->rx.target_itr =
  3011. ITR_TO_REG(vsi->rx_rings[i]->itr_setting);
  3012. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  3013. q_vector->rx.target_itr);
  3014. q_vector->rx.current_itr = q_vector->rx.target_itr;
  3015. q_vector->tx.next_update = jiffies + 1;
  3016. q_vector->tx.target_itr =
  3017. ITR_TO_REG(vsi->tx_rings[i]->itr_setting);
  3018. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  3019. q_vector->tx.target_itr);
  3020. q_vector->tx.current_itr = q_vector->tx.target_itr;
  3021. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  3022. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  3023. /* Linked list for the queuepairs assigned to this vector */
  3024. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  3025. for (q = 0; q < q_vector->num_ringpairs; q++) {
  3026. u32 nextqp = has_xdp ? qp + vsi->alloc_queue_pairs : qp;
  3027. u32 val;
  3028. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3029. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3030. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  3031. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  3032. (I40E_QUEUE_TYPE_TX <<
  3033. I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  3034. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3035. if (has_xdp) {
  3036. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3037. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3038. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3039. (qp << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3040. (I40E_QUEUE_TYPE_TX <<
  3041. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3042. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3043. }
  3044. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3045. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3046. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  3047. ((qp + 1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT) |
  3048. (I40E_QUEUE_TYPE_RX <<
  3049. I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3050. /* Terminate the linked list */
  3051. if (q == (q_vector->num_ringpairs - 1))
  3052. val |= (I40E_QUEUE_END_OF_LIST <<
  3053. I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3054. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3055. qp++;
  3056. }
  3057. }
  3058. i40e_flush(hw);
  3059. }
  3060. /**
  3061. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3062. * @pf: pointer to private device data structure
  3063. **/
  3064. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3065. {
  3066. struct i40e_hw *hw = &pf->hw;
  3067. u32 val;
  3068. /* clear things first */
  3069. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3070. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3071. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3072. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3073. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3074. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3075. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3076. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3077. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3078. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3079. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3080. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3081. if (pf->flags & I40E_FLAG_PTP)
  3082. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3083. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3084. /* SW_ITR_IDX = 0, but don't change INTENA */
  3085. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3086. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3087. /* OTHER_ITR_IDX = 0 */
  3088. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3089. }
  3090. /**
  3091. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3092. * @vsi: the VSI being configured
  3093. **/
  3094. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3095. {
  3096. u32 nextqp = i40e_enabled_xdp_vsi(vsi) ? vsi->alloc_queue_pairs : 0;
  3097. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3098. struct i40e_pf *pf = vsi->back;
  3099. struct i40e_hw *hw = &pf->hw;
  3100. u32 val;
  3101. /* set the ITR configuration */
  3102. q_vector->rx.next_update = jiffies + 1;
  3103. q_vector->rx.target_itr = ITR_TO_REG(vsi->rx_rings[0]->itr_setting);
  3104. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.target_itr);
  3105. q_vector->rx.current_itr = q_vector->rx.target_itr;
  3106. q_vector->tx.next_update = jiffies + 1;
  3107. q_vector->tx.target_itr = ITR_TO_REG(vsi->tx_rings[0]->itr_setting);
  3108. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.target_itr);
  3109. q_vector->tx.current_itr = q_vector->tx.target_itr;
  3110. i40e_enable_misc_int_causes(pf);
  3111. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3112. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3113. /* Associate the queue pair to the vector and enable the queue int */
  3114. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3115. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3116. (nextqp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  3117. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3118. wr32(hw, I40E_QINT_RQCTL(0), val);
  3119. if (i40e_enabled_xdp_vsi(vsi)) {
  3120. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3121. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)|
  3122. (I40E_QUEUE_TYPE_TX
  3123. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3124. wr32(hw, I40E_QINT_TQCTL(nextqp), val);
  3125. }
  3126. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3127. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3128. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3129. wr32(hw, I40E_QINT_TQCTL(0), val);
  3130. i40e_flush(hw);
  3131. }
  3132. /**
  3133. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3134. * @pf: board private structure
  3135. **/
  3136. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3137. {
  3138. struct i40e_hw *hw = &pf->hw;
  3139. wr32(hw, I40E_PFINT_DYN_CTL0,
  3140. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3141. i40e_flush(hw);
  3142. }
  3143. /**
  3144. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3145. * @pf: board private structure
  3146. **/
  3147. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  3148. {
  3149. struct i40e_hw *hw = &pf->hw;
  3150. u32 val;
  3151. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3152. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  3153. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3154. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3155. i40e_flush(hw);
  3156. }
  3157. /**
  3158. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3159. * @irq: interrupt number
  3160. * @data: pointer to a q_vector
  3161. **/
  3162. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3163. {
  3164. struct i40e_q_vector *q_vector = data;
  3165. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3166. return IRQ_HANDLED;
  3167. napi_schedule_irqoff(&q_vector->napi);
  3168. return IRQ_HANDLED;
  3169. }
  3170. /**
  3171. * i40e_irq_affinity_notify - Callback for affinity changes
  3172. * @notify: context as to what irq was changed
  3173. * @mask: the new affinity mask
  3174. *
  3175. * This is a callback function used by the irq_set_affinity_notifier function
  3176. * so that we may register to receive changes to the irq affinity masks.
  3177. **/
  3178. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3179. const cpumask_t *mask)
  3180. {
  3181. struct i40e_q_vector *q_vector =
  3182. container_of(notify, struct i40e_q_vector, affinity_notify);
  3183. cpumask_copy(&q_vector->affinity_mask, mask);
  3184. }
  3185. /**
  3186. * i40e_irq_affinity_release - Callback for affinity notifier release
  3187. * @ref: internal core kernel usage
  3188. *
  3189. * This is a callback function used by the irq_set_affinity_notifier function
  3190. * to inform the current notification subscriber that they will no longer
  3191. * receive notifications.
  3192. **/
  3193. static void i40e_irq_affinity_release(struct kref *ref) {}
  3194. /**
  3195. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3196. * @vsi: the VSI being configured
  3197. * @basename: name for the vector
  3198. *
  3199. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3200. **/
  3201. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3202. {
  3203. int q_vectors = vsi->num_q_vectors;
  3204. struct i40e_pf *pf = vsi->back;
  3205. int base = vsi->base_vector;
  3206. int rx_int_idx = 0;
  3207. int tx_int_idx = 0;
  3208. int vector, err;
  3209. int irq_num;
  3210. int cpu;
  3211. for (vector = 0; vector < q_vectors; vector++) {
  3212. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3213. irq_num = pf->msix_entries[base + vector].vector;
  3214. if (q_vector->tx.ring && q_vector->rx.ring) {
  3215. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3216. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3217. tx_int_idx++;
  3218. } else if (q_vector->rx.ring) {
  3219. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3220. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3221. } else if (q_vector->tx.ring) {
  3222. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3223. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3224. } else {
  3225. /* skip this unused q_vector */
  3226. continue;
  3227. }
  3228. err = request_irq(irq_num,
  3229. vsi->irq_handler,
  3230. 0,
  3231. q_vector->name,
  3232. q_vector);
  3233. if (err) {
  3234. dev_info(&pf->pdev->dev,
  3235. "MSIX request_irq failed, error: %d\n", err);
  3236. goto free_queue_irqs;
  3237. }
  3238. /* register for affinity change notifications */
  3239. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3240. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3241. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3242. /* Spread affinity hints out across online CPUs.
  3243. *
  3244. * get_cpu_mask returns a static constant mask with
  3245. * a permanent lifetime so it's ok to pass to
  3246. * irq_set_affinity_hint without making a copy.
  3247. */
  3248. cpu = cpumask_local_spread(q_vector->v_idx, -1);
  3249. irq_set_affinity_hint(irq_num, get_cpu_mask(cpu));
  3250. }
  3251. vsi->irqs_ready = true;
  3252. return 0;
  3253. free_queue_irqs:
  3254. while (vector) {
  3255. vector--;
  3256. irq_num = pf->msix_entries[base + vector].vector;
  3257. irq_set_affinity_notifier(irq_num, NULL);
  3258. irq_set_affinity_hint(irq_num, NULL);
  3259. free_irq(irq_num, &vsi->q_vectors[vector]);
  3260. }
  3261. return err;
  3262. }
  3263. /**
  3264. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3265. * @vsi: the VSI being un-configured
  3266. **/
  3267. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3268. {
  3269. struct i40e_pf *pf = vsi->back;
  3270. struct i40e_hw *hw = &pf->hw;
  3271. int base = vsi->base_vector;
  3272. int i;
  3273. /* disable interrupt causation from each queue */
  3274. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3275. u32 val;
  3276. val = rd32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
  3277. val &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  3278. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
  3279. val = rd32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx));
  3280. val &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  3281. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), val);
  3282. if (!i40e_enabled_xdp_vsi(vsi))
  3283. continue;
  3284. wr32(hw, I40E_QINT_TQCTL(vsi->xdp_rings[i]->reg_idx), 0);
  3285. }
  3286. /* disable each interrupt */
  3287. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3288. for (i = vsi->base_vector;
  3289. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3290. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3291. i40e_flush(hw);
  3292. for (i = 0; i < vsi->num_q_vectors; i++)
  3293. synchronize_irq(pf->msix_entries[i + base].vector);
  3294. } else {
  3295. /* Legacy and MSI mode - this stops all interrupt handling */
  3296. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3297. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3298. i40e_flush(hw);
  3299. synchronize_irq(pf->pdev->irq);
  3300. }
  3301. }
  3302. /**
  3303. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3304. * @vsi: the VSI being configured
  3305. **/
  3306. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3307. {
  3308. struct i40e_pf *pf = vsi->back;
  3309. int i;
  3310. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3311. for (i = 0; i < vsi->num_q_vectors; i++)
  3312. i40e_irq_dynamic_enable(vsi, i);
  3313. } else {
  3314. i40e_irq_dynamic_enable_icr0(pf);
  3315. }
  3316. i40e_flush(&pf->hw);
  3317. return 0;
  3318. }
  3319. /**
  3320. * i40e_free_misc_vector - Free the vector that handles non-queue events
  3321. * @pf: board private structure
  3322. **/
  3323. static void i40e_free_misc_vector(struct i40e_pf *pf)
  3324. {
  3325. /* Disable ICR 0 */
  3326. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3327. i40e_flush(&pf->hw);
  3328. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3329. synchronize_irq(pf->msix_entries[0].vector);
  3330. free_irq(pf->msix_entries[0].vector, pf);
  3331. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  3332. }
  3333. }
  3334. /**
  3335. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3336. * @irq: interrupt number
  3337. * @data: pointer to a q_vector
  3338. *
  3339. * This is the handler used for all MSI/Legacy interrupts, and deals
  3340. * with both queue and non-queue interrupts. This is also used in
  3341. * MSIX mode to handle the non-queue interrupts.
  3342. **/
  3343. static irqreturn_t i40e_intr(int irq, void *data)
  3344. {
  3345. struct i40e_pf *pf = (struct i40e_pf *)data;
  3346. struct i40e_hw *hw = &pf->hw;
  3347. irqreturn_t ret = IRQ_NONE;
  3348. u32 icr0, icr0_remaining;
  3349. u32 val, ena_mask;
  3350. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3351. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3352. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3353. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3354. goto enable_intr;
  3355. /* if interrupt but no bits showing, must be SWINT */
  3356. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3357. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3358. pf->sw_int_count++;
  3359. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3360. (icr0 & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3361. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3362. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3363. set_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  3364. }
  3365. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3366. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3367. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3368. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3369. /* We do not have a way to disarm Queue causes while leaving
  3370. * interrupt enabled for all other causes, ideally
  3371. * interrupt should be disabled while we are in NAPI but
  3372. * this is not a performance path and napi_schedule()
  3373. * can deal with rescheduling.
  3374. */
  3375. if (!test_bit(__I40E_DOWN, pf->state))
  3376. napi_schedule_irqoff(&q_vector->napi);
  3377. }
  3378. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3379. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3380. set_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  3381. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3382. }
  3383. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3384. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3385. set_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  3386. }
  3387. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3388. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3389. set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3390. }
  3391. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3392. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  3393. set_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  3394. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3395. val = rd32(hw, I40E_GLGEN_RSTAT);
  3396. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3397. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3398. if (val == I40E_RESET_CORER) {
  3399. pf->corer_count++;
  3400. } else if (val == I40E_RESET_GLOBR) {
  3401. pf->globr_count++;
  3402. } else if (val == I40E_RESET_EMPR) {
  3403. pf->empr_count++;
  3404. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state);
  3405. }
  3406. }
  3407. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3408. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3409. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3410. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3411. rd32(hw, I40E_PFHMC_ERRORINFO),
  3412. rd32(hw, I40E_PFHMC_ERRORDATA));
  3413. }
  3414. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3415. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3416. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3417. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3418. i40e_ptp_tx_hwtstamp(pf);
  3419. }
  3420. }
  3421. /* If a critical error is pending we have no choice but to reset the
  3422. * device.
  3423. * Report and mask out any remaining unexpected interrupts.
  3424. */
  3425. icr0_remaining = icr0 & ena_mask;
  3426. if (icr0_remaining) {
  3427. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3428. icr0_remaining);
  3429. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3430. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3431. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3432. dev_info(&pf->pdev->dev, "device will be reset\n");
  3433. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  3434. i40e_service_event_schedule(pf);
  3435. }
  3436. ena_mask &= ~icr0_remaining;
  3437. }
  3438. ret = IRQ_HANDLED;
  3439. enable_intr:
  3440. /* re-enable interrupt causes */
  3441. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3442. if (!test_bit(__I40E_DOWN, pf->state)) {
  3443. i40e_service_event_schedule(pf);
  3444. i40e_irq_dynamic_enable_icr0(pf);
  3445. }
  3446. return ret;
  3447. }
  3448. /**
  3449. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3450. * @tx_ring: tx ring to clean
  3451. * @budget: how many cleans we're allowed
  3452. *
  3453. * Returns true if there's any budget left (e.g. the clean is finished)
  3454. **/
  3455. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3456. {
  3457. struct i40e_vsi *vsi = tx_ring->vsi;
  3458. u16 i = tx_ring->next_to_clean;
  3459. struct i40e_tx_buffer *tx_buf;
  3460. struct i40e_tx_desc *tx_desc;
  3461. tx_buf = &tx_ring->tx_bi[i];
  3462. tx_desc = I40E_TX_DESC(tx_ring, i);
  3463. i -= tx_ring->count;
  3464. do {
  3465. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3466. /* if next_to_watch is not set then there is no work pending */
  3467. if (!eop_desc)
  3468. break;
  3469. /* prevent any other reads prior to eop_desc */
  3470. smp_rmb();
  3471. /* if the descriptor isn't done, no work yet to do */
  3472. if (!(eop_desc->cmd_type_offset_bsz &
  3473. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3474. break;
  3475. /* clear next_to_watch to prevent false hangs */
  3476. tx_buf->next_to_watch = NULL;
  3477. tx_desc->buffer_addr = 0;
  3478. tx_desc->cmd_type_offset_bsz = 0;
  3479. /* move past filter desc */
  3480. tx_buf++;
  3481. tx_desc++;
  3482. i++;
  3483. if (unlikely(!i)) {
  3484. i -= tx_ring->count;
  3485. tx_buf = tx_ring->tx_bi;
  3486. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3487. }
  3488. /* unmap skb header data */
  3489. dma_unmap_single(tx_ring->dev,
  3490. dma_unmap_addr(tx_buf, dma),
  3491. dma_unmap_len(tx_buf, len),
  3492. DMA_TO_DEVICE);
  3493. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3494. kfree(tx_buf->raw_buf);
  3495. tx_buf->raw_buf = NULL;
  3496. tx_buf->tx_flags = 0;
  3497. tx_buf->next_to_watch = NULL;
  3498. dma_unmap_len_set(tx_buf, len, 0);
  3499. tx_desc->buffer_addr = 0;
  3500. tx_desc->cmd_type_offset_bsz = 0;
  3501. /* move us past the eop_desc for start of next FD desc */
  3502. tx_buf++;
  3503. tx_desc++;
  3504. i++;
  3505. if (unlikely(!i)) {
  3506. i -= tx_ring->count;
  3507. tx_buf = tx_ring->tx_bi;
  3508. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3509. }
  3510. /* update budget accounting */
  3511. budget--;
  3512. } while (likely(budget));
  3513. i += tx_ring->count;
  3514. tx_ring->next_to_clean = i;
  3515. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3516. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3517. return budget > 0;
  3518. }
  3519. /**
  3520. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3521. * @irq: interrupt number
  3522. * @data: pointer to a q_vector
  3523. **/
  3524. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3525. {
  3526. struct i40e_q_vector *q_vector = data;
  3527. struct i40e_vsi *vsi;
  3528. if (!q_vector->tx.ring)
  3529. return IRQ_HANDLED;
  3530. vsi = q_vector->tx.ring->vsi;
  3531. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3532. return IRQ_HANDLED;
  3533. }
  3534. /**
  3535. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3536. * @vsi: the VSI being configured
  3537. * @v_idx: vector index
  3538. * @qp_idx: queue pair index
  3539. **/
  3540. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3541. {
  3542. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3543. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3544. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3545. tx_ring->q_vector = q_vector;
  3546. tx_ring->next = q_vector->tx.ring;
  3547. q_vector->tx.ring = tx_ring;
  3548. q_vector->tx.count++;
  3549. /* Place XDP Tx ring in the same q_vector ring list as regular Tx */
  3550. if (i40e_enabled_xdp_vsi(vsi)) {
  3551. struct i40e_ring *xdp_ring = vsi->xdp_rings[qp_idx];
  3552. xdp_ring->q_vector = q_vector;
  3553. xdp_ring->next = q_vector->tx.ring;
  3554. q_vector->tx.ring = xdp_ring;
  3555. q_vector->tx.count++;
  3556. }
  3557. rx_ring->q_vector = q_vector;
  3558. rx_ring->next = q_vector->rx.ring;
  3559. q_vector->rx.ring = rx_ring;
  3560. q_vector->rx.count++;
  3561. }
  3562. /**
  3563. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3564. * @vsi: the VSI being configured
  3565. *
  3566. * This function maps descriptor rings to the queue-specific vectors
  3567. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3568. * one vector per queue pair, but on a constrained vector budget, we
  3569. * group the queue pairs as "efficiently" as possible.
  3570. **/
  3571. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3572. {
  3573. int qp_remaining = vsi->num_queue_pairs;
  3574. int q_vectors = vsi->num_q_vectors;
  3575. int num_ringpairs;
  3576. int v_start = 0;
  3577. int qp_idx = 0;
  3578. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3579. * group them so there are multiple queues per vector.
  3580. * It is also important to go through all the vectors available to be
  3581. * sure that if we don't use all the vectors, that the remaining vectors
  3582. * are cleared. This is especially important when decreasing the
  3583. * number of queues in use.
  3584. */
  3585. for (; v_start < q_vectors; v_start++) {
  3586. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3587. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3588. q_vector->num_ringpairs = num_ringpairs;
  3589. q_vector->reg_idx = q_vector->v_idx + vsi->base_vector - 1;
  3590. q_vector->rx.count = 0;
  3591. q_vector->tx.count = 0;
  3592. q_vector->rx.ring = NULL;
  3593. q_vector->tx.ring = NULL;
  3594. while (num_ringpairs--) {
  3595. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3596. qp_idx++;
  3597. qp_remaining--;
  3598. }
  3599. }
  3600. }
  3601. /**
  3602. * i40e_vsi_request_irq - Request IRQ from the OS
  3603. * @vsi: the VSI being configured
  3604. * @basename: name for the vector
  3605. **/
  3606. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3607. {
  3608. struct i40e_pf *pf = vsi->back;
  3609. int err;
  3610. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3611. err = i40e_vsi_request_irq_msix(vsi, basename);
  3612. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3613. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3614. pf->int_name, pf);
  3615. else
  3616. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3617. pf->int_name, pf);
  3618. if (err)
  3619. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3620. return err;
  3621. }
  3622. #ifdef CONFIG_NET_POLL_CONTROLLER
  3623. /**
  3624. * i40e_netpoll - A Polling 'interrupt' handler
  3625. * @netdev: network interface device structure
  3626. *
  3627. * This is used by netconsole to send skbs without having to re-enable
  3628. * interrupts. It's not called while the normal interrupt routine is executing.
  3629. **/
  3630. static void i40e_netpoll(struct net_device *netdev)
  3631. {
  3632. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3633. struct i40e_vsi *vsi = np->vsi;
  3634. struct i40e_pf *pf = vsi->back;
  3635. int i;
  3636. /* if interface is down do nothing */
  3637. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  3638. return;
  3639. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3640. for (i = 0; i < vsi->num_q_vectors; i++)
  3641. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3642. } else {
  3643. i40e_intr(pf->pdev->irq, netdev);
  3644. }
  3645. }
  3646. #endif
  3647. #define I40E_QTX_ENA_WAIT_COUNT 50
  3648. /**
  3649. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3650. * @pf: the PF being configured
  3651. * @pf_q: the PF queue
  3652. * @enable: enable or disable state of the queue
  3653. *
  3654. * This routine will wait for the given Tx queue of the PF to reach the
  3655. * enabled or disabled state.
  3656. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3657. * multiple retries; else will return 0 in case of success.
  3658. **/
  3659. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3660. {
  3661. int i;
  3662. u32 tx_reg;
  3663. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3664. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3665. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3666. break;
  3667. usleep_range(10, 20);
  3668. }
  3669. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3670. return -ETIMEDOUT;
  3671. return 0;
  3672. }
  3673. /**
  3674. * i40e_control_tx_q - Start or stop a particular Tx queue
  3675. * @pf: the PF structure
  3676. * @pf_q: the PF queue to configure
  3677. * @enable: start or stop the queue
  3678. *
  3679. * This function enables or disables a single queue. Note that any delay
  3680. * required after the operation is expected to be handled by the caller of
  3681. * this function.
  3682. **/
  3683. static void i40e_control_tx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3684. {
  3685. struct i40e_hw *hw = &pf->hw;
  3686. u32 tx_reg;
  3687. int i;
  3688. /* warn the TX unit of coming changes */
  3689. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3690. if (!enable)
  3691. usleep_range(10, 20);
  3692. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3693. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3694. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3695. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3696. break;
  3697. usleep_range(1000, 2000);
  3698. }
  3699. /* Skip if the queue is already in the requested state */
  3700. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3701. return;
  3702. /* turn on/off the queue */
  3703. if (enable) {
  3704. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3705. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3706. } else {
  3707. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3708. }
  3709. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3710. }
  3711. /**
  3712. * i40e_control_wait_tx_q - Start/stop Tx queue and wait for completion
  3713. * @seid: VSI SEID
  3714. * @pf: the PF structure
  3715. * @pf_q: the PF queue to configure
  3716. * @is_xdp: true if the queue is used for XDP
  3717. * @enable: start or stop the queue
  3718. **/
  3719. static int i40e_control_wait_tx_q(int seid, struct i40e_pf *pf, int pf_q,
  3720. bool is_xdp, bool enable)
  3721. {
  3722. int ret;
  3723. i40e_control_tx_q(pf, pf_q, enable);
  3724. /* wait for the change to finish */
  3725. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3726. if (ret) {
  3727. dev_info(&pf->pdev->dev,
  3728. "VSI seid %d %sTx ring %d %sable timeout\n",
  3729. seid, (is_xdp ? "XDP " : ""), pf_q,
  3730. (enable ? "en" : "dis"));
  3731. }
  3732. return ret;
  3733. }
  3734. /**
  3735. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3736. * @vsi: the VSI being configured
  3737. * @enable: start or stop the rings
  3738. **/
  3739. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3740. {
  3741. struct i40e_pf *pf = vsi->back;
  3742. int i, pf_q, ret = 0;
  3743. pf_q = vsi->base_queue;
  3744. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3745. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3746. pf_q,
  3747. false /*is xdp*/, enable);
  3748. if (ret)
  3749. break;
  3750. if (!i40e_enabled_xdp_vsi(vsi))
  3751. continue;
  3752. ret = i40e_control_wait_tx_q(vsi->seid, pf,
  3753. pf_q + vsi->alloc_queue_pairs,
  3754. true /*is xdp*/, enable);
  3755. if (ret)
  3756. break;
  3757. }
  3758. return ret;
  3759. }
  3760. /**
  3761. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3762. * @pf: the PF being configured
  3763. * @pf_q: the PF queue
  3764. * @enable: enable or disable state of the queue
  3765. *
  3766. * This routine will wait for the given Rx queue of the PF to reach the
  3767. * enabled or disabled state.
  3768. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3769. * multiple retries; else will return 0 in case of success.
  3770. **/
  3771. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3772. {
  3773. int i;
  3774. u32 rx_reg;
  3775. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3776. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3777. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3778. break;
  3779. usleep_range(10, 20);
  3780. }
  3781. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3782. return -ETIMEDOUT;
  3783. return 0;
  3784. }
  3785. /**
  3786. * i40e_control_rx_q - Start or stop a particular Rx queue
  3787. * @pf: the PF structure
  3788. * @pf_q: the PF queue to configure
  3789. * @enable: start or stop the queue
  3790. *
  3791. * This function enables or disables a single queue. Note that any delay
  3792. * required after the operation is expected to be handled by the caller of
  3793. * this function.
  3794. **/
  3795. static void i40e_control_rx_q(struct i40e_pf *pf, int pf_q, bool enable)
  3796. {
  3797. struct i40e_hw *hw = &pf->hw;
  3798. u32 rx_reg;
  3799. int i;
  3800. for (i = 0; i < I40E_QTX_ENA_WAIT_COUNT; i++) {
  3801. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3802. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3803. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3804. break;
  3805. usleep_range(1000, 2000);
  3806. }
  3807. /* Skip if the queue is already in the requested state */
  3808. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3809. return;
  3810. /* turn on/off the queue */
  3811. if (enable)
  3812. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3813. else
  3814. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3815. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3816. }
  3817. /**
  3818. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3819. * @vsi: the VSI being configured
  3820. * @enable: start or stop the rings
  3821. **/
  3822. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3823. {
  3824. struct i40e_pf *pf = vsi->back;
  3825. int i, pf_q, ret = 0;
  3826. pf_q = vsi->base_queue;
  3827. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3828. i40e_control_rx_q(pf, pf_q, enable);
  3829. /* wait for the change to finish */
  3830. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3831. if (ret) {
  3832. dev_info(&pf->pdev->dev,
  3833. "VSI seid %d Rx ring %d %sable timeout\n",
  3834. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3835. break;
  3836. }
  3837. }
  3838. /* Due to HW errata, on Rx disable only, the register can indicate done
  3839. * before it really is. Needs 50ms to be sure
  3840. */
  3841. if (!enable)
  3842. mdelay(50);
  3843. return ret;
  3844. }
  3845. /**
  3846. * i40e_vsi_start_rings - Start a VSI's rings
  3847. * @vsi: the VSI being configured
  3848. **/
  3849. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3850. {
  3851. int ret = 0;
  3852. /* do rx first for enable and last for disable */
  3853. ret = i40e_vsi_control_rx(vsi, true);
  3854. if (ret)
  3855. return ret;
  3856. ret = i40e_vsi_control_tx(vsi, true);
  3857. return ret;
  3858. }
  3859. /**
  3860. * i40e_vsi_stop_rings - Stop a VSI's rings
  3861. * @vsi: the VSI being configured
  3862. **/
  3863. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3864. {
  3865. /* When port TX is suspended, don't wait */
  3866. if (test_bit(__I40E_PORT_SUSPENDED, vsi->back->state))
  3867. return i40e_vsi_stop_rings_no_wait(vsi);
  3868. /* do rx first for enable and last for disable
  3869. * Ignore return value, we need to shutdown whatever we can
  3870. */
  3871. i40e_vsi_control_tx(vsi, false);
  3872. i40e_vsi_control_rx(vsi, false);
  3873. }
  3874. /**
  3875. * i40e_vsi_stop_rings_no_wait - Stop a VSI's rings and do not delay
  3876. * @vsi: the VSI being shutdown
  3877. *
  3878. * This function stops all the rings for a VSI but does not delay to verify
  3879. * that rings have been disabled. It is expected that the caller is shutting
  3880. * down multiple VSIs at once and will delay together for all the VSIs after
  3881. * initiating the shutdown. This is particularly useful for shutting down lots
  3882. * of VFs together. Otherwise, a large delay can be incurred while configuring
  3883. * each VSI in serial.
  3884. **/
  3885. void i40e_vsi_stop_rings_no_wait(struct i40e_vsi *vsi)
  3886. {
  3887. struct i40e_pf *pf = vsi->back;
  3888. int i, pf_q;
  3889. pf_q = vsi->base_queue;
  3890. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3891. i40e_control_tx_q(pf, pf_q, false);
  3892. i40e_control_rx_q(pf, pf_q, false);
  3893. }
  3894. }
  3895. /**
  3896. * i40e_vsi_free_irq - Free the irq association with the OS
  3897. * @vsi: the VSI being configured
  3898. **/
  3899. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3900. {
  3901. struct i40e_pf *pf = vsi->back;
  3902. struct i40e_hw *hw = &pf->hw;
  3903. int base = vsi->base_vector;
  3904. u32 val, qp;
  3905. int i;
  3906. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3907. if (!vsi->q_vectors)
  3908. return;
  3909. if (!vsi->irqs_ready)
  3910. return;
  3911. vsi->irqs_ready = false;
  3912. for (i = 0; i < vsi->num_q_vectors; i++) {
  3913. int irq_num;
  3914. u16 vector;
  3915. vector = i + base;
  3916. irq_num = pf->msix_entries[vector].vector;
  3917. /* free only the irqs that were actually requested */
  3918. if (!vsi->q_vectors[i] ||
  3919. !vsi->q_vectors[i]->num_ringpairs)
  3920. continue;
  3921. /* clear the affinity notifier in the IRQ descriptor */
  3922. irq_set_affinity_notifier(irq_num, NULL);
  3923. /* remove our suggested affinity mask for this IRQ */
  3924. irq_set_affinity_hint(irq_num, NULL);
  3925. synchronize_irq(irq_num);
  3926. free_irq(irq_num, vsi->q_vectors[i]);
  3927. /* Tear down the interrupt queue link list
  3928. *
  3929. * We know that they come in pairs and always
  3930. * the Rx first, then the Tx. To clear the
  3931. * link list, stick the EOL value into the
  3932. * next_q field of the registers.
  3933. */
  3934. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3935. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3936. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3937. val |= I40E_QUEUE_END_OF_LIST
  3938. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3939. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3940. while (qp != I40E_QUEUE_END_OF_LIST) {
  3941. u32 next;
  3942. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3943. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3944. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3945. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3946. I40E_QINT_RQCTL_INTEVENT_MASK);
  3947. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3948. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3949. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3950. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3951. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3952. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3953. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3954. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3955. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3956. I40E_QINT_TQCTL_INTEVENT_MASK);
  3957. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3958. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3959. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3960. qp = next;
  3961. }
  3962. }
  3963. } else {
  3964. free_irq(pf->pdev->irq, pf);
  3965. val = rd32(hw, I40E_PFINT_LNKLST0);
  3966. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3967. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3968. val |= I40E_QUEUE_END_OF_LIST
  3969. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3970. wr32(hw, I40E_PFINT_LNKLST0, val);
  3971. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3972. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3973. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3974. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3975. I40E_QINT_RQCTL_INTEVENT_MASK);
  3976. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3977. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3978. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3979. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3980. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3981. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3982. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3983. I40E_QINT_TQCTL_INTEVENT_MASK);
  3984. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3985. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3986. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3987. }
  3988. }
  3989. /**
  3990. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3991. * @vsi: the VSI being configured
  3992. * @v_idx: Index of vector to be freed
  3993. *
  3994. * This function frees the memory allocated to the q_vector. In addition if
  3995. * NAPI is enabled it will delete any references to the NAPI struct prior
  3996. * to freeing the q_vector.
  3997. **/
  3998. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3999. {
  4000. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  4001. struct i40e_ring *ring;
  4002. if (!q_vector)
  4003. return;
  4004. /* disassociate q_vector from rings */
  4005. i40e_for_each_ring(ring, q_vector->tx)
  4006. ring->q_vector = NULL;
  4007. i40e_for_each_ring(ring, q_vector->rx)
  4008. ring->q_vector = NULL;
  4009. /* only VSI w/ an associated netdev is set up w/ NAPI */
  4010. if (vsi->netdev)
  4011. netif_napi_del(&q_vector->napi);
  4012. vsi->q_vectors[v_idx] = NULL;
  4013. kfree_rcu(q_vector, rcu);
  4014. }
  4015. /**
  4016. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  4017. * @vsi: the VSI being un-configured
  4018. *
  4019. * This frees the memory allocated to the q_vectors and
  4020. * deletes references to the NAPI struct.
  4021. **/
  4022. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  4023. {
  4024. int v_idx;
  4025. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  4026. i40e_free_q_vector(vsi, v_idx);
  4027. }
  4028. /**
  4029. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  4030. * @pf: board private structure
  4031. **/
  4032. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  4033. {
  4034. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  4035. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  4036. pci_disable_msix(pf->pdev);
  4037. kfree(pf->msix_entries);
  4038. pf->msix_entries = NULL;
  4039. kfree(pf->irq_pile);
  4040. pf->irq_pile = NULL;
  4041. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  4042. pci_disable_msi(pf->pdev);
  4043. }
  4044. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  4045. }
  4046. /**
  4047. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4048. * @pf: board private structure
  4049. *
  4050. * We go through and clear interrupt specific resources and reset the structure
  4051. * to pre-load conditions
  4052. **/
  4053. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  4054. {
  4055. int i;
  4056. i40e_free_misc_vector(pf);
  4057. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  4058. I40E_IWARP_IRQ_PILE_ID);
  4059. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  4060. for (i = 0; i < pf->num_alloc_vsi; i++)
  4061. if (pf->vsi[i])
  4062. i40e_vsi_free_q_vectors(pf->vsi[i]);
  4063. i40e_reset_interrupt_capability(pf);
  4064. }
  4065. /**
  4066. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  4067. * @vsi: the VSI being configured
  4068. **/
  4069. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  4070. {
  4071. int q_idx;
  4072. if (!vsi->netdev)
  4073. return;
  4074. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4075. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4076. if (q_vector->rx.ring || q_vector->tx.ring)
  4077. napi_enable(&q_vector->napi);
  4078. }
  4079. }
  4080. /**
  4081. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  4082. * @vsi: the VSI being configured
  4083. **/
  4084. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  4085. {
  4086. int q_idx;
  4087. if (!vsi->netdev)
  4088. return;
  4089. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  4090. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  4091. if (q_vector->rx.ring || q_vector->tx.ring)
  4092. napi_disable(&q_vector->napi);
  4093. }
  4094. }
  4095. /**
  4096. * i40e_vsi_close - Shut down a VSI
  4097. * @vsi: the vsi to be quelled
  4098. **/
  4099. static void i40e_vsi_close(struct i40e_vsi *vsi)
  4100. {
  4101. struct i40e_pf *pf = vsi->back;
  4102. if (!test_and_set_bit(__I40E_VSI_DOWN, vsi->state))
  4103. i40e_down(vsi);
  4104. i40e_vsi_free_irq(vsi);
  4105. i40e_vsi_free_tx_resources(vsi);
  4106. i40e_vsi_free_rx_resources(vsi);
  4107. vsi->current_netdev_flags = 0;
  4108. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  4109. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  4110. set_bit(__I40E_CLIENT_RESET, pf->state);
  4111. }
  4112. /**
  4113. * i40e_quiesce_vsi - Pause a given VSI
  4114. * @vsi: the VSI being paused
  4115. **/
  4116. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  4117. {
  4118. if (test_bit(__I40E_VSI_DOWN, vsi->state))
  4119. return;
  4120. set_bit(__I40E_VSI_NEEDS_RESTART, vsi->state);
  4121. if (vsi->netdev && netif_running(vsi->netdev))
  4122. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  4123. else
  4124. i40e_vsi_close(vsi);
  4125. }
  4126. /**
  4127. * i40e_unquiesce_vsi - Resume a given VSI
  4128. * @vsi: the VSI being resumed
  4129. **/
  4130. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  4131. {
  4132. if (!test_and_clear_bit(__I40E_VSI_NEEDS_RESTART, vsi->state))
  4133. return;
  4134. if (vsi->netdev && netif_running(vsi->netdev))
  4135. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  4136. else
  4137. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  4138. }
  4139. /**
  4140. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  4141. * @pf: the PF
  4142. **/
  4143. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  4144. {
  4145. int v;
  4146. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4147. if (pf->vsi[v])
  4148. i40e_quiesce_vsi(pf->vsi[v]);
  4149. }
  4150. }
  4151. /**
  4152. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  4153. * @pf: the PF
  4154. **/
  4155. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  4156. {
  4157. int v;
  4158. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4159. if (pf->vsi[v])
  4160. i40e_unquiesce_vsi(pf->vsi[v]);
  4161. }
  4162. }
  4163. /**
  4164. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  4165. * @vsi: the VSI being configured
  4166. *
  4167. * Wait until all queues on a given VSI have been disabled.
  4168. **/
  4169. int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4170. {
  4171. struct i40e_pf *pf = vsi->back;
  4172. int i, pf_q, ret;
  4173. pf_q = vsi->base_queue;
  4174. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4175. /* Check and wait for the Tx queue */
  4176. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4177. if (ret) {
  4178. dev_info(&pf->pdev->dev,
  4179. "VSI seid %d Tx ring %d disable timeout\n",
  4180. vsi->seid, pf_q);
  4181. return ret;
  4182. }
  4183. if (!i40e_enabled_xdp_vsi(vsi))
  4184. goto wait_rx;
  4185. /* Check and wait for the XDP Tx queue */
  4186. ret = i40e_pf_txq_wait(pf, pf_q + vsi->alloc_queue_pairs,
  4187. false);
  4188. if (ret) {
  4189. dev_info(&pf->pdev->dev,
  4190. "VSI seid %d XDP Tx ring %d disable timeout\n",
  4191. vsi->seid, pf_q);
  4192. return ret;
  4193. }
  4194. wait_rx:
  4195. /* Check and wait for the Rx queue */
  4196. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4197. if (ret) {
  4198. dev_info(&pf->pdev->dev,
  4199. "VSI seid %d Rx ring %d disable timeout\n",
  4200. vsi->seid, pf_q);
  4201. return ret;
  4202. }
  4203. }
  4204. return 0;
  4205. }
  4206. #ifdef CONFIG_I40E_DCB
  4207. /**
  4208. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4209. * @pf: the PF
  4210. *
  4211. * This function waits for the queues to be in disabled state for all the
  4212. * VSIs that are managed by this PF.
  4213. **/
  4214. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4215. {
  4216. int v, ret = 0;
  4217. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4218. if (pf->vsi[v]) {
  4219. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4220. if (ret)
  4221. break;
  4222. }
  4223. }
  4224. return ret;
  4225. }
  4226. #endif
  4227. /**
  4228. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4229. * @pf: pointer to PF
  4230. *
  4231. * Get TC map for ISCSI PF type that will include iSCSI TC
  4232. * and LAN TC.
  4233. **/
  4234. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4235. {
  4236. struct i40e_dcb_app_priority_table app;
  4237. struct i40e_hw *hw = &pf->hw;
  4238. u8 enabled_tc = 1; /* TC0 is always enabled */
  4239. u8 tc, i;
  4240. /* Get the iSCSI APP TLV */
  4241. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4242. for (i = 0; i < dcbcfg->numapps; i++) {
  4243. app = dcbcfg->app[i];
  4244. if (app.selector == I40E_APP_SEL_TCPIP &&
  4245. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4246. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4247. enabled_tc |= BIT(tc);
  4248. break;
  4249. }
  4250. }
  4251. return enabled_tc;
  4252. }
  4253. /**
  4254. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4255. * @dcbcfg: the corresponding DCBx configuration structure
  4256. *
  4257. * Return the number of TCs from given DCBx configuration
  4258. **/
  4259. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4260. {
  4261. int i, tc_unused = 0;
  4262. u8 num_tc = 0;
  4263. u8 ret = 0;
  4264. /* Scan the ETS Config Priority Table to find
  4265. * traffic class enabled for a given priority
  4266. * and create a bitmask of enabled TCs
  4267. */
  4268. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4269. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4270. /* Now scan the bitmask to check for
  4271. * contiguous TCs starting with TC0
  4272. */
  4273. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4274. if (num_tc & BIT(i)) {
  4275. if (!tc_unused) {
  4276. ret++;
  4277. } else {
  4278. pr_err("Non-contiguous TC - Disabling DCB\n");
  4279. return 1;
  4280. }
  4281. } else {
  4282. tc_unused = 1;
  4283. }
  4284. }
  4285. /* There is always at least TC0 */
  4286. if (!ret)
  4287. ret = 1;
  4288. return ret;
  4289. }
  4290. /**
  4291. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4292. * @dcbcfg: the corresponding DCBx configuration structure
  4293. *
  4294. * Query the current DCB configuration and return the number of
  4295. * traffic classes enabled from the given DCBX config
  4296. **/
  4297. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4298. {
  4299. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4300. u8 enabled_tc = 1;
  4301. u8 i;
  4302. for (i = 0; i < num_tc; i++)
  4303. enabled_tc |= BIT(i);
  4304. return enabled_tc;
  4305. }
  4306. /**
  4307. * i40e_mqprio_get_enabled_tc - Get enabled traffic classes
  4308. * @pf: PF being queried
  4309. *
  4310. * Query the current MQPRIO configuration and return the number of
  4311. * traffic classes enabled.
  4312. **/
  4313. static u8 i40e_mqprio_get_enabled_tc(struct i40e_pf *pf)
  4314. {
  4315. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  4316. u8 num_tc = vsi->mqprio_qopt.qopt.num_tc;
  4317. u8 enabled_tc = 1, i;
  4318. for (i = 1; i < num_tc; i++)
  4319. enabled_tc |= BIT(i);
  4320. return enabled_tc;
  4321. }
  4322. /**
  4323. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4324. * @pf: PF being queried
  4325. *
  4326. * Return number of traffic classes enabled for the given PF
  4327. **/
  4328. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4329. {
  4330. struct i40e_hw *hw = &pf->hw;
  4331. u8 i, enabled_tc = 1;
  4332. u8 num_tc = 0;
  4333. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4334. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4335. return pf->vsi[pf->lan_vsi]->mqprio_qopt.qopt.num_tc;
  4336. /* If neither MQPRIO nor DCB is enabled, then always use single TC */
  4337. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4338. return 1;
  4339. /* SFP mode will be enabled for all TCs on port */
  4340. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4341. return i40e_dcb_get_num_tc(dcbcfg);
  4342. /* MFP mode return count of enabled TCs for this PF */
  4343. if (pf->hw.func_caps.iscsi)
  4344. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4345. else
  4346. return 1; /* Only TC0 */
  4347. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4348. if (enabled_tc & BIT(i))
  4349. num_tc++;
  4350. }
  4351. return num_tc;
  4352. }
  4353. /**
  4354. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4355. * @pf: PF being queried
  4356. *
  4357. * Return a bitmap for enabled traffic classes for this PF.
  4358. **/
  4359. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4360. {
  4361. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4362. return i40e_mqprio_get_enabled_tc(pf);
  4363. /* If neither MQPRIO nor DCB is enabled for this PF then just return
  4364. * default TC
  4365. */
  4366. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4367. return I40E_DEFAULT_TRAFFIC_CLASS;
  4368. /* SFP mode we want PF to be enabled for all TCs */
  4369. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4370. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4371. /* MFP enabled and iSCSI PF type */
  4372. if (pf->hw.func_caps.iscsi)
  4373. return i40e_get_iscsi_tc_map(pf);
  4374. else
  4375. return I40E_DEFAULT_TRAFFIC_CLASS;
  4376. }
  4377. /**
  4378. * i40e_vsi_get_bw_info - Query VSI BW Information
  4379. * @vsi: the VSI being queried
  4380. *
  4381. * Returns 0 on success, negative value on failure
  4382. **/
  4383. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4384. {
  4385. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4386. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4387. struct i40e_pf *pf = vsi->back;
  4388. struct i40e_hw *hw = &pf->hw;
  4389. i40e_status ret;
  4390. u32 tc_bw_max;
  4391. int i;
  4392. /* Get the VSI level BW configuration */
  4393. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4394. if (ret) {
  4395. dev_info(&pf->pdev->dev,
  4396. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4397. i40e_stat_str(&pf->hw, ret),
  4398. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4399. return -EINVAL;
  4400. }
  4401. /* Get the VSI level BW configuration per TC */
  4402. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4403. NULL);
  4404. if (ret) {
  4405. dev_info(&pf->pdev->dev,
  4406. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4407. i40e_stat_str(&pf->hw, ret),
  4408. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4409. return -EINVAL;
  4410. }
  4411. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4412. dev_info(&pf->pdev->dev,
  4413. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4414. bw_config.tc_valid_bits,
  4415. bw_ets_config.tc_valid_bits);
  4416. /* Still continuing */
  4417. }
  4418. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4419. vsi->bw_max_quanta = bw_config.max_bw;
  4420. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4421. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4422. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4423. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4424. vsi->bw_ets_limit_credits[i] =
  4425. le16_to_cpu(bw_ets_config.credits[i]);
  4426. /* 3 bits out of 4 for each TC */
  4427. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4428. }
  4429. return 0;
  4430. }
  4431. /**
  4432. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4433. * @vsi: the VSI being configured
  4434. * @enabled_tc: TC bitmap
  4435. * @bw_share: BW shared credits per TC
  4436. *
  4437. * Returns 0 on success, negative value on failure
  4438. **/
  4439. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4440. u8 *bw_share)
  4441. {
  4442. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4443. i40e_status ret;
  4444. int i;
  4445. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO)
  4446. return 0;
  4447. if (!vsi->mqprio_qopt.qopt.hw) {
  4448. ret = i40e_set_bw_limit(vsi, vsi->seid, 0);
  4449. if (ret)
  4450. dev_info(&vsi->back->pdev->dev,
  4451. "Failed to reset tx rate for vsi->seid %u\n",
  4452. vsi->seid);
  4453. return ret;
  4454. }
  4455. bw_data.tc_valid_bits = enabled_tc;
  4456. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4457. bw_data.tc_bw_credits[i] = bw_share[i];
  4458. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4459. NULL);
  4460. if (ret) {
  4461. dev_info(&vsi->back->pdev->dev,
  4462. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4463. vsi->back->hw.aq.asq_last_status);
  4464. return -EINVAL;
  4465. }
  4466. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4467. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4468. return 0;
  4469. }
  4470. /**
  4471. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4472. * @vsi: the VSI being configured
  4473. * @enabled_tc: TC map to be enabled
  4474. *
  4475. **/
  4476. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4477. {
  4478. struct net_device *netdev = vsi->netdev;
  4479. struct i40e_pf *pf = vsi->back;
  4480. struct i40e_hw *hw = &pf->hw;
  4481. u8 netdev_tc = 0;
  4482. int i;
  4483. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4484. if (!netdev)
  4485. return;
  4486. if (!enabled_tc) {
  4487. netdev_reset_tc(netdev);
  4488. return;
  4489. }
  4490. /* Set up actual enabled TCs on the VSI */
  4491. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4492. return;
  4493. /* set per TC queues for the VSI */
  4494. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4495. /* Only set TC queues for enabled tcs
  4496. *
  4497. * e.g. For a VSI that has TC0 and TC3 enabled the
  4498. * enabled_tc bitmap would be 0x00001001; the driver
  4499. * will set the numtc for netdev as 2 that will be
  4500. * referenced by the netdev layer as TC 0 and 1.
  4501. */
  4502. if (vsi->tc_config.enabled_tc & BIT(i))
  4503. netdev_set_tc_queue(netdev,
  4504. vsi->tc_config.tc_info[i].netdev_tc,
  4505. vsi->tc_config.tc_info[i].qcount,
  4506. vsi->tc_config.tc_info[i].qoffset);
  4507. }
  4508. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  4509. return;
  4510. /* Assign UP2TC map for the VSI */
  4511. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4512. /* Get the actual TC# for the UP */
  4513. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4514. /* Get the mapped netdev TC# for the UP */
  4515. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4516. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4517. }
  4518. }
  4519. /**
  4520. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4521. * @vsi: the VSI being configured
  4522. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4523. **/
  4524. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4525. struct i40e_vsi_context *ctxt)
  4526. {
  4527. /* copy just the sections touched not the entire info
  4528. * since not all sections are valid as returned by
  4529. * update vsi params
  4530. */
  4531. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4532. memcpy(&vsi->info.queue_mapping,
  4533. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4534. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4535. sizeof(vsi->info.tc_mapping));
  4536. }
  4537. /**
  4538. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4539. * @vsi: VSI to be configured
  4540. * @enabled_tc: TC bitmap
  4541. *
  4542. * This configures a particular VSI for TCs that are mapped to the
  4543. * given TC bitmap. It uses default bandwidth share for TCs across
  4544. * VSIs to configure TC for a particular VSI.
  4545. *
  4546. * NOTE:
  4547. * It is expected that the VSI queues have been quisced before calling
  4548. * this function.
  4549. **/
  4550. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4551. {
  4552. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4553. struct i40e_pf *pf = vsi->back;
  4554. struct i40e_hw *hw = &pf->hw;
  4555. struct i40e_vsi_context ctxt;
  4556. int ret = 0;
  4557. int i;
  4558. /* Check if enabled_tc is same as existing or new TCs */
  4559. if (vsi->tc_config.enabled_tc == enabled_tc &&
  4560. vsi->mqprio_qopt.mode != TC_MQPRIO_MODE_CHANNEL)
  4561. return ret;
  4562. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4563. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4564. if (enabled_tc & BIT(i))
  4565. bw_share[i] = 1;
  4566. }
  4567. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4568. if (ret) {
  4569. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4570. dev_info(&pf->pdev->dev,
  4571. "Failed configuring TC map %d for VSI %d\n",
  4572. enabled_tc, vsi->seid);
  4573. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid,
  4574. &bw_config, NULL);
  4575. if (ret) {
  4576. dev_info(&pf->pdev->dev,
  4577. "Failed querying vsi bw info, err %s aq_err %s\n",
  4578. i40e_stat_str(hw, ret),
  4579. i40e_aq_str(hw, hw->aq.asq_last_status));
  4580. goto out;
  4581. }
  4582. if ((bw_config.tc_valid_bits & enabled_tc) != enabled_tc) {
  4583. u8 valid_tc = bw_config.tc_valid_bits & enabled_tc;
  4584. if (!valid_tc)
  4585. valid_tc = bw_config.tc_valid_bits;
  4586. /* Always enable TC0, no matter what */
  4587. valid_tc |= 1;
  4588. dev_info(&pf->pdev->dev,
  4589. "Requested tc 0x%x, but FW reports 0x%x as valid. Attempting to use 0x%x.\n",
  4590. enabled_tc, bw_config.tc_valid_bits, valid_tc);
  4591. enabled_tc = valid_tc;
  4592. }
  4593. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4594. if (ret) {
  4595. dev_err(&pf->pdev->dev,
  4596. "Unable to configure TC map %d for VSI %d\n",
  4597. enabled_tc, vsi->seid);
  4598. goto out;
  4599. }
  4600. }
  4601. /* Update Queue Pairs Mapping for currently enabled UPs */
  4602. ctxt.seid = vsi->seid;
  4603. ctxt.pf_num = vsi->back->hw.pf_id;
  4604. ctxt.vf_num = 0;
  4605. ctxt.uplink_seid = vsi->uplink_seid;
  4606. ctxt.info = vsi->info;
  4607. if (vsi->back->flags & I40E_FLAG_TC_MQPRIO) {
  4608. ret = i40e_vsi_setup_queue_map_mqprio(vsi, &ctxt, enabled_tc);
  4609. if (ret)
  4610. goto out;
  4611. } else {
  4612. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4613. }
  4614. /* On destroying the qdisc, reset vsi->rss_size, as number of enabled
  4615. * queues changed.
  4616. */
  4617. if (!vsi->mqprio_qopt.qopt.hw && vsi->reconfig_rss) {
  4618. vsi->rss_size = min_t(int, vsi->back->alloc_rss_size,
  4619. vsi->num_queue_pairs);
  4620. ret = i40e_vsi_config_rss(vsi);
  4621. if (ret) {
  4622. dev_info(&vsi->back->pdev->dev,
  4623. "Failed to reconfig rss for num_queues\n");
  4624. return ret;
  4625. }
  4626. vsi->reconfig_rss = false;
  4627. }
  4628. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4629. ctxt.info.valid_sections |=
  4630. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4631. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4632. }
  4633. /* Update the VSI after updating the VSI queue-mapping
  4634. * information
  4635. */
  4636. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  4637. if (ret) {
  4638. dev_info(&pf->pdev->dev,
  4639. "Update vsi tc config failed, err %s aq_err %s\n",
  4640. i40e_stat_str(hw, ret),
  4641. i40e_aq_str(hw, hw->aq.asq_last_status));
  4642. goto out;
  4643. }
  4644. /* update the local VSI info with updated queue map */
  4645. i40e_vsi_update_queue_map(vsi, &ctxt);
  4646. vsi->info.valid_sections = 0;
  4647. /* Update current VSI BW information */
  4648. ret = i40e_vsi_get_bw_info(vsi);
  4649. if (ret) {
  4650. dev_info(&pf->pdev->dev,
  4651. "Failed updating vsi bw info, err %s aq_err %s\n",
  4652. i40e_stat_str(hw, ret),
  4653. i40e_aq_str(hw, hw->aq.asq_last_status));
  4654. goto out;
  4655. }
  4656. /* Update the netdev TC setup */
  4657. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4658. out:
  4659. return ret;
  4660. }
  4661. /**
  4662. * i40e_get_link_speed - Returns link speed for the interface
  4663. * @vsi: VSI to be configured
  4664. *
  4665. **/
  4666. static int i40e_get_link_speed(struct i40e_vsi *vsi)
  4667. {
  4668. struct i40e_pf *pf = vsi->back;
  4669. switch (pf->hw.phy.link_info.link_speed) {
  4670. case I40E_LINK_SPEED_40GB:
  4671. return 40000;
  4672. case I40E_LINK_SPEED_25GB:
  4673. return 25000;
  4674. case I40E_LINK_SPEED_20GB:
  4675. return 20000;
  4676. case I40E_LINK_SPEED_10GB:
  4677. return 10000;
  4678. case I40E_LINK_SPEED_1GB:
  4679. return 1000;
  4680. default:
  4681. return -EINVAL;
  4682. }
  4683. }
  4684. /**
  4685. * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
  4686. * @vsi: VSI to be configured
  4687. * @seid: seid of the channel/VSI
  4688. * @max_tx_rate: max TX rate to be configured as BW limit
  4689. *
  4690. * Helper function to set BW limit for a given VSI
  4691. **/
  4692. int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
  4693. {
  4694. struct i40e_pf *pf = vsi->back;
  4695. u64 credits = 0;
  4696. int speed = 0;
  4697. int ret = 0;
  4698. speed = i40e_get_link_speed(vsi);
  4699. if (max_tx_rate > speed) {
  4700. dev_err(&pf->pdev->dev,
  4701. "Invalid max tx rate %llu specified for VSI seid %d.",
  4702. max_tx_rate, seid);
  4703. return -EINVAL;
  4704. }
  4705. if (max_tx_rate && max_tx_rate < 50) {
  4706. dev_warn(&pf->pdev->dev,
  4707. "Setting max tx rate to minimum usable value of 50Mbps.\n");
  4708. max_tx_rate = 50;
  4709. }
  4710. /* Tx rate credits are in values of 50Mbps, 0 is disabled */
  4711. credits = max_tx_rate;
  4712. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  4713. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, seid, credits,
  4714. I40E_MAX_BW_INACTIVE_ACCUM, NULL);
  4715. if (ret)
  4716. dev_err(&pf->pdev->dev,
  4717. "Failed set tx rate (%llu Mbps) for vsi->seid %u, err %s aq_err %s\n",
  4718. max_tx_rate, seid, i40e_stat_str(&pf->hw, ret),
  4719. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4720. return ret;
  4721. }
  4722. /**
  4723. * i40e_remove_queue_channels - Remove queue channels for the TCs
  4724. * @vsi: VSI to be configured
  4725. *
  4726. * Remove queue channels for the TCs
  4727. **/
  4728. static void i40e_remove_queue_channels(struct i40e_vsi *vsi)
  4729. {
  4730. enum i40e_admin_queue_err last_aq_status;
  4731. struct i40e_cloud_filter *cfilter;
  4732. struct i40e_channel *ch, *ch_tmp;
  4733. struct i40e_pf *pf = vsi->back;
  4734. struct hlist_node *node;
  4735. int ret, i;
  4736. /* Reset rss size that was stored when reconfiguring rss for
  4737. * channel VSIs with non-power-of-2 queue count.
  4738. */
  4739. vsi->current_rss_size = 0;
  4740. /* perform cleanup for channels if they exist */
  4741. if (list_empty(&vsi->ch_list))
  4742. return;
  4743. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4744. struct i40e_vsi *p_vsi;
  4745. list_del(&ch->list);
  4746. p_vsi = ch->parent_vsi;
  4747. if (!p_vsi || !ch->initialized) {
  4748. kfree(ch);
  4749. continue;
  4750. }
  4751. /* Reset queue contexts */
  4752. for (i = 0; i < ch->num_queue_pairs; i++) {
  4753. struct i40e_ring *tx_ring, *rx_ring;
  4754. u16 pf_q;
  4755. pf_q = ch->base_queue + i;
  4756. tx_ring = vsi->tx_rings[pf_q];
  4757. tx_ring->ch = NULL;
  4758. rx_ring = vsi->rx_rings[pf_q];
  4759. rx_ring->ch = NULL;
  4760. }
  4761. /* Reset BW configured for this VSI via mqprio */
  4762. ret = i40e_set_bw_limit(vsi, ch->seid, 0);
  4763. if (ret)
  4764. dev_info(&vsi->back->pdev->dev,
  4765. "Failed to reset tx rate for ch->seid %u\n",
  4766. ch->seid);
  4767. /* delete cloud filters associated with this channel */
  4768. hlist_for_each_entry_safe(cfilter, node,
  4769. &pf->cloud_filter_list, cloud_node) {
  4770. if (cfilter->seid != ch->seid)
  4771. continue;
  4772. hash_del(&cfilter->cloud_node);
  4773. if (cfilter->dst_port)
  4774. ret = i40e_add_del_cloud_filter_big_buf(vsi,
  4775. cfilter,
  4776. false);
  4777. else
  4778. ret = i40e_add_del_cloud_filter(vsi, cfilter,
  4779. false);
  4780. last_aq_status = pf->hw.aq.asq_last_status;
  4781. if (ret)
  4782. dev_info(&pf->pdev->dev,
  4783. "Failed to delete cloud filter, err %s aq_err %s\n",
  4784. i40e_stat_str(&pf->hw, ret),
  4785. i40e_aq_str(&pf->hw, last_aq_status));
  4786. kfree(cfilter);
  4787. }
  4788. /* delete VSI from FW */
  4789. ret = i40e_aq_delete_element(&vsi->back->hw, ch->seid,
  4790. NULL);
  4791. if (ret)
  4792. dev_err(&vsi->back->pdev->dev,
  4793. "unable to remove channel (%d) for parent VSI(%d)\n",
  4794. ch->seid, p_vsi->seid);
  4795. kfree(ch);
  4796. }
  4797. INIT_LIST_HEAD(&vsi->ch_list);
  4798. }
  4799. /**
  4800. * i40e_is_any_channel - channel exist or not
  4801. * @vsi: ptr to VSI to which channels are associated with
  4802. *
  4803. * Returns true or false if channel(s) exist for associated VSI or not
  4804. **/
  4805. static bool i40e_is_any_channel(struct i40e_vsi *vsi)
  4806. {
  4807. struct i40e_channel *ch, *ch_tmp;
  4808. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4809. if (ch->initialized)
  4810. return true;
  4811. }
  4812. return false;
  4813. }
  4814. /**
  4815. * i40e_get_max_queues_for_channel
  4816. * @vsi: ptr to VSI to which channels are associated with
  4817. *
  4818. * Helper function which returns max value among the queue counts set on the
  4819. * channels/TCs created.
  4820. **/
  4821. static int i40e_get_max_queues_for_channel(struct i40e_vsi *vsi)
  4822. {
  4823. struct i40e_channel *ch, *ch_tmp;
  4824. int max = 0;
  4825. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  4826. if (!ch->initialized)
  4827. continue;
  4828. if (ch->num_queue_pairs > max)
  4829. max = ch->num_queue_pairs;
  4830. }
  4831. return max;
  4832. }
  4833. /**
  4834. * i40e_validate_num_queues - validate num_queues w.r.t channel
  4835. * @pf: ptr to PF device
  4836. * @num_queues: number of queues
  4837. * @vsi: the parent VSI
  4838. * @reconfig_rss: indicates should the RSS be reconfigured or not
  4839. *
  4840. * This function validates number of queues in the context of new channel
  4841. * which is being established and determines if RSS should be reconfigured
  4842. * or not for parent VSI.
  4843. **/
  4844. static int i40e_validate_num_queues(struct i40e_pf *pf, int num_queues,
  4845. struct i40e_vsi *vsi, bool *reconfig_rss)
  4846. {
  4847. int max_ch_queues;
  4848. if (!reconfig_rss)
  4849. return -EINVAL;
  4850. *reconfig_rss = false;
  4851. if (vsi->current_rss_size) {
  4852. if (num_queues > vsi->current_rss_size) {
  4853. dev_dbg(&pf->pdev->dev,
  4854. "Error: num_queues (%d) > vsi's current_size(%d)\n",
  4855. num_queues, vsi->current_rss_size);
  4856. return -EINVAL;
  4857. } else if ((num_queues < vsi->current_rss_size) &&
  4858. (!is_power_of_2(num_queues))) {
  4859. dev_dbg(&pf->pdev->dev,
  4860. "Error: num_queues (%d) < vsi's current_size(%d), but not power of 2\n",
  4861. num_queues, vsi->current_rss_size);
  4862. return -EINVAL;
  4863. }
  4864. }
  4865. if (!is_power_of_2(num_queues)) {
  4866. /* Find the max num_queues configured for channel if channel
  4867. * exist.
  4868. * if channel exist, then enforce 'num_queues' to be more than
  4869. * max ever queues configured for channel.
  4870. */
  4871. max_ch_queues = i40e_get_max_queues_for_channel(vsi);
  4872. if (num_queues < max_ch_queues) {
  4873. dev_dbg(&pf->pdev->dev,
  4874. "Error: num_queues (%d) < max queues configured for channel(%d)\n",
  4875. num_queues, max_ch_queues);
  4876. return -EINVAL;
  4877. }
  4878. *reconfig_rss = true;
  4879. }
  4880. return 0;
  4881. }
  4882. /**
  4883. * i40e_vsi_reconfig_rss - reconfig RSS based on specified rss_size
  4884. * @vsi: the VSI being setup
  4885. * @rss_size: size of RSS, accordingly LUT gets reprogrammed
  4886. *
  4887. * This function reconfigures RSS by reprogramming LUTs using 'rss_size'
  4888. **/
  4889. static int i40e_vsi_reconfig_rss(struct i40e_vsi *vsi, u16 rss_size)
  4890. {
  4891. struct i40e_pf *pf = vsi->back;
  4892. u8 seed[I40E_HKEY_ARRAY_SIZE];
  4893. struct i40e_hw *hw = &pf->hw;
  4894. int local_rss_size;
  4895. u8 *lut;
  4896. int ret;
  4897. if (!vsi->rss_size)
  4898. return -EINVAL;
  4899. if (rss_size > vsi->rss_size)
  4900. return -EINVAL;
  4901. local_rss_size = min_t(int, vsi->rss_size, rss_size);
  4902. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  4903. if (!lut)
  4904. return -ENOMEM;
  4905. /* Ignoring user configured lut if there is one */
  4906. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, local_rss_size);
  4907. /* Use user configured hash key if there is one, otherwise
  4908. * use default.
  4909. */
  4910. if (vsi->rss_hkey_user)
  4911. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  4912. else
  4913. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  4914. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  4915. if (ret) {
  4916. dev_info(&pf->pdev->dev,
  4917. "Cannot set RSS lut, err %s aq_err %s\n",
  4918. i40e_stat_str(hw, ret),
  4919. i40e_aq_str(hw, hw->aq.asq_last_status));
  4920. kfree(lut);
  4921. return ret;
  4922. }
  4923. kfree(lut);
  4924. /* Do the update w.r.t. storing rss_size */
  4925. if (!vsi->orig_rss_size)
  4926. vsi->orig_rss_size = vsi->rss_size;
  4927. vsi->current_rss_size = local_rss_size;
  4928. return ret;
  4929. }
  4930. /**
  4931. * i40e_channel_setup_queue_map - Setup a channel queue map
  4932. * @pf: ptr to PF device
  4933. * @vsi: the VSI being setup
  4934. * @ctxt: VSI context structure
  4935. * @ch: ptr to channel structure
  4936. *
  4937. * Setup queue map for a specific channel
  4938. **/
  4939. static void i40e_channel_setup_queue_map(struct i40e_pf *pf,
  4940. struct i40e_vsi_context *ctxt,
  4941. struct i40e_channel *ch)
  4942. {
  4943. u16 qcount, qmap, sections = 0;
  4944. u8 offset = 0;
  4945. int pow;
  4946. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  4947. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  4948. qcount = min_t(int, ch->num_queue_pairs, pf->num_lan_msix);
  4949. ch->num_queue_pairs = qcount;
  4950. /* find the next higher power-of-2 of num queue pairs */
  4951. pow = ilog2(qcount);
  4952. if (!is_power_of_2(qcount))
  4953. pow++;
  4954. qmap = (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  4955. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  4956. /* Setup queue TC[0].qmap for given VSI context */
  4957. ctxt->info.tc_mapping[0] = cpu_to_le16(qmap);
  4958. ctxt->info.up_enable_bits = 0x1; /* TC0 enabled */
  4959. ctxt->info.mapping_flags |= cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  4960. ctxt->info.queue_mapping[0] = cpu_to_le16(ch->base_queue);
  4961. ctxt->info.valid_sections |= cpu_to_le16(sections);
  4962. }
  4963. /**
  4964. * i40e_add_channel - add a channel by adding VSI
  4965. * @pf: ptr to PF device
  4966. * @uplink_seid: underlying HW switching element (VEB) ID
  4967. * @ch: ptr to channel structure
  4968. *
  4969. * Add a channel (VSI) using add_vsi and queue_map
  4970. **/
  4971. static int i40e_add_channel(struct i40e_pf *pf, u16 uplink_seid,
  4972. struct i40e_channel *ch)
  4973. {
  4974. struct i40e_hw *hw = &pf->hw;
  4975. struct i40e_vsi_context ctxt;
  4976. u8 enabled_tc = 0x1; /* TC0 enabled */
  4977. int ret;
  4978. if (ch->type != I40E_VSI_VMDQ2) {
  4979. dev_info(&pf->pdev->dev,
  4980. "add new vsi failed, ch->type %d\n", ch->type);
  4981. return -EINVAL;
  4982. }
  4983. memset(&ctxt, 0, sizeof(ctxt));
  4984. ctxt.pf_num = hw->pf_id;
  4985. ctxt.vf_num = 0;
  4986. ctxt.uplink_seid = uplink_seid;
  4987. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  4988. if (ch->type == I40E_VSI_VMDQ2)
  4989. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  4990. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED) {
  4991. ctxt.info.valid_sections |=
  4992. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  4993. ctxt.info.switch_id =
  4994. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  4995. }
  4996. /* Set queue map for a given VSI context */
  4997. i40e_channel_setup_queue_map(pf, &ctxt, ch);
  4998. /* Now time to create VSI */
  4999. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  5000. if (ret) {
  5001. dev_info(&pf->pdev->dev,
  5002. "add new vsi failed, err %s aq_err %s\n",
  5003. i40e_stat_str(&pf->hw, ret),
  5004. i40e_aq_str(&pf->hw,
  5005. pf->hw.aq.asq_last_status));
  5006. return -ENOENT;
  5007. }
  5008. /* Success, update channel */
  5009. ch->enabled_tc = enabled_tc;
  5010. ch->seid = ctxt.seid;
  5011. ch->vsi_number = ctxt.vsi_number;
  5012. ch->stat_counter_idx = cpu_to_le16(ctxt.info.stat_counter_idx);
  5013. /* copy just the sections touched not the entire info
  5014. * since not all sections are valid as returned by
  5015. * update vsi params
  5016. */
  5017. ch->info.mapping_flags = ctxt.info.mapping_flags;
  5018. memcpy(&ch->info.queue_mapping,
  5019. &ctxt.info.queue_mapping, sizeof(ctxt.info.queue_mapping));
  5020. memcpy(&ch->info.tc_mapping, ctxt.info.tc_mapping,
  5021. sizeof(ctxt.info.tc_mapping));
  5022. return 0;
  5023. }
  5024. static int i40e_channel_config_bw(struct i40e_vsi *vsi, struct i40e_channel *ch,
  5025. u8 *bw_share)
  5026. {
  5027. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  5028. i40e_status ret;
  5029. int i;
  5030. bw_data.tc_valid_bits = ch->enabled_tc;
  5031. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5032. bw_data.tc_bw_credits[i] = bw_share[i];
  5033. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, ch->seid,
  5034. &bw_data, NULL);
  5035. if (ret) {
  5036. dev_info(&vsi->back->pdev->dev,
  5037. "Config VSI BW allocation per TC failed, aq_err: %d for new_vsi->seid %u\n",
  5038. vsi->back->hw.aq.asq_last_status, ch->seid);
  5039. return -EINVAL;
  5040. }
  5041. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  5042. ch->info.qs_handle[i] = bw_data.qs_handles[i];
  5043. return 0;
  5044. }
  5045. /**
  5046. * i40e_channel_config_tx_ring - config TX ring associated with new channel
  5047. * @pf: ptr to PF device
  5048. * @vsi: the VSI being setup
  5049. * @ch: ptr to channel structure
  5050. *
  5051. * Configure TX rings associated with channel (VSI) since queues are being
  5052. * from parent VSI.
  5053. **/
  5054. static int i40e_channel_config_tx_ring(struct i40e_pf *pf,
  5055. struct i40e_vsi *vsi,
  5056. struct i40e_channel *ch)
  5057. {
  5058. i40e_status ret;
  5059. int i;
  5060. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  5061. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  5062. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5063. if (ch->enabled_tc & BIT(i))
  5064. bw_share[i] = 1;
  5065. }
  5066. /* configure BW for new VSI */
  5067. ret = i40e_channel_config_bw(vsi, ch, bw_share);
  5068. if (ret) {
  5069. dev_info(&vsi->back->pdev->dev,
  5070. "Failed configuring TC map %d for channel (seid %u)\n",
  5071. ch->enabled_tc, ch->seid);
  5072. return ret;
  5073. }
  5074. for (i = 0; i < ch->num_queue_pairs; i++) {
  5075. struct i40e_ring *tx_ring, *rx_ring;
  5076. u16 pf_q;
  5077. pf_q = ch->base_queue + i;
  5078. /* Get to TX ring ptr of main VSI, for re-setup TX queue
  5079. * context
  5080. */
  5081. tx_ring = vsi->tx_rings[pf_q];
  5082. tx_ring->ch = ch;
  5083. /* Get the RX ring ptr */
  5084. rx_ring = vsi->rx_rings[pf_q];
  5085. rx_ring->ch = ch;
  5086. }
  5087. return 0;
  5088. }
  5089. /**
  5090. * i40e_setup_hw_channel - setup new channel
  5091. * @pf: ptr to PF device
  5092. * @vsi: the VSI being setup
  5093. * @ch: ptr to channel structure
  5094. * @uplink_seid: underlying HW switching element (VEB) ID
  5095. * @type: type of channel to be created (VMDq2/VF)
  5096. *
  5097. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5098. * and configures TX rings accordingly
  5099. **/
  5100. static inline int i40e_setup_hw_channel(struct i40e_pf *pf,
  5101. struct i40e_vsi *vsi,
  5102. struct i40e_channel *ch,
  5103. u16 uplink_seid, u8 type)
  5104. {
  5105. int ret;
  5106. ch->initialized = false;
  5107. ch->base_queue = vsi->next_base_queue;
  5108. ch->type = type;
  5109. /* Proceed with creation of channel (VMDq2) VSI */
  5110. ret = i40e_add_channel(pf, uplink_seid, ch);
  5111. if (ret) {
  5112. dev_info(&pf->pdev->dev,
  5113. "failed to add_channel using uplink_seid %u\n",
  5114. uplink_seid);
  5115. return ret;
  5116. }
  5117. /* Mark the successful creation of channel */
  5118. ch->initialized = true;
  5119. /* Reconfigure TX queues using QTX_CTL register */
  5120. ret = i40e_channel_config_tx_ring(pf, vsi, ch);
  5121. if (ret) {
  5122. dev_info(&pf->pdev->dev,
  5123. "failed to configure TX rings for channel %u\n",
  5124. ch->seid);
  5125. return ret;
  5126. }
  5127. /* update 'next_base_queue' */
  5128. vsi->next_base_queue = vsi->next_base_queue + ch->num_queue_pairs;
  5129. dev_dbg(&pf->pdev->dev,
  5130. "Added channel: vsi_seid %u, vsi_number %u, stat_counter_idx %u, num_queue_pairs %u, pf->next_base_queue %d\n",
  5131. ch->seid, ch->vsi_number, ch->stat_counter_idx,
  5132. ch->num_queue_pairs,
  5133. vsi->next_base_queue);
  5134. return ret;
  5135. }
  5136. /**
  5137. * i40e_setup_channel - setup new channel using uplink element
  5138. * @pf: ptr to PF device
  5139. * @type: type of channel to be created (VMDq2/VF)
  5140. * @uplink_seid: underlying HW switching element (VEB) ID
  5141. * @ch: ptr to channel structure
  5142. *
  5143. * Setup new channel (VSI) based on specified type (VMDq2/VF)
  5144. * and uplink switching element (uplink_seid)
  5145. **/
  5146. static bool i40e_setup_channel(struct i40e_pf *pf, struct i40e_vsi *vsi,
  5147. struct i40e_channel *ch)
  5148. {
  5149. u8 vsi_type;
  5150. u16 seid;
  5151. int ret;
  5152. if (vsi->type == I40E_VSI_MAIN) {
  5153. vsi_type = I40E_VSI_VMDQ2;
  5154. } else {
  5155. dev_err(&pf->pdev->dev, "unsupported parent vsi type(%d)\n",
  5156. vsi->type);
  5157. return false;
  5158. }
  5159. /* underlying switching element */
  5160. seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5161. /* create channel (VSI), configure TX rings */
  5162. ret = i40e_setup_hw_channel(pf, vsi, ch, seid, vsi_type);
  5163. if (ret) {
  5164. dev_err(&pf->pdev->dev, "failed to setup hw_channel\n");
  5165. return false;
  5166. }
  5167. return ch->initialized ? true : false;
  5168. }
  5169. /**
  5170. * i40e_validate_and_set_switch_mode - sets up switch mode correctly
  5171. * @vsi: ptr to VSI which has PF backing
  5172. *
  5173. * Sets up switch mode correctly if it needs to be changed and perform
  5174. * what are allowed modes.
  5175. **/
  5176. static int i40e_validate_and_set_switch_mode(struct i40e_vsi *vsi)
  5177. {
  5178. u8 mode;
  5179. struct i40e_pf *pf = vsi->back;
  5180. struct i40e_hw *hw = &pf->hw;
  5181. int ret;
  5182. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_dev_capabilities);
  5183. if (ret)
  5184. return -EINVAL;
  5185. if (hw->dev_caps.switch_mode) {
  5186. /* if switch mode is set, support mode2 (non-tunneled for
  5187. * cloud filter) for now
  5188. */
  5189. u32 switch_mode = hw->dev_caps.switch_mode &
  5190. I40E_SWITCH_MODE_MASK;
  5191. if (switch_mode >= I40E_CLOUD_FILTER_MODE1) {
  5192. if (switch_mode == I40E_CLOUD_FILTER_MODE2)
  5193. return 0;
  5194. dev_err(&pf->pdev->dev,
  5195. "Invalid switch_mode (%d), only non-tunneled mode for cloud filter is supported\n",
  5196. hw->dev_caps.switch_mode);
  5197. return -EINVAL;
  5198. }
  5199. }
  5200. /* Set Bit 7 to be valid */
  5201. mode = I40E_AQ_SET_SWITCH_BIT7_VALID;
  5202. /* Set L4type for TCP support */
  5203. mode |= I40E_AQ_SET_SWITCH_L4_TYPE_TCP;
  5204. /* Set cloud filter mode */
  5205. mode |= I40E_AQ_SET_SWITCH_MODE_NON_TUNNEL;
  5206. /* Prep mode field for set_switch_config */
  5207. ret = i40e_aq_set_switch_config(hw, pf->last_sw_conf_flags,
  5208. pf->last_sw_conf_valid_flags,
  5209. mode, NULL);
  5210. if (ret && hw->aq.asq_last_status != I40E_AQ_RC_ESRCH)
  5211. dev_err(&pf->pdev->dev,
  5212. "couldn't set switch config bits, err %s aq_err %s\n",
  5213. i40e_stat_str(hw, ret),
  5214. i40e_aq_str(hw,
  5215. hw->aq.asq_last_status));
  5216. return ret;
  5217. }
  5218. /**
  5219. * i40e_create_queue_channel - function to create channel
  5220. * @vsi: VSI to be configured
  5221. * @ch: ptr to channel (it contains channel specific params)
  5222. *
  5223. * This function creates channel (VSI) using num_queues specified by user,
  5224. * reconfigs RSS if needed.
  5225. **/
  5226. int i40e_create_queue_channel(struct i40e_vsi *vsi,
  5227. struct i40e_channel *ch)
  5228. {
  5229. struct i40e_pf *pf = vsi->back;
  5230. bool reconfig_rss;
  5231. int err;
  5232. if (!ch)
  5233. return -EINVAL;
  5234. if (!ch->num_queue_pairs) {
  5235. dev_err(&pf->pdev->dev, "Invalid num_queues requested: %d\n",
  5236. ch->num_queue_pairs);
  5237. return -EINVAL;
  5238. }
  5239. /* validate user requested num_queues for channel */
  5240. err = i40e_validate_num_queues(pf, ch->num_queue_pairs, vsi,
  5241. &reconfig_rss);
  5242. if (err) {
  5243. dev_info(&pf->pdev->dev, "Failed to validate num_queues (%d)\n",
  5244. ch->num_queue_pairs);
  5245. return -EINVAL;
  5246. }
  5247. /* By default we are in VEPA mode, if this is the first VF/VMDq
  5248. * VSI to be added switch to VEB mode.
  5249. */
  5250. if ((!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) ||
  5251. (!i40e_is_any_channel(vsi))) {
  5252. if (!is_power_of_2(vsi->tc_config.tc_info[0].qcount)) {
  5253. dev_dbg(&pf->pdev->dev,
  5254. "Failed to create channel. Override queues (%u) not power of 2\n",
  5255. vsi->tc_config.tc_info[0].qcount);
  5256. return -EINVAL;
  5257. }
  5258. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  5259. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  5260. if (vsi->type == I40E_VSI_MAIN) {
  5261. if (pf->flags & I40E_FLAG_TC_MQPRIO)
  5262. i40e_do_reset(pf, I40E_PF_RESET_FLAG,
  5263. true);
  5264. else
  5265. i40e_do_reset_safe(pf,
  5266. I40E_PF_RESET_FLAG);
  5267. }
  5268. }
  5269. /* now onwards for main VSI, number of queues will be value
  5270. * of TC0's queue count
  5271. */
  5272. }
  5273. /* By this time, vsi->cnt_q_avail shall be set to non-zero and
  5274. * it should be more than num_queues
  5275. */
  5276. if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_queue_pairs) {
  5277. dev_dbg(&pf->pdev->dev,
  5278. "Error: cnt_q_avail (%u) less than num_queues %d\n",
  5279. vsi->cnt_q_avail, ch->num_queue_pairs);
  5280. return -EINVAL;
  5281. }
  5282. /* reconfig_rss only if vsi type is MAIN_VSI */
  5283. if (reconfig_rss && (vsi->type == I40E_VSI_MAIN)) {
  5284. err = i40e_vsi_reconfig_rss(vsi, ch->num_queue_pairs);
  5285. if (err) {
  5286. dev_info(&pf->pdev->dev,
  5287. "Error: unable to reconfig rss for num_queues (%u)\n",
  5288. ch->num_queue_pairs);
  5289. return -EINVAL;
  5290. }
  5291. }
  5292. if (!i40e_setup_channel(pf, vsi, ch)) {
  5293. dev_info(&pf->pdev->dev, "Failed to setup channel\n");
  5294. return -EINVAL;
  5295. }
  5296. dev_info(&pf->pdev->dev,
  5297. "Setup channel (id:%u) utilizing num_queues %d\n",
  5298. ch->seid, ch->num_queue_pairs);
  5299. /* configure VSI for BW limit */
  5300. if (ch->max_tx_rate) {
  5301. u64 credits = ch->max_tx_rate;
  5302. if (i40e_set_bw_limit(vsi, ch->seid, ch->max_tx_rate))
  5303. return -EINVAL;
  5304. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5305. dev_dbg(&pf->pdev->dev,
  5306. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5307. ch->max_tx_rate,
  5308. credits,
  5309. ch->seid);
  5310. }
  5311. /* in case of VF, this will be main SRIOV VSI */
  5312. ch->parent_vsi = vsi;
  5313. /* and update main_vsi's count for queue_available to use */
  5314. vsi->cnt_q_avail -= ch->num_queue_pairs;
  5315. return 0;
  5316. }
  5317. /**
  5318. * i40e_configure_queue_channels - Add queue channel for the given TCs
  5319. * @vsi: VSI to be configured
  5320. *
  5321. * Configures queue channel mapping to the given TCs
  5322. **/
  5323. static int i40e_configure_queue_channels(struct i40e_vsi *vsi)
  5324. {
  5325. struct i40e_channel *ch;
  5326. u64 max_rate = 0;
  5327. int ret = 0, i;
  5328. /* Create app vsi with the TCs. Main VSI with TC0 is already set up */
  5329. vsi->tc_seid_map[0] = vsi->seid;
  5330. for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5331. if (vsi->tc_config.enabled_tc & BIT(i)) {
  5332. ch = kzalloc(sizeof(*ch), GFP_KERNEL);
  5333. if (!ch) {
  5334. ret = -ENOMEM;
  5335. goto err_free;
  5336. }
  5337. INIT_LIST_HEAD(&ch->list);
  5338. ch->num_queue_pairs =
  5339. vsi->tc_config.tc_info[i].qcount;
  5340. ch->base_queue =
  5341. vsi->tc_config.tc_info[i].qoffset;
  5342. /* Bandwidth limit through tc interface is in bytes/s,
  5343. * change to Mbit/s
  5344. */
  5345. max_rate = vsi->mqprio_qopt.max_rate[i];
  5346. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5347. ch->max_tx_rate = max_rate;
  5348. list_add_tail(&ch->list, &vsi->ch_list);
  5349. ret = i40e_create_queue_channel(vsi, ch);
  5350. if (ret) {
  5351. dev_err(&vsi->back->pdev->dev,
  5352. "Failed creating queue channel with TC%d: queues %d\n",
  5353. i, ch->num_queue_pairs);
  5354. goto err_free;
  5355. }
  5356. vsi->tc_seid_map[i] = ch->seid;
  5357. }
  5358. }
  5359. return ret;
  5360. err_free:
  5361. i40e_remove_queue_channels(vsi);
  5362. return ret;
  5363. }
  5364. /**
  5365. * i40e_veb_config_tc - Configure TCs for given VEB
  5366. * @veb: given VEB
  5367. * @enabled_tc: TC bitmap
  5368. *
  5369. * Configures given TC bitmap for VEB (switching) element
  5370. **/
  5371. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  5372. {
  5373. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  5374. struct i40e_pf *pf = veb->pf;
  5375. int ret = 0;
  5376. int i;
  5377. /* No TCs or already enabled TCs just return */
  5378. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  5379. return ret;
  5380. bw_data.tc_valid_bits = enabled_tc;
  5381. /* bw_data.absolute_credits is not set (relative) */
  5382. /* Enable ETS TCs with equal BW Share for now */
  5383. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5384. if (enabled_tc & BIT(i))
  5385. bw_data.tc_bw_share_credits[i] = 1;
  5386. }
  5387. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  5388. &bw_data, NULL);
  5389. if (ret) {
  5390. dev_info(&pf->pdev->dev,
  5391. "VEB bw config failed, err %s aq_err %s\n",
  5392. i40e_stat_str(&pf->hw, ret),
  5393. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5394. goto out;
  5395. }
  5396. /* Update the BW information */
  5397. ret = i40e_veb_get_bw_info(veb);
  5398. if (ret) {
  5399. dev_info(&pf->pdev->dev,
  5400. "Failed getting veb bw config, err %s aq_err %s\n",
  5401. i40e_stat_str(&pf->hw, ret),
  5402. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5403. }
  5404. out:
  5405. return ret;
  5406. }
  5407. #ifdef CONFIG_I40E_DCB
  5408. /**
  5409. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  5410. * @pf: PF struct
  5411. *
  5412. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  5413. * the caller would've quiesce all the VSIs before calling
  5414. * this function
  5415. **/
  5416. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  5417. {
  5418. u8 tc_map = 0;
  5419. int ret;
  5420. u8 v;
  5421. /* Enable the TCs available on PF to all VEBs */
  5422. tc_map = i40e_pf_get_tc_map(pf);
  5423. for (v = 0; v < I40E_MAX_VEB; v++) {
  5424. if (!pf->veb[v])
  5425. continue;
  5426. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  5427. if (ret) {
  5428. dev_info(&pf->pdev->dev,
  5429. "Failed configuring TC for VEB seid=%d\n",
  5430. pf->veb[v]->seid);
  5431. /* Will try to configure as many components */
  5432. }
  5433. }
  5434. /* Update each VSI */
  5435. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5436. if (!pf->vsi[v])
  5437. continue;
  5438. /* - Enable all TCs for the LAN VSI
  5439. * - For all others keep them at TC0 for now
  5440. */
  5441. if (v == pf->lan_vsi)
  5442. tc_map = i40e_pf_get_tc_map(pf);
  5443. else
  5444. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  5445. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  5446. if (ret) {
  5447. dev_info(&pf->pdev->dev,
  5448. "Failed configuring TC for VSI seid=%d\n",
  5449. pf->vsi[v]->seid);
  5450. /* Will try to configure as many components */
  5451. } else {
  5452. /* Re-configure VSI vectors based on updated TC map */
  5453. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  5454. if (pf->vsi[v]->netdev)
  5455. i40e_dcbnl_set_all(pf->vsi[v]);
  5456. }
  5457. }
  5458. }
  5459. /**
  5460. * i40e_resume_port_tx - Resume port Tx
  5461. * @pf: PF struct
  5462. *
  5463. * Resume a port's Tx and issue a PF reset in case of failure to
  5464. * resume.
  5465. **/
  5466. static int i40e_resume_port_tx(struct i40e_pf *pf)
  5467. {
  5468. struct i40e_hw *hw = &pf->hw;
  5469. int ret;
  5470. ret = i40e_aq_resume_port_tx(hw, NULL);
  5471. if (ret) {
  5472. dev_info(&pf->pdev->dev,
  5473. "Resume Port Tx failed, err %s aq_err %s\n",
  5474. i40e_stat_str(&pf->hw, ret),
  5475. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5476. /* Schedule PF reset to recover */
  5477. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  5478. i40e_service_event_schedule(pf);
  5479. }
  5480. return ret;
  5481. }
  5482. /**
  5483. * i40e_init_pf_dcb - Initialize DCB configuration
  5484. * @pf: PF being configured
  5485. *
  5486. * Query the current DCB configuration and cache it
  5487. * in the hardware structure
  5488. **/
  5489. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  5490. {
  5491. struct i40e_hw *hw = &pf->hw;
  5492. int err = 0;
  5493. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable
  5494. * Also do not enable DCBx if FW LLDP agent is disabled
  5495. */
  5496. if ((pf->hw_features & I40E_HW_NO_DCB_SUPPORT) ||
  5497. (pf->flags & I40E_FLAG_DISABLE_FW_LLDP))
  5498. goto out;
  5499. /* Get the initial DCB configuration */
  5500. err = i40e_init_dcb(hw);
  5501. if (!err) {
  5502. /* Device/Function is not DCBX capable */
  5503. if ((!hw->func_caps.dcb) ||
  5504. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  5505. dev_info(&pf->pdev->dev,
  5506. "DCBX offload is not supported or is disabled for this PF.\n");
  5507. } else {
  5508. /* When status is not DISABLED then DCBX in FW */
  5509. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  5510. DCB_CAP_DCBX_VER_IEEE;
  5511. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  5512. /* Enable DCB tagging only when more than one TC
  5513. * or explicitly disable if only one TC
  5514. */
  5515. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5516. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5517. else
  5518. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5519. dev_dbg(&pf->pdev->dev,
  5520. "DCBX offload is supported for this PF.\n");
  5521. }
  5522. } else if (pf->hw.aq.asq_last_status == I40E_AQ_RC_EPERM) {
  5523. dev_info(&pf->pdev->dev, "FW LLDP disabled for this PF.\n");
  5524. pf->flags |= I40E_FLAG_DISABLE_FW_LLDP;
  5525. } else {
  5526. dev_info(&pf->pdev->dev,
  5527. "Query for DCB configuration failed, err %s aq_err %s\n",
  5528. i40e_stat_str(&pf->hw, err),
  5529. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5530. }
  5531. out:
  5532. return err;
  5533. }
  5534. #endif /* CONFIG_I40E_DCB */
  5535. #define SPEED_SIZE 14
  5536. #define FC_SIZE 8
  5537. /**
  5538. * i40e_print_link_message - print link up or down
  5539. * @vsi: the VSI for which link needs a message
  5540. * @isup: true of link is up, false otherwise
  5541. */
  5542. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  5543. {
  5544. enum i40e_aq_link_speed new_speed;
  5545. struct i40e_pf *pf = vsi->back;
  5546. char *speed = "Unknown";
  5547. char *fc = "Unknown";
  5548. char *fec = "";
  5549. char *req_fec = "";
  5550. char *an = "";
  5551. new_speed = pf->hw.phy.link_info.link_speed;
  5552. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  5553. return;
  5554. vsi->current_isup = isup;
  5555. vsi->current_speed = new_speed;
  5556. if (!isup) {
  5557. netdev_info(vsi->netdev, "NIC Link is Down\n");
  5558. return;
  5559. }
  5560. /* Warn user if link speed on NPAR enabled partition is not at
  5561. * least 10GB
  5562. */
  5563. if (pf->hw.func_caps.npar_enable &&
  5564. (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  5565. pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  5566. netdev_warn(vsi->netdev,
  5567. "The partition detected link speed that is less than 10Gbps\n");
  5568. switch (pf->hw.phy.link_info.link_speed) {
  5569. case I40E_LINK_SPEED_40GB:
  5570. speed = "40 G";
  5571. break;
  5572. case I40E_LINK_SPEED_20GB:
  5573. speed = "20 G";
  5574. break;
  5575. case I40E_LINK_SPEED_25GB:
  5576. speed = "25 G";
  5577. break;
  5578. case I40E_LINK_SPEED_10GB:
  5579. speed = "10 G";
  5580. break;
  5581. case I40E_LINK_SPEED_1GB:
  5582. speed = "1000 M";
  5583. break;
  5584. case I40E_LINK_SPEED_100MB:
  5585. speed = "100 M";
  5586. break;
  5587. default:
  5588. break;
  5589. }
  5590. switch (pf->hw.fc.current_mode) {
  5591. case I40E_FC_FULL:
  5592. fc = "RX/TX";
  5593. break;
  5594. case I40E_FC_TX_PAUSE:
  5595. fc = "TX";
  5596. break;
  5597. case I40E_FC_RX_PAUSE:
  5598. fc = "RX";
  5599. break;
  5600. default:
  5601. fc = "None";
  5602. break;
  5603. }
  5604. if (pf->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  5605. req_fec = ", Requested FEC: None";
  5606. fec = ", FEC: None";
  5607. an = ", Autoneg: False";
  5608. if (pf->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  5609. an = ", Autoneg: True";
  5610. if (pf->hw.phy.link_info.fec_info &
  5611. I40E_AQ_CONFIG_FEC_KR_ENA)
  5612. fec = ", FEC: CL74 FC-FEC/BASE-R";
  5613. else if (pf->hw.phy.link_info.fec_info &
  5614. I40E_AQ_CONFIG_FEC_RS_ENA)
  5615. fec = ", FEC: CL108 RS-FEC";
  5616. /* 'CL108 RS-FEC' should be displayed when RS is requested, or
  5617. * both RS and FC are requested
  5618. */
  5619. if (vsi->back->hw.phy.link_info.req_fec_info &
  5620. (I40E_AQ_REQUEST_FEC_KR | I40E_AQ_REQUEST_FEC_RS)) {
  5621. if (vsi->back->hw.phy.link_info.req_fec_info &
  5622. I40E_AQ_REQUEST_FEC_RS)
  5623. req_fec = ", Requested FEC: CL108 RS-FEC";
  5624. else
  5625. req_fec = ", Requested FEC: CL74 FC-FEC/BASE-R";
  5626. }
  5627. }
  5628. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s%s, Flow Control: %s\n",
  5629. speed, req_fec, fec, an, fc);
  5630. }
  5631. /**
  5632. * i40e_up_complete - Finish the last steps of bringing up a connection
  5633. * @vsi: the VSI being configured
  5634. **/
  5635. static int i40e_up_complete(struct i40e_vsi *vsi)
  5636. {
  5637. struct i40e_pf *pf = vsi->back;
  5638. int err;
  5639. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5640. i40e_vsi_configure_msix(vsi);
  5641. else
  5642. i40e_configure_msi_and_legacy(vsi);
  5643. /* start rings */
  5644. err = i40e_vsi_start_rings(vsi);
  5645. if (err)
  5646. return err;
  5647. clear_bit(__I40E_VSI_DOWN, vsi->state);
  5648. i40e_napi_enable_all(vsi);
  5649. i40e_vsi_enable_irq(vsi);
  5650. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  5651. (vsi->netdev)) {
  5652. i40e_print_link_message(vsi, true);
  5653. netif_tx_start_all_queues(vsi->netdev);
  5654. netif_carrier_on(vsi->netdev);
  5655. }
  5656. /* replay FDIR SB filters */
  5657. if (vsi->type == I40E_VSI_FDIR) {
  5658. /* reset fd counters */
  5659. pf->fd_add_err = 0;
  5660. pf->fd_atr_cnt = 0;
  5661. i40e_fdir_filter_restore(vsi);
  5662. }
  5663. /* On the next run of the service_task, notify any clients of the new
  5664. * opened netdev
  5665. */
  5666. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  5667. i40e_service_event_schedule(pf);
  5668. return 0;
  5669. }
  5670. /**
  5671. * i40e_vsi_reinit_locked - Reset the VSI
  5672. * @vsi: the VSI being configured
  5673. *
  5674. * Rebuild the ring structs after some configuration
  5675. * has changed, e.g. MTU size.
  5676. **/
  5677. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  5678. {
  5679. struct i40e_pf *pf = vsi->back;
  5680. WARN_ON(in_interrupt());
  5681. while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state))
  5682. usleep_range(1000, 2000);
  5683. i40e_down(vsi);
  5684. i40e_up(vsi);
  5685. clear_bit(__I40E_CONFIG_BUSY, pf->state);
  5686. }
  5687. /**
  5688. * i40e_up - Bring the connection back up after being down
  5689. * @vsi: the VSI being configured
  5690. **/
  5691. int i40e_up(struct i40e_vsi *vsi)
  5692. {
  5693. int err;
  5694. err = i40e_vsi_configure(vsi);
  5695. if (!err)
  5696. err = i40e_up_complete(vsi);
  5697. return err;
  5698. }
  5699. /**
  5700. * i40e_force_link_state - Force the link status
  5701. * @pf: board private structure
  5702. * @is_up: whether the link state should be forced up or down
  5703. **/
  5704. static i40e_status i40e_force_link_state(struct i40e_pf *pf, bool is_up)
  5705. {
  5706. struct i40e_aq_get_phy_abilities_resp abilities;
  5707. struct i40e_aq_set_phy_config config = {0};
  5708. struct i40e_hw *hw = &pf->hw;
  5709. i40e_status err;
  5710. u64 mask;
  5711. /* Get the current phy config */
  5712. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  5713. NULL);
  5714. if (err) {
  5715. dev_err(&pf->pdev->dev,
  5716. "failed to get phy cap., ret = %s last_status = %s\n",
  5717. i40e_stat_str(hw, err),
  5718. i40e_aq_str(hw, hw->aq.asq_last_status));
  5719. return err;
  5720. }
  5721. /* If link needs to go up, but was not forced to go down,
  5722. * no need for a flap
  5723. */
  5724. if (is_up && abilities.phy_type != 0)
  5725. return I40E_SUCCESS;
  5726. /* To force link we need to set bits for all supported PHY types,
  5727. * but there are now more than 32, so we need to split the bitmap
  5728. * across two fields.
  5729. */
  5730. mask = I40E_PHY_TYPES_BITMASK;
  5731. config.phy_type = is_up ? cpu_to_le32((u32)(mask & 0xffffffff)) : 0;
  5732. config.phy_type_ext = is_up ? (u8)((mask >> 32) & 0xff) : 0;
  5733. /* Copy the old settings, except of phy_type */
  5734. config.abilities = abilities.abilities;
  5735. config.link_speed = abilities.link_speed;
  5736. config.eee_capability = abilities.eee_capability;
  5737. config.eeer = abilities.eeer_val;
  5738. config.low_power_ctrl = abilities.d3_lpan;
  5739. err = i40e_aq_set_phy_config(hw, &config, NULL);
  5740. if (err) {
  5741. dev_err(&pf->pdev->dev,
  5742. "set phy config ret = %s last_status = %s\n",
  5743. i40e_stat_str(&pf->hw, err),
  5744. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5745. return err;
  5746. }
  5747. /* Update the link info */
  5748. err = i40e_update_link_info(hw);
  5749. if (err) {
  5750. /* Wait a little bit (on 40G cards it sometimes takes a really
  5751. * long time for link to come back from the atomic reset)
  5752. * and try once more
  5753. */
  5754. msleep(1000);
  5755. i40e_update_link_info(hw);
  5756. }
  5757. i40e_aq_set_link_restart_an(hw, true, NULL);
  5758. return I40E_SUCCESS;
  5759. }
  5760. /**
  5761. * i40e_down - Shutdown the connection processing
  5762. * @vsi: the VSI being stopped
  5763. **/
  5764. void i40e_down(struct i40e_vsi *vsi)
  5765. {
  5766. int i;
  5767. /* It is assumed that the caller of this function
  5768. * sets the vsi->state __I40E_VSI_DOWN bit.
  5769. */
  5770. if (vsi->netdev) {
  5771. netif_carrier_off(vsi->netdev);
  5772. netif_tx_disable(vsi->netdev);
  5773. }
  5774. i40e_vsi_disable_irq(vsi);
  5775. i40e_vsi_stop_rings(vsi);
  5776. if (vsi->type == I40E_VSI_MAIN &&
  5777. vsi->back->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED)
  5778. i40e_force_link_state(vsi->back, false);
  5779. i40e_napi_disable_all(vsi);
  5780. for (i = 0; i < vsi->num_queue_pairs; i++) {
  5781. i40e_clean_tx_ring(vsi->tx_rings[i]);
  5782. if (i40e_enabled_xdp_vsi(vsi))
  5783. i40e_clean_tx_ring(vsi->xdp_rings[i]);
  5784. i40e_clean_rx_ring(vsi->rx_rings[i]);
  5785. }
  5786. }
  5787. /**
  5788. * i40e_validate_mqprio_qopt- validate queue mapping info
  5789. * @vsi: the VSI being configured
  5790. * @mqprio_qopt: queue parametrs
  5791. **/
  5792. static int i40e_validate_mqprio_qopt(struct i40e_vsi *vsi,
  5793. struct tc_mqprio_qopt_offload *mqprio_qopt)
  5794. {
  5795. u64 sum_max_rate = 0;
  5796. u64 max_rate = 0;
  5797. int i;
  5798. if (mqprio_qopt->qopt.offset[0] != 0 ||
  5799. mqprio_qopt->qopt.num_tc < 1 ||
  5800. mqprio_qopt->qopt.num_tc > I40E_MAX_TRAFFIC_CLASS)
  5801. return -EINVAL;
  5802. for (i = 0; ; i++) {
  5803. if (!mqprio_qopt->qopt.count[i])
  5804. return -EINVAL;
  5805. if (mqprio_qopt->min_rate[i]) {
  5806. dev_err(&vsi->back->pdev->dev,
  5807. "Invalid min tx rate (greater than 0) specified\n");
  5808. return -EINVAL;
  5809. }
  5810. max_rate = mqprio_qopt->max_rate[i];
  5811. do_div(max_rate, I40E_BW_MBPS_DIVISOR);
  5812. sum_max_rate += max_rate;
  5813. if (i >= mqprio_qopt->qopt.num_tc - 1)
  5814. break;
  5815. if (mqprio_qopt->qopt.offset[i + 1] !=
  5816. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
  5817. return -EINVAL;
  5818. }
  5819. if (vsi->num_queue_pairs <
  5820. (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) {
  5821. return -EINVAL;
  5822. }
  5823. if (sum_max_rate > i40e_get_link_speed(vsi)) {
  5824. dev_err(&vsi->back->pdev->dev,
  5825. "Invalid max tx rate specified\n");
  5826. return -EINVAL;
  5827. }
  5828. return 0;
  5829. }
  5830. /**
  5831. * i40e_vsi_set_default_tc_config - set default values for tc configuration
  5832. * @vsi: the VSI being configured
  5833. **/
  5834. static void i40e_vsi_set_default_tc_config(struct i40e_vsi *vsi)
  5835. {
  5836. u16 qcount;
  5837. int i;
  5838. /* Only TC0 is enabled */
  5839. vsi->tc_config.numtc = 1;
  5840. vsi->tc_config.enabled_tc = 1;
  5841. qcount = min_t(int, vsi->alloc_queue_pairs,
  5842. i40e_pf_get_max_q_per_tc(vsi->back));
  5843. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  5844. /* For the TC that is not enabled set the offset to to default
  5845. * queue and allocate one queue for the given TC.
  5846. */
  5847. vsi->tc_config.tc_info[i].qoffset = 0;
  5848. if (i == 0)
  5849. vsi->tc_config.tc_info[i].qcount = qcount;
  5850. else
  5851. vsi->tc_config.tc_info[i].qcount = 1;
  5852. vsi->tc_config.tc_info[i].netdev_tc = 0;
  5853. }
  5854. }
  5855. /**
  5856. * i40e_setup_tc - configure multiple traffic classes
  5857. * @netdev: net device to configure
  5858. * @type_data: tc offload data
  5859. **/
  5860. static int i40e_setup_tc(struct net_device *netdev, void *type_data)
  5861. {
  5862. struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
  5863. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5864. struct i40e_vsi *vsi = np->vsi;
  5865. struct i40e_pf *pf = vsi->back;
  5866. u8 enabled_tc = 0, num_tc, hw;
  5867. bool need_reset = false;
  5868. int ret = -EINVAL;
  5869. u16 mode;
  5870. int i;
  5871. num_tc = mqprio_qopt->qopt.num_tc;
  5872. hw = mqprio_qopt->qopt.hw;
  5873. mode = mqprio_qopt->mode;
  5874. if (!hw) {
  5875. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5876. memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
  5877. goto config_tc;
  5878. }
  5879. /* Check if MFP enabled */
  5880. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5881. netdev_info(netdev,
  5882. "Configuring TC not supported in MFP mode\n");
  5883. return ret;
  5884. }
  5885. switch (mode) {
  5886. case TC_MQPRIO_MODE_DCB:
  5887. pf->flags &= ~I40E_FLAG_TC_MQPRIO;
  5888. /* Check if DCB enabled to continue */
  5889. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  5890. netdev_info(netdev,
  5891. "DCB is not enabled for adapter\n");
  5892. return ret;
  5893. }
  5894. /* Check whether tc count is within enabled limit */
  5895. if (num_tc > i40e_pf_get_num_tc(pf)) {
  5896. netdev_info(netdev,
  5897. "TC count greater than enabled on link for adapter\n");
  5898. return ret;
  5899. }
  5900. break;
  5901. case TC_MQPRIO_MODE_CHANNEL:
  5902. if (pf->flags & I40E_FLAG_DCB_ENABLED) {
  5903. netdev_info(netdev,
  5904. "Full offload of TC Mqprio options is not supported when DCB is enabled\n");
  5905. return ret;
  5906. }
  5907. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5908. return ret;
  5909. ret = i40e_validate_mqprio_qopt(vsi, mqprio_qopt);
  5910. if (ret)
  5911. return ret;
  5912. memcpy(&vsi->mqprio_qopt, mqprio_qopt,
  5913. sizeof(*mqprio_qopt));
  5914. pf->flags |= I40E_FLAG_TC_MQPRIO;
  5915. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5916. break;
  5917. default:
  5918. return -EINVAL;
  5919. }
  5920. config_tc:
  5921. /* Generate TC map for number of tc requested */
  5922. for (i = 0; i < num_tc; i++)
  5923. enabled_tc |= BIT(i);
  5924. /* Requesting same TC configuration as already enabled */
  5925. if (enabled_tc == vsi->tc_config.enabled_tc &&
  5926. mode != TC_MQPRIO_MODE_CHANNEL)
  5927. return 0;
  5928. /* Quiesce VSI queues */
  5929. i40e_quiesce_vsi(vsi);
  5930. if (!hw && !(pf->flags & I40E_FLAG_TC_MQPRIO))
  5931. i40e_remove_queue_channels(vsi);
  5932. /* Configure VSI for enabled TCs */
  5933. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  5934. if (ret) {
  5935. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  5936. vsi->seid);
  5937. need_reset = true;
  5938. goto exit;
  5939. }
  5940. if (pf->flags & I40E_FLAG_TC_MQPRIO) {
  5941. if (vsi->mqprio_qopt.max_rate[0]) {
  5942. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  5943. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  5944. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  5945. if (!ret) {
  5946. u64 credits = max_tx_rate;
  5947. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  5948. dev_dbg(&vsi->back->pdev->dev,
  5949. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  5950. max_tx_rate,
  5951. credits,
  5952. vsi->seid);
  5953. } else {
  5954. need_reset = true;
  5955. goto exit;
  5956. }
  5957. }
  5958. ret = i40e_configure_queue_channels(vsi);
  5959. if (ret) {
  5960. netdev_info(netdev,
  5961. "Failed configuring queue channels\n");
  5962. need_reset = true;
  5963. goto exit;
  5964. }
  5965. }
  5966. exit:
  5967. /* Reset the configuration data to defaults, only TC0 is enabled */
  5968. if (need_reset) {
  5969. i40e_vsi_set_default_tc_config(vsi);
  5970. need_reset = false;
  5971. }
  5972. /* Unquiesce VSI */
  5973. i40e_unquiesce_vsi(vsi);
  5974. return ret;
  5975. }
  5976. /**
  5977. * i40e_set_cld_element - sets cloud filter element data
  5978. * @filter: cloud filter rule
  5979. * @cld: ptr to cloud filter element data
  5980. *
  5981. * This is helper function to copy data into cloud filter element
  5982. **/
  5983. static inline void
  5984. i40e_set_cld_element(struct i40e_cloud_filter *filter,
  5985. struct i40e_aqc_cloud_filters_element_data *cld)
  5986. {
  5987. int i, j;
  5988. u32 ipa;
  5989. memset(cld, 0, sizeof(*cld));
  5990. ether_addr_copy(cld->outer_mac, filter->dst_mac);
  5991. ether_addr_copy(cld->inner_mac, filter->src_mac);
  5992. if (filter->n_proto != ETH_P_IP && filter->n_proto != ETH_P_IPV6)
  5993. return;
  5994. if (filter->n_proto == ETH_P_IPV6) {
  5995. #define IPV6_MAX_INDEX (ARRAY_SIZE(filter->dst_ipv6) - 1)
  5996. for (i = 0, j = 0; i < ARRAY_SIZE(filter->dst_ipv6);
  5997. i++, j += 2) {
  5998. ipa = be32_to_cpu(filter->dst_ipv6[IPV6_MAX_INDEX - i]);
  5999. ipa = cpu_to_le32(ipa);
  6000. memcpy(&cld->ipaddr.raw_v6.data[j], &ipa, sizeof(ipa));
  6001. }
  6002. } else {
  6003. ipa = be32_to_cpu(filter->dst_ipv4);
  6004. memcpy(&cld->ipaddr.v4.data, &ipa, sizeof(ipa));
  6005. }
  6006. cld->inner_vlan = cpu_to_le16(ntohs(filter->vlan_id));
  6007. /* tenant_id is not supported by FW now, once the support is enabled
  6008. * fill the cld->tenant_id with cpu_to_le32(filter->tenant_id)
  6009. */
  6010. if (filter->tenant_id)
  6011. return;
  6012. }
  6013. /**
  6014. * i40e_add_del_cloud_filter - Add/del cloud filter
  6015. * @vsi: pointer to VSI
  6016. * @filter: cloud filter rule
  6017. * @add: if true, add, if false, delete
  6018. *
  6019. * Add or delete a cloud filter for a specific flow spec.
  6020. * Returns 0 if the filter were successfully added.
  6021. **/
  6022. int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
  6023. struct i40e_cloud_filter *filter, bool add)
  6024. {
  6025. struct i40e_aqc_cloud_filters_element_data cld_filter;
  6026. struct i40e_pf *pf = vsi->back;
  6027. int ret;
  6028. static const u16 flag_table[128] = {
  6029. [I40E_CLOUD_FILTER_FLAGS_OMAC] =
  6030. I40E_AQC_ADD_CLOUD_FILTER_OMAC,
  6031. [I40E_CLOUD_FILTER_FLAGS_IMAC] =
  6032. I40E_AQC_ADD_CLOUD_FILTER_IMAC,
  6033. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN] =
  6034. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN,
  6035. [I40E_CLOUD_FILTER_FLAGS_IMAC_TEN_ID] =
  6036. I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID,
  6037. [I40E_CLOUD_FILTER_FLAGS_OMAC_TEN_ID_IMAC] =
  6038. I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC,
  6039. [I40E_CLOUD_FILTER_FLAGS_IMAC_IVLAN_TEN_ID] =
  6040. I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID,
  6041. [I40E_CLOUD_FILTER_FLAGS_IIP] =
  6042. I40E_AQC_ADD_CLOUD_FILTER_IIP,
  6043. };
  6044. if (filter->flags >= ARRAY_SIZE(flag_table))
  6045. return I40E_ERR_CONFIG;
  6046. /* copy element needed to add cloud filter from filter */
  6047. i40e_set_cld_element(filter, &cld_filter);
  6048. if (filter->tunnel_type != I40E_CLOUD_TNL_TYPE_NONE)
  6049. cld_filter.flags = cpu_to_le16(filter->tunnel_type <<
  6050. I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
  6051. if (filter->n_proto == ETH_P_IPV6)
  6052. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6053. I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6054. else
  6055. cld_filter.flags |= cpu_to_le16(flag_table[filter->flags] |
  6056. I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6057. if (add)
  6058. ret = i40e_aq_add_cloud_filters(&pf->hw, filter->seid,
  6059. &cld_filter, 1);
  6060. else
  6061. ret = i40e_aq_rem_cloud_filters(&pf->hw, filter->seid,
  6062. &cld_filter, 1);
  6063. if (ret)
  6064. dev_dbg(&pf->pdev->dev,
  6065. "Failed to %s cloud filter using l4 port %u, err %d aq_err %d\n",
  6066. add ? "add" : "delete", filter->dst_port, ret,
  6067. pf->hw.aq.asq_last_status);
  6068. else
  6069. dev_info(&pf->pdev->dev,
  6070. "%s cloud filter for VSI: %d\n",
  6071. add ? "Added" : "Deleted", filter->seid);
  6072. return ret;
  6073. }
  6074. /**
  6075. * i40e_add_del_cloud_filter_big_buf - Add/del cloud filter using big_buf
  6076. * @vsi: pointer to VSI
  6077. * @filter: cloud filter rule
  6078. * @add: if true, add, if false, delete
  6079. *
  6080. * Add or delete a cloud filter for a specific flow spec using big buffer.
  6081. * Returns 0 if the filter were successfully added.
  6082. **/
  6083. int i40e_add_del_cloud_filter_big_buf(struct i40e_vsi *vsi,
  6084. struct i40e_cloud_filter *filter,
  6085. bool add)
  6086. {
  6087. struct i40e_aqc_cloud_filters_element_bb cld_filter;
  6088. struct i40e_pf *pf = vsi->back;
  6089. int ret;
  6090. /* Both (src/dst) valid mac_addr are not supported */
  6091. if ((is_valid_ether_addr(filter->dst_mac) &&
  6092. is_valid_ether_addr(filter->src_mac)) ||
  6093. (is_multicast_ether_addr(filter->dst_mac) &&
  6094. is_multicast_ether_addr(filter->src_mac)))
  6095. return -EOPNOTSUPP;
  6096. /* Big buffer cloud filter needs 'L4 port' to be non-zero. Also, UDP
  6097. * ports are not supported via big buffer now.
  6098. */
  6099. if (!filter->dst_port || filter->ip_proto == IPPROTO_UDP)
  6100. return -EOPNOTSUPP;
  6101. /* adding filter using src_port/src_ip is not supported at this stage */
  6102. if (filter->src_port || filter->src_ipv4 ||
  6103. !ipv6_addr_any(&filter->ip.v6.src_ip6))
  6104. return -EOPNOTSUPP;
  6105. /* copy element needed to add cloud filter from filter */
  6106. i40e_set_cld_element(filter, &cld_filter.element);
  6107. if (is_valid_ether_addr(filter->dst_mac) ||
  6108. is_valid_ether_addr(filter->src_mac) ||
  6109. is_multicast_ether_addr(filter->dst_mac) ||
  6110. is_multicast_ether_addr(filter->src_mac)) {
  6111. /* MAC + IP : unsupported mode */
  6112. if (filter->dst_ipv4)
  6113. return -EOPNOTSUPP;
  6114. /* since we validated that L4 port must be valid before
  6115. * we get here, start with respective "flags" value
  6116. * and update if vlan is present or not
  6117. */
  6118. cld_filter.element.flags =
  6119. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_PORT);
  6120. if (filter->vlan_id) {
  6121. cld_filter.element.flags =
  6122. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_MAC_VLAN_PORT);
  6123. }
  6124. } else if (filter->dst_ipv4 ||
  6125. !ipv6_addr_any(&filter->ip.v6.dst_ip6)) {
  6126. cld_filter.element.flags =
  6127. cpu_to_le16(I40E_AQC_ADD_CLOUD_FILTER_IP_PORT);
  6128. if (filter->n_proto == ETH_P_IPV6)
  6129. cld_filter.element.flags |=
  6130. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV6);
  6131. else
  6132. cld_filter.element.flags |=
  6133. cpu_to_le16(I40E_AQC_ADD_CLOUD_FLAGS_IPV4);
  6134. } else {
  6135. dev_err(&pf->pdev->dev,
  6136. "either mac or ip has to be valid for cloud filter\n");
  6137. return -EINVAL;
  6138. }
  6139. /* Now copy L4 port in Byte 6..7 in general fields */
  6140. cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X16_WORD0] =
  6141. be16_to_cpu(filter->dst_port);
  6142. if (add) {
  6143. /* Validate current device switch mode, change if necessary */
  6144. ret = i40e_validate_and_set_switch_mode(vsi);
  6145. if (ret) {
  6146. dev_err(&pf->pdev->dev,
  6147. "failed to set switch mode, ret %d\n",
  6148. ret);
  6149. return ret;
  6150. }
  6151. ret = i40e_aq_add_cloud_filters_bb(&pf->hw, filter->seid,
  6152. &cld_filter, 1);
  6153. } else {
  6154. ret = i40e_aq_rem_cloud_filters_bb(&pf->hw, filter->seid,
  6155. &cld_filter, 1);
  6156. }
  6157. if (ret)
  6158. dev_dbg(&pf->pdev->dev,
  6159. "Failed to %s cloud filter(big buffer) err %d aq_err %d\n",
  6160. add ? "add" : "delete", ret, pf->hw.aq.asq_last_status);
  6161. else
  6162. dev_info(&pf->pdev->dev,
  6163. "%s cloud filter for VSI: %d, L4 port: %d\n",
  6164. add ? "add" : "delete", filter->seid,
  6165. ntohs(filter->dst_port));
  6166. return ret;
  6167. }
  6168. /**
  6169. * i40e_parse_cls_flower - Parse tc flower filters provided by kernel
  6170. * @vsi: Pointer to VSI
  6171. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6172. * @filter: Pointer to cloud filter structure
  6173. *
  6174. **/
  6175. static int i40e_parse_cls_flower(struct i40e_vsi *vsi,
  6176. struct tc_cls_flower_offload *f,
  6177. struct i40e_cloud_filter *filter)
  6178. {
  6179. u16 n_proto_mask = 0, n_proto_key = 0, addr_type = 0;
  6180. struct i40e_pf *pf = vsi->back;
  6181. u8 field_flags = 0;
  6182. if (f->dissector->used_keys &
  6183. ~(BIT(FLOW_DISSECTOR_KEY_CONTROL) |
  6184. BIT(FLOW_DISSECTOR_KEY_BASIC) |
  6185. BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
  6186. BIT(FLOW_DISSECTOR_KEY_VLAN) |
  6187. BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
  6188. BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
  6189. BIT(FLOW_DISSECTOR_KEY_PORTS) |
  6190. BIT(FLOW_DISSECTOR_KEY_ENC_KEYID))) {
  6191. dev_err(&pf->pdev->dev, "Unsupported key used: 0x%x\n",
  6192. f->dissector->used_keys);
  6193. return -EOPNOTSUPP;
  6194. }
  6195. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
  6196. struct flow_dissector_key_keyid *key =
  6197. skb_flow_dissector_target(f->dissector,
  6198. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6199. f->key);
  6200. struct flow_dissector_key_keyid *mask =
  6201. skb_flow_dissector_target(f->dissector,
  6202. FLOW_DISSECTOR_KEY_ENC_KEYID,
  6203. f->mask);
  6204. if (mask->keyid != 0)
  6205. field_flags |= I40E_CLOUD_FIELD_TEN_ID;
  6206. filter->tenant_id = be32_to_cpu(key->keyid);
  6207. }
  6208. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
  6209. struct flow_dissector_key_basic *key =
  6210. skb_flow_dissector_target(f->dissector,
  6211. FLOW_DISSECTOR_KEY_BASIC,
  6212. f->key);
  6213. struct flow_dissector_key_basic *mask =
  6214. skb_flow_dissector_target(f->dissector,
  6215. FLOW_DISSECTOR_KEY_BASIC,
  6216. f->mask);
  6217. n_proto_key = ntohs(key->n_proto);
  6218. n_proto_mask = ntohs(mask->n_proto);
  6219. if (n_proto_key == ETH_P_ALL) {
  6220. n_proto_key = 0;
  6221. n_proto_mask = 0;
  6222. }
  6223. filter->n_proto = n_proto_key & n_proto_mask;
  6224. filter->ip_proto = key->ip_proto;
  6225. }
  6226. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
  6227. struct flow_dissector_key_eth_addrs *key =
  6228. skb_flow_dissector_target(f->dissector,
  6229. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6230. f->key);
  6231. struct flow_dissector_key_eth_addrs *mask =
  6232. skb_flow_dissector_target(f->dissector,
  6233. FLOW_DISSECTOR_KEY_ETH_ADDRS,
  6234. f->mask);
  6235. /* use is_broadcast and is_zero to check for all 0xf or 0 */
  6236. if (!is_zero_ether_addr(mask->dst)) {
  6237. if (is_broadcast_ether_addr(mask->dst)) {
  6238. field_flags |= I40E_CLOUD_FIELD_OMAC;
  6239. } else {
  6240. dev_err(&pf->pdev->dev, "Bad ether dest mask %pM\n",
  6241. mask->dst);
  6242. return I40E_ERR_CONFIG;
  6243. }
  6244. }
  6245. if (!is_zero_ether_addr(mask->src)) {
  6246. if (is_broadcast_ether_addr(mask->src)) {
  6247. field_flags |= I40E_CLOUD_FIELD_IMAC;
  6248. } else {
  6249. dev_err(&pf->pdev->dev, "Bad ether src mask %pM\n",
  6250. mask->src);
  6251. return I40E_ERR_CONFIG;
  6252. }
  6253. }
  6254. ether_addr_copy(filter->dst_mac, key->dst);
  6255. ether_addr_copy(filter->src_mac, key->src);
  6256. }
  6257. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
  6258. struct flow_dissector_key_vlan *key =
  6259. skb_flow_dissector_target(f->dissector,
  6260. FLOW_DISSECTOR_KEY_VLAN,
  6261. f->key);
  6262. struct flow_dissector_key_vlan *mask =
  6263. skb_flow_dissector_target(f->dissector,
  6264. FLOW_DISSECTOR_KEY_VLAN,
  6265. f->mask);
  6266. if (mask->vlan_id) {
  6267. if (mask->vlan_id == VLAN_VID_MASK) {
  6268. field_flags |= I40E_CLOUD_FIELD_IVLAN;
  6269. } else {
  6270. dev_err(&pf->pdev->dev, "Bad vlan mask 0x%04x\n",
  6271. mask->vlan_id);
  6272. return I40E_ERR_CONFIG;
  6273. }
  6274. }
  6275. filter->vlan_id = cpu_to_be16(key->vlan_id);
  6276. }
  6277. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
  6278. struct flow_dissector_key_control *key =
  6279. skb_flow_dissector_target(f->dissector,
  6280. FLOW_DISSECTOR_KEY_CONTROL,
  6281. f->key);
  6282. addr_type = key->addr_type;
  6283. }
  6284. if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
  6285. struct flow_dissector_key_ipv4_addrs *key =
  6286. skb_flow_dissector_target(f->dissector,
  6287. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6288. f->key);
  6289. struct flow_dissector_key_ipv4_addrs *mask =
  6290. skb_flow_dissector_target(f->dissector,
  6291. FLOW_DISSECTOR_KEY_IPV4_ADDRS,
  6292. f->mask);
  6293. if (mask->dst) {
  6294. if (mask->dst == cpu_to_be32(0xffffffff)) {
  6295. field_flags |= I40E_CLOUD_FIELD_IIP;
  6296. } else {
  6297. mask->dst = be32_to_cpu(mask->dst);
  6298. dev_err(&pf->pdev->dev, "Bad ip dst mask %pI4\n",
  6299. &mask->dst);
  6300. return I40E_ERR_CONFIG;
  6301. }
  6302. }
  6303. if (mask->src) {
  6304. if (mask->src == cpu_to_be32(0xffffffff)) {
  6305. field_flags |= I40E_CLOUD_FIELD_IIP;
  6306. } else {
  6307. mask->src = be32_to_cpu(mask->src);
  6308. dev_err(&pf->pdev->dev, "Bad ip src mask %pI4\n",
  6309. &mask->src);
  6310. return I40E_ERR_CONFIG;
  6311. }
  6312. }
  6313. if (field_flags & I40E_CLOUD_FIELD_TEN_ID) {
  6314. dev_err(&pf->pdev->dev, "Tenant id not allowed for ip filter\n");
  6315. return I40E_ERR_CONFIG;
  6316. }
  6317. filter->dst_ipv4 = key->dst;
  6318. filter->src_ipv4 = key->src;
  6319. }
  6320. if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
  6321. struct flow_dissector_key_ipv6_addrs *key =
  6322. skb_flow_dissector_target(f->dissector,
  6323. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6324. f->key);
  6325. struct flow_dissector_key_ipv6_addrs *mask =
  6326. skb_flow_dissector_target(f->dissector,
  6327. FLOW_DISSECTOR_KEY_IPV6_ADDRS,
  6328. f->mask);
  6329. /* src and dest IPV6 address should not be LOOPBACK
  6330. * (0:0:0:0:0:0:0:1), which can be represented as ::1
  6331. */
  6332. if (ipv6_addr_loopback(&key->dst) ||
  6333. ipv6_addr_loopback(&key->src)) {
  6334. dev_err(&pf->pdev->dev,
  6335. "Bad ipv6, addr is LOOPBACK\n");
  6336. return I40E_ERR_CONFIG;
  6337. }
  6338. if (!ipv6_addr_any(&mask->dst) || !ipv6_addr_any(&mask->src))
  6339. field_flags |= I40E_CLOUD_FIELD_IIP;
  6340. memcpy(&filter->src_ipv6, &key->src.s6_addr32,
  6341. sizeof(filter->src_ipv6));
  6342. memcpy(&filter->dst_ipv6, &key->dst.s6_addr32,
  6343. sizeof(filter->dst_ipv6));
  6344. }
  6345. if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_PORTS)) {
  6346. struct flow_dissector_key_ports *key =
  6347. skb_flow_dissector_target(f->dissector,
  6348. FLOW_DISSECTOR_KEY_PORTS,
  6349. f->key);
  6350. struct flow_dissector_key_ports *mask =
  6351. skb_flow_dissector_target(f->dissector,
  6352. FLOW_DISSECTOR_KEY_PORTS,
  6353. f->mask);
  6354. if (mask->src) {
  6355. if (mask->src == cpu_to_be16(0xffff)) {
  6356. field_flags |= I40E_CLOUD_FIELD_IIP;
  6357. } else {
  6358. dev_err(&pf->pdev->dev, "Bad src port mask 0x%04x\n",
  6359. be16_to_cpu(mask->src));
  6360. return I40E_ERR_CONFIG;
  6361. }
  6362. }
  6363. if (mask->dst) {
  6364. if (mask->dst == cpu_to_be16(0xffff)) {
  6365. field_flags |= I40E_CLOUD_FIELD_IIP;
  6366. } else {
  6367. dev_err(&pf->pdev->dev, "Bad dst port mask 0x%04x\n",
  6368. be16_to_cpu(mask->dst));
  6369. return I40E_ERR_CONFIG;
  6370. }
  6371. }
  6372. filter->dst_port = key->dst;
  6373. filter->src_port = key->src;
  6374. switch (filter->ip_proto) {
  6375. case IPPROTO_TCP:
  6376. case IPPROTO_UDP:
  6377. break;
  6378. default:
  6379. dev_err(&pf->pdev->dev,
  6380. "Only UDP and TCP transport are supported\n");
  6381. return -EINVAL;
  6382. }
  6383. }
  6384. filter->flags = field_flags;
  6385. return 0;
  6386. }
  6387. /**
  6388. * i40e_handle_tclass: Forward to a traffic class on the device
  6389. * @vsi: Pointer to VSI
  6390. * @tc: traffic class index on the device
  6391. * @filter: Pointer to cloud filter structure
  6392. *
  6393. **/
  6394. static int i40e_handle_tclass(struct i40e_vsi *vsi, u32 tc,
  6395. struct i40e_cloud_filter *filter)
  6396. {
  6397. struct i40e_channel *ch, *ch_tmp;
  6398. /* direct to a traffic class on the same device */
  6399. if (tc == 0) {
  6400. filter->seid = vsi->seid;
  6401. return 0;
  6402. } else if (vsi->tc_config.enabled_tc & BIT(tc)) {
  6403. if (!filter->dst_port) {
  6404. dev_err(&vsi->back->pdev->dev,
  6405. "Specify destination port to direct to traffic class that is not default\n");
  6406. return -EINVAL;
  6407. }
  6408. if (list_empty(&vsi->ch_list))
  6409. return -EINVAL;
  6410. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list,
  6411. list) {
  6412. if (ch->seid == vsi->tc_seid_map[tc])
  6413. filter->seid = ch->seid;
  6414. }
  6415. return 0;
  6416. }
  6417. dev_err(&vsi->back->pdev->dev, "TC is not enabled\n");
  6418. return -EINVAL;
  6419. }
  6420. /**
  6421. * i40e_configure_clsflower - Configure tc flower filters
  6422. * @vsi: Pointer to VSI
  6423. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6424. *
  6425. **/
  6426. static int i40e_configure_clsflower(struct i40e_vsi *vsi,
  6427. struct tc_cls_flower_offload *cls_flower)
  6428. {
  6429. int tc = tc_classid_to_hwtc(vsi->netdev, cls_flower->classid);
  6430. struct i40e_cloud_filter *filter = NULL;
  6431. struct i40e_pf *pf = vsi->back;
  6432. int err = 0;
  6433. if (tc < 0) {
  6434. dev_err(&vsi->back->pdev->dev, "Invalid traffic class\n");
  6435. return -EOPNOTSUPP;
  6436. }
  6437. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
  6438. test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
  6439. return -EBUSY;
  6440. if (pf->fdir_pf_active_filters ||
  6441. (!hlist_empty(&pf->fdir_filter_list))) {
  6442. dev_err(&vsi->back->pdev->dev,
  6443. "Flow Director Sideband filters exists, turn ntuple off to configure cloud filters\n");
  6444. return -EINVAL;
  6445. }
  6446. if (vsi->back->flags & I40E_FLAG_FD_SB_ENABLED) {
  6447. dev_err(&vsi->back->pdev->dev,
  6448. "Disable Flow Director Sideband, configuring Cloud filters via tc-flower\n");
  6449. vsi->back->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6450. vsi->back->flags |= I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6451. }
  6452. filter = kzalloc(sizeof(*filter), GFP_KERNEL);
  6453. if (!filter)
  6454. return -ENOMEM;
  6455. filter->cookie = cls_flower->cookie;
  6456. err = i40e_parse_cls_flower(vsi, cls_flower, filter);
  6457. if (err < 0)
  6458. goto err;
  6459. err = i40e_handle_tclass(vsi, tc, filter);
  6460. if (err < 0)
  6461. goto err;
  6462. /* Add cloud filter */
  6463. if (filter->dst_port)
  6464. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, true);
  6465. else
  6466. err = i40e_add_del_cloud_filter(vsi, filter, true);
  6467. if (err) {
  6468. dev_err(&pf->pdev->dev,
  6469. "Failed to add cloud filter, err %s\n",
  6470. i40e_stat_str(&pf->hw, err));
  6471. goto err;
  6472. }
  6473. /* add filter to the ordered list */
  6474. INIT_HLIST_NODE(&filter->cloud_node);
  6475. hlist_add_head(&filter->cloud_node, &pf->cloud_filter_list);
  6476. pf->num_cloud_filters++;
  6477. return err;
  6478. err:
  6479. kfree(filter);
  6480. return err;
  6481. }
  6482. /**
  6483. * i40e_find_cloud_filter - Find the could filter in the list
  6484. * @vsi: Pointer to VSI
  6485. * @cookie: filter specific cookie
  6486. *
  6487. **/
  6488. static struct i40e_cloud_filter *i40e_find_cloud_filter(struct i40e_vsi *vsi,
  6489. unsigned long *cookie)
  6490. {
  6491. struct i40e_cloud_filter *filter = NULL;
  6492. struct hlist_node *node2;
  6493. hlist_for_each_entry_safe(filter, node2,
  6494. &vsi->back->cloud_filter_list, cloud_node)
  6495. if (!memcmp(cookie, &filter->cookie, sizeof(filter->cookie)))
  6496. return filter;
  6497. return NULL;
  6498. }
  6499. /**
  6500. * i40e_delete_clsflower - Remove tc flower filters
  6501. * @vsi: Pointer to VSI
  6502. * @cls_flower: Pointer to struct tc_cls_flower_offload
  6503. *
  6504. **/
  6505. static int i40e_delete_clsflower(struct i40e_vsi *vsi,
  6506. struct tc_cls_flower_offload *cls_flower)
  6507. {
  6508. struct i40e_cloud_filter *filter = NULL;
  6509. struct i40e_pf *pf = vsi->back;
  6510. int err = 0;
  6511. filter = i40e_find_cloud_filter(vsi, &cls_flower->cookie);
  6512. if (!filter)
  6513. return -EINVAL;
  6514. hash_del(&filter->cloud_node);
  6515. if (filter->dst_port)
  6516. err = i40e_add_del_cloud_filter_big_buf(vsi, filter, false);
  6517. else
  6518. err = i40e_add_del_cloud_filter(vsi, filter, false);
  6519. kfree(filter);
  6520. if (err) {
  6521. dev_err(&pf->pdev->dev,
  6522. "Failed to delete cloud filter, err %s\n",
  6523. i40e_stat_str(&pf->hw, err));
  6524. return i40e_aq_rc_to_posix(err, pf->hw.aq.asq_last_status);
  6525. }
  6526. pf->num_cloud_filters--;
  6527. if (!pf->num_cloud_filters)
  6528. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6529. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6530. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6531. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6532. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6533. }
  6534. return 0;
  6535. }
  6536. /**
  6537. * i40e_setup_tc_cls_flower - flower classifier offloads
  6538. * @netdev: net device to configure
  6539. * @type_data: offload data
  6540. **/
  6541. static int i40e_setup_tc_cls_flower(struct i40e_netdev_priv *np,
  6542. struct tc_cls_flower_offload *cls_flower)
  6543. {
  6544. struct i40e_vsi *vsi = np->vsi;
  6545. switch (cls_flower->command) {
  6546. case TC_CLSFLOWER_REPLACE:
  6547. return i40e_configure_clsflower(vsi, cls_flower);
  6548. case TC_CLSFLOWER_DESTROY:
  6549. return i40e_delete_clsflower(vsi, cls_flower);
  6550. case TC_CLSFLOWER_STATS:
  6551. return -EOPNOTSUPP;
  6552. default:
  6553. return -EINVAL;
  6554. }
  6555. }
  6556. static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  6557. void *cb_priv)
  6558. {
  6559. struct i40e_netdev_priv *np = cb_priv;
  6560. if (!tc_cls_can_offload_and_chain0(np->vsi->netdev, type_data))
  6561. return -EOPNOTSUPP;
  6562. switch (type) {
  6563. case TC_SETUP_CLSFLOWER:
  6564. return i40e_setup_tc_cls_flower(np, type_data);
  6565. default:
  6566. return -EOPNOTSUPP;
  6567. }
  6568. }
  6569. static int i40e_setup_tc_block(struct net_device *dev,
  6570. struct tc_block_offload *f)
  6571. {
  6572. struct i40e_netdev_priv *np = netdev_priv(dev);
  6573. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  6574. return -EOPNOTSUPP;
  6575. switch (f->command) {
  6576. case TC_BLOCK_BIND:
  6577. return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
  6578. np, np);
  6579. case TC_BLOCK_UNBIND:
  6580. tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
  6581. return 0;
  6582. default:
  6583. return -EOPNOTSUPP;
  6584. }
  6585. }
  6586. static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
  6587. void *type_data)
  6588. {
  6589. switch (type) {
  6590. case TC_SETUP_QDISC_MQPRIO:
  6591. return i40e_setup_tc(netdev, type_data);
  6592. case TC_SETUP_BLOCK:
  6593. return i40e_setup_tc_block(netdev, type_data);
  6594. default:
  6595. return -EOPNOTSUPP;
  6596. }
  6597. }
  6598. /**
  6599. * i40e_open - Called when a network interface is made active
  6600. * @netdev: network interface device structure
  6601. *
  6602. * The open entry point is called when a network interface is made
  6603. * active by the system (IFF_UP). At this point all resources needed
  6604. * for transmit and receive operations are allocated, the interrupt
  6605. * handler is registered with the OS, the netdev watchdog subtask is
  6606. * enabled, and the stack is notified that the interface is ready.
  6607. *
  6608. * Returns 0 on success, negative value on failure
  6609. **/
  6610. int i40e_open(struct net_device *netdev)
  6611. {
  6612. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6613. struct i40e_vsi *vsi = np->vsi;
  6614. struct i40e_pf *pf = vsi->back;
  6615. int err;
  6616. /* disallow open during test or if eeprom is broken */
  6617. if (test_bit(__I40E_TESTING, pf->state) ||
  6618. test_bit(__I40E_BAD_EEPROM, pf->state))
  6619. return -EBUSY;
  6620. netif_carrier_off(netdev);
  6621. if (i40e_force_link_state(pf, true))
  6622. return -EAGAIN;
  6623. err = i40e_vsi_open(vsi);
  6624. if (err)
  6625. return err;
  6626. /* configure global TSO hardware offload settings */
  6627. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  6628. TCP_FLAG_FIN) >> 16);
  6629. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  6630. TCP_FLAG_FIN |
  6631. TCP_FLAG_CWR) >> 16);
  6632. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  6633. udp_tunnel_get_rx_info(netdev);
  6634. return 0;
  6635. }
  6636. /**
  6637. * i40e_vsi_open -
  6638. * @vsi: the VSI to open
  6639. *
  6640. * Finish initialization of the VSI.
  6641. *
  6642. * Returns 0 on success, negative value on failure
  6643. *
  6644. * Note: expects to be called while under rtnl_lock()
  6645. **/
  6646. int i40e_vsi_open(struct i40e_vsi *vsi)
  6647. {
  6648. struct i40e_pf *pf = vsi->back;
  6649. char int_name[I40E_INT_NAME_STR_LEN];
  6650. int err;
  6651. /* allocate descriptors */
  6652. err = i40e_vsi_setup_tx_resources(vsi);
  6653. if (err)
  6654. goto err_setup_tx;
  6655. err = i40e_vsi_setup_rx_resources(vsi);
  6656. if (err)
  6657. goto err_setup_rx;
  6658. err = i40e_vsi_configure(vsi);
  6659. if (err)
  6660. goto err_setup_rx;
  6661. if (vsi->netdev) {
  6662. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  6663. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  6664. err = i40e_vsi_request_irq(vsi, int_name);
  6665. if (err)
  6666. goto err_setup_rx;
  6667. /* Notify the stack of the actual queue counts. */
  6668. err = netif_set_real_num_tx_queues(vsi->netdev,
  6669. vsi->num_queue_pairs);
  6670. if (err)
  6671. goto err_set_queues;
  6672. err = netif_set_real_num_rx_queues(vsi->netdev,
  6673. vsi->num_queue_pairs);
  6674. if (err)
  6675. goto err_set_queues;
  6676. } else if (vsi->type == I40E_VSI_FDIR) {
  6677. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  6678. dev_driver_string(&pf->pdev->dev),
  6679. dev_name(&pf->pdev->dev));
  6680. err = i40e_vsi_request_irq(vsi, int_name);
  6681. } else {
  6682. err = -EINVAL;
  6683. goto err_setup_rx;
  6684. }
  6685. err = i40e_up_complete(vsi);
  6686. if (err)
  6687. goto err_up_complete;
  6688. return 0;
  6689. err_up_complete:
  6690. i40e_down(vsi);
  6691. err_set_queues:
  6692. i40e_vsi_free_irq(vsi);
  6693. err_setup_rx:
  6694. i40e_vsi_free_rx_resources(vsi);
  6695. err_setup_tx:
  6696. i40e_vsi_free_tx_resources(vsi);
  6697. if (vsi == pf->vsi[pf->lan_vsi])
  6698. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  6699. return err;
  6700. }
  6701. /**
  6702. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  6703. * @pf: Pointer to PF
  6704. *
  6705. * This function destroys the hlist where all the Flow Director
  6706. * filters were saved.
  6707. **/
  6708. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  6709. {
  6710. struct i40e_fdir_filter *filter;
  6711. struct i40e_flex_pit *pit_entry, *tmp;
  6712. struct hlist_node *node2;
  6713. hlist_for_each_entry_safe(filter, node2,
  6714. &pf->fdir_filter_list, fdir_node) {
  6715. hlist_del(&filter->fdir_node);
  6716. kfree(filter);
  6717. }
  6718. list_for_each_entry_safe(pit_entry, tmp, &pf->l3_flex_pit_list, list) {
  6719. list_del(&pit_entry->list);
  6720. kfree(pit_entry);
  6721. }
  6722. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  6723. list_for_each_entry_safe(pit_entry, tmp, &pf->l4_flex_pit_list, list) {
  6724. list_del(&pit_entry->list);
  6725. kfree(pit_entry);
  6726. }
  6727. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  6728. pf->fdir_pf_active_filters = 0;
  6729. pf->fd_tcp4_filter_cnt = 0;
  6730. pf->fd_udp4_filter_cnt = 0;
  6731. pf->fd_sctp4_filter_cnt = 0;
  6732. pf->fd_ip4_filter_cnt = 0;
  6733. /* Reprogram the default input set for TCP/IPv4 */
  6734. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  6735. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6736. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6737. /* Reprogram the default input set for UDP/IPv4 */
  6738. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
  6739. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6740. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6741. /* Reprogram the default input set for SCTP/IPv4 */
  6742. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
  6743. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  6744. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  6745. /* Reprogram the default input set for Other/IPv4 */
  6746. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
  6747. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6748. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
  6749. I40E_L3_SRC_MASK | I40E_L3_DST_MASK);
  6750. }
  6751. /**
  6752. * i40e_cloud_filter_exit - Cleans up the cloud filters
  6753. * @pf: Pointer to PF
  6754. *
  6755. * This function destroys the hlist where all the cloud filters
  6756. * were saved.
  6757. **/
  6758. static void i40e_cloud_filter_exit(struct i40e_pf *pf)
  6759. {
  6760. struct i40e_cloud_filter *cfilter;
  6761. struct hlist_node *node;
  6762. hlist_for_each_entry_safe(cfilter, node,
  6763. &pf->cloud_filter_list, cloud_node) {
  6764. hlist_del(&cfilter->cloud_node);
  6765. kfree(cfilter);
  6766. }
  6767. pf->num_cloud_filters = 0;
  6768. if ((pf->flags & I40E_FLAG_FD_SB_TO_CLOUD_FILTER) &&
  6769. !(pf->flags & I40E_FLAG_FD_SB_INACTIVE)) {
  6770. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  6771. pf->flags &= ~I40E_FLAG_FD_SB_TO_CLOUD_FILTER;
  6772. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  6773. }
  6774. }
  6775. /**
  6776. * i40e_close - Disables a network interface
  6777. * @netdev: network interface device structure
  6778. *
  6779. * The close entry point is called when an interface is de-activated
  6780. * by the OS. The hardware is still under the driver's control, but
  6781. * this netdev interface is disabled.
  6782. *
  6783. * Returns 0, this is not allowed to fail
  6784. **/
  6785. int i40e_close(struct net_device *netdev)
  6786. {
  6787. struct i40e_netdev_priv *np = netdev_priv(netdev);
  6788. struct i40e_vsi *vsi = np->vsi;
  6789. i40e_vsi_close(vsi);
  6790. return 0;
  6791. }
  6792. /**
  6793. * i40e_do_reset - Start a PF or Core Reset sequence
  6794. * @pf: board private structure
  6795. * @reset_flags: which reset is requested
  6796. * @lock_acquired: indicates whether or not the lock has been acquired
  6797. * before this function was called.
  6798. *
  6799. * The essential difference in resets is that the PF Reset
  6800. * doesn't clear the packet buffers, doesn't reset the PE
  6801. * firmware, and doesn't bother the other PFs on the chip.
  6802. **/
  6803. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags, bool lock_acquired)
  6804. {
  6805. u32 val;
  6806. WARN_ON(in_interrupt());
  6807. /* do the biggest reset indicated */
  6808. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  6809. /* Request a Global Reset
  6810. *
  6811. * This will start the chip's countdown to the actual full
  6812. * chip reset event, and a warning interrupt to be sent
  6813. * to all PFs, including the requestor. Our handler
  6814. * for the warning interrupt will deal with the shutdown
  6815. * and recovery of the switch setup.
  6816. */
  6817. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  6818. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6819. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  6820. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6821. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  6822. /* Request a Core Reset
  6823. *
  6824. * Same as Global Reset, except does *not* include the MAC/PHY
  6825. */
  6826. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  6827. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  6828. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  6829. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  6830. i40e_flush(&pf->hw);
  6831. } else if (reset_flags & I40E_PF_RESET_FLAG) {
  6832. /* Request a PF Reset
  6833. *
  6834. * Resets only the PF-specific registers
  6835. *
  6836. * This goes directly to the tear-down and rebuild of
  6837. * the switch, since we need to do all the recovery as
  6838. * for the Core Reset.
  6839. */
  6840. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  6841. i40e_handle_reset_warning(pf, lock_acquired);
  6842. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  6843. int v;
  6844. /* Find the VSI(s) that requested a re-init */
  6845. dev_info(&pf->pdev->dev,
  6846. "VSI reinit requested\n");
  6847. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6848. struct i40e_vsi *vsi = pf->vsi[v];
  6849. if (vsi != NULL &&
  6850. test_and_clear_bit(__I40E_VSI_REINIT_REQUESTED,
  6851. vsi->state))
  6852. i40e_vsi_reinit_locked(pf->vsi[v]);
  6853. }
  6854. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  6855. int v;
  6856. /* Find the VSI(s) that needs to be brought down */
  6857. dev_info(&pf->pdev->dev, "VSI down requested\n");
  6858. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6859. struct i40e_vsi *vsi = pf->vsi[v];
  6860. if (vsi != NULL &&
  6861. test_and_clear_bit(__I40E_VSI_DOWN_REQUESTED,
  6862. vsi->state)) {
  6863. set_bit(__I40E_VSI_DOWN, vsi->state);
  6864. i40e_down(vsi);
  6865. }
  6866. }
  6867. } else {
  6868. dev_info(&pf->pdev->dev,
  6869. "bad reset request 0x%08x\n", reset_flags);
  6870. }
  6871. }
  6872. #ifdef CONFIG_I40E_DCB
  6873. /**
  6874. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  6875. * @pf: board private structure
  6876. * @old_cfg: current DCB config
  6877. * @new_cfg: new DCB config
  6878. **/
  6879. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  6880. struct i40e_dcbx_config *old_cfg,
  6881. struct i40e_dcbx_config *new_cfg)
  6882. {
  6883. bool need_reconfig = false;
  6884. /* Check if ETS configuration has changed */
  6885. if (memcmp(&new_cfg->etscfg,
  6886. &old_cfg->etscfg,
  6887. sizeof(new_cfg->etscfg))) {
  6888. /* If Priority Table has changed reconfig is needed */
  6889. if (memcmp(&new_cfg->etscfg.prioritytable,
  6890. &old_cfg->etscfg.prioritytable,
  6891. sizeof(new_cfg->etscfg.prioritytable))) {
  6892. need_reconfig = true;
  6893. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  6894. }
  6895. if (memcmp(&new_cfg->etscfg.tcbwtable,
  6896. &old_cfg->etscfg.tcbwtable,
  6897. sizeof(new_cfg->etscfg.tcbwtable)))
  6898. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  6899. if (memcmp(&new_cfg->etscfg.tsatable,
  6900. &old_cfg->etscfg.tsatable,
  6901. sizeof(new_cfg->etscfg.tsatable)))
  6902. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  6903. }
  6904. /* Check if PFC configuration has changed */
  6905. if (memcmp(&new_cfg->pfc,
  6906. &old_cfg->pfc,
  6907. sizeof(new_cfg->pfc))) {
  6908. need_reconfig = true;
  6909. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  6910. }
  6911. /* Check if APP Table has changed */
  6912. if (memcmp(&new_cfg->app,
  6913. &old_cfg->app,
  6914. sizeof(new_cfg->app))) {
  6915. need_reconfig = true;
  6916. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  6917. }
  6918. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  6919. return need_reconfig;
  6920. }
  6921. /**
  6922. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  6923. * @pf: board private structure
  6924. * @e: event info posted on ARQ
  6925. **/
  6926. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  6927. struct i40e_arq_event_info *e)
  6928. {
  6929. struct i40e_aqc_lldp_get_mib *mib =
  6930. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  6931. struct i40e_hw *hw = &pf->hw;
  6932. struct i40e_dcbx_config tmp_dcbx_cfg;
  6933. bool need_reconfig = false;
  6934. int ret = 0;
  6935. u8 type;
  6936. /* Not DCB capable or capability disabled */
  6937. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  6938. return ret;
  6939. /* Ignore if event is not for Nearest Bridge */
  6940. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  6941. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  6942. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  6943. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  6944. return ret;
  6945. /* Check MIB Type and return if event for Remote MIB update */
  6946. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  6947. dev_dbg(&pf->pdev->dev,
  6948. "LLDP event mib type %s\n", type ? "remote" : "local");
  6949. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  6950. /* Update the remote cached instance and return */
  6951. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  6952. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  6953. &hw->remote_dcbx_config);
  6954. goto exit;
  6955. }
  6956. /* Store the old configuration */
  6957. tmp_dcbx_cfg = hw->local_dcbx_config;
  6958. /* Reset the old DCBx configuration data */
  6959. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  6960. /* Get updated DCBX data from firmware */
  6961. ret = i40e_get_dcb_config(&pf->hw);
  6962. if (ret) {
  6963. dev_info(&pf->pdev->dev,
  6964. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  6965. i40e_stat_str(&pf->hw, ret),
  6966. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6967. goto exit;
  6968. }
  6969. /* No change detected in DCBX configs */
  6970. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  6971. sizeof(tmp_dcbx_cfg))) {
  6972. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  6973. goto exit;
  6974. }
  6975. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  6976. &hw->local_dcbx_config);
  6977. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  6978. if (!need_reconfig)
  6979. goto exit;
  6980. /* Enable DCB tagging only when more than one TC */
  6981. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  6982. pf->flags |= I40E_FLAG_DCB_ENABLED;
  6983. else
  6984. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6985. set_bit(__I40E_PORT_SUSPENDED, pf->state);
  6986. /* Reconfiguration needed quiesce all VSIs */
  6987. i40e_pf_quiesce_all_vsi(pf);
  6988. /* Changes in configuration update VEB/VSI */
  6989. i40e_dcb_reconfigure(pf);
  6990. ret = i40e_resume_port_tx(pf);
  6991. clear_bit(__I40E_PORT_SUSPENDED, pf->state);
  6992. /* In case of error no point in resuming VSIs */
  6993. if (ret)
  6994. goto exit;
  6995. /* Wait for the PF's queues to be disabled */
  6996. ret = i40e_pf_wait_queues_disabled(pf);
  6997. if (ret) {
  6998. /* Schedule PF reset to recover */
  6999. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7000. i40e_service_event_schedule(pf);
  7001. } else {
  7002. i40e_pf_unquiesce_all_vsi(pf);
  7003. set_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state);
  7004. set_bit(__I40E_CLIENT_L2_CHANGE, pf->state);
  7005. }
  7006. exit:
  7007. return ret;
  7008. }
  7009. #endif /* CONFIG_I40E_DCB */
  7010. /**
  7011. * i40e_do_reset_safe - Protected reset path for userland calls.
  7012. * @pf: board private structure
  7013. * @reset_flags: which reset is requested
  7014. *
  7015. **/
  7016. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  7017. {
  7018. rtnl_lock();
  7019. i40e_do_reset(pf, reset_flags, true);
  7020. rtnl_unlock();
  7021. }
  7022. /**
  7023. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  7024. * @pf: board private structure
  7025. * @e: event info posted on ARQ
  7026. *
  7027. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  7028. * and VF queues
  7029. **/
  7030. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  7031. struct i40e_arq_event_info *e)
  7032. {
  7033. struct i40e_aqc_lan_overflow *data =
  7034. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  7035. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  7036. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  7037. struct i40e_hw *hw = &pf->hw;
  7038. struct i40e_vf *vf;
  7039. u16 vf_id;
  7040. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  7041. queue, qtx_ctl);
  7042. /* Queue belongs to VF, find the VF and issue VF reset */
  7043. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  7044. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  7045. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  7046. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  7047. vf_id -= hw->func_caps.vf_base_id;
  7048. vf = &pf->vf[vf_id];
  7049. i40e_vc_notify_vf_reset(vf);
  7050. /* Allow VF to process pending reset notification */
  7051. msleep(20);
  7052. i40e_reset_vf(vf, false);
  7053. }
  7054. }
  7055. /**
  7056. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  7057. * @pf: board private structure
  7058. **/
  7059. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  7060. {
  7061. u32 val, fcnt_prog;
  7062. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7063. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  7064. return fcnt_prog;
  7065. }
  7066. /**
  7067. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  7068. * @pf: board private structure
  7069. **/
  7070. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  7071. {
  7072. u32 val, fcnt_prog;
  7073. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  7074. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  7075. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  7076. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  7077. return fcnt_prog;
  7078. }
  7079. /**
  7080. * i40e_get_global_fd_count - Get total FD filters programmed on device
  7081. * @pf: board private structure
  7082. **/
  7083. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  7084. {
  7085. u32 val, fcnt_prog;
  7086. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  7087. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  7088. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  7089. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  7090. return fcnt_prog;
  7091. }
  7092. /**
  7093. * i40e_reenable_fdir_sb - Restore FDir SB capability
  7094. * @pf: board private structure
  7095. **/
  7096. static void i40e_reenable_fdir_sb(struct i40e_pf *pf)
  7097. {
  7098. if (test_and_clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
  7099. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7100. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7101. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  7102. }
  7103. /**
  7104. * i40e_reenable_fdir_atr - Restore FDir ATR capability
  7105. * @pf: board private structure
  7106. **/
  7107. static void i40e_reenable_fdir_atr(struct i40e_pf *pf)
  7108. {
  7109. if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state)) {
  7110. /* ATR uses the same filtering logic as SB rules. It only
  7111. * functions properly if the input set mask is at the default
  7112. * settings. It is safe to restore the default input set
  7113. * because there are no active TCPv4 filter rules.
  7114. */
  7115. i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
  7116. I40E_L3_SRC_MASK | I40E_L3_DST_MASK |
  7117. I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
  7118. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7119. (I40E_DEBUG_FD & pf->hw.debug_mask))
  7120. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  7121. }
  7122. }
  7123. /**
  7124. * i40e_delete_invalid_filter - Delete an invalid FDIR filter
  7125. * @pf: board private structure
  7126. * @filter: FDir filter to remove
  7127. */
  7128. static void i40e_delete_invalid_filter(struct i40e_pf *pf,
  7129. struct i40e_fdir_filter *filter)
  7130. {
  7131. /* Update counters */
  7132. pf->fdir_pf_active_filters--;
  7133. pf->fd_inv = 0;
  7134. switch (filter->flow_type) {
  7135. case TCP_V4_FLOW:
  7136. pf->fd_tcp4_filter_cnt--;
  7137. break;
  7138. case UDP_V4_FLOW:
  7139. pf->fd_udp4_filter_cnt--;
  7140. break;
  7141. case SCTP_V4_FLOW:
  7142. pf->fd_sctp4_filter_cnt--;
  7143. break;
  7144. case IP_USER_FLOW:
  7145. switch (filter->ip4_proto) {
  7146. case IPPROTO_TCP:
  7147. pf->fd_tcp4_filter_cnt--;
  7148. break;
  7149. case IPPROTO_UDP:
  7150. pf->fd_udp4_filter_cnt--;
  7151. break;
  7152. case IPPROTO_SCTP:
  7153. pf->fd_sctp4_filter_cnt--;
  7154. break;
  7155. case IPPROTO_IP:
  7156. pf->fd_ip4_filter_cnt--;
  7157. break;
  7158. }
  7159. break;
  7160. }
  7161. /* Remove the filter from the list and free memory */
  7162. hlist_del(&filter->fdir_node);
  7163. kfree(filter);
  7164. }
  7165. /**
  7166. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  7167. * @pf: board private structure
  7168. **/
  7169. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  7170. {
  7171. struct i40e_fdir_filter *filter;
  7172. u32 fcnt_prog, fcnt_avail;
  7173. struct hlist_node *node;
  7174. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7175. return;
  7176. /* Check if we have enough room to re-enable FDir SB capability. */
  7177. fcnt_prog = i40e_get_global_fd_count(pf);
  7178. fcnt_avail = pf->fdir_pf_filter_count;
  7179. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  7180. (pf->fd_add_err == 0) ||
  7181. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt))
  7182. i40e_reenable_fdir_sb(pf);
  7183. /* We should wait for even more space before re-enabling ATR.
  7184. * Additionally, we cannot enable ATR as long as we still have TCP SB
  7185. * rules active.
  7186. */
  7187. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) &&
  7188. (pf->fd_tcp4_filter_cnt == 0))
  7189. i40e_reenable_fdir_atr(pf);
  7190. /* if hw had a problem adding a filter, delete it */
  7191. if (pf->fd_inv > 0) {
  7192. hlist_for_each_entry_safe(filter, node,
  7193. &pf->fdir_filter_list, fdir_node)
  7194. if (filter->fd_id == pf->fd_inv)
  7195. i40e_delete_invalid_filter(pf, filter);
  7196. }
  7197. }
  7198. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  7199. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  7200. /**
  7201. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  7202. * @pf: board private structure
  7203. **/
  7204. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  7205. {
  7206. unsigned long min_flush_time;
  7207. int flush_wait_retry = 50;
  7208. bool disable_atr = false;
  7209. int fd_room;
  7210. int reg;
  7211. if (!time_after(jiffies, pf->fd_flush_timestamp +
  7212. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  7213. return;
  7214. /* If the flush is happening too quick and we have mostly SB rules we
  7215. * should not re-enable ATR for some time.
  7216. */
  7217. min_flush_time = pf->fd_flush_timestamp +
  7218. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  7219. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  7220. if (!(time_after(jiffies, min_flush_time)) &&
  7221. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  7222. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7223. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  7224. disable_atr = true;
  7225. }
  7226. pf->fd_flush_timestamp = jiffies;
  7227. set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
  7228. /* flush all filters */
  7229. wr32(&pf->hw, I40E_PFQF_CTL_1,
  7230. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  7231. i40e_flush(&pf->hw);
  7232. pf->fd_flush_cnt++;
  7233. pf->fd_add_err = 0;
  7234. do {
  7235. /* Check FD flush status every 5-6msec */
  7236. usleep_range(5000, 6000);
  7237. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  7238. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  7239. break;
  7240. } while (flush_wait_retry--);
  7241. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  7242. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  7243. } else {
  7244. /* replay sideband filters */
  7245. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  7246. if (!disable_atr && !pf->fd_tcp4_filter_cnt)
  7247. clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
  7248. clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
  7249. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7250. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  7251. }
  7252. }
  7253. /**
  7254. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  7255. * @pf: board private structure
  7256. **/
  7257. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  7258. {
  7259. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  7260. }
  7261. /* We can see up to 256 filter programming desc in transit if the filters are
  7262. * being applied really fast; before we see the first
  7263. * filter miss error on Rx queue 0. Accumulating enough error messages before
  7264. * reacting will make sure we don't cause flush too often.
  7265. */
  7266. #define I40E_MAX_FD_PROGRAM_ERROR 256
  7267. /**
  7268. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  7269. * @pf: board private structure
  7270. **/
  7271. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  7272. {
  7273. /* if interface is down do nothing */
  7274. if (test_bit(__I40E_DOWN, pf->state))
  7275. return;
  7276. if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
  7277. i40e_fdir_flush_and_replay(pf);
  7278. i40e_fdir_check_and_reenable(pf);
  7279. }
  7280. /**
  7281. * i40e_vsi_link_event - notify VSI of a link event
  7282. * @vsi: vsi to be notified
  7283. * @link_up: link up or down
  7284. **/
  7285. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  7286. {
  7287. if (!vsi || test_bit(__I40E_VSI_DOWN, vsi->state))
  7288. return;
  7289. switch (vsi->type) {
  7290. case I40E_VSI_MAIN:
  7291. if (!vsi->netdev || !vsi->netdev_registered)
  7292. break;
  7293. if (link_up) {
  7294. netif_carrier_on(vsi->netdev);
  7295. netif_tx_wake_all_queues(vsi->netdev);
  7296. } else {
  7297. netif_carrier_off(vsi->netdev);
  7298. netif_tx_stop_all_queues(vsi->netdev);
  7299. }
  7300. break;
  7301. case I40E_VSI_SRIOV:
  7302. case I40E_VSI_VMDQ2:
  7303. case I40E_VSI_CTRL:
  7304. case I40E_VSI_IWARP:
  7305. case I40E_VSI_MIRROR:
  7306. default:
  7307. /* there is no notification for other VSIs */
  7308. break;
  7309. }
  7310. }
  7311. /**
  7312. * i40e_veb_link_event - notify elements on the veb of a link event
  7313. * @veb: veb to be notified
  7314. * @link_up: link up or down
  7315. **/
  7316. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  7317. {
  7318. struct i40e_pf *pf;
  7319. int i;
  7320. if (!veb || !veb->pf)
  7321. return;
  7322. pf = veb->pf;
  7323. /* depth first... */
  7324. for (i = 0; i < I40E_MAX_VEB; i++)
  7325. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  7326. i40e_veb_link_event(pf->veb[i], link_up);
  7327. /* ... now the local VSIs */
  7328. for (i = 0; i < pf->num_alloc_vsi; i++)
  7329. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  7330. i40e_vsi_link_event(pf->vsi[i], link_up);
  7331. }
  7332. /**
  7333. * i40e_link_event - Update netif_carrier status
  7334. * @pf: board private structure
  7335. **/
  7336. static void i40e_link_event(struct i40e_pf *pf)
  7337. {
  7338. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7339. u8 new_link_speed, old_link_speed;
  7340. i40e_status status;
  7341. bool new_link, old_link;
  7342. /* save off old link status information */
  7343. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  7344. /* set this to force the get_link_status call to refresh state */
  7345. pf->hw.phy.get_link_info = true;
  7346. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  7347. status = i40e_get_link_status(&pf->hw, &new_link);
  7348. /* On success, disable temp link polling */
  7349. if (status == I40E_SUCCESS) {
  7350. clear_bit(__I40E_TEMP_LINK_POLLING, pf->state);
  7351. } else {
  7352. /* Enable link polling temporarily until i40e_get_link_status
  7353. * returns I40E_SUCCESS
  7354. */
  7355. set_bit(__I40E_TEMP_LINK_POLLING, pf->state);
  7356. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  7357. status);
  7358. return;
  7359. }
  7360. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  7361. new_link_speed = pf->hw.phy.link_info.link_speed;
  7362. if (new_link == old_link &&
  7363. new_link_speed == old_link_speed &&
  7364. (test_bit(__I40E_VSI_DOWN, vsi->state) ||
  7365. new_link == netif_carrier_ok(vsi->netdev)))
  7366. return;
  7367. i40e_print_link_message(vsi, new_link);
  7368. /* Notify the base of the switch tree connected to
  7369. * the link. Floating VEBs are not notified.
  7370. */
  7371. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7372. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  7373. else
  7374. i40e_vsi_link_event(vsi, new_link);
  7375. if (pf->vf)
  7376. i40e_vc_notify_link_state(pf);
  7377. if (pf->flags & I40E_FLAG_PTP)
  7378. i40e_ptp_set_increment(pf);
  7379. }
  7380. /**
  7381. * i40e_watchdog_subtask - periodic checks not using event driven response
  7382. * @pf: board private structure
  7383. **/
  7384. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  7385. {
  7386. int i;
  7387. /* if interface is down do nothing */
  7388. if (test_bit(__I40E_DOWN, pf->state) ||
  7389. test_bit(__I40E_CONFIG_BUSY, pf->state))
  7390. return;
  7391. /* make sure we don't do these things too often */
  7392. if (time_before(jiffies, (pf->service_timer_previous +
  7393. pf->service_timer_period)))
  7394. return;
  7395. pf->service_timer_previous = jiffies;
  7396. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  7397. test_bit(__I40E_TEMP_LINK_POLLING, pf->state))
  7398. i40e_link_event(pf);
  7399. /* Update the stats for active netdevs so the network stack
  7400. * can look at updated numbers whenever it cares to
  7401. */
  7402. for (i = 0; i < pf->num_alloc_vsi; i++)
  7403. if (pf->vsi[i] && pf->vsi[i]->netdev)
  7404. i40e_update_stats(pf->vsi[i]);
  7405. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  7406. /* Update the stats for the active switching components */
  7407. for (i = 0; i < I40E_MAX_VEB; i++)
  7408. if (pf->veb[i])
  7409. i40e_update_veb_stats(pf->veb[i]);
  7410. }
  7411. i40e_ptp_rx_hang(pf);
  7412. i40e_ptp_tx_hang(pf);
  7413. }
  7414. /**
  7415. * i40e_reset_subtask - Set up for resetting the device and driver
  7416. * @pf: board private structure
  7417. **/
  7418. static void i40e_reset_subtask(struct i40e_pf *pf)
  7419. {
  7420. u32 reset_flags = 0;
  7421. if (test_bit(__I40E_REINIT_REQUESTED, pf->state)) {
  7422. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  7423. clear_bit(__I40E_REINIT_REQUESTED, pf->state);
  7424. }
  7425. if (test_bit(__I40E_PF_RESET_REQUESTED, pf->state)) {
  7426. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  7427. clear_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  7428. }
  7429. if (test_bit(__I40E_CORE_RESET_REQUESTED, pf->state)) {
  7430. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  7431. clear_bit(__I40E_CORE_RESET_REQUESTED, pf->state);
  7432. }
  7433. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state)) {
  7434. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  7435. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, pf->state);
  7436. }
  7437. if (test_bit(__I40E_DOWN_REQUESTED, pf->state)) {
  7438. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  7439. clear_bit(__I40E_DOWN_REQUESTED, pf->state);
  7440. }
  7441. /* If there's a recovery already waiting, it takes
  7442. * precedence before starting a new reset sequence.
  7443. */
  7444. if (test_bit(__I40E_RESET_INTR_RECEIVED, pf->state)) {
  7445. i40e_prep_for_reset(pf, false);
  7446. i40e_reset(pf);
  7447. i40e_rebuild(pf, false, false);
  7448. }
  7449. /* If we're already down or resetting, just bail */
  7450. if (reset_flags &&
  7451. !test_bit(__I40E_DOWN, pf->state) &&
  7452. !test_bit(__I40E_CONFIG_BUSY, pf->state)) {
  7453. i40e_do_reset(pf, reset_flags, false);
  7454. }
  7455. }
  7456. /**
  7457. * i40e_handle_link_event - Handle link event
  7458. * @pf: board private structure
  7459. * @e: event info posted on ARQ
  7460. **/
  7461. static void i40e_handle_link_event(struct i40e_pf *pf,
  7462. struct i40e_arq_event_info *e)
  7463. {
  7464. struct i40e_aqc_get_link_status *status =
  7465. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  7466. /* Do a new status request to re-enable LSE reporting
  7467. * and load new status information into the hw struct
  7468. * This completely ignores any state information
  7469. * in the ARQ event info, instead choosing to always
  7470. * issue the AQ update link status command.
  7471. */
  7472. i40e_link_event(pf);
  7473. /* Check if module meets thermal requirements */
  7474. if (status->phy_type == I40E_PHY_TYPE_NOT_SUPPORTED_HIGH_TEMP) {
  7475. dev_err(&pf->pdev->dev,
  7476. "Rx/Tx is disabled on this device because the module does not meet thermal requirements.\n");
  7477. dev_err(&pf->pdev->dev,
  7478. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7479. } else {
  7480. /* check for unqualified module, if link is down, suppress
  7481. * the message if link was forced to be down.
  7482. */
  7483. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  7484. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  7485. (!(status->link_info & I40E_AQ_LINK_UP)) &&
  7486. (!(pf->flags & I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED))) {
  7487. dev_err(&pf->pdev->dev,
  7488. "Rx/Tx is disabled on this device because an unsupported SFP module type was detected.\n");
  7489. dev_err(&pf->pdev->dev,
  7490. "Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
  7491. }
  7492. }
  7493. }
  7494. /**
  7495. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  7496. * @pf: board private structure
  7497. **/
  7498. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  7499. {
  7500. struct i40e_arq_event_info event;
  7501. struct i40e_hw *hw = &pf->hw;
  7502. u16 pending, i = 0;
  7503. i40e_status ret;
  7504. u16 opcode;
  7505. u32 oldval;
  7506. u32 val;
  7507. /* Do not run clean AQ when PF reset fails */
  7508. if (test_bit(__I40E_RESET_FAILED, pf->state))
  7509. return;
  7510. /* check for error indications */
  7511. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  7512. oldval = val;
  7513. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  7514. if (hw->debug_mask & I40E_DEBUG_AQ)
  7515. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  7516. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  7517. }
  7518. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  7519. if (hw->debug_mask & I40E_DEBUG_AQ)
  7520. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  7521. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  7522. pf->arq_overflows++;
  7523. }
  7524. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  7525. if (hw->debug_mask & I40E_DEBUG_AQ)
  7526. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  7527. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  7528. }
  7529. if (oldval != val)
  7530. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  7531. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  7532. oldval = val;
  7533. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  7534. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7535. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  7536. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  7537. }
  7538. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  7539. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7540. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  7541. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  7542. }
  7543. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  7544. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  7545. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  7546. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  7547. }
  7548. if (oldval != val)
  7549. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  7550. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  7551. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  7552. if (!event.msg_buf)
  7553. return;
  7554. do {
  7555. ret = i40e_clean_arq_element(hw, &event, &pending);
  7556. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  7557. break;
  7558. else if (ret) {
  7559. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  7560. break;
  7561. }
  7562. opcode = le16_to_cpu(event.desc.opcode);
  7563. switch (opcode) {
  7564. case i40e_aqc_opc_get_link_status:
  7565. i40e_handle_link_event(pf, &event);
  7566. break;
  7567. case i40e_aqc_opc_send_msg_to_pf:
  7568. ret = i40e_vc_process_vf_msg(pf,
  7569. le16_to_cpu(event.desc.retval),
  7570. le32_to_cpu(event.desc.cookie_high),
  7571. le32_to_cpu(event.desc.cookie_low),
  7572. event.msg_buf,
  7573. event.msg_len);
  7574. break;
  7575. case i40e_aqc_opc_lldp_update_mib:
  7576. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  7577. #ifdef CONFIG_I40E_DCB
  7578. rtnl_lock();
  7579. ret = i40e_handle_lldp_event(pf, &event);
  7580. rtnl_unlock();
  7581. #endif /* CONFIG_I40E_DCB */
  7582. break;
  7583. case i40e_aqc_opc_event_lan_overflow:
  7584. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  7585. i40e_handle_lan_overflow_event(pf, &event);
  7586. break;
  7587. case i40e_aqc_opc_send_msg_to_peer:
  7588. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  7589. break;
  7590. case i40e_aqc_opc_nvm_erase:
  7591. case i40e_aqc_opc_nvm_update:
  7592. case i40e_aqc_opc_oem_post_update:
  7593. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  7594. "ARQ NVM operation 0x%04x completed\n",
  7595. opcode);
  7596. break;
  7597. default:
  7598. dev_info(&pf->pdev->dev,
  7599. "ARQ: Unknown event 0x%04x ignored\n",
  7600. opcode);
  7601. break;
  7602. }
  7603. } while (i++ < pf->adminq_work_limit);
  7604. if (i < pf->adminq_work_limit)
  7605. clear_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state);
  7606. /* re-enable Admin queue interrupt cause */
  7607. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  7608. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  7609. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  7610. i40e_flush(hw);
  7611. kfree(event.msg_buf);
  7612. }
  7613. /**
  7614. * i40e_verify_eeprom - make sure eeprom is good to use
  7615. * @pf: board private structure
  7616. **/
  7617. static void i40e_verify_eeprom(struct i40e_pf *pf)
  7618. {
  7619. int err;
  7620. err = i40e_diag_eeprom_test(&pf->hw);
  7621. if (err) {
  7622. /* retry in case of garbage read */
  7623. err = i40e_diag_eeprom_test(&pf->hw);
  7624. if (err) {
  7625. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  7626. err);
  7627. set_bit(__I40E_BAD_EEPROM, pf->state);
  7628. }
  7629. }
  7630. if (!err && test_bit(__I40E_BAD_EEPROM, pf->state)) {
  7631. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  7632. clear_bit(__I40E_BAD_EEPROM, pf->state);
  7633. }
  7634. }
  7635. /**
  7636. * i40e_enable_pf_switch_lb
  7637. * @pf: pointer to the PF structure
  7638. *
  7639. * enable switch loop back or die - no point in a return value
  7640. **/
  7641. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  7642. {
  7643. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7644. struct i40e_vsi_context ctxt;
  7645. int ret;
  7646. ctxt.seid = pf->main_vsi_seid;
  7647. ctxt.pf_num = pf->hw.pf_id;
  7648. ctxt.vf_num = 0;
  7649. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7650. if (ret) {
  7651. dev_info(&pf->pdev->dev,
  7652. "couldn't get PF vsi config, err %s aq_err %s\n",
  7653. i40e_stat_str(&pf->hw, ret),
  7654. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7655. return;
  7656. }
  7657. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7658. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7659. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7660. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7661. if (ret) {
  7662. dev_info(&pf->pdev->dev,
  7663. "update vsi switch failed, err %s aq_err %s\n",
  7664. i40e_stat_str(&pf->hw, ret),
  7665. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7666. }
  7667. }
  7668. /**
  7669. * i40e_disable_pf_switch_lb
  7670. * @pf: pointer to the PF structure
  7671. *
  7672. * disable switch loop back or die - no point in a return value
  7673. **/
  7674. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  7675. {
  7676. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7677. struct i40e_vsi_context ctxt;
  7678. int ret;
  7679. ctxt.seid = pf->main_vsi_seid;
  7680. ctxt.pf_num = pf->hw.pf_id;
  7681. ctxt.vf_num = 0;
  7682. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  7683. if (ret) {
  7684. dev_info(&pf->pdev->dev,
  7685. "couldn't get PF vsi config, err %s aq_err %s\n",
  7686. i40e_stat_str(&pf->hw, ret),
  7687. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7688. return;
  7689. }
  7690. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  7691. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  7692. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  7693. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  7694. if (ret) {
  7695. dev_info(&pf->pdev->dev,
  7696. "update vsi switch failed, err %s aq_err %s\n",
  7697. i40e_stat_str(&pf->hw, ret),
  7698. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  7699. }
  7700. }
  7701. /**
  7702. * i40e_config_bridge_mode - Configure the HW bridge mode
  7703. * @veb: pointer to the bridge instance
  7704. *
  7705. * Configure the loop back mode for the LAN VSI that is downlink to the
  7706. * specified HW bridge instance. It is expected this function is called
  7707. * when a new HW bridge is instantiated.
  7708. **/
  7709. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  7710. {
  7711. struct i40e_pf *pf = veb->pf;
  7712. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  7713. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  7714. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7715. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  7716. i40e_disable_pf_switch_lb(pf);
  7717. else
  7718. i40e_enable_pf_switch_lb(pf);
  7719. }
  7720. /**
  7721. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  7722. * @veb: pointer to the VEB instance
  7723. *
  7724. * This is a recursive function that first builds the attached VSIs then
  7725. * recurses in to build the next layer of VEB. We track the connections
  7726. * through our own index numbers because the seid's from the HW could
  7727. * change across the reset.
  7728. **/
  7729. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  7730. {
  7731. struct i40e_vsi *ctl_vsi = NULL;
  7732. struct i40e_pf *pf = veb->pf;
  7733. int v, veb_idx;
  7734. int ret;
  7735. /* build VSI that owns this VEB, temporarily attached to base VEB */
  7736. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  7737. if (pf->vsi[v] &&
  7738. pf->vsi[v]->veb_idx == veb->idx &&
  7739. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  7740. ctl_vsi = pf->vsi[v];
  7741. break;
  7742. }
  7743. }
  7744. if (!ctl_vsi) {
  7745. dev_info(&pf->pdev->dev,
  7746. "missing owner VSI for veb_idx %d\n", veb->idx);
  7747. ret = -ENOENT;
  7748. goto end_reconstitute;
  7749. }
  7750. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  7751. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  7752. ret = i40e_add_vsi(ctl_vsi);
  7753. if (ret) {
  7754. dev_info(&pf->pdev->dev,
  7755. "rebuild of veb_idx %d owner VSI failed: %d\n",
  7756. veb->idx, ret);
  7757. goto end_reconstitute;
  7758. }
  7759. i40e_vsi_reset_stats(ctl_vsi);
  7760. /* create the VEB in the switch and move the VSI onto the VEB */
  7761. ret = i40e_add_veb(veb, ctl_vsi);
  7762. if (ret)
  7763. goto end_reconstitute;
  7764. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  7765. veb->bridge_mode = BRIDGE_MODE_VEB;
  7766. else
  7767. veb->bridge_mode = BRIDGE_MODE_VEPA;
  7768. i40e_config_bridge_mode(veb);
  7769. /* create the remaining VSIs attached to this VEB */
  7770. for (v = 0; v < pf->num_alloc_vsi; v++) {
  7771. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  7772. continue;
  7773. if (pf->vsi[v]->veb_idx == veb->idx) {
  7774. struct i40e_vsi *vsi = pf->vsi[v];
  7775. vsi->uplink_seid = veb->seid;
  7776. ret = i40e_add_vsi(vsi);
  7777. if (ret) {
  7778. dev_info(&pf->pdev->dev,
  7779. "rebuild of vsi_idx %d failed: %d\n",
  7780. v, ret);
  7781. goto end_reconstitute;
  7782. }
  7783. i40e_vsi_reset_stats(vsi);
  7784. }
  7785. }
  7786. /* create any VEBs attached to this VEB - RECURSION */
  7787. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  7788. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  7789. pf->veb[veb_idx]->uplink_seid = veb->seid;
  7790. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  7791. if (ret)
  7792. break;
  7793. }
  7794. }
  7795. end_reconstitute:
  7796. return ret;
  7797. }
  7798. /**
  7799. * i40e_get_capabilities - get info about the HW
  7800. * @pf: the PF struct
  7801. **/
  7802. static int i40e_get_capabilities(struct i40e_pf *pf,
  7803. enum i40e_admin_queue_opc list_type)
  7804. {
  7805. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  7806. u16 data_size;
  7807. int buf_len;
  7808. int err;
  7809. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  7810. do {
  7811. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  7812. if (!cap_buf)
  7813. return -ENOMEM;
  7814. /* this loads the data into the hw struct for us */
  7815. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  7816. &data_size, list_type,
  7817. NULL);
  7818. /* data loaded, buffer no longer needed */
  7819. kfree(cap_buf);
  7820. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  7821. /* retry with a larger buffer */
  7822. buf_len = data_size;
  7823. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  7824. dev_info(&pf->pdev->dev,
  7825. "capability discovery failed, err %s aq_err %s\n",
  7826. i40e_stat_str(&pf->hw, err),
  7827. i40e_aq_str(&pf->hw,
  7828. pf->hw.aq.asq_last_status));
  7829. return -ENODEV;
  7830. }
  7831. } while (err);
  7832. if (pf->hw.debug_mask & I40E_DEBUG_USER) {
  7833. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7834. dev_info(&pf->pdev->dev,
  7835. "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",
  7836. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  7837. pf->hw.func_caps.num_msix_vectors,
  7838. pf->hw.func_caps.num_msix_vectors_vf,
  7839. pf->hw.func_caps.fd_filters_guaranteed,
  7840. pf->hw.func_caps.fd_filters_best_effort,
  7841. pf->hw.func_caps.num_tx_qp,
  7842. pf->hw.func_caps.num_vsis);
  7843. } else if (list_type == i40e_aqc_opc_list_dev_capabilities) {
  7844. dev_info(&pf->pdev->dev,
  7845. "switch_mode=0x%04x, function_valid=0x%08x\n",
  7846. pf->hw.dev_caps.switch_mode,
  7847. pf->hw.dev_caps.valid_functions);
  7848. dev_info(&pf->pdev->dev,
  7849. "SR-IOV=%d, num_vfs for all function=%u\n",
  7850. pf->hw.dev_caps.sr_iov_1_1,
  7851. pf->hw.dev_caps.num_vfs);
  7852. dev_info(&pf->pdev->dev,
  7853. "num_vsis=%u, num_rx:%u, num_tx=%u\n",
  7854. pf->hw.dev_caps.num_vsis,
  7855. pf->hw.dev_caps.num_rx_qp,
  7856. pf->hw.dev_caps.num_tx_qp);
  7857. }
  7858. }
  7859. if (list_type == i40e_aqc_opc_list_func_capabilities) {
  7860. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  7861. + pf->hw.func_caps.num_vfs)
  7862. if (pf->hw.revision_id == 0 &&
  7863. pf->hw.func_caps.num_vsis < DEF_NUM_VSI) {
  7864. dev_info(&pf->pdev->dev,
  7865. "got num_vsis %d, setting num_vsis to %d\n",
  7866. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  7867. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  7868. }
  7869. }
  7870. return 0;
  7871. }
  7872. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  7873. /**
  7874. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  7875. * @pf: board private structure
  7876. **/
  7877. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  7878. {
  7879. struct i40e_vsi *vsi;
  7880. /* quick workaround for an NVM issue that leaves a critical register
  7881. * uninitialized
  7882. */
  7883. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  7884. static const u32 hkey[] = {
  7885. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  7886. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  7887. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  7888. 0x95b3a76d};
  7889. int i;
  7890. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  7891. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  7892. }
  7893. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7894. return;
  7895. /* find existing VSI and see if it needs configuring */
  7896. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7897. /* create a new VSI if none exists */
  7898. if (!vsi) {
  7899. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  7900. pf->vsi[pf->lan_vsi]->seid, 0);
  7901. if (!vsi) {
  7902. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  7903. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7904. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  7905. return;
  7906. }
  7907. }
  7908. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  7909. }
  7910. /**
  7911. * i40e_fdir_teardown - release the Flow Director resources
  7912. * @pf: board private structure
  7913. **/
  7914. static void i40e_fdir_teardown(struct i40e_pf *pf)
  7915. {
  7916. struct i40e_vsi *vsi;
  7917. i40e_fdir_filter_exit(pf);
  7918. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  7919. if (vsi)
  7920. i40e_vsi_release(vsi);
  7921. }
  7922. /**
  7923. * i40e_rebuild_cloud_filters - Rebuilds cloud filters for VSIs
  7924. * @vsi: PF main vsi
  7925. * @seid: seid of main or channel VSIs
  7926. *
  7927. * Rebuilds cloud filters associated with main VSI and channel VSIs if they
  7928. * existed before reset
  7929. **/
  7930. static int i40e_rebuild_cloud_filters(struct i40e_vsi *vsi, u16 seid)
  7931. {
  7932. struct i40e_cloud_filter *cfilter;
  7933. struct i40e_pf *pf = vsi->back;
  7934. struct hlist_node *node;
  7935. i40e_status ret;
  7936. /* Add cloud filters back if they exist */
  7937. hlist_for_each_entry_safe(cfilter, node, &pf->cloud_filter_list,
  7938. cloud_node) {
  7939. if (cfilter->seid != seid)
  7940. continue;
  7941. if (cfilter->dst_port)
  7942. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  7943. true);
  7944. else
  7945. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  7946. if (ret) {
  7947. dev_dbg(&pf->pdev->dev,
  7948. "Failed to rebuild cloud filter, err %s aq_err %s\n",
  7949. i40e_stat_str(&pf->hw, ret),
  7950. i40e_aq_str(&pf->hw,
  7951. pf->hw.aq.asq_last_status));
  7952. return ret;
  7953. }
  7954. }
  7955. return 0;
  7956. }
  7957. /**
  7958. * i40e_rebuild_channels - Rebuilds channel VSIs if they existed before reset
  7959. * @vsi: PF main vsi
  7960. *
  7961. * Rebuilds channel VSIs if they existed before reset
  7962. **/
  7963. static int i40e_rebuild_channels(struct i40e_vsi *vsi)
  7964. {
  7965. struct i40e_channel *ch, *ch_tmp;
  7966. i40e_status ret;
  7967. if (list_empty(&vsi->ch_list))
  7968. return 0;
  7969. list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
  7970. if (!ch->initialized)
  7971. break;
  7972. /* Proceed with creation of channel (VMDq2) VSI */
  7973. ret = i40e_add_channel(vsi->back, vsi->uplink_seid, ch);
  7974. if (ret) {
  7975. dev_info(&vsi->back->pdev->dev,
  7976. "failed to rebuild channels using uplink_seid %u\n",
  7977. vsi->uplink_seid);
  7978. return ret;
  7979. }
  7980. /* Reconfigure TX queues using QTX_CTL register */
  7981. ret = i40e_channel_config_tx_ring(vsi->back, vsi, ch);
  7982. if (ret) {
  7983. dev_info(&vsi->back->pdev->dev,
  7984. "failed to configure TX rings for channel %u\n",
  7985. ch->seid);
  7986. return ret;
  7987. }
  7988. /* update 'next_base_queue' */
  7989. vsi->next_base_queue = vsi->next_base_queue +
  7990. ch->num_queue_pairs;
  7991. if (ch->max_tx_rate) {
  7992. u64 credits = ch->max_tx_rate;
  7993. if (i40e_set_bw_limit(vsi, ch->seid,
  7994. ch->max_tx_rate))
  7995. return -EINVAL;
  7996. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  7997. dev_dbg(&vsi->back->pdev->dev,
  7998. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  7999. ch->max_tx_rate,
  8000. credits,
  8001. ch->seid);
  8002. }
  8003. ret = i40e_rebuild_cloud_filters(vsi, ch->seid);
  8004. if (ret) {
  8005. dev_dbg(&vsi->back->pdev->dev,
  8006. "Failed to rebuild cloud filters for channel VSI %u\n",
  8007. ch->seid);
  8008. return ret;
  8009. }
  8010. }
  8011. return 0;
  8012. }
  8013. /**
  8014. * i40e_prep_for_reset - prep for the core to reset
  8015. * @pf: board private structure
  8016. * @lock_acquired: indicates whether or not the lock has been acquired
  8017. * before this function was called.
  8018. *
  8019. * Close up the VFs and other things in prep for PF Reset.
  8020. **/
  8021. static void i40e_prep_for_reset(struct i40e_pf *pf, bool lock_acquired)
  8022. {
  8023. struct i40e_hw *hw = &pf->hw;
  8024. i40e_status ret = 0;
  8025. u32 v;
  8026. clear_bit(__I40E_RESET_INTR_RECEIVED, pf->state);
  8027. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  8028. return;
  8029. if (i40e_check_asq_alive(&pf->hw))
  8030. i40e_vc_notify_reset(pf);
  8031. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  8032. /* quiesce the VSIs and their queues that are not already DOWN */
  8033. /* pf_quiesce_all_vsi modifies netdev structures -rtnl_lock needed */
  8034. if (!lock_acquired)
  8035. rtnl_lock();
  8036. i40e_pf_quiesce_all_vsi(pf);
  8037. if (!lock_acquired)
  8038. rtnl_unlock();
  8039. for (v = 0; v < pf->num_alloc_vsi; v++) {
  8040. if (pf->vsi[v])
  8041. pf->vsi[v]->seid = 0;
  8042. }
  8043. i40e_shutdown_adminq(&pf->hw);
  8044. /* call shutdown HMC */
  8045. if (hw->hmc.hmc_obj) {
  8046. ret = i40e_shutdown_lan_hmc(hw);
  8047. if (ret)
  8048. dev_warn(&pf->pdev->dev,
  8049. "shutdown_lan_hmc failed: %d\n", ret);
  8050. }
  8051. }
  8052. /**
  8053. * i40e_send_version - update firmware with driver version
  8054. * @pf: PF struct
  8055. */
  8056. static void i40e_send_version(struct i40e_pf *pf)
  8057. {
  8058. struct i40e_driver_version dv;
  8059. dv.major_version = DRV_VERSION_MAJOR;
  8060. dv.minor_version = DRV_VERSION_MINOR;
  8061. dv.build_version = DRV_VERSION_BUILD;
  8062. dv.subbuild_version = 0;
  8063. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  8064. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  8065. }
  8066. /**
  8067. * i40e_get_oem_version - get OEM specific version information
  8068. * @hw: pointer to the hardware structure
  8069. **/
  8070. static void i40e_get_oem_version(struct i40e_hw *hw)
  8071. {
  8072. u16 block_offset = 0xffff;
  8073. u16 block_length = 0;
  8074. u16 capabilities = 0;
  8075. u16 gen_snap = 0;
  8076. u16 release = 0;
  8077. #define I40E_SR_NVM_OEM_VERSION_PTR 0x1B
  8078. #define I40E_NVM_OEM_LENGTH_OFFSET 0x00
  8079. #define I40E_NVM_OEM_CAPABILITIES_OFFSET 0x01
  8080. #define I40E_NVM_OEM_GEN_OFFSET 0x02
  8081. #define I40E_NVM_OEM_RELEASE_OFFSET 0x03
  8082. #define I40E_NVM_OEM_CAPABILITIES_MASK 0x000F
  8083. #define I40E_NVM_OEM_LENGTH 3
  8084. /* Check if pointer to OEM version block is valid. */
  8085. i40e_read_nvm_word(hw, I40E_SR_NVM_OEM_VERSION_PTR, &block_offset);
  8086. if (block_offset == 0xffff)
  8087. return;
  8088. /* Check if OEM version block has correct length. */
  8089. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_LENGTH_OFFSET,
  8090. &block_length);
  8091. if (block_length < I40E_NVM_OEM_LENGTH)
  8092. return;
  8093. /* Check if OEM version format is as expected. */
  8094. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_CAPABILITIES_OFFSET,
  8095. &capabilities);
  8096. if ((capabilities & I40E_NVM_OEM_CAPABILITIES_MASK) != 0)
  8097. return;
  8098. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_GEN_OFFSET,
  8099. &gen_snap);
  8100. i40e_read_nvm_word(hw, block_offset + I40E_NVM_OEM_RELEASE_OFFSET,
  8101. &release);
  8102. hw->nvm.oem_ver = (gen_snap << I40E_OEM_SNAP_SHIFT) | release;
  8103. hw->nvm.eetrack = I40E_OEM_EETRACK_ID;
  8104. }
  8105. /**
  8106. * i40e_reset - wait for core reset to finish reset, reset pf if corer not seen
  8107. * @pf: board private structure
  8108. **/
  8109. static int i40e_reset(struct i40e_pf *pf)
  8110. {
  8111. struct i40e_hw *hw = &pf->hw;
  8112. i40e_status ret;
  8113. ret = i40e_pf_reset(hw);
  8114. if (ret) {
  8115. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  8116. set_bit(__I40E_RESET_FAILED, pf->state);
  8117. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8118. } else {
  8119. pf->pfr_count++;
  8120. }
  8121. return ret;
  8122. }
  8123. /**
  8124. * i40e_rebuild - rebuild using a saved config
  8125. * @pf: board private structure
  8126. * @reinit: if the Main VSI needs to re-initialized.
  8127. * @lock_acquired: indicates whether or not the lock has been acquired
  8128. * before this function was called.
  8129. **/
  8130. static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
  8131. {
  8132. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  8133. struct i40e_hw *hw = &pf->hw;
  8134. u8 set_fc_aq_fail = 0;
  8135. i40e_status ret;
  8136. u32 val;
  8137. int v;
  8138. if (test_bit(__I40E_DOWN, pf->state))
  8139. goto clear_recovery;
  8140. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  8141. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  8142. ret = i40e_init_adminq(&pf->hw);
  8143. if (ret) {
  8144. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  8145. i40e_stat_str(&pf->hw, ret),
  8146. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8147. goto clear_recovery;
  8148. }
  8149. i40e_get_oem_version(&pf->hw);
  8150. if (test_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state) &&
  8151. ((hw->aq.fw_maj_ver == 4 && hw->aq.fw_min_ver <= 33) ||
  8152. hw->aq.fw_maj_ver < 4) && hw->mac.type == I40E_MAC_XL710) {
  8153. /* The following delay is necessary for 4.33 firmware and older
  8154. * to recover after EMP reset. 200 ms should suffice but we
  8155. * put here 300 ms to be sure that FW is ready to operate
  8156. * after reset.
  8157. */
  8158. mdelay(300);
  8159. }
  8160. /* re-verify the eeprom if we just had an EMP reset */
  8161. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, pf->state))
  8162. i40e_verify_eeprom(pf);
  8163. i40e_clear_pxe_mode(hw);
  8164. ret = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  8165. if (ret)
  8166. goto end_core_reset;
  8167. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  8168. hw->func_caps.num_rx_qp, 0, 0);
  8169. if (ret) {
  8170. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  8171. goto end_core_reset;
  8172. }
  8173. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  8174. if (ret) {
  8175. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  8176. goto end_core_reset;
  8177. }
  8178. /* Enable FW to write a default DCB config on link-up */
  8179. i40e_aq_set_dcb_parameters(hw, true, NULL);
  8180. #ifdef CONFIG_I40E_DCB
  8181. ret = i40e_init_pf_dcb(pf);
  8182. if (ret) {
  8183. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  8184. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  8185. /* Continue without DCB enabled */
  8186. }
  8187. #endif /* CONFIG_I40E_DCB */
  8188. /* do basic switch setup */
  8189. if (!lock_acquired)
  8190. rtnl_lock();
  8191. ret = i40e_setup_pf_switch(pf, reinit);
  8192. if (ret)
  8193. goto end_unlock;
  8194. /* The driver only wants link up/down and module qualification
  8195. * reports from firmware. Note the negative logic.
  8196. */
  8197. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  8198. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  8199. I40E_AQ_EVENT_MEDIA_NA |
  8200. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  8201. if (ret)
  8202. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  8203. i40e_stat_str(&pf->hw, ret),
  8204. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8205. /* make sure our flow control settings are restored */
  8206. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  8207. if (ret)
  8208. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  8209. i40e_stat_str(&pf->hw, ret),
  8210. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8211. /* Rebuild the VSIs and VEBs that existed before reset.
  8212. * They are still in our local switch element arrays, so only
  8213. * need to rebuild the switch model in the HW.
  8214. *
  8215. * If there were VEBs but the reconstitution failed, we'll try
  8216. * try to recover minimal use by getting the basic PF VSI working.
  8217. */
  8218. if (vsi->uplink_seid != pf->mac_seid) {
  8219. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  8220. /* find the one VEB connected to the MAC, and find orphans */
  8221. for (v = 0; v < I40E_MAX_VEB; v++) {
  8222. if (!pf->veb[v])
  8223. continue;
  8224. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  8225. pf->veb[v]->uplink_seid == 0) {
  8226. ret = i40e_reconstitute_veb(pf->veb[v]);
  8227. if (!ret)
  8228. continue;
  8229. /* If Main VEB failed, we're in deep doodoo,
  8230. * so give up rebuilding the switch and set up
  8231. * for minimal rebuild of PF VSI.
  8232. * If orphan failed, we'll report the error
  8233. * but try to keep going.
  8234. */
  8235. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  8236. dev_info(&pf->pdev->dev,
  8237. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  8238. ret);
  8239. vsi->uplink_seid = pf->mac_seid;
  8240. break;
  8241. } else if (pf->veb[v]->uplink_seid == 0) {
  8242. dev_info(&pf->pdev->dev,
  8243. "rebuild of orphan VEB failed: %d\n",
  8244. ret);
  8245. }
  8246. }
  8247. }
  8248. }
  8249. if (vsi->uplink_seid == pf->mac_seid) {
  8250. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  8251. /* no VEB, so rebuild only the Main VSI */
  8252. ret = i40e_add_vsi(vsi);
  8253. if (ret) {
  8254. dev_info(&pf->pdev->dev,
  8255. "rebuild of Main VSI failed: %d\n", ret);
  8256. goto end_unlock;
  8257. }
  8258. }
  8259. if (vsi->mqprio_qopt.max_rate[0]) {
  8260. u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
  8261. u64 credits = 0;
  8262. do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
  8263. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  8264. if (ret)
  8265. goto end_unlock;
  8266. credits = max_tx_rate;
  8267. do_div(credits, I40E_BW_CREDIT_DIVISOR);
  8268. dev_dbg(&vsi->back->pdev->dev,
  8269. "Set tx rate of %llu Mbps (count of 50Mbps %llu) for vsi->seid %u\n",
  8270. max_tx_rate,
  8271. credits,
  8272. vsi->seid);
  8273. }
  8274. ret = i40e_rebuild_cloud_filters(vsi, vsi->seid);
  8275. if (ret)
  8276. goto end_unlock;
  8277. /* PF Main VSI is rebuild by now, go ahead and rebuild channel VSIs
  8278. * for this main VSI if they exist
  8279. */
  8280. ret = i40e_rebuild_channels(vsi);
  8281. if (ret)
  8282. goto end_unlock;
  8283. /* Reconfigure hardware for allowing smaller MSS in the case
  8284. * of TSO, so that we avoid the MDD being fired and causing
  8285. * a reset in the case of small MSS+TSO.
  8286. */
  8287. #define I40E_REG_MSS 0x000E64DC
  8288. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  8289. #define I40E_64BYTE_MSS 0x400000
  8290. val = rd32(hw, I40E_REG_MSS);
  8291. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  8292. val &= ~I40E_REG_MSS_MIN_MASK;
  8293. val |= I40E_64BYTE_MSS;
  8294. wr32(hw, I40E_REG_MSS, val);
  8295. }
  8296. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  8297. msleep(75);
  8298. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  8299. if (ret)
  8300. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  8301. i40e_stat_str(&pf->hw, ret),
  8302. i40e_aq_str(&pf->hw,
  8303. pf->hw.aq.asq_last_status));
  8304. }
  8305. /* reinit the misc interrupt */
  8306. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8307. ret = i40e_setup_misc_vector(pf);
  8308. /* Add a filter to drop all Flow control frames from any VSI from being
  8309. * transmitted. By doing so we stop a malicious VF from sending out
  8310. * PAUSE or PFC frames and potentially controlling traffic for other
  8311. * PF/VF VSIs.
  8312. * The FW can still send Flow control frames if enabled.
  8313. */
  8314. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  8315. pf->main_vsi_seid);
  8316. /* restart the VSIs that were rebuilt and running before the reset */
  8317. i40e_pf_unquiesce_all_vsi(pf);
  8318. /* Release the RTNL lock before we start resetting VFs */
  8319. if (!lock_acquired)
  8320. rtnl_unlock();
  8321. /* Restore promiscuous settings */
  8322. ret = i40e_set_promiscuous(pf, pf->cur_promisc);
  8323. if (ret)
  8324. dev_warn(&pf->pdev->dev,
  8325. "Failed to restore promiscuous setting: %s, err %s aq_err %s\n",
  8326. pf->cur_promisc ? "on" : "off",
  8327. i40e_stat_str(&pf->hw, ret),
  8328. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8329. i40e_reset_all_vfs(pf, true);
  8330. /* tell the firmware that we're starting */
  8331. i40e_send_version(pf);
  8332. /* We've already released the lock, so don't do it again */
  8333. goto end_core_reset;
  8334. end_unlock:
  8335. if (!lock_acquired)
  8336. rtnl_unlock();
  8337. end_core_reset:
  8338. clear_bit(__I40E_RESET_FAILED, pf->state);
  8339. clear_recovery:
  8340. clear_bit(__I40E_RESET_RECOVERY_PENDING, pf->state);
  8341. }
  8342. /**
  8343. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  8344. * @pf: board private structure
  8345. * @reinit: if the Main VSI needs to re-initialized.
  8346. * @lock_acquired: indicates whether or not the lock has been acquired
  8347. * before this function was called.
  8348. **/
  8349. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit,
  8350. bool lock_acquired)
  8351. {
  8352. int ret;
  8353. /* Now we wait for GRST to settle out.
  8354. * We don't have to delete the VEBs or VSIs from the hw switch
  8355. * because the reset will make them disappear.
  8356. */
  8357. ret = i40e_reset(pf);
  8358. if (!ret)
  8359. i40e_rebuild(pf, reinit, lock_acquired);
  8360. }
  8361. /**
  8362. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  8363. * @pf: board private structure
  8364. *
  8365. * Close up the VFs and other things in prep for a Core Reset,
  8366. * then get ready to rebuild the world.
  8367. * @lock_acquired: indicates whether or not the lock has been acquired
  8368. * before this function was called.
  8369. **/
  8370. static void i40e_handle_reset_warning(struct i40e_pf *pf, bool lock_acquired)
  8371. {
  8372. i40e_prep_for_reset(pf, lock_acquired);
  8373. i40e_reset_and_rebuild(pf, false, lock_acquired);
  8374. }
  8375. /**
  8376. * i40e_handle_mdd_event
  8377. * @pf: pointer to the PF structure
  8378. *
  8379. * Called from the MDD irq handler to identify possibly malicious vfs
  8380. **/
  8381. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  8382. {
  8383. struct i40e_hw *hw = &pf->hw;
  8384. bool mdd_detected = false;
  8385. bool pf_mdd_detected = false;
  8386. struct i40e_vf *vf;
  8387. u32 reg;
  8388. int i;
  8389. if (!test_bit(__I40E_MDD_EVENT_PENDING, pf->state))
  8390. return;
  8391. /* find what triggered the MDD event */
  8392. reg = rd32(hw, I40E_GL_MDET_TX);
  8393. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  8394. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  8395. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  8396. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  8397. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  8398. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  8399. I40E_GL_MDET_TX_EVENT_SHIFT;
  8400. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  8401. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  8402. pf->hw.func_caps.base_queue;
  8403. if (netif_msg_tx_err(pf))
  8404. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  8405. event, queue, pf_num, vf_num);
  8406. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  8407. mdd_detected = true;
  8408. }
  8409. reg = rd32(hw, I40E_GL_MDET_RX);
  8410. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  8411. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  8412. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  8413. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  8414. I40E_GL_MDET_RX_EVENT_SHIFT;
  8415. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  8416. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  8417. pf->hw.func_caps.base_queue;
  8418. if (netif_msg_rx_err(pf))
  8419. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  8420. event, queue, func);
  8421. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  8422. mdd_detected = true;
  8423. }
  8424. if (mdd_detected) {
  8425. reg = rd32(hw, I40E_PF_MDET_TX);
  8426. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  8427. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  8428. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  8429. pf_mdd_detected = true;
  8430. }
  8431. reg = rd32(hw, I40E_PF_MDET_RX);
  8432. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  8433. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  8434. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  8435. pf_mdd_detected = true;
  8436. }
  8437. /* Queue belongs to the PF, initiate a reset */
  8438. if (pf_mdd_detected) {
  8439. set_bit(__I40E_PF_RESET_REQUESTED, pf->state);
  8440. i40e_service_event_schedule(pf);
  8441. }
  8442. }
  8443. /* see if one of the VFs needs its hand slapped */
  8444. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  8445. vf = &(pf->vf[i]);
  8446. reg = rd32(hw, I40E_VP_MDET_TX(i));
  8447. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  8448. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  8449. vf->num_mdd_events++;
  8450. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  8451. i);
  8452. }
  8453. reg = rd32(hw, I40E_VP_MDET_RX(i));
  8454. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  8455. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  8456. vf->num_mdd_events++;
  8457. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  8458. i);
  8459. }
  8460. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  8461. dev_info(&pf->pdev->dev,
  8462. "Too many MDD events on VF %d, disabled\n", i);
  8463. dev_info(&pf->pdev->dev,
  8464. "Use PF Control I/F to re-enable the VF\n");
  8465. set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
  8466. }
  8467. }
  8468. /* re-enable mdd interrupt cause */
  8469. clear_bit(__I40E_MDD_EVENT_PENDING, pf->state);
  8470. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  8471. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  8472. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  8473. i40e_flush(hw);
  8474. }
  8475. static const char *i40e_tunnel_name(struct i40e_udp_port_config *port)
  8476. {
  8477. switch (port->type) {
  8478. case UDP_TUNNEL_TYPE_VXLAN:
  8479. return "vxlan";
  8480. case UDP_TUNNEL_TYPE_GENEVE:
  8481. return "geneve";
  8482. default:
  8483. return "unknown";
  8484. }
  8485. }
  8486. /**
  8487. * i40e_sync_udp_filters - Trigger a sync event for existing UDP filters
  8488. * @pf: board private structure
  8489. **/
  8490. static void i40e_sync_udp_filters(struct i40e_pf *pf)
  8491. {
  8492. int i;
  8493. /* loop through and set pending bit for all active UDP filters */
  8494. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8495. if (pf->udp_ports[i].port)
  8496. pf->pending_udp_bitmap |= BIT_ULL(i);
  8497. }
  8498. set_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state);
  8499. }
  8500. /**
  8501. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  8502. * @pf: board private structure
  8503. **/
  8504. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  8505. {
  8506. struct i40e_hw *hw = &pf->hw;
  8507. i40e_status ret;
  8508. u16 port;
  8509. int i;
  8510. if (!test_and_clear_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state))
  8511. return;
  8512. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  8513. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  8514. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  8515. port = pf->udp_ports[i].port;
  8516. if (port)
  8517. ret = i40e_aq_add_udp_tunnel(hw, port,
  8518. pf->udp_ports[i].type,
  8519. NULL, NULL);
  8520. else
  8521. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  8522. if (ret) {
  8523. dev_info(&pf->pdev->dev,
  8524. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  8525. i40e_tunnel_name(&pf->udp_ports[i]),
  8526. port ? "add" : "delete",
  8527. port, i,
  8528. i40e_stat_str(&pf->hw, ret),
  8529. i40e_aq_str(&pf->hw,
  8530. pf->hw.aq.asq_last_status));
  8531. pf->udp_ports[i].port = 0;
  8532. }
  8533. }
  8534. }
  8535. }
  8536. /**
  8537. * i40e_service_task - Run the driver's async subtasks
  8538. * @work: pointer to work_struct containing our data
  8539. **/
  8540. static void i40e_service_task(struct work_struct *work)
  8541. {
  8542. struct i40e_pf *pf = container_of(work,
  8543. struct i40e_pf,
  8544. service_task);
  8545. unsigned long start_time = jiffies;
  8546. /* don't bother with service tasks if a reset is in progress */
  8547. if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state))
  8548. return;
  8549. if (test_and_set_bit(__I40E_SERVICE_SCHED, pf->state))
  8550. return;
  8551. i40e_detect_recover_hung(pf->vsi[pf->lan_vsi]);
  8552. i40e_sync_filters_subtask(pf);
  8553. i40e_reset_subtask(pf);
  8554. i40e_handle_mdd_event(pf);
  8555. i40e_vc_process_vflr_event(pf);
  8556. i40e_watchdog_subtask(pf);
  8557. i40e_fdir_reinit_subtask(pf);
  8558. if (test_and_clear_bit(__I40E_CLIENT_RESET, pf->state)) {
  8559. /* Client subtask will reopen next time through. */
  8560. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
  8561. } else {
  8562. i40e_client_subtask(pf);
  8563. if (test_and_clear_bit(__I40E_CLIENT_L2_CHANGE,
  8564. pf->state))
  8565. i40e_notify_client_of_l2_param_changes(
  8566. pf->vsi[pf->lan_vsi]);
  8567. }
  8568. i40e_sync_filters_subtask(pf);
  8569. i40e_sync_udp_filters_subtask(pf);
  8570. i40e_clean_adminq_subtask(pf);
  8571. /* flush memory to make sure state is correct before next watchdog */
  8572. smp_mb__before_atomic();
  8573. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  8574. /* If the tasks have taken longer than one timer cycle or there
  8575. * is more work to be done, reschedule the service task now
  8576. * rather than wait for the timer to tick again.
  8577. */
  8578. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  8579. test_bit(__I40E_ADMINQ_EVENT_PENDING, pf->state) ||
  8580. test_bit(__I40E_MDD_EVENT_PENDING, pf->state) ||
  8581. test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
  8582. i40e_service_event_schedule(pf);
  8583. }
  8584. /**
  8585. * i40e_service_timer - timer callback
  8586. * @data: pointer to PF struct
  8587. **/
  8588. static void i40e_service_timer(struct timer_list *t)
  8589. {
  8590. struct i40e_pf *pf = from_timer(pf, t, service_timer);
  8591. mod_timer(&pf->service_timer,
  8592. round_jiffies(jiffies + pf->service_timer_period));
  8593. i40e_service_event_schedule(pf);
  8594. }
  8595. /**
  8596. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  8597. * @vsi: the VSI being configured
  8598. **/
  8599. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  8600. {
  8601. struct i40e_pf *pf = vsi->back;
  8602. switch (vsi->type) {
  8603. case I40E_VSI_MAIN:
  8604. vsi->alloc_queue_pairs = pf->num_lan_qps;
  8605. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8606. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8607. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  8608. vsi->num_q_vectors = pf->num_lan_msix;
  8609. else
  8610. vsi->num_q_vectors = 1;
  8611. break;
  8612. case I40E_VSI_FDIR:
  8613. vsi->alloc_queue_pairs = 1;
  8614. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  8615. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8616. vsi->num_q_vectors = pf->num_fdsb_msix;
  8617. break;
  8618. case I40E_VSI_VMDQ2:
  8619. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  8620. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8621. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8622. vsi->num_q_vectors = pf->num_vmdq_msix;
  8623. break;
  8624. case I40E_VSI_SRIOV:
  8625. vsi->alloc_queue_pairs = pf->num_vf_qps;
  8626. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  8627. I40E_REQ_DESCRIPTOR_MULTIPLE);
  8628. break;
  8629. default:
  8630. WARN_ON(1);
  8631. return -ENODATA;
  8632. }
  8633. return 0;
  8634. }
  8635. /**
  8636. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  8637. * @vsi: VSI pointer
  8638. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  8639. *
  8640. * On error: returns error code (negative)
  8641. * On success: returns 0
  8642. **/
  8643. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  8644. {
  8645. struct i40e_ring **next_rings;
  8646. int size;
  8647. int ret = 0;
  8648. /* allocate memory for both Tx, XDP Tx and Rx ring pointers */
  8649. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs *
  8650. (i40e_enabled_xdp_vsi(vsi) ? 3 : 2);
  8651. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  8652. if (!vsi->tx_rings)
  8653. return -ENOMEM;
  8654. next_rings = vsi->tx_rings + vsi->alloc_queue_pairs;
  8655. if (i40e_enabled_xdp_vsi(vsi)) {
  8656. vsi->xdp_rings = next_rings;
  8657. next_rings += vsi->alloc_queue_pairs;
  8658. }
  8659. vsi->rx_rings = next_rings;
  8660. if (alloc_qvectors) {
  8661. /* allocate memory for q_vector pointers */
  8662. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  8663. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  8664. if (!vsi->q_vectors) {
  8665. ret = -ENOMEM;
  8666. goto err_vectors;
  8667. }
  8668. }
  8669. return ret;
  8670. err_vectors:
  8671. kfree(vsi->tx_rings);
  8672. return ret;
  8673. }
  8674. /**
  8675. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  8676. * @pf: board private structure
  8677. * @type: type of VSI
  8678. *
  8679. * On error: returns error code (negative)
  8680. * On success: returns vsi index in PF (positive)
  8681. **/
  8682. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  8683. {
  8684. int ret = -ENODEV;
  8685. struct i40e_vsi *vsi;
  8686. int vsi_idx;
  8687. int i;
  8688. /* Need to protect the allocation of the VSIs at the PF level */
  8689. mutex_lock(&pf->switch_mutex);
  8690. /* VSI list may be fragmented if VSI creation/destruction has
  8691. * been happening. We can afford to do a quick scan to look
  8692. * for any free VSIs in the list.
  8693. *
  8694. * find next empty vsi slot, looping back around if necessary
  8695. */
  8696. i = pf->next_vsi;
  8697. while (i < pf->num_alloc_vsi && pf->vsi[i])
  8698. i++;
  8699. if (i >= pf->num_alloc_vsi) {
  8700. i = 0;
  8701. while (i < pf->next_vsi && pf->vsi[i])
  8702. i++;
  8703. }
  8704. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  8705. vsi_idx = i; /* Found one! */
  8706. } else {
  8707. ret = -ENODEV;
  8708. goto unlock_pf; /* out of VSI slots! */
  8709. }
  8710. pf->next_vsi = ++i;
  8711. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  8712. if (!vsi) {
  8713. ret = -ENOMEM;
  8714. goto unlock_pf;
  8715. }
  8716. vsi->type = type;
  8717. vsi->back = pf;
  8718. set_bit(__I40E_VSI_DOWN, vsi->state);
  8719. vsi->flags = 0;
  8720. vsi->idx = vsi_idx;
  8721. vsi->int_rate_limit = 0;
  8722. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  8723. pf->rss_table_size : 64;
  8724. vsi->netdev_registered = false;
  8725. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  8726. hash_init(vsi->mac_filter_hash);
  8727. vsi->irqs_ready = false;
  8728. ret = i40e_set_num_rings_in_vsi(vsi);
  8729. if (ret)
  8730. goto err_rings;
  8731. ret = i40e_vsi_alloc_arrays(vsi, true);
  8732. if (ret)
  8733. goto err_rings;
  8734. /* Setup default MSIX irq handler for VSI */
  8735. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  8736. /* Initialize VSI lock */
  8737. spin_lock_init(&vsi->mac_filter_hash_lock);
  8738. pf->vsi[vsi_idx] = vsi;
  8739. ret = vsi_idx;
  8740. goto unlock_pf;
  8741. err_rings:
  8742. pf->next_vsi = i - 1;
  8743. kfree(vsi);
  8744. unlock_pf:
  8745. mutex_unlock(&pf->switch_mutex);
  8746. return ret;
  8747. }
  8748. /**
  8749. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  8750. * @vsi: VSI pointer
  8751. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  8752. *
  8753. * On error: returns error code (negative)
  8754. * On success: returns 0
  8755. **/
  8756. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  8757. {
  8758. /* free the ring and vector containers */
  8759. if (free_qvectors) {
  8760. kfree(vsi->q_vectors);
  8761. vsi->q_vectors = NULL;
  8762. }
  8763. kfree(vsi->tx_rings);
  8764. vsi->tx_rings = NULL;
  8765. vsi->rx_rings = NULL;
  8766. vsi->xdp_rings = NULL;
  8767. }
  8768. /**
  8769. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  8770. * and lookup table
  8771. * @vsi: Pointer to VSI structure
  8772. */
  8773. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  8774. {
  8775. if (!vsi)
  8776. return;
  8777. kfree(vsi->rss_hkey_user);
  8778. vsi->rss_hkey_user = NULL;
  8779. kfree(vsi->rss_lut_user);
  8780. vsi->rss_lut_user = NULL;
  8781. }
  8782. /**
  8783. * i40e_vsi_clear - Deallocate the VSI provided
  8784. * @vsi: the VSI being un-configured
  8785. **/
  8786. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  8787. {
  8788. struct i40e_pf *pf;
  8789. if (!vsi)
  8790. return 0;
  8791. if (!vsi->back)
  8792. goto free_vsi;
  8793. pf = vsi->back;
  8794. mutex_lock(&pf->switch_mutex);
  8795. if (!pf->vsi[vsi->idx]) {
  8796. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](type %d)\n",
  8797. vsi->idx, vsi->idx, vsi->type);
  8798. goto unlock_vsi;
  8799. }
  8800. if (pf->vsi[vsi->idx] != vsi) {
  8801. dev_err(&pf->pdev->dev,
  8802. "pf->vsi[%d](type %d) != vsi[%d](type %d): no free!\n",
  8803. pf->vsi[vsi->idx]->idx,
  8804. pf->vsi[vsi->idx]->type,
  8805. vsi->idx, vsi->type);
  8806. goto unlock_vsi;
  8807. }
  8808. /* updates the PF for this cleared vsi */
  8809. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8810. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  8811. i40e_vsi_free_arrays(vsi, true);
  8812. i40e_clear_rss_config_user(vsi);
  8813. pf->vsi[vsi->idx] = NULL;
  8814. if (vsi->idx < pf->next_vsi)
  8815. pf->next_vsi = vsi->idx;
  8816. unlock_vsi:
  8817. mutex_unlock(&pf->switch_mutex);
  8818. free_vsi:
  8819. kfree(vsi);
  8820. return 0;
  8821. }
  8822. /**
  8823. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  8824. * @vsi: the VSI being cleaned
  8825. **/
  8826. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  8827. {
  8828. int i;
  8829. if (vsi->tx_rings && vsi->tx_rings[0]) {
  8830. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8831. kfree_rcu(vsi->tx_rings[i], rcu);
  8832. vsi->tx_rings[i] = NULL;
  8833. vsi->rx_rings[i] = NULL;
  8834. if (vsi->xdp_rings)
  8835. vsi->xdp_rings[i] = NULL;
  8836. }
  8837. }
  8838. }
  8839. /**
  8840. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  8841. * @vsi: the VSI being configured
  8842. **/
  8843. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  8844. {
  8845. int i, qpv = i40e_enabled_xdp_vsi(vsi) ? 3 : 2;
  8846. struct i40e_pf *pf = vsi->back;
  8847. struct i40e_ring *ring;
  8848. /* Set basic values in the rings to be used later during open() */
  8849. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  8850. /* allocate space for both Tx and Rx in one shot */
  8851. ring = kcalloc(qpv, sizeof(struct i40e_ring), GFP_KERNEL);
  8852. if (!ring)
  8853. goto err_out;
  8854. ring->queue_index = i;
  8855. ring->reg_idx = vsi->base_queue + i;
  8856. ring->ring_active = false;
  8857. ring->vsi = vsi;
  8858. ring->netdev = vsi->netdev;
  8859. ring->dev = &pf->pdev->dev;
  8860. ring->count = vsi->num_desc;
  8861. ring->size = 0;
  8862. ring->dcb_tc = 0;
  8863. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8864. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8865. ring->itr_setting = pf->tx_itr_default;
  8866. vsi->tx_rings[i] = ring++;
  8867. if (!i40e_enabled_xdp_vsi(vsi))
  8868. goto setup_rx;
  8869. ring->queue_index = vsi->alloc_queue_pairs + i;
  8870. ring->reg_idx = vsi->base_queue + ring->queue_index;
  8871. ring->ring_active = false;
  8872. ring->vsi = vsi;
  8873. ring->netdev = NULL;
  8874. ring->dev = &pf->pdev->dev;
  8875. ring->count = vsi->num_desc;
  8876. ring->size = 0;
  8877. ring->dcb_tc = 0;
  8878. if (vsi->back->hw_features & I40E_HW_WB_ON_ITR_CAPABLE)
  8879. ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  8880. set_ring_xdp(ring);
  8881. ring->itr_setting = pf->tx_itr_default;
  8882. vsi->xdp_rings[i] = ring++;
  8883. setup_rx:
  8884. ring->queue_index = i;
  8885. ring->reg_idx = vsi->base_queue + i;
  8886. ring->ring_active = false;
  8887. ring->vsi = vsi;
  8888. ring->netdev = vsi->netdev;
  8889. ring->dev = &pf->pdev->dev;
  8890. ring->count = vsi->num_desc;
  8891. ring->size = 0;
  8892. ring->dcb_tc = 0;
  8893. ring->itr_setting = pf->rx_itr_default;
  8894. vsi->rx_rings[i] = ring;
  8895. }
  8896. return 0;
  8897. err_out:
  8898. i40e_vsi_clear_rings(vsi);
  8899. return -ENOMEM;
  8900. }
  8901. /**
  8902. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  8903. * @pf: board private structure
  8904. * @vectors: the number of MSI-X vectors to request
  8905. *
  8906. * Returns the number of vectors reserved, or error
  8907. **/
  8908. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  8909. {
  8910. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  8911. I40E_MIN_MSIX, vectors);
  8912. if (vectors < 0) {
  8913. dev_info(&pf->pdev->dev,
  8914. "MSI-X vector reservation failed: %d\n", vectors);
  8915. vectors = 0;
  8916. }
  8917. return vectors;
  8918. }
  8919. /**
  8920. * i40e_init_msix - Setup the MSIX capability
  8921. * @pf: board private structure
  8922. *
  8923. * Work with the OS to set up the MSIX vectors needed.
  8924. *
  8925. * Returns the number of vectors reserved or negative on failure
  8926. **/
  8927. static int i40e_init_msix(struct i40e_pf *pf)
  8928. {
  8929. struct i40e_hw *hw = &pf->hw;
  8930. int cpus, extra_vectors;
  8931. int vectors_left;
  8932. int v_budget, i;
  8933. int v_actual;
  8934. int iwarp_requested = 0;
  8935. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8936. return -ENODEV;
  8937. /* The number of vectors we'll request will be comprised of:
  8938. * - Add 1 for "other" cause for Admin Queue events, etc.
  8939. * - The number of LAN queue pairs
  8940. * - Queues being used for RSS.
  8941. * We don't need as many as max_rss_size vectors.
  8942. * use rss_size instead in the calculation since that
  8943. * is governed by number of cpus in the system.
  8944. * - assumes symmetric Tx/Rx pairing
  8945. * - The number of VMDq pairs
  8946. * - The CPU count within the NUMA node if iWARP is enabled
  8947. * Once we count this up, try the request.
  8948. *
  8949. * If we can't get what we want, we'll simplify to nearly nothing
  8950. * and try again. If that still fails, we punt.
  8951. */
  8952. vectors_left = hw->func_caps.num_msix_vectors;
  8953. v_budget = 0;
  8954. /* reserve one vector for miscellaneous handler */
  8955. if (vectors_left) {
  8956. v_budget++;
  8957. vectors_left--;
  8958. }
  8959. /* reserve some vectors for the main PF traffic queues. Initially we
  8960. * only reserve at most 50% of the available vectors, in the case that
  8961. * the number of online CPUs is large. This ensures that we can enable
  8962. * extra features as well. Once we've enabled the other features, we
  8963. * will use any remaining vectors to reach as close as we can to the
  8964. * number of online CPUs.
  8965. */
  8966. cpus = num_online_cpus();
  8967. pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
  8968. vectors_left -= pf->num_lan_msix;
  8969. /* reserve one vector for sideband flow director */
  8970. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  8971. if (vectors_left) {
  8972. pf->num_fdsb_msix = 1;
  8973. v_budget++;
  8974. vectors_left--;
  8975. } else {
  8976. pf->num_fdsb_msix = 0;
  8977. }
  8978. }
  8979. /* can we reserve enough for iWARP? */
  8980. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  8981. iwarp_requested = pf->num_iwarp_msix;
  8982. if (!vectors_left)
  8983. pf->num_iwarp_msix = 0;
  8984. else if (vectors_left < pf->num_iwarp_msix)
  8985. pf->num_iwarp_msix = 1;
  8986. v_budget += pf->num_iwarp_msix;
  8987. vectors_left -= pf->num_iwarp_msix;
  8988. }
  8989. /* any vectors left over go for VMDq support */
  8990. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  8991. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  8992. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  8993. if (!vectors_left) {
  8994. pf->num_vmdq_msix = 0;
  8995. pf->num_vmdq_qps = 0;
  8996. } else {
  8997. /* if we're short on vectors for what's desired, we limit
  8998. * the queues per vmdq. If this is still more than are
  8999. * available, the user will need to change the number of
  9000. * queues/vectors used by the PF later with the ethtool
  9001. * channels command
  9002. */
  9003. if (vmdq_vecs < vmdq_vecs_wanted)
  9004. pf->num_vmdq_qps = 1;
  9005. pf->num_vmdq_msix = pf->num_vmdq_qps;
  9006. v_budget += vmdq_vecs;
  9007. vectors_left -= vmdq_vecs;
  9008. }
  9009. }
  9010. /* On systems with a large number of SMP cores, we previously limited
  9011. * the number of vectors for num_lan_msix to be at most 50% of the
  9012. * available vectors, to allow for other features. Now, we add back
  9013. * the remaining vectors. However, we ensure that the total
  9014. * num_lan_msix will not exceed num_online_cpus(). To do this, we
  9015. * calculate the number of vectors we can add without going over the
  9016. * cap of CPUs. For systems with a small number of CPUs this will be
  9017. * zero.
  9018. */
  9019. extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
  9020. pf->num_lan_msix += extra_vectors;
  9021. vectors_left -= extra_vectors;
  9022. WARN(vectors_left < 0,
  9023. "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
  9024. v_budget += pf->num_lan_msix;
  9025. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  9026. GFP_KERNEL);
  9027. if (!pf->msix_entries)
  9028. return -ENOMEM;
  9029. for (i = 0; i < v_budget; i++)
  9030. pf->msix_entries[i].entry = i;
  9031. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  9032. if (v_actual < I40E_MIN_MSIX) {
  9033. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  9034. kfree(pf->msix_entries);
  9035. pf->msix_entries = NULL;
  9036. pci_disable_msix(pf->pdev);
  9037. return -ENODEV;
  9038. } else if (v_actual == I40E_MIN_MSIX) {
  9039. /* Adjust for minimal MSIX use */
  9040. pf->num_vmdq_vsis = 0;
  9041. pf->num_vmdq_qps = 0;
  9042. pf->num_lan_qps = 1;
  9043. pf->num_lan_msix = 1;
  9044. } else if (v_actual != v_budget) {
  9045. /* If we have limited resources, we will start with no vectors
  9046. * for the special features and then allocate vectors to some
  9047. * of these features based on the policy and at the end disable
  9048. * the features that did not get any vectors.
  9049. */
  9050. int vec;
  9051. dev_info(&pf->pdev->dev,
  9052. "MSI-X vector limit reached with %d, wanted %d, attempting to redistribute vectors\n",
  9053. v_actual, v_budget);
  9054. /* reserve the misc vector */
  9055. vec = v_actual - 1;
  9056. /* Scale vector usage down */
  9057. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  9058. pf->num_vmdq_vsis = 1;
  9059. pf->num_vmdq_qps = 1;
  9060. /* partition out the remaining vectors */
  9061. switch (vec) {
  9062. case 2:
  9063. pf->num_lan_msix = 1;
  9064. break;
  9065. case 3:
  9066. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9067. pf->num_lan_msix = 1;
  9068. pf->num_iwarp_msix = 1;
  9069. } else {
  9070. pf->num_lan_msix = 2;
  9071. }
  9072. break;
  9073. default:
  9074. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9075. pf->num_iwarp_msix = min_t(int, (vec / 3),
  9076. iwarp_requested);
  9077. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  9078. I40E_DEFAULT_NUM_VMDQ_VSI);
  9079. } else {
  9080. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  9081. I40E_DEFAULT_NUM_VMDQ_VSI);
  9082. }
  9083. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9084. pf->num_fdsb_msix = 1;
  9085. vec--;
  9086. }
  9087. pf->num_lan_msix = min_t(int,
  9088. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  9089. pf->num_lan_msix);
  9090. pf->num_lan_qps = pf->num_lan_msix;
  9091. break;
  9092. }
  9093. }
  9094. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  9095. (pf->num_fdsb_msix == 0)) {
  9096. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  9097. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9098. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9099. }
  9100. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9101. (pf->num_vmdq_msix == 0)) {
  9102. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  9103. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  9104. }
  9105. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  9106. (pf->num_iwarp_msix == 0)) {
  9107. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  9108. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9109. }
  9110. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  9111. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  9112. pf->num_lan_msix,
  9113. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  9114. pf->num_fdsb_msix,
  9115. pf->num_iwarp_msix);
  9116. return v_actual;
  9117. }
  9118. /**
  9119. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  9120. * @vsi: the VSI being configured
  9121. * @v_idx: index of the vector in the vsi struct
  9122. * @cpu: cpu to be used on affinity_mask
  9123. *
  9124. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  9125. **/
  9126. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  9127. {
  9128. struct i40e_q_vector *q_vector;
  9129. /* allocate q_vector */
  9130. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  9131. if (!q_vector)
  9132. return -ENOMEM;
  9133. q_vector->vsi = vsi;
  9134. q_vector->v_idx = v_idx;
  9135. cpumask_copy(&q_vector->affinity_mask, cpu_possible_mask);
  9136. if (vsi->netdev)
  9137. netif_napi_add(vsi->netdev, &q_vector->napi,
  9138. i40e_napi_poll, NAPI_POLL_WEIGHT);
  9139. /* tie q_vector and vsi together */
  9140. vsi->q_vectors[v_idx] = q_vector;
  9141. return 0;
  9142. }
  9143. /**
  9144. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  9145. * @vsi: the VSI being configured
  9146. *
  9147. * We allocate one q_vector per queue interrupt. If allocation fails we
  9148. * return -ENOMEM.
  9149. **/
  9150. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  9151. {
  9152. struct i40e_pf *pf = vsi->back;
  9153. int err, v_idx, num_q_vectors, current_cpu;
  9154. /* if not MSIX, give the one vector only to the LAN VSI */
  9155. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  9156. num_q_vectors = vsi->num_q_vectors;
  9157. else if (vsi == pf->vsi[pf->lan_vsi])
  9158. num_q_vectors = 1;
  9159. else
  9160. return -EINVAL;
  9161. current_cpu = cpumask_first(cpu_online_mask);
  9162. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  9163. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  9164. if (err)
  9165. goto err_out;
  9166. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  9167. if (unlikely(current_cpu >= nr_cpu_ids))
  9168. current_cpu = cpumask_first(cpu_online_mask);
  9169. }
  9170. return 0;
  9171. err_out:
  9172. while (v_idx--)
  9173. i40e_free_q_vector(vsi, v_idx);
  9174. return err;
  9175. }
  9176. /**
  9177. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  9178. * @pf: board private structure to initialize
  9179. **/
  9180. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  9181. {
  9182. int vectors = 0;
  9183. ssize_t size;
  9184. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9185. vectors = i40e_init_msix(pf);
  9186. if (vectors < 0) {
  9187. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  9188. I40E_FLAG_IWARP_ENABLED |
  9189. I40E_FLAG_RSS_ENABLED |
  9190. I40E_FLAG_DCB_CAPABLE |
  9191. I40E_FLAG_DCB_ENABLED |
  9192. I40E_FLAG_SRIOV_ENABLED |
  9193. I40E_FLAG_FD_SB_ENABLED |
  9194. I40E_FLAG_FD_ATR_ENABLED |
  9195. I40E_FLAG_VMDQ_ENABLED);
  9196. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9197. /* rework the queue expectations without MSIX */
  9198. i40e_determine_queue_usage(pf);
  9199. }
  9200. }
  9201. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9202. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  9203. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  9204. vectors = pci_enable_msi(pf->pdev);
  9205. if (vectors < 0) {
  9206. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  9207. vectors);
  9208. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  9209. }
  9210. vectors = 1; /* one MSI or Legacy vector */
  9211. }
  9212. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  9213. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  9214. /* set up vector assignment tracking */
  9215. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  9216. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  9217. if (!pf->irq_pile)
  9218. return -ENOMEM;
  9219. pf->irq_pile->num_entries = vectors;
  9220. pf->irq_pile->search_hint = 0;
  9221. /* track first vector for misc interrupts, ignore return */
  9222. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  9223. return 0;
  9224. }
  9225. /**
  9226. * i40e_restore_interrupt_scheme - Restore the interrupt scheme
  9227. * @pf: private board data structure
  9228. *
  9229. * Restore the interrupt scheme that was cleared when we suspended the
  9230. * device. This should be called during resume to re-allocate the q_vectors
  9231. * and reacquire IRQs.
  9232. */
  9233. static int i40e_restore_interrupt_scheme(struct i40e_pf *pf)
  9234. {
  9235. int err, i;
  9236. /* We cleared the MSI and MSI-X flags when disabling the old interrupt
  9237. * scheme. We need to re-enabled them here in order to attempt to
  9238. * re-acquire the MSI or MSI-X vectors
  9239. */
  9240. pf->flags |= (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  9241. err = i40e_init_interrupt_scheme(pf);
  9242. if (err)
  9243. return err;
  9244. /* Now that we've re-acquired IRQs, we need to remap the vectors and
  9245. * rings together again.
  9246. */
  9247. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9248. if (pf->vsi[i]) {
  9249. err = i40e_vsi_alloc_q_vectors(pf->vsi[i]);
  9250. if (err)
  9251. goto err_unwind;
  9252. i40e_vsi_map_rings_to_vectors(pf->vsi[i]);
  9253. }
  9254. }
  9255. err = i40e_setup_misc_vector(pf);
  9256. if (err)
  9257. goto err_unwind;
  9258. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  9259. i40e_client_update_msix_info(pf);
  9260. return 0;
  9261. err_unwind:
  9262. while (i--) {
  9263. if (pf->vsi[i])
  9264. i40e_vsi_free_q_vectors(pf->vsi[i]);
  9265. }
  9266. return err;
  9267. }
  9268. /**
  9269. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  9270. * @pf: board private structure
  9271. *
  9272. * This sets up the handler for MSIX 0, which is used to manage the
  9273. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  9274. * when in MSI or Legacy interrupt mode.
  9275. **/
  9276. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  9277. {
  9278. struct i40e_hw *hw = &pf->hw;
  9279. int err = 0;
  9280. /* Only request the IRQ once, the first time through. */
  9281. if (!test_and_set_bit(__I40E_MISC_IRQ_REQUESTED, pf->state)) {
  9282. err = request_irq(pf->msix_entries[0].vector,
  9283. i40e_intr, 0, pf->int_name, pf);
  9284. if (err) {
  9285. clear_bit(__I40E_MISC_IRQ_REQUESTED, pf->state);
  9286. dev_info(&pf->pdev->dev,
  9287. "request_irq for %s failed: %d\n",
  9288. pf->int_name, err);
  9289. return -EFAULT;
  9290. }
  9291. }
  9292. i40e_enable_misc_int_causes(pf);
  9293. /* associate no queues to the misc vector */
  9294. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  9295. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  9296. i40e_flush(hw);
  9297. i40e_irq_dynamic_enable_icr0(pf);
  9298. return err;
  9299. }
  9300. /**
  9301. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  9302. * @vsi: Pointer to vsi structure
  9303. * @seed: Buffter to store the hash keys
  9304. * @lut: Buffer to store the lookup table entries
  9305. * @lut_size: Size of buffer to store the lookup table entries
  9306. *
  9307. * Return 0 on success, negative on failure
  9308. */
  9309. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  9310. u8 *lut, u16 lut_size)
  9311. {
  9312. struct i40e_pf *pf = vsi->back;
  9313. struct i40e_hw *hw = &pf->hw;
  9314. int ret = 0;
  9315. if (seed) {
  9316. ret = i40e_aq_get_rss_key(hw, vsi->id,
  9317. (struct i40e_aqc_get_set_rss_key_data *)seed);
  9318. if (ret) {
  9319. dev_info(&pf->pdev->dev,
  9320. "Cannot get RSS key, err %s aq_err %s\n",
  9321. i40e_stat_str(&pf->hw, ret),
  9322. i40e_aq_str(&pf->hw,
  9323. pf->hw.aq.asq_last_status));
  9324. return ret;
  9325. }
  9326. }
  9327. if (lut) {
  9328. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  9329. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  9330. if (ret) {
  9331. dev_info(&pf->pdev->dev,
  9332. "Cannot get RSS lut, err %s aq_err %s\n",
  9333. i40e_stat_str(&pf->hw, ret),
  9334. i40e_aq_str(&pf->hw,
  9335. pf->hw.aq.asq_last_status));
  9336. return ret;
  9337. }
  9338. }
  9339. return ret;
  9340. }
  9341. /**
  9342. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  9343. * @vsi: Pointer to vsi structure
  9344. * @seed: RSS hash seed
  9345. * @lut: Lookup table
  9346. * @lut_size: Lookup table size
  9347. *
  9348. * Returns 0 on success, negative on failure
  9349. **/
  9350. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  9351. const u8 *lut, u16 lut_size)
  9352. {
  9353. struct i40e_pf *pf = vsi->back;
  9354. struct i40e_hw *hw = &pf->hw;
  9355. u16 vf_id = vsi->vf_id;
  9356. u8 i;
  9357. /* Fill out hash function seed */
  9358. if (seed) {
  9359. u32 *seed_dw = (u32 *)seed;
  9360. if (vsi->type == I40E_VSI_MAIN) {
  9361. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9362. wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  9363. } else if (vsi->type == I40E_VSI_SRIOV) {
  9364. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  9365. wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
  9366. } else {
  9367. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  9368. }
  9369. }
  9370. if (lut) {
  9371. u32 *lut_dw = (u32 *)lut;
  9372. if (vsi->type == I40E_VSI_MAIN) {
  9373. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9374. return -EINVAL;
  9375. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9376. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  9377. } else if (vsi->type == I40E_VSI_SRIOV) {
  9378. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  9379. return -EINVAL;
  9380. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9381. wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
  9382. } else {
  9383. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9384. }
  9385. }
  9386. i40e_flush(hw);
  9387. return 0;
  9388. }
  9389. /**
  9390. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  9391. * @vsi: Pointer to VSI structure
  9392. * @seed: Buffer to store the keys
  9393. * @lut: Buffer to store the lookup table entries
  9394. * @lut_size: Size of buffer to store the lookup table entries
  9395. *
  9396. * Returns 0 on success, negative on failure
  9397. */
  9398. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  9399. u8 *lut, u16 lut_size)
  9400. {
  9401. struct i40e_pf *pf = vsi->back;
  9402. struct i40e_hw *hw = &pf->hw;
  9403. u16 i;
  9404. if (seed) {
  9405. u32 *seed_dw = (u32 *)seed;
  9406. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  9407. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  9408. }
  9409. if (lut) {
  9410. u32 *lut_dw = (u32 *)lut;
  9411. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  9412. return -EINVAL;
  9413. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9414. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  9415. }
  9416. return 0;
  9417. }
  9418. /**
  9419. * i40e_config_rss - Configure RSS keys and lut
  9420. * @vsi: Pointer to VSI structure
  9421. * @seed: RSS hash seed
  9422. * @lut: Lookup table
  9423. * @lut_size: Lookup table size
  9424. *
  9425. * Returns 0 on success, negative on failure
  9426. */
  9427. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9428. {
  9429. struct i40e_pf *pf = vsi->back;
  9430. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9431. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  9432. else
  9433. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  9434. }
  9435. /**
  9436. * i40e_get_rss - Get RSS keys and lut
  9437. * @vsi: Pointer to VSI structure
  9438. * @seed: Buffer to store the keys
  9439. * @lut: Buffer to store the lookup table entries
  9440. * @lut_size: Size of buffer to store the lookup table entries
  9441. *
  9442. * Returns 0 on success, negative on failure
  9443. */
  9444. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  9445. {
  9446. struct i40e_pf *pf = vsi->back;
  9447. if (pf->hw_features & I40E_HW_RSS_AQ_CAPABLE)
  9448. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  9449. else
  9450. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  9451. }
  9452. /**
  9453. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  9454. * @pf: Pointer to board private structure
  9455. * @lut: Lookup table
  9456. * @rss_table_size: Lookup table size
  9457. * @rss_size: Range of queue number for hashing
  9458. */
  9459. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  9460. u16 rss_table_size, u16 rss_size)
  9461. {
  9462. u16 i;
  9463. for (i = 0; i < rss_table_size; i++)
  9464. lut[i] = i % rss_size;
  9465. }
  9466. /**
  9467. * i40e_pf_config_rss - Prepare for RSS if used
  9468. * @pf: board private structure
  9469. **/
  9470. static int i40e_pf_config_rss(struct i40e_pf *pf)
  9471. {
  9472. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9473. u8 seed[I40E_HKEY_ARRAY_SIZE];
  9474. u8 *lut;
  9475. struct i40e_hw *hw = &pf->hw;
  9476. u32 reg_val;
  9477. u64 hena;
  9478. int ret;
  9479. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  9480. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  9481. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  9482. hena |= i40e_pf_get_default_rss_hena(pf);
  9483. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  9484. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  9485. /* Determine the RSS table size based on the hardware capabilities */
  9486. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  9487. reg_val = (pf->rss_table_size == 512) ?
  9488. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  9489. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  9490. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  9491. /* Determine the RSS size of the VSI */
  9492. if (!vsi->rss_size) {
  9493. u16 qcount;
  9494. /* If the firmware does something weird during VSI init, we
  9495. * could end up with zero TCs. Check for that to avoid
  9496. * divide-by-zero. It probably won't pass traffic, but it also
  9497. * won't panic.
  9498. */
  9499. qcount = vsi->num_queue_pairs /
  9500. (vsi->tc_config.numtc ? vsi->tc_config.numtc : 1);
  9501. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9502. }
  9503. if (!vsi->rss_size)
  9504. return -EINVAL;
  9505. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  9506. if (!lut)
  9507. return -ENOMEM;
  9508. /* Use user configured lut if there is one, otherwise use default */
  9509. if (vsi->rss_lut_user)
  9510. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  9511. else
  9512. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  9513. /* Use user configured hash key if there is one, otherwise
  9514. * use default.
  9515. */
  9516. if (vsi->rss_hkey_user)
  9517. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  9518. else
  9519. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  9520. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  9521. kfree(lut);
  9522. return ret;
  9523. }
  9524. /**
  9525. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  9526. * @pf: board private structure
  9527. * @queue_count: the requested queue count for rss.
  9528. *
  9529. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  9530. * count which may be different from the requested queue count.
  9531. * Note: expects to be called while under rtnl_lock()
  9532. **/
  9533. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  9534. {
  9535. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  9536. int new_rss_size;
  9537. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  9538. return 0;
  9539. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  9540. if (queue_count != vsi->num_queue_pairs) {
  9541. u16 qcount;
  9542. vsi->req_queue_pairs = queue_count;
  9543. i40e_prep_for_reset(pf, true);
  9544. pf->alloc_rss_size = new_rss_size;
  9545. i40e_reset_and_rebuild(pf, true, true);
  9546. /* Discard the user configured hash keys and lut, if less
  9547. * queues are enabled.
  9548. */
  9549. if (queue_count < vsi->rss_size) {
  9550. i40e_clear_rss_config_user(vsi);
  9551. dev_dbg(&pf->pdev->dev,
  9552. "discard user configured hash keys and lut\n");
  9553. }
  9554. /* Reset vsi->rss_size, as number of enabled queues changed */
  9555. qcount = vsi->num_queue_pairs / vsi->tc_config.numtc;
  9556. vsi->rss_size = min_t(int, pf->alloc_rss_size, qcount);
  9557. i40e_pf_config_rss(pf);
  9558. }
  9559. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  9560. vsi->req_queue_pairs, pf->rss_size_max);
  9561. return pf->alloc_rss_size;
  9562. }
  9563. /**
  9564. * i40e_get_partition_bw_setting - Retrieve BW settings for this PF partition
  9565. * @pf: board private structure
  9566. **/
  9567. i40e_status i40e_get_partition_bw_setting(struct i40e_pf *pf)
  9568. {
  9569. i40e_status status;
  9570. bool min_valid, max_valid;
  9571. u32 max_bw, min_bw;
  9572. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  9573. &min_valid, &max_valid);
  9574. if (!status) {
  9575. if (min_valid)
  9576. pf->min_bw = min_bw;
  9577. if (max_valid)
  9578. pf->max_bw = max_bw;
  9579. }
  9580. return status;
  9581. }
  9582. /**
  9583. * i40e_set_partition_bw_setting - Set BW settings for this PF partition
  9584. * @pf: board private structure
  9585. **/
  9586. i40e_status i40e_set_partition_bw_setting(struct i40e_pf *pf)
  9587. {
  9588. struct i40e_aqc_configure_partition_bw_data bw_data;
  9589. i40e_status status;
  9590. /* Set the valid bit for this PF */
  9591. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  9592. bw_data.max_bw[pf->hw.pf_id] = pf->max_bw & I40E_ALT_BW_VALUE_MASK;
  9593. bw_data.min_bw[pf->hw.pf_id] = pf->min_bw & I40E_ALT_BW_VALUE_MASK;
  9594. /* Set the new bandwidths */
  9595. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  9596. return status;
  9597. }
  9598. /**
  9599. * i40e_commit_partition_bw_setting - Commit BW settings for this PF partition
  9600. * @pf: board private structure
  9601. **/
  9602. i40e_status i40e_commit_partition_bw_setting(struct i40e_pf *pf)
  9603. {
  9604. /* Commit temporary BW setting to permanent NVM image */
  9605. enum i40e_admin_queue_err last_aq_status;
  9606. i40e_status ret;
  9607. u16 nvm_word;
  9608. if (pf->hw.partition_id != 1) {
  9609. dev_info(&pf->pdev->dev,
  9610. "Commit BW only works on partition 1! This is partition %d",
  9611. pf->hw.partition_id);
  9612. ret = I40E_NOT_SUPPORTED;
  9613. goto bw_commit_out;
  9614. }
  9615. /* Acquire NVM for read access */
  9616. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  9617. last_aq_status = pf->hw.aq.asq_last_status;
  9618. if (ret) {
  9619. dev_info(&pf->pdev->dev,
  9620. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  9621. i40e_stat_str(&pf->hw, ret),
  9622. i40e_aq_str(&pf->hw, last_aq_status));
  9623. goto bw_commit_out;
  9624. }
  9625. /* Read word 0x10 of NVM - SW compatibility word 1 */
  9626. ret = i40e_aq_read_nvm(&pf->hw,
  9627. I40E_SR_NVM_CONTROL_WORD,
  9628. 0x10, sizeof(nvm_word), &nvm_word,
  9629. false, NULL);
  9630. /* Save off last admin queue command status before releasing
  9631. * the NVM
  9632. */
  9633. last_aq_status = pf->hw.aq.asq_last_status;
  9634. i40e_release_nvm(&pf->hw);
  9635. if (ret) {
  9636. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  9637. i40e_stat_str(&pf->hw, ret),
  9638. i40e_aq_str(&pf->hw, last_aq_status));
  9639. goto bw_commit_out;
  9640. }
  9641. /* Wait a bit for NVM release to complete */
  9642. msleep(50);
  9643. /* Acquire NVM for write access */
  9644. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  9645. last_aq_status = pf->hw.aq.asq_last_status;
  9646. if (ret) {
  9647. dev_info(&pf->pdev->dev,
  9648. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  9649. i40e_stat_str(&pf->hw, ret),
  9650. i40e_aq_str(&pf->hw, last_aq_status));
  9651. goto bw_commit_out;
  9652. }
  9653. /* Write it back out unchanged to initiate update NVM,
  9654. * which will force a write of the shadow (alt) RAM to
  9655. * the NVM - thus storing the bandwidth values permanently.
  9656. */
  9657. ret = i40e_aq_update_nvm(&pf->hw,
  9658. I40E_SR_NVM_CONTROL_WORD,
  9659. 0x10, sizeof(nvm_word),
  9660. &nvm_word, true, 0, NULL);
  9661. /* Save off last admin queue command status before releasing
  9662. * the NVM
  9663. */
  9664. last_aq_status = pf->hw.aq.asq_last_status;
  9665. i40e_release_nvm(&pf->hw);
  9666. if (ret)
  9667. dev_info(&pf->pdev->dev,
  9668. "BW settings NOT SAVED, err %s aq_err %s\n",
  9669. i40e_stat_str(&pf->hw, ret),
  9670. i40e_aq_str(&pf->hw, last_aq_status));
  9671. bw_commit_out:
  9672. return ret;
  9673. }
  9674. /**
  9675. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  9676. * @pf: board private structure to initialize
  9677. *
  9678. * i40e_sw_init initializes the Adapter private data structure.
  9679. * Fields are initialized based on PCI device information and
  9680. * OS network device settings (MTU size).
  9681. **/
  9682. static int i40e_sw_init(struct i40e_pf *pf)
  9683. {
  9684. int err = 0;
  9685. int size;
  9686. /* Set default capability flags */
  9687. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  9688. I40E_FLAG_MSI_ENABLED |
  9689. I40E_FLAG_MSIX_ENABLED;
  9690. /* Set default ITR */
  9691. pf->rx_itr_default = I40E_ITR_RX_DEF;
  9692. pf->tx_itr_default = I40E_ITR_TX_DEF;
  9693. /* Depending on PF configurations, it is possible that the RSS
  9694. * maximum might end up larger than the available queues
  9695. */
  9696. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  9697. pf->alloc_rss_size = 1;
  9698. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  9699. pf->rss_size_max = min_t(int, pf->rss_size_max,
  9700. pf->hw.func_caps.num_tx_qp);
  9701. if (pf->hw.func_caps.rss) {
  9702. pf->flags |= I40E_FLAG_RSS_ENABLED;
  9703. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  9704. num_online_cpus());
  9705. }
  9706. /* MFP mode enabled */
  9707. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  9708. pf->flags |= I40E_FLAG_MFP_ENABLED;
  9709. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  9710. if (i40e_get_partition_bw_setting(pf)) {
  9711. dev_warn(&pf->pdev->dev,
  9712. "Could not get partition bw settings\n");
  9713. } else {
  9714. dev_info(&pf->pdev->dev,
  9715. "Partition BW Min = %8.8x, Max = %8.8x\n",
  9716. pf->min_bw, pf->max_bw);
  9717. /* nudge the Tx scheduler */
  9718. i40e_set_partition_bw_setting(pf);
  9719. }
  9720. }
  9721. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  9722. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  9723. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  9724. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  9725. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  9726. pf->hw.num_partitions > 1)
  9727. dev_info(&pf->pdev->dev,
  9728. "Flow Director Sideband mode Disabled in MFP mode\n");
  9729. else
  9730. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9731. pf->fdir_pf_filter_count =
  9732. pf->hw.func_caps.fd_filters_guaranteed;
  9733. pf->hw.fdir_shared_filter_count =
  9734. pf->hw.func_caps.fd_filters_best_effort;
  9735. }
  9736. if (pf->hw.mac.type == I40E_MAC_X722) {
  9737. pf->hw_features |= (I40E_HW_RSS_AQ_CAPABLE |
  9738. I40E_HW_128_QP_RSS_CAPABLE |
  9739. I40E_HW_ATR_EVICT_CAPABLE |
  9740. I40E_HW_WB_ON_ITR_CAPABLE |
  9741. I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  9742. I40E_HW_NO_PCI_LINK_CHECK |
  9743. I40E_HW_USE_SET_LLDP_MIB |
  9744. I40E_HW_GENEVE_OFFLOAD_CAPABLE |
  9745. I40E_HW_PTP_L4_CAPABLE |
  9746. I40E_HW_WOL_MC_MAGIC_PKT_WAKE |
  9747. I40E_HW_OUTER_UDP_CSUM_CAPABLE);
  9748. #define I40E_FDEVICT_PCTYPE_DEFAULT 0xc03
  9749. if (rd32(&pf->hw, I40E_GLQF_FDEVICTENA(1)) !=
  9750. I40E_FDEVICT_PCTYPE_DEFAULT) {
  9751. dev_warn(&pf->pdev->dev,
  9752. "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
  9753. pf->hw_features &= ~I40E_HW_ATR_EVICT_CAPABLE;
  9754. }
  9755. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  9756. ((pf->hw.aq.api_maj_ver == 1) &&
  9757. (pf->hw.aq.api_min_ver > 4))) {
  9758. /* Supported in FW API version higher than 1.4 */
  9759. pf->hw_features |= I40E_HW_GENEVE_OFFLOAD_CAPABLE;
  9760. }
  9761. /* Enable HW ATR eviction if possible */
  9762. if (pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE)
  9763. pf->flags |= I40E_FLAG_HW_ATR_EVICT_ENABLED;
  9764. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9765. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  9766. (pf->hw.aq.fw_maj_ver < 4))) {
  9767. pf->hw_features |= I40E_HW_RESTART_AUTONEG;
  9768. /* No DCB support for FW < v4.33 */
  9769. pf->hw_features |= I40E_HW_NO_DCB_SUPPORT;
  9770. }
  9771. /* Disable FW LLDP if FW < v4.3 */
  9772. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9773. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  9774. (pf->hw.aq.fw_maj_ver < 4)))
  9775. pf->hw_features |= I40E_HW_STOP_FW_LLDP;
  9776. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  9777. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  9778. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  9779. (pf->hw.aq.fw_maj_ver >= 5)))
  9780. pf->hw_features |= I40E_HW_USE_SET_LLDP_MIB;
  9781. /* Enable PTP L4 if FW > v6.0 */
  9782. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9783. pf->hw.aq.fw_maj_ver >= 6)
  9784. pf->hw_features |= I40E_HW_PTP_L4_CAPABLE;
  9785. if (pf->hw.func_caps.vmdq && num_online_cpus() != 1) {
  9786. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  9787. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  9788. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  9789. }
  9790. if (pf->hw.func_caps.iwarp && num_online_cpus() != 1) {
  9791. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  9792. /* IWARP needs one extra vector for CQP just like MISC.*/
  9793. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  9794. }
  9795. /* Stopping the FW LLDP engine is only supported on the
  9796. * XL710 with a FW ver >= 1.7. Also, stopping FW LLDP
  9797. * engine is not supported if NPAR is functioning on this
  9798. * part
  9799. */
  9800. if (pf->hw.mac.type == I40E_MAC_XL710 &&
  9801. !pf->hw.func_caps.npar_enable &&
  9802. (pf->hw.aq.api_maj_ver > 1 ||
  9803. (pf->hw.aq.api_maj_ver == 1 && pf->hw.aq.api_min_ver > 6)))
  9804. pf->hw_features |= I40E_HW_STOPPABLE_FW_LLDP;
  9805. #ifdef CONFIG_PCI_IOV
  9806. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  9807. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  9808. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  9809. pf->num_req_vfs = min_t(int,
  9810. pf->hw.func_caps.num_vfs,
  9811. I40E_MAX_VF_COUNT);
  9812. }
  9813. #endif /* CONFIG_PCI_IOV */
  9814. pf->eeprom_version = 0xDEAD;
  9815. pf->lan_veb = I40E_NO_VEB;
  9816. pf->lan_vsi = I40E_NO_VSI;
  9817. /* By default FW has this off for performance reasons */
  9818. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  9819. /* set up queue assignment tracking */
  9820. size = sizeof(struct i40e_lump_tracking)
  9821. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  9822. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  9823. if (!pf->qp_pile) {
  9824. err = -ENOMEM;
  9825. goto sw_init_done;
  9826. }
  9827. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  9828. pf->qp_pile->search_hint = 0;
  9829. pf->tx_timeout_recovery_level = 1;
  9830. mutex_init(&pf->switch_mutex);
  9831. sw_init_done:
  9832. return err;
  9833. }
  9834. /**
  9835. * i40e_set_ntuple - set the ntuple feature flag and take action
  9836. * @pf: board private structure to initialize
  9837. * @features: the feature set that the stack is suggesting
  9838. *
  9839. * returns a bool to indicate if reset needs to happen
  9840. **/
  9841. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  9842. {
  9843. bool need_reset = false;
  9844. /* Check if Flow Director n-tuple support was enabled or disabled. If
  9845. * the state changed, we need to reset.
  9846. */
  9847. if (features & NETIF_F_NTUPLE) {
  9848. /* Enable filters and mark for reset */
  9849. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  9850. need_reset = true;
  9851. /* enable FD_SB only if there is MSI-X vector and no cloud
  9852. * filters exist
  9853. */
  9854. if (pf->num_fdsb_msix > 0 && !pf->num_cloud_filters) {
  9855. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  9856. pf->flags &= ~I40E_FLAG_FD_SB_INACTIVE;
  9857. }
  9858. } else {
  9859. /* turn off filters, mark for reset and clear SW filter list */
  9860. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9861. need_reset = true;
  9862. i40e_fdir_filter_exit(pf);
  9863. }
  9864. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9865. clear_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state);
  9866. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  9867. /* reset fd counters */
  9868. pf->fd_add_err = 0;
  9869. pf->fd_atr_cnt = 0;
  9870. /* if ATR was auto disabled it can be re-enabled. */
  9871. if (test_and_clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
  9872. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  9873. (I40E_DEBUG_FD & pf->hw.debug_mask))
  9874. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  9875. }
  9876. return need_reset;
  9877. }
  9878. /**
  9879. * i40e_clear_rss_lut - clear the rx hash lookup table
  9880. * @vsi: the VSI being configured
  9881. **/
  9882. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  9883. {
  9884. struct i40e_pf *pf = vsi->back;
  9885. struct i40e_hw *hw = &pf->hw;
  9886. u16 vf_id = vsi->vf_id;
  9887. u8 i;
  9888. if (vsi->type == I40E_VSI_MAIN) {
  9889. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  9890. wr32(hw, I40E_PFQF_HLUT(i), 0);
  9891. } else if (vsi->type == I40E_VSI_SRIOV) {
  9892. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  9893. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  9894. } else {
  9895. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  9896. }
  9897. }
  9898. /**
  9899. * i40e_set_features - set the netdev feature flags
  9900. * @netdev: ptr to the netdev being adjusted
  9901. * @features: the feature set that the stack is suggesting
  9902. * Note: expects to be called while under rtnl_lock()
  9903. **/
  9904. static int i40e_set_features(struct net_device *netdev,
  9905. netdev_features_t features)
  9906. {
  9907. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9908. struct i40e_vsi *vsi = np->vsi;
  9909. struct i40e_pf *pf = vsi->back;
  9910. bool need_reset;
  9911. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  9912. i40e_pf_config_rss(pf);
  9913. else if (!(features & NETIF_F_RXHASH) &&
  9914. netdev->features & NETIF_F_RXHASH)
  9915. i40e_clear_rss_lut(vsi);
  9916. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  9917. i40e_vlan_stripping_enable(vsi);
  9918. else
  9919. i40e_vlan_stripping_disable(vsi);
  9920. if (!(features & NETIF_F_HW_TC) && pf->num_cloud_filters) {
  9921. dev_err(&pf->pdev->dev,
  9922. "Offloaded tc filters active, can't turn hw_tc_offload off");
  9923. return -EINVAL;
  9924. }
  9925. need_reset = i40e_set_ntuple(pf, features);
  9926. if (need_reset)
  9927. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  9928. return 0;
  9929. }
  9930. /**
  9931. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  9932. * @pf: board private structure
  9933. * @port: The UDP port to look up
  9934. *
  9935. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  9936. **/
  9937. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, u16 port)
  9938. {
  9939. u8 i;
  9940. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  9941. if (pf->udp_ports[i].port == port)
  9942. return i;
  9943. }
  9944. return i;
  9945. }
  9946. /**
  9947. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  9948. * @netdev: This physical port's netdev
  9949. * @ti: Tunnel endpoint information
  9950. **/
  9951. static void i40e_udp_tunnel_add(struct net_device *netdev,
  9952. struct udp_tunnel_info *ti)
  9953. {
  9954. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9955. struct i40e_vsi *vsi = np->vsi;
  9956. struct i40e_pf *pf = vsi->back;
  9957. u16 port = ntohs(ti->port);
  9958. u8 next_idx;
  9959. u8 idx;
  9960. idx = i40e_get_udp_port_idx(pf, port);
  9961. /* Check if port already exists */
  9962. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9963. netdev_info(netdev, "port %d already offloaded\n", port);
  9964. return;
  9965. }
  9966. /* Now check if there is space to add the new port */
  9967. next_idx = i40e_get_udp_port_idx(pf, 0);
  9968. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  9969. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  9970. port);
  9971. return;
  9972. }
  9973. switch (ti->type) {
  9974. case UDP_TUNNEL_TYPE_VXLAN:
  9975. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  9976. break;
  9977. case UDP_TUNNEL_TYPE_GENEVE:
  9978. if (!(pf->hw_features & I40E_HW_GENEVE_OFFLOAD_CAPABLE))
  9979. return;
  9980. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  9981. break;
  9982. default:
  9983. return;
  9984. }
  9985. /* New port: add it and mark its index in the bitmap */
  9986. pf->udp_ports[next_idx].port = port;
  9987. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  9988. set_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state);
  9989. }
  9990. /**
  9991. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  9992. * @netdev: This physical port's netdev
  9993. * @ti: Tunnel endpoint information
  9994. **/
  9995. static void i40e_udp_tunnel_del(struct net_device *netdev,
  9996. struct udp_tunnel_info *ti)
  9997. {
  9998. struct i40e_netdev_priv *np = netdev_priv(netdev);
  9999. struct i40e_vsi *vsi = np->vsi;
  10000. struct i40e_pf *pf = vsi->back;
  10001. u16 port = ntohs(ti->port);
  10002. u8 idx;
  10003. idx = i40e_get_udp_port_idx(pf, port);
  10004. /* Check if port already exists */
  10005. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  10006. goto not_found;
  10007. switch (ti->type) {
  10008. case UDP_TUNNEL_TYPE_VXLAN:
  10009. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  10010. goto not_found;
  10011. break;
  10012. case UDP_TUNNEL_TYPE_GENEVE:
  10013. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  10014. goto not_found;
  10015. break;
  10016. default:
  10017. goto not_found;
  10018. }
  10019. /* if port exists, set it to 0 (mark for deletion)
  10020. * and make it pending
  10021. */
  10022. pf->udp_ports[idx].port = 0;
  10023. pf->pending_udp_bitmap |= BIT_ULL(idx);
  10024. set_bit(__I40E_UDP_FILTER_SYNC_PENDING, pf->state);
  10025. return;
  10026. not_found:
  10027. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  10028. port);
  10029. }
  10030. static int i40e_get_phys_port_id(struct net_device *netdev,
  10031. struct netdev_phys_item_id *ppid)
  10032. {
  10033. struct i40e_netdev_priv *np = netdev_priv(netdev);
  10034. struct i40e_pf *pf = np->vsi->back;
  10035. struct i40e_hw *hw = &pf->hw;
  10036. if (!(pf->hw_features & I40E_HW_PORT_ID_VALID))
  10037. return -EOPNOTSUPP;
  10038. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  10039. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  10040. return 0;
  10041. }
  10042. /**
  10043. * i40e_ndo_fdb_add - add an entry to the hardware database
  10044. * @ndm: the input from the stack
  10045. * @tb: pointer to array of nladdr (unused)
  10046. * @dev: the net device pointer
  10047. * @addr: the MAC address entry being added
  10048. * @vid: VLAN ID
  10049. * @flags: instructions from stack about fdb operation
  10050. */
  10051. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  10052. struct net_device *dev,
  10053. const unsigned char *addr, u16 vid,
  10054. u16 flags)
  10055. {
  10056. struct i40e_netdev_priv *np = netdev_priv(dev);
  10057. struct i40e_pf *pf = np->vsi->back;
  10058. int err = 0;
  10059. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  10060. return -EOPNOTSUPP;
  10061. if (vid) {
  10062. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  10063. return -EINVAL;
  10064. }
  10065. /* Hardware does not support aging addresses so if a
  10066. * ndm_state is given only allow permanent addresses
  10067. */
  10068. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  10069. netdev_info(dev, "FDB only supports static addresses\n");
  10070. return -EINVAL;
  10071. }
  10072. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  10073. err = dev_uc_add_excl(dev, addr);
  10074. else if (is_multicast_ether_addr(addr))
  10075. err = dev_mc_add_excl(dev, addr);
  10076. else
  10077. err = -EINVAL;
  10078. /* Only return duplicate errors if NLM_F_EXCL is set */
  10079. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  10080. err = 0;
  10081. return err;
  10082. }
  10083. /**
  10084. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  10085. * @dev: the netdev being configured
  10086. * @nlh: RTNL message
  10087. * @flags: bridge flags
  10088. *
  10089. * Inserts a new hardware bridge if not already created and
  10090. * enables the bridging mode requested (VEB or VEPA). If the
  10091. * hardware bridge has already been inserted and the request
  10092. * is to change the mode then that requires a PF reset to
  10093. * allow rebuild of the components with required hardware
  10094. * bridge mode enabled.
  10095. *
  10096. * Note: expects to be called while under rtnl_lock()
  10097. **/
  10098. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  10099. struct nlmsghdr *nlh,
  10100. u16 flags)
  10101. {
  10102. struct i40e_netdev_priv *np = netdev_priv(dev);
  10103. struct i40e_vsi *vsi = np->vsi;
  10104. struct i40e_pf *pf = vsi->back;
  10105. struct i40e_veb *veb = NULL;
  10106. struct nlattr *attr, *br_spec;
  10107. int i, rem;
  10108. /* Only for PF VSI for now */
  10109. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10110. return -EOPNOTSUPP;
  10111. /* Find the HW bridge for PF VSI */
  10112. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10113. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10114. veb = pf->veb[i];
  10115. }
  10116. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  10117. nla_for_each_nested(attr, br_spec, rem) {
  10118. __u16 mode;
  10119. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  10120. continue;
  10121. mode = nla_get_u16(attr);
  10122. if ((mode != BRIDGE_MODE_VEPA) &&
  10123. (mode != BRIDGE_MODE_VEB))
  10124. return -EINVAL;
  10125. /* Insert a new HW bridge */
  10126. if (!veb) {
  10127. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10128. vsi->tc_config.enabled_tc);
  10129. if (veb) {
  10130. veb->bridge_mode = mode;
  10131. i40e_config_bridge_mode(veb);
  10132. } else {
  10133. /* No Bridge HW offload available */
  10134. return -ENOENT;
  10135. }
  10136. break;
  10137. } else if (mode != veb->bridge_mode) {
  10138. /* Existing HW bridge but different mode needs reset */
  10139. veb->bridge_mode = mode;
  10140. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  10141. if (mode == BRIDGE_MODE_VEB)
  10142. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  10143. else
  10144. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10145. i40e_do_reset(pf, I40E_PF_RESET_FLAG, true);
  10146. break;
  10147. }
  10148. }
  10149. return 0;
  10150. }
  10151. /**
  10152. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  10153. * @skb: skb buff
  10154. * @pid: process id
  10155. * @seq: RTNL message seq #
  10156. * @dev: the netdev being configured
  10157. * @filter_mask: unused
  10158. * @nlflags: netlink flags passed in
  10159. *
  10160. * Return the mode in which the hardware bridge is operating in
  10161. * i.e VEB or VEPA.
  10162. **/
  10163. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  10164. struct net_device *dev,
  10165. u32 __always_unused filter_mask,
  10166. int nlflags)
  10167. {
  10168. struct i40e_netdev_priv *np = netdev_priv(dev);
  10169. struct i40e_vsi *vsi = np->vsi;
  10170. struct i40e_pf *pf = vsi->back;
  10171. struct i40e_veb *veb = NULL;
  10172. int i;
  10173. /* Only for PF VSI for now */
  10174. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  10175. return -EOPNOTSUPP;
  10176. /* Find the HW bridge for the PF VSI */
  10177. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10178. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10179. veb = pf->veb[i];
  10180. }
  10181. if (!veb)
  10182. return 0;
  10183. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  10184. 0, 0, nlflags, filter_mask, NULL);
  10185. }
  10186. /**
  10187. * i40e_features_check - Validate encapsulated packet conforms to limits
  10188. * @skb: skb buff
  10189. * @dev: This physical port's netdev
  10190. * @features: Offload features that the stack believes apply
  10191. **/
  10192. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  10193. struct net_device *dev,
  10194. netdev_features_t features)
  10195. {
  10196. size_t len;
  10197. /* No point in doing any of this if neither checksum nor GSO are
  10198. * being requested for this frame. We can rule out both by just
  10199. * checking for CHECKSUM_PARTIAL
  10200. */
  10201. if (skb->ip_summed != CHECKSUM_PARTIAL)
  10202. return features;
  10203. /* We cannot support GSO if the MSS is going to be less than
  10204. * 64 bytes. If it is then we need to drop support for GSO.
  10205. */
  10206. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  10207. features &= ~NETIF_F_GSO_MASK;
  10208. /* MACLEN can support at most 63 words */
  10209. len = skb_network_header(skb) - skb->data;
  10210. if (len & ~(63 * 2))
  10211. goto out_err;
  10212. /* IPLEN and EIPLEN can support at most 127 dwords */
  10213. len = skb_transport_header(skb) - skb_network_header(skb);
  10214. if (len & ~(127 * 4))
  10215. goto out_err;
  10216. if (skb->encapsulation) {
  10217. /* L4TUNLEN can support 127 words */
  10218. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  10219. if (len & ~(127 * 2))
  10220. goto out_err;
  10221. /* IPLEN can support at most 127 dwords */
  10222. len = skb_inner_transport_header(skb) -
  10223. skb_inner_network_header(skb);
  10224. if (len & ~(127 * 4))
  10225. goto out_err;
  10226. }
  10227. /* No need to validate L4LEN as TCP is the only protocol with a
  10228. * a flexible value and we support all possible values supported
  10229. * by TCP, which is at most 15 dwords
  10230. */
  10231. return features;
  10232. out_err:
  10233. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  10234. }
  10235. /**
  10236. * i40e_xdp_setup - add/remove an XDP program
  10237. * @vsi: VSI to changed
  10238. * @prog: XDP program
  10239. **/
  10240. static int i40e_xdp_setup(struct i40e_vsi *vsi,
  10241. struct bpf_prog *prog)
  10242. {
  10243. int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  10244. struct i40e_pf *pf = vsi->back;
  10245. struct bpf_prog *old_prog;
  10246. bool need_reset;
  10247. int i;
  10248. /* Don't allow frames that span over multiple buffers */
  10249. if (frame_size > vsi->rx_buf_len)
  10250. return -EINVAL;
  10251. if (!i40e_enabled_xdp_vsi(vsi) && !prog)
  10252. return 0;
  10253. /* When turning XDP on->off/off->on we reset and rebuild the rings. */
  10254. need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog);
  10255. if (need_reset)
  10256. i40e_prep_for_reset(pf, true);
  10257. old_prog = xchg(&vsi->xdp_prog, prog);
  10258. if (need_reset)
  10259. i40e_reset_and_rebuild(pf, true, true);
  10260. for (i = 0; i < vsi->num_queue_pairs; i++)
  10261. WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
  10262. if (old_prog)
  10263. bpf_prog_put(old_prog);
  10264. return 0;
  10265. }
  10266. /**
  10267. * i40e_xdp - implements ndo_bpf for i40e
  10268. * @dev: netdevice
  10269. * @xdp: XDP command
  10270. **/
  10271. static int i40e_xdp(struct net_device *dev,
  10272. struct netdev_bpf *xdp)
  10273. {
  10274. struct i40e_netdev_priv *np = netdev_priv(dev);
  10275. struct i40e_vsi *vsi = np->vsi;
  10276. if (vsi->type != I40E_VSI_MAIN)
  10277. return -EINVAL;
  10278. switch (xdp->command) {
  10279. case XDP_SETUP_PROG:
  10280. return i40e_xdp_setup(vsi, xdp->prog);
  10281. case XDP_QUERY_PROG:
  10282. xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
  10283. xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
  10284. return 0;
  10285. default:
  10286. return -EINVAL;
  10287. }
  10288. }
  10289. static const struct net_device_ops i40e_netdev_ops = {
  10290. .ndo_open = i40e_open,
  10291. .ndo_stop = i40e_close,
  10292. .ndo_start_xmit = i40e_lan_xmit_frame,
  10293. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  10294. .ndo_set_rx_mode = i40e_set_rx_mode,
  10295. .ndo_validate_addr = eth_validate_addr,
  10296. .ndo_set_mac_address = i40e_set_mac,
  10297. .ndo_change_mtu = i40e_change_mtu,
  10298. .ndo_do_ioctl = i40e_ioctl,
  10299. .ndo_tx_timeout = i40e_tx_timeout,
  10300. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  10301. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  10302. #ifdef CONFIG_NET_POLL_CONTROLLER
  10303. .ndo_poll_controller = i40e_netpoll,
  10304. #endif
  10305. .ndo_setup_tc = __i40e_setup_tc,
  10306. .ndo_set_features = i40e_set_features,
  10307. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  10308. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  10309. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  10310. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  10311. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  10312. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  10313. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  10314. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  10315. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  10316. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  10317. .ndo_fdb_add = i40e_ndo_fdb_add,
  10318. .ndo_features_check = i40e_features_check,
  10319. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  10320. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  10321. .ndo_bpf = i40e_xdp,
  10322. .ndo_xdp_xmit = i40e_xdp_xmit,
  10323. .ndo_xdp_flush = i40e_xdp_flush,
  10324. };
  10325. /**
  10326. * i40e_config_netdev - Setup the netdev flags
  10327. * @vsi: the VSI being configured
  10328. *
  10329. * Returns 0 on success, negative value on failure
  10330. **/
  10331. static int i40e_config_netdev(struct i40e_vsi *vsi)
  10332. {
  10333. struct i40e_pf *pf = vsi->back;
  10334. struct i40e_hw *hw = &pf->hw;
  10335. struct i40e_netdev_priv *np;
  10336. struct net_device *netdev;
  10337. u8 broadcast[ETH_ALEN];
  10338. u8 mac_addr[ETH_ALEN];
  10339. int etherdev_size;
  10340. netdev_features_t hw_enc_features;
  10341. netdev_features_t hw_features;
  10342. etherdev_size = sizeof(struct i40e_netdev_priv);
  10343. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  10344. if (!netdev)
  10345. return -ENOMEM;
  10346. vsi->netdev = netdev;
  10347. np = netdev_priv(netdev);
  10348. np->vsi = vsi;
  10349. hw_enc_features = NETIF_F_SG |
  10350. NETIF_F_IP_CSUM |
  10351. NETIF_F_IPV6_CSUM |
  10352. NETIF_F_HIGHDMA |
  10353. NETIF_F_SOFT_FEATURES |
  10354. NETIF_F_TSO |
  10355. NETIF_F_TSO_ECN |
  10356. NETIF_F_TSO6 |
  10357. NETIF_F_GSO_GRE |
  10358. NETIF_F_GSO_GRE_CSUM |
  10359. NETIF_F_GSO_PARTIAL |
  10360. NETIF_F_GSO_UDP_TUNNEL |
  10361. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  10362. NETIF_F_SCTP_CRC |
  10363. NETIF_F_RXHASH |
  10364. NETIF_F_RXCSUM |
  10365. 0;
  10366. if (!(pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE))
  10367. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  10368. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  10369. netdev->hw_enc_features |= hw_enc_features;
  10370. /* record features VLANs can make use of */
  10371. netdev->vlan_features |= hw_enc_features | NETIF_F_TSO_MANGLEID;
  10372. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  10373. netdev->hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC;
  10374. hw_features = hw_enc_features |
  10375. NETIF_F_HW_VLAN_CTAG_TX |
  10376. NETIF_F_HW_VLAN_CTAG_RX;
  10377. netdev->hw_features |= hw_features;
  10378. netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  10379. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  10380. if (vsi->type == I40E_VSI_MAIN) {
  10381. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  10382. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  10383. /* The following steps are necessary for two reasons. First,
  10384. * some older NVM configurations load a default MAC-VLAN
  10385. * filter that will accept any tagged packet, and we want to
  10386. * replace this with a normal filter. Additionally, it is
  10387. * possible our MAC address was provided by the platform using
  10388. * Open Firmware or similar.
  10389. *
  10390. * Thus, we need to remove the default filter and install one
  10391. * specific to the MAC address.
  10392. */
  10393. i40e_rm_default_mac_filter(vsi, mac_addr);
  10394. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10395. i40e_add_mac_filter(vsi, mac_addr);
  10396. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10397. } else {
  10398. /* Relate the VSI_VMDQ name to the VSI_MAIN name. Note that we
  10399. * are still limited by IFNAMSIZ, but we're adding 'v%d\0' to
  10400. * the end, which is 4 bytes long, so force truncation of the
  10401. * original name by IFNAMSIZ - 4
  10402. */
  10403. snprintf(netdev->name, IFNAMSIZ, "%.*sv%%d",
  10404. IFNAMSIZ - 4,
  10405. pf->vsi[pf->lan_vsi]->netdev->name);
  10406. random_ether_addr(mac_addr);
  10407. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10408. i40e_add_mac_filter(vsi, mac_addr);
  10409. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10410. }
  10411. /* Add the broadcast filter so that we initially will receive
  10412. * broadcast packets. Note that when a new VLAN is first added the
  10413. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  10414. * specific filters as part of transitioning into "vlan" operation.
  10415. * When more VLANs are added, the driver will copy each existing MAC
  10416. * filter and add it for the new VLAN.
  10417. *
  10418. * Broadcast filters are handled specially by
  10419. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  10420. * promiscuous bit instead of adding this directly as a MAC/VLAN
  10421. * filter. The subtask will update the correct broadcast promiscuous
  10422. * bits as VLANs become active or inactive.
  10423. */
  10424. eth_broadcast_addr(broadcast);
  10425. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10426. i40e_add_mac_filter(vsi, broadcast);
  10427. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10428. ether_addr_copy(netdev->dev_addr, mac_addr);
  10429. ether_addr_copy(netdev->perm_addr, mac_addr);
  10430. netdev->priv_flags |= IFF_UNICAST_FLT;
  10431. netdev->priv_flags |= IFF_SUPP_NOFCS;
  10432. /* Setup netdev TC information */
  10433. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  10434. netdev->netdev_ops = &i40e_netdev_ops;
  10435. netdev->watchdog_timeo = 5 * HZ;
  10436. i40e_set_ethtool_ops(netdev);
  10437. /* MTU range: 68 - 9706 */
  10438. netdev->min_mtu = ETH_MIN_MTU;
  10439. netdev->max_mtu = I40E_MAX_RXBUFFER - I40E_PACKET_HDR_PAD;
  10440. return 0;
  10441. }
  10442. /**
  10443. * i40e_vsi_delete - Delete a VSI from the switch
  10444. * @vsi: the VSI being removed
  10445. *
  10446. * Returns 0 on success, negative value on failure
  10447. **/
  10448. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  10449. {
  10450. /* remove default VSI is not allowed */
  10451. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  10452. return;
  10453. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  10454. }
  10455. /**
  10456. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  10457. * @vsi: the VSI being queried
  10458. *
  10459. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  10460. **/
  10461. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  10462. {
  10463. struct i40e_veb *veb;
  10464. struct i40e_pf *pf = vsi->back;
  10465. /* Uplink is not a bridge so default to VEB */
  10466. if (vsi->veb_idx == I40E_NO_VEB)
  10467. return 1;
  10468. veb = pf->veb[vsi->veb_idx];
  10469. if (!veb) {
  10470. dev_info(&pf->pdev->dev,
  10471. "There is no veb associated with the bridge\n");
  10472. return -ENOENT;
  10473. }
  10474. /* Uplink is a bridge in VEPA mode */
  10475. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  10476. return 0;
  10477. } else {
  10478. /* Uplink is a bridge in VEB mode */
  10479. return 1;
  10480. }
  10481. /* VEPA is now default bridge, so return 0 */
  10482. return 0;
  10483. }
  10484. /**
  10485. * i40e_add_vsi - Add a VSI to the switch
  10486. * @vsi: the VSI being configured
  10487. *
  10488. * This initializes a VSI context depending on the VSI type to be added and
  10489. * passes it down to the add_vsi aq command.
  10490. **/
  10491. static int i40e_add_vsi(struct i40e_vsi *vsi)
  10492. {
  10493. int ret = -ENODEV;
  10494. struct i40e_pf *pf = vsi->back;
  10495. struct i40e_hw *hw = &pf->hw;
  10496. struct i40e_vsi_context ctxt;
  10497. struct i40e_mac_filter *f;
  10498. struct hlist_node *h;
  10499. int bkt;
  10500. u8 enabled_tc = 0x1; /* TC0 enabled */
  10501. int f_count = 0;
  10502. memset(&ctxt, 0, sizeof(ctxt));
  10503. switch (vsi->type) {
  10504. case I40E_VSI_MAIN:
  10505. /* The PF's main VSI is already setup as part of the
  10506. * device initialization, so we'll not bother with
  10507. * the add_vsi call, but we will retrieve the current
  10508. * VSI context.
  10509. */
  10510. ctxt.seid = pf->main_vsi_seid;
  10511. ctxt.pf_num = pf->hw.pf_id;
  10512. ctxt.vf_num = 0;
  10513. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  10514. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10515. if (ret) {
  10516. dev_info(&pf->pdev->dev,
  10517. "couldn't get PF vsi config, err %s aq_err %s\n",
  10518. i40e_stat_str(&pf->hw, ret),
  10519. i40e_aq_str(&pf->hw,
  10520. pf->hw.aq.asq_last_status));
  10521. return -ENOENT;
  10522. }
  10523. vsi->info = ctxt.info;
  10524. vsi->info.valid_sections = 0;
  10525. vsi->seid = ctxt.seid;
  10526. vsi->id = ctxt.vsi_number;
  10527. enabled_tc = i40e_pf_get_tc_map(pf);
  10528. /* Source pruning is enabled by default, so the flag is
  10529. * negative logic - if it's set, we need to fiddle with
  10530. * the VSI to disable source pruning.
  10531. */
  10532. if (pf->flags & I40E_FLAG_SOURCE_PRUNING_DISABLED) {
  10533. memset(&ctxt, 0, sizeof(ctxt));
  10534. ctxt.seid = pf->main_vsi_seid;
  10535. ctxt.pf_num = pf->hw.pf_id;
  10536. ctxt.vf_num = 0;
  10537. ctxt.info.valid_sections |=
  10538. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10539. ctxt.info.switch_id =
  10540. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  10541. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10542. if (ret) {
  10543. dev_info(&pf->pdev->dev,
  10544. "update vsi failed, err %s aq_err %s\n",
  10545. i40e_stat_str(&pf->hw, ret),
  10546. i40e_aq_str(&pf->hw,
  10547. pf->hw.aq.asq_last_status));
  10548. ret = -ENOENT;
  10549. goto err;
  10550. }
  10551. }
  10552. /* MFP mode setup queue map and update VSI */
  10553. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  10554. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  10555. memset(&ctxt, 0, sizeof(ctxt));
  10556. ctxt.seid = pf->main_vsi_seid;
  10557. ctxt.pf_num = pf->hw.pf_id;
  10558. ctxt.vf_num = 0;
  10559. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  10560. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  10561. if (ret) {
  10562. dev_info(&pf->pdev->dev,
  10563. "update vsi failed, err %s aq_err %s\n",
  10564. i40e_stat_str(&pf->hw, ret),
  10565. i40e_aq_str(&pf->hw,
  10566. pf->hw.aq.asq_last_status));
  10567. ret = -ENOENT;
  10568. goto err;
  10569. }
  10570. /* update the local VSI info queue map */
  10571. i40e_vsi_update_queue_map(vsi, &ctxt);
  10572. vsi->info.valid_sections = 0;
  10573. } else {
  10574. /* Default/Main VSI is only enabled for TC0
  10575. * reconfigure it to enable all TCs that are
  10576. * available on the port in SFP mode.
  10577. * For MFP case the iSCSI PF would use this
  10578. * flow to enable LAN+iSCSI TC.
  10579. */
  10580. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  10581. if (ret) {
  10582. /* Single TC condition is not fatal,
  10583. * message and continue
  10584. */
  10585. dev_info(&pf->pdev->dev,
  10586. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  10587. enabled_tc,
  10588. i40e_stat_str(&pf->hw, ret),
  10589. i40e_aq_str(&pf->hw,
  10590. pf->hw.aq.asq_last_status));
  10591. }
  10592. }
  10593. break;
  10594. case I40E_VSI_FDIR:
  10595. ctxt.pf_num = hw->pf_id;
  10596. ctxt.vf_num = 0;
  10597. ctxt.uplink_seid = vsi->uplink_seid;
  10598. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10599. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  10600. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  10601. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  10602. ctxt.info.valid_sections |=
  10603. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10604. ctxt.info.switch_id =
  10605. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10606. }
  10607. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10608. break;
  10609. case I40E_VSI_VMDQ2:
  10610. ctxt.pf_num = hw->pf_id;
  10611. ctxt.vf_num = 0;
  10612. ctxt.uplink_seid = vsi->uplink_seid;
  10613. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10614. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  10615. /* This VSI is connected to VEB so the switch_id
  10616. * should be set to zero by default.
  10617. */
  10618. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10619. ctxt.info.valid_sections |=
  10620. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10621. ctxt.info.switch_id =
  10622. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10623. }
  10624. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10625. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10626. break;
  10627. case I40E_VSI_SRIOV:
  10628. ctxt.pf_num = hw->pf_id;
  10629. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  10630. ctxt.uplink_seid = vsi->uplink_seid;
  10631. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  10632. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  10633. /* This VSI is connected to VEB so the switch_id
  10634. * should be set to zero by default.
  10635. */
  10636. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  10637. ctxt.info.valid_sections |=
  10638. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  10639. ctxt.info.switch_id =
  10640. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  10641. }
  10642. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  10643. ctxt.info.valid_sections |=
  10644. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  10645. ctxt.info.queueing_opt_flags |=
  10646. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  10647. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  10648. }
  10649. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  10650. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  10651. if (pf->vf[vsi->vf_id].spoofchk) {
  10652. ctxt.info.valid_sections |=
  10653. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  10654. ctxt.info.sec_flags |=
  10655. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  10656. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  10657. }
  10658. /* Setup the VSI tx/rx queue map for TC0 only for now */
  10659. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  10660. break;
  10661. case I40E_VSI_IWARP:
  10662. /* send down message to iWARP */
  10663. break;
  10664. default:
  10665. return -ENODEV;
  10666. }
  10667. if (vsi->type != I40E_VSI_MAIN) {
  10668. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  10669. if (ret) {
  10670. dev_info(&vsi->back->pdev->dev,
  10671. "add vsi failed, err %s aq_err %s\n",
  10672. i40e_stat_str(&pf->hw, ret),
  10673. i40e_aq_str(&pf->hw,
  10674. pf->hw.aq.asq_last_status));
  10675. ret = -ENOENT;
  10676. goto err;
  10677. }
  10678. vsi->info = ctxt.info;
  10679. vsi->info.valid_sections = 0;
  10680. vsi->seid = ctxt.seid;
  10681. vsi->id = ctxt.vsi_number;
  10682. }
  10683. vsi->active_filters = 0;
  10684. clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
  10685. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10686. /* If macvlan filters already exist, force them to get loaded */
  10687. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  10688. f->state = I40E_FILTER_NEW;
  10689. f_count++;
  10690. }
  10691. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10692. if (f_count) {
  10693. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  10694. set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
  10695. }
  10696. /* Update VSI BW information */
  10697. ret = i40e_vsi_get_bw_info(vsi);
  10698. if (ret) {
  10699. dev_info(&pf->pdev->dev,
  10700. "couldn't get vsi bw info, err %s aq_err %s\n",
  10701. i40e_stat_str(&pf->hw, ret),
  10702. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10703. /* VSI is already added so not tearing that up */
  10704. ret = 0;
  10705. }
  10706. err:
  10707. return ret;
  10708. }
  10709. /**
  10710. * i40e_vsi_release - Delete a VSI and free its resources
  10711. * @vsi: the VSI being removed
  10712. *
  10713. * Returns 0 on success or < 0 on error
  10714. **/
  10715. int i40e_vsi_release(struct i40e_vsi *vsi)
  10716. {
  10717. struct i40e_mac_filter *f;
  10718. struct hlist_node *h;
  10719. struct i40e_veb *veb = NULL;
  10720. struct i40e_pf *pf;
  10721. u16 uplink_seid;
  10722. int i, n, bkt;
  10723. pf = vsi->back;
  10724. /* release of a VEB-owner or last VSI is not allowed */
  10725. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  10726. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  10727. vsi->seid, vsi->uplink_seid);
  10728. return -ENODEV;
  10729. }
  10730. if (vsi == pf->vsi[pf->lan_vsi] &&
  10731. !test_bit(__I40E_DOWN, pf->state)) {
  10732. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  10733. return -ENODEV;
  10734. }
  10735. uplink_seid = vsi->uplink_seid;
  10736. if (vsi->type != I40E_VSI_SRIOV) {
  10737. if (vsi->netdev_registered) {
  10738. vsi->netdev_registered = false;
  10739. if (vsi->netdev) {
  10740. /* results in a call to i40e_close() */
  10741. unregister_netdev(vsi->netdev);
  10742. }
  10743. } else {
  10744. i40e_vsi_close(vsi);
  10745. }
  10746. i40e_vsi_disable_irq(vsi);
  10747. }
  10748. spin_lock_bh(&vsi->mac_filter_hash_lock);
  10749. /* clear the sync flag on all filters */
  10750. if (vsi->netdev) {
  10751. __dev_uc_unsync(vsi->netdev, NULL);
  10752. __dev_mc_unsync(vsi->netdev, NULL);
  10753. }
  10754. /* make sure any remaining filters are marked for deletion */
  10755. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  10756. __i40e_del_filter(vsi, f);
  10757. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  10758. i40e_sync_vsi_filters(vsi);
  10759. i40e_vsi_delete(vsi);
  10760. i40e_vsi_free_q_vectors(vsi);
  10761. if (vsi->netdev) {
  10762. free_netdev(vsi->netdev);
  10763. vsi->netdev = NULL;
  10764. }
  10765. i40e_vsi_clear_rings(vsi);
  10766. i40e_vsi_clear(vsi);
  10767. /* If this was the last thing on the VEB, except for the
  10768. * controlling VSI, remove the VEB, which puts the controlling
  10769. * VSI onto the next level down in the switch.
  10770. *
  10771. * Well, okay, there's one more exception here: don't remove
  10772. * the orphan VEBs yet. We'll wait for an explicit remove request
  10773. * from up the network stack.
  10774. */
  10775. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  10776. if (pf->vsi[i] &&
  10777. pf->vsi[i]->uplink_seid == uplink_seid &&
  10778. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  10779. n++; /* count the VSIs */
  10780. }
  10781. }
  10782. for (i = 0; i < I40E_MAX_VEB; i++) {
  10783. if (!pf->veb[i])
  10784. continue;
  10785. if (pf->veb[i]->uplink_seid == uplink_seid)
  10786. n++; /* count the VEBs */
  10787. if (pf->veb[i]->seid == uplink_seid)
  10788. veb = pf->veb[i];
  10789. }
  10790. if (n == 0 && veb && veb->uplink_seid != 0)
  10791. i40e_veb_release(veb);
  10792. return 0;
  10793. }
  10794. /**
  10795. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  10796. * @vsi: ptr to the VSI
  10797. *
  10798. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  10799. * corresponding SW VSI structure and initializes num_queue_pairs for the
  10800. * newly allocated VSI.
  10801. *
  10802. * Returns 0 on success or negative on failure
  10803. **/
  10804. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  10805. {
  10806. int ret = -ENOENT;
  10807. struct i40e_pf *pf = vsi->back;
  10808. if (vsi->q_vectors[0]) {
  10809. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  10810. vsi->seid);
  10811. return -EEXIST;
  10812. }
  10813. if (vsi->base_vector) {
  10814. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  10815. vsi->seid, vsi->base_vector);
  10816. return -EEXIST;
  10817. }
  10818. ret = i40e_vsi_alloc_q_vectors(vsi);
  10819. if (ret) {
  10820. dev_info(&pf->pdev->dev,
  10821. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  10822. vsi->num_q_vectors, vsi->seid, ret);
  10823. vsi->num_q_vectors = 0;
  10824. goto vector_setup_out;
  10825. }
  10826. /* In Legacy mode, we do not have to get any other vector since we
  10827. * piggyback on the misc/ICR0 for queue interrupts.
  10828. */
  10829. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  10830. return ret;
  10831. if (vsi->num_q_vectors)
  10832. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  10833. vsi->num_q_vectors, vsi->idx);
  10834. if (vsi->base_vector < 0) {
  10835. dev_info(&pf->pdev->dev,
  10836. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  10837. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  10838. i40e_vsi_free_q_vectors(vsi);
  10839. ret = -ENOENT;
  10840. goto vector_setup_out;
  10841. }
  10842. vector_setup_out:
  10843. return ret;
  10844. }
  10845. /**
  10846. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  10847. * @vsi: pointer to the vsi.
  10848. *
  10849. * This re-allocates a vsi's queue resources.
  10850. *
  10851. * Returns pointer to the successfully allocated and configured VSI sw struct
  10852. * on success, otherwise returns NULL on failure.
  10853. **/
  10854. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  10855. {
  10856. u16 alloc_queue_pairs;
  10857. struct i40e_pf *pf;
  10858. u8 enabled_tc;
  10859. int ret;
  10860. if (!vsi)
  10861. return NULL;
  10862. pf = vsi->back;
  10863. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  10864. i40e_vsi_clear_rings(vsi);
  10865. i40e_vsi_free_arrays(vsi, false);
  10866. i40e_set_num_rings_in_vsi(vsi);
  10867. ret = i40e_vsi_alloc_arrays(vsi, false);
  10868. if (ret)
  10869. goto err_vsi;
  10870. alloc_queue_pairs = vsi->alloc_queue_pairs *
  10871. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  10872. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  10873. if (ret < 0) {
  10874. dev_info(&pf->pdev->dev,
  10875. "failed to get tracking for %d queues for VSI %d err %d\n",
  10876. alloc_queue_pairs, vsi->seid, ret);
  10877. goto err_vsi;
  10878. }
  10879. vsi->base_queue = ret;
  10880. /* Update the FW view of the VSI. Force a reset of TC and queue
  10881. * layout configurations.
  10882. */
  10883. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  10884. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  10885. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  10886. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  10887. if (vsi->type == I40E_VSI_MAIN)
  10888. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  10889. /* assign it some queues */
  10890. ret = i40e_alloc_rings(vsi);
  10891. if (ret)
  10892. goto err_rings;
  10893. /* map all of the rings to the q_vectors */
  10894. i40e_vsi_map_rings_to_vectors(vsi);
  10895. return vsi;
  10896. err_rings:
  10897. i40e_vsi_free_q_vectors(vsi);
  10898. if (vsi->netdev_registered) {
  10899. vsi->netdev_registered = false;
  10900. unregister_netdev(vsi->netdev);
  10901. free_netdev(vsi->netdev);
  10902. vsi->netdev = NULL;
  10903. }
  10904. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  10905. err_vsi:
  10906. i40e_vsi_clear(vsi);
  10907. return NULL;
  10908. }
  10909. /**
  10910. * i40e_vsi_setup - Set up a VSI by a given type
  10911. * @pf: board private structure
  10912. * @type: VSI type
  10913. * @uplink_seid: the switch element to link to
  10914. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  10915. *
  10916. * This allocates the sw VSI structure and its queue resources, then add a VSI
  10917. * to the identified VEB.
  10918. *
  10919. * Returns pointer to the successfully allocated and configure VSI sw struct on
  10920. * success, otherwise returns NULL on failure.
  10921. **/
  10922. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  10923. u16 uplink_seid, u32 param1)
  10924. {
  10925. struct i40e_vsi *vsi = NULL;
  10926. struct i40e_veb *veb = NULL;
  10927. u16 alloc_queue_pairs;
  10928. int ret, i;
  10929. int v_idx;
  10930. /* The requested uplink_seid must be either
  10931. * - the PF's port seid
  10932. * no VEB is needed because this is the PF
  10933. * or this is a Flow Director special case VSI
  10934. * - seid of an existing VEB
  10935. * - seid of a VSI that owns an existing VEB
  10936. * - seid of a VSI that doesn't own a VEB
  10937. * a new VEB is created and the VSI becomes the owner
  10938. * - seid of the PF VSI, which is what creates the first VEB
  10939. * this is a special case of the previous
  10940. *
  10941. * Find which uplink_seid we were given and create a new VEB if needed
  10942. */
  10943. for (i = 0; i < I40E_MAX_VEB; i++) {
  10944. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  10945. veb = pf->veb[i];
  10946. break;
  10947. }
  10948. }
  10949. if (!veb && uplink_seid != pf->mac_seid) {
  10950. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10951. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  10952. vsi = pf->vsi[i];
  10953. break;
  10954. }
  10955. }
  10956. if (!vsi) {
  10957. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  10958. uplink_seid);
  10959. return NULL;
  10960. }
  10961. if (vsi->uplink_seid == pf->mac_seid)
  10962. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  10963. vsi->tc_config.enabled_tc);
  10964. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  10965. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  10966. vsi->tc_config.enabled_tc);
  10967. if (veb) {
  10968. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  10969. dev_info(&vsi->back->pdev->dev,
  10970. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  10971. return NULL;
  10972. }
  10973. /* We come up by default in VEPA mode if SRIOV is not
  10974. * already enabled, in which case we can't force VEPA
  10975. * mode.
  10976. */
  10977. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  10978. veb->bridge_mode = BRIDGE_MODE_VEPA;
  10979. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  10980. }
  10981. i40e_config_bridge_mode(veb);
  10982. }
  10983. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  10984. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  10985. veb = pf->veb[i];
  10986. }
  10987. if (!veb) {
  10988. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  10989. return NULL;
  10990. }
  10991. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  10992. uplink_seid = veb->seid;
  10993. }
  10994. /* get vsi sw struct */
  10995. v_idx = i40e_vsi_mem_alloc(pf, type);
  10996. if (v_idx < 0)
  10997. goto err_alloc;
  10998. vsi = pf->vsi[v_idx];
  10999. if (!vsi)
  11000. goto err_alloc;
  11001. vsi->type = type;
  11002. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  11003. if (type == I40E_VSI_MAIN)
  11004. pf->lan_vsi = v_idx;
  11005. else if (type == I40E_VSI_SRIOV)
  11006. vsi->vf_id = param1;
  11007. /* assign it some queues */
  11008. alloc_queue_pairs = vsi->alloc_queue_pairs *
  11009. (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
  11010. ret = i40e_get_lump(pf, pf->qp_pile, alloc_queue_pairs, vsi->idx);
  11011. if (ret < 0) {
  11012. dev_info(&pf->pdev->dev,
  11013. "failed to get tracking for %d queues for VSI %d err=%d\n",
  11014. alloc_queue_pairs, vsi->seid, ret);
  11015. goto err_vsi;
  11016. }
  11017. vsi->base_queue = ret;
  11018. /* get a VSI from the hardware */
  11019. vsi->uplink_seid = uplink_seid;
  11020. ret = i40e_add_vsi(vsi);
  11021. if (ret)
  11022. goto err_vsi;
  11023. switch (vsi->type) {
  11024. /* setup the netdev if needed */
  11025. case I40E_VSI_MAIN:
  11026. case I40E_VSI_VMDQ2:
  11027. ret = i40e_config_netdev(vsi);
  11028. if (ret)
  11029. goto err_netdev;
  11030. ret = register_netdev(vsi->netdev);
  11031. if (ret)
  11032. goto err_netdev;
  11033. vsi->netdev_registered = true;
  11034. netif_carrier_off(vsi->netdev);
  11035. #ifdef CONFIG_I40E_DCB
  11036. /* Setup DCB netlink interface */
  11037. i40e_dcbnl_setup(vsi);
  11038. #endif /* CONFIG_I40E_DCB */
  11039. /* fall through */
  11040. case I40E_VSI_FDIR:
  11041. /* set up vectors and rings if needed */
  11042. ret = i40e_vsi_setup_vectors(vsi);
  11043. if (ret)
  11044. goto err_msix;
  11045. ret = i40e_alloc_rings(vsi);
  11046. if (ret)
  11047. goto err_rings;
  11048. /* map all of the rings to the q_vectors */
  11049. i40e_vsi_map_rings_to_vectors(vsi);
  11050. i40e_vsi_reset_stats(vsi);
  11051. break;
  11052. default:
  11053. /* no netdev or rings for the other VSI types */
  11054. break;
  11055. }
  11056. if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
  11057. (vsi->type == I40E_VSI_VMDQ2)) {
  11058. ret = i40e_vsi_config_rss(vsi);
  11059. }
  11060. return vsi;
  11061. err_rings:
  11062. i40e_vsi_free_q_vectors(vsi);
  11063. err_msix:
  11064. if (vsi->netdev_registered) {
  11065. vsi->netdev_registered = false;
  11066. unregister_netdev(vsi->netdev);
  11067. free_netdev(vsi->netdev);
  11068. vsi->netdev = NULL;
  11069. }
  11070. err_netdev:
  11071. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  11072. err_vsi:
  11073. i40e_vsi_clear(vsi);
  11074. err_alloc:
  11075. return NULL;
  11076. }
  11077. /**
  11078. * i40e_veb_get_bw_info - Query VEB BW information
  11079. * @veb: the veb to query
  11080. *
  11081. * Query the Tx scheduler BW configuration data for given VEB
  11082. **/
  11083. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  11084. {
  11085. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  11086. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  11087. struct i40e_pf *pf = veb->pf;
  11088. struct i40e_hw *hw = &pf->hw;
  11089. u32 tc_bw_max;
  11090. int ret = 0;
  11091. int i;
  11092. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  11093. &bw_data, NULL);
  11094. if (ret) {
  11095. dev_info(&pf->pdev->dev,
  11096. "query veb bw config failed, err %s aq_err %s\n",
  11097. i40e_stat_str(&pf->hw, ret),
  11098. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11099. goto out;
  11100. }
  11101. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  11102. &ets_data, NULL);
  11103. if (ret) {
  11104. dev_info(&pf->pdev->dev,
  11105. "query veb bw ets config failed, err %s aq_err %s\n",
  11106. i40e_stat_str(&pf->hw, ret),
  11107. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  11108. goto out;
  11109. }
  11110. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  11111. veb->bw_max_quanta = ets_data.tc_bw_max;
  11112. veb->is_abs_credits = bw_data.absolute_credits_enable;
  11113. veb->enabled_tc = ets_data.tc_valid_bits;
  11114. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  11115. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  11116. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  11117. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  11118. veb->bw_tc_limit_credits[i] =
  11119. le16_to_cpu(bw_data.tc_bw_limits[i]);
  11120. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  11121. }
  11122. out:
  11123. return ret;
  11124. }
  11125. /**
  11126. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  11127. * @pf: board private structure
  11128. *
  11129. * On error: returns error code (negative)
  11130. * On success: returns vsi index in PF (positive)
  11131. **/
  11132. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  11133. {
  11134. int ret = -ENOENT;
  11135. struct i40e_veb *veb;
  11136. int i;
  11137. /* Need to protect the allocation of switch elements at the PF level */
  11138. mutex_lock(&pf->switch_mutex);
  11139. /* VEB list may be fragmented if VEB creation/destruction has
  11140. * been happening. We can afford to do a quick scan to look
  11141. * for any free slots in the list.
  11142. *
  11143. * find next empty veb slot, looping back around if necessary
  11144. */
  11145. i = 0;
  11146. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  11147. i++;
  11148. if (i >= I40E_MAX_VEB) {
  11149. ret = -ENOMEM;
  11150. goto err_alloc_veb; /* out of VEB slots! */
  11151. }
  11152. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  11153. if (!veb) {
  11154. ret = -ENOMEM;
  11155. goto err_alloc_veb;
  11156. }
  11157. veb->pf = pf;
  11158. veb->idx = i;
  11159. veb->enabled_tc = 1;
  11160. pf->veb[i] = veb;
  11161. ret = i;
  11162. err_alloc_veb:
  11163. mutex_unlock(&pf->switch_mutex);
  11164. return ret;
  11165. }
  11166. /**
  11167. * i40e_switch_branch_release - Delete a branch of the switch tree
  11168. * @branch: where to start deleting
  11169. *
  11170. * This uses recursion to find the tips of the branch to be
  11171. * removed, deleting until we get back to and can delete this VEB.
  11172. **/
  11173. static void i40e_switch_branch_release(struct i40e_veb *branch)
  11174. {
  11175. struct i40e_pf *pf = branch->pf;
  11176. u16 branch_seid = branch->seid;
  11177. u16 veb_idx = branch->idx;
  11178. int i;
  11179. /* release any VEBs on this VEB - RECURSION */
  11180. for (i = 0; i < I40E_MAX_VEB; i++) {
  11181. if (!pf->veb[i])
  11182. continue;
  11183. if (pf->veb[i]->uplink_seid == branch->seid)
  11184. i40e_switch_branch_release(pf->veb[i]);
  11185. }
  11186. /* Release the VSIs on this VEB, but not the owner VSI.
  11187. *
  11188. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  11189. * the VEB itself, so don't use (*branch) after this loop.
  11190. */
  11191. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11192. if (!pf->vsi[i])
  11193. continue;
  11194. if (pf->vsi[i]->uplink_seid == branch_seid &&
  11195. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  11196. i40e_vsi_release(pf->vsi[i]);
  11197. }
  11198. }
  11199. /* There's one corner case where the VEB might not have been
  11200. * removed, so double check it here and remove it if needed.
  11201. * This case happens if the veb was created from the debugfs
  11202. * commands and no VSIs were added to it.
  11203. */
  11204. if (pf->veb[veb_idx])
  11205. i40e_veb_release(pf->veb[veb_idx]);
  11206. }
  11207. /**
  11208. * i40e_veb_clear - remove veb struct
  11209. * @veb: the veb to remove
  11210. **/
  11211. static void i40e_veb_clear(struct i40e_veb *veb)
  11212. {
  11213. if (!veb)
  11214. return;
  11215. if (veb->pf) {
  11216. struct i40e_pf *pf = veb->pf;
  11217. mutex_lock(&pf->switch_mutex);
  11218. if (pf->veb[veb->idx] == veb)
  11219. pf->veb[veb->idx] = NULL;
  11220. mutex_unlock(&pf->switch_mutex);
  11221. }
  11222. kfree(veb);
  11223. }
  11224. /**
  11225. * i40e_veb_release - Delete a VEB and free its resources
  11226. * @veb: the VEB being removed
  11227. **/
  11228. void i40e_veb_release(struct i40e_veb *veb)
  11229. {
  11230. struct i40e_vsi *vsi = NULL;
  11231. struct i40e_pf *pf;
  11232. int i, n = 0;
  11233. pf = veb->pf;
  11234. /* find the remaining VSI and check for extras */
  11235. for (i = 0; i < pf->num_alloc_vsi; i++) {
  11236. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  11237. n++;
  11238. vsi = pf->vsi[i];
  11239. }
  11240. }
  11241. if (n != 1) {
  11242. dev_info(&pf->pdev->dev,
  11243. "can't remove VEB %d with %d VSIs left\n",
  11244. veb->seid, n);
  11245. return;
  11246. }
  11247. /* move the remaining VSI to uplink veb */
  11248. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  11249. if (veb->uplink_seid) {
  11250. vsi->uplink_seid = veb->uplink_seid;
  11251. if (veb->uplink_seid == pf->mac_seid)
  11252. vsi->veb_idx = I40E_NO_VEB;
  11253. else
  11254. vsi->veb_idx = veb->veb_idx;
  11255. } else {
  11256. /* floating VEB */
  11257. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  11258. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  11259. }
  11260. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11261. i40e_veb_clear(veb);
  11262. }
  11263. /**
  11264. * i40e_add_veb - create the VEB in the switch
  11265. * @veb: the VEB to be instantiated
  11266. * @vsi: the controlling VSI
  11267. **/
  11268. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  11269. {
  11270. struct i40e_pf *pf = veb->pf;
  11271. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  11272. int ret;
  11273. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  11274. veb->enabled_tc, false,
  11275. &veb->seid, enable_stats, NULL);
  11276. /* get a VEB from the hardware */
  11277. if (ret) {
  11278. dev_info(&pf->pdev->dev,
  11279. "couldn't add VEB, err %s aq_err %s\n",
  11280. i40e_stat_str(&pf->hw, ret),
  11281. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11282. return -EPERM;
  11283. }
  11284. /* get statistics counter */
  11285. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  11286. &veb->stats_idx, NULL, NULL, NULL);
  11287. if (ret) {
  11288. dev_info(&pf->pdev->dev,
  11289. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  11290. i40e_stat_str(&pf->hw, ret),
  11291. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11292. return -EPERM;
  11293. }
  11294. ret = i40e_veb_get_bw_info(veb);
  11295. if (ret) {
  11296. dev_info(&pf->pdev->dev,
  11297. "couldn't get VEB bw info, err %s aq_err %s\n",
  11298. i40e_stat_str(&pf->hw, ret),
  11299. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11300. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  11301. return -ENOENT;
  11302. }
  11303. vsi->uplink_seid = veb->seid;
  11304. vsi->veb_idx = veb->idx;
  11305. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  11306. return 0;
  11307. }
  11308. /**
  11309. * i40e_veb_setup - Set up a VEB
  11310. * @pf: board private structure
  11311. * @flags: VEB setup flags
  11312. * @uplink_seid: the switch element to link to
  11313. * @vsi_seid: the initial VSI seid
  11314. * @enabled_tc: Enabled TC bit-map
  11315. *
  11316. * This allocates the sw VEB structure and links it into the switch
  11317. * It is possible and legal for this to be a duplicate of an already
  11318. * existing VEB. It is also possible for both uplink and vsi seids
  11319. * to be zero, in order to create a floating VEB.
  11320. *
  11321. * Returns pointer to the successfully allocated VEB sw struct on
  11322. * success, otherwise returns NULL on failure.
  11323. **/
  11324. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  11325. u16 uplink_seid, u16 vsi_seid,
  11326. u8 enabled_tc)
  11327. {
  11328. struct i40e_veb *veb, *uplink_veb = NULL;
  11329. int vsi_idx, veb_idx;
  11330. int ret;
  11331. /* if one seid is 0, the other must be 0 to create a floating relay */
  11332. if ((uplink_seid == 0 || vsi_seid == 0) &&
  11333. (uplink_seid + vsi_seid != 0)) {
  11334. dev_info(&pf->pdev->dev,
  11335. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  11336. uplink_seid, vsi_seid);
  11337. return NULL;
  11338. }
  11339. /* make sure there is such a vsi and uplink */
  11340. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  11341. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  11342. break;
  11343. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  11344. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  11345. vsi_seid);
  11346. return NULL;
  11347. }
  11348. if (uplink_seid && uplink_seid != pf->mac_seid) {
  11349. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  11350. if (pf->veb[veb_idx] &&
  11351. pf->veb[veb_idx]->seid == uplink_seid) {
  11352. uplink_veb = pf->veb[veb_idx];
  11353. break;
  11354. }
  11355. }
  11356. if (!uplink_veb) {
  11357. dev_info(&pf->pdev->dev,
  11358. "uplink seid %d not found\n", uplink_seid);
  11359. return NULL;
  11360. }
  11361. }
  11362. /* get veb sw struct */
  11363. veb_idx = i40e_veb_mem_alloc(pf);
  11364. if (veb_idx < 0)
  11365. goto err_alloc;
  11366. veb = pf->veb[veb_idx];
  11367. veb->flags = flags;
  11368. veb->uplink_seid = uplink_seid;
  11369. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  11370. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  11371. /* create the VEB in the switch */
  11372. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  11373. if (ret)
  11374. goto err_veb;
  11375. if (vsi_idx == pf->lan_vsi)
  11376. pf->lan_veb = veb->idx;
  11377. return veb;
  11378. err_veb:
  11379. i40e_veb_clear(veb);
  11380. err_alloc:
  11381. return NULL;
  11382. }
  11383. /**
  11384. * i40e_setup_pf_switch_element - set PF vars based on switch type
  11385. * @pf: board private structure
  11386. * @ele: element we are building info from
  11387. * @num_reported: total number of elements
  11388. * @printconfig: should we print the contents
  11389. *
  11390. * helper function to assist in extracting a few useful SEID values.
  11391. **/
  11392. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  11393. struct i40e_aqc_switch_config_element_resp *ele,
  11394. u16 num_reported, bool printconfig)
  11395. {
  11396. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  11397. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  11398. u8 element_type = ele->element_type;
  11399. u16 seid = le16_to_cpu(ele->seid);
  11400. if (printconfig)
  11401. dev_info(&pf->pdev->dev,
  11402. "type=%d seid=%d uplink=%d downlink=%d\n",
  11403. element_type, seid, uplink_seid, downlink_seid);
  11404. switch (element_type) {
  11405. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  11406. pf->mac_seid = seid;
  11407. break;
  11408. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  11409. /* Main VEB? */
  11410. if (uplink_seid != pf->mac_seid)
  11411. break;
  11412. if (pf->lan_veb == I40E_NO_VEB) {
  11413. int v;
  11414. /* find existing or else empty VEB */
  11415. for (v = 0; v < I40E_MAX_VEB; v++) {
  11416. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  11417. pf->lan_veb = v;
  11418. break;
  11419. }
  11420. }
  11421. if (pf->lan_veb == I40E_NO_VEB) {
  11422. v = i40e_veb_mem_alloc(pf);
  11423. if (v < 0)
  11424. break;
  11425. pf->lan_veb = v;
  11426. }
  11427. }
  11428. pf->veb[pf->lan_veb]->seid = seid;
  11429. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  11430. pf->veb[pf->lan_veb]->pf = pf;
  11431. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  11432. break;
  11433. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  11434. if (num_reported != 1)
  11435. break;
  11436. /* This is immediately after a reset so we can assume this is
  11437. * the PF's VSI
  11438. */
  11439. pf->mac_seid = uplink_seid;
  11440. pf->pf_seid = downlink_seid;
  11441. pf->main_vsi_seid = seid;
  11442. if (printconfig)
  11443. dev_info(&pf->pdev->dev,
  11444. "pf_seid=%d main_vsi_seid=%d\n",
  11445. pf->pf_seid, pf->main_vsi_seid);
  11446. break;
  11447. case I40E_SWITCH_ELEMENT_TYPE_PF:
  11448. case I40E_SWITCH_ELEMENT_TYPE_VF:
  11449. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  11450. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  11451. case I40E_SWITCH_ELEMENT_TYPE_PE:
  11452. case I40E_SWITCH_ELEMENT_TYPE_PA:
  11453. /* ignore these for now */
  11454. break;
  11455. default:
  11456. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  11457. element_type, seid);
  11458. break;
  11459. }
  11460. }
  11461. /**
  11462. * i40e_fetch_switch_configuration - Get switch config from firmware
  11463. * @pf: board private structure
  11464. * @printconfig: should we print the contents
  11465. *
  11466. * Get the current switch configuration from the device and
  11467. * extract a few useful SEID values.
  11468. **/
  11469. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  11470. {
  11471. struct i40e_aqc_get_switch_config_resp *sw_config;
  11472. u16 next_seid = 0;
  11473. int ret = 0;
  11474. u8 *aq_buf;
  11475. int i;
  11476. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  11477. if (!aq_buf)
  11478. return -ENOMEM;
  11479. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  11480. do {
  11481. u16 num_reported, num_total;
  11482. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  11483. I40E_AQ_LARGE_BUF,
  11484. &next_seid, NULL);
  11485. if (ret) {
  11486. dev_info(&pf->pdev->dev,
  11487. "get switch config failed err %s aq_err %s\n",
  11488. i40e_stat_str(&pf->hw, ret),
  11489. i40e_aq_str(&pf->hw,
  11490. pf->hw.aq.asq_last_status));
  11491. kfree(aq_buf);
  11492. return -ENOENT;
  11493. }
  11494. num_reported = le16_to_cpu(sw_config->header.num_reported);
  11495. num_total = le16_to_cpu(sw_config->header.num_total);
  11496. if (printconfig)
  11497. dev_info(&pf->pdev->dev,
  11498. "header: %d reported %d total\n",
  11499. num_reported, num_total);
  11500. for (i = 0; i < num_reported; i++) {
  11501. struct i40e_aqc_switch_config_element_resp *ele =
  11502. &sw_config->element[i];
  11503. i40e_setup_pf_switch_element(pf, ele, num_reported,
  11504. printconfig);
  11505. }
  11506. } while (next_seid != 0);
  11507. kfree(aq_buf);
  11508. return ret;
  11509. }
  11510. /**
  11511. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  11512. * @pf: board private structure
  11513. * @reinit: if the Main VSI needs to re-initialized.
  11514. *
  11515. * Returns 0 on success, negative value on failure
  11516. **/
  11517. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  11518. {
  11519. u16 flags = 0;
  11520. int ret;
  11521. /* find out what's out there already */
  11522. ret = i40e_fetch_switch_configuration(pf, false);
  11523. if (ret) {
  11524. dev_info(&pf->pdev->dev,
  11525. "couldn't fetch switch config, err %s aq_err %s\n",
  11526. i40e_stat_str(&pf->hw, ret),
  11527. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  11528. return ret;
  11529. }
  11530. i40e_pf_reset_stats(pf);
  11531. /* set the switch config bit for the whole device to
  11532. * support limited promisc or true promisc
  11533. * when user requests promisc. The default is limited
  11534. * promisc.
  11535. */
  11536. if ((pf->hw.pf_id == 0) &&
  11537. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  11538. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11539. pf->last_sw_conf_flags = flags;
  11540. }
  11541. if (pf->hw.pf_id == 0) {
  11542. u16 valid_flags;
  11543. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  11544. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags, 0,
  11545. NULL);
  11546. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  11547. dev_info(&pf->pdev->dev,
  11548. "couldn't set switch config bits, err %s aq_err %s\n",
  11549. i40e_stat_str(&pf->hw, ret),
  11550. i40e_aq_str(&pf->hw,
  11551. pf->hw.aq.asq_last_status));
  11552. /* not a fatal problem, just keep going */
  11553. }
  11554. pf->last_sw_conf_valid_flags = valid_flags;
  11555. }
  11556. /* first time setup */
  11557. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  11558. struct i40e_vsi *vsi = NULL;
  11559. u16 uplink_seid;
  11560. /* Set up the PF VSI associated with the PF's main VSI
  11561. * that is already in the HW switch
  11562. */
  11563. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  11564. uplink_seid = pf->veb[pf->lan_veb]->seid;
  11565. else
  11566. uplink_seid = pf->mac_seid;
  11567. if (pf->lan_vsi == I40E_NO_VSI)
  11568. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  11569. else if (reinit)
  11570. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  11571. if (!vsi) {
  11572. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  11573. i40e_cloud_filter_exit(pf);
  11574. i40e_fdir_teardown(pf);
  11575. return -EAGAIN;
  11576. }
  11577. } else {
  11578. /* force a reset of TC and queue layout configurations */
  11579. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  11580. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  11581. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  11582. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  11583. }
  11584. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  11585. i40e_fdir_sb_setup(pf);
  11586. /* Setup static PF queue filter control settings */
  11587. ret = i40e_setup_pf_filter_control(pf);
  11588. if (ret) {
  11589. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  11590. ret);
  11591. /* Failure here should not stop continuing other steps */
  11592. }
  11593. /* enable RSS in the HW, even for only one queue, as the stack can use
  11594. * the hash
  11595. */
  11596. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  11597. i40e_pf_config_rss(pf);
  11598. /* fill in link information and enable LSE reporting */
  11599. i40e_link_event(pf);
  11600. /* Initialize user-specific link properties */
  11601. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  11602. I40E_AQ_AN_COMPLETED) ? true : false);
  11603. i40e_ptp_init(pf);
  11604. /* repopulate tunnel port filters */
  11605. i40e_sync_udp_filters(pf);
  11606. return ret;
  11607. }
  11608. /**
  11609. * i40e_determine_queue_usage - Work out queue distribution
  11610. * @pf: board private structure
  11611. **/
  11612. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  11613. {
  11614. int queues_left;
  11615. int q_max;
  11616. pf->num_lan_qps = 0;
  11617. /* Find the max queues to be put into basic use. We'll always be
  11618. * using TC0, whether or not DCB is running, and TC0 will get the
  11619. * big RSS set.
  11620. */
  11621. queues_left = pf->hw.func_caps.num_tx_qp;
  11622. if ((queues_left == 1) ||
  11623. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  11624. /* one qp for PF, no queues for anything else */
  11625. queues_left = 0;
  11626. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11627. /* make sure all the fancies are disabled */
  11628. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11629. I40E_FLAG_IWARP_ENABLED |
  11630. I40E_FLAG_FD_SB_ENABLED |
  11631. I40E_FLAG_FD_ATR_ENABLED |
  11632. I40E_FLAG_DCB_CAPABLE |
  11633. I40E_FLAG_DCB_ENABLED |
  11634. I40E_FLAG_SRIOV_ENABLED |
  11635. I40E_FLAG_VMDQ_ENABLED);
  11636. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11637. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  11638. I40E_FLAG_FD_SB_ENABLED |
  11639. I40E_FLAG_FD_ATR_ENABLED |
  11640. I40E_FLAG_DCB_CAPABLE))) {
  11641. /* one qp for PF */
  11642. pf->alloc_rss_size = pf->num_lan_qps = 1;
  11643. queues_left -= pf->num_lan_qps;
  11644. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  11645. I40E_FLAG_IWARP_ENABLED |
  11646. I40E_FLAG_FD_SB_ENABLED |
  11647. I40E_FLAG_FD_ATR_ENABLED |
  11648. I40E_FLAG_DCB_ENABLED |
  11649. I40E_FLAG_VMDQ_ENABLED);
  11650. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11651. } else {
  11652. /* Not enough queues for all TCs */
  11653. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  11654. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  11655. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  11656. I40E_FLAG_DCB_ENABLED);
  11657. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  11658. }
  11659. /* limit lan qps to the smaller of qps, cpus or msix */
  11660. q_max = max_t(int, pf->rss_size_max, num_online_cpus());
  11661. q_max = min_t(int, q_max, pf->hw.func_caps.num_tx_qp);
  11662. q_max = min_t(int, q_max, pf->hw.func_caps.num_msix_vectors);
  11663. pf->num_lan_qps = q_max;
  11664. queues_left -= pf->num_lan_qps;
  11665. }
  11666. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11667. if (queues_left > 1) {
  11668. queues_left -= 1; /* save 1 queue for FD */
  11669. } else {
  11670. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  11671. pf->flags |= I40E_FLAG_FD_SB_INACTIVE;
  11672. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  11673. }
  11674. }
  11675. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  11676. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  11677. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  11678. (queues_left / pf->num_vf_qps));
  11679. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  11680. }
  11681. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  11682. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  11683. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  11684. (queues_left / pf->num_vmdq_qps));
  11685. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  11686. }
  11687. pf->queues_left = queues_left;
  11688. dev_dbg(&pf->pdev->dev,
  11689. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  11690. pf->hw.func_caps.num_tx_qp,
  11691. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  11692. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  11693. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  11694. queues_left);
  11695. }
  11696. /**
  11697. * i40e_setup_pf_filter_control - Setup PF static filter control
  11698. * @pf: PF to be setup
  11699. *
  11700. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  11701. * settings. If PE/FCoE are enabled then it will also set the per PF
  11702. * based filter sizes required for them. It also enables Flow director,
  11703. * ethertype and macvlan type filter settings for the pf.
  11704. *
  11705. * Returns 0 on success, negative on failure
  11706. **/
  11707. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  11708. {
  11709. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  11710. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  11711. /* Flow Director is enabled */
  11712. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  11713. settings->enable_fdir = true;
  11714. /* Ethtype and MACVLAN filters enabled for PF */
  11715. settings->enable_ethtype = true;
  11716. settings->enable_macvlan = true;
  11717. if (i40e_set_filter_control(&pf->hw, settings))
  11718. return -ENOENT;
  11719. return 0;
  11720. }
  11721. #define INFO_STRING_LEN 255
  11722. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  11723. static void i40e_print_features(struct i40e_pf *pf)
  11724. {
  11725. struct i40e_hw *hw = &pf->hw;
  11726. char *buf;
  11727. int i;
  11728. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  11729. if (!buf)
  11730. return;
  11731. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  11732. #ifdef CONFIG_PCI_IOV
  11733. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  11734. #endif
  11735. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  11736. pf->hw.func_caps.num_vsis,
  11737. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  11738. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  11739. i += snprintf(&buf[i], REMAIN(i), " RSS");
  11740. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  11741. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  11742. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  11743. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  11744. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  11745. }
  11746. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  11747. i += snprintf(&buf[i], REMAIN(i), " DCB");
  11748. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  11749. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  11750. if (pf->flags & I40E_FLAG_PTP)
  11751. i += snprintf(&buf[i], REMAIN(i), " PTP");
  11752. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  11753. i += snprintf(&buf[i], REMAIN(i), " VEB");
  11754. else
  11755. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  11756. dev_info(&pf->pdev->dev, "%s\n", buf);
  11757. kfree(buf);
  11758. WARN_ON(i > INFO_STRING_LEN);
  11759. }
  11760. /**
  11761. * i40e_get_platform_mac_addr - get platform-specific MAC address
  11762. * @pdev: PCI device information struct
  11763. * @pf: board private structure
  11764. *
  11765. * Look up the MAC address for the device. First we'll try
  11766. * eth_platform_get_mac_address, which will check Open Firmware, or arch
  11767. * specific fallback. Otherwise, we'll default to the stored value in
  11768. * firmware.
  11769. **/
  11770. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  11771. {
  11772. if (eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  11773. i40e_get_mac_addr(&pf->hw, pf->hw.mac.addr);
  11774. }
  11775. /**
  11776. * i40e_probe - Device initialization routine
  11777. * @pdev: PCI device information struct
  11778. * @ent: entry in i40e_pci_tbl
  11779. *
  11780. * i40e_probe initializes a PF identified by a pci_dev structure.
  11781. * The OS initialization, configuring of the PF private structure,
  11782. * and a hardware reset occur.
  11783. *
  11784. * Returns 0 on success, negative on failure
  11785. **/
  11786. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  11787. {
  11788. struct i40e_aq_get_phy_abilities_resp abilities;
  11789. struct i40e_pf *pf;
  11790. struct i40e_hw *hw;
  11791. static u16 pfs_found;
  11792. u16 wol_nvm_bits;
  11793. u16 link_status;
  11794. int err;
  11795. u32 val;
  11796. u32 i;
  11797. u8 set_fc_aq_fail;
  11798. err = pci_enable_device_mem(pdev);
  11799. if (err)
  11800. return err;
  11801. /* set up for high or low dma */
  11802. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  11803. if (err) {
  11804. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  11805. if (err) {
  11806. dev_err(&pdev->dev,
  11807. "DMA configuration failed: 0x%x\n", err);
  11808. goto err_dma;
  11809. }
  11810. }
  11811. /* set up pci connections */
  11812. err = pci_request_mem_regions(pdev, i40e_driver_name);
  11813. if (err) {
  11814. dev_info(&pdev->dev,
  11815. "pci_request_selected_regions failed %d\n", err);
  11816. goto err_pci_reg;
  11817. }
  11818. pci_enable_pcie_error_reporting(pdev);
  11819. pci_set_master(pdev);
  11820. /* Now that we have a PCI connection, we need to do the
  11821. * low level device setup. This is primarily setting up
  11822. * the Admin Queue structures and then querying for the
  11823. * device's current profile information.
  11824. */
  11825. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  11826. if (!pf) {
  11827. err = -ENOMEM;
  11828. goto err_pf_alloc;
  11829. }
  11830. pf->next_vsi = 0;
  11831. pf->pdev = pdev;
  11832. set_bit(__I40E_DOWN, pf->state);
  11833. hw = &pf->hw;
  11834. hw->back = pf;
  11835. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  11836. I40E_MAX_CSR_SPACE);
  11837. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  11838. if (!hw->hw_addr) {
  11839. err = -EIO;
  11840. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  11841. (unsigned int)pci_resource_start(pdev, 0),
  11842. pf->ioremap_len, err);
  11843. goto err_ioremap;
  11844. }
  11845. hw->vendor_id = pdev->vendor;
  11846. hw->device_id = pdev->device;
  11847. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  11848. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  11849. hw->subsystem_device_id = pdev->subsystem_device;
  11850. hw->bus.device = PCI_SLOT(pdev->devfn);
  11851. hw->bus.func = PCI_FUNC(pdev->devfn);
  11852. hw->bus.bus_id = pdev->bus->number;
  11853. pf->instance = pfs_found;
  11854. /* Select something other than the 802.1ad ethertype for the
  11855. * switch to use internally and drop on ingress.
  11856. */
  11857. hw->switch_tag = 0xffff;
  11858. hw->first_tag = ETH_P_8021AD;
  11859. hw->second_tag = ETH_P_8021Q;
  11860. INIT_LIST_HEAD(&pf->l3_flex_pit_list);
  11861. INIT_LIST_HEAD(&pf->l4_flex_pit_list);
  11862. /* set up the locks for the AQ, do this only once in probe
  11863. * and destroy them only once in remove
  11864. */
  11865. mutex_init(&hw->aq.asq_mutex);
  11866. mutex_init(&hw->aq.arq_mutex);
  11867. pf->msg_enable = netif_msg_init(debug,
  11868. NETIF_MSG_DRV |
  11869. NETIF_MSG_PROBE |
  11870. NETIF_MSG_LINK);
  11871. if (debug < -1)
  11872. pf->hw.debug_mask = debug;
  11873. /* do a special CORER for clearing PXE mode once at init */
  11874. if (hw->revision_id == 0 &&
  11875. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  11876. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  11877. i40e_flush(hw);
  11878. msleep(200);
  11879. pf->corer_count++;
  11880. i40e_clear_pxe_mode(hw);
  11881. }
  11882. /* Reset here to make sure all is clean and to define PF 'n' */
  11883. i40e_clear_hw(hw);
  11884. err = i40e_pf_reset(hw);
  11885. if (err) {
  11886. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  11887. goto err_pf_reset;
  11888. }
  11889. pf->pfr_count++;
  11890. hw->aq.num_arq_entries = I40E_AQ_LEN;
  11891. hw->aq.num_asq_entries = I40E_AQ_LEN;
  11892. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11893. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  11894. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  11895. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  11896. "%s-%s:misc",
  11897. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  11898. err = i40e_init_shared_code(hw);
  11899. if (err) {
  11900. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  11901. err);
  11902. goto err_pf_reset;
  11903. }
  11904. /* set up a default setting for link flow control */
  11905. pf->hw.fc.requested_mode = I40E_FC_NONE;
  11906. err = i40e_init_adminq(hw);
  11907. if (err) {
  11908. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  11909. dev_info(&pdev->dev,
  11910. "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");
  11911. else
  11912. dev_info(&pdev->dev,
  11913. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  11914. goto err_pf_reset;
  11915. }
  11916. i40e_get_oem_version(hw);
  11917. /* provide nvm, fw, api versions */
  11918. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  11919. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  11920. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  11921. i40e_nvm_version_str(hw));
  11922. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  11923. hw->aq.api_min_ver > I40E_FW_MINOR_VERSION(hw))
  11924. dev_info(&pdev->dev,
  11925. "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");
  11926. else if (hw->aq.api_maj_ver == 1 && hw->aq.api_min_ver < 4)
  11927. dev_info(&pdev->dev,
  11928. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  11929. i40e_verify_eeprom(pf);
  11930. /* Rev 0 hardware was never productized */
  11931. if (hw->revision_id < 1)
  11932. 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");
  11933. i40e_clear_pxe_mode(hw);
  11934. err = i40e_get_capabilities(pf, i40e_aqc_opc_list_func_capabilities);
  11935. if (err)
  11936. goto err_adminq_setup;
  11937. err = i40e_sw_init(pf);
  11938. if (err) {
  11939. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  11940. goto err_sw_init;
  11941. }
  11942. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  11943. hw->func_caps.num_rx_qp, 0, 0);
  11944. if (err) {
  11945. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  11946. goto err_init_lan_hmc;
  11947. }
  11948. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  11949. if (err) {
  11950. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  11951. err = -ENOENT;
  11952. goto err_configure_lan_hmc;
  11953. }
  11954. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  11955. * Ignore error return codes because if it was already disabled via
  11956. * hardware settings this will fail
  11957. */
  11958. if (pf->hw_features & I40E_HW_STOP_FW_LLDP) {
  11959. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  11960. i40e_aq_stop_lldp(hw, true, NULL);
  11961. }
  11962. /* allow a platform config to override the HW addr */
  11963. i40e_get_platform_mac_addr(pdev, pf);
  11964. if (!is_valid_ether_addr(hw->mac.addr)) {
  11965. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  11966. err = -EIO;
  11967. goto err_mac_addr;
  11968. }
  11969. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  11970. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  11971. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  11972. if (is_valid_ether_addr(hw->mac.port_addr))
  11973. pf->hw_features |= I40E_HW_PORT_ID_VALID;
  11974. pci_set_drvdata(pdev, pf);
  11975. pci_save_state(pdev);
  11976. /* Enable FW to write default DCB config on link-up */
  11977. i40e_aq_set_dcb_parameters(hw, true, NULL);
  11978. #ifdef CONFIG_I40E_DCB
  11979. err = i40e_init_pf_dcb(pf);
  11980. if (err) {
  11981. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  11982. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  11983. /* Continue without DCB enabled */
  11984. }
  11985. #endif /* CONFIG_I40E_DCB */
  11986. /* set up periodic task facility */
  11987. timer_setup(&pf->service_timer, i40e_service_timer, 0);
  11988. pf->service_timer_period = HZ;
  11989. INIT_WORK(&pf->service_task, i40e_service_task);
  11990. clear_bit(__I40E_SERVICE_SCHED, pf->state);
  11991. /* NVM bit on means WoL disabled for the port */
  11992. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  11993. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  11994. pf->wol_en = false;
  11995. else
  11996. pf->wol_en = true;
  11997. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  11998. /* set up the main switch operations */
  11999. i40e_determine_queue_usage(pf);
  12000. err = i40e_init_interrupt_scheme(pf);
  12001. if (err)
  12002. goto err_switch_setup;
  12003. /* The number of VSIs reported by the FW is the minimum guaranteed
  12004. * to us; HW supports far more and we share the remaining pool with
  12005. * the other PFs. We allocate space for more than the guarantee with
  12006. * the understanding that we might not get them all later.
  12007. */
  12008. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  12009. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  12010. else
  12011. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  12012. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  12013. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  12014. GFP_KERNEL);
  12015. if (!pf->vsi) {
  12016. err = -ENOMEM;
  12017. goto err_switch_setup;
  12018. }
  12019. #ifdef CONFIG_PCI_IOV
  12020. /* prep for VF support */
  12021. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12022. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12023. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12024. if (pci_num_vf(pdev))
  12025. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  12026. }
  12027. #endif
  12028. err = i40e_setup_pf_switch(pf, false);
  12029. if (err) {
  12030. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  12031. goto err_vsis;
  12032. }
  12033. INIT_LIST_HEAD(&pf->vsi[pf->lan_vsi]->ch_list);
  12034. /* Make sure flow control is set according to current settings */
  12035. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  12036. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  12037. dev_dbg(&pf->pdev->dev,
  12038. "Set fc with err %s aq_err %s on get_phy_cap\n",
  12039. i40e_stat_str(hw, err),
  12040. i40e_aq_str(hw, hw->aq.asq_last_status));
  12041. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  12042. dev_dbg(&pf->pdev->dev,
  12043. "Set fc with err %s aq_err %s on set_phy_config\n",
  12044. i40e_stat_str(hw, err),
  12045. i40e_aq_str(hw, hw->aq.asq_last_status));
  12046. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  12047. dev_dbg(&pf->pdev->dev,
  12048. "Set fc with err %s aq_err %s on get_link_info\n",
  12049. i40e_stat_str(hw, err),
  12050. i40e_aq_str(hw, hw->aq.asq_last_status));
  12051. /* if FDIR VSI was set up, start it now */
  12052. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12053. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  12054. i40e_vsi_open(pf->vsi[i]);
  12055. break;
  12056. }
  12057. }
  12058. /* The driver only wants link up/down and module qualification
  12059. * reports from firmware. Note the negative logic.
  12060. */
  12061. err = i40e_aq_set_phy_int_mask(&pf->hw,
  12062. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  12063. I40E_AQ_EVENT_MEDIA_NA |
  12064. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  12065. if (err)
  12066. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  12067. i40e_stat_str(&pf->hw, err),
  12068. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12069. /* Reconfigure hardware for allowing smaller MSS in the case
  12070. * of TSO, so that we avoid the MDD being fired and causing
  12071. * a reset in the case of small MSS+TSO.
  12072. */
  12073. val = rd32(hw, I40E_REG_MSS);
  12074. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  12075. val &= ~I40E_REG_MSS_MIN_MASK;
  12076. val |= I40E_64BYTE_MSS;
  12077. wr32(hw, I40E_REG_MSS, val);
  12078. }
  12079. if (pf->hw_features & I40E_HW_RESTART_AUTONEG) {
  12080. msleep(75);
  12081. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  12082. if (err)
  12083. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  12084. i40e_stat_str(&pf->hw, err),
  12085. i40e_aq_str(&pf->hw,
  12086. pf->hw.aq.asq_last_status));
  12087. }
  12088. /* The main driver is (mostly) up and happy. We need to set this state
  12089. * before setting up the misc vector or we get a race and the vector
  12090. * ends up disabled forever.
  12091. */
  12092. clear_bit(__I40E_DOWN, pf->state);
  12093. /* In case of MSIX we are going to setup the misc vector right here
  12094. * to handle admin queue events etc. In case of legacy and MSI
  12095. * the misc functionality and queue processing is combined in
  12096. * the same vector and that gets setup at open.
  12097. */
  12098. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  12099. err = i40e_setup_misc_vector(pf);
  12100. if (err) {
  12101. dev_info(&pdev->dev,
  12102. "setup of misc vector failed: %d\n", err);
  12103. goto err_vsis;
  12104. }
  12105. }
  12106. #ifdef CONFIG_PCI_IOV
  12107. /* prep for VF support */
  12108. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  12109. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  12110. !test_bit(__I40E_BAD_EEPROM, pf->state)) {
  12111. /* disable link interrupts for VFs */
  12112. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  12113. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  12114. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  12115. i40e_flush(hw);
  12116. if (pci_num_vf(pdev)) {
  12117. dev_info(&pdev->dev,
  12118. "Active VFs found, allocating resources.\n");
  12119. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  12120. if (err)
  12121. dev_info(&pdev->dev,
  12122. "Error %d allocating resources for existing VFs\n",
  12123. err);
  12124. }
  12125. }
  12126. #endif /* CONFIG_PCI_IOV */
  12127. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12128. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  12129. pf->num_iwarp_msix,
  12130. I40E_IWARP_IRQ_PILE_ID);
  12131. if (pf->iwarp_base_vector < 0) {
  12132. dev_info(&pdev->dev,
  12133. "failed to get tracking for %d vectors for IWARP err=%d\n",
  12134. pf->num_iwarp_msix, pf->iwarp_base_vector);
  12135. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  12136. }
  12137. }
  12138. i40e_dbg_pf_init(pf);
  12139. /* tell the firmware that we're starting */
  12140. i40e_send_version(pf);
  12141. /* since everything's happy, start the service_task timer */
  12142. mod_timer(&pf->service_timer,
  12143. round_jiffies(jiffies + pf->service_timer_period));
  12144. /* add this PF to client device list and launch a client service task */
  12145. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12146. err = i40e_lan_add_device(pf);
  12147. if (err)
  12148. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  12149. err);
  12150. }
  12151. #define PCI_SPEED_SIZE 8
  12152. #define PCI_WIDTH_SIZE 8
  12153. /* Devices on the IOSF bus do not have this information
  12154. * and will report PCI Gen 1 x 1 by default so don't bother
  12155. * checking them.
  12156. */
  12157. if (!(pf->hw_features & I40E_HW_NO_PCI_LINK_CHECK)) {
  12158. char speed[PCI_SPEED_SIZE] = "Unknown";
  12159. char width[PCI_WIDTH_SIZE] = "Unknown";
  12160. /* Get the negotiated link width and speed from PCI config
  12161. * space
  12162. */
  12163. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  12164. &link_status);
  12165. i40e_set_pci_config_data(hw, link_status);
  12166. switch (hw->bus.speed) {
  12167. case i40e_bus_speed_8000:
  12168. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  12169. case i40e_bus_speed_5000:
  12170. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  12171. case i40e_bus_speed_2500:
  12172. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  12173. default:
  12174. break;
  12175. }
  12176. switch (hw->bus.width) {
  12177. case i40e_bus_width_pcie_x8:
  12178. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  12179. case i40e_bus_width_pcie_x4:
  12180. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  12181. case i40e_bus_width_pcie_x2:
  12182. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  12183. case i40e_bus_width_pcie_x1:
  12184. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  12185. default:
  12186. break;
  12187. }
  12188. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  12189. speed, width);
  12190. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  12191. hw->bus.speed < i40e_bus_speed_8000) {
  12192. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  12193. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  12194. }
  12195. }
  12196. /* get the requested speeds from the fw */
  12197. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  12198. if (err)
  12199. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  12200. i40e_stat_str(&pf->hw, err),
  12201. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12202. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  12203. /* get the supported phy types from the fw */
  12204. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  12205. if (err)
  12206. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  12207. i40e_stat_str(&pf->hw, err),
  12208. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  12209. /* Add a filter to drop all Flow control frames from any VSI from being
  12210. * transmitted. By doing so we stop a malicious VF from sending out
  12211. * PAUSE or PFC frames and potentially controlling traffic for other
  12212. * PF/VF VSIs.
  12213. * The FW can still send Flow control frames if enabled.
  12214. */
  12215. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  12216. pf->main_vsi_seid);
  12217. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  12218. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  12219. pf->hw_features |= I40E_HW_PHY_CONTROLS_LEDS;
  12220. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  12221. pf->hw_features |= I40E_HW_HAVE_CRT_RETIMER;
  12222. /* print a string summarizing features */
  12223. i40e_print_features(pf);
  12224. return 0;
  12225. /* Unwind what we've done if something failed in the setup */
  12226. err_vsis:
  12227. set_bit(__I40E_DOWN, pf->state);
  12228. i40e_clear_interrupt_scheme(pf);
  12229. kfree(pf->vsi);
  12230. err_switch_setup:
  12231. i40e_reset_interrupt_capability(pf);
  12232. del_timer_sync(&pf->service_timer);
  12233. err_mac_addr:
  12234. err_configure_lan_hmc:
  12235. (void)i40e_shutdown_lan_hmc(hw);
  12236. err_init_lan_hmc:
  12237. kfree(pf->qp_pile);
  12238. err_sw_init:
  12239. err_adminq_setup:
  12240. err_pf_reset:
  12241. iounmap(hw->hw_addr);
  12242. err_ioremap:
  12243. kfree(pf);
  12244. err_pf_alloc:
  12245. pci_disable_pcie_error_reporting(pdev);
  12246. pci_release_mem_regions(pdev);
  12247. err_pci_reg:
  12248. err_dma:
  12249. pci_disable_device(pdev);
  12250. return err;
  12251. }
  12252. /**
  12253. * i40e_remove - Device removal routine
  12254. * @pdev: PCI device information struct
  12255. *
  12256. * i40e_remove is called by the PCI subsystem to alert the driver
  12257. * that is should release a PCI device. This could be caused by a
  12258. * Hot-Plug event, or because the driver is going to be removed from
  12259. * memory.
  12260. **/
  12261. static void i40e_remove(struct pci_dev *pdev)
  12262. {
  12263. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12264. struct i40e_hw *hw = &pf->hw;
  12265. i40e_status ret_code;
  12266. int i;
  12267. i40e_dbg_pf_exit(pf);
  12268. i40e_ptp_stop(pf);
  12269. /* Disable RSS in hw */
  12270. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  12271. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  12272. /* no more scheduling of any task */
  12273. set_bit(__I40E_SUSPENDED, pf->state);
  12274. set_bit(__I40E_DOWN, pf->state);
  12275. if (pf->service_timer.function)
  12276. del_timer_sync(&pf->service_timer);
  12277. if (pf->service_task.func)
  12278. cancel_work_sync(&pf->service_task);
  12279. /* Client close must be called explicitly here because the timer
  12280. * has been stopped.
  12281. */
  12282. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12283. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  12284. i40e_free_vfs(pf);
  12285. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  12286. }
  12287. i40e_fdir_teardown(pf);
  12288. /* If there is a switch structure or any orphans, remove them.
  12289. * This will leave only the PF's VSI remaining.
  12290. */
  12291. for (i = 0; i < I40E_MAX_VEB; i++) {
  12292. if (!pf->veb[i])
  12293. continue;
  12294. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  12295. pf->veb[i]->uplink_seid == 0)
  12296. i40e_switch_branch_release(pf->veb[i]);
  12297. }
  12298. /* Now we can shutdown the PF's VSI, just before we kill
  12299. * adminq and hmc.
  12300. */
  12301. if (pf->vsi[pf->lan_vsi])
  12302. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  12303. i40e_cloud_filter_exit(pf);
  12304. /* remove attached clients */
  12305. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  12306. ret_code = i40e_lan_del_device(pf);
  12307. if (ret_code)
  12308. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  12309. ret_code);
  12310. }
  12311. /* shutdown and destroy the HMC */
  12312. if (hw->hmc.hmc_obj) {
  12313. ret_code = i40e_shutdown_lan_hmc(hw);
  12314. if (ret_code)
  12315. dev_warn(&pdev->dev,
  12316. "Failed to destroy the HMC resources: %d\n",
  12317. ret_code);
  12318. }
  12319. /* shutdown the adminq */
  12320. i40e_shutdown_adminq(hw);
  12321. /* destroy the locks only once, here */
  12322. mutex_destroy(&hw->aq.arq_mutex);
  12323. mutex_destroy(&hw->aq.asq_mutex);
  12324. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  12325. i40e_clear_interrupt_scheme(pf);
  12326. for (i = 0; i < pf->num_alloc_vsi; i++) {
  12327. if (pf->vsi[i]) {
  12328. i40e_vsi_clear_rings(pf->vsi[i]);
  12329. i40e_vsi_clear(pf->vsi[i]);
  12330. pf->vsi[i] = NULL;
  12331. }
  12332. }
  12333. for (i = 0; i < I40E_MAX_VEB; i++) {
  12334. kfree(pf->veb[i]);
  12335. pf->veb[i] = NULL;
  12336. }
  12337. kfree(pf->qp_pile);
  12338. kfree(pf->vsi);
  12339. iounmap(hw->hw_addr);
  12340. kfree(pf);
  12341. pci_release_mem_regions(pdev);
  12342. pci_disable_pcie_error_reporting(pdev);
  12343. pci_disable_device(pdev);
  12344. }
  12345. /**
  12346. * i40e_pci_error_detected - warning that something funky happened in PCI land
  12347. * @pdev: PCI device information struct
  12348. * @error: the type of PCI error
  12349. *
  12350. * Called to warn that something happened and the error handling steps
  12351. * are in progress. Allows the driver to quiesce things, be ready for
  12352. * remediation.
  12353. **/
  12354. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  12355. enum pci_channel_state error)
  12356. {
  12357. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12358. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  12359. if (!pf) {
  12360. dev_info(&pdev->dev,
  12361. "Cannot recover - error happened during device probe\n");
  12362. return PCI_ERS_RESULT_DISCONNECT;
  12363. }
  12364. /* shutdown all operations */
  12365. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12366. i40e_prep_for_reset(pf, false);
  12367. /* Request a slot reset */
  12368. return PCI_ERS_RESULT_NEED_RESET;
  12369. }
  12370. /**
  12371. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  12372. * @pdev: PCI device information struct
  12373. *
  12374. * Called to find if the driver can work with the device now that
  12375. * the pci slot has been reset. If a basic connection seems good
  12376. * (registers are readable and have sane content) then return a
  12377. * happy little PCI_ERS_RESULT_xxx.
  12378. **/
  12379. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  12380. {
  12381. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12382. pci_ers_result_t result;
  12383. int err;
  12384. u32 reg;
  12385. dev_dbg(&pdev->dev, "%s\n", __func__);
  12386. if (pci_enable_device_mem(pdev)) {
  12387. dev_info(&pdev->dev,
  12388. "Cannot re-enable PCI device after reset.\n");
  12389. result = PCI_ERS_RESULT_DISCONNECT;
  12390. } else {
  12391. pci_set_master(pdev);
  12392. pci_restore_state(pdev);
  12393. pci_save_state(pdev);
  12394. pci_wake_from_d3(pdev, false);
  12395. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  12396. if (reg == 0)
  12397. result = PCI_ERS_RESULT_RECOVERED;
  12398. else
  12399. result = PCI_ERS_RESULT_DISCONNECT;
  12400. }
  12401. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  12402. if (err) {
  12403. dev_info(&pdev->dev,
  12404. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  12405. err);
  12406. /* non-fatal, continue */
  12407. }
  12408. return result;
  12409. }
  12410. /**
  12411. * i40e_pci_error_reset_prepare - prepare device driver for pci reset
  12412. * @pdev: PCI device information struct
  12413. */
  12414. static void i40e_pci_error_reset_prepare(struct pci_dev *pdev)
  12415. {
  12416. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12417. i40e_prep_for_reset(pf, false);
  12418. }
  12419. /**
  12420. * i40e_pci_error_reset_done - pci reset done, device driver reset can begin
  12421. * @pdev: PCI device information struct
  12422. */
  12423. static void i40e_pci_error_reset_done(struct pci_dev *pdev)
  12424. {
  12425. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12426. i40e_reset_and_rebuild(pf, false, false);
  12427. }
  12428. /**
  12429. * i40e_pci_error_resume - restart operations after PCI error recovery
  12430. * @pdev: PCI device information struct
  12431. *
  12432. * Called to allow the driver to bring things back up after PCI error
  12433. * and/or reset recovery has finished.
  12434. **/
  12435. static void i40e_pci_error_resume(struct pci_dev *pdev)
  12436. {
  12437. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12438. dev_dbg(&pdev->dev, "%s\n", __func__);
  12439. if (test_bit(__I40E_SUSPENDED, pf->state))
  12440. return;
  12441. i40e_handle_reset_warning(pf, false);
  12442. }
  12443. /**
  12444. * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
  12445. * using the mac_address_write admin q function
  12446. * @pf: pointer to i40e_pf struct
  12447. **/
  12448. static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
  12449. {
  12450. struct i40e_hw *hw = &pf->hw;
  12451. i40e_status ret;
  12452. u8 mac_addr[6];
  12453. u16 flags = 0;
  12454. /* Get current MAC address in case it's an LAA */
  12455. if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
  12456. ether_addr_copy(mac_addr,
  12457. pf->vsi[pf->lan_vsi]->netdev->dev_addr);
  12458. } else {
  12459. dev_err(&pf->pdev->dev,
  12460. "Failed to retrieve MAC address; using default\n");
  12461. ether_addr_copy(mac_addr, hw->mac.addr);
  12462. }
  12463. /* The FW expects the mac address write cmd to first be called with
  12464. * one of these flags before calling it again with the multicast
  12465. * enable flags.
  12466. */
  12467. flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
  12468. if (hw->func_caps.flex10_enable && hw->partition_id != 1)
  12469. flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
  12470. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12471. if (ret) {
  12472. dev_err(&pf->pdev->dev,
  12473. "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
  12474. return;
  12475. }
  12476. flags = I40E_AQC_MC_MAG_EN
  12477. | I40E_AQC_WOL_PRESERVE_ON_PFR
  12478. | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
  12479. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  12480. if (ret)
  12481. dev_err(&pf->pdev->dev,
  12482. "Failed to enable Multicast Magic Packet wake up\n");
  12483. }
  12484. /**
  12485. * i40e_shutdown - PCI callback for shutting down
  12486. * @pdev: PCI device information struct
  12487. **/
  12488. static void i40e_shutdown(struct pci_dev *pdev)
  12489. {
  12490. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12491. struct i40e_hw *hw = &pf->hw;
  12492. set_bit(__I40E_SUSPENDED, pf->state);
  12493. set_bit(__I40E_DOWN, pf->state);
  12494. rtnl_lock();
  12495. i40e_prep_for_reset(pf, true);
  12496. rtnl_unlock();
  12497. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12498. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12499. del_timer_sync(&pf->service_timer);
  12500. cancel_work_sync(&pf->service_task);
  12501. i40e_cloud_filter_exit(pf);
  12502. i40e_fdir_teardown(pf);
  12503. /* Client close must be called explicitly here because the timer
  12504. * has been stopped.
  12505. */
  12506. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12507. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12508. i40e_enable_mc_magic_wake(pf);
  12509. i40e_prep_for_reset(pf, false);
  12510. wr32(hw, I40E_PFPM_APM,
  12511. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12512. wr32(hw, I40E_PFPM_WUFC,
  12513. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12514. i40e_clear_interrupt_scheme(pf);
  12515. if (system_state == SYSTEM_POWER_OFF) {
  12516. pci_wake_from_d3(pdev, pf->wol_en);
  12517. pci_set_power_state(pdev, PCI_D3hot);
  12518. }
  12519. }
  12520. /**
  12521. * i40e_suspend - PM callback for moving to D3
  12522. * @dev: generic device information structure
  12523. **/
  12524. static int __maybe_unused i40e_suspend(struct device *dev)
  12525. {
  12526. struct pci_dev *pdev = to_pci_dev(dev);
  12527. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12528. struct i40e_hw *hw = &pf->hw;
  12529. /* If we're already suspended, then there is nothing to do */
  12530. if (test_and_set_bit(__I40E_SUSPENDED, pf->state))
  12531. return 0;
  12532. set_bit(__I40E_DOWN, pf->state);
  12533. /* Ensure service task will not be running */
  12534. del_timer_sync(&pf->service_timer);
  12535. cancel_work_sync(&pf->service_task);
  12536. /* Client close must be called explicitly here because the timer
  12537. * has been stopped.
  12538. */
  12539. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], false);
  12540. if (pf->wol_en && (pf->hw_features & I40E_HW_WOL_MC_MAGIC_PKT_WAKE))
  12541. i40e_enable_mc_magic_wake(pf);
  12542. /* Since we're going to destroy queues during the
  12543. * i40e_clear_interrupt_scheme() we should hold the RTNL lock for this
  12544. * whole section
  12545. */
  12546. rtnl_lock();
  12547. i40e_prep_for_reset(pf, true);
  12548. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  12549. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  12550. /* Clear the interrupt scheme and release our IRQs so that the system
  12551. * can safely hibernate even when there are a large number of CPUs.
  12552. * Otherwise hibernation might fail when mapping all the vectors back
  12553. * to CPU0.
  12554. */
  12555. i40e_clear_interrupt_scheme(pf);
  12556. rtnl_unlock();
  12557. return 0;
  12558. }
  12559. /**
  12560. * i40e_resume - PM callback for waking up from D3
  12561. * @dev: generic device information structure
  12562. **/
  12563. static int __maybe_unused i40e_resume(struct device *dev)
  12564. {
  12565. struct pci_dev *pdev = to_pci_dev(dev);
  12566. struct i40e_pf *pf = pci_get_drvdata(pdev);
  12567. int err;
  12568. /* If we're not suspended, then there is nothing to do */
  12569. if (!test_bit(__I40E_SUSPENDED, pf->state))
  12570. return 0;
  12571. /* We need to hold the RTNL lock prior to restoring interrupt schemes,
  12572. * since we're going to be restoring queues
  12573. */
  12574. rtnl_lock();
  12575. /* We cleared the interrupt scheme when we suspended, so we need to
  12576. * restore it now to resume device functionality.
  12577. */
  12578. err = i40e_restore_interrupt_scheme(pf);
  12579. if (err) {
  12580. dev_err(&pdev->dev, "Cannot restore interrupt scheme: %d\n",
  12581. err);
  12582. }
  12583. clear_bit(__I40E_DOWN, pf->state);
  12584. i40e_reset_and_rebuild(pf, false, true);
  12585. rtnl_unlock();
  12586. /* Clear suspended state last after everything is recovered */
  12587. clear_bit(__I40E_SUSPENDED, pf->state);
  12588. /* Restart the service task */
  12589. mod_timer(&pf->service_timer,
  12590. round_jiffies(jiffies + pf->service_timer_period));
  12591. return 0;
  12592. }
  12593. static const struct pci_error_handlers i40e_err_handler = {
  12594. .error_detected = i40e_pci_error_detected,
  12595. .slot_reset = i40e_pci_error_slot_reset,
  12596. .reset_prepare = i40e_pci_error_reset_prepare,
  12597. .reset_done = i40e_pci_error_reset_done,
  12598. .resume = i40e_pci_error_resume,
  12599. };
  12600. static SIMPLE_DEV_PM_OPS(i40e_pm_ops, i40e_suspend, i40e_resume);
  12601. static struct pci_driver i40e_driver = {
  12602. .name = i40e_driver_name,
  12603. .id_table = i40e_pci_tbl,
  12604. .probe = i40e_probe,
  12605. .remove = i40e_remove,
  12606. .driver = {
  12607. .pm = &i40e_pm_ops,
  12608. },
  12609. .shutdown = i40e_shutdown,
  12610. .err_handler = &i40e_err_handler,
  12611. .sriov_configure = i40e_pci_sriov_configure,
  12612. };
  12613. /**
  12614. * i40e_init_module - Driver registration routine
  12615. *
  12616. * i40e_init_module is the first routine called when the driver is
  12617. * loaded. All it does is register with the PCI subsystem.
  12618. **/
  12619. static int __init i40e_init_module(void)
  12620. {
  12621. pr_info("%s: %s - version %s\n", i40e_driver_name,
  12622. i40e_driver_string, i40e_driver_version_str);
  12623. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  12624. /* There is no need to throttle the number of active tasks because
  12625. * each device limits its own task using a state bit for scheduling
  12626. * the service task, and the device tasks do not interfere with each
  12627. * other, so we don't set a max task limit. We must set WQ_MEM_RECLAIM
  12628. * since we need to be able to guarantee forward progress even under
  12629. * memory pressure.
  12630. */
  12631. i40e_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, i40e_driver_name);
  12632. if (!i40e_wq) {
  12633. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  12634. return -ENOMEM;
  12635. }
  12636. i40e_dbg_init();
  12637. return pci_register_driver(&i40e_driver);
  12638. }
  12639. module_init(i40e_init_module);
  12640. /**
  12641. * i40e_exit_module - Driver exit cleanup routine
  12642. *
  12643. * i40e_exit_module is called just before the driver is removed
  12644. * from memory.
  12645. **/
  12646. static void __exit i40e_exit_module(void)
  12647. {
  12648. pci_unregister_driver(&i40e_driver);
  12649. destroy_workqueue(i40e_wq);
  12650. i40e_dbg_exit();
  12651. }
  12652. module_exit(i40e_exit_module);