i40e_main.c 318 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include <linux/etherdevice.h>
  27. #include <linux/of_net.h>
  28. #include <linux/pci.h>
  29. /* Local includes */
  30. #include "i40e.h"
  31. #include "i40e_diag.h"
  32. #if IS_ENABLED(CONFIG_VXLAN)
  33. #include <net/vxlan.h>
  34. #endif
  35. #if IS_ENABLED(CONFIG_GENEVE)
  36. #include <net/geneve.h>
  37. #endif
  38. const char i40e_driver_name[] = "i40e";
  39. static const char i40e_driver_string[] =
  40. "Intel(R) Ethernet Connection XL710 Network Driver";
  41. #define DRV_KERN "-k"
  42. #define DRV_VERSION_MAJOR 1
  43. #define DRV_VERSION_MINOR 5
  44. #define DRV_VERSION_BUILD 1
  45. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  46. __stringify(DRV_VERSION_MINOR) "." \
  47. __stringify(DRV_VERSION_BUILD) DRV_KERN
  48. const char i40e_driver_version_str[] = DRV_VERSION;
  49. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  50. /* a bit of forward declarations */
  51. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  52. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  53. static int i40e_add_vsi(struct i40e_vsi *vsi);
  54. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  55. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  56. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  57. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  58. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  59. static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  60. u16 rss_table_size, u16 rss_size);
  61. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  62. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  63. /* i40e_pci_tbl - PCI Device ID Table
  64. *
  65. * Last entry must be all 0s
  66. *
  67. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  68. * Class, Class Mask, private data (not used) }
  69. */
  70. static const struct pci_device_id i40e_pci_tbl[] = {
  71. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  72. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  73. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  74. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  75. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  76. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  77. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  78. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  79. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  80. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  81. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  82. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  83. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  84. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  85. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  86. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  87. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  88. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  89. /* required last entry */
  90. {0, }
  91. };
  92. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  93. #define I40E_MAX_VF_COUNT 128
  94. static int debug = -1;
  95. module_param(debug, int, 0);
  96. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  97. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  98. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  99. MODULE_LICENSE("GPL");
  100. MODULE_VERSION(DRV_VERSION);
  101. static struct workqueue_struct *i40e_wq;
  102. /**
  103. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  104. * @hw: pointer to the HW structure
  105. * @mem: ptr to mem struct to fill out
  106. * @size: size of memory requested
  107. * @alignment: what to align the allocation to
  108. **/
  109. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  110. u64 size, u32 alignment)
  111. {
  112. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  113. mem->size = ALIGN(size, alignment);
  114. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  115. &mem->pa, GFP_KERNEL);
  116. if (!mem->va)
  117. return -ENOMEM;
  118. return 0;
  119. }
  120. /**
  121. * i40e_free_dma_mem_d - OS specific memory free for shared code
  122. * @hw: pointer to the HW structure
  123. * @mem: ptr to mem struct to free
  124. **/
  125. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  126. {
  127. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  128. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  129. mem->va = NULL;
  130. mem->pa = 0;
  131. mem->size = 0;
  132. return 0;
  133. }
  134. /**
  135. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  136. * @hw: pointer to the HW structure
  137. * @mem: ptr to mem struct to fill out
  138. * @size: size of memory requested
  139. **/
  140. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  141. u32 size)
  142. {
  143. mem->size = size;
  144. mem->va = kzalloc(size, GFP_KERNEL);
  145. if (!mem->va)
  146. return -ENOMEM;
  147. return 0;
  148. }
  149. /**
  150. * i40e_free_virt_mem_d - OS specific memory free for shared code
  151. * @hw: pointer to the HW structure
  152. * @mem: ptr to mem struct to free
  153. **/
  154. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  155. {
  156. /* it's ok to kfree a NULL pointer */
  157. kfree(mem->va);
  158. mem->va = NULL;
  159. mem->size = 0;
  160. return 0;
  161. }
  162. /**
  163. * i40e_get_lump - find a lump of free generic resource
  164. * @pf: board private structure
  165. * @pile: the pile of resource to search
  166. * @needed: the number of items needed
  167. * @id: an owner id to stick on the items assigned
  168. *
  169. * Returns the base item index of the lump, or negative for error
  170. *
  171. * The search_hint trick and lack of advanced fit-finding only work
  172. * because we're highly likely to have all the same size lump requests.
  173. * Linear search time and any fragmentation should be minimal.
  174. **/
  175. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  176. u16 needed, u16 id)
  177. {
  178. int ret = -ENOMEM;
  179. int i, j;
  180. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  181. dev_info(&pf->pdev->dev,
  182. "param err: pile=%p needed=%d id=0x%04x\n",
  183. pile, needed, id);
  184. return -EINVAL;
  185. }
  186. /* start the linear search with an imperfect hint */
  187. i = pile->search_hint;
  188. while (i < pile->num_entries) {
  189. /* skip already allocated entries */
  190. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  191. i++;
  192. continue;
  193. }
  194. /* do we have enough in this lump? */
  195. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  196. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  197. break;
  198. }
  199. if (j == needed) {
  200. /* there was enough, so assign it to the requestor */
  201. for (j = 0; j < needed; j++)
  202. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  203. ret = i;
  204. pile->search_hint = i + j;
  205. break;
  206. }
  207. /* not enough, so skip over it and continue looking */
  208. i += j;
  209. }
  210. return ret;
  211. }
  212. /**
  213. * i40e_put_lump - return a lump of generic resource
  214. * @pile: the pile of resource to search
  215. * @index: the base item index
  216. * @id: the owner id of the items assigned
  217. *
  218. * Returns the count of items in the lump
  219. **/
  220. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  221. {
  222. int valid_id = (id | I40E_PILE_VALID_BIT);
  223. int count = 0;
  224. int i;
  225. if (!pile || index >= pile->num_entries)
  226. return -EINVAL;
  227. for (i = index;
  228. i < pile->num_entries && pile->list[i] == valid_id;
  229. i++) {
  230. pile->list[i] = 0;
  231. count++;
  232. }
  233. if (count && index < pile->search_hint)
  234. pile->search_hint = index;
  235. return count;
  236. }
  237. /**
  238. * i40e_find_vsi_from_id - searches for the vsi with the given id
  239. * @pf - the pf structure to search for the vsi
  240. * @id - id of the vsi it is searching for
  241. **/
  242. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  243. {
  244. int i;
  245. for (i = 0; i < pf->num_alloc_vsi; i++)
  246. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  247. return pf->vsi[i];
  248. return NULL;
  249. }
  250. /**
  251. * i40e_service_event_schedule - Schedule the service task to wake up
  252. * @pf: board private structure
  253. *
  254. * If not already scheduled, this puts the task into the work queue
  255. **/
  256. void i40e_service_event_schedule(struct i40e_pf *pf)
  257. {
  258. if (!test_bit(__I40E_DOWN, &pf->state) &&
  259. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
  260. !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  261. queue_work(i40e_wq, &pf->service_task);
  262. }
  263. /**
  264. * i40e_tx_timeout - Respond to a Tx Hang
  265. * @netdev: network interface device structure
  266. *
  267. * If any port has noticed a Tx timeout, it is likely that the whole
  268. * device is munged, not just the one netdev port, so go for the full
  269. * reset.
  270. **/
  271. #ifdef I40E_FCOE
  272. void i40e_tx_timeout(struct net_device *netdev)
  273. #else
  274. static void i40e_tx_timeout(struct net_device *netdev)
  275. #endif
  276. {
  277. struct i40e_netdev_priv *np = netdev_priv(netdev);
  278. struct i40e_vsi *vsi = np->vsi;
  279. struct i40e_pf *pf = vsi->back;
  280. struct i40e_ring *tx_ring = NULL;
  281. unsigned int i, hung_queue = 0;
  282. u32 head, val;
  283. pf->tx_timeout_count++;
  284. /* find the stopped queue the same way the stack does */
  285. for (i = 0; i < netdev->num_tx_queues; i++) {
  286. struct netdev_queue *q;
  287. unsigned long trans_start;
  288. q = netdev_get_tx_queue(netdev, i);
  289. trans_start = q->trans_start ? : netdev->trans_start;
  290. if (netif_xmit_stopped(q) &&
  291. time_after(jiffies,
  292. (trans_start + netdev->watchdog_timeo))) {
  293. hung_queue = i;
  294. break;
  295. }
  296. }
  297. if (i == netdev->num_tx_queues) {
  298. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  299. } else {
  300. /* now that we have an index, find the tx_ring struct */
  301. for (i = 0; i < vsi->num_queue_pairs; i++) {
  302. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  303. if (hung_queue ==
  304. vsi->tx_rings[i]->queue_index) {
  305. tx_ring = vsi->tx_rings[i];
  306. break;
  307. }
  308. }
  309. }
  310. }
  311. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  312. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  313. else if (time_before(jiffies,
  314. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  315. return; /* don't do any new action before the next timeout */
  316. if (tx_ring) {
  317. head = i40e_get_head(tx_ring);
  318. /* Read interrupt register */
  319. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  320. val = rd32(&pf->hw,
  321. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  322. tx_ring->vsi->base_vector - 1));
  323. else
  324. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  325. 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",
  326. vsi->seid, hung_queue, tx_ring->next_to_clean,
  327. head, tx_ring->next_to_use,
  328. readl(tx_ring->tail), val);
  329. }
  330. pf->tx_timeout_last_recovery = jiffies;
  331. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  332. pf->tx_timeout_recovery_level, hung_queue);
  333. switch (pf->tx_timeout_recovery_level) {
  334. case 1:
  335. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  336. break;
  337. case 2:
  338. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  339. break;
  340. case 3:
  341. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  342. break;
  343. default:
  344. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  345. break;
  346. }
  347. i40e_service_event_schedule(pf);
  348. pf->tx_timeout_recovery_level++;
  349. }
  350. /**
  351. * i40e_release_rx_desc - Store the new tail and head values
  352. * @rx_ring: ring to bump
  353. * @val: new head index
  354. **/
  355. static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
  356. {
  357. rx_ring->next_to_use = val;
  358. /* Force memory writes to complete before letting h/w
  359. * know there are new descriptors to fetch. (Only
  360. * applicable for weak-ordered memory model archs,
  361. * such as IA-64).
  362. */
  363. wmb();
  364. writel(val, rx_ring->tail);
  365. }
  366. /**
  367. * i40e_get_vsi_stats_struct - Get System Network Statistics
  368. * @vsi: the VSI we care about
  369. *
  370. * Returns the address of the device statistics structure.
  371. * The statistics are actually updated from the service task.
  372. **/
  373. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  374. {
  375. return &vsi->net_stats;
  376. }
  377. /**
  378. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  379. * @netdev: network interface device structure
  380. *
  381. * Returns the address of the device statistics structure.
  382. * The statistics are actually updated from the service task.
  383. **/
  384. #ifdef I40E_FCOE
  385. struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  386. struct net_device *netdev,
  387. struct rtnl_link_stats64 *stats)
  388. #else
  389. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  390. struct net_device *netdev,
  391. struct rtnl_link_stats64 *stats)
  392. #endif
  393. {
  394. struct i40e_netdev_priv *np = netdev_priv(netdev);
  395. struct i40e_ring *tx_ring, *rx_ring;
  396. struct i40e_vsi *vsi = np->vsi;
  397. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  398. int i;
  399. if (test_bit(__I40E_DOWN, &vsi->state))
  400. return stats;
  401. if (!vsi->tx_rings)
  402. return stats;
  403. rcu_read_lock();
  404. for (i = 0; i < vsi->num_queue_pairs; i++) {
  405. u64 bytes, packets;
  406. unsigned int start;
  407. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  408. if (!tx_ring)
  409. continue;
  410. do {
  411. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  412. packets = tx_ring->stats.packets;
  413. bytes = tx_ring->stats.bytes;
  414. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  415. stats->tx_packets += packets;
  416. stats->tx_bytes += bytes;
  417. rx_ring = &tx_ring[1];
  418. do {
  419. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  420. packets = rx_ring->stats.packets;
  421. bytes = rx_ring->stats.bytes;
  422. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  423. stats->rx_packets += packets;
  424. stats->rx_bytes += bytes;
  425. }
  426. rcu_read_unlock();
  427. /* following stats updated by i40e_watchdog_subtask() */
  428. stats->multicast = vsi_stats->multicast;
  429. stats->tx_errors = vsi_stats->tx_errors;
  430. stats->tx_dropped = vsi_stats->tx_dropped;
  431. stats->rx_errors = vsi_stats->rx_errors;
  432. stats->rx_dropped = vsi_stats->rx_dropped;
  433. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  434. stats->rx_length_errors = vsi_stats->rx_length_errors;
  435. return stats;
  436. }
  437. /**
  438. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  439. * @vsi: the VSI to have its stats reset
  440. **/
  441. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  442. {
  443. struct rtnl_link_stats64 *ns;
  444. int i;
  445. if (!vsi)
  446. return;
  447. ns = i40e_get_vsi_stats_struct(vsi);
  448. memset(ns, 0, sizeof(*ns));
  449. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  450. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  451. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  452. if (vsi->rx_rings && vsi->rx_rings[0]) {
  453. for (i = 0; i < vsi->num_queue_pairs; i++) {
  454. memset(&vsi->rx_rings[i]->stats, 0,
  455. sizeof(vsi->rx_rings[i]->stats));
  456. memset(&vsi->rx_rings[i]->rx_stats, 0,
  457. sizeof(vsi->rx_rings[i]->rx_stats));
  458. memset(&vsi->tx_rings[i]->stats, 0,
  459. sizeof(vsi->tx_rings[i]->stats));
  460. memset(&vsi->tx_rings[i]->tx_stats, 0,
  461. sizeof(vsi->tx_rings[i]->tx_stats));
  462. }
  463. }
  464. vsi->stat_offsets_loaded = false;
  465. }
  466. /**
  467. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  468. * @pf: the PF to be reset
  469. **/
  470. void i40e_pf_reset_stats(struct i40e_pf *pf)
  471. {
  472. int i;
  473. memset(&pf->stats, 0, sizeof(pf->stats));
  474. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  475. pf->stat_offsets_loaded = false;
  476. for (i = 0; i < I40E_MAX_VEB; i++) {
  477. if (pf->veb[i]) {
  478. memset(&pf->veb[i]->stats, 0,
  479. sizeof(pf->veb[i]->stats));
  480. memset(&pf->veb[i]->stats_offsets, 0,
  481. sizeof(pf->veb[i]->stats_offsets));
  482. pf->veb[i]->stat_offsets_loaded = false;
  483. }
  484. }
  485. }
  486. /**
  487. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  488. * @hw: ptr to the hardware info
  489. * @hireg: the high 32 bit reg to read
  490. * @loreg: the low 32 bit reg to read
  491. * @offset_loaded: has the initial offset been loaded yet
  492. * @offset: ptr to current offset value
  493. * @stat: ptr to the stat
  494. *
  495. * Since the device stats are not reset at PFReset, they likely will not
  496. * be zeroed when the driver starts. We'll save the first values read
  497. * and use them as offsets to be subtracted from the raw values in order
  498. * to report stats that count from zero. In the process, we also manage
  499. * the potential roll-over.
  500. **/
  501. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  502. bool offset_loaded, u64 *offset, u64 *stat)
  503. {
  504. u64 new_data;
  505. if (hw->device_id == I40E_DEV_ID_QEMU) {
  506. new_data = rd32(hw, loreg);
  507. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  508. } else {
  509. new_data = rd64(hw, loreg);
  510. }
  511. if (!offset_loaded)
  512. *offset = new_data;
  513. if (likely(new_data >= *offset))
  514. *stat = new_data - *offset;
  515. else
  516. *stat = (new_data + BIT_ULL(48)) - *offset;
  517. *stat &= 0xFFFFFFFFFFFFULL;
  518. }
  519. /**
  520. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  521. * @hw: ptr to the hardware info
  522. * @reg: the hw reg to read
  523. * @offset_loaded: has the initial offset been loaded yet
  524. * @offset: ptr to current offset value
  525. * @stat: ptr to the stat
  526. **/
  527. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  528. bool offset_loaded, u64 *offset, u64 *stat)
  529. {
  530. u32 new_data;
  531. new_data = rd32(hw, reg);
  532. if (!offset_loaded)
  533. *offset = new_data;
  534. if (likely(new_data >= *offset))
  535. *stat = (u32)(new_data - *offset);
  536. else
  537. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  538. }
  539. /**
  540. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  541. * @vsi: the VSI to be updated
  542. **/
  543. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  544. {
  545. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  546. struct i40e_pf *pf = vsi->back;
  547. struct i40e_hw *hw = &pf->hw;
  548. struct i40e_eth_stats *oes;
  549. struct i40e_eth_stats *es; /* device's eth stats */
  550. es = &vsi->eth_stats;
  551. oes = &vsi->eth_stats_offsets;
  552. /* Gather up the stats that the hw collects */
  553. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  554. vsi->stat_offsets_loaded,
  555. &oes->tx_errors, &es->tx_errors);
  556. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  557. vsi->stat_offsets_loaded,
  558. &oes->rx_discards, &es->rx_discards);
  559. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  560. vsi->stat_offsets_loaded,
  561. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  562. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  563. vsi->stat_offsets_loaded,
  564. &oes->tx_errors, &es->tx_errors);
  565. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  566. I40E_GLV_GORCL(stat_idx),
  567. vsi->stat_offsets_loaded,
  568. &oes->rx_bytes, &es->rx_bytes);
  569. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  570. I40E_GLV_UPRCL(stat_idx),
  571. vsi->stat_offsets_loaded,
  572. &oes->rx_unicast, &es->rx_unicast);
  573. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  574. I40E_GLV_MPRCL(stat_idx),
  575. vsi->stat_offsets_loaded,
  576. &oes->rx_multicast, &es->rx_multicast);
  577. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  578. I40E_GLV_BPRCL(stat_idx),
  579. vsi->stat_offsets_loaded,
  580. &oes->rx_broadcast, &es->rx_broadcast);
  581. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  582. I40E_GLV_GOTCL(stat_idx),
  583. vsi->stat_offsets_loaded,
  584. &oes->tx_bytes, &es->tx_bytes);
  585. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  586. I40E_GLV_UPTCL(stat_idx),
  587. vsi->stat_offsets_loaded,
  588. &oes->tx_unicast, &es->tx_unicast);
  589. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  590. I40E_GLV_MPTCL(stat_idx),
  591. vsi->stat_offsets_loaded,
  592. &oes->tx_multicast, &es->tx_multicast);
  593. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  594. I40E_GLV_BPTCL(stat_idx),
  595. vsi->stat_offsets_loaded,
  596. &oes->tx_broadcast, &es->tx_broadcast);
  597. vsi->stat_offsets_loaded = true;
  598. }
  599. /**
  600. * i40e_update_veb_stats - Update Switch component statistics
  601. * @veb: the VEB being updated
  602. **/
  603. static void i40e_update_veb_stats(struct i40e_veb *veb)
  604. {
  605. struct i40e_pf *pf = veb->pf;
  606. struct i40e_hw *hw = &pf->hw;
  607. struct i40e_eth_stats *oes;
  608. struct i40e_eth_stats *es; /* device's eth stats */
  609. struct i40e_veb_tc_stats *veb_oes;
  610. struct i40e_veb_tc_stats *veb_es;
  611. int i, idx = 0;
  612. idx = veb->stats_idx;
  613. es = &veb->stats;
  614. oes = &veb->stats_offsets;
  615. veb_es = &veb->tc_stats;
  616. veb_oes = &veb->tc_stats_offsets;
  617. /* Gather up the stats that the hw collects */
  618. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  619. veb->stat_offsets_loaded,
  620. &oes->tx_discards, &es->tx_discards);
  621. if (hw->revision_id > 0)
  622. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  623. veb->stat_offsets_loaded,
  624. &oes->rx_unknown_protocol,
  625. &es->rx_unknown_protocol);
  626. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  627. veb->stat_offsets_loaded,
  628. &oes->rx_bytes, &es->rx_bytes);
  629. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  630. veb->stat_offsets_loaded,
  631. &oes->rx_unicast, &es->rx_unicast);
  632. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  633. veb->stat_offsets_loaded,
  634. &oes->rx_multicast, &es->rx_multicast);
  635. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  636. veb->stat_offsets_loaded,
  637. &oes->rx_broadcast, &es->rx_broadcast);
  638. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  639. veb->stat_offsets_loaded,
  640. &oes->tx_bytes, &es->tx_bytes);
  641. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  642. veb->stat_offsets_loaded,
  643. &oes->tx_unicast, &es->tx_unicast);
  644. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  645. veb->stat_offsets_loaded,
  646. &oes->tx_multicast, &es->tx_multicast);
  647. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  648. veb->stat_offsets_loaded,
  649. &oes->tx_broadcast, &es->tx_broadcast);
  650. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  651. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  652. I40E_GLVEBTC_RPCL(i, idx),
  653. veb->stat_offsets_loaded,
  654. &veb_oes->tc_rx_packets[i],
  655. &veb_es->tc_rx_packets[i]);
  656. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  657. I40E_GLVEBTC_RBCL(i, idx),
  658. veb->stat_offsets_loaded,
  659. &veb_oes->tc_rx_bytes[i],
  660. &veb_es->tc_rx_bytes[i]);
  661. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  662. I40E_GLVEBTC_TPCL(i, idx),
  663. veb->stat_offsets_loaded,
  664. &veb_oes->tc_tx_packets[i],
  665. &veb_es->tc_tx_packets[i]);
  666. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  667. I40E_GLVEBTC_TBCL(i, idx),
  668. veb->stat_offsets_loaded,
  669. &veb_oes->tc_tx_bytes[i],
  670. &veb_es->tc_tx_bytes[i]);
  671. }
  672. veb->stat_offsets_loaded = true;
  673. }
  674. #ifdef I40E_FCOE
  675. /**
  676. * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
  677. * @vsi: the VSI that is capable of doing FCoE
  678. **/
  679. static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
  680. {
  681. struct i40e_pf *pf = vsi->back;
  682. struct i40e_hw *hw = &pf->hw;
  683. struct i40e_fcoe_stats *ofs;
  684. struct i40e_fcoe_stats *fs; /* device's eth stats */
  685. int idx;
  686. if (vsi->type != I40E_VSI_FCOE)
  687. return;
  688. idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
  689. fs = &vsi->fcoe_stats;
  690. ofs = &vsi->fcoe_stats_offsets;
  691. i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
  692. vsi->fcoe_stat_offsets_loaded,
  693. &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
  694. i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
  695. vsi->fcoe_stat_offsets_loaded,
  696. &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
  697. i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
  698. vsi->fcoe_stat_offsets_loaded,
  699. &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
  700. i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
  701. vsi->fcoe_stat_offsets_loaded,
  702. &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
  703. i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
  704. vsi->fcoe_stat_offsets_loaded,
  705. &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
  706. i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
  707. vsi->fcoe_stat_offsets_loaded,
  708. &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
  709. i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
  710. vsi->fcoe_stat_offsets_loaded,
  711. &ofs->fcoe_last_error, &fs->fcoe_last_error);
  712. i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
  713. vsi->fcoe_stat_offsets_loaded,
  714. &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
  715. vsi->fcoe_stat_offsets_loaded = true;
  716. }
  717. #endif
  718. /**
  719. * i40e_update_vsi_stats - Update the vsi statistics counters.
  720. * @vsi: the VSI to be updated
  721. *
  722. * There are a few instances where we store the same stat in a
  723. * couple of different structs. This is partly because we have
  724. * the netdev stats that need to be filled out, which is slightly
  725. * different from the "eth_stats" defined by the chip and used in
  726. * VF communications. We sort it out here.
  727. **/
  728. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  729. {
  730. struct i40e_pf *pf = vsi->back;
  731. struct rtnl_link_stats64 *ons;
  732. struct rtnl_link_stats64 *ns; /* netdev stats */
  733. struct i40e_eth_stats *oes;
  734. struct i40e_eth_stats *es; /* device's eth stats */
  735. u32 tx_restart, tx_busy;
  736. u64 tx_lost_interrupt;
  737. struct i40e_ring *p;
  738. u32 rx_page, rx_buf;
  739. u64 bytes, packets;
  740. unsigned int start;
  741. u64 tx_linearize;
  742. u64 tx_force_wb;
  743. u64 rx_p, rx_b;
  744. u64 tx_p, tx_b;
  745. u16 q;
  746. if (test_bit(__I40E_DOWN, &vsi->state) ||
  747. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  748. return;
  749. ns = i40e_get_vsi_stats_struct(vsi);
  750. ons = &vsi->net_stats_offsets;
  751. es = &vsi->eth_stats;
  752. oes = &vsi->eth_stats_offsets;
  753. /* Gather up the netdev and vsi stats that the driver collects
  754. * on the fly during packet processing
  755. */
  756. rx_b = rx_p = 0;
  757. tx_b = tx_p = 0;
  758. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  759. tx_lost_interrupt = 0;
  760. rx_page = 0;
  761. rx_buf = 0;
  762. rcu_read_lock();
  763. for (q = 0; q < vsi->num_queue_pairs; q++) {
  764. /* locate Tx ring */
  765. p = ACCESS_ONCE(vsi->tx_rings[q]);
  766. do {
  767. start = u64_stats_fetch_begin_irq(&p->syncp);
  768. packets = p->stats.packets;
  769. bytes = p->stats.bytes;
  770. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  771. tx_b += bytes;
  772. tx_p += packets;
  773. tx_restart += p->tx_stats.restart_queue;
  774. tx_busy += p->tx_stats.tx_busy;
  775. tx_linearize += p->tx_stats.tx_linearize;
  776. tx_force_wb += p->tx_stats.tx_force_wb;
  777. tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
  778. /* Rx queue is part of the same block as Tx queue */
  779. p = &p[1];
  780. do {
  781. start = u64_stats_fetch_begin_irq(&p->syncp);
  782. packets = p->stats.packets;
  783. bytes = p->stats.bytes;
  784. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  785. rx_b += bytes;
  786. rx_p += packets;
  787. rx_buf += p->rx_stats.alloc_buff_failed;
  788. rx_page += p->rx_stats.alloc_page_failed;
  789. }
  790. rcu_read_unlock();
  791. vsi->tx_restart = tx_restart;
  792. vsi->tx_busy = tx_busy;
  793. vsi->tx_linearize = tx_linearize;
  794. vsi->tx_force_wb = tx_force_wb;
  795. vsi->tx_lost_interrupt = tx_lost_interrupt;
  796. vsi->rx_page_failed = rx_page;
  797. vsi->rx_buf_failed = rx_buf;
  798. ns->rx_packets = rx_p;
  799. ns->rx_bytes = rx_b;
  800. ns->tx_packets = tx_p;
  801. ns->tx_bytes = tx_b;
  802. /* update netdev stats from eth stats */
  803. i40e_update_eth_stats(vsi);
  804. ons->tx_errors = oes->tx_errors;
  805. ns->tx_errors = es->tx_errors;
  806. ons->multicast = oes->rx_multicast;
  807. ns->multicast = es->rx_multicast;
  808. ons->rx_dropped = oes->rx_discards;
  809. ns->rx_dropped = es->rx_discards;
  810. ons->tx_dropped = oes->tx_discards;
  811. ns->tx_dropped = es->tx_discards;
  812. /* pull in a couple PF stats if this is the main vsi */
  813. if (vsi == pf->vsi[pf->lan_vsi]) {
  814. ns->rx_crc_errors = pf->stats.crc_errors;
  815. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  816. ns->rx_length_errors = pf->stats.rx_length_errors;
  817. }
  818. }
  819. /**
  820. * i40e_update_pf_stats - Update the PF statistics counters.
  821. * @pf: the PF to be updated
  822. **/
  823. static void i40e_update_pf_stats(struct i40e_pf *pf)
  824. {
  825. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  826. struct i40e_hw_port_stats *nsd = &pf->stats;
  827. struct i40e_hw *hw = &pf->hw;
  828. u32 val;
  829. int i;
  830. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  831. I40E_GLPRT_GORCL(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  834. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  835. I40E_GLPRT_GOTCL(hw->port),
  836. pf->stat_offsets_loaded,
  837. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  838. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  839. pf->stat_offsets_loaded,
  840. &osd->eth.rx_discards,
  841. &nsd->eth.rx_discards);
  842. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  843. I40E_GLPRT_UPRCL(hw->port),
  844. pf->stat_offsets_loaded,
  845. &osd->eth.rx_unicast,
  846. &nsd->eth.rx_unicast);
  847. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  848. I40E_GLPRT_MPRCL(hw->port),
  849. pf->stat_offsets_loaded,
  850. &osd->eth.rx_multicast,
  851. &nsd->eth.rx_multicast);
  852. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  853. I40E_GLPRT_BPRCL(hw->port),
  854. pf->stat_offsets_loaded,
  855. &osd->eth.rx_broadcast,
  856. &nsd->eth.rx_broadcast);
  857. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  858. I40E_GLPRT_UPTCL(hw->port),
  859. pf->stat_offsets_loaded,
  860. &osd->eth.tx_unicast,
  861. &nsd->eth.tx_unicast);
  862. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  863. I40E_GLPRT_MPTCL(hw->port),
  864. pf->stat_offsets_loaded,
  865. &osd->eth.tx_multicast,
  866. &nsd->eth.tx_multicast);
  867. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  868. I40E_GLPRT_BPTCL(hw->port),
  869. pf->stat_offsets_loaded,
  870. &osd->eth.tx_broadcast,
  871. &nsd->eth.tx_broadcast);
  872. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  873. pf->stat_offsets_loaded,
  874. &osd->tx_dropped_link_down,
  875. &nsd->tx_dropped_link_down);
  876. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  877. pf->stat_offsets_loaded,
  878. &osd->crc_errors, &nsd->crc_errors);
  879. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  880. pf->stat_offsets_loaded,
  881. &osd->illegal_bytes, &nsd->illegal_bytes);
  882. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  883. pf->stat_offsets_loaded,
  884. &osd->mac_local_faults,
  885. &nsd->mac_local_faults);
  886. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  887. pf->stat_offsets_loaded,
  888. &osd->mac_remote_faults,
  889. &nsd->mac_remote_faults);
  890. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  891. pf->stat_offsets_loaded,
  892. &osd->rx_length_errors,
  893. &nsd->rx_length_errors);
  894. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  895. pf->stat_offsets_loaded,
  896. &osd->link_xon_rx, &nsd->link_xon_rx);
  897. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  898. pf->stat_offsets_loaded,
  899. &osd->link_xon_tx, &nsd->link_xon_tx);
  900. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  901. pf->stat_offsets_loaded,
  902. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  903. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  904. pf->stat_offsets_loaded,
  905. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  906. for (i = 0; i < 8; i++) {
  907. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  908. pf->stat_offsets_loaded,
  909. &osd->priority_xoff_rx[i],
  910. &nsd->priority_xoff_rx[i]);
  911. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  912. pf->stat_offsets_loaded,
  913. &osd->priority_xon_rx[i],
  914. &nsd->priority_xon_rx[i]);
  915. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  916. pf->stat_offsets_loaded,
  917. &osd->priority_xon_tx[i],
  918. &nsd->priority_xon_tx[i]);
  919. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  920. pf->stat_offsets_loaded,
  921. &osd->priority_xoff_tx[i],
  922. &nsd->priority_xoff_tx[i]);
  923. i40e_stat_update32(hw,
  924. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  925. pf->stat_offsets_loaded,
  926. &osd->priority_xon_2_xoff[i],
  927. &nsd->priority_xon_2_xoff[i]);
  928. }
  929. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  930. I40E_GLPRT_PRC64L(hw->port),
  931. pf->stat_offsets_loaded,
  932. &osd->rx_size_64, &nsd->rx_size_64);
  933. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  934. I40E_GLPRT_PRC127L(hw->port),
  935. pf->stat_offsets_loaded,
  936. &osd->rx_size_127, &nsd->rx_size_127);
  937. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  938. I40E_GLPRT_PRC255L(hw->port),
  939. pf->stat_offsets_loaded,
  940. &osd->rx_size_255, &nsd->rx_size_255);
  941. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  942. I40E_GLPRT_PRC511L(hw->port),
  943. pf->stat_offsets_loaded,
  944. &osd->rx_size_511, &nsd->rx_size_511);
  945. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  946. I40E_GLPRT_PRC1023L(hw->port),
  947. pf->stat_offsets_loaded,
  948. &osd->rx_size_1023, &nsd->rx_size_1023);
  949. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  950. I40E_GLPRT_PRC1522L(hw->port),
  951. pf->stat_offsets_loaded,
  952. &osd->rx_size_1522, &nsd->rx_size_1522);
  953. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  954. I40E_GLPRT_PRC9522L(hw->port),
  955. pf->stat_offsets_loaded,
  956. &osd->rx_size_big, &nsd->rx_size_big);
  957. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  958. I40E_GLPRT_PTC64L(hw->port),
  959. pf->stat_offsets_loaded,
  960. &osd->tx_size_64, &nsd->tx_size_64);
  961. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  962. I40E_GLPRT_PTC127L(hw->port),
  963. pf->stat_offsets_loaded,
  964. &osd->tx_size_127, &nsd->tx_size_127);
  965. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  966. I40E_GLPRT_PTC255L(hw->port),
  967. pf->stat_offsets_loaded,
  968. &osd->tx_size_255, &nsd->tx_size_255);
  969. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  970. I40E_GLPRT_PTC511L(hw->port),
  971. pf->stat_offsets_loaded,
  972. &osd->tx_size_511, &nsd->tx_size_511);
  973. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  974. I40E_GLPRT_PTC1023L(hw->port),
  975. pf->stat_offsets_loaded,
  976. &osd->tx_size_1023, &nsd->tx_size_1023);
  977. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  978. I40E_GLPRT_PTC1522L(hw->port),
  979. pf->stat_offsets_loaded,
  980. &osd->tx_size_1522, &nsd->tx_size_1522);
  981. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  982. I40E_GLPRT_PTC9522L(hw->port),
  983. pf->stat_offsets_loaded,
  984. &osd->tx_size_big, &nsd->tx_size_big);
  985. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  986. pf->stat_offsets_loaded,
  987. &osd->rx_undersize, &nsd->rx_undersize);
  988. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  989. pf->stat_offsets_loaded,
  990. &osd->rx_fragments, &nsd->rx_fragments);
  991. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  992. pf->stat_offsets_loaded,
  993. &osd->rx_oversize, &nsd->rx_oversize);
  994. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  995. pf->stat_offsets_loaded,
  996. &osd->rx_jabber, &nsd->rx_jabber);
  997. /* FDIR stats */
  998. i40e_stat_update32(hw,
  999. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
  1000. pf->stat_offsets_loaded,
  1001. &osd->fd_atr_match, &nsd->fd_atr_match);
  1002. i40e_stat_update32(hw,
  1003. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
  1004. pf->stat_offsets_loaded,
  1005. &osd->fd_sb_match, &nsd->fd_sb_match);
  1006. i40e_stat_update32(hw,
  1007. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
  1008. pf->stat_offsets_loaded,
  1009. &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
  1010. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  1011. nsd->tx_lpi_status =
  1012. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  1013. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  1014. nsd->rx_lpi_status =
  1015. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  1016. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  1017. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  1018. pf->stat_offsets_loaded,
  1019. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  1020. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  1021. pf->stat_offsets_loaded,
  1022. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  1023. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  1024. !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
  1025. nsd->fd_sb_status = true;
  1026. else
  1027. nsd->fd_sb_status = false;
  1028. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  1029. !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
  1030. nsd->fd_atr_status = true;
  1031. else
  1032. nsd->fd_atr_status = false;
  1033. pf->stat_offsets_loaded = true;
  1034. }
  1035. /**
  1036. * i40e_update_stats - Update the various statistics counters.
  1037. * @vsi: the VSI to be updated
  1038. *
  1039. * Update the various stats for this VSI and its related entities.
  1040. **/
  1041. void i40e_update_stats(struct i40e_vsi *vsi)
  1042. {
  1043. struct i40e_pf *pf = vsi->back;
  1044. if (vsi == pf->vsi[pf->lan_vsi])
  1045. i40e_update_pf_stats(pf);
  1046. i40e_update_vsi_stats(vsi);
  1047. #ifdef I40E_FCOE
  1048. i40e_update_fcoe_stats(vsi);
  1049. #endif
  1050. }
  1051. /**
  1052. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1053. * @vsi: the VSI to be searched
  1054. * @macaddr: the MAC address
  1055. * @vlan: the vlan
  1056. * @is_vf: make sure its a VF filter, else doesn't matter
  1057. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1058. *
  1059. * Returns ptr to the filter object or NULL
  1060. **/
  1061. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1062. u8 *macaddr, s16 vlan,
  1063. bool is_vf, bool is_netdev)
  1064. {
  1065. struct i40e_mac_filter *f;
  1066. if (!vsi || !macaddr)
  1067. return NULL;
  1068. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1069. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1070. (vlan == f->vlan) &&
  1071. (!is_vf || f->is_vf) &&
  1072. (!is_netdev || f->is_netdev))
  1073. return f;
  1074. }
  1075. return NULL;
  1076. }
  1077. /**
  1078. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1079. * @vsi: the VSI to be searched
  1080. * @macaddr: the MAC address we are searching for
  1081. * @is_vf: make sure its a VF filter, else doesn't matter
  1082. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1083. *
  1084. * Returns the first filter with the provided MAC address or NULL if
  1085. * MAC address was not found
  1086. **/
  1087. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
  1088. bool is_vf, bool is_netdev)
  1089. {
  1090. struct i40e_mac_filter *f;
  1091. if (!vsi || !macaddr)
  1092. return NULL;
  1093. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1094. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1095. (!is_vf || f->is_vf) &&
  1096. (!is_netdev || f->is_netdev))
  1097. return f;
  1098. }
  1099. return NULL;
  1100. }
  1101. /**
  1102. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1103. * @vsi: the VSI to be searched
  1104. *
  1105. * Returns true if VSI is in vlan mode or false otherwise
  1106. **/
  1107. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1108. {
  1109. struct i40e_mac_filter *f;
  1110. /* Only -1 for all the filters denotes not in vlan mode
  1111. * so we have to go through all the list in order to make sure
  1112. */
  1113. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1114. if (f->vlan >= 0 || vsi->info.pvid)
  1115. return true;
  1116. }
  1117. return false;
  1118. }
  1119. /**
  1120. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  1121. * @vsi: the VSI to be searched
  1122. * @macaddr: the mac address to be filtered
  1123. * @is_vf: true if it is a VF
  1124. * @is_netdev: true if it is a netdev
  1125. *
  1126. * Goes through all the macvlan filters and adds a
  1127. * macvlan filter for each unique vlan that already exists
  1128. *
  1129. * Returns first filter found on success, else NULL
  1130. **/
  1131. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  1132. bool is_vf, bool is_netdev)
  1133. {
  1134. struct i40e_mac_filter *f;
  1135. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1136. if (vsi->info.pvid)
  1137. f->vlan = le16_to_cpu(vsi->info.pvid);
  1138. if (!i40e_find_filter(vsi, macaddr, f->vlan,
  1139. is_vf, is_netdev)) {
  1140. if (!i40e_add_filter(vsi, macaddr, f->vlan,
  1141. is_vf, is_netdev))
  1142. return NULL;
  1143. }
  1144. }
  1145. return list_first_entry_or_null(&vsi->mac_filter_list,
  1146. struct i40e_mac_filter, list);
  1147. }
  1148. /**
  1149. * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
  1150. * @vsi: the VSI to be searched
  1151. * @macaddr: the mac address to be removed
  1152. * @is_vf: true if it is a VF
  1153. * @is_netdev: true if it is a netdev
  1154. *
  1155. * Removes a given MAC address from a VSI, regardless of VLAN
  1156. *
  1157. * Returns 0 for success, or error
  1158. **/
  1159. int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  1160. bool is_vf, bool is_netdev)
  1161. {
  1162. struct i40e_mac_filter *f = NULL;
  1163. int changed = 0;
  1164. WARN(!spin_is_locked(&vsi->mac_filter_list_lock),
  1165. "Missing mac_filter_list_lock\n");
  1166. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1167. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1168. (is_vf == f->is_vf) &&
  1169. (is_netdev == f->is_netdev)) {
  1170. f->counter--;
  1171. f->changed = true;
  1172. changed = 1;
  1173. }
  1174. }
  1175. if (changed) {
  1176. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1177. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1178. return 0;
  1179. }
  1180. return -ENOENT;
  1181. }
  1182. /**
  1183. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1184. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1185. * @macaddr: the MAC address
  1186. *
  1187. * Some older firmware configurations set up a default promiscuous VLAN
  1188. * filter that needs to be removed.
  1189. **/
  1190. static int i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1191. {
  1192. struct i40e_aqc_remove_macvlan_element_data element;
  1193. struct i40e_pf *pf = vsi->back;
  1194. i40e_status ret;
  1195. /* Only appropriate for the PF main VSI */
  1196. if (vsi->type != I40E_VSI_MAIN)
  1197. return -EINVAL;
  1198. memset(&element, 0, sizeof(element));
  1199. ether_addr_copy(element.mac_addr, macaddr);
  1200. element.vlan_tag = 0;
  1201. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1202. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1203. ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1204. if (ret)
  1205. return -ENOENT;
  1206. return 0;
  1207. }
  1208. /**
  1209. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1210. * @vsi: the VSI to be searched
  1211. * @macaddr: the MAC address
  1212. * @vlan: the vlan
  1213. * @is_vf: make sure its a VF filter, else doesn't matter
  1214. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1215. *
  1216. * Returns ptr to the filter object or NULL when no memory available.
  1217. *
  1218. * NOTE: This function is expected to be called with mac_filter_list_lock
  1219. * being held.
  1220. **/
  1221. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1222. u8 *macaddr, s16 vlan,
  1223. bool is_vf, bool is_netdev)
  1224. {
  1225. struct i40e_mac_filter *f;
  1226. if (!vsi || !macaddr)
  1227. return NULL;
  1228. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1229. if (!f) {
  1230. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1231. if (!f)
  1232. goto add_filter_out;
  1233. ether_addr_copy(f->macaddr, macaddr);
  1234. f->vlan = vlan;
  1235. f->changed = true;
  1236. INIT_LIST_HEAD(&f->list);
  1237. list_add_tail(&f->list, &vsi->mac_filter_list);
  1238. }
  1239. /* increment counter and add a new flag if needed */
  1240. if (is_vf) {
  1241. if (!f->is_vf) {
  1242. f->is_vf = true;
  1243. f->counter++;
  1244. }
  1245. } else if (is_netdev) {
  1246. if (!f->is_netdev) {
  1247. f->is_netdev = true;
  1248. f->counter++;
  1249. }
  1250. } else {
  1251. f->counter++;
  1252. }
  1253. /* changed tells sync_filters_subtask to
  1254. * push the filter down to the firmware
  1255. */
  1256. if (f->changed) {
  1257. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1258. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1259. }
  1260. add_filter_out:
  1261. return f;
  1262. }
  1263. /**
  1264. * i40e_del_filter - Remove a mac/vlan filter from the VSI
  1265. * @vsi: the VSI to be searched
  1266. * @macaddr: the MAC address
  1267. * @vlan: the vlan
  1268. * @is_vf: make sure it's a VF filter, else doesn't matter
  1269. * @is_netdev: make sure it's a netdev filter, else doesn't matter
  1270. *
  1271. * NOTE: This function is expected to be called with mac_filter_list_lock
  1272. * being held.
  1273. **/
  1274. void i40e_del_filter(struct i40e_vsi *vsi,
  1275. u8 *macaddr, s16 vlan,
  1276. bool is_vf, bool is_netdev)
  1277. {
  1278. struct i40e_mac_filter *f;
  1279. if (!vsi || !macaddr)
  1280. return;
  1281. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1282. if (!f || f->counter == 0)
  1283. return;
  1284. if (is_vf) {
  1285. if (f->is_vf) {
  1286. f->is_vf = false;
  1287. f->counter--;
  1288. }
  1289. } else if (is_netdev) {
  1290. if (f->is_netdev) {
  1291. f->is_netdev = false;
  1292. f->counter--;
  1293. }
  1294. } else {
  1295. /* make sure we don't remove a filter in use by VF or netdev */
  1296. int min_f = 0;
  1297. min_f += (f->is_vf ? 1 : 0);
  1298. min_f += (f->is_netdev ? 1 : 0);
  1299. if (f->counter > min_f)
  1300. f->counter--;
  1301. }
  1302. /* counter == 0 tells sync_filters_subtask to
  1303. * remove the filter from the firmware's list
  1304. */
  1305. if (f->counter == 0) {
  1306. f->changed = true;
  1307. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1308. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1309. }
  1310. }
  1311. /**
  1312. * i40e_set_mac - NDO callback to set mac address
  1313. * @netdev: network interface device structure
  1314. * @p: pointer to an address structure
  1315. *
  1316. * Returns 0 on success, negative on failure
  1317. **/
  1318. #ifdef I40E_FCOE
  1319. int i40e_set_mac(struct net_device *netdev, void *p)
  1320. #else
  1321. static int i40e_set_mac(struct net_device *netdev, void *p)
  1322. #endif
  1323. {
  1324. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1325. struct i40e_vsi *vsi = np->vsi;
  1326. struct i40e_pf *pf = vsi->back;
  1327. struct i40e_hw *hw = &pf->hw;
  1328. struct sockaddr *addr = p;
  1329. struct i40e_mac_filter *f;
  1330. if (!is_valid_ether_addr(addr->sa_data))
  1331. return -EADDRNOTAVAIL;
  1332. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1333. netdev_info(netdev, "already using mac address %pM\n",
  1334. addr->sa_data);
  1335. return 0;
  1336. }
  1337. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1338. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1339. return -EADDRNOTAVAIL;
  1340. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1341. netdev_info(netdev, "returning to hw mac address %pM\n",
  1342. hw->mac.addr);
  1343. else
  1344. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1345. if (vsi->type == I40E_VSI_MAIN) {
  1346. i40e_status ret;
  1347. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1348. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1349. addr->sa_data, NULL);
  1350. if (ret) {
  1351. netdev_info(netdev,
  1352. "Addr change for Main VSI failed: %d\n",
  1353. ret);
  1354. return -EADDRNOTAVAIL;
  1355. }
  1356. }
  1357. if (ether_addr_equal(netdev->dev_addr, hw->mac.addr)) {
  1358. struct i40e_aqc_remove_macvlan_element_data element;
  1359. memset(&element, 0, sizeof(element));
  1360. ether_addr_copy(element.mac_addr, netdev->dev_addr);
  1361. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1362. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1363. } else {
  1364. spin_lock_bh(&vsi->mac_filter_list_lock);
  1365. i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  1366. false, false);
  1367. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1368. }
  1369. if (ether_addr_equal(addr->sa_data, hw->mac.addr)) {
  1370. struct i40e_aqc_add_macvlan_element_data element;
  1371. memset(&element, 0, sizeof(element));
  1372. ether_addr_copy(element.mac_addr, hw->mac.addr);
  1373. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  1374. i40e_aq_add_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1375. } else {
  1376. spin_lock_bh(&vsi->mac_filter_list_lock);
  1377. f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY,
  1378. false, false);
  1379. if (f)
  1380. f->is_laa = true;
  1381. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1382. }
  1383. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1384. /* schedule our worker thread which will take care of
  1385. * applying the new filter changes
  1386. */
  1387. i40e_service_event_schedule(vsi->back);
  1388. return 0;
  1389. }
  1390. /**
  1391. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1392. * @vsi: the VSI being setup
  1393. * @ctxt: VSI context structure
  1394. * @enabled_tc: Enabled TCs bitmap
  1395. * @is_add: True if called before Add VSI
  1396. *
  1397. * Setup VSI queue mapping for enabled traffic classes.
  1398. **/
  1399. #ifdef I40E_FCOE
  1400. void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1401. struct i40e_vsi_context *ctxt,
  1402. u8 enabled_tc,
  1403. bool is_add)
  1404. #else
  1405. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1406. struct i40e_vsi_context *ctxt,
  1407. u8 enabled_tc,
  1408. bool is_add)
  1409. #endif
  1410. {
  1411. struct i40e_pf *pf = vsi->back;
  1412. u16 sections = 0;
  1413. u8 netdev_tc = 0;
  1414. u16 numtc = 0;
  1415. u16 qcount;
  1416. u8 offset;
  1417. u16 qmap;
  1418. int i;
  1419. u16 num_tc_qps = 0;
  1420. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1421. offset = 0;
  1422. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1423. /* Find numtc from enabled TC bitmap */
  1424. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1425. if (enabled_tc & BIT(i)) /* TC is enabled */
  1426. numtc++;
  1427. }
  1428. if (!numtc) {
  1429. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1430. numtc = 1;
  1431. }
  1432. } else {
  1433. /* At least TC0 is enabled in case of non-DCB case */
  1434. numtc = 1;
  1435. }
  1436. vsi->tc_config.numtc = numtc;
  1437. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1438. /* Number of queues per enabled TC */
  1439. /* In MFP case we can have a much lower count of MSIx
  1440. * vectors available and so we need to lower the used
  1441. * q count.
  1442. */
  1443. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1444. qcount = min_t(int, vsi->alloc_queue_pairs, pf->num_lan_msix);
  1445. else
  1446. qcount = vsi->alloc_queue_pairs;
  1447. num_tc_qps = qcount / numtc;
  1448. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1449. /* Setup queue offset/count for all TCs for given VSI */
  1450. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1451. /* See if the given TC is enabled for the given VSI */
  1452. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1453. /* TC is enabled */
  1454. int pow, num_qps;
  1455. switch (vsi->type) {
  1456. case I40E_VSI_MAIN:
  1457. qcount = min_t(int, pf->alloc_rss_size,
  1458. num_tc_qps);
  1459. break;
  1460. #ifdef I40E_FCOE
  1461. case I40E_VSI_FCOE:
  1462. qcount = num_tc_qps;
  1463. break;
  1464. #endif
  1465. case I40E_VSI_FDIR:
  1466. case I40E_VSI_SRIOV:
  1467. case I40E_VSI_VMDQ2:
  1468. default:
  1469. qcount = num_tc_qps;
  1470. WARN_ON(i != 0);
  1471. break;
  1472. }
  1473. vsi->tc_config.tc_info[i].qoffset = offset;
  1474. vsi->tc_config.tc_info[i].qcount = qcount;
  1475. /* find the next higher power-of-2 of num queue pairs */
  1476. num_qps = qcount;
  1477. pow = 0;
  1478. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1479. pow++;
  1480. num_qps >>= 1;
  1481. }
  1482. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1483. qmap =
  1484. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1485. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1486. offset += qcount;
  1487. } else {
  1488. /* TC is not enabled so set the offset to
  1489. * default queue and allocate one queue
  1490. * for the given TC.
  1491. */
  1492. vsi->tc_config.tc_info[i].qoffset = 0;
  1493. vsi->tc_config.tc_info[i].qcount = 1;
  1494. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1495. qmap = 0;
  1496. }
  1497. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1498. }
  1499. /* Set actual Tx/Rx queue pairs */
  1500. vsi->num_queue_pairs = offset;
  1501. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1502. if (vsi->req_queue_pairs > 0)
  1503. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1504. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1505. vsi->num_queue_pairs = pf->num_lan_msix;
  1506. }
  1507. /* Scheduler section valid can only be set for ADD VSI */
  1508. if (is_add) {
  1509. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1510. ctxt->info.up_enable_bits = enabled_tc;
  1511. }
  1512. if (vsi->type == I40E_VSI_SRIOV) {
  1513. ctxt->info.mapping_flags |=
  1514. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1515. for (i = 0; i < vsi->num_queue_pairs; i++)
  1516. ctxt->info.queue_mapping[i] =
  1517. cpu_to_le16(vsi->base_queue + i);
  1518. } else {
  1519. ctxt->info.mapping_flags |=
  1520. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1521. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1522. }
  1523. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1524. }
  1525. /**
  1526. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1527. * @netdev: network interface device structure
  1528. **/
  1529. #ifdef I40E_FCOE
  1530. void i40e_set_rx_mode(struct net_device *netdev)
  1531. #else
  1532. static void i40e_set_rx_mode(struct net_device *netdev)
  1533. #endif
  1534. {
  1535. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1536. struct i40e_mac_filter *f, *ftmp;
  1537. struct i40e_vsi *vsi = np->vsi;
  1538. struct netdev_hw_addr *uca;
  1539. struct netdev_hw_addr *mca;
  1540. struct netdev_hw_addr *ha;
  1541. spin_lock_bh(&vsi->mac_filter_list_lock);
  1542. /* add addr if not already in the filter list */
  1543. netdev_for_each_uc_addr(uca, netdev) {
  1544. if (!i40e_find_mac(vsi, uca->addr, false, true)) {
  1545. if (i40e_is_vsi_in_vlan(vsi))
  1546. i40e_put_mac_in_vlan(vsi, uca->addr,
  1547. false, true);
  1548. else
  1549. i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
  1550. false, true);
  1551. }
  1552. }
  1553. netdev_for_each_mc_addr(mca, netdev) {
  1554. if (!i40e_find_mac(vsi, mca->addr, false, true)) {
  1555. if (i40e_is_vsi_in_vlan(vsi))
  1556. i40e_put_mac_in_vlan(vsi, mca->addr,
  1557. false, true);
  1558. else
  1559. i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
  1560. false, true);
  1561. }
  1562. }
  1563. /* remove filter if not in netdev list */
  1564. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1565. if (!f->is_netdev)
  1566. continue;
  1567. netdev_for_each_mc_addr(mca, netdev)
  1568. if (ether_addr_equal(mca->addr, f->macaddr))
  1569. goto bottom_of_search_loop;
  1570. netdev_for_each_uc_addr(uca, netdev)
  1571. if (ether_addr_equal(uca->addr, f->macaddr))
  1572. goto bottom_of_search_loop;
  1573. for_each_dev_addr(netdev, ha)
  1574. if (ether_addr_equal(ha->addr, f->macaddr))
  1575. goto bottom_of_search_loop;
  1576. /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
  1577. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
  1578. bottom_of_search_loop:
  1579. continue;
  1580. }
  1581. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1582. /* check for other flag changes */
  1583. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1584. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1585. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1586. }
  1587. /* schedule our worker thread which will take care of
  1588. * applying the new filter changes
  1589. */
  1590. i40e_service_event_schedule(vsi->back);
  1591. }
  1592. /**
  1593. * i40e_mac_filter_entry_clone - Clones a MAC filter entry
  1594. * @src: source MAC filter entry to be clones
  1595. *
  1596. * Returns the pointer to newly cloned MAC filter entry or NULL
  1597. * in case of error
  1598. **/
  1599. static struct i40e_mac_filter *i40e_mac_filter_entry_clone(
  1600. struct i40e_mac_filter *src)
  1601. {
  1602. struct i40e_mac_filter *f;
  1603. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1604. if (!f)
  1605. return NULL;
  1606. *f = *src;
  1607. INIT_LIST_HEAD(&f->list);
  1608. return f;
  1609. }
  1610. /**
  1611. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1612. * @vsi: pointer to vsi struct
  1613. * @from: Pointer to list which contains MAC filter entries - changes to
  1614. * those entries needs to be undone.
  1615. *
  1616. * MAC filter entries from list were slated to be removed from device.
  1617. **/
  1618. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1619. struct list_head *from)
  1620. {
  1621. struct i40e_mac_filter *f, *ftmp;
  1622. list_for_each_entry_safe(f, ftmp, from, list) {
  1623. f->changed = true;
  1624. /* Move the element back into MAC filter list*/
  1625. list_move_tail(&f->list, &vsi->mac_filter_list);
  1626. }
  1627. }
  1628. /**
  1629. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1630. * @vsi: pointer to vsi struct
  1631. *
  1632. * MAC filter entries from list were slated to be added from device.
  1633. **/
  1634. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi)
  1635. {
  1636. struct i40e_mac_filter *f, *ftmp;
  1637. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1638. if (!f->changed && f->counter)
  1639. f->changed = true;
  1640. }
  1641. }
  1642. /**
  1643. * i40e_cleanup_add_list - Deletes the element from add list and release
  1644. * memory
  1645. * @add_list: Pointer to list which contains MAC filter entries
  1646. **/
  1647. static void i40e_cleanup_add_list(struct list_head *add_list)
  1648. {
  1649. struct i40e_mac_filter *f, *ftmp;
  1650. list_for_each_entry_safe(f, ftmp, add_list, list) {
  1651. list_del(&f->list);
  1652. kfree(f);
  1653. }
  1654. }
  1655. /**
  1656. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1657. * @vsi: ptr to the VSI
  1658. *
  1659. * Push any outstanding VSI filter changes through the AdminQ.
  1660. *
  1661. * Returns 0 or error value
  1662. **/
  1663. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1664. {
  1665. struct list_head tmp_del_list, tmp_add_list;
  1666. struct i40e_mac_filter *f, *ftmp, *fclone;
  1667. bool promisc_forced_on = false;
  1668. bool add_happened = false;
  1669. int filter_list_len = 0;
  1670. u32 changed_flags = 0;
  1671. i40e_status aq_ret = 0;
  1672. bool err_cond = false;
  1673. int retval = 0;
  1674. struct i40e_pf *pf;
  1675. int num_add = 0;
  1676. int num_del = 0;
  1677. int aq_err = 0;
  1678. u16 cmd_flags;
  1679. /* empty array typed pointers, kcalloc later */
  1680. struct i40e_aqc_add_macvlan_element_data *add_list;
  1681. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1682. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1683. usleep_range(1000, 2000);
  1684. pf = vsi->back;
  1685. if (vsi->netdev) {
  1686. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1687. vsi->current_netdev_flags = vsi->netdev->flags;
  1688. }
  1689. INIT_LIST_HEAD(&tmp_del_list);
  1690. INIT_LIST_HEAD(&tmp_add_list);
  1691. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1692. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1693. spin_lock_bh(&vsi->mac_filter_list_lock);
  1694. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1695. if (!f->changed)
  1696. continue;
  1697. if (f->counter != 0)
  1698. continue;
  1699. f->changed = false;
  1700. /* Move the element into temporary del_list */
  1701. list_move_tail(&f->list, &tmp_del_list);
  1702. }
  1703. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1704. if (!f->changed)
  1705. continue;
  1706. if (f->counter == 0)
  1707. continue;
  1708. f->changed = false;
  1709. /* Clone MAC filter entry and add into temporary list */
  1710. fclone = i40e_mac_filter_entry_clone(f);
  1711. if (!fclone) {
  1712. err_cond = true;
  1713. break;
  1714. }
  1715. list_add_tail(&fclone->list, &tmp_add_list);
  1716. }
  1717. /* if failed to clone MAC filter entry - undo */
  1718. if (err_cond) {
  1719. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  1720. i40e_undo_add_filter_entries(vsi);
  1721. }
  1722. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1723. if (err_cond) {
  1724. i40e_cleanup_add_list(&tmp_add_list);
  1725. retval = -ENOMEM;
  1726. goto out;
  1727. }
  1728. }
  1729. /* Now process 'del_list' outside the lock */
  1730. if (!list_empty(&tmp_del_list)) {
  1731. int del_list_size;
  1732. filter_list_len = pf->hw.aq.asq_buf_size /
  1733. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1734. del_list_size = filter_list_len *
  1735. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1736. del_list = kzalloc(del_list_size, GFP_ATOMIC);
  1737. if (!del_list) {
  1738. i40e_cleanup_add_list(&tmp_add_list);
  1739. /* Undo VSI's MAC filter entry element updates */
  1740. spin_lock_bh(&vsi->mac_filter_list_lock);
  1741. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  1742. i40e_undo_add_filter_entries(vsi);
  1743. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1744. retval = -ENOMEM;
  1745. goto out;
  1746. }
  1747. list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
  1748. cmd_flags = 0;
  1749. /* add to delete list */
  1750. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1751. del_list[num_del].vlan_tag =
  1752. cpu_to_le16((u16)(f->vlan ==
  1753. I40E_VLAN_ANY ? 0 : f->vlan));
  1754. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1755. del_list[num_del].flags = cmd_flags;
  1756. num_del++;
  1757. /* flush a full buffer */
  1758. if (num_del == filter_list_len) {
  1759. aq_ret = i40e_aq_remove_macvlan(&pf->hw,
  1760. vsi->seid,
  1761. del_list,
  1762. num_del,
  1763. NULL);
  1764. aq_err = pf->hw.aq.asq_last_status;
  1765. num_del = 0;
  1766. memset(del_list, 0, del_list_size);
  1767. if (aq_ret && aq_err != I40E_AQ_RC_ENOENT) {
  1768. retval = -EIO;
  1769. dev_err(&pf->pdev->dev,
  1770. "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
  1771. i40e_stat_str(&pf->hw, aq_ret),
  1772. i40e_aq_str(&pf->hw, aq_err));
  1773. }
  1774. }
  1775. /* Release memory for MAC filter entries which were
  1776. * synced up with HW.
  1777. */
  1778. list_del(&f->list);
  1779. kfree(f);
  1780. }
  1781. if (num_del) {
  1782. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
  1783. del_list, num_del,
  1784. NULL);
  1785. aq_err = pf->hw.aq.asq_last_status;
  1786. num_del = 0;
  1787. if (aq_ret && aq_err != I40E_AQ_RC_ENOENT)
  1788. dev_info(&pf->pdev->dev,
  1789. "ignoring delete macvlan error, err %s aq_err %s\n",
  1790. i40e_stat_str(&pf->hw, aq_ret),
  1791. i40e_aq_str(&pf->hw, aq_err));
  1792. }
  1793. kfree(del_list);
  1794. del_list = NULL;
  1795. }
  1796. if (!list_empty(&tmp_add_list)) {
  1797. int add_list_size;
  1798. /* do all the adds now */
  1799. filter_list_len = pf->hw.aq.asq_buf_size /
  1800. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1801. add_list_size = filter_list_len *
  1802. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1803. add_list = kzalloc(add_list_size, GFP_ATOMIC);
  1804. if (!add_list) {
  1805. /* Purge element from temporary lists */
  1806. i40e_cleanup_add_list(&tmp_add_list);
  1807. /* Undo add filter entries from VSI MAC filter list */
  1808. spin_lock_bh(&vsi->mac_filter_list_lock);
  1809. i40e_undo_add_filter_entries(vsi);
  1810. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1811. retval = -ENOMEM;
  1812. goto out;
  1813. }
  1814. list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
  1815. add_happened = true;
  1816. cmd_flags = 0;
  1817. /* add to add array */
  1818. ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
  1819. add_list[num_add].vlan_tag =
  1820. cpu_to_le16(
  1821. (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
  1822. add_list[num_add].queue_number = 0;
  1823. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1824. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1825. num_add++;
  1826. /* flush a full buffer */
  1827. if (num_add == filter_list_len) {
  1828. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1829. add_list, num_add,
  1830. NULL);
  1831. aq_err = pf->hw.aq.asq_last_status;
  1832. num_add = 0;
  1833. if (aq_ret)
  1834. break;
  1835. memset(add_list, 0, add_list_size);
  1836. }
  1837. /* Entries from tmp_add_list were cloned from MAC
  1838. * filter list, hence clean those cloned entries
  1839. */
  1840. list_del(&f->list);
  1841. kfree(f);
  1842. }
  1843. if (num_add) {
  1844. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1845. add_list, num_add, NULL);
  1846. aq_err = pf->hw.aq.asq_last_status;
  1847. num_add = 0;
  1848. }
  1849. kfree(add_list);
  1850. add_list = NULL;
  1851. if (add_happened && aq_ret && aq_err != I40E_AQ_RC_EINVAL) {
  1852. retval = i40e_aq_rc_to_posix(aq_ret, aq_err);
  1853. dev_info(&pf->pdev->dev,
  1854. "add filter failed, err %s aq_err %s\n",
  1855. i40e_stat_str(&pf->hw, aq_ret),
  1856. i40e_aq_str(&pf->hw, aq_err));
  1857. if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
  1858. !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1859. &vsi->state)) {
  1860. promisc_forced_on = true;
  1861. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1862. &vsi->state);
  1863. dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
  1864. }
  1865. }
  1866. }
  1867. /* check for changes in promiscuous modes */
  1868. if (changed_flags & IFF_ALLMULTI) {
  1869. bool cur_multipromisc;
  1870. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  1871. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  1872. vsi->seid,
  1873. cur_multipromisc,
  1874. NULL);
  1875. if (aq_ret) {
  1876. retval = i40e_aq_rc_to_posix(aq_ret,
  1877. pf->hw.aq.asq_last_status);
  1878. dev_info(&pf->pdev->dev,
  1879. "set multi promisc failed, err %s aq_err %s\n",
  1880. i40e_stat_str(&pf->hw, aq_ret),
  1881. i40e_aq_str(&pf->hw,
  1882. pf->hw.aq.asq_last_status));
  1883. }
  1884. }
  1885. if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
  1886. bool cur_promisc;
  1887. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  1888. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1889. &vsi->state));
  1890. if ((vsi->type == I40E_VSI_MAIN) &&
  1891. (pf->lan_veb != I40E_NO_VEB) &&
  1892. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1893. /* set defport ON for Main VSI instead of true promisc
  1894. * this way we will get all unicast/multicast and VLAN
  1895. * promisc behavior but will not get VF or VMDq traffic
  1896. * replicated on the Main VSI.
  1897. */
  1898. if (pf->cur_promisc != cur_promisc) {
  1899. pf->cur_promisc = cur_promisc;
  1900. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  1901. }
  1902. } else {
  1903. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1904. &vsi->back->hw,
  1905. vsi->seid,
  1906. cur_promisc, NULL);
  1907. if (aq_ret) {
  1908. retval =
  1909. i40e_aq_rc_to_posix(aq_ret,
  1910. pf->hw.aq.asq_last_status);
  1911. dev_info(&pf->pdev->dev,
  1912. "set unicast promisc failed, err %d, aq_err %d\n",
  1913. aq_ret, pf->hw.aq.asq_last_status);
  1914. }
  1915. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  1916. &vsi->back->hw,
  1917. vsi->seid,
  1918. cur_promisc, NULL);
  1919. if (aq_ret) {
  1920. retval =
  1921. i40e_aq_rc_to_posix(aq_ret,
  1922. pf->hw.aq.asq_last_status);
  1923. dev_info(&pf->pdev->dev,
  1924. "set multicast promisc failed, err %d, aq_err %d\n",
  1925. aq_ret, pf->hw.aq.asq_last_status);
  1926. }
  1927. }
  1928. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  1929. vsi->seid,
  1930. cur_promisc, NULL);
  1931. if (aq_ret) {
  1932. retval = i40e_aq_rc_to_posix(aq_ret,
  1933. pf->hw.aq.asq_last_status);
  1934. dev_info(&pf->pdev->dev,
  1935. "set brdcast promisc failed, err %s, aq_err %s\n",
  1936. i40e_stat_str(&pf->hw, aq_ret),
  1937. i40e_aq_str(&pf->hw,
  1938. pf->hw.aq.asq_last_status));
  1939. }
  1940. }
  1941. out:
  1942. /* if something went wrong then set the changed flag so we try again */
  1943. if (retval)
  1944. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1945. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  1946. return retval;
  1947. }
  1948. /**
  1949. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  1950. * @pf: board private structure
  1951. **/
  1952. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  1953. {
  1954. int v;
  1955. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  1956. return;
  1957. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  1958. for (v = 0; v < pf->num_alloc_vsi; v++) {
  1959. if (pf->vsi[v] &&
  1960. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  1961. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  1962. if (ret) {
  1963. /* come back and try again later */
  1964. pf->flags |= I40E_FLAG_FILTER_SYNC;
  1965. break;
  1966. }
  1967. }
  1968. }
  1969. }
  1970. /**
  1971. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  1972. * @netdev: network interface device structure
  1973. * @new_mtu: new value for maximum frame size
  1974. *
  1975. * Returns 0 on success, negative on failure
  1976. **/
  1977. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  1978. {
  1979. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1980. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  1981. struct i40e_vsi *vsi = np->vsi;
  1982. /* MTU < 68 is an error and causes problems on some kernels */
  1983. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  1984. return -EINVAL;
  1985. netdev_info(netdev, "changing MTU from %d to %d\n",
  1986. netdev->mtu, new_mtu);
  1987. netdev->mtu = new_mtu;
  1988. if (netif_running(netdev))
  1989. i40e_vsi_reinit_locked(vsi);
  1990. i40e_notify_client_of_l2_param_changes(vsi);
  1991. return 0;
  1992. }
  1993. /**
  1994. * i40e_ioctl - Access the hwtstamp interface
  1995. * @netdev: network interface device structure
  1996. * @ifr: interface request data
  1997. * @cmd: ioctl command
  1998. **/
  1999. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2000. {
  2001. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2002. struct i40e_pf *pf = np->vsi->back;
  2003. switch (cmd) {
  2004. case SIOCGHWTSTAMP:
  2005. return i40e_ptp_get_ts_config(pf, ifr);
  2006. case SIOCSHWTSTAMP:
  2007. return i40e_ptp_set_ts_config(pf, ifr);
  2008. default:
  2009. return -EOPNOTSUPP;
  2010. }
  2011. }
  2012. /**
  2013. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2014. * @vsi: the vsi being adjusted
  2015. **/
  2016. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2017. {
  2018. struct i40e_vsi_context ctxt;
  2019. i40e_status ret;
  2020. if ((vsi->info.valid_sections &
  2021. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2022. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2023. return; /* already enabled */
  2024. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2025. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2026. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2027. ctxt.seid = vsi->seid;
  2028. ctxt.info = vsi->info;
  2029. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2030. if (ret) {
  2031. dev_info(&vsi->back->pdev->dev,
  2032. "update vlan stripping failed, err %s aq_err %s\n",
  2033. i40e_stat_str(&vsi->back->hw, ret),
  2034. i40e_aq_str(&vsi->back->hw,
  2035. vsi->back->hw.aq.asq_last_status));
  2036. }
  2037. }
  2038. /**
  2039. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2040. * @vsi: the vsi being adjusted
  2041. **/
  2042. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2043. {
  2044. struct i40e_vsi_context ctxt;
  2045. i40e_status ret;
  2046. if ((vsi->info.valid_sections &
  2047. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2048. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2049. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2050. return; /* already disabled */
  2051. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2052. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2053. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2054. ctxt.seid = vsi->seid;
  2055. ctxt.info = vsi->info;
  2056. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2057. if (ret) {
  2058. dev_info(&vsi->back->pdev->dev,
  2059. "update vlan stripping failed, err %s aq_err %s\n",
  2060. i40e_stat_str(&vsi->back->hw, ret),
  2061. i40e_aq_str(&vsi->back->hw,
  2062. vsi->back->hw.aq.asq_last_status));
  2063. }
  2064. }
  2065. /**
  2066. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2067. * @netdev: network interface to be adjusted
  2068. * @features: netdev features to test if VLAN offload is enabled or not
  2069. **/
  2070. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2071. {
  2072. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2073. struct i40e_vsi *vsi = np->vsi;
  2074. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2075. i40e_vlan_stripping_enable(vsi);
  2076. else
  2077. i40e_vlan_stripping_disable(vsi);
  2078. }
  2079. /**
  2080. * i40e_vsi_add_vlan - Add vsi membership for given vlan
  2081. * @vsi: the vsi being configured
  2082. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2083. **/
  2084. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  2085. {
  2086. struct i40e_mac_filter *f, *add_f;
  2087. bool is_netdev, is_vf;
  2088. is_vf = (vsi->type == I40E_VSI_SRIOV);
  2089. is_netdev = !!(vsi->netdev);
  2090. /* Locked once because all functions invoked below iterates list*/
  2091. spin_lock_bh(&vsi->mac_filter_list_lock);
  2092. if (is_netdev) {
  2093. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
  2094. is_vf, is_netdev);
  2095. if (!add_f) {
  2096. dev_info(&vsi->back->pdev->dev,
  2097. "Could not add vlan filter %d for %pM\n",
  2098. vid, vsi->netdev->dev_addr);
  2099. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2100. return -ENOMEM;
  2101. }
  2102. }
  2103. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  2104. add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  2105. if (!add_f) {
  2106. dev_info(&vsi->back->pdev->dev,
  2107. "Could not add vlan filter %d for %pM\n",
  2108. vid, f->macaddr);
  2109. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2110. return -ENOMEM;
  2111. }
  2112. }
  2113. /* Now if we add a vlan tag, make sure to check if it is the first
  2114. * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
  2115. * with 0, so we now accept untagged and specified tagged traffic
  2116. * (and not any taged and untagged)
  2117. */
  2118. if (vid > 0) {
  2119. if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
  2120. I40E_VLAN_ANY,
  2121. is_vf, is_netdev)) {
  2122. i40e_del_filter(vsi, vsi->netdev->dev_addr,
  2123. I40E_VLAN_ANY, is_vf, is_netdev);
  2124. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
  2125. is_vf, is_netdev);
  2126. if (!add_f) {
  2127. dev_info(&vsi->back->pdev->dev,
  2128. "Could not add filter 0 for %pM\n",
  2129. vsi->netdev->dev_addr);
  2130. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2131. return -ENOMEM;
  2132. }
  2133. }
  2134. }
  2135. /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
  2136. if (vid > 0 && !vsi->info.pvid) {
  2137. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  2138. if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  2139. is_vf, is_netdev))
  2140. continue;
  2141. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  2142. is_vf, is_netdev);
  2143. add_f = i40e_add_filter(vsi, f->macaddr,
  2144. 0, is_vf, is_netdev);
  2145. if (!add_f) {
  2146. dev_info(&vsi->back->pdev->dev,
  2147. "Could not add filter 0 for %pM\n",
  2148. f->macaddr);
  2149. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2150. return -ENOMEM;
  2151. }
  2152. }
  2153. }
  2154. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2155. /* schedule our worker thread which will take care of
  2156. * applying the new filter changes
  2157. */
  2158. i40e_service_event_schedule(vsi->back);
  2159. return 0;
  2160. }
  2161. /**
  2162. * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
  2163. * @vsi: the vsi being configured
  2164. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2165. *
  2166. * Return: 0 on success or negative otherwise
  2167. **/
  2168. int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  2169. {
  2170. struct net_device *netdev = vsi->netdev;
  2171. struct i40e_mac_filter *f, *add_f;
  2172. bool is_vf, is_netdev;
  2173. int filter_count = 0;
  2174. is_vf = (vsi->type == I40E_VSI_SRIOV);
  2175. is_netdev = !!(netdev);
  2176. /* Locked once because all functions invoked below iterates list */
  2177. spin_lock_bh(&vsi->mac_filter_list_lock);
  2178. if (is_netdev)
  2179. i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
  2180. list_for_each_entry(f, &vsi->mac_filter_list, list)
  2181. i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  2182. /* go through all the filters for this VSI and if there is only
  2183. * vid == 0 it means there are no other filters, so vid 0 must
  2184. * be replaced with -1. This signifies that we should from now
  2185. * on accept any traffic (with any tag present, or untagged)
  2186. */
  2187. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  2188. if (is_netdev) {
  2189. if (f->vlan &&
  2190. ether_addr_equal(netdev->dev_addr, f->macaddr))
  2191. filter_count++;
  2192. }
  2193. if (f->vlan)
  2194. filter_count++;
  2195. }
  2196. if (!filter_count && is_netdev) {
  2197. i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
  2198. f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  2199. is_vf, is_netdev);
  2200. if (!f) {
  2201. dev_info(&vsi->back->pdev->dev,
  2202. "Could not add filter %d for %pM\n",
  2203. I40E_VLAN_ANY, netdev->dev_addr);
  2204. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2205. return -ENOMEM;
  2206. }
  2207. }
  2208. if (!filter_count) {
  2209. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  2210. i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
  2211. add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  2212. is_vf, is_netdev);
  2213. if (!add_f) {
  2214. dev_info(&vsi->back->pdev->dev,
  2215. "Could not add filter %d for %pM\n",
  2216. I40E_VLAN_ANY, f->macaddr);
  2217. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2218. return -ENOMEM;
  2219. }
  2220. }
  2221. }
  2222. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2223. /* schedule our worker thread which will take care of
  2224. * applying the new filter changes
  2225. */
  2226. i40e_service_event_schedule(vsi->back);
  2227. return 0;
  2228. }
  2229. /**
  2230. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2231. * @netdev: network interface to be adjusted
  2232. * @vid: vlan id to be added
  2233. *
  2234. * net_device_ops implementation for adding vlan ids
  2235. **/
  2236. #ifdef I40E_FCOE
  2237. int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2238. __always_unused __be16 proto, u16 vid)
  2239. #else
  2240. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2241. __always_unused __be16 proto, u16 vid)
  2242. #endif
  2243. {
  2244. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2245. struct i40e_vsi *vsi = np->vsi;
  2246. int ret = 0;
  2247. if (vid > 4095)
  2248. return -EINVAL;
  2249. netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
  2250. /* If the network stack called us with vid = 0 then
  2251. * it is asking to receive priority tagged packets with
  2252. * vlan id 0. Our HW receives them by default when configured
  2253. * to receive untagged packets so there is no need to add an
  2254. * extra filter for vlan 0 tagged packets.
  2255. */
  2256. if (vid)
  2257. ret = i40e_vsi_add_vlan(vsi, vid);
  2258. if (!ret && (vid < VLAN_N_VID))
  2259. set_bit(vid, vsi->active_vlans);
  2260. return ret;
  2261. }
  2262. /**
  2263. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2264. * @netdev: network interface to be adjusted
  2265. * @vid: vlan id to be removed
  2266. *
  2267. * net_device_ops implementation for removing vlan ids
  2268. **/
  2269. #ifdef I40E_FCOE
  2270. int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2271. __always_unused __be16 proto, u16 vid)
  2272. #else
  2273. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2274. __always_unused __be16 proto, u16 vid)
  2275. #endif
  2276. {
  2277. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2278. struct i40e_vsi *vsi = np->vsi;
  2279. netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
  2280. /* return code is ignored as there is nothing a user
  2281. * can do about failure to remove and a log message was
  2282. * already printed from the other function
  2283. */
  2284. i40e_vsi_kill_vlan(vsi, vid);
  2285. clear_bit(vid, vsi->active_vlans);
  2286. return 0;
  2287. }
  2288. /**
  2289. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2290. * @vsi: the vsi being brought back up
  2291. **/
  2292. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2293. {
  2294. u16 vid;
  2295. if (!vsi->netdev)
  2296. return;
  2297. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2298. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2299. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2300. vid);
  2301. }
  2302. /**
  2303. * i40e_vsi_add_pvid - Add pvid for the VSI
  2304. * @vsi: the vsi being adjusted
  2305. * @vid: the vlan id to set as a PVID
  2306. **/
  2307. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2308. {
  2309. struct i40e_vsi_context ctxt;
  2310. i40e_status ret;
  2311. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2312. vsi->info.pvid = cpu_to_le16(vid);
  2313. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2314. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2315. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2316. ctxt.seid = vsi->seid;
  2317. ctxt.info = vsi->info;
  2318. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2319. if (ret) {
  2320. dev_info(&vsi->back->pdev->dev,
  2321. "add pvid failed, err %s aq_err %s\n",
  2322. i40e_stat_str(&vsi->back->hw, ret),
  2323. i40e_aq_str(&vsi->back->hw,
  2324. vsi->back->hw.aq.asq_last_status));
  2325. return -ENOENT;
  2326. }
  2327. return 0;
  2328. }
  2329. /**
  2330. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2331. * @vsi: the vsi being adjusted
  2332. *
  2333. * Just use the vlan_rx_register() service to put it back to normal
  2334. **/
  2335. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2336. {
  2337. i40e_vlan_stripping_disable(vsi);
  2338. vsi->info.pvid = 0;
  2339. }
  2340. /**
  2341. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2342. * @vsi: ptr to the VSI
  2343. *
  2344. * If this function returns with an error, then it's possible one or
  2345. * more of the rings is populated (while the rest are not). It is the
  2346. * callers duty to clean those orphaned rings.
  2347. *
  2348. * Return 0 on success, negative on failure
  2349. **/
  2350. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2351. {
  2352. int i, err = 0;
  2353. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2354. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2355. return err;
  2356. }
  2357. /**
  2358. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2359. * @vsi: ptr to the VSI
  2360. *
  2361. * Free VSI's transmit software resources
  2362. **/
  2363. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2364. {
  2365. int i;
  2366. if (!vsi->tx_rings)
  2367. return;
  2368. for (i = 0; i < vsi->num_queue_pairs; i++)
  2369. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2370. i40e_free_tx_resources(vsi->tx_rings[i]);
  2371. }
  2372. /**
  2373. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2374. * @vsi: ptr to the VSI
  2375. *
  2376. * If this function returns with an error, then it's possible one or
  2377. * more of the rings is populated (while the rest are not). It is the
  2378. * callers duty to clean those orphaned rings.
  2379. *
  2380. * Return 0 on success, negative on failure
  2381. **/
  2382. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2383. {
  2384. int i, err = 0;
  2385. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2386. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2387. #ifdef I40E_FCOE
  2388. i40e_fcoe_setup_ddp_resources(vsi);
  2389. #endif
  2390. return err;
  2391. }
  2392. /**
  2393. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2394. * @vsi: ptr to the VSI
  2395. *
  2396. * Free all receive software resources
  2397. **/
  2398. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2399. {
  2400. int i;
  2401. if (!vsi->rx_rings)
  2402. return;
  2403. for (i = 0; i < vsi->num_queue_pairs; i++)
  2404. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2405. i40e_free_rx_resources(vsi->rx_rings[i]);
  2406. #ifdef I40E_FCOE
  2407. i40e_fcoe_free_ddp_resources(vsi);
  2408. #endif
  2409. }
  2410. /**
  2411. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2412. * @ring: The Tx ring to configure
  2413. *
  2414. * This enables/disables XPS for a given Tx descriptor ring
  2415. * based on the TCs enabled for the VSI that ring belongs to.
  2416. **/
  2417. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2418. {
  2419. struct i40e_vsi *vsi = ring->vsi;
  2420. cpumask_var_t mask;
  2421. if (!ring->q_vector || !ring->netdev)
  2422. return;
  2423. /* Single TC mode enable XPS */
  2424. if (vsi->tc_config.numtc <= 1) {
  2425. if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2426. netif_set_xps_queue(ring->netdev,
  2427. &ring->q_vector->affinity_mask,
  2428. ring->queue_index);
  2429. } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
  2430. /* Disable XPS to allow selection based on TC */
  2431. bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
  2432. netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
  2433. free_cpumask_var(mask);
  2434. }
  2435. /* schedule our worker thread which will take care of
  2436. * applying the new filter changes
  2437. */
  2438. i40e_service_event_schedule(vsi->back);
  2439. }
  2440. /**
  2441. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2442. * @ring: The Tx ring to configure
  2443. *
  2444. * Configure the Tx descriptor ring in the HMC context.
  2445. **/
  2446. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2447. {
  2448. struct i40e_vsi *vsi = ring->vsi;
  2449. u16 pf_q = vsi->base_queue + ring->queue_index;
  2450. struct i40e_hw *hw = &vsi->back->hw;
  2451. struct i40e_hmc_obj_txq tx_ctx;
  2452. i40e_status err = 0;
  2453. u32 qtx_ctl = 0;
  2454. /* some ATR related tx ring init */
  2455. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2456. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2457. ring->atr_count = 0;
  2458. } else {
  2459. ring->atr_sample_rate = 0;
  2460. }
  2461. /* configure XPS */
  2462. i40e_config_xps_tx_ring(ring);
  2463. /* clear the context structure first */
  2464. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2465. tx_ctx.new_context = 1;
  2466. tx_ctx.base = (ring->dma / 128);
  2467. tx_ctx.qlen = ring->count;
  2468. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2469. I40E_FLAG_FD_ATR_ENABLED));
  2470. #ifdef I40E_FCOE
  2471. tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2472. #endif
  2473. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2474. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2475. if (vsi->type != I40E_VSI_FDIR)
  2476. tx_ctx.head_wb_ena = 1;
  2477. tx_ctx.head_wb_addr = ring->dma +
  2478. (ring->count * sizeof(struct i40e_tx_desc));
  2479. /* As part of VSI creation/update, FW allocates certain
  2480. * Tx arbitration queue sets for each TC enabled for
  2481. * the VSI. The FW returns the handles to these queue
  2482. * sets as part of the response buffer to Add VSI,
  2483. * Update VSI, etc. AQ commands. It is expected that
  2484. * these queue set handles be associated with the Tx
  2485. * queues by the driver as part of the TX queue context
  2486. * initialization. This has to be done regardless of
  2487. * DCB as by default everything is mapped to TC0.
  2488. */
  2489. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2490. tx_ctx.rdylist_act = 0;
  2491. /* clear the context in the HMC */
  2492. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2493. if (err) {
  2494. dev_info(&vsi->back->pdev->dev,
  2495. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2496. ring->queue_index, pf_q, err);
  2497. return -ENOMEM;
  2498. }
  2499. /* set the context in the HMC */
  2500. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2501. if (err) {
  2502. dev_info(&vsi->back->pdev->dev,
  2503. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2504. ring->queue_index, pf_q, err);
  2505. return -ENOMEM;
  2506. }
  2507. /* Now associate this queue with this PCI function */
  2508. if (vsi->type == I40E_VSI_VMDQ2) {
  2509. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2510. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2511. I40E_QTX_CTL_VFVM_INDX_MASK;
  2512. } else {
  2513. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2514. }
  2515. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2516. I40E_QTX_CTL_PF_INDX_MASK);
  2517. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2518. i40e_flush(hw);
  2519. /* cache tail off for easier writes later */
  2520. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2521. return 0;
  2522. }
  2523. /**
  2524. * i40e_configure_rx_ring - Configure a receive ring context
  2525. * @ring: The Rx ring to configure
  2526. *
  2527. * Configure the Rx descriptor ring in the HMC context.
  2528. **/
  2529. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2530. {
  2531. struct i40e_vsi *vsi = ring->vsi;
  2532. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2533. u16 pf_q = vsi->base_queue + ring->queue_index;
  2534. struct i40e_hw *hw = &vsi->back->hw;
  2535. struct i40e_hmc_obj_rxq rx_ctx;
  2536. i40e_status err = 0;
  2537. ring->state = 0;
  2538. /* clear the context structure first */
  2539. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2540. ring->rx_buf_len = vsi->rx_buf_len;
  2541. ring->rx_hdr_len = vsi->rx_hdr_len;
  2542. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2543. rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
  2544. rx_ctx.base = (ring->dma / 128);
  2545. rx_ctx.qlen = ring->count;
  2546. if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
  2547. set_ring_16byte_desc_enabled(ring);
  2548. rx_ctx.dsize = 0;
  2549. } else {
  2550. rx_ctx.dsize = 1;
  2551. }
  2552. rx_ctx.dtype = vsi->dtype;
  2553. if (vsi->dtype) {
  2554. set_ring_ps_enabled(ring);
  2555. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  2556. I40E_RX_SPLIT_IP |
  2557. I40E_RX_SPLIT_TCP_UDP |
  2558. I40E_RX_SPLIT_SCTP;
  2559. } else {
  2560. rx_ctx.hsplit_0 = 0;
  2561. }
  2562. rx_ctx.rxmax = min_t(u16, vsi->max_frame,
  2563. (chain_len * ring->rx_buf_len));
  2564. if (hw->revision_id == 0)
  2565. rx_ctx.lrxqthresh = 0;
  2566. else
  2567. rx_ctx.lrxqthresh = 2;
  2568. rx_ctx.crcstrip = 1;
  2569. rx_ctx.l2tsel = 1;
  2570. /* this controls whether VLAN is stripped from inner headers */
  2571. rx_ctx.showiv = 0;
  2572. #ifdef I40E_FCOE
  2573. rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2574. #endif
  2575. /* set the prefena field to 1 because the manual says to */
  2576. rx_ctx.prefena = 1;
  2577. /* clear the context in the HMC */
  2578. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2579. if (err) {
  2580. dev_info(&vsi->back->pdev->dev,
  2581. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2582. ring->queue_index, pf_q, err);
  2583. return -ENOMEM;
  2584. }
  2585. /* set the context in the HMC */
  2586. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2587. if (err) {
  2588. dev_info(&vsi->back->pdev->dev,
  2589. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2590. ring->queue_index, pf_q, err);
  2591. return -ENOMEM;
  2592. }
  2593. /* cache tail for quicker writes, and clear the reg before use */
  2594. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2595. writel(0, ring->tail);
  2596. if (ring_is_ps_enabled(ring)) {
  2597. i40e_alloc_rx_headers(ring);
  2598. i40e_alloc_rx_buffers_ps(ring, I40E_DESC_UNUSED(ring));
  2599. } else {
  2600. i40e_alloc_rx_buffers_1buf(ring, I40E_DESC_UNUSED(ring));
  2601. }
  2602. return 0;
  2603. }
  2604. /**
  2605. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2606. * @vsi: VSI structure describing this set of rings and resources
  2607. *
  2608. * Configure the Tx VSI for operation.
  2609. **/
  2610. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2611. {
  2612. int err = 0;
  2613. u16 i;
  2614. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2615. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2616. return err;
  2617. }
  2618. /**
  2619. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2620. * @vsi: the VSI being configured
  2621. *
  2622. * Configure the Rx VSI for operation.
  2623. **/
  2624. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2625. {
  2626. int err = 0;
  2627. u16 i;
  2628. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2629. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2630. + ETH_FCS_LEN + VLAN_HLEN;
  2631. else
  2632. vsi->max_frame = I40E_RXBUFFER_2048;
  2633. /* figure out correct receive buffer length */
  2634. switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
  2635. I40E_FLAG_RX_PS_ENABLED)) {
  2636. case I40E_FLAG_RX_1BUF_ENABLED:
  2637. vsi->rx_hdr_len = 0;
  2638. vsi->rx_buf_len = vsi->max_frame;
  2639. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2640. break;
  2641. case I40E_FLAG_RX_PS_ENABLED:
  2642. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2643. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2644. vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  2645. break;
  2646. default:
  2647. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2648. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2649. vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
  2650. break;
  2651. }
  2652. #ifdef I40E_FCOE
  2653. /* setup rx buffer for FCoE */
  2654. if ((vsi->type == I40E_VSI_FCOE) &&
  2655. (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
  2656. vsi->rx_hdr_len = 0;
  2657. vsi->rx_buf_len = I40E_RXBUFFER_3072;
  2658. vsi->max_frame = I40E_RXBUFFER_3072;
  2659. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2660. }
  2661. #endif /* I40E_FCOE */
  2662. /* round up for the chip's needs */
  2663. vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
  2664. BIT_ULL(I40E_RXQ_CTX_HBUFF_SHIFT));
  2665. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2666. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2667. /* set up individual rings */
  2668. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2669. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2670. return err;
  2671. }
  2672. /**
  2673. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2674. * @vsi: ptr to the VSI
  2675. **/
  2676. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2677. {
  2678. struct i40e_ring *tx_ring, *rx_ring;
  2679. u16 qoffset, qcount;
  2680. int i, n;
  2681. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2682. /* Reset the TC information */
  2683. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2684. rx_ring = vsi->rx_rings[i];
  2685. tx_ring = vsi->tx_rings[i];
  2686. rx_ring->dcb_tc = 0;
  2687. tx_ring->dcb_tc = 0;
  2688. }
  2689. }
  2690. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2691. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2692. continue;
  2693. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2694. qcount = vsi->tc_config.tc_info[n].qcount;
  2695. for (i = qoffset; i < (qoffset + qcount); i++) {
  2696. rx_ring = vsi->rx_rings[i];
  2697. tx_ring = vsi->tx_rings[i];
  2698. rx_ring->dcb_tc = n;
  2699. tx_ring->dcb_tc = n;
  2700. }
  2701. }
  2702. }
  2703. /**
  2704. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2705. * @vsi: ptr to the VSI
  2706. **/
  2707. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2708. {
  2709. if (vsi->netdev)
  2710. i40e_set_rx_mode(vsi->netdev);
  2711. }
  2712. /**
  2713. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2714. * @vsi: Pointer to the targeted VSI
  2715. *
  2716. * This function replays the hlist on the hw where all the SB Flow Director
  2717. * filters were saved.
  2718. **/
  2719. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2720. {
  2721. struct i40e_fdir_filter *filter;
  2722. struct i40e_pf *pf = vsi->back;
  2723. struct hlist_node *node;
  2724. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2725. return;
  2726. hlist_for_each_entry_safe(filter, node,
  2727. &pf->fdir_filter_list, fdir_node) {
  2728. i40e_add_del_fdir(vsi, filter, true);
  2729. }
  2730. }
  2731. /**
  2732. * i40e_vsi_configure - Set up the VSI for action
  2733. * @vsi: the VSI being configured
  2734. **/
  2735. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2736. {
  2737. int err;
  2738. i40e_set_vsi_rx_mode(vsi);
  2739. i40e_restore_vlan(vsi);
  2740. i40e_vsi_config_dcb_rings(vsi);
  2741. err = i40e_vsi_configure_tx(vsi);
  2742. if (!err)
  2743. err = i40e_vsi_configure_rx(vsi);
  2744. return err;
  2745. }
  2746. /**
  2747. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2748. * @vsi: the VSI being configured
  2749. **/
  2750. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2751. {
  2752. struct i40e_pf *pf = vsi->back;
  2753. struct i40e_hw *hw = &pf->hw;
  2754. u16 vector;
  2755. int i, q;
  2756. u32 qp;
  2757. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2758. * and PFINT_LNKLSTn registers, e.g.:
  2759. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2760. */
  2761. qp = vsi->base_queue;
  2762. vector = vsi->base_vector;
  2763. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2764. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  2765. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2766. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  2767. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2768. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2769. q_vector->rx.itr);
  2770. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  2771. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2772. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2773. q_vector->tx.itr);
  2774. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  2775. INTRL_USEC_TO_REG(vsi->int_rate_limit));
  2776. /* Linked list for the queuepairs assigned to this vector */
  2777. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2778. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2779. u32 val;
  2780. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2781. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2782. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2783. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2784. (I40E_QUEUE_TYPE_TX
  2785. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2786. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2787. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2788. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2789. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2790. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2791. (I40E_QUEUE_TYPE_RX
  2792. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2793. /* Terminate the linked list */
  2794. if (q == (q_vector->num_ringpairs - 1))
  2795. val |= (I40E_QUEUE_END_OF_LIST
  2796. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2797. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2798. qp++;
  2799. }
  2800. }
  2801. i40e_flush(hw);
  2802. }
  2803. /**
  2804. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2805. * @hw: ptr to the hardware info
  2806. **/
  2807. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  2808. {
  2809. struct i40e_hw *hw = &pf->hw;
  2810. u32 val;
  2811. /* clear things first */
  2812. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2813. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2814. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2815. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2816. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2817. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2818. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2819. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2820. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2821. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2822. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  2823. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  2824. if (pf->flags & I40E_FLAG_PTP)
  2825. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2826. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2827. /* SW_ITR_IDX = 0, but don't change INTENA */
  2828. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2829. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2830. /* OTHER_ITR_IDX = 0 */
  2831. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2832. }
  2833. /**
  2834. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2835. * @vsi: the VSI being configured
  2836. **/
  2837. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2838. {
  2839. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2840. struct i40e_pf *pf = vsi->back;
  2841. struct i40e_hw *hw = &pf->hw;
  2842. u32 val;
  2843. /* set the ITR configuration */
  2844. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2845. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  2846. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2847. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2848. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  2849. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2850. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2851. i40e_enable_misc_int_causes(pf);
  2852. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2853. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2854. /* Associate the queue pair to the vector and enable the queue int */
  2855. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2856. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2857. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2858. wr32(hw, I40E_QINT_RQCTL(0), val);
  2859. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2860. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2861. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2862. wr32(hw, I40E_QINT_TQCTL(0), val);
  2863. i40e_flush(hw);
  2864. }
  2865. /**
  2866. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  2867. * @pf: board private structure
  2868. **/
  2869. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  2870. {
  2871. struct i40e_hw *hw = &pf->hw;
  2872. wr32(hw, I40E_PFINT_DYN_CTL0,
  2873. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2874. i40e_flush(hw);
  2875. }
  2876. /**
  2877. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  2878. * @pf: board private structure
  2879. * @clearpba: true when all pending interrupt events should be cleared
  2880. **/
  2881. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
  2882. {
  2883. struct i40e_hw *hw = &pf->hw;
  2884. u32 val;
  2885. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  2886. (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
  2887. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  2888. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2889. i40e_flush(hw);
  2890. }
  2891. /**
  2892. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  2893. * @irq: interrupt number
  2894. * @data: pointer to a q_vector
  2895. **/
  2896. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  2897. {
  2898. struct i40e_q_vector *q_vector = data;
  2899. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2900. return IRQ_HANDLED;
  2901. napi_schedule_irqoff(&q_vector->napi);
  2902. return IRQ_HANDLED;
  2903. }
  2904. /**
  2905. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  2906. * @vsi: the VSI being configured
  2907. * @basename: name for the vector
  2908. *
  2909. * Allocates MSI-X vectors and requests interrupts from the kernel.
  2910. **/
  2911. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  2912. {
  2913. int q_vectors = vsi->num_q_vectors;
  2914. struct i40e_pf *pf = vsi->back;
  2915. int base = vsi->base_vector;
  2916. int rx_int_idx = 0;
  2917. int tx_int_idx = 0;
  2918. int vector, err;
  2919. for (vector = 0; vector < q_vectors; vector++) {
  2920. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  2921. if (q_vector->tx.ring && q_vector->rx.ring) {
  2922. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2923. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  2924. tx_int_idx++;
  2925. } else if (q_vector->rx.ring) {
  2926. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2927. "%s-%s-%d", basename, "rx", rx_int_idx++);
  2928. } else if (q_vector->tx.ring) {
  2929. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2930. "%s-%s-%d", basename, "tx", tx_int_idx++);
  2931. } else {
  2932. /* skip this unused q_vector */
  2933. continue;
  2934. }
  2935. err = request_irq(pf->msix_entries[base + vector].vector,
  2936. vsi->irq_handler,
  2937. 0,
  2938. q_vector->name,
  2939. q_vector);
  2940. if (err) {
  2941. dev_info(&pf->pdev->dev,
  2942. "MSIX request_irq failed, error: %d\n", err);
  2943. goto free_queue_irqs;
  2944. }
  2945. /* assign the mask for this irq */
  2946. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2947. &q_vector->affinity_mask);
  2948. }
  2949. vsi->irqs_ready = true;
  2950. return 0;
  2951. free_queue_irqs:
  2952. while (vector) {
  2953. vector--;
  2954. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2955. NULL);
  2956. free_irq(pf->msix_entries[base + vector].vector,
  2957. &(vsi->q_vectors[vector]));
  2958. }
  2959. return err;
  2960. }
  2961. /**
  2962. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  2963. * @vsi: the VSI being un-configured
  2964. **/
  2965. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  2966. {
  2967. struct i40e_pf *pf = vsi->back;
  2968. struct i40e_hw *hw = &pf->hw;
  2969. int base = vsi->base_vector;
  2970. int i;
  2971. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2972. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  2973. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  2974. }
  2975. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2976. for (i = vsi->base_vector;
  2977. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2978. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  2979. i40e_flush(hw);
  2980. for (i = 0; i < vsi->num_q_vectors; i++)
  2981. synchronize_irq(pf->msix_entries[i + base].vector);
  2982. } else {
  2983. /* Legacy and MSI mode - this stops all interrupt handling */
  2984. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  2985. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  2986. i40e_flush(hw);
  2987. synchronize_irq(pf->pdev->irq);
  2988. }
  2989. }
  2990. /**
  2991. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  2992. * @vsi: the VSI being configured
  2993. **/
  2994. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  2995. {
  2996. struct i40e_pf *pf = vsi->back;
  2997. int i;
  2998. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2999. for (i = 0; i < vsi->num_q_vectors; i++)
  3000. i40e_irq_dynamic_enable(vsi, i);
  3001. } else {
  3002. i40e_irq_dynamic_enable_icr0(pf, true);
  3003. }
  3004. i40e_flush(&pf->hw);
  3005. return 0;
  3006. }
  3007. /**
  3008. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  3009. * @pf: board private structure
  3010. **/
  3011. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  3012. {
  3013. /* Disable ICR 0 */
  3014. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3015. i40e_flush(&pf->hw);
  3016. }
  3017. /**
  3018. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3019. * @irq: interrupt number
  3020. * @data: pointer to a q_vector
  3021. *
  3022. * This is the handler used for all MSI/Legacy interrupts, and deals
  3023. * with both queue and non-queue interrupts. This is also used in
  3024. * MSIX mode to handle the non-queue interrupts.
  3025. **/
  3026. static irqreturn_t i40e_intr(int irq, void *data)
  3027. {
  3028. struct i40e_pf *pf = (struct i40e_pf *)data;
  3029. struct i40e_hw *hw = &pf->hw;
  3030. irqreturn_t ret = IRQ_NONE;
  3031. u32 icr0, icr0_remaining;
  3032. u32 val, ena_mask;
  3033. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3034. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3035. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3036. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3037. goto enable_intr;
  3038. /* if interrupt but no bits showing, must be SWINT */
  3039. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3040. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3041. pf->sw_int_count++;
  3042. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3043. (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3044. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3045. icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3046. dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3047. }
  3048. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3049. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3050. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3051. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3052. /* We do not have a way to disarm Queue causes while leaving
  3053. * interrupt enabled for all other causes, ideally
  3054. * interrupt should be disabled while we are in NAPI but
  3055. * this is not a performance path and napi_schedule()
  3056. * can deal with rescheduling.
  3057. */
  3058. if (!test_bit(__I40E_DOWN, &pf->state))
  3059. napi_schedule_irqoff(&q_vector->napi);
  3060. }
  3061. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3062. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3063. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  3064. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3065. }
  3066. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3067. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3068. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  3069. }
  3070. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3071. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3072. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  3073. }
  3074. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3075. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  3076. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  3077. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3078. val = rd32(hw, I40E_GLGEN_RSTAT);
  3079. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3080. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3081. if (val == I40E_RESET_CORER) {
  3082. pf->corer_count++;
  3083. } else if (val == I40E_RESET_GLOBR) {
  3084. pf->globr_count++;
  3085. } else if (val == I40E_RESET_EMPR) {
  3086. pf->empr_count++;
  3087. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
  3088. }
  3089. }
  3090. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3091. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3092. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3093. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3094. rd32(hw, I40E_PFHMC_ERRORINFO),
  3095. rd32(hw, I40E_PFHMC_ERRORDATA));
  3096. }
  3097. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3098. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3099. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3100. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3101. i40e_ptp_tx_hwtstamp(pf);
  3102. }
  3103. }
  3104. /* If a critical error is pending we have no choice but to reset the
  3105. * device.
  3106. * Report and mask out any remaining unexpected interrupts.
  3107. */
  3108. icr0_remaining = icr0 & ena_mask;
  3109. if (icr0_remaining) {
  3110. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3111. icr0_remaining);
  3112. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3113. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3114. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3115. dev_info(&pf->pdev->dev, "device will be reset\n");
  3116. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  3117. i40e_service_event_schedule(pf);
  3118. }
  3119. ena_mask &= ~icr0_remaining;
  3120. }
  3121. ret = IRQ_HANDLED;
  3122. enable_intr:
  3123. /* re-enable interrupt causes */
  3124. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3125. if (!test_bit(__I40E_DOWN, &pf->state)) {
  3126. i40e_service_event_schedule(pf);
  3127. i40e_irq_dynamic_enable_icr0(pf, false);
  3128. }
  3129. return ret;
  3130. }
  3131. /**
  3132. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3133. * @tx_ring: tx ring to clean
  3134. * @budget: how many cleans we're allowed
  3135. *
  3136. * Returns true if there's any budget left (e.g. the clean is finished)
  3137. **/
  3138. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3139. {
  3140. struct i40e_vsi *vsi = tx_ring->vsi;
  3141. u16 i = tx_ring->next_to_clean;
  3142. struct i40e_tx_buffer *tx_buf;
  3143. struct i40e_tx_desc *tx_desc;
  3144. tx_buf = &tx_ring->tx_bi[i];
  3145. tx_desc = I40E_TX_DESC(tx_ring, i);
  3146. i -= tx_ring->count;
  3147. do {
  3148. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3149. /* if next_to_watch is not set then there is no work pending */
  3150. if (!eop_desc)
  3151. break;
  3152. /* prevent any other reads prior to eop_desc */
  3153. read_barrier_depends();
  3154. /* if the descriptor isn't done, no work yet to do */
  3155. if (!(eop_desc->cmd_type_offset_bsz &
  3156. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3157. break;
  3158. /* clear next_to_watch to prevent false hangs */
  3159. tx_buf->next_to_watch = NULL;
  3160. tx_desc->buffer_addr = 0;
  3161. tx_desc->cmd_type_offset_bsz = 0;
  3162. /* move past filter desc */
  3163. tx_buf++;
  3164. tx_desc++;
  3165. i++;
  3166. if (unlikely(!i)) {
  3167. i -= tx_ring->count;
  3168. tx_buf = tx_ring->tx_bi;
  3169. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3170. }
  3171. /* unmap skb header data */
  3172. dma_unmap_single(tx_ring->dev,
  3173. dma_unmap_addr(tx_buf, dma),
  3174. dma_unmap_len(tx_buf, len),
  3175. DMA_TO_DEVICE);
  3176. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3177. kfree(tx_buf->raw_buf);
  3178. tx_buf->raw_buf = NULL;
  3179. tx_buf->tx_flags = 0;
  3180. tx_buf->next_to_watch = NULL;
  3181. dma_unmap_len_set(tx_buf, len, 0);
  3182. tx_desc->buffer_addr = 0;
  3183. tx_desc->cmd_type_offset_bsz = 0;
  3184. /* move us past the eop_desc for start of next FD desc */
  3185. tx_buf++;
  3186. tx_desc++;
  3187. i++;
  3188. if (unlikely(!i)) {
  3189. i -= tx_ring->count;
  3190. tx_buf = tx_ring->tx_bi;
  3191. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3192. }
  3193. /* update budget accounting */
  3194. budget--;
  3195. } while (likely(budget));
  3196. i += tx_ring->count;
  3197. tx_ring->next_to_clean = i;
  3198. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3199. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3200. return budget > 0;
  3201. }
  3202. /**
  3203. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3204. * @irq: interrupt number
  3205. * @data: pointer to a q_vector
  3206. **/
  3207. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3208. {
  3209. struct i40e_q_vector *q_vector = data;
  3210. struct i40e_vsi *vsi;
  3211. if (!q_vector->tx.ring)
  3212. return IRQ_HANDLED;
  3213. vsi = q_vector->tx.ring->vsi;
  3214. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3215. return IRQ_HANDLED;
  3216. }
  3217. /**
  3218. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3219. * @vsi: the VSI being configured
  3220. * @v_idx: vector index
  3221. * @qp_idx: queue pair index
  3222. **/
  3223. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3224. {
  3225. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3226. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3227. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3228. tx_ring->q_vector = q_vector;
  3229. tx_ring->next = q_vector->tx.ring;
  3230. q_vector->tx.ring = tx_ring;
  3231. q_vector->tx.count++;
  3232. rx_ring->q_vector = q_vector;
  3233. rx_ring->next = q_vector->rx.ring;
  3234. q_vector->rx.ring = rx_ring;
  3235. q_vector->rx.count++;
  3236. }
  3237. /**
  3238. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3239. * @vsi: the VSI being configured
  3240. *
  3241. * This function maps descriptor rings to the queue-specific vectors
  3242. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3243. * one vector per queue pair, but on a constrained vector budget, we
  3244. * group the queue pairs as "efficiently" as possible.
  3245. **/
  3246. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3247. {
  3248. int qp_remaining = vsi->num_queue_pairs;
  3249. int q_vectors = vsi->num_q_vectors;
  3250. int num_ringpairs;
  3251. int v_start = 0;
  3252. int qp_idx = 0;
  3253. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3254. * group them so there are multiple queues per vector.
  3255. * It is also important to go through all the vectors available to be
  3256. * sure that if we don't use all the vectors, that the remaining vectors
  3257. * are cleared. This is especially important when decreasing the
  3258. * number of queues in use.
  3259. */
  3260. for (; v_start < q_vectors; v_start++) {
  3261. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3262. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3263. q_vector->num_ringpairs = num_ringpairs;
  3264. q_vector->rx.count = 0;
  3265. q_vector->tx.count = 0;
  3266. q_vector->rx.ring = NULL;
  3267. q_vector->tx.ring = NULL;
  3268. while (num_ringpairs--) {
  3269. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3270. qp_idx++;
  3271. qp_remaining--;
  3272. }
  3273. }
  3274. }
  3275. /**
  3276. * i40e_vsi_request_irq - Request IRQ from the OS
  3277. * @vsi: the VSI being configured
  3278. * @basename: name for the vector
  3279. **/
  3280. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3281. {
  3282. struct i40e_pf *pf = vsi->back;
  3283. int err;
  3284. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3285. err = i40e_vsi_request_irq_msix(vsi, basename);
  3286. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3287. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3288. pf->int_name, pf);
  3289. else
  3290. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3291. pf->int_name, pf);
  3292. if (err)
  3293. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3294. return err;
  3295. }
  3296. #ifdef CONFIG_NET_POLL_CONTROLLER
  3297. /**
  3298. * i40e_netpoll - A Polling 'interrupt' handler
  3299. * @netdev: network interface device structure
  3300. *
  3301. * This is used by netconsole to send skbs without having to re-enable
  3302. * interrupts. It's not called while the normal interrupt routine is executing.
  3303. **/
  3304. #ifdef I40E_FCOE
  3305. void i40e_netpoll(struct net_device *netdev)
  3306. #else
  3307. static void i40e_netpoll(struct net_device *netdev)
  3308. #endif
  3309. {
  3310. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3311. struct i40e_vsi *vsi = np->vsi;
  3312. struct i40e_pf *pf = vsi->back;
  3313. int i;
  3314. /* if interface is down do nothing */
  3315. if (test_bit(__I40E_DOWN, &vsi->state))
  3316. return;
  3317. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3318. for (i = 0; i < vsi->num_q_vectors; i++)
  3319. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3320. } else {
  3321. i40e_intr(pf->pdev->irq, netdev);
  3322. }
  3323. }
  3324. #endif
  3325. /**
  3326. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3327. * @pf: the PF being configured
  3328. * @pf_q: the PF queue
  3329. * @enable: enable or disable state of the queue
  3330. *
  3331. * This routine will wait for the given Tx queue of the PF to reach the
  3332. * enabled or disabled state.
  3333. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3334. * multiple retries; else will return 0 in case of success.
  3335. **/
  3336. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3337. {
  3338. int i;
  3339. u32 tx_reg;
  3340. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3341. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3342. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3343. break;
  3344. usleep_range(10, 20);
  3345. }
  3346. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3347. return -ETIMEDOUT;
  3348. return 0;
  3349. }
  3350. /**
  3351. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3352. * @vsi: the VSI being configured
  3353. * @enable: start or stop the rings
  3354. **/
  3355. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3356. {
  3357. struct i40e_pf *pf = vsi->back;
  3358. struct i40e_hw *hw = &pf->hw;
  3359. int i, j, pf_q, ret = 0;
  3360. u32 tx_reg;
  3361. pf_q = vsi->base_queue;
  3362. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3363. /* warn the TX unit of coming changes */
  3364. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3365. if (!enable)
  3366. usleep_range(10, 20);
  3367. for (j = 0; j < 50; j++) {
  3368. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3369. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3370. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3371. break;
  3372. usleep_range(1000, 2000);
  3373. }
  3374. /* Skip if the queue is already in the requested state */
  3375. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3376. continue;
  3377. /* turn on/off the queue */
  3378. if (enable) {
  3379. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3380. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3381. } else {
  3382. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3383. }
  3384. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3385. /* No waiting for the Tx queue to disable */
  3386. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3387. continue;
  3388. /* wait for the change to finish */
  3389. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3390. if (ret) {
  3391. dev_info(&pf->pdev->dev,
  3392. "VSI seid %d Tx ring %d %sable timeout\n",
  3393. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3394. break;
  3395. }
  3396. }
  3397. if (hw->revision_id == 0)
  3398. mdelay(50);
  3399. return ret;
  3400. }
  3401. /**
  3402. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3403. * @pf: the PF being configured
  3404. * @pf_q: the PF queue
  3405. * @enable: enable or disable state of the queue
  3406. *
  3407. * This routine will wait for the given Rx queue of the PF to reach the
  3408. * enabled or disabled state.
  3409. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3410. * multiple retries; else will return 0 in case of success.
  3411. **/
  3412. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3413. {
  3414. int i;
  3415. u32 rx_reg;
  3416. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3417. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3418. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3419. break;
  3420. usleep_range(10, 20);
  3421. }
  3422. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3423. return -ETIMEDOUT;
  3424. return 0;
  3425. }
  3426. /**
  3427. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3428. * @vsi: the VSI being configured
  3429. * @enable: start or stop the rings
  3430. **/
  3431. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3432. {
  3433. struct i40e_pf *pf = vsi->back;
  3434. struct i40e_hw *hw = &pf->hw;
  3435. int i, j, pf_q, ret = 0;
  3436. u32 rx_reg;
  3437. pf_q = vsi->base_queue;
  3438. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3439. for (j = 0; j < 50; j++) {
  3440. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3441. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3442. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3443. break;
  3444. usleep_range(1000, 2000);
  3445. }
  3446. /* Skip if the queue is already in the requested state */
  3447. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3448. continue;
  3449. /* turn on/off the queue */
  3450. if (enable)
  3451. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3452. else
  3453. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3454. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3455. /* No waiting for the Tx queue to disable */
  3456. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3457. continue;
  3458. /* wait for the change to finish */
  3459. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3460. if (ret) {
  3461. dev_info(&pf->pdev->dev,
  3462. "VSI seid %d Rx ring %d %sable timeout\n",
  3463. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3464. break;
  3465. }
  3466. }
  3467. return ret;
  3468. }
  3469. /**
  3470. * i40e_vsi_control_rings - Start or stop a VSI's rings
  3471. * @vsi: the VSI being configured
  3472. * @enable: start or stop the rings
  3473. **/
  3474. int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
  3475. {
  3476. int ret = 0;
  3477. /* do rx first for enable and last for disable */
  3478. if (request) {
  3479. ret = i40e_vsi_control_rx(vsi, request);
  3480. if (ret)
  3481. return ret;
  3482. ret = i40e_vsi_control_tx(vsi, request);
  3483. } else {
  3484. /* Ignore return value, we need to shutdown whatever we can */
  3485. i40e_vsi_control_tx(vsi, request);
  3486. i40e_vsi_control_rx(vsi, request);
  3487. }
  3488. return ret;
  3489. }
  3490. /**
  3491. * i40e_vsi_free_irq - Free the irq association with the OS
  3492. * @vsi: the VSI being configured
  3493. **/
  3494. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3495. {
  3496. struct i40e_pf *pf = vsi->back;
  3497. struct i40e_hw *hw = &pf->hw;
  3498. int base = vsi->base_vector;
  3499. u32 val, qp;
  3500. int i;
  3501. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3502. if (!vsi->q_vectors)
  3503. return;
  3504. if (!vsi->irqs_ready)
  3505. return;
  3506. vsi->irqs_ready = false;
  3507. for (i = 0; i < vsi->num_q_vectors; i++) {
  3508. u16 vector = i + base;
  3509. /* free only the irqs that were actually requested */
  3510. if (!vsi->q_vectors[i] ||
  3511. !vsi->q_vectors[i]->num_ringpairs)
  3512. continue;
  3513. /* clear the affinity_mask in the IRQ descriptor */
  3514. irq_set_affinity_hint(pf->msix_entries[vector].vector,
  3515. NULL);
  3516. free_irq(pf->msix_entries[vector].vector,
  3517. vsi->q_vectors[i]);
  3518. /* Tear down the interrupt queue link list
  3519. *
  3520. * We know that they come in pairs and always
  3521. * the Rx first, then the Tx. To clear the
  3522. * link list, stick the EOL value into the
  3523. * next_q field of the registers.
  3524. */
  3525. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3526. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3527. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3528. val |= I40E_QUEUE_END_OF_LIST
  3529. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3530. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3531. while (qp != I40E_QUEUE_END_OF_LIST) {
  3532. u32 next;
  3533. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3534. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3535. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3536. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3537. I40E_QINT_RQCTL_INTEVENT_MASK);
  3538. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3539. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3540. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3541. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3542. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3543. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3544. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3545. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3546. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3547. I40E_QINT_TQCTL_INTEVENT_MASK);
  3548. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3549. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3550. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3551. qp = next;
  3552. }
  3553. }
  3554. } else {
  3555. free_irq(pf->pdev->irq, pf);
  3556. val = rd32(hw, I40E_PFINT_LNKLST0);
  3557. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3558. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3559. val |= I40E_QUEUE_END_OF_LIST
  3560. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3561. wr32(hw, I40E_PFINT_LNKLST0, val);
  3562. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3563. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3564. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3565. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3566. I40E_QINT_RQCTL_INTEVENT_MASK);
  3567. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3568. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3569. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3570. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3571. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3572. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3573. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3574. I40E_QINT_TQCTL_INTEVENT_MASK);
  3575. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3576. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3577. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3578. }
  3579. }
  3580. /**
  3581. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3582. * @vsi: the VSI being configured
  3583. * @v_idx: Index of vector to be freed
  3584. *
  3585. * This function frees the memory allocated to the q_vector. In addition if
  3586. * NAPI is enabled it will delete any references to the NAPI struct prior
  3587. * to freeing the q_vector.
  3588. **/
  3589. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3590. {
  3591. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3592. struct i40e_ring *ring;
  3593. if (!q_vector)
  3594. return;
  3595. /* disassociate q_vector from rings */
  3596. i40e_for_each_ring(ring, q_vector->tx)
  3597. ring->q_vector = NULL;
  3598. i40e_for_each_ring(ring, q_vector->rx)
  3599. ring->q_vector = NULL;
  3600. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3601. if (vsi->netdev)
  3602. netif_napi_del(&q_vector->napi);
  3603. vsi->q_vectors[v_idx] = NULL;
  3604. kfree_rcu(q_vector, rcu);
  3605. }
  3606. /**
  3607. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3608. * @vsi: the VSI being un-configured
  3609. *
  3610. * This frees the memory allocated to the q_vectors and
  3611. * deletes references to the NAPI struct.
  3612. **/
  3613. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3614. {
  3615. int v_idx;
  3616. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3617. i40e_free_q_vector(vsi, v_idx);
  3618. }
  3619. /**
  3620. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3621. * @pf: board private structure
  3622. **/
  3623. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3624. {
  3625. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3626. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3627. pci_disable_msix(pf->pdev);
  3628. kfree(pf->msix_entries);
  3629. pf->msix_entries = NULL;
  3630. kfree(pf->irq_pile);
  3631. pf->irq_pile = NULL;
  3632. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3633. pci_disable_msi(pf->pdev);
  3634. }
  3635. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3636. }
  3637. /**
  3638. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3639. * @pf: board private structure
  3640. *
  3641. * We go through and clear interrupt specific resources and reset the structure
  3642. * to pre-load conditions
  3643. **/
  3644. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3645. {
  3646. int i;
  3647. i40e_stop_misc_vector(pf);
  3648. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3649. synchronize_irq(pf->msix_entries[0].vector);
  3650. free_irq(pf->msix_entries[0].vector, pf);
  3651. }
  3652. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  3653. I40E_IWARP_IRQ_PILE_ID);
  3654. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3655. for (i = 0; i < pf->num_alloc_vsi; i++)
  3656. if (pf->vsi[i])
  3657. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3658. i40e_reset_interrupt_capability(pf);
  3659. }
  3660. /**
  3661. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3662. * @vsi: the VSI being configured
  3663. **/
  3664. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3665. {
  3666. int q_idx;
  3667. if (!vsi->netdev)
  3668. return;
  3669. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3670. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3671. }
  3672. /**
  3673. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3674. * @vsi: the VSI being configured
  3675. **/
  3676. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3677. {
  3678. int q_idx;
  3679. if (!vsi->netdev)
  3680. return;
  3681. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3682. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3683. }
  3684. /**
  3685. * i40e_vsi_close - Shut down a VSI
  3686. * @vsi: the vsi to be quelled
  3687. **/
  3688. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3689. {
  3690. bool reset = false;
  3691. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3692. i40e_down(vsi);
  3693. i40e_vsi_free_irq(vsi);
  3694. i40e_vsi_free_tx_resources(vsi);
  3695. i40e_vsi_free_rx_resources(vsi);
  3696. vsi->current_netdev_flags = 0;
  3697. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  3698. reset = true;
  3699. i40e_notify_client_of_netdev_close(vsi, reset);
  3700. }
  3701. /**
  3702. * i40e_quiesce_vsi - Pause a given VSI
  3703. * @vsi: the VSI being paused
  3704. **/
  3705. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3706. {
  3707. if (test_bit(__I40E_DOWN, &vsi->state))
  3708. return;
  3709. /* No need to disable FCoE VSI when Tx suspended */
  3710. if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
  3711. vsi->type == I40E_VSI_FCOE) {
  3712. dev_dbg(&vsi->back->pdev->dev,
  3713. "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
  3714. return;
  3715. }
  3716. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3717. if (vsi->netdev && netif_running(vsi->netdev))
  3718. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3719. else
  3720. i40e_vsi_close(vsi);
  3721. }
  3722. /**
  3723. * i40e_unquiesce_vsi - Resume a given VSI
  3724. * @vsi: the VSI being resumed
  3725. **/
  3726. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3727. {
  3728. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3729. return;
  3730. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3731. if (vsi->netdev && netif_running(vsi->netdev))
  3732. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3733. else
  3734. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3735. }
  3736. /**
  3737. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3738. * @pf: the PF
  3739. **/
  3740. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3741. {
  3742. int v;
  3743. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3744. if (pf->vsi[v])
  3745. i40e_quiesce_vsi(pf->vsi[v]);
  3746. }
  3747. }
  3748. /**
  3749. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3750. * @pf: the PF
  3751. **/
  3752. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3753. {
  3754. int v;
  3755. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3756. if (pf->vsi[v])
  3757. i40e_unquiesce_vsi(pf->vsi[v]);
  3758. }
  3759. }
  3760. #ifdef CONFIG_I40E_DCB
  3761. /**
  3762. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  3763. * @vsi: the VSI being configured
  3764. *
  3765. * This function waits for the given VSI's queues to be disabled.
  3766. **/
  3767. static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  3768. {
  3769. struct i40e_pf *pf = vsi->back;
  3770. int i, pf_q, ret;
  3771. pf_q = vsi->base_queue;
  3772. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3773. /* Check and wait for the disable status of the queue */
  3774. ret = i40e_pf_txq_wait(pf, pf_q, false);
  3775. if (ret) {
  3776. dev_info(&pf->pdev->dev,
  3777. "VSI seid %d Tx ring %d disable timeout\n",
  3778. vsi->seid, pf_q);
  3779. return ret;
  3780. }
  3781. }
  3782. pf_q = vsi->base_queue;
  3783. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3784. /* Check and wait for the disable status of the queue */
  3785. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  3786. if (ret) {
  3787. dev_info(&pf->pdev->dev,
  3788. "VSI seid %d Rx ring %d disable timeout\n",
  3789. vsi->seid, pf_q);
  3790. return ret;
  3791. }
  3792. }
  3793. return 0;
  3794. }
  3795. /**
  3796. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  3797. * @pf: the PF
  3798. *
  3799. * This function waits for the queues to be in disabled state for all the
  3800. * VSIs that are managed by this PF.
  3801. **/
  3802. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  3803. {
  3804. int v, ret = 0;
  3805. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3806. /* No need to wait for FCoE VSI queues */
  3807. if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
  3808. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  3809. if (ret)
  3810. break;
  3811. }
  3812. }
  3813. return ret;
  3814. }
  3815. #endif
  3816. /**
  3817. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  3818. * @q_idx: TX queue number
  3819. * @vsi: Pointer to VSI struct
  3820. *
  3821. * This function checks specified queue for given VSI. Detects hung condition.
  3822. * Sets hung bit since it is two step process. Before next run of service task
  3823. * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
  3824. * hung condition remain unchanged and during subsequent run, this function
  3825. * issues SW interrupt to recover from hung condition.
  3826. **/
  3827. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  3828. {
  3829. struct i40e_ring *tx_ring = NULL;
  3830. struct i40e_pf *pf;
  3831. u32 head, val, tx_pending_hw;
  3832. int i;
  3833. pf = vsi->back;
  3834. /* now that we have an index, find the tx_ring struct */
  3835. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3836. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  3837. if (q_idx == vsi->tx_rings[i]->queue_index) {
  3838. tx_ring = vsi->tx_rings[i];
  3839. break;
  3840. }
  3841. }
  3842. }
  3843. if (!tx_ring)
  3844. return;
  3845. /* Read interrupt register */
  3846. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3847. val = rd32(&pf->hw,
  3848. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  3849. tx_ring->vsi->base_vector - 1));
  3850. else
  3851. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  3852. head = i40e_get_head(tx_ring);
  3853. tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
  3854. /* HW is done executing descriptors, updated HEAD write back,
  3855. * but SW hasn't processed those descriptors. If interrupt is
  3856. * not generated from this point ON, it could result into
  3857. * dev_watchdog detecting timeout on those netdev_queue,
  3858. * hence proactively trigger SW interrupt.
  3859. */
  3860. if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  3861. /* NAPI Poll didn't run and clear since it was set */
  3862. if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
  3863. &tx_ring->q_vector->hung_detected)) {
  3864. netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
  3865. vsi->seid, q_idx, tx_pending_hw,
  3866. tx_ring->next_to_clean, head,
  3867. tx_ring->next_to_use,
  3868. readl(tx_ring->tail));
  3869. netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
  3870. vsi->seid, q_idx, val);
  3871. i40e_force_wb(vsi, tx_ring->q_vector);
  3872. } else {
  3873. /* First Chance - detected possible hung */
  3874. set_bit(I40E_Q_VECTOR_HUNG_DETECT,
  3875. &tx_ring->q_vector->hung_detected);
  3876. }
  3877. }
  3878. /* This is the case where we have interrupts missing,
  3879. * so the tx_pending in HW will most likely be 0, but we
  3880. * will have tx_pending in SW since the WB happened but the
  3881. * interrupt got lost.
  3882. */
  3883. if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
  3884. (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  3885. if (napi_reschedule(&tx_ring->q_vector->napi))
  3886. tx_ring->tx_stats.tx_lost_interrupt++;
  3887. }
  3888. }
  3889. /**
  3890. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  3891. * @pf: pointer to PF struct
  3892. *
  3893. * LAN VSI has netdev and netdev has TX queues. This function is to check
  3894. * each of those TX queues if they are hung, trigger recovery by issuing
  3895. * SW interrupt.
  3896. **/
  3897. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  3898. {
  3899. struct net_device *netdev;
  3900. struct i40e_vsi *vsi;
  3901. int i;
  3902. /* Only for LAN VSI */
  3903. vsi = pf->vsi[pf->lan_vsi];
  3904. if (!vsi)
  3905. return;
  3906. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  3907. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  3908. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  3909. return;
  3910. /* Make sure type is MAIN VSI */
  3911. if (vsi->type != I40E_VSI_MAIN)
  3912. return;
  3913. netdev = vsi->netdev;
  3914. if (!netdev)
  3915. return;
  3916. /* Bail out if netif_carrier is not OK */
  3917. if (!netif_carrier_ok(netdev))
  3918. return;
  3919. /* Go thru' TX queues for netdev */
  3920. for (i = 0; i < netdev->num_tx_queues; i++) {
  3921. struct netdev_queue *q;
  3922. q = netdev_get_tx_queue(netdev, i);
  3923. if (q)
  3924. i40e_detect_recover_hung_queue(i, vsi);
  3925. }
  3926. }
  3927. /**
  3928. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  3929. * @pf: pointer to PF
  3930. *
  3931. * Get TC map for ISCSI PF type that will include iSCSI TC
  3932. * and LAN TC.
  3933. **/
  3934. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  3935. {
  3936. struct i40e_dcb_app_priority_table app;
  3937. struct i40e_hw *hw = &pf->hw;
  3938. u8 enabled_tc = 1; /* TC0 is always enabled */
  3939. u8 tc, i;
  3940. /* Get the iSCSI APP TLV */
  3941. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3942. for (i = 0; i < dcbcfg->numapps; i++) {
  3943. app = dcbcfg->app[i];
  3944. if (app.selector == I40E_APP_SEL_TCPIP &&
  3945. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  3946. tc = dcbcfg->etscfg.prioritytable[app.priority];
  3947. enabled_tc |= BIT(tc);
  3948. break;
  3949. }
  3950. }
  3951. return enabled_tc;
  3952. }
  3953. /**
  3954. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  3955. * @dcbcfg: the corresponding DCBx configuration structure
  3956. *
  3957. * Return the number of TCs from given DCBx configuration
  3958. **/
  3959. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  3960. {
  3961. u8 num_tc = 0;
  3962. int i;
  3963. /* Scan the ETS Config Priority Table to find
  3964. * traffic class enabled for a given priority
  3965. * and use the traffic class index to get the
  3966. * number of traffic classes enabled
  3967. */
  3968. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3969. if (dcbcfg->etscfg.prioritytable[i] > num_tc)
  3970. num_tc = dcbcfg->etscfg.prioritytable[i];
  3971. }
  3972. /* Traffic class index starts from zero so
  3973. * increment to return the actual count
  3974. */
  3975. return num_tc + 1;
  3976. }
  3977. /**
  3978. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  3979. * @dcbcfg: the corresponding DCBx configuration structure
  3980. *
  3981. * Query the current DCB configuration and return the number of
  3982. * traffic classes enabled from the given DCBX config
  3983. **/
  3984. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  3985. {
  3986. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  3987. u8 enabled_tc = 1;
  3988. u8 i;
  3989. for (i = 0; i < num_tc; i++)
  3990. enabled_tc |= BIT(i);
  3991. return enabled_tc;
  3992. }
  3993. /**
  3994. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  3995. * @pf: PF being queried
  3996. *
  3997. * Return number of traffic classes enabled for the given PF
  3998. **/
  3999. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4000. {
  4001. struct i40e_hw *hw = &pf->hw;
  4002. u8 i, enabled_tc;
  4003. u8 num_tc = 0;
  4004. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4005. /* If DCB is not enabled then always in single TC */
  4006. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4007. return 1;
  4008. /* SFP mode will be enabled for all TCs on port */
  4009. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4010. return i40e_dcb_get_num_tc(dcbcfg);
  4011. /* MFP mode return count of enabled TCs for this PF */
  4012. if (pf->hw.func_caps.iscsi)
  4013. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4014. else
  4015. return 1; /* Only TC0 */
  4016. /* At least have TC0 */
  4017. enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  4018. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4019. if (enabled_tc & BIT(i))
  4020. num_tc++;
  4021. }
  4022. return num_tc;
  4023. }
  4024. /**
  4025. * i40e_pf_get_default_tc - Get bitmap for first enabled TC
  4026. * @pf: PF being queried
  4027. *
  4028. * Return a bitmap for first enabled traffic class for this PF.
  4029. **/
  4030. static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
  4031. {
  4032. u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
  4033. u8 i = 0;
  4034. if (!enabled_tc)
  4035. return 0x1; /* TC0 */
  4036. /* Find the first enabled TC */
  4037. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4038. if (enabled_tc & BIT(i))
  4039. break;
  4040. }
  4041. return BIT(i);
  4042. }
  4043. /**
  4044. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4045. * @pf: PF being queried
  4046. *
  4047. * Return a bitmap for enabled traffic classes for this PF.
  4048. **/
  4049. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4050. {
  4051. /* If DCB is not enabled for this PF then just return default TC */
  4052. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4053. return i40e_pf_get_default_tc(pf);
  4054. /* SFP mode we want PF to be enabled for all TCs */
  4055. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4056. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4057. /* MFP enabled and iSCSI PF type */
  4058. if (pf->hw.func_caps.iscsi)
  4059. return i40e_get_iscsi_tc_map(pf);
  4060. else
  4061. return i40e_pf_get_default_tc(pf);
  4062. }
  4063. /**
  4064. * i40e_vsi_get_bw_info - Query VSI BW Information
  4065. * @vsi: the VSI being queried
  4066. *
  4067. * Returns 0 on success, negative value on failure
  4068. **/
  4069. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4070. {
  4071. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4072. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4073. struct i40e_pf *pf = vsi->back;
  4074. struct i40e_hw *hw = &pf->hw;
  4075. i40e_status ret;
  4076. u32 tc_bw_max;
  4077. int i;
  4078. /* Get the VSI level BW configuration */
  4079. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4080. if (ret) {
  4081. dev_info(&pf->pdev->dev,
  4082. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4083. i40e_stat_str(&pf->hw, ret),
  4084. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4085. return -EINVAL;
  4086. }
  4087. /* Get the VSI level BW configuration per TC */
  4088. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4089. NULL);
  4090. if (ret) {
  4091. dev_info(&pf->pdev->dev,
  4092. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4093. i40e_stat_str(&pf->hw, ret),
  4094. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4095. return -EINVAL;
  4096. }
  4097. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4098. dev_info(&pf->pdev->dev,
  4099. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4100. bw_config.tc_valid_bits,
  4101. bw_ets_config.tc_valid_bits);
  4102. /* Still continuing */
  4103. }
  4104. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4105. vsi->bw_max_quanta = bw_config.max_bw;
  4106. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4107. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4108. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4109. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4110. vsi->bw_ets_limit_credits[i] =
  4111. le16_to_cpu(bw_ets_config.credits[i]);
  4112. /* 3 bits out of 4 for each TC */
  4113. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4114. }
  4115. return 0;
  4116. }
  4117. /**
  4118. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4119. * @vsi: the VSI being configured
  4120. * @enabled_tc: TC bitmap
  4121. * @bw_credits: BW shared credits per TC
  4122. *
  4123. * Returns 0 on success, negative value on failure
  4124. **/
  4125. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4126. u8 *bw_share)
  4127. {
  4128. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4129. i40e_status ret;
  4130. int i;
  4131. bw_data.tc_valid_bits = enabled_tc;
  4132. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4133. bw_data.tc_bw_credits[i] = bw_share[i];
  4134. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4135. NULL);
  4136. if (ret) {
  4137. dev_info(&vsi->back->pdev->dev,
  4138. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4139. vsi->back->hw.aq.asq_last_status);
  4140. return -EINVAL;
  4141. }
  4142. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4143. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4144. return 0;
  4145. }
  4146. /**
  4147. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4148. * @vsi: the VSI being configured
  4149. * @enabled_tc: TC map to be enabled
  4150. *
  4151. **/
  4152. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4153. {
  4154. struct net_device *netdev = vsi->netdev;
  4155. struct i40e_pf *pf = vsi->back;
  4156. struct i40e_hw *hw = &pf->hw;
  4157. u8 netdev_tc = 0;
  4158. int i;
  4159. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4160. if (!netdev)
  4161. return;
  4162. if (!enabled_tc) {
  4163. netdev_reset_tc(netdev);
  4164. return;
  4165. }
  4166. /* Set up actual enabled TCs on the VSI */
  4167. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4168. return;
  4169. /* set per TC queues for the VSI */
  4170. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4171. /* Only set TC queues for enabled tcs
  4172. *
  4173. * e.g. For a VSI that has TC0 and TC3 enabled the
  4174. * enabled_tc bitmap would be 0x00001001; the driver
  4175. * will set the numtc for netdev as 2 that will be
  4176. * referenced by the netdev layer as TC 0 and 1.
  4177. */
  4178. if (vsi->tc_config.enabled_tc & BIT(i))
  4179. netdev_set_tc_queue(netdev,
  4180. vsi->tc_config.tc_info[i].netdev_tc,
  4181. vsi->tc_config.tc_info[i].qcount,
  4182. vsi->tc_config.tc_info[i].qoffset);
  4183. }
  4184. /* Assign UP2TC map for the VSI */
  4185. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4186. /* Get the actual TC# for the UP */
  4187. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4188. /* Get the mapped netdev TC# for the UP */
  4189. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4190. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4191. }
  4192. }
  4193. /**
  4194. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4195. * @vsi: the VSI being configured
  4196. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4197. **/
  4198. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4199. struct i40e_vsi_context *ctxt)
  4200. {
  4201. /* copy just the sections touched not the entire info
  4202. * since not all sections are valid as returned by
  4203. * update vsi params
  4204. */
  4205. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4206. memcpy(&vsi->info.queue_mapping,
  4207. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4208. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4209. sizeof(vsi->info.tc_mapping));
  4210. }
  4211. /**
  4212. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4213. * @vsi: VSI to be configured
  4214. * @enabled_tc: TC bitmap
  4215. *
  4216. * This configures a particular VSI for TCs that are mapped to the
  4217. * given TC bitmap. It uses default bandwidth share for TCs across
  4218. * VSIs to configure TC for a particular VSI.
  4219. *
  4220. * NOTE:
  4221. * It is expected that the VSI queues have been quisced before calling
  4222. * this function.
  4223. **/
  4224. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4225. {
  4226. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4227. struct i40e_vsi_context ctxt;
  4228. int ret = 0;
  4229. int i;
  4230. /* Check if enabled_tc is same as existing or new TCs */
  4231. if (vsi->tc_config.enabled_tc == enabled_tc)
  4232. return ret;
  4233. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4234. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4235. if (enabled_tc & BIT(i))
  4236. bw_share[i] = 1;
  4237. }
  4238. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4239. if (ret) {
  4240. dev_info(&vsi->back->pdev->dev,
  4241. "Failed configuring TC map %d for VSI %d\n",
  4242. enabled_tc, vsi->seid);
  4243. goto out;
  4244. }
  4245. /* Update Queue Pairs Mapping for currently enabled UPs */
  4246. ctxt.seid = vsi->seid;
  4247. ctxt.pf_num = vsi->back->hw.pf_id;
  4248. ctxt.vf_num = 0;
  4249. ctxt.uplink_seid = vsi->uplink_seid;
  4250. ctxt.info = vsi->info;
  4251. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4252. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4253. ctxt.info.valid_sections |=
  4254. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4255. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4256. }
  4257. /* Update the VSI after updating the VSI queue-mapping information */
  4258. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4259. if (ret) {
  4260. dev_info(&vsi->back->pdev->dev,
  4261. "Update vsi tc config failed, err %s aq_err %s\n",
  4262. i40e_stat_str(&vsi->back->hw, ret),
  4263. i40e_aq_str(&vsi->back->hw,
  4264. vsi->back->hw.aq.asq_last_status));
  4265. goto out;
  4266. }
  4267. /* update the local VSI info with updated queue map */
  4268. i40e_vsi_update_queue_map(vsi, &ctxt);
  4269. vsi->info.valid_sections = 0;
  4270. /* Update current VSI BW information */
  4271. ret = i40e_vsi_get_bw_info(vsi);
  4272. if (ret) {
  4273. dev_info(&vsi->back->pdev->dev,
  4274. "Failed updating vsi bw info, err %s aq_err %s\n",
  4275. i40e_stat_str(&vsi->back->hw, ret),
  4276. i40e_aq_str(&vsi->back->hw,
  4277. vsi->back->hw.aq.asq_last_status));
  4278. goto out;
  4279. }
  4280. /* Update the netdev TC setup */
  4281. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4282. out:
  4283. return ret;
  4284. }
  4285. /**
  4286. * i40e_veb_config_tc - Configure TCs for given VEB
  4287. * @veb: given VEB
  4288. * @enabled_tc: TC bitmap
  4289. *
  4290. * Configures given TC bitmap for VEB (switching) element
  4291. **/
  4292. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  4293. {
  4294. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  4295. struct i40e_pf *pf = veb->pf;
  4296. int ret = 0;
  4297. int i;
  4298. /* No TCs or already enabled TCs just return */
  4299. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  4300. return ret;
  4301. bw_data.tc_valid_bits = enabled_tc;
  4302. /* bw_data.absolute_credits is not set (relative) */
  4303. /* Enable ETS TCs with equal BW Share for now */
  4304. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4305. if (enabled_tc & BIT(i))
  4306. bw_data.tc_bw_share_credits[i] = 1;
  4307. }
  4308. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  4309. &bw_data, NULL);
  4310. if (ret) {
  4311. dev_info(&pf->pdev->dev,
  4312. "VEB bw config failed, err %s aq_err %s\n",
  4313. i40e_stat_str(&pf->hw, ret),
  4314. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4315. goto out;
  4316. }
  4317. /* Update the BW information */
  4318. ret = i40e_veb_get_bw_info(veb);
  4319. if (ret) {
  4320. dev_info(&pf->pdev->dev,
  4321. "Failed getting veb bw config, err %s aq_err %s\n",
  4322. i40e_stat_str(&pf->hw, ret),
  4323. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4324. }
  4325. out:
  4326. return ret;
  4327. }
  4328. #ifdef CONFIG_I40E_DCB
  4329. /**
  4330. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  4331. * @pf: PF struct
  4332. *
  4333. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  4334. * the caller would've quiesce all the VSIs before calling
  4335. * this function
  4336. **/
  4337. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  4338. {
  4339. u8 tc_map = 0;
  4340. int ret;
  4341. u8 v;
  4342. /* Enable the TCs available on PF to all VEBs */
  4343. tc_map = i40e_pf_get_tc_map(pf);
  4344. for (v = 0; v < I40E_MAX_VEB; v++) {
  4345. if (!pf->veb[v])
  4346. continue;
  4347. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  4348. if (ret) {
  4349. dev_info(&pf->pdev->dev,
  4350. "Failed configuring TC for VEB seid=%d\n",
  4351. pf->veb[v]->seid);
  4352. /* Will try to configure as many components */
  4353. }
  4354. }
  4355. /* Update each VSI */
  4356. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4357. if (!pf->vsi[v])
  4358. continue;
  4359. /* - Enable all TCs for the LAN VSI
  4360. #ifdef I40E_FCOE
  4361. * - For FCoE VSI only enable the TC configured
  4362. * as per the APP TLV
  4363. #endif
  4364. * - For all others keep them at TC0 for now
  4365. */
  4366. if (v == pf->lan_vsi)
  4367. tc_map = i40e_pf_get_tc_map(pf);
  4368. else
  4369. tc_map = i40e_pf_get_default_tc(pf);
  4370. #ifdef I40E_FCOE
  4371. if (pf->vsi[v]->type == I40E_VSI_FCOE)
  4372. tc_map = i40e_get_fcoe_tc_map(pf);
  4373. #endif /* #ifdef I40E_FCOE */
  4374. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  4375. if (ret) {
  4376. dev_info(&pf->pdev->dev,
  4377. "Failed configuring TC for VSI seid=%d\n",
  4378. pf->vsi[v]->seid);
  4379. /* Will try to configure as many components */
  4380. } else {
  4381. /* Re-configure VSI vectors based on updated TC map */
  4382. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  4383. if (pf->vsi[v]->netdev)
  4384. i40e_dcbnl_set_all(pf->vsi[v]);
  4385. }
  4386. i40e_notify_client_of_l2_param_changes(pf->vsi[v]);
  4387. }
  4388. }
  4389. /**
  4390. * i40e_resume_port_tx - Resume port Tx
  4391. * @pf: PF struct
  4392. *
  4393. * Resume a port's Tx and issue a PF reset in case of failure to
  4394. * resume.
  4395. **/
  4396. static int i40e_resume_port_tx(struct i40e_pf *pf)
  4397. {
  4398. struct i40e_hw *hw = &pf->hw;
  4399. int ret;
  4400. ret = i40e_aq_resume_port_tx(hw, NULL);
  4401. if (ret) {
  4402. dev_info(&pf->pdev->dev,
  4403. "Resume Port Tx failed, err %s aq_err %s\n",
  4404. i40e_stat_str(&pf->hw, ret),
  4405. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4406. /* Schedule PF reset to recover */
  4407. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4408. i40e_service_event_schedule(pf);
  4409. }
  4410. return ret;
  4411. }
  4412. /**
  4413. * i40e_init_pf_dcb - Initialize DCB configuration
  4414. * @pf: PF being configured
  4415. *
  4416. * Query the current DCB configuration and cache it
  4417. * in the hardware structure
  4418. **/
  4419. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  4420. {
  4421. struct i40e_hw *hw = &pf->hw;
  4422. int err = 0;
  4423. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  4424. if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
  4425. goto out;
  4426. /* Get the initial DCB configuration */
  4427. err = i40e_init_dcb(hw);
  4428. if (!err) {
  4429. /* Device/Function is not DCBX capable */
  4430. if ((!hw->func_caps.dcb) ||
  4431. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  4432. dev_info(&pf->pdev->dev,
  4433. "DCBX offload is not supported or is disabled for this PF.\n");
  4434. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  4435. goto out;
  4436. } else {
  4437. /* When status is not DISABLED then DCBX in FW */
  4438. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  4439. DCB_CAP_DCBX_VER_IEEE;
  4440. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  4441. /* Enable DCB tagging only when more than one TC */
  4442. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  4443. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4444. dev_dbg(&pf->pdev->dev,
  4445. "DCBX offload is supported for this PF.\n");
  4446. }
  4447. } else {
  4448. dev_info(&pf->pdev->dev,
  4449. "Query for DCB configuration failed, err %s aq_err %s\n",
  4450. i40e_stat_str(&pf->hw, err),
  4451. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4452. }
  4453. out:
  4454. return err;
  4455. }
  4456. #endif /* CONFIG_I40E_DCB */
  4457. #define SPEED_SIZE 14
  4458. #define FC_SIZE 8
  4459. /**
  4460. * i40e_print_link_message - print link up or down
  4461. * @vsi: the VSI for which link needs a message
  4462. */
  4463. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  4464. {
  4465. char *speed = "Unknown";
  4466. char *fc = "Unknown";
  4467. if (vsi->current_isup == isup)
  4468. return;
  4469. vsi->current_isup = isup;
  4470. if (!isup) {
  4471. netdev_info(vsi->netdev, "NIC Link is Down\n");
  4472. return;
  4473. }
  4474. /* Warn user if link speed on NPAR enabled partition is not at
  4475. * least 10GB
  4476. */
  4477. if (vsi->back->hw.func_caps.npar_enable &&
  4478. (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  4479. vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  4480. netdev_warn(vsi->netdev,
  4481. "The partition detected link speed that is less than 10Gbps\n");
  4482. switch (vsi->back->hw.phy.link_info.link_speed) {
  4483. case I40E_LINK_SPEED_40GB:
  4484. speed = "40 G";
  4485. break;
  4486. case I40E_LINK_SPEED_20GB:
  4487. speed = "20 G";
  4488. break;
  4489. case I40E_LINK_SPEED_10GB:
  4490. speed = "10 G";
  4491. break;
  4492. case I40E_LINK_SPEED_1GB:
  4493. speed = "1000 M";
  4494. break;
  4495. case I40E_LINK_SPEED_100MB:
  4496. speed = "100 M";
  4497. break;
  4498. default:
  4499. break;
  4500. }
  4501. switch (vsi->back->hw.fc.current_mode) {
  4502. case I40E_FC_FULL:
  4503. fc = "RX/TX";
  4504. break;
  4505. case I40E_FC_TX_PAUSE:
  4506. fc = "TX";
  4507. break;
  4508. case I40E_FC_RX_PAUSE:
  4509. fc = "RX";
  4510. break;
  4511. default:
  4512. fc = "None";
  4513. break;
  4514. }
  4515. netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
  4516. speed, fc);
  4517. }
  4518. /**
  4519. * i40e_up_complete - Finish the last steps of bringing up a connection
  4520. * @vsi: the VSI being configured
  4521. **/
  4522. static int i40e_up_complete(struct i40e_vsi *vsi)
  4523. {
  4524. struct i40e_pf *pf = vsi->back;
  4525. int err;
  4526. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4527. i40e_vsi_configure_msix(vsi);
  4528. else
  4529. i40e_configure_msi_and_legacy(vsi);
  4530. /* start rings */
  4531. err = i40e_vsi_control_rings(vsi, true);
  4532. if (err)
  4533. return err;
  4534. clear_bit(__I40E_DOWN, &vsi->state);
  4535. i40e_napi_enable_all(vsi);
  4536. i40e_vsi_enable_irq(vsi);
  4537. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  4538. (vsi->netdev)) {
  4539. i40e_print_link_message(vsi, true);
  4540. netif_tx_start_all_queues(vsi->netdev);
  4541. netif_carrier_on(vsi->netdev);
  4542. } else if (vsi->netdev) {
  4543. i40e_print_link_message(vsi, false);
  4544. /* need to check for qualified module here*/
  4545. if ((pf->hw.phy.link_info.link_info &
  4546. I40E_AQ_MEDIA_AVAILABLE) &&
  4547. (!(pf->hw.phy.link_info.an_info &
  4548. I40E_AQ_QUALIFIED_MODULE)))
  4549. netdev_err(vsi->netdev,
  4550. "the driver failed to link because an unqualified module was detected.");
  4551. }
  4552. /* replay FDIR SB filters */
  4553. if (vsi->type == I40E_VSI_FDIR) {
  4554. /* reset fd counters */
  4555. pf->fd_add_err = pf->fd_atr_cnt = 0;
  4556. if (pf->fd_tcp_rule > 0) {
  4557. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  4558. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  4559. dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
  4560. pf->fd_tcp_rule = 0;
  4561. }
  4562. i40e_fdir_filter_restore(vsi);
  4563. }
  4564. /* On the next run of the service_task, notify any clients of the new
  4565. * opened netdev
  4566. */
  4567. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4568. i40e_service_event_schedule(pf);
  4569. return 0;
  4570. }
  4571. /**
  4572. * i40e_vsi_reinit_locked - Reset the VSI
  4573. * @vsi: the VSI being configured
  4574. *
  4575. * Rebuild the ring structs after some configuration
  4576. * has changed, e.g. MTU size.
  4577. **/
  4578. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  4579. {
  4580. struct i40e_pf *pf = vsi->back;
  4581. WARN_ON(in_interrupt());
  4582. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  4583. usleep_range(1000, 2000);
  4584. i40e_down(vsi);
  4585. /* Give a VF some time to respond to the reset. The
  4586. * two second wait is based upon the watchdog cycle in
  4587. * the VF driver.
  4588. */
  4589. if (vsi->type == I40E_VSI_SRIOV)
  4590. msleep(2000);
  4591. i40e_up(vsi);
  4592. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  4593. }
  4594. /**
  4595. * i40e_up - Bring the connection back up after being down
  4596. * @vsi: the VSI being configured
  4597. **/
  4598. int i40e_up(struct i40e_vsi *vsi)
  4599. {
  4600. int err;
  4601. err = i40e_vsi_configure(vsi);
  4602. if (!err)
  4603. err = i40e_up_complete(vsi);
  4604. return err;
  4605. }
  4606. /**
  4607. * i40e_down - Shutdown the connection processing
  4608. * @vsi: the VSI being stopped
  4609. **/
  4610. void i40e_down(struct i40e_vsi *vsi)
  4611. {
  4612. int i;
  4613. /* It is assumed that the caller of this function
  4614. * sets the vsi->state __I40E_DOWN bit.
  4615. */
  4616. if (vsi->netdev) {
  4617. netif_carrier_off(vsi->netdev);
  4618. netif_tx_disable(vsi->netdev);
  4619. }
  4620. i40e_vsi_disable_irq(vsi);
  4621. i40e_vsi_control_rings(vsi, false);
  4622. i40e_napi_disable_all(vsi);
  4623. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4624. i40e_clean_tx_ring(vsi->tx_rings[i]);
  4625. i40e_clean_rx_ring(vsi->rx_rings[i]);
  4626. }
  4627. }
  4628. /**
  4629. * i40e_setup_tc - configure multiple traffic classes
  4630. * @netdev: net device to configure
  4631. * @tc: number of traffic classes to enable
  4632. **/
  4633. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4634. {
  4635. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4636. struct i40e_vsi *vsi = np->vsi;
  4637. struct i40e_pf *pf = vsi->back;
  4638. u8 enabled_tc = 0;
  4639. int ret = -EINVAL;
  4640. int i;
  4641. /* Check if DCB enabled to continue */
  4642. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4643. netdev_info(netdev, "DCB is not enabled for adapter\n");
  4644. goto exit;
  4645. }
  4646. /* Check if MFP enabled */
  4647. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  4648. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  4649. goto exit;
  4650. }
  4651. /* Check whether tc count is within enabled limit */
  4652. if (tc > i40e_pf_get_num_tc(pf)) {
  4653. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  4654. goto exit;
  4655. }
  4656. /* Generate TC map for number of tc requested */
  4657. for (i = 0; i < tc; i++)
  4658. enabled_tc |= BIT(i);
  4659. /* Requesting same TC configuration as already enabled */
  4660. if (enabled_tc == vsi->tc_config.enabled_tc)
  4661. return 0;
  4662. /* Quiesce VSI queues */
  4663. i40e_quiesce_vsi(vsi);
  4664. /* Configure VSI for enabled TCs */
  4665. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  4666. if (ret) {
  4667. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  4668. vsi->seid);
  4669. goto exit;
  4670. }
  4671. /* Unquiesce VSI */
  4672. i40e_unquiesce_vsi(vsi);
  4673. exit:
  4674. return ret;
  4675. }
  4676. #ifdef I40E_FCOE
  4677. int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4678. struct tc_to_netdev *tc)
  4679. #else
  4680. static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4681. struct tc_to_netdev *tc)
  4682. #endif
  4683. {
  4684. if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
  4685. return -EINVAL;
  4686. return i40e_setup_tc(netdev, tc->tc);
  4687. }
  4688. /**
  4689. * i40e_open - Called when a network interface is made active
  4690. * @netdev: network interface device structure
  4691. *
  4692. * The open entry point is called when a network interface is made
  4693. * active by the system (IFF_UP). At this point all resources needed
  4694. * for transmit and receive operations are allocated, the interrupt
  4695. * handler is registered with the OS, the netdev watchdog subtask is
  4696. * enabled, and the stack is notified that the interface is ready.
  4697. *
  4698. * Returns 0 on success, negative value on failure
  4699. **/
  4700. int i40e_open(struct net_device *netdev)
  4701. {
  4702. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4703. struct i40e_vsi *vsi = np->vsi;
  4704. struct i40e_pf *pf = vsi->back;
  4705. int err;
  4706. /* disallow open during test or if eeprom is broken */
  4707. if (test_bit(__I40E_TESTING, &pf->state) ||
  4708. test_bit(__I40E_BAD_EEPROM, &pf->state))
  4709. return -EBUSY;
  4710. netif_carrier_off(netdev);
  4711. err = i40e_vsi_open(vsi);
  4712. if (err)
  4713. return err;
  4714. /* configure global TSO hardware offload settings */
  4715. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  4716. TCP_FLAG_FIN) >> 16);
  4717. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  4718. TCP_FLAG_FIN |
  4719. TCP_FLAG_CWR) >> 16);
  4720. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  4721. #ifdef CONFIG_I40E_VXLAN
  4722. vxlan_get_rx_port(netdev);
  4723. #endif
  4724. #ifdef CONFIG_I40E_GENEVE
  4725. if (pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)
  4726. geneve_get_rx_port(netdev);
  4727. #endif
  4728. i40e_notify_client_of_netdev_open(vsi);
  4729. return 0;
  4730. }
  4731. /**
  4732. * i40e_vsi_open -
  4733. * @vsi: the VSI to open
  4734. *
  4735. * Finish initialization of the VSI.
  4736. *
  4737. * Returns 0 on success, negative value on failure
  4738. **/
  4739. int i40e_vsi_open(struct i40e_vsi *vsi)
  4740. {
  4741. struct i40e_pf *pf = vsi->back;
  4742. char int_name[I40E_INT_NAME_STR_LEN];
  4743. int err;
  4744. /* allocate descriptors */
  4745. err = i40e_vsi_setup_tx_resources(vsi);
  4746. if (err)
  4747. goto err_setup_tx;
  4748. err = i40e_vsi_setup_rx_resources(vsi);
  4749. if (err)
  4750. goto err_setup_rx;
  4751. err = i40e_vsi_configure(vsi);
  4752. if (err)
  4753. goto err_setup_rx;
  4754. if (vsi->netdev) {
  4755. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  4756. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  4757. err = i40e_vsi_request_irq(vsi, int_name);
  4758. if (err)
  4759. goto err_setup_rx;
  4760. /* Notify the stack of the actual queue counts. */
  4761. err = netif_set_real_num_tx_queues(vsi->netdev,
  4762. vsi->num_queue_pairs);
  4763. if (err)
  4764. goto err_set_queues;
  4765. err = netif_set_real_num_rx_queues(vsi->netdev,
  4766. vsi->num_queue_pairs);
  4767. if (err)
  4768. goto err_set_queues;
  4769. } else if (vsi->type == I40E_VSI_FDIR) {
  4770. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  4771. dev_driver_string(&pf->pdev->dev),
  4772. dev_name(&pf->pdev->dev));
  4773. err = i40e_vsi_request_irq(vsi, int_name);
  4774. } else {
  4775. err = -EINVAL;
  4776. goto err_setup_rx;
  4777. }
  4778. err = i40e_up_complete(vsi);
  4779. if (err)
  4780. goto err_up_complete;
  4781. return 0;
  4782. err_up_complete:
  4783. i40e_down(vsi);
  4784. err_set_queues:
  4785. i40e_vsi_free_irq(vsi);
  4786. err_setup_rx:
  4787. i40e_vsi_free_rx_resources(vsi);
  4788. err_setup_tx:
  4789. i40e_vsi_free_tx_resources(vsi);
  4790. if (vsi == pf->vsi[pf->lan_vsi])
  4791. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  4792. return err;
  4793. }
  4794. /**
  4795. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  4796. * @pf: Pointer to PF
  4797. *
  4798. * This function destroys the hlist where all the Flow Director
  4799. * filters were saved.
  4800. **/
  4801. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  4802. {
  4803. struct i40e_fdir_filter *filter;
  4804. struct hlist_node *node2;
  4805. hlist_for_each_entry_safe(filter, node2,
  4806. &pf->fdir_filter_list, fdir_node) {
  4807. hlist_del(&filter->fdir_node);
  4808. kfree(filter);
  4809. }
  4810. pf->fdir_pf_active_filters = 0;
  4811. }
  4812. /**
  4813. * i40e_close - Disables a network interface
  4814. * @netdev: network interface device structure
  4815. *
  4816. * The close entry point is called when an interface is de-activated
  4817. * by the OS. The hardware is still under the driver's control, but
  4818. * this netdev interface is disabled.
  4819. *
  4820. * Returns 0, this is not allowed to fail
  4821. **/
  4822. int i40e_close(struct net_device *netdev)
  4823. {
  4824. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4825. struct i40e_vsi *vsi = np->vsi;
  4826. i40e_vsi_close(vsi);
  4827. return 0;
  4828. }
  4829. /**
  4830. * i40e_do_reset - Start a PF or Core Reset sequence
  4831. * @pf: board private structure
  4832. * @reset_flags: which reset is requested
  4833. *
  4834. * The essential difference in resets is that the PF Reset
  4835. * doesn't clear the packet buffers, doesn't reset the PE
  4836. * firmware, and doesn't bother the other PFs on the chip.
  4837. **/
  4838. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  4839. {
  4840. u32 val;
  4841. WARN_ON(in_interrupt());
  4842. /* do the biggest reset indicated */
  4843. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  4844. /* Request a Global Reset
  4845. *
  4846. * This will start the chip's countdown to the actual full
  4847. * chip reset event, and a warning interrupt to be sent
  4848. * to all PFs, including the requestor. Our handler
  4849. * for the warning interrupt will deal with the shutdown
  4850. * and recovery of the switch setup.
  4851. */
  4852. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  4853. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4854. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  4855. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4856. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  4857. /* Request a Core Reset
  4858. *
  4859. * Same as Global Reset, except does *not* include the MAC/PHY
  4860. */
  4861. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  4862. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4863. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  4864. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4865. i40e_flush(&pf->hw);
  4866. } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
  4867. /* Request a PF Reset
  4868. *
  4869. * Resets only the PF-specific registers
  4870. *
  4871. * This goes directly to the tear-down and rebuild of
  4872. * the switch, since we need to do all the recovery as
  4873. * for the Core Reset.
  4874. */
  4875. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  4876. i40e_handle_reset_warning(pf);
  4877. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  4878. int v;
  4879. /* Find the VSI(s) that requested a re-init */
  4880. dev_info(&pf->pdev->dev,
  4881. "VSI reinit requested\n");
  4882. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4883. struct i40e_vsi *vsi = pf->vsi[v];
  4884. if (vsi != NULL &&
  4885. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  4886. i40e_vsi_reinit_locked(pf->vsi[v]);
  4887. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  4888. }
  4889. }
  4890. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  4891. int v;
  4892. /* Find the VSI(s) that needs to be brought down */
  4893. dev_info(&pf->pdev->dev, "VSI down requested\n");
  4894. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4895. struct i40e_vsi *vsi = pf->vsi[v];
  4896. if (vsi != NULL &&
  4897. test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
  4898. set_bit(__I40E_DOWN, &vsi->state);
  4899. i40e_down(vsi);
  4900. clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  4901. }
  4902. }
  4903. } else {
  4904. dev_info(&pf->pdev->dev,
  4905. "bad reset request 0x%08x\n", reset_flags);
  4906. }
  4907. }
  4908. #ifdef CONFIG_I40E_DCB
  4909. /**
  4910. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  4911. * @pf: board private structure
  4912. * @old_cfg: current DCB config
  4913. * @new_cfg: new DCB config
  4914. **/
  4915. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  4916. struct i40e_dcbx_config *old_cfg,
  4917. struct i40e_dcbx_config *new_cfg)
  4918. {
  4919. bool need_reconfig = false;
  4920. /* Check if ETS configuration has changed */
  4921. if (memcmp(&new_cfg->etscfg,
  4922. &old_cfg->etscfg,
  4923. sizeof(new_cfg->etscfg))) {
  4924. /* If Priority Table has changed reconfig is needed */
  4925. if (memcmp(&new_cfg->etscfg.prioritytable,
  4926. &old_cfg->etscfg.prioritytable,
  4927. sizeof(new_cfg->etscfg.prioritytable))) {
  4928. need_reconfig = true;
  4929. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  4930. }
  4931. if (memcmp(&new_cfg->etscfg.tcbwtable,
  4932. &old_cfg->etscfg.tcbwtable,
  4933. sizeof(new_cfg->etscfg.tcbwtable)))
  4934. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  4935. if (memcmp(&new_cfg->etscfg.tsatable,
  4936. &old_cfg->etscfg.tsatable,
  4937. sizeof(new_cfg->etscfg.tsatable)))
  4938. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  4939. }
  4940. /* Check if PFC configuration has changed */
  4941. if (memcmp(&new_cfg->pfc,
  4942. &old_cfg->pfc,
  4943. sizeof(new_cfg->pfc))) {
  4944. need_reconfig = true;
  4945. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  4946. }
  4947. /* Check if APP Table has changed */
  4948. if (memcmp(&new_cfg->app,
  4949. &old_cfg->app,
  4950. sizeof(new_cfg->app))) {
  4951. need_reconfig = true;
  4952. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  4953. }
  4954. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  4955. return need_reconfig;
  4956. }
  4957. /**
  4958. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  4959. * @pf: board private structure
  4960. * @e: event info posted on ARQ
  4961. **/
  4962. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  4963. struct i40e_arq_event_info *e)
  4964. {
  4965. struct i40e_aqc_lldp_get_mib *mib =
  4966. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  4967. struct i40e_hw *hw = &pf->hw;
  4968. struct i40e_dcbx_config tmp_dcbx_cfg;
  4969. bool need_reconfig = false;
  4970. int ret = 0;
  4971. u8 type;
  4972. /* Not DCB capable or capability disabled */
  4973. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  4974. return ret;
  4975. /* Ignore if event is not for Nearest Bridge */
  4976. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  4977. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  4978. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  4979. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  4980. return ret;
  4981. /* Check MIB Type and return if event for Remote MIB update */
  4982. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  4983. dev_dbg(&pf->pdev->dev,
  4984. "LLDP event mib type %s\n", type ? "remote" : "local");
  4985. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  4986. /* Update the remote cached instance and return */
  4987. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  4988. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  4989. &hw->remote_dcbx_config);
  4990. goto exit;
  4991. }
  4992. /* Store the old configuration */
  4993. tmp_dcbx_cfg = hw->local_dcbx_config;
  4994. /* Reset the old DCBx configuration data */
  4995. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  4996. /* Get updated DCBX data from firmware */
  4997. ret = i40e_get_dcb_config(&pf->hw);
  4998. if (ret) {
  4999. dev_info(&pf->pdev->dev,
  5000. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  5001. i40e_stat_str(&pf->hw, ret),
  5002. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5003. goto exit;
  5004. }
  5005. /* No change detected in DCBX configs */
  5006. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  5007. sizeof(tmp_dcbx_cfg))) {
  5008. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  5009. goto exit;
  5010. }
  5011. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  5012. &hw->local_dcbx_config);
  5013. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  5014. if (!need_reconfig)
  5015. goto exit;
  5016. /* Enable DCB tagging only when more than one TC */
  5017. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5018. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5019. else
  5020. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5021. set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5022. /* Reconfiguration needed quiesce all VSIs */
  5023. i40e_pf_quiesce_all_vsi(pf);
  5024. /* Changes in configuration update VEB/VSI */
  5025. i40e_dcb_reconfigure(pf);
  5026. ret = i40e_resume_port_tx(pf);
  5027. clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5028. /* In case of error no point in resuming VSIs */
  5029. if (ret)
  5030. goto exit;
  5031. /* Wait for the PF's queues to be disabled */
  5032. ret = i40e_pf_wait_queues_disabled(pf);
  5033. if (ret) {
  5034. /* Schedule PF reset to recover */
  5035. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5036. i40e_service_event_schedule(pf);
  5037. } else {
  5038. i40e_pf_unquiesce_all_vsi(pf);
  5039. }
  5040. exit:
  5041. return ret;
  5042. }
  5043. #endif /* CONFIG_I40E_DCB */
  5044. /**
  5045. * i40e_do_reset_safe - Protected reset path for userland calls.
  5046. * @pf: board private structure
  5047. * @reset_flags: which reset is requested
  5048. *
  5049. **/
  5050. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  5051. {
  5052. rtnl_lock();
  5053. i40e_do_reset(pf, reset_flags);
  5054. rtnl_unlock();
  5055. }
  5056. /**
  5057. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  5058. * @pf: board private structure
  5059. * @e: event info posted on ARQ
  5060. *
  5061. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  5062. * and VF queues
  5063. **/
  5064. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  5065. struct i40e_arq_event_info *e)
  5066. {
  5067. struct i40e_aqc_lan_overflow *data =
  5068. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  5069. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  5070. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  5071. struct i40e_hw *hw = &pf->hw;
  5072. struct i40e_vf *vf;
  5073. u16 vf_id;
  5074. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  5075. queue, qtx_ctl);
  5076. /* Queue belongs to VF, find the VF and issue VF reset */
  5077. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  5078. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  5079. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  5080. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  5081. vf_id -= hw->func_caps.vf_base_id;
  5082. vf = &pf->vf[vf_id];
  5083. i40e_vc_notify_vf_reset(vf);
  5084. /* Allow VF to process pending reset notification */
  5085. msleep(20);
  5086. i40e_reset_vf(vf, false);
  5087. }
  5088. }
  5089. /**
  5090. * i40e_service_event_complete - Finish up the service event
  5091. * @pf: board private structure
  5092. **/
  5093. static void i40e_service_event_complete(struct i40e_pf *pf)
  5094. {
  5095. WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
  5096. /* flush memory to make sure state is correct before next watchog */
  5097. smp_mb__before_atomic();
  5098. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  5099. }
  5100. /**
  5101. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  5102. * @pf: board private structure
  5103. **/
  5104. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  5105. {
  5106. u32 val, fcnt_prog;
  5107. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5108. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  5109. return fcnt_prog;
  5110. }
  5111. /**
  5112. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  5113. * @pf: board private structure
  5114. **/
  5115. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  5116. {
  5117. u32 val, fcnt_prog;
  5118. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5119. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  5120. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  5121. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  5122. return fcnt_prog;
  5123. }
  5124. /**
  5125. * i40e_get_global_fd_count - Get total FD filters programmed on device
  5126. * @pf: board private structure
  5127. **/
  5128. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  5129. {
  5130. u32 val, fcnt_prog;
  5131. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  5132. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  5133. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  5134. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  5135. return fcnt_prog;
  5136. }
  5137. /**
  5138. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  5139. * @pf: board private structure
  5140. **/
  5141. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  5142. {
  5143. struct i40e_fdir_filter *filter;
  5144. u32 fcnt_prog, fcnt_avail;
  5145. struct hlist_node *node;
  5146. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5147. return;
  5148. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  5149. * to re-enable
  5150. */
  5151. fcnt_prog = i40e_get_global_fd_count(pf);
  5152. fcnt_avail = pf->fdir_pf_filter_count;
  5153. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  5154. (pf->fd_add_err == 0) ||
  5155. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  5156. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  5157. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  5158. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5159. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5160. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  5161. }
  5162. }
  5163. /* Wait for some more space to be available to turn on ATR */
  5164. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  5165. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5166. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  5167. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5168. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5169. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
  5170. }
  5171. }
  5172. /* if hw had a problem adding a filter, delete it */
  5173. if (pf->fd_inv > 0) {
  5174. hlist_for_each_entry_safe(filter, node,
  5175. &pf->fdir_filter_list, fdir_node) {
  5176. if (filter->fd_id == pf->fd_inv) {
  5177. hlist_del(&filter->fdir_node);
  5178. kfree(filter);
  5179. pf->fdir_pf_active_filters--;
  5180. }
  5181. }
  5182. }
  5183. }
  5184. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  5185. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  5186. /**
  5187. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  5188. * @pf: board private structure
  5189. **/
  5190. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  5191. {
  5192. unsigned long min_flush_time;
  5193. int flush_wait_retry = 50;
  5194. bool disable_atr = false;
  5195. int fd_room;
  5196. int reg;
  5197. if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
  5198. return;
  5199. if (!time_after(jiffies, pf->fd_flush_timestamp +
  5200. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  5201. return;
  5202. /* If the flush is happening too quick and we have mostly SB rules we
  5203. * should not re-enable ATR for some time.
  5204. */
  5205. min_flush_time = pf->fd_flush_timestamp +
  5206. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  5207. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  5208. if (!(time_after(jiffies, min_flush_time)) &&
  5209. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  5210. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5211. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  5212. disable_atr = true;
  5213. }
  5214. pf->fd_flush_timestamp = jiffies;
  5215. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5216. /* flush all filters */
  5217. wr32(&pf->hw, I40E_PFQF_CTL_1,
  5218. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  5219. i40e_flush(&pf->hw);
  5220. pf->fd_flush_cnt++;
  5221. pf->fd_add_err = 0;
  5222. do {
  5223. /* Check FD flush status every 5-6msec */
  5224. usleep_range(5000, 6000);
  5225. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  5226. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  5227. break;
  5228. } while (flush_wait_retry--);
  5229. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  5230. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  5231. } else {
  5232. /* replay sideband filters */
  5233. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  5234. if (!disable_atr)
  5235. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  5236. clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  5237. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5238. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  5239. }
  5240. }
  5241. /**
  5242. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  5243. * @pf: board private structure
  5244. **/
  5245. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  5246. {
  5247. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  5248. }
  5249. /* We can see up to 256 filter programming desc in transit if the filters are
  5250. * being applied really fast; before we see the first
  5251. * filter miss error on Rx queue 0. Accumulating enough error messages before
  5252. * reacting will make sure we don't cause flush too often.
  5253. */
  5254. #define I40E_MAX_FD_PROGRAM_ERROR 256
  5255. /**
  5256. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  5257. * @pf: board private structure
  5258. **/
  5259. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  5260. {
  5261. /* if interface is down do nothing */
  5262. if (test_bit(__I40E_DOWN, &pf->state))
  5263. return;
  5264. if (!(pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)))
  5265. return;
  5266. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5267. i40e_fdir_flush_and_replay(pf);
  5268. i40e_fdir_check_and_reenable(pf);
  5269. }
  5270. /**
  5271. * i40e_vsi_link_event - notify VSI of a link event
  5272. * @vsi: vsi to be notified
  5273. * @link_up: link up or down
  5274. **/
  5275. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  5276. {
  5277. if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
  5278. return;
  5279. switch (vsi->type) {
  5280. case I40E_VSI_MAIN:
  5281. #ifdef I40E_FCOE
  5282. case I40E_VSI_FCOE:
  5283. #endif
  5284. if (!vsi->netdev || !vsi->netdev_registered)
  5285. break;
  5286. if (link_up) {
  5287. netif_carrier_on(vsi->netdev);
  5288. netif_tx_wake_all_queues(vsi->netdev);
  5289. } else {
  5290. netif_carrier_off(vsi->netdev);
  5291. netif_tx_stop_all_queues(vsi->netdev);
  5292. }
  5293. break;
  5294. case I40E_VSI_SRIOV:
  5295. case I40E_VSI_VMDQ2:
  5296. case I40E_VSI_CTRL:
  5297. case I40E_VSI_IWARP:
  5298. case I40E_VSI_MIRROR:
  5299. default:
  5300. /* there is no notification for other VSIs */
  5301. break;
  5302. }
  5303. }
  5304. /**
  5305. * i40e_veb_link_event - notify elements on the veb of a link event
  5306. * @veb: veb to be notified
  5307. * @link_up: link up or down
  5308. **/
  5309. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  5310. {
  5311. struct i40e_pf *pf;
  5312. int i;
  5313. if (!veb || !veb->pf)
  5314. return;
  5315. pf = veb->pf;
  5316. /* depth first... */
  5317. for (i = 0; i < I40E_MAX_VEB; i++)
  5318. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  5319. i40e_veb_link_event(pf->veb[i], link_up);
  5320. /* ... now the local VSIs */
  5321. for (i = 0; i < pf->num_alloc_vsi; i++)
  5322. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  5323. i40e_vsi_link_event(pf->vsi[i], link_up);
  5324. }
  5325. /**
  5326. * i40e_link_event - Update netif_carrier status
  5327. * @pf: board private structure
  5328. **/
  5329. static void i40e_link_event(struct i40e_pf *pf)
  5330. {
  5331. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5332. u8 new_link_speed, old_link_speed;
  5333. i40e_status status;
  5334. bool new_link, old_link;
  5335. /* save off old link status information */
  5336. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  5337. /* set this to force the get_link_status call to refresh state */
  5338. pf->hw.phy.get_link_info = true;
  5339. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  5340. status = i40e_get_link_status(&pf->hw, &new_link);
  5341. if (status) {
  5342. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  5343. status);
  5344. return;
  5345. }
  5346. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  5347. new_link_speed = pf->hw.phy.link_info.link_speed;
  5348. if (new_link == old_link &&
  5349. new_link_speed == old_link_speed &&
  5350. (test_bit(__I40E_DOWN, &vsi->state) ||
  5351. new_link == netif_carrier_ok(vsi->netdev)))
  5352. return;
  5353. if (!test_bit(__I40E_DOWN, &vsi->state))
  5354. i40e_print_link_message(vsi, new_link);
  5355. /* Notify the base of the switch tree connected to
  5356. * the link. Floating VEBs are not notified.
  5357. */
  5358. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  5359. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  5360. else
  5361. i40e_vsi_link_event(vsi, new_link);
  5362. if (pf->vf)
  5363. i40e_vc_notify_link_state(pf);
  5364. if (pf->flags & I40E_FLAG_PTP)
  5365. i40e_ptp_set_increment(pf);
  5366. }
  5367. /**
  5368. * i40e_watchdog_subtask - periodic checks not using event driven response
  5369. * @pf: board private structure
  5370. **/
  5371. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  5372. {
  5373. int i;
  5374. /* if interface is down do nothing */
  5375. if (test_bit(__I40E_DOWN, &pf->state) ||
  5376. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5377. return;
  5378. /* make sure we don't do these things too often */
  5379. if (time_before(jiffies, (pf->service_timer_previous +
  5380. pf->service_timer_period)))
  5381. return;
  5382. pf->service_timer_previous = jiffies;
  5383. if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
  5384. i40e_link_event(pf);
  5385. /* Update the stats for active netdevs so the network stack
  5386. * can look at updated numbers whenever it cares to
  5387. */
  5388. for (i = 0; i < pf->num_alloc_vsi; i++)
  5389. if (pf->vsi[i] && pf->vsi[i]->netdev)
  5390. i40e_update_stats(pf->vsi[i]);
  5391. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  5392. /* Update the stats for the active switching components */
  5393. for (i = 0; i < I40E_MAX_VEB; i++)
  5394. if (pf->veb[i])
  5395. i40e_update_veb_stats(pf->veb[i]);
  5396. }
  5397. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  5398. }
  5399. /**
  5400. * i40e_reset_subtask - Set up for resetting the device and driver
  5401. * @pf: board private structure
  5402. **/
  5403. static void i40e_reset_subtask(struct i40e_pf *pf)
  5404. {
  5405. u32 reset_flags = 0;
  5406. rtnl_lock();
  5407. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  5408. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  5409. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  5410. }
  5411. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  5412. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  5413. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5414. }
  5415. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  5416. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  5417. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  5418. }
  5419. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  5420. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  5421. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  5422. }
  5423. if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
  5424. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  5425. clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
  5426. }
  5427. /* If there's a recovery already waiting, it takes
  5428. * precedence before starting a new reset sequence.
  5429. */
  5430. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  5431. i40e_handle_reset_warning(pf);
  5432. goto unlock;
  5433. }
  5434. /* If we're already down or resetting, just bail */
  5435. if (reset_flags &&
  5436. !test_bit(__I40E_DOWN, &pf->state) &&
  5437. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5438. i40e_do_reset(pf, reset_flags);
  5439. unlock:
  5440. rtnl_unlock();
  5441. }
  5442. /**
  5443. * i40e_handle_link_event - Handle link event
  5444. * @pf: board private structure
  5445. * @e: event info posted on ARQ
  5446. **/
  5447. static void i40e_handle_link_event(struct i40e_pf *pf,
  5448. struct i40e_arq_event_info *e)
  5449. {
  5450. struct i40e_aqc_get_link_status *status =
  5451. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  5452. /* Do a new status request to re-enable LSE reporting
  5453. * and load new status information into the hw struct
  5454. * This completely ignores any state information
  5455. * in the ARQ event info, instead choosing to always
  5456. * issue the AQ update link status command.
  5457. */
  5458. i40e_link_event(pf);
  5459. /* check for unqualified module, if link is down */
  5460. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  5461. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  5462. (!(status->link_info & I40E_AQ_LINK_UP)))
  5463. dev_err(&pf->pdev->dev,
  5464. "The driver failed to link because an unqualified module was detected.\n");
  5465. }
  5466. /**
  5467. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  5468. * @pf: board private structure
  5469. **/
  5470. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  5471. {
  5472. struct i40e_arq_event_info event;
  5473. struct i40e_hw *hw = &pf->hw;
  5474. u16 pending, i = 0;
  5475. i40e_status ret;
  5476. u16 opcode;
  5477. u32 oldval;
  5478. u32 val;
  5479. /* Do not run clean AQ when PF reset fails */
  5480. if (test_bit(__I40E_RESET_FAILED, &pf->state))
  5481. return;
  5482. /* check for error indications */
  5483. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  5484. oldval = val;
  5485. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  5486. if (hw->debug_mask & I40E_DEBUG_AQ)
  5487. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  5488. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  5489. }
  5490. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  5491. if (hw->debug_mask & I40E_DEBUG_AQ)
  5492. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  5493. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  5494. pf->arq_overflows++;
  5495. }
  5496. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  5497. if (hw->debug_mask & I40E_DEBUG_AQ)
  5498. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  5499. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  5500. }
  5501. if (oldval != val)
  5502. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  5503. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  5504. oldval = val;
  5505. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  5506. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5507. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  5508. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  5509. }
  5510. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  5511. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5512. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  5513. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  5514. }
  5515. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  5516. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5517. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  5518. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  5519. }
  5520. if (oldval != val)
  5521. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  5522. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  5523. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  5524. if (!event.msg_buf)
  5525. return;
  5526. do {
  5527. ret = i40e_clean_arq_element(hw, &event, &pending);
  5528. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  5529. break;
  5530. else if (ret) {
  5531. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  5532. break;
  5533. }
  5534. opcode = le16_to_cpu(event.desc.opcode);
  5535. switch (opcode) {
  5536. case i40e_aqc_opc_get_link_status:
  5537. i40e_handle_link_event(pf, &event);
  5538. break;
  5539. case i40e_aqc_opc_send_msg_to_pf:
  5540. ret = i40e_vc_process_vf_msg(pf,
  5541. le16_to_cpu(event.desc.retval),
  5542. le32_to_cpu(event.desc.cookie_high),
  5543. le32_to_cpu(event.desc.cookie_low),
  5544. event.msg_buf,
  5545. event.msg_len);
  5546. break;
  5547. case i40e_aqc_opc_lldp_update_mib:
  5548. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  5549. #ifdef CONFIG_I40E_DCB
  5550. rtnl_lock();
  5551. ret = i40e_handle_lldp_event(pf, &event);
  5552. rtnl_unlock();
  5553. #endif /* CONFIG_I40E_DCB */
  5554. break;
  5555. case i40e_aqc_opc_event_lan_overflow:
  5556. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  5557. i40e_handle_lan_overflow_event(pf, &event);
  5558. break;
  5559. case i40e_aqc_opc_send_msg_to_peer:
  5560. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  5561. break;
  5562. case i40e_aqc_opc_nvm_erase:
  5563. case i40e_aqc_opc_nvm_update:
  5564. case i40e_aqc_opc_oem_post_update:
  5565. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  5566. "ARQ NVM operation 0x%04x completed\n",
  5567. opcode);
  5568. break;
  5569. default:
  5570. dev_info(&pf->pdev->dev,
  5571. "ARQ: Unknown event 0x%04x ignored\n",
  5572. opcode);
  5573. break;
  5574. }
  5575. } while (pending && (i++ < pf->adminq_work_limit));
  5576. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  5577. /* re-enable Admin queue interrupt cause */
  5578. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  5579. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  5580. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  5581. i40e_flush(hw);
  5582. kfree(event.msg_buf);
  5583. }
  5584. /**
  5585. * i40e_verify_eeprom - make sure eeprom is good to use
  5586. * @pf: board private structure
  5587. **/
  5588. static void i40e_verify_eeprom(struct i40e_pf *pf)
  5589. {
  5590. int err;
  5591. err = i40e_diag_eeprom_test(&pf->hw);
  5592. if (err) {
  5593. /* retry in case of garbage read */
  5594. err = i40e_diag_eeprom_test(&pf->hw);
  5595. if (err) {
  5596. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  5597. err);
  5598. set_bit(__I40E_BAD_EEPROM, &pf->state);
  5599. }
  5600. }
  5601. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  5602. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  5603. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  5604. }
  5605. }
  5606. /**
  5607. * i40e_enable_pf_switch_lb
  5608. * @pf: pointer to the PF structure
  5609. *
  5610. * enable switch loop back or die - no point in a return value
  5611. **/
  5612. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  5613. {
  5614. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5615. struct i40e_vsi_context ctxt;
  5616. int ret;
  5617. ctxt.seid = pf->main_vsi_seid;
  5618. ctxt.pf_num = pf->hw.pf_id;
  5619. ctxt.vf_num = 0;
  5620. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5621. if (ret) {
  5622. dev_info(&pf->pdev->dev,
  5623. "couldn't get PF vsi config, err %s aq_err %s\n",
  5624. i40e_stat_str(&pf->hw, ret),
  5625. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5626. return;
  5627. }
  5628. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5629. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5630. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5631. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5632. if (ret) {
  5633. dev_info(&pf->pdev->dev,
  5634. "update vsi switch failed, err %s aq_err %s\n",
  5635. i40e_stat_str(&pf->hw, ret),
  5636. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5637. }
  5638. }
  5639. /**
  5640. * i40e_disable_pf_switch_lb
  5641. * @pf: pointer to the PF structure
  5642. *
  5643. * disable switch loop back or die - no point in a return value
  5644. **/
  5645. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  5646. {
  5647. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5648. struct i40e_vsi_context ctxt;
  5649. int ret;
  5650. ctxt.seid = pf->main_vsi_seid;
  5651. ctxt.pf_num = pf->hw.pf_id;
  5652. ctxt.vf_num = 0;
  5653. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5654. if (ret) {
  5655. dev_info(&pf->pdev->dev,
  5656. "couldn't get PF vsi config, err %s aq_err %s\n",
  5657. i40e_stat_str(&pf->hw, ret),
  5658. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5659. return;
  5660. }
  5661. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5662. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5663. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5664. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5665. if (ret) {
  5666. dev_info(&pf->pdev->dev,
  5667. "update vsi switch failed, err %s aq_err %s\n",
  5668. i40e_stat_str(&pf->hw, ret),
  5669. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5670. }
  5671. }
  5672. /**
  5673. * i40e_config_bridge_mode - Configure the HW bridge mode
  5674. * @veb: pointer to the bridge instance
  5675. *
  5676. * Configure the loop back mode for the LAN VSI that is downlink to the
  5677. * specified HW bridge instance. It is expected this function is called
  5678. * when a new HW bridge is instantiated.
  5679. **/
  5680. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  5681. {
  5682. struct i40e_pf *pf = veb->pf;
  5683. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  5684. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  5685. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  5686. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  5687. i40e_disable_pf_switch_lb(pf);
  5688. else
  5689. i40e_enable_pf_switch_lb(pf);
  5690. }
  5691. /**
  5692. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  5693. * @veb: pointer to the VEB instance
  5694. *
  5695. * This is a recursive function that first builds the attached VSIs then
  5696. * recurses in to build the next layer of VEB. We track the connections
  5697. * through our own index numbers because the seid's from the HW could
  5698. * change across the reset.
  5699. **/
  5700. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  5701. {
  5702. struct i40e_vsi *ctl_vsi = NULL;
  5703. struct i40e_pf *pf = veb->pf;
  5704. int v, veb_idx;
  5705. int ret;
  5706. /* build VSI that owns this VEB, temporarily attached to base VEB */
  5707. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  5708. if (pf->vsi[v] &&
  5709. pf->vsi[v]->veb_idx == veb->idx &&
  5710. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  5711. ctl_vsi = pf->vsi[v];
  5712. break;
  5713. }
  5714. }
  5715. if (!ctl_vsi) {
  5716. dev_info(&pf->pdev->dev,
  5717. "missing owner VSI for veb_idx %d\n", veb->idx);
  5718. ret = -ENOENT;
  5719. goto end_reconstitute;
  5720. }
  5721. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  5722. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5723. ret = i40e_add_vsi(ctl_vsi);
  5724. if (ret) {
  5725. dev_info(&pf->pdev->dev,
  5726. "rebuild of veb_idx %d owner VSI failed: %d\n",
  5727. veb->idx, ret);
  5728. goto end_reconstitute;
  5729. }
  5730. i40e_vsi_reset_stats(ctl_vsi);
  5731. /* create the VEB in the switch and move the VSI onto the VEB */
  5732. ret = i40e_add_veb(veb, ctl_vsi);
  5733. if (ret)
  5734. goto end_reconstitute;
  5735. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  5736. veb->bridge_mode = BRIDGE_MODE_VEB;
  5737. else
  5738. veb->bridge_mode = BRIDGE_MODE_VEPA;
  5739. i40e_config_bridge_mode(veb);
  5740. /* create the remaining VSIs attached to this VEB */
  5741. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5742. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  5743. continue;
  5744. if (pf->vsi[v]->veb_idx == veb->idx) {
  5745. struct i40e_vsi *vsi = pf->vsi[v];
  5746. vsi->uplink_seid = veb->seid;
  5747. ret = i40e_add_vsi(vsi);
  5748. if (ret) {
  5749. dev_info(&pf->pdev->dev,
  5750. "rebuild of vsi_idx %d failed: %d\n",
  5751. v, ret);
  5752. goto end_reconstitute;
  5753. }
  5754. i40e_vsi_reset_stats(vsi);
  5755. }
  5756. }
  5757. /* create any VEBs attached to this VEB - RECURSION */
  5758. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5759. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  5760. pf->veb[veb_idx]->uplink_seid = veb->seid;
  5761. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  5762. if (ret)
  5763. break;
  5764. }
  5765. }
  5766. end_reconstitute:
  5767. return ret;
  5768. }
  5769. /**
  5770. * i40e_get_capabilities - get info about the HW
  5771. * @pf: the PF struct
  5772. **/
  5773. static int i40e_get_capabilities(struct i40e_pf *pf)
  5774. {
  5775. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  5776. u16 data_size;
  5777. int buf_len;
  5778. int err;
  5779. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  5780. do {
  5781. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  5782. if (!cap_buf)
  5783. return -ENOMEM;
  5784. /* this loads the data into the hw struct for us */
  5785. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  5786. &data_size,
  5787. i40e_aqc_opc_list_func_capabilities,
  5788. NULL);
  5789. /* data loaded, buffer no longer needed */
  5790. kfree(cap_buf);
  5791. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  5792. /* retry with a larger buffer */
  5793. buf_len = data_size;
  5794. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  5795. dev_info(&pf->pdev->dev,
  5796. "capability discovery failed, err %s aq_err %s\n",
  5797. i40e_stat_str(&pf->hw, err),
  5798. i40e_aq_str(&pf->hw,
  5799. pf->hw.aq.asq_last_status));
  5800. return -ENODEV;
  5801. }
  5802. } while (err);
  5803. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  5804. dev_info(&pf->pdev->dev,
  5805. "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",
  5806. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  5807. pf->hw.func_caps.num_msix_vectors,
  5808. pf->hw.func_caps.num_msix_vectors_vf,
  5809. pf->hw.func_caps.fd_filters_guaranteed,
  5810. pf->hw.func_caps.fd_filters_best_effort,
  5811. pf->hw.func_caps.num_tx_qp,
  5812. pf->hw.func_caps.num_vsis);
  5813. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  5814. + pf->hw.func_caps.num_vfs)
  5815. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  5816. dev_info(&pf->pdev->dev,
  5817. "got num_vsis %d, setting num_vsis to %d\n",
  5818. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  5819. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  5820. }
  5821. return 0;
  5822. }
  5823. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  5824. /**
  5825. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  5826. * @pf: board private structure
  5827. **/
  5828. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  5829. {
  5830. struct i40e_vsi *vsi;
  5831. int i;
  5832. /* quick workaround for an NVM issue that leaves a critical register
  5833. * uninitialized
  5834. */
  5835. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  5836. static const u32 hkey[] = {
  5837. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  5838. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  5839. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  5840. 0x95b3a76d};
  5841. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  5842. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  5843. }
  5844. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  5845. return;
  5846. /* find existing VSI and see if it needs configuring */
  5847. vsi = NULL;
  5848. for (i = 0; i < pf->num_alloc_vsi; i++) {
  5849. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  5850. vsi = pf->vsi[i];
  5851. break;
  5852. }
  5853. }
  5854. /* create a new VSI if none exists */
  5855. if (!vsi) {
  5856. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  5857. pf->vsi[pf->lan_vsi]->seid, 0);
  5858. if (!vsi) {
  5859. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  5860. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5861. return;
  5862. }
  5863. }
  5864. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  5865. }
  5866. /**
  5867. * i40e_fdir_teardown - release the Flow Director resources
  5868. * @pf: board private structure
  5869. **/
  5870. static void i40e_fdir_teardown(struct i40e_pf *pf)
  5871. {
  5872. int i;
  5873. i40e_fdir_filter_exit(pf);
  5874. for (i = 0; i < pf->num_alloc_vsi; i++) {
  5875. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  5876. i40e_vsi_release(pf->vsi[i]);
  5877. break;
  5878. }
  5879. }
  5880. }
  5881. /**
  5882. * i40e_prep_for_reset - prep for the core to reset
  5883. * @pf: board private structure
  5884. *
  5885. * Close up the VFs and other things in prep for PF Reset.
  5886. **/
  5887. static void i40e_prep_for_reset(struct i40e_pf *pf)
  5888. {
  5889. struct i40e_hw *hw = &pf->hw;
  5890. i40e_status ret = 0;
  5891. u32 v;
  5892. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  5893. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  5894. return;
  5895. if (i40e_check_asq_alive(&pf->hw))
  5896. i40e_vc_notify_reset(pf);
  5897. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  5898. /* quiesce the VSIs and their queues that are not already DOWN */
  5899. i40e_pf_quiesce_all_vsi(pf);
  5900. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5901. if (pf->vsi[v])
  5902. pf->vsi[v]->seid = 0;
  5903. }
  5904. i40e_shutdown_adminq(&pf->hw);
  5905. /* call shutdown HMC */
  5906. if (hw->hmc.hmc_obj) {
  5907. ret = i40e_shutdown_lan_hmc(hw);
  5908. if (ret)
  5909. dev_warn(&pf->pdev->dev,
  5910. "shutdown_lan_hmc failed: %d\n", ret);
  5911. }
  5912. }
  5913. /**
  5914. * i40e_send_version - update firmware with driver version
  5915. * @pf: PF struct
  5916. */
  5917. static void i40e_send_version(struct i40e_pf *pf)
  5918. {
  5919. struct i40e_driver_version dv;
  5920. dv.major_version = DRV_VERSION_MAJOR;
  5921. dv.minor_version = DRV_VERSION_MINOR;
  5922. dv.build_version = DRV_VERSION_BUILD;
  5923. dv.subbuild_version = 0;
  5924. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  5925. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  5926. }
  5927. /**
  5928. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  5929. * @pf: board private structure
  5930. * @reinit: if the Main VSI needs to re-initialized.
  5931. **/
  5932. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  5933. {
  5934. struct i40e_hw *hw = &pf->hw;
  5935. u8 set_fc_aq_fail = 0;
  5936. i40e_status ret;
  5937. u32 val;
  5938. u32 v;
  5939. /* Now we wait for GRST to settle out.
  5940. * We don't have to delete the VEBs or VSIs from the hw switch
  5941. * because the reset will make them disappear.
  5942. */
  5943. ret = i40e_pf_reset(hw);
  5944. if (ret) {
  5945. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  5946. set_bit(__I40E_RESET_FAILED, &pf->state);
  5947. goto clear_recovery;
  5948. }
  5949. pf->pfr_count++;
  5950. if (test_bit(__I40E_DOWN, &pf->state))
  5951. goto clear_recovery;
  5952. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  5953. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  5954. ret = i40e_init_adminq(&pf->hw);
  5955. if (ret) {
  5956. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  5957. i40e_stat_str(&pf->hw, ret),
  5958. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5959. goto clear_recovery;
  5960. }
  5961. /* re-verify the eeprom if we just had an EMP reset */
  5962. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
  5963. i40e_verify_eeprom(pf);
  5964. i40e_clear_pxe_mode(hw);
  5965. ret = i40e_get_capabilities(pf);
  5966. if (ret)
  5967. goto end_core_reset;
  5968. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  5969. hw->func_caps.num_rx_qp,
  5970. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  5971. if (ret) {
  5972. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  5973. goto end_core_reset;
  5974. }
  5975. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  5976. if (ret) {
  5977. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  5978. goto end_core_reset;
  5979. }
  5980. #ifdef CONFIG_I40E_DCB
  5981. ret = i40e_init_pf_dcb(pf);
  5982. if (ret) {
  5983. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  5984. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  5985. /* Continue without DCB enabled */
  5986. }
  5987. #endif /* CONFIG_I40E_DCB */
  5988. #ifdef I40E_FCOE
  5989. i40e_init_pf_fcoe(pf);
  5990. #endif
  5991. /* do basic switch setup */
  5992. ret = i40e_setup_pf_switch(pf, reinit);
  5993. if (ret)
  5994. goto end_core_reset;
  5995. /* The driver only wants link up/down and module qualification
  5996. * reports from firmware. Note the negative logic.
  5997. */
  5998. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  5999. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  6000. I40E_AQ_EVENT_MEDIA_NA |
  6001. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  6002. if (ret)
  6003. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  6004. i40e_stat_str(&pf->hw, ret),
  6005. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6006. /* make sure our flow control settings are restored */
  6007. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  6008. if (ret)
  6009. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  6010. i40e_stat_str(&pf->hw, ret),
  6011. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6012. /* Rebuild the VSIs and VEBs that existed before reset.
  6013. * They are still in our local switch element arrays, so only
  6014. * need to rebuild the switch model in the HW.
  6015. *
  6016. * If there were VEBs but the reconstitution failed, we'll try
  6017. * try to recover minimal use by getting the basic PF VSI working.
  6018. */
  6019. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  6020. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  6021. /* find the one VEB connected to the MAC, and find orphans */
  6022. for (v = 0; v < I40E_MAX_VEB; v++) {
  6023. if (!pf->veb[v])
  6024. continue;
  6025. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  6026. pf->veb[v]->uplink_seid == 0) {
  6027. ret = i40e_reconstitute_veb(pf->veb[v]);
  6028. if (!ret)
  6029. continue;
  6030. /* If Main VEB failed, we're in deep doodoo,
  6031. * so give up rebuilding the switch and set up
  6032. * for minimal rebuild of PF VSI.
  6033. * If orphan failed, we'll report the error
  6034. * but try to keep going.
  6035. */
  6036. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  6037. dev_info(&pf->pdev->dev,
  6038. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  6039. ret);
  6040. pf->vsi[pf->lan_vsi]->uplink_seid
  6041. = pf->mac_seid;
  6042. break;
  6043. } else if (pf->veb[v]->uplink_seid == 0) {
  6044. dev_info(&pf->pdev->dev,
  6045. "rebuild of orphan VEB failed: %d\n",
  6046. ret);
  6047. }
  6048. }
  6049. }
  6050. }
  6051. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  6052. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  6053. /* no VEB, so rebuild only the Main VSI */
  6054. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  6055. if (ret) {
  6056. dev_info(&pf->pdev->dev,
  6057. "rebuild of Main VSI failed: %d\n", ret);
  6058. goto end_core_reset;
  6059. }
  6060. }
  6061. /* Reconfigure hardware for allowing smaller MSS in the case
  6062. * of TSO, so that we avoid the MDD being fired and causing
  6063. * a reset in the case of small MSS+TSO.
  6064. */
  6065. #define I40E_REG_MSS 0x000E64DC
  6066. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  6067. #define I40E_64BYTE_MSS 0x400000
  6068. val = rd32(hw, I40E_REG_MSS);
  6069. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  6070. val &= ~I40E_REG_MSS_MIN_MASK;
  6071. val |= I40E_64BYTE_MSS;
  6072. wr32(hw, I40E_REG_MSS, val);
  6073. }
  6074. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  6075. msleep(75);
  6076. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  6077. if (ret)
  6078. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  6079. i40e_stat_str(&pf->hw, ret),
  6080. i40e_aq_str(&pf->hw,
  6081. pf->hw.aq.asq_last_status));
  6082. }
  6083. /* reinit the misc interrupt */
  6084. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6085. ret = i40e_setup_misc_vector(pf);
  6086. /* Add a filter to drop all Flow control frames from any VSI from being
  6087. * transmitted. By doing so we stop a malicious VF from sending out
  6088. * PAUSE or PFC frames and potentially controlling traffic for other
  6089. * PF/VF VSIs.
  6090. * The FW can still send Flow control frames if enabled.
  6091. */
  6092. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  6093. pf->main_vsi_seid);
  6094. /* restart the VSIs that were rebuilt and running before the reset */
  6095. i40e_pf_unquiesce_all_vsi(pf);
  6096. if (pf->num_alloc_vfs) {
  6097. for (v = 0; v < pf->num_alloc_vfs; v++)
  6098. i40e_reset_vf(&pf->vf[v], true);
  6099. }
  6100. /* tell the firmware that we're starting */
  6101. i40e_send_version(pf);
  6102. end_core_reset:
  6103. clear_bit(__I40E_RESET_FAILED, &pf->state);
  6104. clear_recovery:
  6105. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  6106. }
  6107. /**
  6108. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  6109. * @pf: board private structure
  6110. *
  6111. * Close up the VFs and other things in prep for a Core Reset,
  6112. * then get ready to rebuild the world.
  6113. **/
  6114. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  6115. {
  6116. i40e_prep_for_reset(pf);
  6117. i40e_reset_and_rebuild(pf, false);
  6118. }
  6119. /**
  6120. * i40e_handle_mdd_event
  6121. * @pf: pointer to the PF structure
  6122. *
  6123. * Called from the MDD irq handler to identify possibly malicious vfs
  6124. **/
  6125. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  6126. {
  6127. struct i40e_hw *hw = &pf->hw;
  6128. bool mdd_detected = false;
  6129. bool pf_mdd_detected = false;
  6130. struct i40e_vf *vf;
  6131. u32 reg;
  6132. int i;
  6133. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  6134. return;
  6135. /* find what triggered the MDD event */
  6136. reg = rd32(hw, I40E_GL_MDET_TX);
  6137. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  6138. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  6139. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  6140. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  6141. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  6142. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  6143. I40E_GL_MDET_TX_EVENT_SHIFT;
  6144. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  6145. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  6146. pf->hw.func_caps.base_queue;
  6147. if (netif_msg_tx_err(pf))
  6148. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  6149. event, queue, pf_num, vf_num);
  6150. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  6151. mdd_detected = true;
  6152. }
  6153. reg = rd32(hw, I40E_GL_MDET_RX);
  6154. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  6155. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  6156. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  6157. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  6158. I40E_GL_MDET_RX_EVENT_SHIFT;
  6159. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  6160. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  6161. pf->hw.func_caps.base_queue;
  6162. if (netif_msg_rx_err(pf))
  6163. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  6164. event, queue, func);
  6165. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  6166. mdd_detected = true;
  6167. }
  6168. if (mdd_detected) {
  6169. reg = rd32(hw, I40E_PF_MDET_TX);
  6170. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  6171. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  6172. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  6173. pf_mdd_detected = true;
  6174. }
  6175. reg = rd32(hw, I40E_PF_MDET_RX);
  6176. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  6177. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  6178. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  6179. pf_mdd_detected = true;
  6180. }
  6181. /* Queue belongs to the PF, initiate a reset */
  6182. if (pf_mdd_detected) {
  6183. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  6184. i40e_service_event_schedule(pf);
  6185. }
  6186. }
  6187. /* see if one of the VFs needs its hand slapped */
  6188. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  6189. vf = &(pf->vf[i]);
  6190. reg = rd32(hw, I40E_VP_MDET_TX(i));
  6191. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  6192. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  6193. vf->num_mdd_events++;
  6194. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  6195. i);
  6196. }
  6197. reg = rd32(hw, I40E_VP_MDET_RX(i));
  6198. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  6199. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  6200. vf->num_mdd_events++;
  6201. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  6202. i);
  6203. }
  6204. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  6205. dev_info(&pf->pdev->dev,
  6206. "Too many MDD events on VF %d, disabled\n", i);
  6207. dev_info(&pf->pdev->dev,
  6208. "Use PF Control I/F to re-enable the VF\n");
  6209. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  6210. }
  6211. }
  6212. /* re-enable mdd interrupt cause */
  6213. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  6214. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  6215. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  6216. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  6217. i40e_flush(hw);
  6218. }
  6219. /**
  6220. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  6221. * @pf: board private structure
  6222. **/
  6223. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  6224. {
  6225. #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
  6226. struct i40e_hw *hw = &pf->hw;
  6227. i40e_status ret;
  6228. __be16 port;
  6229. int i;
  6230. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  6231. return;
  6232. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  6233. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  6234. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  6235. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  6236. port = pf->udp_ports[i].index;
  6237. if (port)
  6238. ret = i40e_aq_add_udp_tunnel(hw, ntohs(port),
  6239. pf->udp_ports[i].type,
  6240. NULL, NULL);
  6241. else
  6242. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  6243. if (ret) {
  6244. dev_dbg(&pf->pdev->dev,
  6245. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  6246. pf->udp_ports[i].type ? "vxlan" : "geneve",
  6247. port ? "add" : "delete",
  6248. ntohs(port), i,
  6249. i40e_stat_str(&pf->hw, ret),
  6250. i40e_aq_str(&pf->hw,
  6251. pf->hw.aq.asq_last_status));
  6252. pf->udp_ports[i].index = 0;
  6253. }
  6254. }
  6255. }
  6256. #endif
  6257. }
  6258. /**
  6259. * i40e_service_task - Run the driver's async subtasks
  6260. * @work: pointer to work_struct containing our data
  6261. **/
  6262. static void i40e_service_task(struct work_struct *work)
  6263. {
  6264. struct i40e_pf *pf = container_of(work,
  6265. struct i40e_pf,
  6266. service_task);
  6267. unsigned long start_time = jiffies;
  6268. /* don't bother with service tasks if a reset is in progress */
  6269. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6270. i40e_service_event_complete(pf);
  6271. return;
  6272. }
  6273. i40e_detect_recover_hung(pf);
  6274. i40e_sync_filters_subtask(pf);
  6275. i40e_reset_subtask(pf);
  6276. i40e_handle_mdd_event(pf);
  6277. i40e_vc_process_vflr_event(pf);
  6278. i40e_watchdog_subtask(pf);
  6279. i40e_fdir_reinit_subtask(pf);
  6280. i40e_client_subtask(pf);
  6281. i40e_sync_filters_subtask(pf);
  6282. i40e_sync_udp_filters_subtask(pf);
  6283. i40e_clean_adminq_subtask(pf);
  6284. i40e_service_event_complete(pf);
  6285. /* If the tasks have taken longer than one timer cycle or there
  6286. * is more work to be done, reschedule the service task now
  6287. * rather than wait for the timer to tick again.
  6288. */
  6289. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  6290. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  6291. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  6292. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  6293. i40e_service_event_schedule(pf);
  6294. }
  6295. /**
  6296. * i40e_service_timer - timer callback
  6297. * @data: pointer to PF struct
  6298. **/
  6299. static void i40e_service_timer(unsigned long data)
  6300. {
  6301. struct i40e_pf *pf = (struct i40e_pf *)data;
  6302. mod_timer(&pf->service_timer,
  6303. round_jiffies(jiffies + pf->service_timer_period));
  6304. i40e_service_event_schedule(pf);
  6305. }
  6306. /**
  6307. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  6308. * @vsi: the VSI being configured
  6309. **/
  6310. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  6311. {
  6312. struct i40e_pf *pf = vsi->back;
  6313. switch (vsi->type) {
  6314. case I40E_VSI_MAIN:
  6315. vsi->alloc_queue_pairs = pf->num_lan_qps;
  6316. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6317. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6318. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6319. vsi->num_q_vectors = pf->num_lan_msix;
  6320. else
  6321. vsi->num_q_vectors = 1;
  6322. break;
  6323. case I40E_VSI_FDIR:
  6324. vsi->alloc_queue_pairs = 1;
  6325. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  6326. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6327. vsi->num_q_vectors = 1;
  6328. break;
  6329. case I40E_VSI_VMDQ2:
  6330. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  6331. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6332. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6333. vsi->num_q_vectors = pf->num_vmdq_msix;
  6334. break;
  6335. case I40E_VSI_SRIOV:
  6336. vsi->alloc_queue_pairs = pf->num_vf_qps;
  6337. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6338. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6339. break;
  6340. #ifdef I40E_FCOE
  6341. case I40E_VSI_FCOE:
  6342. vsi->alloc_queue_pairs = pf->num_fcoe_qps;
  6343. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6344. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6345. vsi->num_q_vectors = pf->num_fcoe_msix;
  6346. break;
  6347. #endif /* I40E_FCOE */
  6348. default:
  6349. WARN_ON(1);
  6350. return -ENODATA;
  6351. }
  6352. return 0;
  6353. }
  6354. /**
  6355. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  6356. * @type: VSI pointer
  6357. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  6358. *
  6359. * On error: returns error code (negative)
  6360. * On success: returns 0
  6361. **/
  6362. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  6363. {
  6364. int size;
  6365. int ret = 0;
  6366. /* allocate memory for both Tx and Rx ring pointers */
  6367. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  6368. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  6369. if (!vsi->tx_rings)
  6370. return -ENOMEM;
  6371. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  6372. if (alloc_qvectors) {
  6373. /* allocate memory for q_vector pointers */
  6374. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  6375. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  6376. if (!vsi->q_vectors) {
  6377. ret = -ENOMEM;
  6378. goto err_vectors;
  6379. }
  6380. }
  6381. return ret;
  6382. err_vectors:
  6383. kfree(vsi->tx_rings);
  6384. return ret;
  6385. }
  6386. /**
  6387. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  6388. * @pf: board private structure
  6389. * @type: type of VSI
  6390. *
  6391. * On error: returns error code (negative)
  6392. * On success: returns vsi index in PF (positive)
  6393. **/
  6394. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  6395. {
  6396. int ret = -ENODEV;
  6397. struct i40e_vsi *vsi;
  6398. int vsi_idx;
  6399. int i;
  6400. /* Need to protect the allocation of the VSIs at the PF level */
  6401. mutex_lock(&pf->switch_mutex);
  6402. /* VSI list may be fragmented if VSI creation/destruction has
  6403. * been happening. We can afford to do a quick scan to look
  6404. * for any free VSIs in the list.
  6405. *
  6406. * find next empty vsi slot, looping back around if necessary
  6407. */
  6408. i = pf->next_vsi;
  6409. while (i < pf->num_alloc_vsi && pf->vsi[i])
  6410. i++;
  6411. if (i >= pf->num_alloc_vsi) {
  6412. i = 0;
  6413. while (i < pf->next_vsi && pf->vsi[i])
  6414. i++;
  6415. }
  6416. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  6417. vsi_idx = i; /* Found one! */
  6418. } else {
  6419. ret = -ENODEV;
  6420. goto unlock_pf; /* out of VSI slots! */
  6421. }
  6422. pf->next_vsi = ++i;
  6423. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  6424. if (!vsi) {
  6425. ret = -ENOMEM;
  6426. goto unlock_pf;
  6427. }
  6428. vsi->type = type;
  6429. vsi->back = pf;
  6430. set_bit(__I40E_DOWN, &vsi->state);
  6431. vsi->flags = 0;
  6432. vsi->idx = vsi_idx;
  6433. vsi->int_rate_limit = 0;
  6434. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  6435. pf->rss_table_size : 64;
  6436. vsi->netdev_registered = false;
  6437. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  6438. INIT_LIST_HEAD(&vsi->mac_filter_list);
  6439. vsi->irqs_ready = false;
  6440. ret = i40e_set_num_rings_in_vsi(vsi);
  6441. if (ret)
  6442. goto err_rings;
  6443. ret = i40e_vsi_alloc_arrays(vsi, true);
  6444. if (ret)
  6445. goto err_rings;
  6446. /* Setup default MSIX irq handler for VSI */
  6447. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  6448. /* Initialize VSI lock */
  6449. spin_lock_init(&vsi->mac_filter_list_lock);
  6450. pf->vsi[vsi_idx] = vsi;
  6451. ret = vsi_idx;
  6452. goto unlock_pf;
  6453. err_rings:
  6454. pf->next_vsi = i - 1;
  6455. kfree(vsi);
  6456. unlock_pf:
  6457. mutex_unlock(&pf->switch_mutex);
  6458. return ret;
  6459. }
  6460. /**
  6461. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  6462. * @type: VSI pointer
  6463. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  6464. *
  6465. * On error: returns error code (negative)
  6466. * On success: returns 0
  6467. **/
  6468. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  6469. {
  6470. /* free the ring and vector containers */
  6471. if (free_qvectors) {
  6472. kfree(vsi->q_vectors);
  6473. vsi->q_vectors = NULL;
  6474. }
  6475. kfree(vsi->tx_rings);
  6476. vsi->tx_rings = NULL;
  6477. vsi->rx_rings = NULL;
  6478. }
  6479. /**
  6480. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  6481. * and lookup table
  6482. * @vsi: Pointer to VSI structure
  6483. */
  6484. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  6485. {
  6486. if (!vsi)
  6487. return;
  6488. kfree(vsi->rss_hkey_user);
  6489. vsi->rss_hkey_user = NULL;
  6490. kfree(vsi->rss_lut_user);
  6491. vsi->rss_lut_user = NULL;
  6492. }
  6493. /**
  6494. * i40e_vsi_clear - Deallocate the VSI provided
  6495. * @vsi: the VSI being un-configured
  6496. **/
  6497. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  6498. {
  6499. struct i40e_pf *pf;
  6500. if (!vsi)
  6501. return 0;
  6502. if (!vsi->back)
  6503. goto free_vsi;
  6504. pf = vsi->back;
  6505. mutex_lock(&pf->switch_mutex);
  6506. if (!pf->vsi[vsi->idx]) {
  6507. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  6508. vsi->idx, vsi->idx, vsi, vsi->type);
  6509. goto unlock_vsi;
  6510. }
  6511. if (pf->vsi[vsi->idx] != vsi) {
  6512. dev_err(&pf->pdev->dev,
  6513. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  6514. pf->vsi[vsi->idx]->idx,
  6515. pf->vsi[vsi->idx],
  6516. pf->vsi[vsi->idx]->type,
  6517. vsi->idx, vsi, vsi->type);
  6518. goto unlock_vsi;
  6519. }
  6520. /* updates the PF for this cleared vsi */
  6521. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6522. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  6523. i40e_vsi_free_arrays(vsi, true);
  6524. i40e_clear_rss_config_user(vsi);
  6525. pf->vsi[vsi->idx] = NULL;
  6526. if (vsi->idx < pf->next_vsi)
  6527. pf->next_vsi = vsi->idx;
  6528. unlock_vsi:
  6529. mutex_unlock(&pf->switch_mutex);
  6530. free_vsi:
  6531. kfree(vsi);
  6532. return 0;
  6533. }
  6534. /**
  6535. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  6536. * @vsi: the VSI being cleaned
  6537. **/
  6538. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  6539. {
  6540. int i;
  6541. if (vsi->tx_rings && vsi->tx_rings[0]) {
  6542. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6543. kfree_rcu(vsi->tx_rings[i], rcu);
  6544. vsi->tx_rings[i] = NULL;
  6545. vsi->rx_rings[i] = NULL;
  6546. }
  6547. }
  6548. }
  6549. /**
  6550. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  6551. * @vsi: the VSI being configured
  6552. **/
  6553. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  6554. {
  6555. struct i40e_ring *tx_ring, *rx_ring;
  6556. struct i40e_pf *pf = vsi->back;
  6557. int i;
  6558. /* Set basic values in the rings to be used later during open() */
  6559. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6560. /* allocate space for both Tx and Rx in one shot */
  6561. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  6562. if (!tx_ring)
  6563. goto err_out;
  6564. tx_ring->queue_index = i;
  6565. tx_ring->reg_idx = vsi->base_queue + i;
  6566. tx_ring->ring_active = false;
  6567. tx_ring->vsi = vsi;
  6568. tx_ring->netdev = vsi->netdev;
  6569. tx_ring->dev = &pf->pdev->dev;
  6570. tx_ring->count = vsi->num_desc;
  6571. tx_ring->size = 0;
  6572. tx_ring->dcb_tc = 0;
  6573. if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  6574. tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  6575. tx_ring->tx_itr_setting = pf->tx_itr_default;
  6576. vsi->tx_rings[i] = tx_ring;
  6577. rx_ring = &tx_ring[1];
  6578. rx_ring->queue_index = i;
  6579. rx_ring->reg_idx = vsi->base_queue + i;
  6580. rx_ring->ring_active = false;
  6581. rx_ring->vsi = vsi;
  6582. rx_ring->netdev = vsi->netdev;
  6583. rx_ring->dev = &pf->pdev->dev;
  6584. rx_ring->count = vsi->num_desc;
  6585. rx_ring->size = 0;
  6586. rx_ring->dcb_tc = 0;
  6587. if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
  6588. set_ring_16byte_desc_enabled(rx_ring);
  6589. else
  6590. clear_ring_16byte_desc_enabled(rx_ring);
  6591. rx_ring->rx_itr_setting = pf->rx_itr_default;
  6592. vsi->rx_rings[i] = rx_ring;
  6593. }
  6594. return 0;
  6595. err_out:
  6596. i40e_vsi_clear_rings(vsi);
  6597. return -ENOMEM;
  6598. }
  6599. /**
  6600. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  6601. * @pf: board private structure
  6602. * @vectors: the number of MSI-X vectors to request
  6603. *
  6604. * Returns the number of vectors reserved, or error
  6605. **/
  6606. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  6607. {
  6608. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  6609. I40E_MIN_MSIX, vectors);
  6610. if (vectors < 0) {
  6611. dev_info(&pf->pdev->dev,
  6612. "MSI-X vector reservation failed: %d\n", vectors);
  6613. vectors = 0;
  6614. }
  6615. return vectors;
  6616. }
  6617. /**
  6618. * i40e_init_msix - Setup the MSIX capability
  6619. * @pf: board private structure
  6620. *
  6621. * Work with the OS to set up the MSIX vectors needed.
  6622. *
  6623. * Returns the number of vectors reserved or negative on failure
  6624. **/
  6625. static int i40e_init_msix(struct i40e_pf *pf)
  6626. {
  6627. struct i40e_hw *hw = &pf->hw;
  6628. int vectors_left;
  6629. int v_budget, i;
  6630. int v_actual;
  6631. int iwarp_requested = 0;
  6632. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  6633. return -ENODEV;
  6634. /* The number of vectors we'll request will be comprised of:
  6635. * - Add 1 for "other" cause for Admin Queue events, etc.
  6636. * - The number of LAN queue pairs
  6637. * - Queues being used for RSS.
  6638. * We don't need as many as max_rss_size vectors.
  6639. * use rss_size instead in the calculation since that
  6640. * is governed by number of cpus in the system.
  6641. * - assumes symmetric Tx/Rx pairing
  6642. * - The number of VMDq pairs
  6643. * - The CPU count within the NUMA node if iWARP is enabled
  6644. #ifdef I40E_FCOE
  6645. * - The number of FCOE qps.
  6646. #endif
  6647. * Once we count this up, try the request.
  6648. *
  6649. * If we can't get what we want, we'll simplify to nearly nothing
  6650. * and try again. If that still fails, we punt.
  6651. */
  6652. vectors_left = hw->func_caps.num_msix_vectors;
  6653. v_budget = 0;
  6654. /* reserve one vector for miscellaneous handler */
  6655. if (vectors_left) {
  6656. v_budget++;
  6657. vectors_left--;
  6658. }
  6659. /* reserve vectors for the main PF traffic queues */
  6660. pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
  6661. vectors_left -= pf->num_lan_msix;
  6662. v_budget += pf->num_lan_msix;
  6663. /* reserve one vector for sideband flow director */
  6664. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6665. if (vectors_left) {
  6666. v_budget++;
  6667. vectors_left--;
  6668. } else {
  6669. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6670. }
  6671. }
  6672. #ifdef I40E_FCOE
  6673. /* can we reserve enough for FCoE? */
  6674. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6675. if (!vectors_left)
  6676. pf->num_fcoe_msix = 0;
  6677. else if (vectors_left >= pf->num_fcoe_qps)
  6678. pf->num_fcoe_msix = pf->num_fcoe_qps;
  6679. else
  6680. pf->num_fcoe_msix = 1;
  6681. v_budget += pf->num_fcoe_msix;
  6682. vectors_left -= pf->num_fcoe_msix;
  6683. }
  6684. #endif
  6685. /* can we reserve enough for iWARP? */
  6686. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6687. if (!vectors_left)
  6688. pf->num_iwarp_msix = 0;
  6689. else if (vectors_left < pf->num_iwarp_msix)
  6690. pf->num_iwarp_msix = 1;
  6691. v_budget += pf->num_iwarp_msix;
  6692. vectors_left -= pf->num_iwarp_msix;
  6693. }
  6694. /* any vectors left over go for VMDq support */
  6695. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  6696. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  6697. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  6698. /* if we're short on vectors for what's desired, we limit
  6699. * the queues per vmdq. If this is still more than are
  6700. * available, the user will need to change the number of
  6701. * queues/vectors used by the PF later with the ethtool
  6702. * channels command
  6703. */
  6704. if (vmdq_vecs < vmdq_vecs_wanted)
  6705. pf->num_vmdq_qps = 1;
  6706. pf->num_vmdq_msix = pf->num_vmdq_qps;
  6707. v_budget += vmdq_vecs;
  6708. vectors_left -= vmdq_vecs;
  6709. }
  6710. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  6711. GFP_KERNEL);
  6712. if (!pf->msix_entries)
  6713. return -ENOMEM;
  6714. for (i = 0; i < v_budget; i++)
  6715. pf->msix_entries[i].entry = i;
  6716. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  6717. if (v_actual != v_budget) {
  6718. /* If we have limited resources, we will start with no vectors
  6719. * for the special features and then allocate vectors to some
  6720. * of these features based on the policy and at the end disable
  6721. * the features that did not get any vectors.
  6722. */
  6723. iwarp_requested = pf->num_iwarp_msix;
  6724. pf->num_iwarp_msix = 0;
  6725. #ifdef I40E_FCOE
  6726. pf->num_fcoe_qps = 0;
  6727. pf->num_fcoe_msix = 0;
  6728. #endif
  6729. pf->num_vmdq_msix = 0;
  6730. }
  6731. if (v_actual < I40E_MIN_MSIX) {
  6732. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  6733. kfree(pf->msix_entries);
  6734. pf->msix_entries = NULL;
  6735. return -ENODEV;
  6736. } else if (v_actual == I40E_MIN_MSIX) {
  6737. /* Adjust for minimal MSIX use */
  6738. pf->num_vmdq_vsis = 0;
  6739. pf->num_vmdq_qps = 0;
  6740. pf->num_lan_qps = 1;
  6741. pf->num_lan_msix = 1;
  6742. } else if (v_actual != v_budget) {
  6743. int vec;
  6744. /* reserve the misc vector */
  6745. vec = v_actual - 1;
  6746. /* Scale vector usage down */
  6747. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  6748. pf->num_vmdq_vsis = 1;
  6749. pf->num_vmdq_qps = 1;
  6750. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6751. /* partition out the remaining vectors */
  6752. switch (vec) {
  6753. case 2:
  6754. pf->num_lan_msix = 1;
  6755. break;
  6756. case 3:
  6757. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6758. pf->num_lan_msix = 1;
  6759. pf->num_iwarp_msix = 1;
  6760. } else {
  6761. pf->num_lan_msix = 2;
  6762. }
  6763. #ifdef I40E_FCOE
  6764. /* give one vector to FCoE */
  6765. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6766. pf->num_lan_msix = 1;
  6767. pf->num_fcoe_msix = 1;
  6768. }
  6769. #endif
  6770. break;
  6771. default:
  6772. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6773. pf->num_iwarp_msix = min_t(int, (vec / 3),
  6774. iwarp_requested);
  6775. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  6776. I40E_DEFAULT_NUM_VMDQ_VSI);
  6777. } else {
  6778. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  6779. I40E_DEFAULT_NUM_VMDQ_VSI);
  6780. }
  6781. pf->num_lan_msix = min_t(int,
  6782. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  6783. pf->num_lan_msix);
  6784. #ifdef I40E_FCOE
  6785. /* give one vector to FCoE */
  6786. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6787. pf->num_fcoe_msix = 1;
  6788. vec--;
  6789. }
  6790. #endif
  6791. break;
  6792. }
  6793. }
  6794. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  6795. (pf->num_vmdq_msix == 0)) {
  6796. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  6797. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  6798. }
  6799. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  6800. (pf->num_iwarp_msix == 0)) {
  6801. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  6802. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  6803. }
  6804. #ifdef I40E_FCOE
  6805. if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
  6806. dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
  6807. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  6808. }
  6809. #endif
  6810. return v_actual;
  6811. }
  6812. /**
  6813. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  6814. * @vsi: the VSI being configured
  6815. * @v_idx: index of the vector in the vsi struct
  6816. *
  6817. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  6818. **/
  6819. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
  6820. {
  6821. struct i40e_q_vector *q_vector;
  6822. /* allocate q_vector */
  6823. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  6824. if (!q_vector)
  6825. return -ENOMEM;
  6826. q_vector->vsi = vsi;
  6827. q_vector->v_idx = v_idx;
  6828. cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
  6829. if (vsi->netdev)
  6830. netif_napi_add(vsi->netdev, &q_vector->napi,
  6831. i40e_napi_poll, NAPI_POLL_WEIGHT);
  6832. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  6833. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  6834. /* tie q_vector and vsi together */
  6835. vsi->q_vectors[v_idx] = q_vector;
  6836. return 0;
  6837. }
  6838. /**
  6839. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  6840. * @vsi: the VSI being configured
  6841. *
  6842. * We allocate one q_vector per queue interrupt. If allocation fails we
  6843. * return -ENOMEM.
  6844. **/
  6845. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  6846. {
  6847. struct i40e_pf *pf = vsi->back;
  6848. int v_idx, num_q_vectors;
  6849. int err;
  6850. /* if not MSIX, give the one vector only to the LAN VSI */
  6851. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6852. num_q_vectors = vsi->num_q_vectors;
  6853. else if (vsi == pf->vsi[pf->lan_vsi])
  6854. num_q_vectors = 1;
  6855. else
  6856. return -EINVAL;
  6857. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  6858. err = i40e_vsi_alloc_q_vector(vsi, v_idx);
  6859. if (err)
  6860. goto err_out;
  6861. }
  6862. return 0;
  6863. err_out:
  6864. while (v_idx--)
  6865. i40e_free_q_vector(vsi, v_idx);
  6866. return err;
  6867. }
  6868. /**
  6869. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  6870. * @pf: board private structure to initialize
  6871. **/
  6872. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  6873. {
  6874. int vectors = 0;
  6875. ssize_t size;
  6876. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  6877. vectors = i40e_init_msix(pf);
  6878. if (vectors < 0) {
  6879. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  6880. I40E_FLAG_IWARP_ENABLED |
  6881. #ifdef I40E_FCOE
  6882. I40E_FLAG_FCOE_ENABLED |
  6883. #endif
  6884. I40E_FLAG_RSS_ENABLED |
  6885. I40E_FLAG_DCB_CAPABLE |
  6886. I40E_FLAG_SRIOV_ENABLED |
  6887. I40E_FLAG_FD_SB_ENABLED |
  6888. I40E_FLAG_FD_ATR_ENABLED |
  6889. I40E_FLAG_VMDQ_ENABLED);
  6890. /* rework the queue expectations without MSIX */
  6891. i40e_determine_queue_usage(pf);
  6892. }
  6893. }
  6894. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  6895. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  6896. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  6897. vectors = pci_enable_msi(pf->pdev);
  6898. if (vectors < 0) {
  6899. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  6900. vectors);
  6901. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  6902. }
  6903. vectors = 1; /* one MSI or Legacy vector */
  6904. }
  6905. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  6906. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  6907. /* set up vector assignment tracking */
  6908. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  6909. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  6910. if (!pf->irq_pile) {
  6911. dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
  6912. return -ENOMEM;
  6913. }
  6914. pf->irq_pile->num_entries = vectors;
  6915. pf->irq_pile->search_hint = 0;
  6916. /* track first vector for misc interrupts, ignore return */
  6917. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  6918. return 0;
  6919. }
  6920. /**
  6921. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  6922. * @pf: board private structure
  6923. *
  6924. * This sets up the handler for MSIX 0, which is used to manage the
  6925. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  6926. * when in MSI or Legacy interrupt mode.
  6927. **/
  6928. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  6929. {
  6930. struct i40e_hw *hw = &pf->hw;
  6931. int err = 0;
  6932. /* Only request the irq if this is the first time through, and
  6933. * not when we're rebuilding after a Reset
  6934. */
  6935. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6936. err = request_irq(pf->msix_entries[0].vector,
  6937. i40e_intr, 0, pf->int_name, pf);
  6938. if (err) {
  6939. dev_info(&pf->pdev->dev,
  6940. "request_irq for %s failed: %d\n",
  6941. pf->int_name, err);
  6942. return -EFAULT;
  6943. }
  6944. }
  6945. i40e_enable_misc_int_causes(pf);
  6946. /* associate no queues to the misc vector */
  6947. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  6948. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  6949. i40e_flush(hw);
  6950. i40e_irq_dynamic_enable_icr0(pf, true);
  6951. return err;
  6952. }
  6953. /**
  6954. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  6955. * @vsi: vsi structure
  6956. * @seed: RSS hash seed
  6957. **/
  6958. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  6959. u8 *lut, u16 lut_size)
  6960. {
  6961. struct i40e_aqc_get_set_rss_key_data rss_key;
  6962. struct i40e_pf *pf = vsi->back;
  6963. struct i40e_hw *hw = &pf->hw;
  6964. bool pf_lut = false;
  6965. u8 *rss_lut;
  6966. int ret, i;
  6967. memset(&rss_key, 0, sizeof(rss_key));
  6968. memcpy(&rss_key, seed, sizeof(rss_key));
  6969. rss_lut = kzalloc(pf->rss_table_size, GFP_KERNEL);
  6970. if (!rss_lut)
  6971. return -ENOMEM;
  6972. /* Populate the LUT with max no. of queues in round robin fashion */
  6973. for (i = 0; i < vsi->rss_table_size; i++)
  6974. rss_lut[i] = i % vsi->rss_size;
  6975. ret = i40e_aq_set_rss_key(hw, vsi->id, &rss_key);
  6976. if (ret) {
  6977. dev_info(&pf->pdev->dev,
  6978. "Cannot set RSS key, err %s aq_err %s\n",
  6979. i40e_stat_str(&pf->hw, ret),
  6980. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6981. goto config_rss_aq_out;
  6982. }
  6983. if (vsi->type == I40E_VSI_MAIN)
  6984. pf_lut = true;
  6985. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, rss_lut,
  6986. vsi->rss_table_size);
  6987. if (ret)
  6988. dev_info(&pf->pdev->dev,
  6989. "Cannot set RSS lut, err %s aq_err %s\n",
  6990. i40e_stat_str(&pf->hw, ret),
  6991. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6992. config_rss_aq_out:
  6993. kfree(rss_lut);
  6994. return ret;
  6995. }
  6996. /**
  6997. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  6998. * @vsi: VSI structure
  6999. **/
  7000. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  7001. {
  7002. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7003. struct i40e_pf *pf = vsi->back;
  7004. u8 *lut;
  7005. int ret;
  7006. if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
  7007. return 0;
  7008. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7009. if (!lut)
  7010. return -ENOMEM;
  7011. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7012. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7013. vsi->rss_size = min_t(int, pf->alloc_rss_size, vsi->num_queue_pairs);
  7014. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  7015. kfree(lut);
  7016. return ret;
  7017. }
  7018. /**
  7019. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  7020. * @vsi: Pointer to vsi structure
  7021. * @seed: Buffter to store the hash keys
  7022. * @lut: Buffer to store the lookup table entries
  7023. * @lut_size: Size of buffer to store the lookup table entries
  7024. *
  7025. * Return 0 on success, negative on failure
  7026. */
  7027. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7028. u8 *lut, u16 lut_size)
  7029. {
  7030. struct i40e_pf *pf = vsi->back;
  7031. struct i40e_hw *hw = &pf->hw;
  7032. int ret = 0;
  7033. if (seed) {
  7034. ret = i40e_aq_get_rss_key(hw, vsi->id,
  7035. (struct i40e_aqc_get_set_rss_key_data *)seed);
  7036. if (ret) {
  7037. dev_info(&pf->pdev->dev,
  7038. "Cannot get RSS key, err %s aq_err %s\n",
  7039. i40e_stat_str(&pf->hw, ret),
  7040. i40e_aq_str(&pf->hw,
  7041. pf->hw.aq.asq_last_status));
  7042. return ret;
  7043. }
  7044. }
  7045. if (lut) {
  7046. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7047. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7048. if (ret) {
  7049. dev_info(&pf->pdev->dev,
  7050. "Cannot get RSS lut, err %s aq_err %s\n",
  7051. i40e_stat_str(&pf->hw, ret),
  7052. i40e_aq_str(&pf->hw,
  7053. pf->hw.aq.asq_last_status));
  7054. return ret;
  7055. }
  7056. }
  7057. return ret;
  7058. }
  7059. /**
  7060. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  7061. * @vsi: Pointer to vsi structure
  7062. * @seed: RSS hash seed
  7063. * @lut: Lookup table
  7064. * @lut_size: Lookup table size
  7065. *
  7066. * Returns 0 on success, negative on failure
  7067. **/
  7068. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  7069. const u8 *lut, u16 lut_size)
  7070. {
  7071. struct i40e_pf *pf = vsi->back;
  7072. struct i40e_hw *hw = &pf->hw;
  7073. u8 i;
  7074. /* Fill out hash function seed */
  7075. if (seed) {
  7076. u32 *seed_dw = (u32 *)seed;
  7077. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7078. i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  7079. }
  7080. if (lut) {
  7081. u32 *lut_dw = (u32 *)lut;
  7082. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7083. return -EINVAL;
  7084. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7085. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  7086. }
  7087. i40e_flush(hw);
  7088. return 0;
  7089. }
  7090. /**
  7091. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  7092. * @vsi: Pointer to VSI structure
  7093. * @seed: Buffer to store the keys
  7094. * @lut: Buffer to store the lookup table entries
  7095. * @lut_size: Size of buffer to store the lookup table entries
  7096. *
  7097. * Returns 0 on success, negative on failure
  7098. */
  7099. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  7100. u8 *lut, u16 lut_size)
  7101. {
  7102. struct i40e_pf *pf = vsi->back;
  7103. struct i40e_hw *hw = &pf->hw;
  7104. u16 i;
  7105. if (seed) {
  7106. u32 *seed_dw = (u32 *)seed;
  7107. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7108. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  7109. }
  7110. if (lut) {
  7111. u32 *lut_dw = (u32 *)lut;
  7112. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7113. return -EINVAL;
  7114. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7115. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  7116. }
  7117. return 0;
  7118. }
  7119. /**
  7120. * i40e_config_rss - Configure RSS keys and lut
  7121. * @vsi: Pointer to VSI structure
  7122. * @seed: RSS hash seed
  7123. * @lut: Lookup table
  7124. * @lut_size: Lookup table size
  7125. *
  7126. * Returns 0 on success, negative on failure
  7127. */
  7128. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7129. {
  7130. struct i40e_pf *pf = vsi->back;
  7131. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7132. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  7133. else
  7134. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  7135. }
  7136. /**
  7137. * i40e_get_rss - Get RSS keys and lut
  7138. * @vsi: Pointer to VSI structure
  7139. * @seed: Buffer to store the keys
  7140. * @lut: Buffer to store the lookup table entries
  7141. * lut_size: Size of buffer to store the lookup table entries
  7142. *
  7143. * Returns 0 on success, negative on failure
  7144. */
  7145. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7146. {
  7147. struct i40e_pf *pf = vsi->back;
  7148. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7149. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  7150. else
  7151. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  7152. }
  7153. /**
  7154. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  7155. * @pf: Pointer to board private structure
  7156. * @lut: Lookup table
  7157. * @rss_table_size: Lookup table size
  7158. * @rss_size: Range of queue number for hashing
  7159. */
  7160. static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  7161. u16 rss_table_size, u16 rss_size)
  7162. {
  7163. u16 i;
  7164. for (i = 0; i < rss_table_size; i++)
  7165. lut[i] = i % rss_size;
  7166. }
  7167. /**
  7168. * i40e_pf_config_rss - Prepare for RSS if used
  7169. * @pf: board private structure
  7170. **/
  7171. static int i40e_pf_config_rss(struct i40e_pf *pf)
  7172. {
  7173. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7174. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7175. u8 *lut;
  7176. struct i40e_hw *hw = &pf->hw;
  7177. u32 reg_val;
  7178. u64 hena;
  7179. int ret;
  7180. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  7181. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  7182. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  7183. hena |= i40e_pf_get_default_rss_hena(pf);
  7184. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  7185. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  7186. /* Determine the RSS table size based on the hardware capabilities */
  7187. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  7188. reg_val = (pf->rss_table_size == 512) ?
  7189. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  7190. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  7191. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  7192. /* Determine the RSS size of the VSI */
  7193. if (!vsi->rss_size)
  7194. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7195. vsi->num_queue_pairs);
  7196. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7197. if (!lut)
  7198. return -ENOMEM;
  7199. /* Use user configured lut if there is one, otherwise use default */
  7200. if (vsi->rss_lut_user)
  7201. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7202. else
  7203. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7204. /* Use user configured hash key if there is one, otherwise
  7205. * use default.
  7206. */
  7207. if (vsi->rss_hkey_user)
  7208. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7209. else
  7210. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7211. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  7212. kfree(lut);
  7213. return ret;
  7214. }
  7215. /**
  7216. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  7217. * @pf: board private structure
  7218. * @queue_count: the requested queue count for rss.
  7219. *
  7220. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  7221. * count which may be different from the requested queue count.
  7222. **/
  7223. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  7224. {
  7225. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7226. int new_rss_size;
  7227. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  7228. return 0;
  7229. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  7230. if (queue_count != vsi->num_queue_pairs) {
  7231. vsi->req_queue_pairs = queue_count;
  7232. i40e_prep_for_reset(pf);
  7233. pf->alloc_rss_size = new_rss_size;
  7234. i40e_reset_and_rebuild(pf, true);
  7235. /* Discard the user configured hash keys and lut, if less
  7236. * queues are enabled.
  7237. */
  7238. if (queue_count < vsi->rss_size) {
  7239. i40e_clear_rss_config_user(vsi);
  7240. dev_dbg(&pf->pdev->dev,
  7241. "discard user configured hash keys and lut\n");
  7242. }
  7243. /* Reset vsi->rss_size, as number of enabled queues changed */
  7244. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7245. vsi->num_queue_pairs);
  7246. i40e_pf_config_rss(pf);
  7247. }
  7248. dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n",
  7249. pf->alloc_rss_size, pf->rss_size_max);
  7250. return pf->alloc_rss_size;
  7251. }
  7252. /**
  7253. * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
  7254. * @pf: board private structure
  7255. **/
  7256. i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
  7257. {
  7258. i40e_status status;
  7259. bool min_valid, max_valid;
  7260. u32 max_bw, min_bw;
  7261. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  7262. &min_valid, &max_valid);
  7263. if (!status) {
  7264. if (min_valid)
  7265. pf->npar_min_bw = min_bw;
  7266. if (max_valid)
  7267. pf->npar_max_bw = max_bw;
  7268. }
  7269. return status;
  7270. }
  7271. /**
  7272. * i40e_set_npar_bw_setting - Set BW settings for this PF partition
  7273. * @pf: board private structure
  7274. **/
  7275. i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
  7276. {
  7277. struct i40e_aqc_configure_partition_bw_data bw_data;
  7278. i40e_status status;
  7279. /* Set the valid bit for this PF */
  7280. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  7281. bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
  7282. bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
  7283. /* Set the new bandwidths */
  7284. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  7285. return status;
  7286. }
  7287. /**
  7288. * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
  7289. * @pf: board private structure
  7290. **/
  7291. i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
  7292. {
  7293. /* Commit temporary BW setting to permanent NVM image */
  7294. enum i40e_admin_queue_err last_aq_status;
  7295. i40e_status ret;
  7296. u16 nvm_word;
  7297. if (pf->hw.partition_id != 1) {
  7298. dev_info(&pf->pdev->dev,
  7299. "Commit BW only works on partition 1! This is partition %d",
  7300. pf->hw.partition_id);
  7301. ret = I40E_NOT_SUPPORTED;
  7302. goto bw_commit_out;
  7303. }
  7304. /* Acquire NVM for read access */
  7305. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  7306. last_aq_status = pf->hw.aq.asq_last_status;
  7307. if (ret) {
  7308. dev_info(&pf->pdev->dev,
  7309. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  7310. i40e_stat_str(&pf->hw, ret),
  7311. i40e_aq_str(&pf->hw, last_aq_status));
  7312. goto bw_commit_out;
  7313. }
  7314. /* Read word 0x10 of NVM - SW compatibility word 1 */
  7315. ret = i40e_aq_read_nvm(&pf->hw,
  7316. I40E_SR_NVM_CONTROL_WORD,
  7317. 0x10, sizeof(nvm_word), &nvm_word,
  7318. false, NULL);
  7319. /* Save off last admin queue command status before releasing
  7320. * the NVM
  7321. */
  7322. last_aq_status = pf->hw.aq.asq_last_status;
  7323. i40e_release_nvm(&pf->hw);
  7324. if (ret) {
  7325. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  7326. i40e_stat_str(&pf->hw, ret),
  7327. i40e_aq_str(&pf->hw, last_aq_status));
  7328. goto bw_commit_out;
  7329. }
  7330. /* Wait a bit for NVM release to complete */
  7331. msleep(50);
  7332. /* Acquire NVM for write access */
  7333. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  7334. last_aq_status = pf->hw.aq.asq_last_status;
  7335. if (ret) {
  7336. dev_info(&pf->pdev->dev,
  7337. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  7338. i40e_stat_str(&pf->hw, ret),
  7339. i40e_aq_str(&pf->hw, last_aq_status));
  7340. goto bw_commit_out;
  7341. }
  7342. /* Write it back out unchanged to initiate update NVM,
  7343. * which will force a write of the shadow (alt) RAM to
  7344. * the NVM - thus storing the bandwidth values permanently.
  7345. */
  7346. ret = i40e_aq_update_nvm(&pf->hw,
  7347. I40E_SR_NVM_CONTROL_WORD,
  7348. 0x10, sizeof(nvm_word),
  7349. &nvm_word, true, NULL);
  7350. /* Save off last admin queue command status before releasing
  7351. * the NVM
  7352. */
  7353. last_aq_status = pf->hw.aq.asq_last_status;
  7354. i40e_release_nvm(&pf->hw);
  7355. if (ret)
  7356. dev_info(&pf->pdev->dev,
  7357. "BW settings NOT SAVED, err %s aq_err %s\n",
  7358. i40e_stat_str(&pf->hw, ret),
  7359. i40e_aq_str(&pf->hw, last_aq_status));
  7360. bw_commit_out:
  7361. return ret;
  7362. }
  7363. /**
  7364. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  7365. * @pf: board private structure to initialize
  7366. *
  7367. * i40e_sw_init initializes the Adapter private data structure.
  7368. * Fields are initialized based on PCI device information and
  7369. * OS network device settings (MTU size).
  7370. **/
  7371. static int i40e_sw_init(struct i40e_pf *pf)
  7372. {
  7373. int err = 0;
  7374. int size;
  7375. pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
  7376. (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
  7377. pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
  7378. if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
  7379. if (I40E_DEBUG_USER & debug)
  7380. pf->hw.debug_mask = debug;
  7381. pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
  7382. I40E_DEFAULT_MSG_ENABLE);
  7383. }
  7384. /* Set default capability flags */
  7385. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  7386. I40E_FLAG_MSI_ENABLED |
  7387. I40E_FLAG_MSIX_ENABLED;
  7388. if (iommu_present(&pci_bus_type))
  7389. pf->flags |= I40E_FLAG_RX_PS_ENABLED;
  7390. else
  7391. pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
  7392. /* Set default ITR */
  7393. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  7394. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  7395. /* Depending on PF configurations, it is possible that the RSS
  7396. * maximum might end up larger than the available queues
  7397. */
  7398. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  7399. pf->alloc_rss_size = 1;
  7400. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  7401. pf->rss_size_max = min_t(int, pf->rss_size_max,
  7402. pf->hw.func_caps.num_tx_qp);
  7403. if (pf->hw.func_caps.rss) {
  7404. pf->flags |= I40E_FLAG_RSS_ENABLED;
  7405. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  7406. num_online_cpus());
  7407. }
  7408. /* MFP mode enabled */
  7409. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  7410. pf->flags |= I40E_FLAG_MFP_ENABLED;
  7411. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  7412. if (i40e_get_npar_bw_setting(pf))
  7413. dev_warn(&pf->pdev->dev,
  7414. "Could not get NPAR bw settings\n");
  7415. else
  7416. dev_info(&pf->pdev->dev,
  7417. "Min BW = %8.8x, Max BW = %8.8x\n",
  7418. pf->npar_min_bw, pf->npar_max_bw);
  7419. }
  7420. /* FW/NVM is not yet fixed in this regard */
  7421. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  7422. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  7423. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  7424. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  7425. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  7426. pf->hw.num_partitions > 1)
  7427. dev_info(&pf->pdev->dev,
  7428. "Flow Director Sideband mode Disabled in MFP mode\n");
  7429. else
  7430. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7431. pf->fdir_pf_filter_count =
  7432. pf->hw.func_caps.fd_filters_guaranteed;
  7433. pf->hw.fdir_shared_filter_count =
  7434. pf->hw.func_caps.fd_filters_best_effort;
  7435. }
  7436. if (i40e_is_mac_710(&pf->hw) &&
  7437. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  7438. (pf->hw.aq.fw_maj_ver < 4))) {
  7439. pf->flags |= I40E_FLAG_RESTART_AUTONEG;
  7440. /* No DCB support for FW < v4.33 */
  7441. pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
  7442. }
  7443. /* Disable FW LLDP if FW < v4.3 */
  7444. if (i40e_is_mac_710(&pf->hw) &&
  7445. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  7446. (pf->hw.aq.fw_maj_ver < 4)))
  7447. pf->flags |= I40E_FLAG_STOP_FW_LLDP;
  7448. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  7449. if (i40e_is_mac_710(&pf->hw) &&
  7450. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  7451. (pf->hw.aq.fw_maj_ver >= 5)))
  7452. pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
  7453. if (pf->hw.func_caps.vmdq) {
  7454. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  7455. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  7456. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  7457. }
  7458. if (pf->hw.func_caps.iwarp) {
  7459. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  7460. /* IWARP needs one extra vector for CQP just like MISC.*/
  7461. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  7462. }
  7463. #ifdef I40E_FCOE
  7464. i40e_init_pf_fcoe(pf);
  7465. #endif /* I40E_FCOE */
  7466. #ifdef CONFIG_PCI_IOV
  7467. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  7468. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  7469. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  7470. pf->num_req_vfs = min_t(int,
  7471. pf->hw.func_caps.num_vfs,
  7472. I40E_MAX_VF_COUNT);
  7473. }
  7474. #endif /* CONFIG_PCI_IOV */
  7475. if (pf->hw.mac.type == I40E_MAC_X722) {
  7476. pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
  7477. I40E_FLAG_128_QP_RSS_CAPABLE |
  7478. I40E_FLAG_HW_ATR_EVICT_CAPABLE |
  7479. I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
  7480. I40E_FLAG_WB_ON_ITR_CAPABLE |
  7481. I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  7482. I40E_FLAG_100M_SGMII_CAPABLE |
  7483. I40E_FLAG_USE_SET_LLDP_MIB |
  7484. I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7485. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  7486. ((pf->hw.aq.api_maj_ver == 1) &&
  7487. (pf->hw.aq.api_min_ver > 4))) {
  7488. /* Supported in FW API version higher than 1.4 */
  7489. pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7490. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7491. } else {
  7492. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7493. }
  7494. pf->eeprom_version = 0xDEAD;
  7495. pf->lan_veb = I40E_NO_VEB;
  7496. pf->lan_vsi = I40E_NO_VSI;
  7497. /* By default FW has this off for performance reasons */
  7498. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  7499. /* set up queue assignment tracking */
  7500. size = sizeof(struct i40e_lump_tracking)
  7501. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  7502. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  7503. if (!pf->qp_pile) {
  7504. err = -ENOMEM;
  7505. goto sw_init_done;
  7506. }
  7507. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  7508. pf->qp_pile->search_hint = 0;
  7509. pf->tx_timeout_recovery_level = 1;
  7510. mutex_init(&pf->switch_mutex);
  7511. /* If NPAR is enabled nudge the Tx scheduler */
  7512. if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
  7513. i40e_set_npar_bw_setting(pf);
  7514. sw_init_done:
  7515. return err;
  7516. }
  7517. /**
  7518. * i40e_set_ntuple - set the ntuple feature flag and take action
  7519. * @pf: board private structure to initialize
  7520. * @features: the feature set that the stack is suggesting
  7521. *
  7522. * returns a bool to indicate if reset needs to happen
  7523. **/
  7524. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  7525. {
  7526. bool need_reset = false;
  7527. /* Check if Flow Director n-tuple support was enabled or disabled. If
  7528. * the state changed, we need to reset.
  7529. */
  7530. if (features & NETIF_F_NTUPLE) {
  7531. /* Enable filters and mark for reset */
  7532. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7533. need_reset = true;
  7534. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7535. } else {
  7536. /* turn off filters, mark for reset and clear SW filter list */
  7537. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7538. need_reset = true;
  7539. i40e_fdir_filter_exit(pf);
  7540. }
  7541. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7542. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7543. /* reset fd counters */
  7544. pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
  7545. pf->fdir_pf_active_filters = 0;
  7546. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  7547. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7548. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  7549. /* if ATR was auto disabled it can be re-enabled. */
  7550. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7551. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
  7552. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  7553. }
  7554. return need_reset;
  7555. }
  7556. /**
  7557. * i40e_set_features - set the netdev feature flags
  7558. * @netdev: ptr to the netdev being adjusted
  7559. * @features: the feature set that the stack is suggesting
  7560. **/
  7561. static int i40e_set_features(struct net_device *netdev,
  7562. netdev_features_t features)
  7563. {
  7564. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7565. struct i40e_vsi *vsi = np->vsi;
  7566. struct i40e_pf *pf = vsi->back;
  7567. bool need_reset;
  7568. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  7569. i40e_vlan_stripping_enable(vsi);
  7570. else
  7571. i40e_vlan_stripping_disable(vsi);
  7572. need_reset = i40e_set_ntuple(pf, features);
  7573. if (need_reset)
  7574. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7575. return 0;
  7576. }
  7577. #if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
  7578. /**
  7579. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  7580. * @pf: board private structure
  7581. * @port: The UDP port to look up
  7582. *
  7583. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  7584. **/
  7585. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
  7586. {
  7587. u8 i;
  7588. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  7589. if (pf->udp_ports[i].index == port)
  7590. return i;
  7591. }
  7592. return i;
  7593. }
  7594. #endif
  7595. #if IS_ENABLED(CONFIG_VXLAN)
  7596. /**
  7597. * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
  7598. * @netdev: This physical port's netdev
  7599. * @sa_family: Socket Family that VXLAN is notifying us about
  7600. * @port: New UDP port number that VXLAN started listening to
  7601. **/
  7602. static void i40e_add_vxlan_port(struct net_device *netdev,
  7603. sa_family_t sa_family, __be16 port)
  7604. {
  7605. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7606. struct i40e_vsi *vsi = np->vsi;
  7607. struct i40e_pf *pf = vsi->back;
  7608. u8 next_idx;
  7609. u8 idx;
  7610. idx = i40e_get_udp_port_idx(pf, port);
  7611. /* Check if port already exists */
  7612. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7613. netdev_info(netdev, "vxlan port %d already offloaded\n",
  7614. ntohs(port));
  7615. return;
  7616. }
  7617. /* Now check if there is space to add the new port */
  7618. next_idx = i40e_get_udp_port_idx(pf, 0);
  7619. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7620. netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n",
  7621. ntohs(port));
  7622. return;
  7623. }
  7624. /* New port: add it and mark its index in the bitmap */
  7625. pf->udp_ports[next_idx].index = port;
  7626. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  7627. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  7628. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7629. }
  7630. /**
  7631. * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
  7632. * @netdev: This physical port's netdev
  7633. * @sa_family: Socket Family that VXLAN is notifying us about
  7634. * @port: UDP port number that VXLAN stopped listening to
  7635. **/
  7636. static void i40e_del_vxlan_port(struct net_device *netdev,
  7637. sa_family_t sa_family, __be16 port)
  7638. {
  7639. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7640. struct i40e_vsi *vsi = np->vsi;
  7641. struct i40e_pf *pf = vsi->back;
  7642. u8 idx;
  7643. idx = i40e_get_udp_port_idx(pf, port);
  7644. /* Check if port already exists */
  7645. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7646. /* if port exists, set it to 0 (mark for deletion)
  7647. * and make it pending
  7648. */
  7649. pf->udp_ports[idx].index = 0;
  7650. pf->pending_udp_bitmap |= BIT_ULL(idx);
  7651. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7652. } else {
  7653. netdev_warn(netdev, "vxlan port %d was not found, not deleting\n",
  7654. ntohs(port));
  7655. }
  7656. }
  7657. #endif
  7658. #if IS_ENABLED(CONFIG_GENEVE)
  7659. /**
  7660. * i40e_add_geneve_port - Get notifications about GENEVE ports that come up
  7661. * @netdev: This physical port's netdev
  7662. * @sa_family: Socket Family that GENEVE is notifying us about
  7663. * @port: New UDP port number that GENEVE started listening to
  7664. **/
  7665. static void i40e_add_geneve_port(struct net_device *netdev,
  7666. sa_family_t sa_family, __be16 port)
  7667. {
  7668. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7669. struct i40e_vsi *vsi = np->vsi;
  7670. struct i40e_pf *pf = vsi->back;
  7671. u8 next_idx;
  7672. u8 idx;
  7673. if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7674. return;
  7675. idx = i40e_get_udp_port_idx(pf, port);
  7676. /* Check if port already exists */
  7677. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7678. netdev_info(netdev, "udp port %d already offloaded\n",
  7679. ntohs(port));
  7680. return;
  7681. }
  7682. /* Now check if there is space to add the new port */
  7683. next_idx = i40e_get_udp_port_idx(pf, 0);
  7684. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7685. netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n",
  7686. ntohs(port));
  7687. return;
  7688. }
  7689. /* New port: add it and mark its index in the bitmap */
  7690. pf->udp_ports[next_idx].index = port;
  7691. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  7692. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  7693. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7694. dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port));
  7695. }
  7696. /**
  7697. * i40e_del_geneve_port - Get notifications about GENEVE ports that go away
  7698. * @netdev: This physical port's netdev
  7699. * @sa_family: Socket Family that GENEVE is notifying us about
  7700. * @port: UDP port number that GENEVE stopped listening to
  7701. **/
  7702. static void i40e_del_geneve_port(struct net_device *netdev,
  7703. sa_family_t sa_family, __be16 port)
  7704. {
  7705. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7706. struct i40e_vsi *vsi = np->vsi;
  7707. struct i40e_pf *pf = vsi->back;
  7708. u8 idx;
  7709. if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7710. return;
  7711. idx = i40e_get_udp_port_idx(pf, port);
  7712. /* Check if port already exists */
  7713. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7714. /* if port exists, set it to 0 (mark for deletion)
  7715. * and make it pending
  7716. */
  7717. pf->udp_ports[idx].index = 0;
  7718. pf->pending_udp_bitmap |= BIT_ULL(idx);
  7719. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7720. dev_info(&pf->pdev->dev, "deleting geneve port %d\n",
  7721. ntohs(port));
  7722. } else {
  7723. netdev_warn(netdev, "geneve port %d was not found, not deleting\n",
  7724. ntohs(port));
  7725. }
  7726. }
  7727. #endif
  7728. static int i40e_get_phys_port_id(struct net_device *netdev,
  7729. struct netdev_phys_item_id *ppid)
  7730. {
  7731. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7732. struct i40e_pf *pf = np->vsi->back;
  7733. struct i40e_hw *hw = &pf->hw;
  7734. if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
  7735. return -EOPNOTSUPP;
  7736. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  7737. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  7738. return 0;
  7739. }
  7740. /**
  7741. * i40e_ndo_fdb_add - add an entry to the hardware database
  7742. * @ndm: the input from the stack
  7743. * @tb: pointer to array of nladdr (unused)
  7744. * @dev: the net device pointer
  7745. * @addr: the MAC address entry being added
  7746. * @flags: instructions from stack about fdb operation
  7747. */
  7748. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  7749. struct net_device *dev,
  7750. const unsigned char *addr, u16 vid,
  7751. u16 flags)
  7752. {
  7753. struct i40e_netdev_priv *np = netdev_priv(dev);
  7754. struct i40e_pf *pf = np->vsi->back;
  7755. int err = 0;
  7756. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  7757. return -EOPNOTSUPP;
  7758. if (vid) {
  7759. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  7760. return -EINVAL;
  7761. }
  7762. /* Hardware does not support aging addresses so if a
  7763. * ndm_state is given only allow permanent addresses
  7764. */
  7765. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  7766. netdev_info(dev, "FDB only supports static addresses\n");
  7767. return -EINVAL;
  7768. }
  7769. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  7770. err = dev_uc_add_excl(dev, addr);
  7771. else if (is_multicast_ether_addr(addr))
  7772. err = dev_mc_add_excl(dev, addr);
  7773. else
  7774. err = -EINVAL;
  7775. /* Only return duplicate errors if NLM_F_EXCL is set */
  7776. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  7777. err = 0;
  7778. return err;
  7779. }
  7780. /**
  7781. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  7782. * @dev: the netdev being configured
  7783. * @nlh: RTNL message
  7784. *
  7785. * Inserts a new hardware bridge if not already created and
  7786. * enables the bridging mode requested (VEB or VEPA). If the
  7787. * hardware bridge has already been inserted and the request
  7788. * is to change the mode then that requires a PF reset to
  7789. * allow rebuild of the components with required hardware
  7790. * bridge mode enabled.
  7791. **/
  7792. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  7793. struct nlmsghdr *nlh,
  7794. u16 flags)
  7795. {
  7796. struct i40e_netdev_priv *np = netdev_priv(dev);
  7797. struct i40e_vsi *vsi = np->vsi;
  7798. struct i40e_pf *pf = vsi->back;
  7799. struct i40e_veb *veb = NULL;
  7800. struct nlattr *attr, *br_spec;
  7801. int i, rem;
  7802. /* Only for PF VSI for now */
  7803. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  7804. return -EOPNOTSUPP;
  7805. /* Find the HW bridge for PF VSI */
  7806. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7807. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7808. veb = pf->veb[i];
  7809. }
  7810. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  7811. nla_for_each_nested(attr, br_spec, rem) {
  7812. __u16 mode;
  7813. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  7814. continue;
  7815. mode = nla_get_u16(attr);
  7816. if ((mode != BRIDGE_MODE_VEPA) &&
  7817. (mode != BRIDGE_MODE_VEB))
  7818. return -EINVAL;
  7819. /* Insert a new HW bridge */
  7820. if (!veb) {
  7821. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  7822. vsi->tc_config.enabled_tc);
  7823. if (veb) {
  7824. veb->bridge_mode = mode;
  7825. i40e_config_bridge_mode(veb);
  7826. } else {
  7827. /* No Bridge HW offload available */
  7828. return -ENOENT;
  7829. }
  7830. break;
  7831. } else if (mode != veb->bridge_mode) {
  7832. /* Existing HW bridge but different mode needs reset */
  7833. veb->bridge_mode = mode;
  7834. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  7835. if (mode == BRIDGE_MODE_VEB)
  7836. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  7837. else
  7838. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  7839. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7840. break;
  7841. }
  7842. }
  7843. return 0;
  7844. }
  7845. /**
  7846. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  7847. * @skb: skb buff
  7848. * @pid: process id
  7849. * @seq: RTNL message seq #
  7850. * @dev: the netdev being configured
  7851. * @filter_mask: unused
  7852. * @nlflags: netlink flags passed in
  7853. *
  7854. * Return the mode in which the hardware bridge is operating in
  7855. * i.e VEB or VEPA.
  7856. **/
  7857. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  7858. struct net_device *dev,
  7859. u32 __always_unused filter_mask,
  7860. int nlflags)
  7861. {
  7862. struct i40e_netdev_priv *np = netdev_priv(dev);
  7863. struct i40e_vsi *vsi = np->vsi;
  7864. struct i40e_pf *pf = vsi->back;
  7865. struct i40e_veb *veb = NULL;
  7866. int i;
  7867. /* Only for PF VSI for now */
  7868. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  7869. return -EOPNOTSUPP;
  7870. /* Find the HW bridge for the PF VSI */
  7871. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7872. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7873. veb = pf->veb[i];
  7874. }
  7875. if (!veb)
  7876. return 0;
  7877. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  7878. nlflags, 0, 0, filter_mask, NULL);
  7879. }
  7880. /* Hardware supports L4 tunnel length of 128B (=2^7) which includes
  7881. * inner mac plus all inner ethertypes.
  7882. */
  7883. #define I40E_MAX_TUNNEL_HDR_LEN 128
  7884. /**
  7885. * i40e_features_check - Validate encapsulated packet conforms to limits
  7886. * @skb: skb buff
  7887. * @dev: This physical port's netdev
  7888. * @features: Offload features that the stack believes apply
  7889. **/
  7890. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  7891. struct net_device *dev,
  7892. netdev_features_t features)
  7893. {
  7894. if (skb->encapsulation &&
  7895. ((skb_inner_network_header(skb) - skb_transport_header(skb)) >
  7896. I40E_MAX_TUNNEL_HDR_LEN))
  7897. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  7898. return features;
  7899. }
  7900. static const struct net_device_ops i40e_netdev_ops = {
  7901. .ndo_open = i40e_open,
  7902. .ndo_stop = i40e_close,
  7903. .ndo_start_xmit = i40e_lan_xmit_frame,
  7904. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  7905. .ndo_set_rx_mode = i40e_set_rx_mode,
  7906. .ndo_validate_addr = eth_validate_addr,
  7907. .ndo_set_mac_address = i40e_set_mac,
  7908. .ndo_change_mtu = i40e_change_mtu,
  7909. .ndo_do_ioctl = i40e_ioctl,
  7910. .ndo_tx_timeout = i40e_tx_timeout,
  7911. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  7912. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  7913. #ifdef CONFIG_NET_POLL_CONTROLLER
  7914. .ndo_poll_controller = i40e_netpoll,
  7915. #endif
  7916. .ndo_setup_tc = __i40e_setup_tc,
  7917. #ifdef I40E_FCOE
  7918. .ndo_fcoe_enable = i40e_fcoe_enable,
  7919. .ndo_fcoe_disable = i40e_fcoe_disable,
  7920. #endif
  7921. .ndo_set_features = i40e_set_features,
  7922. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  7923. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  7924. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  7925. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  7926. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  7927. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  7928. #if IS_ENABLED(CONFIG_VXLAN)
  7929. .ndo_add_vxlan_port = i40e_add_vxlan_port,
  7930. .ndo_del_vxlan_port = i40e_del_vxlan_port,
  7931. #endif
  7932. #if IS_ENABLED(CONFIG_GENEVE)
  7933. .ndo_add_geneve_port = i40e_add_geneve_port,
  7934. .ndo_del_geneve_port = i40e_del_geneve_port,
  7935. #endif
  7936. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  7937. .ndo_fdb_add = i40e_ndo_fdb_add,
  7938. .ndo_features_check = i40e_features_check,
  7939. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  7940. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  7941. };
  7942. /**
  7943. * i40e_config_netdev - Setup the netdev flags
  7944. * @vsi: the VSI being configured
  7945. *
  7946. * Returns 0 on success, negative value on failure
  7947. **/
  7948. static int i40e_config_netdev(struct i40e_vsi *vsi)
  7949. {
  7950. u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  7951. struct i40e_pf *pf = vsi->back;
  7952. struct i40e_hw *hw = &pf->hw;
  7953. struct i40e_netdev_priv *np;
  7954. struct net_device *netdev;
  7955. u8 mac_addr[ETH_ALEN];
  7956. int etherdev_size;
  7957. etherdev_size = sizeof(struct i40e_netdev_priv);
  7958. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  7959. if (!netdev)
  7960. return -ENOMEM;
  7961. vsi->netdev = netdev;
  7962. np = netdev_priv(netdev);
  7963. np->vsi = vsi;
  7964. netdev->hw_enc_features |= NETIF_F_IP_CSUM |
  7965. NETIF_F_IPV6_CSUM |
  7966. NETIF_F_TSO |
  7967. NETIF_F_TSO6 |
  7968. NETIF_F_TSO_ECN |
  7969. NETIF_F_GSO_GRE |
  7970. NETIF_F_GSO_UDP_TUNNEL |
  7971. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  7972. 0;
  7973. netdev->features = NETIF_F_SG |
  7974. NETIF_F_IP_CSUM |
  7975. NETIF_F_SCTP_CRC |
  7976. NETIF_F_HIGHDMA |
  7977. NETIF_F_GSO_UDP_TUNNEL |
  7978. NETIF_F_GSO_GRE |
  7979. NETIF_F_HW_VLAN_CTAG_TX |
  7980. NETIF_F_HW_VLAN_CTAG_RX |
  7981. NETIF_F_HW_VLAN_CTAG_FILTER |
  7982. NETIF_F_IPV6_CSUM |
  7983. NETIF_F_TSO |
  7984. NETIF_F_TSO_ECN |
  7985. NETIF_F_TSO6 |
  7986. NETIF_F_RXCSUM |
  7987. NETIF_F_RXHASH |
  7988. 0;
  7989. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  7990. netdev->features |= NETIF_F_NTUPLE;
  7991. if (pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE)
  7992. netdev->features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  7993. /* copy netdev features into list of user selectable features */
  7994. netdev->hw_features |= netdev->features;
  7995. if (vsi->type == I40E_VSI_MAIN) {
  7996. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  7997. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  7998. /* The following steps are necessary to prevent reception
  7999. * of tagged packets - some older NVM configurations load a
  8000. * default a MAC-VLAN filter that accepts any tagged packet
  8001. * which must be replaced by a normal filter.
  8002. */
  8003. if (!i40e_rm_default_mac_filter(vsi, mac_addr)) {
  8004. spin_lock_bh(&vsi->mac_filter_list_lock);
  8005. i40e_add_filter(vsi, mac_addr,
  8006. I40E_VLAN_ANY, false, true);
  8007. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8008. }
  8009. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  8010. ((pf->hw.aq.api_maj_ver == 1) &&
  8011. (pf->hw.aq.api_min_ver > 4))) {
  8012. /* Supported in FW API version higher than 1.4 */
  8013. pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  8014. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  8015. } else {
  8016. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  8017. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  8018. pf->vsi[pf->lan_vsi]->netdev->name);
  8019. random_ether_addr(mac_addr);
  8020. spin_lock_bh(&vsi->mac_filter_list_lock);
  8021. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
  8022. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8023. }
  8024. spin_lock_bh(&vsi->mac_filter_list_lock);
  8025. i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
  8026. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8027. ether_addr_copy(netdev->dev_addr, mac_addr);
  8028. ether_addr_copy(netdev->perm_addr, mac_addr);
  8029. /* vlan gets same features (except vlan offload)
  8030. * after any tweaks for specific VSI types
  8031. */
  8032. netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
  8033. NETIF_F_HW_VLAN_CTAG_RX |
  8034. NETIF_F_HW_VLAN_CTAG_FILTER);
  8035. netdev->priv_flags |= IFF_UNICAST_FLT;
  8036. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8037. /* Setup netdev TC information */
  8038. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  8039. netdev->netdev_ops = &i40e_netdev_ops;
  8040. netdev->watchdog_timeo = 5 * HZ;
  8041. i40e_set_ethtool_ops(netdev);
  8042. #ifdef I40E_FCOE
  8043. i40e_fcoe_config_netdev(netdev, vsi);
  8044. #endif
  8045. return 0;
  8046. }
  8047. /**
  8048. * i40e_vsi_delete - Delete a VSI from the switch
  8049. * @vsi: the VSI being removed
  8050. *
  8051. * Returns 0 on success, negative value on failure
  8052. **/
  8053. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  8054. {
  8055. /* remove default VSI is not allowed */
  8056. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  8057. return;
  8058. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  8059. }
  8060. /**
  8061. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  8062. * @vsi: the VSI being queried
  8063. *
  8064. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  8065. **/
  8066. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  8067. {
  8068. struct i40e_veb *veb;
  8069. struct i40e_pf *pf = vsi->back;
  8070. /* Uplink is not a bridge so default to VEB */
  8071. if (vsi->veb_idx == I40E_NO_VEB)
  8072. return 1;
  8073. veb = pf->veb[vsi->veb_idx];
  8074. if (!veb) {
  8075. dev_info(&pf->pdev->dev,
  8076. "There is no veb associated with the bridge\n");
  8077. return -ENOENT;
  8078. }
  8079. /* Uplink is a bridge in VEPA mode */
  8080. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  8081. return 0;
  8082. } else {
  8083. /* Uplink is a bridge in VEB mode */
  8084. return 1;
  8085. }
  8086. /* VEPA is now default bridge, so return 0 */
  8087. return 0;
  8088. }
  8089. /**
  8090. * i40e_add_vsi - Add a VSI to the switch
  8091. * @vsi: the VSI being configured
  8092. *
  8093. * This initializes a VSI context depending on the VSI type to be added and
  8094. * passes it down to the add_vsi aq command.
  8095. **/
  8096. static int i40e_add_vsi(struct i40e_vsi *vsi)
  8097. {
  8098. int ret = -ENODEV;
  8099. u8 laa_macaddr[ETH_ALEN];
  8100. bool found_laa_mac_filter = false;
  8101. struct i40e_pf *pf = vsi->back;
  8102. struct i40e_hw *hw = &pf->hw;
  8103. struct i40e_vsi_context ctxt;
  8104. struct i40e_mac_filter *f, *ftmp;
  8105. u8 enabled_tc = 0x1; /* TC0 enabled */
  8106. int f_count = 0;
  8107. memset(&ctxt, 0, sizeof(ctxt));
  8108. switch (vsi->type) {
  8109. case I40E_VSI_MAIN:
  8110. /* The PF's main VSI is already setup as part of the
  8111. * device initialization, so we'll not bother with
  8112. * the add_vsi call, but we will retrieve the current
  8113. * VSI context.
  8114. */
  8115. ctxt.seid = pf->main_vsi_seid;
  8116. ctxt.pf_num = pf->hw.pf_id;
  8117. ctxt.vf_num = 0;
  8118. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  8119. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8120. if (ret) {
  8121. dev_info(&pf->pdev->dev,
  8122. "couldn't get PF vsi config, err %s aq_err %s\n",
  8123. i40e_stat_str(&pf->hw, ret),
  8124. i40e_aq_str(&pf->hw,
  8125. pf->hw.aq.asq_last_status));
  8126. return -ENOENT;
  8127. }
  8128. vsi->info = ctxt.info;
  8129. vsi->info.valid_sections = 0;
  8130. vsi->seid = ctxt.seid;
  8131. vsi->id = ctxt.vsi_number;
  8132. enabled_tc = i40e_pf_get_tc_map(pf);
  8133. /* MFP mode setup queue map and update VSI */
  8134. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  8135. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  8136. memset(&ctxt, 0, sizeof(ctxt));
  8137. ctxt.seid = pf->main_vsi_seid;
  8138. ctxt.pf_num = pf->hw.pf_id;
  8139. ctxt.vf_num = 0;
  8140. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  8141. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  8142. if (ret) {
  8143. dev_info(&pf->pdev->dev,
  8144. "update vsi failed, err %s aq_err %s\n",
  8145. i40e_stat_str(&pf->hw, ret),
  8146. i40e_aq_str(&pf->hw,
  8147. pf->hw.aq.asq_last_status));
  8148. ret = -ENOENT;
  8149. goto err;
  8150. }
  8151. /* update the local VSI info queue map */
  8152. i40e_vsi_update_queue_map(vsi, &ctxt);
  8153. vsi->info.valid_sections = 0;
  8154. } else {
  8155. /* Default/Main VSI is only enabled for TC0
  8156. * reconfigure it to enable all TCs that are
  8157. * available on the port in SFP mode.
  8158. * For MFP case the iSCSI PF would use this
  8159. * flow to enable LAN+iSCSI TC.
  8160. */
  8161. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  8162. if (ret) {
  8163. dev_info(&pf->pdev->dev,
  8164. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  8165. enabled_tc,
  8166. i40e_stat_str(&pf->hw, ret),
  8167. i40e_aq_str(&pf->hw,
  8168. pf->hw.aq.asq_last_status));
  8169. ret = -ENOENT;
  8170. }
  8171. }
  8172. break;
  8173. case I40E_VSI_FDIR:
  8174. ctxt.pf_num = hw->pf_id;
  8175. ctxt.vf_num = 0;
  8176. ctxt.uplink_seid = vsi->uplink_seid;
  8177. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8178. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8179. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  8180. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  8181. ctxt.info.valid_sections |=
  8182. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8183. ctxt.info.switch_id =
  8184. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8185. }
  8186. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8187. break;
  8188. case I40E_VSI_VMDQ2:
  8189. ctxt.pf_num = hw->pf_id;
  8190. ctxt.vf_num = 0;
  8191. ctxt.uplink_seid = vsi->uplink_seid;
  8192. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8193. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  8194. /* This VSI is connected to VEB so the switch_id
  8195. * should be set to zero by default.
  8196. */
  8197. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8198. ctxt.info.valid_sections |=
  8199. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8200. ctxt.info.switch_id =
  8201. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8202. }
  8203. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8204. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8205. break;
  8206. case I40E_VSI_SRIOV:
  8207. ctxt.pf_num = hw->pf_id;
  8208. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  8209. ctxt.uplink_seid = vsi->uplink_seid;
  8210. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8211. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  8212. /* This VSI is connected to VEB so the switch_id
  8213. * should be set to zero by default.
  8214. */
  8215. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8216. ctxt.info.valid_sections |=
  8217. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8218. ctxt.info.switch_id =
  8219. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8220. }
  8221. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  8222. ctxt.info.valid_sections |=
  8223. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  8224. ctxt.info.queueing_opt_flags |=
  8225. I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  8226. }
  8227. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  8228. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  8229. if (pf->vf[vsi->vf_id].spoofchk) {
  8230. ctxt.info.valid_sections |=
  8231. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  8232. ctxt.info.sec_flags |=
  8233. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  8234. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  8235. }
  8236. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8237. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8238. break;
  8239. #ifdef I40E_FCOE
  8240. case I40E_VSI_FCOE:
  8241. ret = i40e_fcoe_vsi_init(vsi, &ctxt);
  8242. if (ret) {
  8243. dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
  8244. return ret;
  8245. }
  8246. break;
  8247. #endif /* I40E_FCOE */
  8248. case I40E_VSI_IWARP:
  8249. /* send down message to iWARP */
  8250. break;
  8251. default:
  8252. return -ENODEV;
  8253. }
  8254. if (vsi->type != I40E_VSI_MAIN) {
  8255. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  8256. if (ret) {
  8257. dev_info(&vsi->back->pdev->dev,
  8258. "add vsi failed, err %s aq_err %s\n",
  8259. i40e_stat_str(&pf->hw, ret),
  8260. i40e_aq_str(&pf->hw,
  8261. pf->hw.aq.asq_last_status));
  8262. ret = -ENOENT;
  8263. goto err;
  8264. }
  8265. vsi->info = ctxt.info;
  8266. vsi->info.valid_sections = 0;
  8267. vsi->seid = ctxt.seid;
  8268. vsi->id = ctxt.vsi_number;
  8269. }
  8270. spin_lock_bh(&vsi->mac_filter_list_lock);
  8271. /* If macvlan filters already exist, force them to get loaded */
  8272. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  8273. f->changed = true;
  8274. f_count++;
  8275. /* Expected to have only one MAC filter entry for LAA in list */
  8276. if (f->is_laa && vsi->type == I40E_VSI_MAIN) {
  8277. ether_addr_copy(laa_macaddr, f->macaddr);
  8278. found_laa_mac_filter = true;
  8279. }
  8280. }
  8281. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8282. if (found_laa_mac_filter) {
  8283. struct i40e_aqc_remove_macvlan_element_data element;
  8284. memset(&element, 0, sizeof(element));
  8285. ether_addr_copy(element.mac_addr, laa_macaddr);
  8286. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  8287. ret = i40e_aq_remove_macvlan(hw, vsi->seid,
  8288. &element, 1, NULL);
  8289. if (ret) {
  8290. /* some older FW has a different default */
  8291. element.flags |=
  8292. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  8293. i40e_aq_remove_macvlan(hw, vsi->seid,
  8294. &element, 1, NULL);
  8295. }
  8296. i40e_aq_mac_address_write(hw,
  8297. I40E_AQC_WRITE_TYPE_LAA_WOL,
  8298. laa_macaddr, NULL);
  8299. }
  8300. if (f_count) {
  8301. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  8302. pf->flags |= I40E_FLAG_FILTER_SYNC;
  8303. }
  8304. /* Update VSI BW information */
  8305. ret = i40e_vsi_get_bw_info(vsi);
  8306. if (ret) {
  8307. dev_info(&pf->pdev->dev,
  8308. "couldn't get vsi bw info, err %s aq_err %s\n",
  8309. i40e_stat_str(&pf->hw, ret),
  8310. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8311. /* VSI is already added so not tearing that up */
  8312. ret = 0;
  8313. }
  8314. err:
  8315. return ret;
  8316. }
  8317. /**
  8318. * i40e_vsi_release - Delete a VSI and free its resources
  8319. * @vsi: the VSI being removed
  8320. *
  8321. * Returns 0 on success or < 0 on error
  8322. **/
  8323. int i40e_vsi_release(struct i40e_vsi *vsi)
  8324. {
  8325. struct i40e_mac_filter *f, *ftmp;
  8326. struct i40e_veb *veb = NULL;
  8327. struct i40e_pf *pf;
  8328. u16 uplink_seid;
  8329. int i, n;
  8330. pf = vsi->back;
  8331. /* release of a VEB-owner or last VSI is not allowed */
  8332. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  8333. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  8334. vsi->seid, vsi->uplink_seid);
  8335. return -ENODEV;
  8336. }
  8337. if (vsi == pf->vsi[pf->lan_vsi] &&
  8338. !test_bit(__I40E_DOWN, &pf->state)) {
  8339. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  8340. return -ENODEV;
  8341. }
  8342. uplink_seid = vsi->uplink_seid;
  8343. if (vsi->type != I40E_VSI_SRIOV) {
  8344. if (vsi->netdev_registered) {
  8345. vsi->netdev_registered = false;
  8346. if (vsi->netdev) {
  8347. /* results in a call to i40e_close() */
  8348. unregister_netdev(vsi->netdev);
  8349. }
  8350. } else {
  8351. i40e_vsi_close(vsi);
  8352. }
  8353. i40e_vsi_disable_irq(vsi);
  8354. }
  8355. spin_lock_bh(&vsi->mac_filter_list_lock);
  8356. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  8357. i40e_del_filter(vsi, f->macaddr, f->vlan,
  8358. f->is_vf, f->is_netdev);
  8359. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8360. i40e_sync_vsi_filters(vsi);
  8361. i40e_vsi_delete(vsi);
  8362. i40e_vsi_free_q_vectors(vsi);
  8363. if (vsi->netdev) {
  8364. free_netdev(vsi->netdev);
  8365. vsi->netdev = NULL;
  8366. }
  8367. i40e_vsi_clear_rings(vsi);
  8368. i40e_vsi_clear(vsi);
  8369. /* If this was the last thing on the VEB, except for the
  8370. * controlling VSI, remove the VEB, which puts the controlling
  8371. * VSI onto the next level down in the switch.
  8372. *
  8373. * Well, okay, there's one more exception here: don't remove
  8374. * the orphan VEBs yet. We'll wait for an explicit remove request
  8375. * from up the network stack.
  8376. */
  8377. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  8378. if (pf->vsi[i] &&
  8379. pf->vsi[i]->uplink_seid == uplink_seid &&
  8380. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8381. n++; /* count the VSIs */
  8382. }
  8383. }
  8384. for (i = 0; i < I40E_MAX_VEB; i++) {
  8385. if (!pf->veb[i])
  8386. continue;
  8387. if (pf->veb[i]->uplink_seid == uplink_seid)
  8388. n++; /* count the VEBs */
  8389. if (pf->veb[i]->seid == uplink_seid)
  8390. veb = pf->veb[i];
  8391. }
  8392. if (n == 0 && veb && veb->uplink_seid != 0)
  8393. i40e_veb_release(veb);
  8394. return 0;
  8395. }
  8396. /**
  8397. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  8398. * @vsi: ptr to the VSI
  8399. *
  8400. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  8401. * corresponding SW VSI structure and initializes num_queue_pairs for the
  8402. * newly allocated VSI.
  8403. *
  8404. * Returns 0 on success or negative on failure
  8405. **/
  8406. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  8407. {
  8408. int ret = -ENOENT;
  8409. struct i40e_pf *pf = vsi->back;
  8410. if (vsi->q_vectors[0]) {
  8411. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  8412. vsi->seid);
  8413. return -EEXIST;
  8414. }
  8415. if (vsi->base_vector) {
  8416. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  8417. vsi->seid, vsi->base_vector);
  8418. return -EEXIST;
  8419. }
  8420. ret = i40e_vsi_alloc_q_vectors(vsi);
  8421. if (ret) {
  8422. dev_info(&pf->pdev->dev,
  8423. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  8424. vsi->num_q_vectors, vsi->seid, ret);
  8425. vsi->num_q_vectors = 0;
  8426. goto vector_setup_out;
  8427. }
  8428. /* In Legacy mode, we do not have to get any other vector since we
  8429. * piggyback on the misc/ICR0 for queue interrupts.
  8430. */
  8431. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8432. return ret;
  8433. if (vsi->num_q_vectors)
  8434. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  8435. vsi->num_q_vectors, vsi->idx);
  8436. if (vsi->base_vector < 0) {
  8437. dev_info(&pf->pdev->dev,
  8438. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  8439. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  8440. i40e_vsi_free_q_vectors(vsi);
  8441. ret = -ENOENT;
  8442. goto vector_setup_out;
  8443. }
  8444. vector_setup_out:
  8445. return ret;
  8446. }
  8447. /**
  8448. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  8449. * @vsi: pointer to the vsi.
  8450. *
  8451. * This re-allocates a vsi's queue resources.
  8452. *
  8453. * Returns pointer to the successfully allocated and configured VSI sw struct
  8454. * on success, otherwise returns NULL on failure.
  8455. **/
  8456. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  8457. {
  8458. struct i40e_pf *pf;
  8459. u8 enabled_tc;
  8460. int ret;
  8461. if (!vsi)
  8462. return NULL;
  8463. pf = vsi->back;
  8464. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8465. i40e_vsi_clear_rings(vsi);
  8466. i40e_vsi_free_arrays(vsi, false);
  8467. i40e_set_num_rings_in_vsi(vsi);
  8468. ret = i40e_vsi_alloc_arrays(vsi, false);
  8469. if (ret)
  8470. goto err_vsi;
  8471. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  8472. if (ret < 0) {
  8473. dev_info(&pf->pdev->dev,
  8474. "failed to get tracking for %d queues for VSI %d err %d\n",
  8475. vsi->alloc_queue_pairs, vsi->seid, ret);
  8476. goto err_vsi;
  8477. }
  8478. vsi->base_queue = ret;
  8479. /* Update the FW view of the VSI. Force a reset of TC and queue
  8480. * layout configurations.
  8481. */
  8482. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  8483. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  8484. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  8485. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  8486. /* assign it some queues */
  8487. ret = i40e_alloc_rings(vsi);
  8488. if (ret)
  8489. goto err_rings;
  8490. /* map all of the rings to the q_vectors */
  8491. i40e_vsi_map_rings_to_vectors(vsi);
  8492. return vsi;
  8493. err_rings:
  8494. i40e_vsi_free_q_vectors(vsi);
  8495. if (vsi->netdev_registered) {
  8496. vsi->netdev_registered = false;
  8497. unregister_netdev(vsi->netdev);
  8498. free_netdev(vsi->netdev);
  8499. vsi->netdev = NULL;
  8500. }
  8501. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8502. err_vsi:
  8503. i40e_vsi_clear(vsi);
  8504. return NULL;
  8505. }
  8506. /**
  8507. * i40e_macaddr_init - explicitly write the mac address filters.
  8508. *
  8509. * @vsi: pointer to the vsi.
  8510. * @macaddr: the MAC address
  8511. *
  8512. * This is needed when the macaddr has been obtained by other
  8513. * means than the default, e.g., from Open Firmware or IDPROM.
  8514. * Returns 0 on success, negative on failure
  8515. **/
  8516. static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
  8517. {
  8518. int ret;
  8519. struct i40e_aqc_add_macvlan_element_data element;
  8520. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  8521. I40E_AQC_WRITE_TYPE_LAA_WOL,
  8522. macaddr, NULL);
  8523. if (ret) {
  8524. dev_info(&vsi->back->pdev->dev,
  8525. "Addr change for VSI failed: %d\n", ret);
  8526. return -EADDRNOTAVAIL;
  8527. }
  8528. memset(&element, 0, sizeof(element));
  8529. ether_addr_copy(element.mac_addr, macaddr);
  8530. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  8531. ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
  8532. if (ret) {
  8533. dev_info(&vsi->back->pdev->dev,
  8534. "add filter failed err %s aq_err %s\n",
  8535. i40e_stat_str(&vsi->back->hw, ret),
  8536. i40e_aq_str(&vsi->back->hw,
  8537. vsi->back->hw.aq.asq_last_status));
  8538. }
  8539. return ret;
  8540. }
  8541. /**
  8542. * i40e_vsi_setup - Set up a VSI by a given type
  8543. * @pf: board private structure
  8544. * @type: VSI type
  8545. * @uplink_seid: the switch element to link to
  8546. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  8547. *
  8548. * This allocates the sw VSI structure and its queue resources, then add a VSI
  8549. * to the identified VEB.
  8550. *
  8551. * Returns pointer to the successfully allocated and configure VSI sw struct on
  8552. * success, otherwise returns NULL on failure.
  8553. **/
  8554. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  8555. u16 uplink_seid, u32 param1)
  8556. {
  8557. struct i40e_vsi *vsi = NULL;
  8558. struct i40e_veb *veb = NULL;
  8559. int ret, i;
  8560. int v_idx;
  8561. /* The requested uplink_seid must be either
  8562. * - the PF's port seid
  8563. * no VEB is needed because this is the PF
  8564. * or this is a Flow Director special case VSI
  8565. * - seid of an existing VEB
  8566. * - seid of a VSI that owns an existing VEB
  8567. * - seid of a VSI that doesn't own a VEB
  8568. * a new VEB is created and the VSI becomes the owner
  8569. * - seid of the PF VSI, which is what creates the first VEB
  8570. * this is a special case of the previous
  8571. *
  8572. * Find which uplink_seid we were given and create a new VEB if needed
  8573. */
  8574. for (i = 0; i < I40E_MAX_VEB; i++) {
  8575. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  8576. veb = pf->veb[i];
  8577. break;
  8578. }
  8579. }
  8580. if (!veb && uplink_seid != pf->mac_seid) {
  8581. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8582. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  8583. vsi = pf->vsi[i];
  8584. break;
  8585. }
  8586. }
  8587. if (!vsi) {
  8588. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  8589. uplink_seid);
  8590. return NULL;
  8591. }
  8592. if (vsi->uplink_seid == pf->mac_seid)
  8593. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  8594. vsi->tc_config.enabled_tc);
  8595. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  8596. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  8597. vsi->tc_config.enabled_tc);
  8598. if (veb) {
  8599. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  8600. dev_info(&vsi->back->pdev->dev,
  8601. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  8602. return NULL;
  8603. }
  8604. /* We come up by default in VEPA mode if SRIOV is not
  8605. * already enabled, in which case we can't force VEPA
  8606. * mode.
  8607. */
  8608. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  8609. veb->bridge_mode = BRIDGE_MODE_VEPA;
  8610. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8611. }
  8612. i40e_config_bridge_mode(veb);
  8613. }
  8614. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8615. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8616. veb = pf->veb[i];
  8617. }
  8618. if (!veb) {
  8619. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  8620. return NULL;
  8621. }
  8622. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8623. uplink_seid = veb->seid;
  8624. }
  8625. /* get vsi sw struct */
  8626. v_idx = i40e_vsi_mem_alloc(pf, type);
  8627. if (v_idx < 0)
  8628. goto err_alloc;
  8629. vsi = pf->vsi[v_idx];
  8630. if (!vsi)
  8631. goto err_alloc;
  8632. vsi->type = type;
  8633. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  8634. if (type == I40E_VSI_MAIN)
  8635. pf->lan_vsi = v_idx;
  8636. else if (type == I40E_VSI_SRIOV)
  8637. vsi->vf_id = param1;
  8638. /* assign it some queues */
  8639. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  8640. vsi->idx);
  8641. if (ret < 0) {
  8642. dev_info(&pf->pdev->dev,
  8643. "failed to get tracking for %d queues for VSI %d err=%d\n",
  8644. vsi->alloc_queue_pairs, vsi->seid, ret);
  8645. goto err_vsi;
  8646. }
  8647. vsi->base_queue = ret;
  8648. /* get a VSI from the hardware */
  8649. vsi->uplink_seid = uplink_seid;
  8650. ret = i40e_add_vsi(vsi);
  8651. if (ret)
  8652. goto err_vsi;
  8653. switch (vsi->type) {
  8654. /* setup the netdev if needed */
  8655. case I40E_VSI_MAIN:
  8656. /* Apply relevant filters if a platform-specific mac
  8657. * address was selected.
  8658. */
  8659. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  8660. ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  8661. if (ret) {
  8662. dev_warn(&pf->pdev->dev,
  8663. "could not set up macaddr; err %d\n",
  8664. ret);
  8665. }
  8666. }
  8667. case I40E_VSI_VMDQ2:
  8668. case I40E_VSI_FCOE:
  8669. ret = i40e_config_netdev(vsi);
  8670. if (ret)
  8671. goto err_netdev;
  8672. ret = register_netdev(vsi->netdev);
  8673. if (ret)
  8674. goto err_netdev;
  8675. vsi->netdev_registered = true;
  8676. netif_carrier_off(vsi->netdev);
  8677. #ifdef CONFIG_I40E_DCB
  8678. /* Setup DCB netlink interface */
  8679. i40e_dcbnl_setup(vsi);
  8680. #endif /* CONFIG_I40E_DCB */
  8681. /* fall through */
  8682. case I40E_VSI_FDIR:
  8683. /* set up vectors and rings if needed */
  8684. ret = i40e_vsi_setup_vectors(vsi);
  8685. if (ret)
  8686. goto err_msix;
  8687. ret = i40e_alloc_rings(vsi);
  8688. if (ret)
  8689. goto err_rings;
  8690. /* map all of the rings to the q_vectors */
  8691. i40e_vsi_map_rings_to_vectors(vsi);
  8692. i40e_vsi_reset_stats(vsi);
  8693. break;
  8694. default:
  8695. /* no netdev or rings for the other VSI types */
  8696. break;
  8697. }
  8698. if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
  8699. (vsi->type == I40E_VSI_VMDQ2)) {
  8700. ret = i40e_vsi_config_rss(vsi);
  8701. }
  8702. return vsi;
  8703. err_rings:
  8704. i40e_vsi_free_q_vectors(vsi);
  8705. err_msix:
  8706. if (vsi->netdev_registered) {
  8707. vsi->netdev_registered = false;
  8708. unregister_netdev(vsi->netdev);
  8709. free_netdev(vsi->netdev);
  8710. vsi->netdev = NULL;
  8711. }
  8712. err_netdev:
  8713. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8714. err_vsi:
  8715. i40e_vsi_clear(vsi);
  8716. err_alloc:
  8717. return NULL;
  8718. }
  8719. /**
  8720. * i40e_veb_get_bw_info - Query VEB BW information
  8721. * @veb: the veb to query
  8722. *
  8723. * Query the Tx scheduler BW configuration data for given VEB
  8724. **/
  8725. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  8726. {
  8727. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  8728. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  8729. struct i40e_pf *pf = veb->pf;
  8730. struct i40e_hw *hw = &pf->hw;
  8731. u32 tc_bw_max;
  8732. int ret = 0;
  8733. int i;
  8734. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  8735. &bw_data, NULL);
  8736. if (ret) {
  8737. dev_info(&pf->pdev->dev,
  8738. "query veb bw config failed, err %s aq_err %s\n",
  8739. i40e_stat_str(&pf->hw, ret),
  8740. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8741. goto out;
  8742. }
  8743. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  8744. &ets_data, NULL);
  8745. if (ret) {
  8746. dev_info(&pf->pdev->dev,
  8747. "query veb bw ets config failed, err %s aq_err %s\n",
  8748. i40e_stat_str(&pf->hw, ret),
  8749. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8750. goto out;
  8751. }
  8752. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  8753. veb->bw_max_quanta = ets_data.tc_bw_max;
  8754. veb->is_abs_credits = bw_data.absolute_credits_enable;
  8755. veb->enabled_tc = ets_data.tc_valid_bits;
  8756. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  8757. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  8758. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  8759. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  8760. veb->bw_tc_limit_credits[i] =
  8761. le16_to_cpu(bw_data.tc_bw_limits[i]);
  8762. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  8763. }
  8764. out:
  8765. return ret;
  8766. }
  8767. /**
  8768. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  8769. * @pf: board private structure
  8770. *
  8771. * On error: returns error code (negative)
  8772. * On success: returns vsi index in PF (positive)
  8773. **/
  8774. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  8775. {
  8776. int ret = -ENOENT;
  8777. struct i40e_veb *veb;
  8778. int i;
  8779. /* Need to protect the allocation of switch elements at the PF level */
  8780. mutex_lock(&pf->switch_mutex);
  8781. /* VEB list may be fragmented if VEB creation/destruction has
  8782. * been happening. We can afford to do a quick scan to look
  8783. * for any free slots in the list.
  8784. *
  8785. * find next empty veb slot, looping back around if necessary
  8786. */
  8787. i = 0;
  8788. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  8789. i++;
  8790. if (i >= I40E_MAX_VEB) {
  8791. ret = -ENOMEM;
  8792. goto err_alloc_veb; /* out of VEB slots! */
  8793. }
  8794. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  8795. if (!veb) {
  8796. ret = -ENOMEM;
  8797. goto err_alloc_veb;
  8798. }
  8799. veb->pf = pf;
  8800. veb->idx = i;
  8801. veb->enabled_tc = 1;
  8802. pf->veb[i] = veb;
  8803. ret = i;
  8804. err_alloc_veb:
  8805. mutex_unlock(&pf->switch_mutex);
  8806. return ret;
  8807. }
  8808. /**
  8809. * i40e_switch_branch_release - Delete a branch of the switch tree
  8810. * @branch: where to start deleting
  8811. *
  8812. * This uses recursion to find the tips of the branch to be
  8813. * removed, deleting until we get back to and can delete this VEB.
  8814. **/
  8815. static void i40e_switch_branch_release(struct i40e_veb *branch)
  8816. {
  8817. struct i40e_pf *pf = branch->pf;
  8818. u16 branch_seid = branch->seid;
  8819. u16 veb_idx = branch->idx;
  8820. int i;
  8821. /* release any VEBs on this VEB - RECURSION */
  8822. for (i = 0; i < I40E_MAX_VEB; i++) {
  8823. if (!pf->veb[i])
  8824. continue;
  8825. if (pf->veb[i]->uplink_seid == branch->seid)
  8826. i40e_switch_branch_release(pf->veb[i]);
  8827. }
  8828. /* Release the VSIs on this VEB, but not the owner VSI.
  8829. *
  8830. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  8831. * the VEB itself, so don't use (*branch) after this loop.
  8832. */
  8833. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8834. if (!pf->vsi[i])
  8835. continue;
  8836. if (pf->vsi[i]->uplink_seid == branch_seid &&
  8837. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8838. i40e_vsi_release(pf->vsi[i]);
  8839. }
  8840. }
  8841. /* There's one corner case where the VEB might not have been
  8842. * removed, so double check it here and remove it if needed.
  8843. * This case happens if the veb was created from the debugfs
  8844. * commands and no VSIs were added to it.
  8845. */
  8846. if (pf->veb[veb_idx])
  8847. i40e_veb_release(pf->veb[veb_idx]);
  8848. }
  8849. /**
  8850. * i40e_veb_clear - remove veb struct
  8851. * @veb: the veb to remove
  8852. **/
  8853. static void i40e_veb_clear(struct i40e_veb *veb)
  8854. {
  8855. if (!veb)
  8856. return;
  8857. if (veb->pf) {
  8858. struct i40e_pf *pf = veb->pf;
  8859. mutex_lock(&pf->switch_mutex);
  8860. if (pf->veb[veb->idx] == veb)
  8861. pf->veb[veb->idx] = NULL;
  8862. mutex_unlock(&pf->switch_mutex);
  8863. }
  8864. kfree(veb);
  8865. }
  8866. /**
  8867. * i40e_veb_release - Delete a VEB and free its resources
  8868. * @veb: the VEB being removed
  8869. **/
  8870. void i40e_veb_release(struct i40e_veb *veb)
  8871. {
  8872. struct i40e_vsi *vsi = NULL;
  8873. struct i40e_pf *pf;
  8874. int i, n = 0;
  8875. pf = veb->pf;
  8876. /* find the remaining VSI and check for extras */
  8877. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8878. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  8879. n++;
  8880. vsi = pf->vsi[i];
  8881. }
  8882. }
  8883. if (n != 1) {
  8884. dev_info(&pf->pdev->dev,
  8885. "can't remove VEB %d with %d VSIs left\n",
  8886. veb->seid, n);
  8887. return;
  8888. }
  8889. /* move the remaining VSI to uplink veb */
  8890. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  8891. if (veb->uplink_seid) {
  8892. vsi->uplink_seid = veb->uplink_seid;
  8893. if (veb->uplink_seid == pf->mac_seid)
  8894. vsi->veb_idx = I40E_NO_VEB;
  8895. else
  8896. vsi->veb_idx = veb->veb_idx;
  8897. } else {
  8898. /* floating VEB */
  8899. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  8900. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  8901. }
  8902. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  8903. i40e_veb_clear(veb);
  8904. }
  8905. /**
  8906. * i40e_add_veb - create the VEB in the switch
  8907. * @veb: the VEB to be instantiated
  8908. * @vsi: the controlling VSI
  8909. **/
  8910. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  8911. {
  8912. struct i40e_pf *pf = veb->pf;
  8913. bool is_default = veb->pf->cur_promisc;
  8914. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  8915. int ret;
  8916. /* get a VEB from the hardware */
  8917. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  8918. veb->enabled_tc, is_default,
  8919. &veb->seid, enable_stats, NULL);
  8920. if (ret) {
  8921. dev_info(&pf->pdev->dev,
  8922. "couldn't add VEB, err %s aq_err %s\n",
  8923. i40e_stat_str(&pf->hw, ret),
  8924. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8925. return -EPERM;
  8926. }
  8927. /* get statistics counter */
  8928. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  8929. &veb->stats_idx, NULL, NULL, NULL);
  8930. if (ret) {
  8931. dev_info(&pf->pdev->dev,
  8932. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  8933. i40e_stat_str(&pf->hw, ret),
  8934. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8935. return -EPERM;
  8936. }
  8937. ret = i40e_veb_get_bw_info(veb);
  8938. if (ret) {
  8939. dev_info(&pf->pdev->dev,
  8940. "couldn't get VEB bw info, err %s aq_err %s\n",
  8941. i40e_stat_str(&pf->hw, ret),
  8942. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8943. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  8944. return -ENOENT;
  8945. }
  8946. vsi->uplink_seid = veb->seid;
  8947. vsi->veb_idx = veb->idx;
  8948. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8949. return 0;
  8950. }
  8951. /**
  8952. * i40e_veb_setup - Set up a VEB
  8953. * @pf: board private structure
  8954. * @flags: VEB setup flags
  8955. * @uplink_seid: the switch element to link to
  8956. * @vsi_seid: the initial VSI seid
  8957. * @enabled_tc: Enabled TC bit-map
  8958. *
  8959. * This allocates the sw VEB structure and links it into the switch
  8960. * It is possible and legal for this to be a duplicate of an already
  8961. * existing VEB. It is also possible for both uplink and vsi seids
  8962. * to be zero, in order to create a floating VEB.
  8963. *
  8964. * Returns pointer to the successfully allocated VEB sw struct on
  8965. * success, otherwise returns NULL on failure.
  8966. **/
  8967. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  8968. u16 uplink_seid, u16 vsi_seid,
  8969. u8 enabled_tc)
  8970. {
  8971. struct i40e_veb *veb, *uplink_veb = NULL;
  8972. int vsi_idx, veb_idx;
  8973. int ret;
  8974. /* if one seid is 0, the other must be 0 to create a floating relay */
  8975. if ((uplink_seid == 0 || vsi_seid == 0) &&
  8976. (uplink_seid + vsi_seid != 0)) {
  8977. dev_info(&pf->pdev->dev,
  8978. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  8979. uplink_seid, vsi_seid);
  8980. return NULL;
  8981. }
  8982. /* make sure there is such a vsi and uplink */
  8983. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  8984. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  8985. break;
  8986. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  8987. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  8988. vsi_seid);
  8989. return NULL;
  8990. }
  8991. if (uplink_seid && uplink_seid != pf->mac_seid) {
  8992. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  8993. if (pf->veb[veb_idx] &&
  8994. pf->veb[veb_idx]->seid == uplink_seid) {
  8995. uplink_veb = pf->veb[veb_idx];
  8996. break;
  8997. }
  8998. }
  8999. if (!uplink_veb) {
  9000. dev_info(&pf->pdev->dev,
  9001. "uplink seid %d not found\n", uplink_seid);
  9002. return NULL;
  9003. }
  9004. }
  9005. /* get veb sw struct */
  9006. veb_idx = i40e_veb_mem_alloc(pf);
  9007. if (veb_idx < 0)
  9008. goto err_alloc;
  9009. veb = pf->veb[veb_idx];
  9010. veb->flags = flags;
  9011. veb->uplink_seid = uplink_seid;
  9012. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  9013. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  9014. /* create the VEB in the switch */
  9015. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  9016. if (ret)
  9017. goto err_veb;
  9018. if (vsi_idx == pf->lan_vsi)
  9019. pf->lan_veb = veb->idx;
  9020. return veb;
  9021. err_veb:
  9022. i40e_veb_clear(veb);
  9023. err_alloc:
  9024. return NULL;
  9025. }
  9026. /**
  9027. * i40e_setup_pf_switch_element - set PF vars based on switch type
  9028. * @pf: board private structure
  9029. * @ele: element we are building info from
  9030. * @num_reported: total number of elements
  9031. * @printconfig: should we print the contents
  9032. *
  9033. * helper function to assist in extracting a few useful SEID values.
  9034. **/
  9035. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  9036. struct i40e_aqc_switch_config_element_resp *ele,
  9037. u16 num_reported, bool printconfig)
  9038. {
  9039. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  9040. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  9041. u8 element_type = ele->element_type;
  9042. u16 seid = le16_to_cpu(ele->seid);
  9043. if (printconfig)
  9044. dev_info(&pf->pdev->dev,
  9045. "type=%d seid=%d uplink=%d downlink=%d\n",
  9046. element_type, seid, uplink_seid, downlink_seid);
  9047. switch (element_type) {
  9048. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  9049. pf->mac_seid = seid;
  9050. break;
  9051. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  9052. /* Main VEB? */
  9053. if (uplink_seid != pf->mac_seid)
  9054. break;
  9055. if (pf->lan_veb == I40E_NO_VEB) {
  9056. int v;
  9057. /* find existing or else empty VEB */
  9058. for (v = 0; v < I40E_MAX_VEB; v++) {
  9059. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  9060. pf->lan_veb = v;
  9061. break;
  9062. }
  9063. }
  9064. if (pf->lan_veb == I40E_NO_VEB) {
  9065. v = i40e_veb_mem_alloc(pf);
  9066. if (v < 0)
  9067. break;
  9068. pf->lan_veb = v;
  9069. }
  9070. }
  9071. pf->veb[pf->lan_veb]->seid = seid;
  9072. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  9073. pf->veb[pf->lan_veb]->pf = pf;
  9074. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  9075. break;
  9076. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  9077. if (num_reported != 1)
  9078. break;
  9079. /* This is immediately after a reset so we can assume this is
  9080. * the PF's VSI
  9081. */
  9082. pf->mac_seid = uplink_seid;
  9083. pf->pf_seid = downlink_seid;
  9084. pf->main_vsi_seid = seid;
  9085. if (printconfig)
  9086. dev_info(&pf->pdev->dev,
  9087. "pf_seid=%d main_vsi_seid=%d\n",
  9088. pf->pf_seid, pf->main_vsi_seid);
  9089. break;
  9090. case I40E_SWITCH_ELEMENT_TYPE_PF:
  9091. case I40E_SWITCH_ELEMENT_TYPE_VF:
  9092. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  9093. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  9094. case I40E_SWITCH_ELEMENT_TYPE_PE:
  9095. case I40E_SWITCH_ELEMENT_TYPE_PA:
  9096. /* ignore these for now */
  9097. break;
  9098. default:
  9099. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  9100. element_type, seid);
  9101. break;
  9102. }
  9103. }
  9104. /**
  9105. * i40e_fetch_switch_configuration - Get switch config from firmware
  9106. * @pf: board private structure
  9107. * @printconfig: should we print the contents
  9108. *
  9109. * Get the current switch configuration from the device and
  9110. * extract a few useful SEID values.
  9111. **/
  9112. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  9113. {
  9114. struct i40e_aqc_get_switch_config_resp *sw_config;
  9115. u16 next_seid = 0;
  9116. int ret = 0;
  9117. u8 *aq_buf;
  9118. int i;
  9119. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  9120. if (!aq_buf)
  9121. return -ENOMEM;
  9122. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  9123. do {
  9124. u16 num_reported, num_total;
  9125. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  9126. I40E_AQ_LARGE_BUF,
  9127. &next_seid, NULL);
  9128. if (ret) {
  9129. dev_info(&pf->pdev->dev,
  9130. "get switch config failed err %s aq_err %s\n",
  9131. i40e_stat_str(&pf->hw, ret),
  9132. i40e_aq_str(&pf->hw,
  9133. pf->hw.aq.asq_last_status));
  9134. kfree(aq_buf);
  9135. return -ENOENT;
  9136. }
  9137. num_reported = le16_to_cpu(sw_config->header.num_reported);
  9138. num_total = le16_to_cpu(sw_config->header.num_total);
  9139. if (printconfig)
  9140. dev_info(&pf->pdev->dev,
  9141. "header: %d reported %d total\n",
  9142. num_reported, num_total);
  9143. for (i = 0; i < num_reported; i++) {
  9144. struct i40e_aqc_switch_config_element_resp *ele =
  9145. &sw_config->element[i];
  9146. i40e_setup_pf_switch_element(pf, ele, num_reported,
  9147. printconfig);
  9148. }
  9149. } while (next_seid != 0);
  9150. kfree(aq_buf);
  9151. return ret;
  9152. }
  9153. /**
  9154. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  9155. * @pf: board private structure
  9156. * @reinit: if the Main VSI needs to re-initialized.
  9157. *
  9158. * Returns 0 on success, negative value on failure
  9159. **/
  9160. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  9161. {
  9162. int ret;
  9163. /* find out what's out there already */
  9164. ret = i40e_fetch_switch_configuration(pf, false);
  9165. if (ret) {
  9166. dev_info(&pf->pdev->dev,
  9167. "couldn't fetch switch config, err %s aq_err %s\n",
  9168. i40e_stat_str(&pf->hw, ret),
  9169. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9170. return ret;
  9171. }
  9172. i40e_pf_reset_stats(pf);
  9173. /* first time setup */
  9174. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  9175. struct i40e_vsi *vsi = NULL;
  9176. u16 uplink_seid;
  9177. /* Set up the PF VSI associated with the PF's main VSI
  9178. * that is already in the HW switch
  9179. */
  9180. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  9181. uplink_seid = pf->veb[pf->lan_veb]->seid;
  9182. else
  9183. uplink_seid = pf->mac_seid;
  9184. if (pf->lan_vsi == I40E_NO_VSI)
  9185. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  9186. else if (reinit)
  9187. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  9188. if (!vsi) {
  9189. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  9190. i40e_fdir_teardown(pf);
  9191. return -EAGAIN;
  9192. }
  9193. } else {
  9194. /* force a reset of TC and queue layout configurations */
  9195. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  9196. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  9197. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  9198. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  9199. }
  9200. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  9201. i40e_fdir_sb_setup(pf);
  9202. /* Setup static PF queue filter control settings */
  9203. ret = i40e_setup_pf_filter_control(pf);
  9204. if (ret) {
  9205. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  9206. ret);
  9207. /* Failure here should not stop continuing other steps */
  9208. }
  9209. /* enable RSS in the HW, even for only one queue, as the stack can use
  9210. * the hash
  9211. */
  9212. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  9213. i40e_pf_config_rss(pf);
  9214. /* fill in link information and enable LSE reporting */
  9215. i40e_update_link_info(&pf->hw);
  9216. i40e_link_event(pf);
  9217. /* Initialize user-specific link properties */
  9218. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  9219. I40E_AQ_AN_COMPLETED) ? true : false);
  9220. i40e_ptp_init(pf);
  9221. return ret;
  9222. }
  9223. /**
  9224. * i40e_determine_queue_usage - Work out queue distribution
  9225. * @pf: board private structure
  9226. **/
  9227. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  9228. {
  9229. int queues_left;
  9230. pf->num_lan_qps = 0;
  9231. #ifdef I40E_FCOE
  9232. pf->num_fcoe_qps = 0;
  9233. #endif
  9234. /* Find the max queues to be put into basic use. We'll always be
  9235. * using TC0, whether or not DCB is running, and TC0 will get the
  9236. * big RSS set.
  9237. */
  9238. queues_left = pf->hw.func_caps.num_tx_qp;
  9239. if ((queues_left == 1) ||
  9240. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  9241. /* one qp for PF, no queues for anything else */
  9242. queues_left = 0;
  9243. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9244. /* make sure all the fancies are disabled */
  9245. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9246. I40E_FLAG_IWARP_ENABLED |
  9247. #ifdef I40E_FCOE
  9248. I40E_FLAG_FCOE_ENABLED |
  9249. #endif
  9250. I40E_FLAG_FD_SB_ENABLED |
  9251. I40E_FLAG_FD_ATR_ENABLED |
  9252. I40E_FLAG_DCB_CAPABLE |
  9253. I40E_FLAG_SRIOV_ENABLED |
  9254. I40E_FLAG_VMDQ_ENABLED);
  9255. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  9256. I40E_FLAG_FD_SB_ENABLED |
  9257. I40E_FLAG_FD_ATR_ENABLED |
  9258. I40E_FLAG_DCB_CAPABLE))) {
  9259. /* one qp for PF */
  9260. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9261. queues_left -= pf->num_lan_qps;
  9262. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9263. I40E_FLAG_IWARP_ENABLED |
  9264. #ifdef I40E_FCOE
  9265. I40E_FLAG_FCOE_ENABLED |
  9266. #endif
  9267. I40E_FLAG_FD_SB_ENABLED |
  9268. I40E_FLAG_FD_ATR_ENABLED |
  9269. I40E_FLAG_DCB_ENABLED |
  9270. I40E_FLAG_VMDQ_ENABLED);
  9271. } else {
  9272. /* Not enough queues for all TCs */
  9273. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  9274. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  9275. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  9276. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  9277. }
  9278. pf->num_lan_qps = max_t(int, pf->rss_size_max,
  9279. num_online_cpus());
  9280. pf->num_lan_qps = min_t(int, pf->num_lan_qps,
  9281. pf->hw.func_caps.num_tx_qp);
  9282. queues_left -= pf->num_lan_qps;
  9283. }
  9284. #ifdef I40E_FCOE
  9285. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  9286. if (I40E_DEFAULT_FCOE <= queues_left) {
  9287. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  9288. } else if (I40E_MINIMUM_FCOE <= queues_left) {
  9289. pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
  9290. } else {
  9291. pf->num_fcoe_qps = 0;
  9292. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  9293. dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
  9294. }
  9295. queues_left -= pf->num_fcoe_qps;
  9296. }
  9297. #endif
  9298. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9299. if (queues_left > 1) {
  9300. queues_left -= 1; /* save 1 queue for FD */
  9301. } else {
  9302. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9303. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  9304. }
  9305. }
  9306. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9307. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  9308. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  9309. (queues_left / pf->num_vf_qps));
  9310. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  9311. }
  9312. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9313. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  9314. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  9315. (queues_left / pf->num_vmdq_qps));
  9316. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  9317. }
  9318. pf->queues_left = queues_left;
  9319. dev_dbg(&pf->pdev->dev,
  9320. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  9321. pf->hw.func_caps.num_tx_qp,
  9322. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  9323. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  9324. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  9325. queues_left);
  9326. #ifdef I40E_FCOE
  9327. dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
  9328. #endif
  9329. }
  9330. /**
  9331. * i40e_setup_pf_filter_control - Setup PF static filter control
  9332. * @pf: PF to be setup
  9333. *
  9334. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  9335. * settings. If PE/FCoE are enabled then it will also set the per PF
  9336. * based filter sizes required for them. It also enables Flow director,
  9337. * ethertype and macvlan type filter settings for the pf.
  9338. *
  9339. * Returns 0 on success, negative on failure
  9340. **/
  9341. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  9342. {
  9343. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  9344. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  9345. /* Flow Director is enabled */
  9346. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  9347. settings->enable_fdir = true;
  9348. /* Ethtype and MACVLAN filters enabled for PF */
  9349. settings->enable_ethtype = true;
  9350. settings->enable_macvlan = true;
  9351. if (i40e_set_filter_control(&pf->hw, settings))
  9352. return -ENOENT;
  9353. return 0;
  9354. }
  9355. #define INFO_STRING_LEN 255
  9356. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  9357. static void i40e_print_features(struct i40e_pf *pf)
  9358. {
  9359. struct i40e_hw *hw = &pf->hw;
  9360. char *buf;
  9361. int i;
  9362. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  9363. if (!buf)
  9364. return;
  9365. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  9366. #ifdef CONFIG_PCI_IOV
  9367. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  9368. #endif
  9369. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d RX: %s",
  9370. pf->hw.func_caps.num_vsis,
  9371. pf->vsi[pf->lan_vsi]->num_queue_pairs,
  9372. pf->flags & I40E_FLAG_RX_PS_ENABLED ? "PS" : "1BUF");
  9373. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  9374. i += snprintf(&buf[i], REMAIN(i), " RSS");
  9375. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  9376. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  9377. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9378. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  9379. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  9380. }
  9381. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  9382. i += snprintf(&buf[i], REMAIN(i), " DCB");
  9383. #if IS_ENABLED(CONFIG_VXLAN)
  9384. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  9385. #endif
  9386. #if IS_ENABLED(CONFIG_GENEVE)
  9387. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  9388. #endif
  9389. if (pf->flags & I40E_FLAG_PTP)
  9390. i += snprintf(&buf[i], REMAIN(i), " PTP");
  9391. #ifdef I40E_FCOE
  9392. if (pf->flags & I40E_FLAG_FCOE_ENABLED)
  9393. i += snprintf(&buf[i], REMAIN(i), " FCOE");
  9394. #endif
  9395. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  9396. i += snprintf(&buf[i], REMAIN(i), " VEB");
  9397. else
  9398. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  9399. dev_info(&pf->pdev->dev, "%s\n", buf);
  9400. kfree(buf);
  9401. WARN_ON(i > INFO_STRING_LEN);
  9402. }
  9403. /**
  9404. * i40e_get_platform_mac_addr - get platform-specific MAC address
  9405. *
  9406. * @pdev: PCI device information struct
  9407. * @pf: board private structure
  9408. *
  9409. * Look up the MAC address in Open Firmware on systems that support it,
  9410. * and use IDPROM on SPARC if no OF address is found. On return, the
  9411. * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
  9412. * has been selected.
  9413. **/
  9414. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  9415. {
  9416. pf->flags &= ~I40E_FLAG_PF_MAC;
  9417. if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  9418. pf->flags |= I40E_FLAG_PF_MAC;
  9419. }
  9420. /**
  9421. * i40e_probe - Device initialization routine
  9422. * @pdev: PCI device information struct
  9423. * @ent: entry in i40e_pci_tbl
  9424. *
  9425. * i40e_probe initializes a PF identified by a pci_dev structure.
  9426. * The OS initialization, configuring of the PF private structure,
  9427. * and a hardware reset occur.
  9428. *
  9429. * Returns 0 on success, negative on failure
  9430. **/
  9431. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9432. {
  9433. struct i40e_aq_get_phy_abilities_resp abilities;
  9434. struct i40e_pf *pf;
  9435. struct i40e_hw *hw;
  9436. static u16 pfs_found;
  9437. u16 wol_nvm_bits;
  9438. u16 link_status;
  9439. int err;
  9440. u32 val;
  9441. u32 i;
  9442. u8 set_fc_aq_fail;
  9443. err = pci_enable_device_mem(pdev);
  9444. if (err)
  9445. return err;
  9446. /* set up for high or low dma */
  9447. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  9448. if (err) {
  9449. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  9450. if (err) {
  9451. dev_err(&pdev->dev,
  9452. "DMA configuration failed: 0x%x\n", err);
  9453. goto err_dma;
  9454. }
  9455. }
  9456. /* set up pci connections */
  9457. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  9458. IORESOURCE_MEM), i40e_driver_name);
  9459. if (err) {
  9460. dev_info(&pdev->dev,
  9461. "pci_request_selected_regions failed %d\n", err);
  9462. goto err_pci_reg;
  9463. }
  9464. pci_enable_pcie_error_reporting(pdev);
  9465. pci_set_master(pdev);
  9466. /* Now that we have a PCI connection, we need to do the
  9467. * low level device setup. This is primarily setting up
  9468. * the Admin Queue structures and then querying for the
  9469. * device's current profile information.
  9470. */
  9471. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  9472. if (!pf) {
  9473. err = -ENOMEM;
  9474. goto err_pf_alloc;
  9475. }
  9476. pf->next_vsi = 0;
  9477. pf->pdev = pdev;
  9478. set_bit(__I40E_DOWN, &pf->state);
  9479. hw = &pf->hw;
  9480. hw->back = pf;
  9481. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  9482. I40E_MAX_CSR_SPACE);
  9483. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  9484. if (!hw->hw_addr) {
  9485. err = -EIO;
  9486. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  9487. (unsigned int)pci_resource_start(pdev, 0),
  9488. pf->ioremap_len, err);
  9489. goto err_ioremap;
  9490. }
  9491. hw->vendor_id = pdev->vendor;
  9492. hw->device_id = pdev->device;
  9493. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  9494. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  9495. hw->subsystem_device_id = pdev->subsystem_device;
  9496. hw->bus.device = PCI_SLOT(pdev->devfn);
  9497. hw->bus.func = PCI_FUNC(pdev->devfn);
  9498. pf->instance = pfs_found;
  9499. /* set up the locks for the AQ, do this only once in probe
  9500. * and destroy them only once in remove
  9501. */
  9502. mutex_init(&hw->aq.asq_mutex);
  9503. mutex_init(&hw->aq.arq_mutex);
  9504. if (debug != -1) {
  9505. pf->msg_enable = pf->hw.debug_mask;
  9506. pf->msg_enable = debug;
  9507. }
  9508. /* do a special CORER for clearing PXE mode once at init */
  9509. if (hw->revision_id == 0 &&
  9510. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  9511. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  9512. i40e_flush(hw);
  9513. msleep(200);
  9514. pf->corer_count++;
  9515. i40e_clear_pxe_mode(hw);
  9516. }
  9517. /* Reset here to make sure all is clean and to define PF 'n' */
  9518. i40e_clear_hw(hw);
  9519. err = i40e_pf_reset(hw);
  9520. if (err) {
  9521. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  9522. goto err_pf_reset;
  9523. }
  9524. pf->pfr_count++;
  9525. hw->aq.num_arq_entries = I40E_AQ_LEN;
  9526. hw->aq.num_asq_entries = I40E_AQ_LEN;
  9527. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9528. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9529. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  9530. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  9531. "%s-%s:misc",
  9532. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  9533. err = i40e_init_shared_code(hw);
  9534. if (err) {
  9535. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  9536. err);
  9537. goto err_pf_reset;
  9538. }
  9539. /* set up a default setting for link flow control */
  9540. pf->hw.fc.requested_mode = I40E_FC_NONE;
  9541. err = i40e_init_adminq(hw);
  9542. if (err) {
  9543. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  9544. dev_info(&pdev->dev,
  9545. "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");
  9546. else
  9547. dev_info(&pdev->dev,
  9548. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  9549. goto err_pf_reset;
  9550. }
  9551. /* provide nvm, fw, api versions */
  9552. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  9553. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  9554. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  9555. i40e_nvm_version_str(hw));
  9556. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  9557. hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
  9558. dev_info(&pdev->dev,
  9559. "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");
  9560. else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
  9561. hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
  9562. dev_info(&pdev->dev,
  9563. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  9564. i40e_verify_eeprom(pf);
  9565. /* Rev 0 hardware was never productized */
  9566. if (hw->revision_id < 1)
  9567. 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");
  9568. i40e_clear_pxe_mode(hw);
  9569. err = i40e_get_capabilities(pf);
  9570. if (err)
  9571. goto err_adminq_setup;
  9572. err = i40e_sw_init(pf);
  9573. if (err) {
  9574. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  9575. goto err_sw_init;
  9576. }
  9577. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  9578. hw->func_caps.num_rx_qp,
  9579. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  9580. if (err) {
  9581. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  9582. goto err_init_lan_hmc;
  9583. }
  9584. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  9585. if (err) {
  9586. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  9587. err = -ENOENT;
  9588. goto err_configure_lan_hmc;
  9589. }
  9590. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  9591. * Ignore error return codes because if it was already disabled via
  9592. * hardware settings this will fail
  9593. */
  9594. if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
  9595. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  9596. i40e_aq_stop_lldp(hw, true, NULL);
  9597. }
  9598. i40e_get_mac_addr(hw, hw->mac.addr);
  9599. /* allow a platform config to override the HW addr */
  9600. i40e_get_platform_mac_addr(pdev, pf);
  9601. if (!is_valid_ether_addr(hw->mac.addr)) {
  9602. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  9603. err = -EIO;
  9604. goto err_mac_addr;
  9605. }
  9606. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  9607. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  9608. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  9609. if (is_valid_ether_addr(hw->mac.port_addr))
  9610. pf->flags |= I40E_FLAG_PORT_ID_VALID;
  9611. #ifdef I40E_FCOE
  9612. err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
  9613. if (err)
  9614. dev_info(&pdev->dev,
  9615. "(non-fatal) SAN MAC retrieval failed: %d\n", err);
  9616. if (!is_valid_ether_addr(hw->mac.san_addr)) {
  9617. dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
  9618. hw->mac.san_addr);
  9619. ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
  9620. }
  9621. dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
  9622. #endif /* I40E_FCOE */
  9623. pci_set_drvdata(pdev, pf);
  9624. pci_save_state(pdev);
  9625. #ifdef CONFIG_I40E_DCB
  9626. err = i40e_init_pf_dcb(pf);
  9627. if (err) {
  9628. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  9629. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  9630. /* Continue without DCB enabled */
  9631. }
  9632. #endif /* CONFIG_I40E_DCB */
  9633. /* set up periodic task facility */
  9634. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  9635. pf->service_timer_period = HZ;
  9636. INIT_WORK(&pf->service_task, i40e_service_task);
  9637. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  9638. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  9639. /* NVM bit on means WoL disabled for the port */
  9640. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  9641. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  9642. pf->wol_en = false;
  9643. else
  9644. pf->wol_en = true;
  9645. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  9646. /* set up the main switch operations */
  9647. i40e_determine_queue_usage(pf);
  9648. err = i40e_init_interrupt_scheme(pf);
  9649. if (err)
  9650. goto err_switch_setup;
  9651. /* The number of VSIs reported by the FW is the minimum guaranteed
  9652. * to us; HW supports far more and we share the remaining pool with
  9653. * the other PFs. We allocate space for more than the guarantee with
  9654. * the understanding that we might not get them all later.
  9655. */
  9656. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  9657. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  9658. else
  9659. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  9660. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  9661. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  9662. GFP_KERNEL);
  9663. if (!pf->vsi) {
  9664. err = -ENOMEM;
  9665. goto err_switch_setup;
  9666. }
  9667. #ifdef CONFIG_PCI_IOV
  9668. /* prep for VF support */
  9669. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9670. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9671. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9672. if (pci_num_vf(pdev))
  9673. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  9674. }
  9675. #endif
  9676. err = i40e_setup_pf_switch(pf, false);
  9677. if (err) {
  9678. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  9679. goto err_vsis;
  9680. }
  9681. /* Make sure flow control is set according to current settings */
  9682. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  9683. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  9684. dev_dbg(&pf->pdev->dev,
  9685. "Set fc with err %s aq_err %s on get_phy_cap\n",
  9686. i40e_stat_str(hw, err),
  9687. i40e_aq_str(hw, hw->aq.asq_last_status));
  9688. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  9689. dev_dbg(&pf->pdev->dev,
  9690. "Set fc with err %s aq_err %s on set_phy_config\n",
  9691. i40e_stat_str(hw, err),
  9692. i40e_aq_str(hw, hw->aq.asq_last_status));
  9693. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  9694. dev_dbg(&pf->pdev->dev,
  9695. "Set fc with err %s aq_err %s on get_link_info\n",
  9696. i40e_stat_str(hw, err),
  9697. i40e_aq_str(hw, hw->aq.asq_last_status));
  9698. /* if FDIR VSI was set up, start it now */
  9699. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9700. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  9701. i40e_vsi_open(pf->vsi[i]);
  9702. break;
  9703. }
  9704. }
  9705. /* The driver only wants link up/down and module qualification
  9706. * reports from firmware. Note the negative logic.
  9707. */
  9708. err = i40e_aq_set_phy_int_mask(&pf->hw,
  9709. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  9710. I40E_AQ_EVENT_MEDIA_NA |
  9711. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  9712. if (err)
  9713. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  9714. i40e_stat_str(&pf->hw, err),
  9715. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9716. /* Reconfigure hardware for allowing smaller MSS in the case
  9717. * of TSO, so that we avoid the MDD being fired and causing
  9718. * a reset in the case of small MSS+TSO.
  9719. */
  9720. val = rd32(hw, I40E_REG_MSS);
  9721. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  9722. val &= ~I40E_REG_MSS_MIN_MASK;
  9723. val |= I40E_64BYTE_MSS;
  9724. wr32(hw, I40E_REG_MSS, val);
  9725. }
  9726. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  9727. msleep(75);
  9728. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  9729. if (err)
  9730. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  9731. i40e_stat_str(&pf->hw, err),
  9732. i40e_aq_str(&pf->hw,
  9733. pf->hw.aq.asq_last_status));
  9734. }
  9735. /* The main driver is (mostly) up and happy. We need to set this state
  9736. * before setting up the misc vector or we get a race and the vector
  9737. * ends up disabled forever.
  9738. */
  9739. clear_bit(__I40E_DOWN, &pf->state);
  9740. /* In case of MSIX we are going to setup the misc vector right here
  9741. * to handle admin queue events etc. In case of legacy and MSI
  9742. * the misc functionality and queue processing is combined in
  9743. * the same vector and that gets setup at open.
  9744. */
  9745. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9746. err = i40e_setup_misc_vector(pf);
  9747. if (err) {
  9748. dev_info(&pdev->dev,
  9749. "setup of misc vector failed: %d\n", err);
  9750. goto err_vsis;
  9751. }
  9752. }
  9753. #ifdef CONFIG_PCI_IOV
  9754. /* prep for VF support */
  9755. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9756. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9757. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9758. /* disable link interrupts for VFs */
  9759. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  9760. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  9761. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  9762. i40e_flush(hw);
  9763. if (pci_num_vf(pdev)) {
  9764. dev_info(&pdev->dev,
  9765. "Active VFs found, allocating resources.\n");
  9766. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  9767. if (err)
  9768. dev_info(&pdev->dev,
  9769. "Error %d allocating resources for existing VFs\n",
  9770. err);
  9771. }
  9772. }
  9773. #endif /* CONFIG_PCI_IOV */
  9774. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9775. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  9776. pf->num_iwarp_msix,
  9777. I40E_IWARP_IRQ_PILE_ID);
  9778. if (pf->iwarp_base_vector < 0) {
  9779. dev_info(&pdev->dev,
  9780. "failed to get tracking for %d vectors for IWARP err=%d\n",
  9781. pf->num_iwarp_msix, pf->iwarp_base_vector);
  9782. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9783. }
  9784. }
  9785. i40e_dbg_pf_init(pf);
  9786. /* tell the firmware that we're starting */
  9787. i40e_send_version(pf);
  9788. /* since everything's happy, start the service_task timer */
  9789. mod_timer(&pf->service_timer,
  9790. round_jiffies(jiffies + pf->service_timer_period));
  9791. /* add this PF to client device list and launch a client service task */
  9792. err = i40e_lan_add_device(pf);
  9793. if (err)
  9794. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  9795. err);
  9796. #ifdef I40E_FCOE
  9797. /* create FCoE interface */
  9798. i40e_fcoe_vsi_setup(pf);
  9799. #endif
  9800. #define PCI_SPEED_SIZE 8
  9801. #define PCI_WIDTH_SIZE 8
  9802. /* Devices on the IOSF bus do not have this information
  9803. * and will report PCI Gen 1 x 1 by default so don't bother
  9804. * checking them.
  9805. */
  9806. if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
  9807. char speed[PCI_SPEED_SIZE] = "Unknown";
  9808. char width[PCI_WIDTH_SIZE] = "Unknown";
  9809. /* Get the negotiated link width and speed from PCI config
  9810. * space
  9811. */
  9812. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  9813. &link_status);
  9814. i40e_set_pci_config_data(hw, link_status);
  9815. switch (hw->bus.speed) {
  9816. case i40e_bus_speed_8000:
  9817. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  9818. case i40e_bus_speed_5000:
  9819. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  9820. case i40e_bus_speed_2500:
  9821. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  9822. default:
  9823. break;
  9824. }
  9825. switch (hw->bus.width) {
  9826. case i40e_bus_width_pcie_x8:
  9827. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  9828. case i40e_bus_width_pcie_x4:
  9829. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  9830. case i40e_bus_width_pcie_x2:
  9831. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  9832. case i40e_bus_width_pcie_x1:
  9833. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  9834. default:
  9835. break;
  9836. }
  9837. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  9838. speed, width);
  9839. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  9840. hw->bus.speed < i40e_bus_speed_8000) {
  9841. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  9842. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  9843. }
  9844. }
  9845. /* get the requested speeds from the fw */
  9846. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  9847. if (err)
  9848. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  9849. i40e_stat_str(&pf->hw, err),
  9850. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9851. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  9852. /* get the supported phy types from the fw */
  9853. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  9854. if (err)
  9855. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  9856. i40e_stat_str(&pf->hw, err),
  9857. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9858. pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
  9859. /* Add a filter to drop all Flow control frames from any VSI from being
  9860. * transmitted. By doing so we stop a malicious VF from sending out
  9861. * PAUSE or PFC frames and potentially controlling traffic for other
  9862. * PF/VF VSIs.
  9863. * The FW can still send Flow control frames if enabled.
  9864. */
  9865. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  9866. pf->main_vsi_seid);
  9867. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  9868. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  9869. pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY;
  9870. /* print a string summarizing features */
  9871. i40e_print_features(pf);
  9872. return 0;
  9873. /* Unwind what we've done if something failed in the setup */
  9874. err_vsis:
  9875. set_bit(__I40E_DOWN, &pf->state);
  9876. i40e_clear_interrupt_scheme(pf);
  9877. kfree(pf->vsi);
  9878. err_switch_setup:
  9879. i40e_reset_interrupt_capability(pf);
  9880. del_timer_sync(&pf->service_timer);
  9881. err_mac_addr:
  9882. err_configure_lan_hmc:
  9883. (void)i40e_shutdown_lan_hmc(hw);
  9884. err_init_lan_hmc:
  9885. kfree(pf->qp_pile);
  9886. err_sw_init:
  9887. err_adminq_setup:
  9888. err_pf_reset:
  9889. iounmap(hw->hw_addr);
  9890. err_ioremap:
  9891. kfree(pf);
  9892. err_pf_alloc:
  9893. pci_disable_pcie_error_reporting(pdev);
  9894. pci_release_selected_regions(pdev,
  9895. pci_select_bars(pdev, IORESOURCE_MEM));
  9896. err_pci_reg:
  9897. err_dma:
  9898. pci_disable_device(pdev);
  9899. return err;
  9900. }
  9901. /**
  9902. * i40e_remove - Device removal routine
  9903. * @pdev: PCI device information struct
  9904. *
  9905. * i40e_remove is called by the PCI subsystem to alert the driver
  9906. * that is should release a PCI device. This could be caused by a
  9907. * Hot-Plug event, or because the driver is going to be removed from
  9908. * memory.
  9909. **/
  9910. static void i40e_remove(struct pci_dev *pdev)
  9911. {
  9912. struct i40e_pf *pf = pci_get_drvdata(pdev);
  9913. struct i40e_hw *hw = &pf->hw;
  9914. i40e_status ret_code;
  9915. int i;
  9916. i40e_dbg_pf_exit(pf);
  9917. i40e_ptp_stop(pf);
  9918. /* Disable RSS in hw */
  9919. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  9920. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  9921. /* no more scheduling of any task */
  9922. set_bit(__I40E_SUSPENDED, &pf->state);
  9923. set_bit(__I40E_DOWN, &pf->state);
  9924. if (pf->service_timer.data)
  9925. del_timer_sync(&pf->service_timer);
  9926. if (pf->service_task.func)
  9927. cancel_work_sync(&pf->service_task);
  9928. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  9929. i40e_free_vfs(pf);
  9930. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  9931. }
  9932. i40e_fdir_teardown(pf);
  9933. /* If there is a switch structure or any orphans, remove them.
  9934. * This will leave only the PF's VSI remaining.
  9935. */
  9936. for (i = 0; i < I40E_MAX_VEB; i++) {
  9937. if (!pf->veb[i])
  9938. continue;
  9939. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  9940. pf->veb[i]->uplink_seid == 0)
  9941. i40e_switch_branch_release(pf->veb[i]);
  9942. }
  9943. /* Now we can shutdown the PF's VSI, just before we kill
  9944. * adminq and hmc.
  9945. */
  9946. if (pf->vsi[pf->lan_vsi])
  9947. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  9948. /* remove attached clients */
  9949. ret_code = i40e_lan_del_device(pf);
  9950. if (ret_code) {
  9951. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  9952. ret_code);
  9953. }
  9954. /* shutdown and destroy the HMC */
  9955. if (hw->hmc.hmc_obj) {
  9956. ret_code = i40e_shutdown_lan_hmc(hw);
  9957. if (ret_code)
  9958. dev_warn(&pdev->dev,
  9959. "Failed to destroy the HMC resources: %d\n",
  9960. ret_code);
  9961. }
  9962. /* shutdown the adminq */
  9963. ret_code = i40e_shutdown_adminq(hw);
  9964. if (ret_code)
  9965. dev_warn(&pdev->dev,
  9966. "Failed to destroy the Admin Queue resources: %d\n",
  9967. ret_code);
  9968. /* destroy the locks only once, here */
  9969. mutex_destroy(&hw->aq.arq_mutex);
  9970. mutex_destroy(&hw->aq.asq_mutex);
  9971. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  9972. i40e_clear_interrupt_scheme(pf);
  9973. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9974. if (pf->vsi[i]) {
  9975. i40e_vsi_clear_rings(pf->vsi[i]);
  9976. i40e_vsi_clear(pf->vsi[i]);
  9977. pf->vsi[i] = NULL;
  9978. }
  9979. }
  9980. for (i = 0; i < I40E_MAX_VEB; i++) {
  9981. kfree(pf->veb[i]);
  9982. pf->veb[i] = NULL;
  9983. }
  9984. kfree(pf->qp_pile);
  9985. kfree(pf->vsi);
  9986. iounmap(hw->hw_addr);
  9987. kfree(pf);
  9988. pci_release_selected_regions(pdev,
  9989. pci_select_bars(pdev, IORESOURCE_MEM));
  9990. pci_disable_pcie_error_reporting(pdev);
  9991. pci_disable_device(pdev);
  9992. }
  9993. /**
  9994. * i40e_pci_error_detected - warning that something funky happened in PCI land
  9995. * @pdev: PCI device information struct
  9996. *
  9997. * Called to warn that something happened and the error handling steps
  9998. * are in progress. Allows the driver to quiesce things, be ready for
  9999. * remediation.
  10000. **/
  10001. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  10002. enum pci_channel_state error)
  10003. {
  10004. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10005. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  10006. /* shutdown all operations */
  10007. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  10008. rtnl_lock();
  10009. i40e_prep_for_reset(pf);
  10010. rtnl_unlock();
  10011. }
  10012. /* Request a slot reset */
  10013. return PCI_ERS_RESULT_NEED_RESET;
  10014. }
  10015. /**
  10016. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  10017. * @pdev: PCI device information struct
  10018. *
  10019. * Called to find if the driver can work with the device now that
  10020. * the pci slot has been reset. If a basic connection seems good
  10021. * (registers are readable and have sane content) then return a
  10022. * happy little PCI_ERS_RESULT_xxx.
  10023. **/
  10024. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  10025. {
  10026. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10027. pci_ers_result_t result;
  10028. int err;
  10029. u32 reg;
  10030. dev_dbg(&pdev->dev, "%s\n", __func__);
  10031. if (pci_enable_device_mem(pdev)) {
  10032. dev_info(&pdev->dev,
  10033. "Cannot re-enable PCI device after reset.\n");
  10034. result = PCI_ERS_RESULT_DISCONNECT;
  10035. } else {
  10036. pci_set_master(pdev);
  10037. pci_restore_state(pdev);
  10038. pci_save_state(pdev);
  10039. pci_wake_from_d3(pdev, false);
  10040. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  10041. if (reg == 0)
  10042. result = PCI_ERS_RESULT_RECOVERED;
  10043. else
  10044. result = PCI_ERS_RESULT_DISCONNECT;
  10045. }
  10046. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  10047. if (err) {
  10048. dev_info(&pdev->dev,
  10049. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  10050. err);
  10051. /* non-fatal, continue */
  10052. }
  10053. return result;
  10054. }
  10055. /**
  10056. * i40e_pci_error_resume - restart operations after PCI error recovery
  10057. * @pdev: PCI device information struct
  10058. *
  10059. * Called to allow the driver to bring things back up after PCI error
  10060. * and/or reset recovery has finished.
  10061. **/
  10062. static void i40e_pci_error_resume(struct pci_dev *pdev)
  10063. {
  10064. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10065. dev_dbg(&pdev->dev, "%s\n", __func__);
  10066. if (test_bit(__I40E_SUSPENDED, &pf->state))
  10067. return;
  10068. rtnl_lock();
  10069. i40e_handle_reset_warning(pf);
  10070. rtnl_unlock();
  10071. }
  10072. /**
  10073. * i40e_shutdown - PCI callback for shutting down
  10074. * @pdev: PCI device information struct
  10075. **/
  10076. static void i40e_shutdown(struct pci_dev *pdev)
  10077. {
  10078. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10079. struct i40e_hw *hw = &pf->hw;
  10080. set_bit(__I40E_SUSPENDED, &pf->state);
  10081. set_bit(__I40E_DOWN, &pf->state);
  10082. rtnl_lock();
  10083. i40e_prep_for_reset(pf);
  10084. rtnl_unlock();
  10085. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10086. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10087. del_timer_sync(&pf->service_timer);
  10088. cancel_work_sync(&pf->service_task);
  10089. i40e_fdir_teardown(pf);
  10090. rtnl_lock();
  10091. i40e_prep_for_reset(pf);
  10092. rtnl_unlock();
  10093. wr32(hw, I40E_PFPM_APM,
  10094. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10095. wr32(hw, I40E_PFPM_WUFC,
  10096. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10097. i40e_clear_interrupt_scheme(pf);
  10098. if (system_state == SYSTEM_POWER_OFF) {
  10099. pci_wake_from_d3(pdev, pf->wol_en);
  10100. pci_set_power_state(pdev, PCI_D3hot);
  10101. }
  10102. }
  10103. #ifdef CONFIG_PM
  10104. /**
  10105. * i40e_suspend - PCI callback for moving to D3
  10106. * @pdev: PCI device information struct
  10107. **/
  10108. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  10109. {
  10110. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10111. struct i40e_hw *hw = &pf->hw;
  10112. set_bit(__I40E_SUSPENDED, &pf->state);
  10113. set_bit(__I40E_DOWN, &pf->state);
  10114. rtnl_lock();
  10115. i40e_prep_for_reset(pf);
  10116. rtnl_unlock();
  10117. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10118. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10119. pci_wake_from_d3(pdev, pf->wol_en);
  10120. pci_set_power_state(pdev, PCI_D3hot);
  10121. return 0;
  10122. }
  10123. /**
  10124. * i40e_resume - PCI callback for waking up from D3
  10125. * @pdev: PCI device information struct
  10126. **/
  10127. static int i40e_resume(struct pci_dev *pdev)
  10128. {
  10129. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10130. u32 err;
  10131. pci_set_power_state(pdev, PCI_D0);
  10132. pci_restore_state(pdev);
  10133. /* pci_restore_state() clears dev->state_saves, so
  10134. * call pci_save_state() again to restore it.
  10135. */
  10136. pci_save_state(pdev);
  10137. err = pci_enable_device_mem(pdev);
  10138. if (err) {
  10139. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  10140. return err;
  10141. }
  10142. pci_set_master(pdev);
  10143. /* no wakeup events while running */
  10144. pci_wake_from_d3(pdev, false);
  10145. /* handling the reset will rebuild the device state */
  10146. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  10147. clear_bit(__I40E_DOWN, &pf->state);
  10148. rtnl_lock();
  10149. i40e_reset_and_rebuild(pf, false);
  10150. rtnl_unlock();
  10151. }
  10152. return 0;
  10153. }
  10154. #endif
  10155. static const struct pci_error_handlers i40e_err_handler = {
  10156. .error_detected = i40e_pci_error_detected,
  10157. .slot_reset = i40e_pci_error_slot_reset,
  10158. .resume = i40e_pci_error_resume,
  10159. };
  10160. static struct pci_driver i40e_driver = {
  10161. .name = i40e_driver_name,
  10162. .id_table = i40e_pci_tbl,
  10163. .probe = i40e_probe,
  10164. .remove = i40e_remove,
  10165. #ifdef CONFIG_PM
  10166. .suspend = i40e_suspend,
  10167. .resume = i40e_resume,
  10168. #endif
  10169. .shutdown = i40e_shutdown,
  10170. .err_handler = &i40e_err_handler,
  10171. .sriov_configure = i40e_pci_sriov_configure,
  10172. };
  10173. /**
  10174. * i40e_init_module - Driver registration routine
  10175. *
  10176. * i40e_init_module is the first routine called when the driver is
  10177. * loaded. All it does is register with the PCI subsystem.
  10178. **/
  10179. static int __init i40e_init_module(void)
  10180. {
  10181. pr_info("%s: %s - version %s\n", i40e_driver_name,
  10182. i40e_driver_string, i40e_driver_version_str);
  10183. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  10184. /* we will see if single thread per module is enough for now,
  10185. * it can't be any worse than using the system workqueue which
  10186. * was already single threaded
  10187. */
  10188. i40e_wq = create_singlethread_workqueue(i40e_driver_name);
  10189. if (!i40e_wq) {
  10190. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  10191. return -ENOMEM;
  10192. }
  10193. i40e_dbg_init();
  10194. return pci_register_driver(&i40e_driver);
  10195. }
  10196. module_init(i40e_init_module);
  10197. /**
  10198. * i40e_exit_module - Driver exit cleanup routine
  10199. *
  10200. * i40e_exit_module is called just before the driver is removed
  10201. * from memory.
  10202. **/
  10203. static void __exit i40e_exit_module(void)
  10204. {
  10205. pci_unregister_driver(&i40e_driver);
  10206. destroy_workqueue(i40e_wq);
  10207. i40e_dbg_exit();
  10208. }
  10209. module_exit(i40e_exit_module);