i40e_main.c 235 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 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. /* Local includes */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. #ifdef CONFIG_I40E_VXLAN
  30. #include <net/vxlan.h>
  31. #endif
  32. const char i40e_driver_name[] = "i40e";
  33. static const char i40e_driver_string[] =
  34. "Intel(R) Ethernet Connection XL710 Network Driver";
  35. #define DRV_KERN "-k"
  36. #define DRV_VERSION_MAJOR 0
  37. #define DRV_VERSION_MINOR 3
  38. #define DRV_VERSION_BUILD 46
  39. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  40. __stringify(DRV_VERSION_MINOR) "." \
  41. __stringify(DRV_VERSION_BUILD) DRV_KERN
  42. const char i40e_driver_version_str[] = DRV_VERSION;
  43. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  44. /* a bit of forward declarations */
  45. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  46. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  47. static int i40e_add_vsi(struct i40e_vsi *vsi);
  48. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  49. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  50. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  51. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  52. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  53. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  54. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  55. /* i40e_pci_tbl - PCI Device ID Table
  56. *
  57. * Last entry must be all 0s
  58. *
  59. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  60. * Class, Class Mask, private data (not used) }
  61. */
  62. static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = {
  63. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X710), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_D), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  71. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  72. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  73. /* required last entry */
  74. {0, }
  75. };
  76. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  77. #define I40E_MAX_VF_COUNT 128
  78. static int debug = -1;
  79. module_param(debug, int, 0);
  80. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  81. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  82. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_VERSION);
  85. /**
  86. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  87. * @hw: pointer to the HW structure
  88. * @mem: ptr to mem struct to fill out
  89. * @size: size of memory requested
  90. * @alignment: what to align the allocation to
  91. **/
  92. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  93. u64 size, u32 alignment)
  94. {
  95. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  96. mem->size = ALIGN(size, alignment);
  97. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  98. &mem->pa, GFP_KERNEL);
  99. if (!mem->va)
  100. return -ENOMEM;
  101. return 0;
  102. }
  103. /**
  104. * i40e_free_dma_mem_d - OS specific memory free for shared code
  105. * @hw: pointer to the HW structure
  106. * @mem: ptr to mem struct to free
  107. **/
  108. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  109. {
  110. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  111. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  112. mem->va = NULL;
  113. mem->pa = 0;
  114. mem->size = 0;
  115. return 0;
  116. }
  117. /**
  118. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  119. * @hw: pointer to the HW structure
  120. * @mem: ptr to mem struct to fill out
  121. * @size: size of memory requested
  122. **/
  123. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  124. u32 size)
  125. {
  126. mem->size = size;
  127. mem->va = kzalloc(size, GFP_KERNEL);
  128. if (!mem->va)
  129. return -ENOMEM;
  130. return 0;
  131. }
  132. /**
  133. * i40e_free_virt_mem_d - OS specific memory free for shared code
  134. * @hw: pointer to the HW structure
  135. * @mem: ptr to mem struct to free
  136. **/
  137. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  138. {
  139. /* it's ok to kfree a NULL pointer */
  140. kfree(mem->va);
  141. mem->va = NULL;
  142. mem->size = 0;
  143. return 0;
  144. }
  145. /**
  146. * i40e_get_lump - find a lump of free generic resource
  147. * @pf: board private structure
  148. * @pile: the pile of resource to search
  149. * @needed: the number of items needed
  150. * @id: an owner id to stick on the items assigned
  151. *
  152. * Returns the base item index of the lump, or negative for error
  153. *
  154. * The search_hint trick and lack of advanced fit-finding only work
  155. * because we're highly likely to have all the same size lump requests.
  156. * Linear search time and any fragmentation should be minimal.
  157. **/
  158. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  159. u16 needed, u16 id)
  160. {
  161. int ret = -ENOMEM;
  162. int i, j;
  163. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  164. dev_info(&pf->pdev->dev,
  165. "param err: pile=%p needed=%d id=0x%04x\n",
  166. pile, needed, id);
  167. return -EINVAL;
  168. }
  169. /* start the linear search with an imperfect hint */
  170. i = pile->search_hint;
  171. while (i < pile->num_entries) {
  172. /* skip already allocated entries */
  173. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  174. i++;
  175. continue;
  176. }
  177. /* do we have enough in this lump? */
  178. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  179. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  180. break;
  181. }
  182. if (j == needed) {
  183. /* there was enough, so assign it to the requestor */
  184. for (j = 0; j < needed; j++)
  185. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  186. ret = i;
  187. pile->search_hint = i + j;
  188. break;
  189. } else {
  190. /* not enough, so skip over it and continue looking */
  191. i += j;
  192. }
  193. }
  194. return ret;
  195. }
  196. /**
  197. * i40e_put_lump - return a lump of generic resource
  198. * @pile: the pile of resource to search
  199. * @index: the base item index
  200. * @id: the owner id of the items assigned
  201. *
  202. * Returns the count of items in the lump
  203. **/
  204. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  205. {
  206. int valid_id = (id | I40E_PILE_VALID_BIT);
  207. int count = 0;
  208. int i;
  209. if (!pile || index >= pile->num_entries)
  210. return -EINVAL;
  211. for (i = index;
  212. i < pile->num_entries && pile->list[i] == valid_id;
  213. i++) {
  214. pile->list[i] = 0;
  215. count++;
  216. }
  217. if (count && index < pile->search_hint)
  218. pile->search_hint = index;
  219. return count;
  220. }
  221. /**
  222. * i40e_service_event_schedule - Schedule the service task to wake up
  223. * @pf: board private structure
  224. *
  225. * If not already scheduled, this puts the task into the work queue
  226. **/
  227. static void i40e_service_event_schedule(struct i40e_pf *pf)
  228. {
  229. if (!test_bit(__I40E_DOWN, &pf->state) &&
  230. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
  231. !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  232. schedule_work(&pf->service_task);
  233. }
  234. /**
  235. * i40e_tx_timeout - Respond to a Tx Hang
  236. * @netdev: network interface device structure
  237. *
  238. * If any port has noticed a Tx timeout, it is likely that the whole
  239. * device is munged, not just the one netdev port, so go for the full
  240. * reset.
  241. **/
  242. static void i40e_tx_timeout(struct net_device *netdev)
  243. {
  244. struct i40e_netdev_priv *np = netdev_priv(netdev);
  245. struct i40e_vsi *vsi = np->vsi;
  246. struct i40e_pf *pf = vsi->back;
  247. pf->tx_timeout_count++;
  248. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  249. pf->tx_timeout_recovery_level = 0;
  250. pf->tx_timeout_last_recovery = jiffies;
  251. netdev_info(netdev, "tx_timeout recovery level %d\n",
  252. pf->tx_timeout_recovery_level);
  253. switch (pf->tx_timeout_recovery_level) {
  254. case 0:
  255. /* disable and re-enable queues for the VSI */
  256. if (in_interrupt()) {
  257. set_bit(__I40E_REINIT_REQUESTED, &pf->state);
  258. set_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  259. } else {
  260. i40e_vsi_reinit_locked(vsi);
  261. }
  262. break;
  263. case 1:
  264. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  265. break;
  266. case 2:
  267. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  268. break;
  269. case 3:
  270. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  271. break;
  272. default:
  273. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  274. set_bit(__I40E_DOWN, &vsi->state);
  275. i40e_down(vsi);
  276. break;
  277. }
  278. i40e_service_event_schedule(pf);
  279. pf->tx_timeout_recovery_level++;
  280. }
  281. /**
  282. * i40e_release_rx_desc - Store the new tail and head values
  283. * @rx_ring: ring to bump
  284. * @val: new head index
  285. **/
  286. static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
  287. {
  288. rx_ring->next_to_use = val;
  289. /* Force memory writes to complete before letting h/w
  290. * know there are new descriptors to fetch. (Only
  291. * applicable for weak-ordered memory model archs,
  292. * such as IA-64).
  293. */
  294. wmb();
  295. writel(val, rx_ring->tail);
  296. }
  297. /**
  298. * i40e_get_vsi_stats_struct - Get System Network Statistics
  299. * @vsi: the VSI we care about
  300. *
  301. * Returns the address of the device statistics structure.
  302. * The statistics are actually updated from the service task.
  303. **/
  304. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  305. {
  306. return &vsi->net_stats;
  307. }
  308. /**
  309. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  310. * @netdev: network interface device structure
  311. *
  312. * Returns the address of the device statistics structure.
  313. * The statistics are actually updated from the service task.
  314. **/
  315. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  316. struct net_device *netdev,
  317. struct rtnl_link_stats64 *stats)
  318. {
  319. struct i40e_netdev_priv *np = netdev_priv(netdev);
  320. struct i40e_vsi *vsi = np->vsi;
  321. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  322. int i;
  323. if (test_bit(__I40E_DOWN, &vsi->state))
  324. return stats;
  325. if (!vsi->tx_rings)
  326. return stats;
  327. rcu_read_lock();
  328. for (i = 0; i < vsi->num_queue_pairs; i++) {
  329. struct i40e_ring *tx_ring, *rx_ring;
  330. u64 bytes, packets;
  331. unsigned int start;
  332. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  333. if (!tx_ring)
  334. continue;
  335. do {
  336. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  337. packets = tx_ring->stats.packets;
  338. bytes = tx_ring->stats.bytes;
  339. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  340. stats->tx_packets += packets;
  341. stats->tx_bytes += bytes;
  342. rx_ring = &tx_ring[1];
  343. do {
  344. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  345. packets = rx_ring->stats.packets;
  346. bytes = rx_ring->stats.bytes;
  347. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  348. stats->rx_packets += packets;
  349. stats->rx_bytes += bytes;
  350. }
  351. rcu_read_unlock();
  352. /* following stats updated by ixgbe_watchdog_task() */
  353. stats->multicast = vsi_stats->multicast;
  354. stats->tx_errors = vsi_stats->tx_errors;
  355. stats->tx_dropped = vsi_stats->tx_dropped;
  356. stats->rx_errors = vsi_stats->rx_errors;
  357. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  358. stats->rx_length_errors = vsi_stats->rx_length_errors;
  359. return stats;
  360. }
  361. /**
  362. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  363. * @vsi: the VSI to have its stats reset
  364. **/
  365. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  366. {
  367. struct rtnl_link_stats64 *ns;
  368. int i;
  369. if (!vsi)
  370. return;
  371. ns = i40e_get_vsi_stats_struct(vsi);
  372. memset(ns, 0, sizeof(*ns));
  373. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  374. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  375. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  376. if (vsi->rx_rings && vsi->rx_rings[0]) {
  377. for (i = 0; i < vsi->num_queue_pairs; i++) {
  378. memset(&vsi->rx_rings[i]->stats, 0 ,
  379. sizeof(vsi->rx_rings[i]->stats));
  380. memset(&vsi->rx_rings[i]->rx_stats, 0 ,
  381. sizeof(vsi->rx_rings[i]->rx_stats));
  382. memset(&vsi->tx_rings[i]->stats, 0 ,
  383. sizeof(vsi->tx_rings[i]->stats));
  384. memset(&vsi->tx_rings[i]->tx_stats, 0,
  385. sizeof(vsi->tx_rings[i]->tx_stats));
  386. }
  387. }
  388. vsi->stat_offsets_loaded = false;
  389. }
  390. /**
  391. * i40e_pf_reset_stats - Reset all of the stats for the given pf
  392. * @pf: the PF to be reset
  393. **/
  394. void i40e_pf_reset_stats(struct i40e_pf *pf)
  395. {
  396. memset(&pf->stats, 0, sizeof(pf->stats));
  397. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  398. pf->stat_offsets_loaded = false;
  399. }
  400. /**
  401. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  402. * @hw: ptr to the hardware info
  403. * @hireg: the high 32 bit reg to read
  404. * @loreg: the low 32 bit reg to read
  405. * @offset_loaded: has the initial offset been loaded yet
  406. * @offset: ptr to current offset value
  407. * @stat: ptr to the stat
  408. *
  409. * Since the device stats are not reset at PFReset, they likely will not
  410. * be zeroed when the driver starts. We'll save the first values read
  411. * and use them as offsets to be subtracted from the raw values in order
  412. * to report stats that count from zero. In the process, we also manage
  413. * the potential roll-over.
  414. **/
  415. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  416. bool offset_loaded, u64 *offset, u64 *stat)
  417. {
  418. u64 new_data;
  419. if (hw->device_id == I40E_DEV_ID_QEMU) {
  420. new_data = rd32(hw, loreg);
  421. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  422. } else {
  423. new_data = rd64(hw, loreg);
  424. }
  425. if (!offset_loaded)
  426. *offset = new_data;
  427. if (likely(new_data >= *offset))
  428. *stat = new_data - *offset;
  429. else
  430. *stat = (new_data + ((u64)1 << 48)) - *offset;
  431. *stat &= 0xFFFFFFFFFFFFULL;
  432. }
  433. /**
  434. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  435. * @hw: ptr to the hardware info
  436. * @reg: the hw reg to read
  437. * @offset_loaded: has the initial offset been loaded yet
  438. * @offset: ptr to current offset value
  439. * @stat: ptr to the stat
  440. **/
  441. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  442. bool offset_loaded, u64 *offset, u64 *stat)
  443. {
  444. u32 new_data;
  445. new_data = rd32(hw, reg);
  446. if (!offset_loaded)
  447. *offset = new_data;
  448. if (likely(new_data >= *offset))
  449. *stat = (u32)(new_data - *offset);
  450. else
  451. *stat = (u32)((new_data + ((u64)1 << 32)) - *offset);
  452. }
  453. /**
  454. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  455. * @vsi: the VSI to be updated
  456. **/
  457. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  458. {
  459. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  460. struct i40e_pf *pf = vsi->back;
  461. struct i40e_hw *hw = &pf->hw;
  462. struct i40e_eth_stats *oes;
  463. struct i40e_eth_stats *es; /* device's eth stats */
  464. es = &vsi->eth_stats;
  465. oes = &vsi->eth_stats_offsets;
  466. /* Gather up the stats that the hw collects */
  467. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  468. vsi->stat_offsets_loaded,
  469. &oes->tx_errors, &es->tx_errors);
  470. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  471. vsi->stat_offsets_loaded,
  472. &oes->rx_discards, &es->rx_discards);
  473. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  474. I40E_GLV_GORCL(stat_idx),
  475. vsi->stat_offsets_loaded,
  476. &oes->rx_bytes, &es->rx_bytes);
  477. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  478. I40E_GLV_UPRCL(stat_idx),
  479. vsi->stat_offsets_loaded,
  480. &oes->rx_unicast, &es->rx_unicast);
  481. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  482. I40E_GLV_MPRCL(stat_idx),
  483. vsi->stat_offsets_loaded,
  484. &oes->rx_multicast, &es->rx_multicast);
  485. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  486. I40E_GLV_BPRCL(stat_idx),
  487. vsi->stat_offsets_loaded,
  488. &oes->rx_broadcast, &es->rx_broadcast);
  489. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  490. I40E_GLV_GOTCL(stat_idx),
  491. vsi->stat_offsets_loaded,
  492. &oes->tx_bytes, &es->tx_bytes);
  493. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  494. I40E_GLV_UPTCL(stat_idx),
  495. vsi->stat_offsets_loaded,
  496. &oes->tx_unicast, &es->tx_unicast);
  497. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  498. I40E_GLV_MPTCL(stat_idx),
  499. vsi->stat_offsets_loaded,
  500. &oes->tx_multicast, &es->tx_multicast);
  501. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  502. I40E_GLV_BPTCL(stat_idx),
  503. vsi->stat_offsets_loaded,
  504. &oes->tx_broadcast, &es->tx_broadcast);
  505. vsi->stat_offsets_loaded = true;
  506. }
  507. /**
  508. * i40e_update_veb_stats - Update Switch component statistics
  509. * @veb: the VEB being updated
  510. **/
  511. static void i40e_update_veb_stats(struct i40e_veb *veb)
  512. {
  513. struct i40e_pf *pf = veb->pf;
  514. struct i40e_hw *hw = &pf->hw;
  515. struct i40e_eth_stats *oes;
  516. struct i40e_eth_stats *es; /* device's eth stats */
  517. int idx = 0;
  518. idx = veb->stats_idx;
  519. es = &veb->stats;
  520. oes = &veb->stats_offsets;
  521. /* Gather up the stats that the hw collects */
  522. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  523. veb->stat_offsets_loaded,
  524. &oes->tx_discards, &es->tx_discards);
  525. if (hw->revision_id > 0)
  526. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  527. veb->stat_offsets_loaded,
  528. &oes->rx_unknown_protocol,
  529. &es->rx_unknown_protocol);
  530. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  531. veb->stat_offsets_loaded,
  532. &oes->rx_bytes, &es->rx_bytes);
  533. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  534. veb->stat_offsets_loaded,
  535. &oes->rx_unicast, &es->rx_unicast);
  536. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  537. veb->stat_offsets_loaded,
  538. &oes->rx_multicast, &es->rx_multicast);
  539. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  540. veb->stat_offsets_loaded,
  541. &oes->rx_broadcast, &es->rx_broadcast);
  542. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  543. veb->stat_offsets_loaded,
  544. &oes->tx_bytes, &es->tx_bytes);
  545. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  546. veb->stat_offsets_loaded,
  547. &oes->tx_unicast, &es->tx_unicast);
  548. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  549. veb->stat_offsets_loaded,
  550. &oes->tx_multicast, &es->tx_multicast);
  551. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  552. veb->stat_offsets_loaded,
  553. &oes->tx_broadcast, &es->tx_broadcast);
  554. veb->stat_offsets_loaded = true;
  555. }
  556. /**
  557. * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
  558. * @pf: the corresponding PF
  559. *
  560. * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
  561. **/
  562. static void i40e_update_link_xoff_rx(struct i40e_pf *pf)
  563. {
  564. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  565. struct i40e_hw_port_stats *nsd = &pf->stats;
  566. struct i40e_hw *hw = &pf->hw;
  567. u64 xoff = 0;
  568. u16 i, v;
  569. if ((hw->fc.current_mode != I40E_FC_FULL) &&
  570. (hw->fc.current_mode != I40E_FC_RX_PAUSE))
  571. return;
  572. xoff = nsd->link_xoff_rx;
  573. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  574. pf->stat_offsets_loaded,
  575. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  576. /* No new LFC xoff rx */
  577. if (!(nsd->link_xoff_rx - xoff))
  578. return;
  579. /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
  580. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  581. struct i40e_vsi *vsi = pf->vsi[v];
  582. if (!vsi)
  583. continue;
  584. for (i = 0; i < vsi->num_queue_pairs; i++) {
  585. struct i40e_ring *ring = vsi->tx_rings[i];
  586. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  587. }
  588. }
  589. }
  590. /**
  591. * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
  592. * @pf: the corresponding PF
  593. *
  594. * Update the Rx XOFF counter (PAUSE frames) in PFC mode
  595. **/
  596. static void i40e_update_prio_xoff_rx(struct i40e_pf *pf)
  597. {
  598. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  599. struct i40e_hw_port_stats *nsd = &pf->stats;
  600. bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false};
  601. struct i40e_dcbx_config *dcb_cfg;
  602. struct i40e_hw *hw = &pf->hw;
  603. u16 i, v;
  604. u8 tc;
  605. dcb_cfg = &hw->local_dcbx_config;
  606. /* See if DCB enabled with PFC TC */
  607. if (!(pf->flags & I40E_FLAG_DCB_ENABLED) ||
  608. !(dcb_cfg->pfc.pfcenable)) {
  609. i40e_update_link_xoff_rx(pf);
  610. return;
  611. }
  612. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  613. u64 prio_xoff = nsd->priority_xoff_rx[i];
  614. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  615. pf->stat_offsets_loaded,
  616. &osd->priority_xoff_rx[i],
  617. &nsd->priority_xoff_rx[i]);
  618. /* No new PFC xoff rx */
  619. if (!(nsd->priority_xoff_rx[i] - prio_xoff))
  620. continue;
  621. /* Get the TC for given priority */
  622. tc = dcb_cfg->etscfg.prioritytable[i];
  623. xoff[tc] = true;
  624. }
  625. /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
  626. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  627. struct i40e_vsi *vsi = pf->vsi[v];
  628. if (!vsi)
  629. continue;
  630. for (i = 0; i < vsi->num_queue_pairs; i++) {
  631. struct i40e_ring *ring = vsi->tx_rings[i];
  632. tc = ring->dcb_tc;
  633. if (xoff[tc])
  634. clear_bit(__I40E_HANG_CHECK_ARMED,
  635. &ring->state);
  636. }
  637. }
  638. }
  639. /**
  640. * i40e_update_stats - Update the board statistics counters.
  641. * @vsi: the VSI to be updated
  642. *
  643. * There are a few instances where we store the same stat in a
  644. * couple of different structs. This is partly because we have
  645. * the netdev stats that need to be filled out, which is slightly
  646. * different from the "eth_stats" defined by the chip and used in
  647. * VF communications. We sort it all out here in a central place.
  648. **/
  649. void i40e_update_stats(struct i40e_vsi *vsi)
  650. {
  651. struct i40e_pf *pf = vsi->back;
  652. struct i40e_hw *hw = &pf->hw;
  653. struct rtnl_link_stats64 *ons;
  654. struct rtnl_link_stats64 *ns; /* netdev stats */
  655. struct i40e_eth_stats *oes;
  656. struct i40e_eth_stats *es; /* device's eth stats */
  657. u32 tx_restart, tx_busy;
  658. u32 rx_page, rx_buf;
  659. u64 rx_p, rx_b;
  660. u64 tx_p, tx_b;
  661. u32 val;
  662. int i;
  663. u16 q;
  664. if (test_bit(__I40E_DOWN, &vsi->state) ||
  665. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  666. return;
  667. ns = i40e_get_vsi_stats_struct(vsi);
  668. ons = &vsi->net_stats_offsets;
  669. es = &vsi->eth_stats;
  670. oes = &vsi->eth_stats_offsets;
  671. /* Gather up the netdev and vsi stats that the driver collects
  672. * on the fly during packet processing
  673. */
  674. rx_b = rx_p = 0;
  675. tx_b = tx_p = 0;
  676. tx_restart = tx_busy = 0;
  677. rx_page = 0;
  678. rx_buf = 0;
  679. rcu_read_lock();
  680. for (q = 0; q < vsi->num_queue_pairs; q++) {
  681. struct i40e_ring *p;
  682. u64 bytes, packets;
  683. unsigned int start;
  684. /* locate Tx ring */
  685. p = ACCESS_ONCE(vsi->tx_rings[q]);
  686. do {
  687. start = u64_stats_fetch_begin_irq(&p->syncp);
  688. packets = p->stats.packets;
  689. bytes = p->stats.bytes;
  690. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  691. tx_b += bytes;
  692. tx_p += packets;
  693. tx_restart += p->tx_stats.restart_queue;
  694. tx_busy += p->tx_stats.tx_busy;
  695. /* Rx queue is part of the same block as Tx queue */
  696. p = &p[1];
  697. do {
  698. start = u64_stats_fetch_begin_irq(&p->syncp);
  699. packets = p->stats.packets;
  700. bytes = p->stats.bytes;
  701. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  702. rx_b += bytes;
  703. rx_p += packets;
  704. rx_buf += p->rx_stats.alloc_buff_failed;
  705. rx_page += p->rx_stats.alloc_page_failed;
  706. }
  707. rcu_read_unlock();
  708. vsi->tx_restart = tx_restart;
  709. vsi->tx_busy = tx_busy;
  710. vsi->rx_page_failed = rx_page;
  711. vsi->rx_buf_failed = rx_buf;
  712. ns->rx_packets = rx_p;
  713. ns->rx_bytes = rx_b;
  714. ns->tx_packets = tx_p;
  715. ns->tx_bytes = tx_b;
  716. i40e_update_eth_stats(vsi);
  717. /* update netdev stats from eth stats */
  718. ons->rx_errors = oes->rx_errors;
  719. ns->rx_errors = es->rx_errors;
  720. ons->tx_errors = oes->tx_errors;
  721. ns->tx_errors = es->tx_errors;
  722. ons->multicast = oes->rx_multicast;
  723. ns->multicast = es->rx_multicast;
  724. ons->tx_dropped = oes->tx_discards;
  725. ns->tx_dropped = es->tx_discards;
  726. /* Get the port data only if this is the main PF VSI */
  727. if (vsi == pf->vsi[pf->lan_vsi]) {
  728. struct i40e_hw_port_stats *nsd = &pf->stats;
  729. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  730. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  731. I40E_GLPRT_GORCL(hw->port),
  732. pf->stat_offsets_loaded,
  733. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  734. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  735. I40E_GLPRT_GOTCL(hw->port),
  736. pf->stat_offsets_loaded,
  737. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  738. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  739. pf->stat_offsets_loaded,
  740. &osd->eth.rx_discards,
  741. &nsd->eth.rx_discards);
  742. i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port),
  743. pf->stat_offsets_loaded,
  744. &osd->eth.tx_discards,
  745. &nsd->eth.tx_discards);
  746. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  747. I40E_GLPRT_MPRCL(hw->port),
  748. pf->stat_offsets_loaded,
  749. &osd->eth.rx_multicast,
  750. &nsd->eth.rx_multicast);
  751. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  752. pf->stat_offsets_loaded,
  753. &osd->tx_dropped_link_down,
  754. &nsd->tx_dropped_link_down);
  755. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  756. pf->stat_offsets_loaded,
  757. &osd->crc_errors, &nsd->crc_errors);
  758. ns->rx_crc_errors = nsd->crc_errors;
  759. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  760. pf->stat_offsets_loaded,
  761. &osd->illegal_bytes, &nsd->illegal_bytes);
  762. ns->rx_errors = nsd->crc_errors
  763. + nsd->illegal_bytes;
  764. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  765. pf->stat_offsets_loaded,
  766. &osd->mac_local_faults,
  767. &nsd->mac_local_faults);
  768. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  769. pf->stat_offsets_loaded,
  770. &osd->mac_remote_faults,
  771. &nsd->mac_remote_faults);
  772. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  773. pf->stat_offsets_loaded,
  774. &osd->rx_length_errors,
  775. &nsd->rx_length_errors);
  776. ns->rx_length_errors = nsd->rx_length_errors;
  777. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  778. pf->stat_offsets_loaded,
  779. &osd->link_xon_rx, &nsd->link_xon_rx);
  780. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  781. pf->stat_offsets_loaded,
  782. &osd->link_xon_tx, &nsd->link_xon_tx);
  783. i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */
  784. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  785. pf->stat_offsets_loaded,
  786. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  787. for (i = 0; i < 8; i++) {
  788. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  789. pf->stat_offsets_loaded,
  790. &osd->priority_xon_rx[i],
  791. &nsd->priority_xon_rx[i]);
  792. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  793. pf->stat_offsets_loaded,
  794. &osd->priority_xon_tx[i],
  795. &nsd->priority_xon_tx[i]);
  796. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  797. pf->stat_offsets_loaded,
  798. &osd->priority_xoff_tx[i],
  799. &nsd->priority_xoff_tx[i]);
  800. i40e_stat_update32(hw,
  801. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  802. pf->stat_offsets_loaded,
  803. &osd->priority_xon_2_xoff[i],
  804. &nsd->priority_xon_2_xoff[i]);
  805. }
  806. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  807. I40E_GLPRT_PRC64L(hw->port),
  808. pf->stat_offsets_loaded,
  809. &osd->rx_size_64, &nsd->rx_size_64);
  810. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  811. I40E_GLPRT_PRC127L(hw->port),
  812. pf->stat_offsets_loaded,
  813. &osd->rx_size_127, &nsd->rx_size_127);
  814. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  815. I40E_GLPRT_PRC255L(hw->port),
  816. pf->stat_offsets_loaded,
  817. &osd->rx_size_255, &nsd->rx_size_255);
  818. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  819. I40E_GLPRT_PRC511L(hw->port),
  820. pf->stat_offsets_loaded,
  821. &osd->rx_size_511, &nsd->rx_size_511);
  822. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  823. I40E_GLPRT_PRC1023L(hw->port),
  824. pf->stat_offsets_loaded,
  825. &osd->rx_size_1023, &nsd->rx_size_1023);
  826. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  827. I40E_GLPRT_PRC1522L(hw->port),
  828. pf->stat_offsets_loaded,
  829. &osd->rx_size_1522, &nsd->rx_size_1522);
  830. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  831. I40E_GLPRT_PRC9522L(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->rx_size_big, &nsd->rx_size_big);
  834. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  835. I40E_GLPRT_PTC64L(hw->port),
  836. pf->stat_offsets_loaded,
  837. &osd->tx_size_64, &nsd->tx_size_64);
  838. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  839. I40E_GLPRT_PTC127L(hw->port),
  840. pf->stat_offsets_loaded,
  841. &osd->tx_size_127, &nsd->tx_size_127);
  842. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  843. I40E_GLPRT_PTC255L(hw->port),
  844. pf->stat_offsets_loaded,
  845. &osd->tx_size_255, &nsd->tx_size_255);
  846. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  847. I40E_GLPRT_PTC511L(hw->port),
  848. pf->stat_offsets_loaded,
  849. &osd->tx_size_511, &nsd->tx_size_511);
  850. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  851. I40E_GLPRT_PTC1023L(hw->port),
  852. pf->stat_offsets_loaded,
  853. &osd->tx_size_1023, &nsd->tx_size_1023);
  854. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  855. I40E_GLPRT_PTC1522L(hw->port),
  856. pf->stat_offsets_loaded,
  857. &osd->tx_size_1522, &nsd->tx_size_1522);
  858. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  859. I40E_GLPRT_PTC9522L(hw->port),
  860. pf->stat_offsets_loaded,
  861. &osd->tx_size_big, &nsd->tx_size_big);
  862. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  863. pf->stat_offsets_loaded,
  864. &osd->rx_undersize, &nsd->rx_undersize);
  865. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  866. pf->stat_offsets_loaded,
  867. &osd->rx_fragments, &nsd->rx_fragments);
  868. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  869. pf->stat_offsets_loaded,
  870. &osd->rx_oversize, &nsd->rx_oversize);
  871. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  872. pf->stat_offsets_loaded,
  873. &osd->rx_jabber, &nsd->rx_jabber);
  874. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  875. nsd->tx_lpi_status =
  876. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  877. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  878. nsd->rx_lpi_status =
  879. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  880. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  881. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  882. pf->stat_offsets_loaded,
  883. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  884. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  885. pf->stat_offsets_loaded,
  886. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  887. }
  888. pf->stat_offsets_loaded = true;
  889. }
  890. /**
  891. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  892. * @vsi: the VSI to be searched
  893. * @macaddr: the MAC address
  894. * @vlan: the vlan
  895. * @is_vf: make sure its a vf filter, else doesn't matter
  896. * @is_netdev: make sure its a netdev filter, else doesn't matter
  897. *
  898. * Returns ptr to the filter object or NULL
  899. **/
  900. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  901. u8 *macaddr, s16 vlan,
  902. bool is_vf, bool is_netdev)
  903. {
  904. struct i40e_mac_filter *f;
  905. if (!vsi || !macaddr)
  906. return NULL;
  907. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  908. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  909. (vlan == f->vlan) &&
  910. (!is_vf || f->is_vf) &&
  911. (!is_netdev || f->is_netdev))
  912. return f;
  913. }
  914. return NULL;
  915. }
  916. /**
  917. * i40e_find_mac - Find a mac addr in the macvlan filters list
  918. * @vsi: the VSI to be searched
  919. * @macaddr: the MAC address we are searching for
  920. * @is_vf: make sure its a vf filter, else doesn't matter
  921. * @is_netdev: make sure its a netdev filter, else doesn't matter
  922. *
  923. * Returns the first filter with the provided MAC address or NULL if
  924. * MAC address was not found
  925. **/
  926. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
  927. bool is_vf, bool is_netdev)
  928. {
  929. struct i40e_mac_filter *f;
  930. if (!vsi || !macaddr)
  931. return NULL;
  932. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  933. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  934. (!is_vf || f->is_vf) &&
  935. (!is_netdev || f->is_netdev))
  936. return f;
  937. }
  938. return NULL;
  939. }
  940. /**
  941. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  942. * @vsi: the VSI to be searched
  943. *
  944. * Returns true if VSI is in vlan mode or false otherwise
  945. **/
  946. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  947. {
  948. struct i40e_mac_filter *f;
  949. /* Only -1 for all the filters denotes not in vlan mode
  950. * so we have to go through all the list in order to make sure
  951. */
  952. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  953. if (f->vlan >= 0)
  954. return true;
  955. }
  956. return false;
  957. }
  958. /**
  959. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  960. * @vsi: the VSI to be searched
  961. * @macaddr: the mac address to be filtered
  962. * @is_vf: true if it is a vf
  963. * @is_netdev: true if it is a netdev
  964. *
  965. * Goes through all the macvlan filters and adds a
  966. * macvlan filter for each unique vlan that already exists
  967. *
  968. * Returns first filter found on success, else NULL
  969. **/
  970. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  971. bool is_vf, bool is_netdev)
  972. {
  973. struct i40e_mac_filter *f;
  974. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  975. if (!i40e_find_filter(vsi, macaddr, f->vlan,
  976. is_vf, is_netdev)) {
  977. if (!i40e_add_filter(vsi, macaddr, f->vlan,
  978. is_vf, is_netdev))
  979. return NULL;
  980. }
  981. }
  982. return list_first_entry_or_null(&vsi->mac_filter_list,
  983. struct i40e_mac_filter, list);
  984. }
  985. /**
  986. * i40e_add_filter - Add a mac/vlan filter to the VSI
  987. * @vsi: the VSI to be searched
  988. * @macaddr: the MAC address
  989. * @vlan: the vlan
  990. * @is_vf: make sure its a vf filter, else doesn't matter
  991. * @is_netdev: make sure its a netdev filter, else doesn't matter
  992. *
  993. * Returns ptr to the filter object or NULL when no memory available.
  994. **/
  995. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  996. u8 *macaddr, s16 vlan,
  997. bool is_vf, bool is_netdev)
  998. {
  999. struct i40e_mac_filter *f;
  1000. if (!vsi || !macaddr)
  1001. return NULL;
  1002. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1003. if (!f) {
  1004. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1005. if (!f)
  1006. goto add_filter_out;
  1007. memcpy(f->macaddr, macaddr, ETH_ALEN);
  1008. f->vlan = vlan;
  1009. f->changed = true;
  1010. INIT_LIST_HEAD(&f->list);
  1011. list_add(&f->list, &vsi->mac_filter_list);
  1012. }
  1013. /* increment counter and add a new flag if needed */
  1014. if (is_vf) {
  1015. if (!f->is_vf) {
  1016. f->is_vf = true;
  1017. f->counter++;
  1018. }
  1019. } else if (is_netdev) {
  1020. if (!f->is_netdev) {
  1021. f->is_netdev = true;
  1022. f->counter++;
  1023. }
  1024. } else {
  1025. f->counter++;
  1026. }
  1027. /* changed tells sync_filters_subtask to
  1028. * push the filter down to the firmware
  1029. */
  1030. if (f->changed) {
  1031. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1032. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1033. }
  1034. add_filter_out:
  1035. return f;
  1036. }
  1037. /**
  1038. * i40e_del_filter - Remove a mac/vlan filter from the VSI
  1039. * @vsi: the VSI to be searched
  1040. * @macaddr: the MAC address
  1041. * @vlan: the vlan
  1042. * @is_vf: make sure it's a vf filter, else doesn't matter
  1043. * @is_netdev: make sure it's a netdev filter, else doesn't matter
  1044. **/
  1045. void i40e_del_filter(struct i40e_vsi *vsi,
  1046. u8 *macaddr, s16 vlan,
  1047. bool is_vf, bool is_netdev)
  1048. {
  1049. struct i40e_mac_filter *f;
  1050. if (!vsi || !macaddr)
  1051. return;
  1052. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1053. if (!f || f->counter == 0)
  1054. return;
  1055. if (is_vf) {
  1056. if (f->is_vf) {
  1057. f->is_vf = false;
  1058. f->counter--;
  1059. }
  1060. } else if (is_netdev) {
  1061. if (f->is_netdev) {
  1062. f->is_netdev = false;
  1063. f->counter--;
  1064. }
  1065. } else {
  1066. /* make sure we don't remove a filter in use by vf or netdev */
  1067. int min_f = 0;
  1068. min_f += (f->is_vf ? 1 : 0);
  1069. min_f += (f->is_netdev ? 1 : 0);
  1070. if (f->counter > min_f)
  1071. f->counter--;
  1072. }
  1073. /* counter == 0 tells sync_filters_subtask to
  1074. * remove the filter from the firmware's list
  1075. */
  1076. if (f->counter == 0) {
  1077. f->changed = true;
  1078. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1079. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1080. }
  1081. }
  1082. /**
  1083. * i40e_set_mac - NDO callback to set mac address
  1084. * @netdev: network interface device structure
  1085. * @p: pointer to an address structure
  1086. *
  1087. * Returns 0 on success, negative on failure
  1088. **/
  1089. static int i40e_set_mac(struct net_device *netdev, void *p)
  1090. {
  1091. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1092. struct i40e_vsi *vsi = np->vsi;
  1093. struct sockaddr *addr = p;
  1094. struct i40e_mac_filter *f;
  1095. if (!is_valid_ether_addr(addr->sa_data))
  1096. return -EADDRNOTAVAIL;
  1097. netdev_info(netdev, "set mac address=%pM\n", addr->sa_data);
  1098. if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
  1099. return 0;
  1100. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1101. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1102. return -EADDRNOTAVAIL;
  1103. if (vsi->type == I40E_VSI_MAIN) {
  1104. i40e_status ret;
  1105. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1106. I40E_AQC_WRITE_TYPE_LAA_ONLY,
  1107. addr->sa_data, NULL);
  1108. if (ret) {
  1109. netdev_info(netdev,
  1110. "Addr change for Main VSI failed: %d\n",
  1111. ret);
  1112. return -EADDRNOTAVAIL;
  1113. }
  1114. memcpy(vsi->back->hw.mac.addr, addr->sa_data, netdev->addr_len);
  1115. }
  1116. /* In order to be sure to not drop any packets, add the new address
  1117. * then delete the old one.
  1118. */
  1119. f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false);
  1120. if (!f)
  1121. return -ENOMEM;
  1122. i40e_sync_vsi_filters(vsi);
  1123. i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false);
  1124. i40e_sync_vsi_filters(vsi);
  1125. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1126. return 0;
  1127. }
  1128. /**
  1129. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1130. * @vsi: the VSI being setup
  1131. * @ctxt: VSI context structure
  1132. * @enabled_tc: Enabled TCs bitmap
  1133. * @is_add: True if called before Add VSI
  1134. *
  1135. * Setup VSI queue mapping for enabled traffic classes.
  1136. **/
  1137. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1138. struct i40e_vsi_context *ctxt,
  1139. u8 enabled_tc,
  1140. bool is_add)
  1141. {
  1142. struct i40e_pf *pf = vsi->back;
  1143. u16 sections = 0;
  1144. u8 netdev_tc = 0;
  1145. u16 numtc = 0;
  1146. u16 qcount;
  1147. u8 offset;
  1148. u16 qmap;
  1149. int i;
  1150. u16 num_tc_qps = 0;
  1151. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1152. offset = 0;
  1153. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1154. /* Find numtc from enabled TC bitmap */
  1155. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1156. if (enabled_tc & (1 << i)) /* TC is enabled */
  1157. numtc++;
  1158. }
  1159. if (!numtc) {
  1160. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1161. numtc = 1;
  1162. }
  1163. } else {
  1164. /* At least TC0 is enabled in case of non-DCB case */
  1165. numtc = 1;
  1166. }
  1167. vsi->tc_config.numtc = numtc;
  1168. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1169. /* Number of queues per enabled TC */
  1170. num_tc_qps = rounddown_pow_of_two(vsi->alloc_queue_pairs/numtc);
  1171. num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC);
  1172. /* Setup queue offset/count for all TCs for given VSI */
  1173. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1174. /* See if the given TC is enabled for the given VSI */
  1175. if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */
  1176. int pow, num_qps;
  1177. switch (vsi->type) {
  1178. case I40E_VSI_MAIN:
  1179. qcount = min_t(int, pf->rss_size, num_tc_qps);
  1180. break;
  1181. case I40E_VSI_FDIR:
  1182. case I40E_VSI_SRIOV:
  1183. case I40E_VSI_VMDQ2:
  1184. default:
  1185. qcount = num_tc_qps;
  1186. WARN_ON(i != 0);
  1187. break;
  1188. }
  1189. vsi->tc_config.tc_info[i].qoffset = offset;
  1190. vsi->tc_config.tc_info[i].qcount = qcount;
  1191. /* find the power-of-2 of the number of queue pairs */
  1192. num_qps = qcount;
  1193. pow = 0;
  1194. while (num_qps && ((1 << pow) < qcount)) {
  1195. pow++;
  1196. num_qps >>= 1;
  1197. }
  1198. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1199. qmap =
  1200. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1201. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1202. offset += qcount;
  1203. } else {
  1204. /* TC is not enabled so set the offset to
  1205. * default queue and allocate one queue
  1206. * for the given TC.
  1207. */
  1208. vsi->tc_config.tc_info[i].qoffset = 0;
  1209. vsi->tc_config.tc_info[i].qcount = 1;
  1210. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1211. qmap = 0;
  1212. }
  1213. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1214. }
  1215. /* Set actual Tx/Rx queue pairs */
  1216. vsi->num_queue_pairs = offset;
  1217. /* Scheduler section valid can only be set for ADD VSI */
  1218. if (is_add) {
  1219. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1220. ctxt->info.up_enable_bits = enabled_tc;
  1221. }
  1222. if (vsi->type == I40E_VSI_SRIOV) {
  1223. ctxt->info.mapping_flags |=
  1224. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1225. for (i = 0; i < vsi->num_queue_pairs; i++)
  1226. ctxt->info.queue_mapping[i] =
  1227. cpu_to_le16(vsi->base_queue + i);
  1228. } else {
  1229. ctxt->info.mapping_flags |=
  1230. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1231. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1232. }
  1233. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1234. }
  1235. /**
  1236. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1237. * @netdev: network interface device structure
  1238. **/
  1239. static void i40e_set_rx_mode(struct net_device *netdev)
  1240. {
  1241. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1242. struct i40e_mac_filter *f, *ftmp;
  1243. struct i40e_vsi *vsi = np->vsi;
  1244. struct netdev_hw_addr *uca;
  1245. struct netdev_hw_addr *mca;
  1246. struct netdev_hw_addr *ha;
  1247. /* add addr if not already in the filter list */
  1248. netdev_for_each_uc_addr(uca, netdev) {
  1249. if (!i40e_find_mac(vsi, uca->addr, false, true)) {
  1250. if (i40e_is_vsi_in_vlan(vsi))
  1251. i40e_put_mac_in_vlan(vsi, uca->addr,
  1252. false, true);
  1253. else
  1254. i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
  1255. false, true);
  1256. }
  1257. }
  1258. netdev_for_each_mc_addr(mca, netdev) {
  1259. if (!i40e_find_mac(vsi, mca->addr, false, true)) {
  1260. if (i40e_is_vsi_in_vlan(vsi))
  1261. i40e_put_mac_in_vlan(vsi, mca->addr,
  1262. false, true);
  1263. else
  1264. i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
  1265. false, true);
  1266. }
  1267. }
  1268. /* remove filter if not in netdev list */
  1269. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1270. bool found = false;
  1271. if (!f->is_netdev)
  1272. continue;
  1273. if (is_multicast_ether_addr(f->macaddr)) {
  1274. netdev_for_each_mc_addr(mca, netdev) {
  1275. if (ether_addr_equal(mca->addr, f->macaddr)) {
  1276. found = true;
  1277. break;
  1278. }
  1279. }
  1280. } else {
  1281. netdev_for_each_uc_addr(uca, netdev) {
  1282. if (ether_addr_equal(uca->addr, f->macaddr)) {
  1283. found = true;
  1284. break;
  1285. }
  1286. }
  1287. for_each_dev_addr(netdev, ha) {
  1288. if (ether_addr_equal(ha->addr, f->macaddr)) {
  1289. found = true;
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. if (!found)
  1295. i40e_del_filter(
  1296. vsi, f->macaddr, I40E_VLAN_ANY, false, true);
  1297. }
  1298. /* check for other flag changes */
  1299. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1300. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1301. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1302. }
  1303. }
  1304. /**
  1305. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1306. * @vsi: ptr to the VSI
  1307. *
  1308. * Push any outstanding VSI filter changes through the AdminQ.
  1309. *
  1310. * Returns 0 or error value
  1311. **/
  1312. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1313. {
  1314. struct i40e_mac_filter *f, *ftmp;
  1315. bool promisc_forced_on = false;
  1316. bool add_happened = false;
  1317. int filter_list_len = 0;
  1318. u32 changed_flags = 0;
  1319. i40e_status aq_ret = 0;
  1320. struct i40e_pf *pf;
  1321. int num_add = 0;
  1322. int num_del = 0;
  1323. u16 cmd_flags;
  1324. /* empty array typed pointers, kcalloc later */
  1325. struct i40e_aqc_add_macvlan_element_data *add_list;
  1326. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1327. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1328. usleep_range(1000, 2000);
  1329. pf = vsi->back;
  1330. if (vsi->netdev) {
  1331. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1332. vsi->current_netdev_flags = vsi->netdev->flags;
  1333. }
  1334. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1335. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1336. filter_list_len = pf->hw.aq.asq_buf_size /
  1337. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1338. del_list = kcalloc(filter_list_len,
  1339. sizeof(struct i40e_aqc_remove_macvlan_element_data),
  1340. GFP_KERNEL);
  1341. if (!del_list)
  1342. return -ENOMEM;
  1343. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1344. if (!f->changed)
  1345. continue;
  1346. if (f->counter != 0)
  1347. continue;
  1348. f->changed = false;
  1349. cmd_flags = 0;
  1350. /* add to delete list */
  1351. memcpy(del_list[num_del].mac_addr,
  1352. f->macaddr, ETH_ALEN);
  1353. del_list[num_del].vlan_tag =
  1354. cpu_to_le16((u16)(f->vlan ==
  1355. I40E_VLAN_ANY ? 0 : f->vlan));
  1356. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1357. del_list[num_del].flags = cmd_flags;
  1358. num_del++;
  1359. /* unlink from filter list */
  1360. list_del(&f->list);
  1361. kfree(f);
  1362. /* flush a full buffer */
  1363. if (num_del == filter_list_len) {
  1364. aq_ret = i40e_aq_remove_macvlan(&pf->hw,
  1365. vsi->seid, del_list, num_del,
  1366. NULL);
  1367. num_del = 0;
  1368. memset(del_list, 0, sizeof(*del_list));
  1369. if (aq_ret)
  1370. dev_info(&pf->pdev->dev,
  1371. "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
  1372. aq_ret,
  1373. pf->hw.aq.asq_last_status);
  1374. }
  1375. }
  1376. if (num_del) {
  1377. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
  1378. del_list, num_del, NULL);
  1379. num_del = 0;
  1380. if (aq_ret)
  1381. dev_info(&pf->pdev->dev,
  1382. "ignoring delete macvlan error, err %d, aq_err %d\n",
  1383. aq_ret, pf->hw.aq.asq_last_status);
  1384. }
  1385. kfree(del_list);
  1386. del_list = NULL;
  1387. /* do all the adds now */
  1388. filter_list_len = pf->hw.aq.asq_buf_size /
  1389. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1390. add_list = kcalloc(filter_list_len,
  1391. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1392. GFP_KERNEL);
  1393. if (!add_list)
  1394. return -ENOMEM;
  1395. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1396. if (!f->changed)
  1397. continue;
  1398. if (f->counter == 0)
  1399. continue;
  1400. f->changed = false;
  1401. add_happened = true;
  1402. cmd_flags = 0;
  1403. /* add to add array */
  1404. memcpy(add_list[num_add].mac_addr,
  1405. f->macaddr, ETH_ALEN);
  1406. add_list[num_add].vlan_tag =
  1407. cpu_to_le16(
  1408. (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
  1409. add_list[num_add].queue_number = 0;
  1410. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1411. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1412. num_add++;
  1413. /* flush a full buffer */
  1414. if (num_add == filter_list_len) {
  1415. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1416. add_list, num_add,
  1417. NULL);
  1418. num_add = 0;
  1419. if (aq_ret)
  1420. break;
  1421. memset(add_list, 0, sizeof(*add_list));
  1422. }
  1423. }
  1424. if (num_add) {
  1425. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1426. add_list, num_add, NULL);
  1427. num_add = 0;
  1428. }
  1429. kfree(add_list);
  1430. add_list = NULL;
  1431. if (add_happened && (!aq_ret)) {
  1432. /* do nothing */;
  1433. } else if (add_happened && (aq_ret)) {
  1434. dev_info(&pf->pdev->dev,
  1435. "add filter failed, err %d, aq_err %d\n",
  1436. aq_ret, pf->hw.aq.asq_last_status);
  1437. if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
  1438. !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1439. &vsi->state)) {
  1440. promisc_forced_on = true;
  1441. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1442. &vsi->state);
  1443. dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
  1444. }
  1445. }
  1446. }
  1447. /* check for changes in promiscuous modes */
  1448. if (changed_flags & IFF_ALLMULTI) {
  1449. bool cur_multipromisc;
  1450. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  1451. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  1452. vsi->seid,
  1453. cur_multipromisc,
  1454. NULL);
  1455. if (aq_ret)
  1456. dev_info(&pf->pdev->dev,
  1457. "set multi promisc failed, err %d, aq_err %d\n",
  1458. aq_ret, pf->hw.aq.asq_last_status);
  1459. }
  1460. if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
  1461. bool cur_promisc;
  1462. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  1463. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1464. &vsi->state));
  1465. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw,
  1466. vsi->seid,
  1467. cur_promisc, NULL);
  1468. if (aq_ret)
  1469. dev_info(&pf->pdev->dev,
  1470. "set uni promisc failed, err %d, aq_err %d\n",
  1471. aq_ret, pf->hw.aq.asq_last_status);
  1472. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  1473. vsi->seid,
  1474. cur_promisc, NULL);
  1475. if (aq_ret)
  1476. dev_info(&pf->pdev->dev,
  1477. "set brdcast promisc failed, err %d, aq_err %d\n",
  1478. aq_ret, pf->hw.aq.asq_last_status);
  1479. }
  1480. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  1481. return 0;
  1482. }
  1483. /**
  1484. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  1485. * @pf: board private structure
  1486. **/
  1487. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  1488. {
  1489. int v;
  1490. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  1491. return;
  1492. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  1493. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  1494. if (pf->vsi[v] &&
  1495. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
  1496. i40e_sync_vsi_filters(pf->vsi[v]);
  1497. }
  1498. }
  1499. /**
  1500. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  1501. * @netdev: network interface device structure
  1502. * @new_mtu: new value for maximum frame size
  1503. *
  1504. * Returns 0 on success, negative on failure
  1505. **/
  1506. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  1507. {
  1508. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1509. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  1510. struct i40e_vsi *vsi = np->vsi;
  1511. /* MTU < 68 is an error and causes problems on some kernels */
  1512. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  1513. return -EINVAL;
  1514. netdev_info(netdev, "changing MTU from %d to %d\n",
  1515. netdev->mtu, new_mtu);
  1516. netdev->mtu = new_mtu;
  1517. if (netif_running(netdev))
  1518. i40e_vsi_reinit_locked(vsi);
  1519. return 0;
  1520. }
  1521. /**
  1522. * i40e_ioctl - Access the hwtstamp interface
  1523. * @netdev: network interface device structure
  1524. * @ifr: interface request data
  1525. * @cmd: ioctl command
  1526. **/
  1527. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  1528. {
  1529. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1530. struct i40e_pf *pf = np->vsi->back;
  1531. switch (cmd) {
  1532. case SIOCGHWTSTAMP:
  1533. return i40e_ptp_get_ts_config(pf, ifr);
  1534. case SIOCSHWTSTAMP:
  1535. return i40e_ptp_set_ts_config(pf, ifr);
  1536. default:
  1537. return -EOPNOTSUPP;
  1538. }
  1539. }
  1540. /**
  1541. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  1542. * @vsi: the vsi being adjusted
  1543. **/
  1544. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  1545. {
  1546. struct i40e_vsi_context ctxt;
  1547. i40e_status ret;
  1548. if ((vsi->info.valid_sections &
  1549. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1550. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  1551. return; /* already enabled */
  1552. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1553. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1554. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  1555. ctxt.seid = vsi->seid;
  1556. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1557. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1558. if (ret) {
  1559. dev_info(&vsi->back->pdev->dev,
  1560. "%s: update vsi failed, aq_err=%d\n",
  1561. __func__, vsi->back->hw.aq.asq_last_status);
  1562. }
  1563. }
  1564. /**
  1565. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  1566. * @vsi: the vsi being adjusted
  1567. **/
  1568. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  1569. {
  1570. struct i40e_vsi_context ctxt;
  1571. i40e_status ret;
  1572. if ((vsi->info.valid_sections &
  1573. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1574. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  1575. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  1576. return; /* already disabled */
  1577. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1578. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1579. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  1580. ctxt.seid = vsi->seid;
  1581. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1582. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1583. if (ret) {
  1584. dev_info(&vsi->back->pdev->dev,
  1585. "%s: update vsi failed, aq_err=%d\n",
  1586. __func__, vsi->back->hw.aq.asq_last_status);
  1587. }
  1588. }
  1589. /**
  1590. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  1591. * @netdev: network interface to be adjusted
  1592. * @features: netdev features to test if VLAN offload is enabled or not
  1593. **/
  1594. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  1595. {
  1596. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1597. struct i40e_vsi *vsi = np->vsi;
  1598. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  1599. i40e_vlan_stripping_enable(vsi);
  1600. else
  1601. i40e_vlan_stripping_disable(vsi);
  1602. }
  1603. /**
  1604. * i40e_vsi_add_vlan - Add vsi membership for given vlan
  1605. * @vsi: the vsi being configured
  1606. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  1607. **/
  1608. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  1609. {
  1610. struct i40e_mac_filter *f, *add_f;
  1611. bool is_netdev, is_vf;
  1612. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1613. is_netdev = !!(vsi->netdev);
  1614. if (is_netdev) {
  1615. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
  1616. is_vf, is_netdev);
  1617. if (!add_f) {
  1618. dev_info(&vsi->back->pdev->dev,
  1619. "Could not add vlan filter %d for %pM\n",
  1620. vid, vsi->netdev->dev_addr);
  1621. return -ENOMEM;
  1622. }
  1623. }
  1624. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1625. add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1626. if (!add_f) {
  1627. dev_info(&vsi->back->pdev->dev,
  1628. "Could not add vlan filter %d for %pM\n",
  1629. vid, f->macaddr);
  1630. return -ENOMEM;
  1631. }
  1632. }
  1633. /* Now if we add a vlan tag, make sure to check if it is the first
  1634. * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
  1635. * with 0, so we now accept untagged and specified tagged traffic
  1636. * (and not any taged and untagged)
  1637. */
  1638. if (vid > 0) {
  1639. if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
  1640. I40E_VLAN_ANY,
  1641. is_vf, is_netdev)) {
  1642. i40e_del_filter(vsi, vsi->netdev->dev_addr,
  1643. I40E_VLAN_ANY, is_vf, is_netdev);
  1644. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
  1645. is_vf, is_netdev);
  1646. if (!add_f) {
  1647. dev_info(&vsi->back->pdev->dev,
  1648. "Could not add filter 0 for %pM\n",
  1649. vsi->netdev->dev_addr);
  1650. return -ENOMEM;
  1651. }
  1652. }
  1653. }
  1654. /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
  1655. if (vid > 0 && !vsi->info.pvid) {
  1656. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1657. if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1658. is_vf, is_netdev)) {
  1659. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1660. is_vf, is_netdev);
  1661. add_f = i40e_add_filter(vsi, f->macaddr,
  1662. 0, is_vf, is_netdev);
  1663. if (!add_f) {
  1664. dev_info(&vsi->back->pdev->dev,
  1665. "Could not add filter 0 for %pM\n",
  1666. f->macaddr);
  1667. return -ENOMEM;
  1668. }
  1669. }
  1670. }
  1671. }
  1672. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1673. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1674. return 0;
  1675. return i40e_sync_vsi_filters(vsi);
  1676. }
  1677. /**
  1678. * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
  1679. * @vsi: the vsi being configured
  1680. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  1681. *
  1682. * Return: 0 on success or negative otherwise
  1683. **/
  1684. int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  1685. {
  1686. struct net_device *netdev = vsi->netdev;
  1687. struct i40e_mac_filter *f, *add_f;
  1688. bool is_vf, is_netdev;
  1689. int filter_count = 0;
  1690. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1691. is_netdev = !!(netdev);
  1692. if (is_netdev)
  1693. i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
  1694. list_for_each_entry(f, &vsi->mac_filter_list, list)
  1695. i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1696. /* go through all the filters for this VSI and if there is only
  1697. * vid == 0 it means there are no other filters, so vid 0 must
  1698. * be replaced with -1. This signifies that we should from now
  1699. * on accept any traffic (with any tag present, or untagged)
  1700. */
  1701. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1702. if (is_netdev) {
  1703. if (f->vlan &&
  1704. ether_addr_equal(netdev->dev_addr, f->macaddr))
  1705. filter_count++;
  1706. }
  1707. if (f->vlan)
  1708. filter_count++;
  1709. }
  1710. if (!filter_count && is_netdev) {
  1711. i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
  1712. f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  1713. is_vf, is_netdev);
  1714. if (!f) {
  1715. dev_info(&vsi->back->pdev->dev,
  1716. "Could not add filter %d for %pM\n",
  1717. I40E_VLAN_ANY, netdev->dev_addr);
  1718. return -ENOMEM;
  1719. }
  1720. }
  1721. if (!filter_count) {
  1722. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1723. i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
  1724. add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1725. is_vf, is_netdev);
  1726. if (!add_f) {
  1727. dev_info(&vsi->back->pdev->dev,
  1728. "Could not add filter %d for %pM\n",
  1729. I40E_VLAN_ANY, f->macaddr);
  1730. return -ENOMEM;
  1731. }
  1732. }
  1733. }
  1734. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1735. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1736. return 0;
  1737. return i40e_sync_vsi_filters(vsi);
  1738. }
  1739. /**
  1740. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  1741. * @netdev: network interface to be adjusted
  1742. * @vid: vlan id to be added
  1743. *
  1744. * net_device_ops implementation for adding vlan ids
  1745. **/
  1746. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  1747. __always_unused __be16 proto, u16 vid)
  1748. {
  1749. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1750. struct i40e_vsi *vsi = np->vsi;
  1751. int ret = 0;
  1752. if (vid > 4095)
  1753. return -EINVAL;
  1754. netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
  1755. /* If the network stack called us with vid = 0 then
  1756. * it is asking to receive priority tagged packets with
  1757. * vlan id 0. Our HW receives them by default when configured
  1758. * to receive untagged packets so there is no need to add an
  1759. * extra filter for vlan 0 tagged packets.
  1760. */
  1761. if (vid)
  1762. ret = i40e_vsi_add_vlan(vsi, vid);
  1763. if (!ret && (vid < VLAN_N_VID))
  1764. set_bit(vid, vsi->active_vlans);
  1765. return ret;
  1766. }
  1767. /**
  1768. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  1769. * @netdev: network interface to be adjusted
  1770. * @vid: vlan id to be removed
  1771. *
  1772. * net_device_ops implementation for removing vlan ids
  1773. **/
  1774. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  1775. __always_unused __be16 proto, u16 vid)
  1776. {
  1777. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1778. struct i40e_vsi *vsi = np->vsi;
  1779. netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
  1780. /* return code is ignored as there is nothing a user
  1781. * can do about failure to remove and a log message was
  1782. * already printed from the other function
  1783. */
  1784. i40e_vsi_kill_vlan(vsi, vid);
  1785. clear_bit(vid, vsi->active_vlans);
  1786. return 0;
  1787. }
  1788. /**
  1789. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  1790. * @vsi: the vsi being brought back up
  1791. **/
  1792. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  1793. {
  1794. u16 vid;
  1795. if (!vsi->netdev)
  1796. return;
  1797. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  1798. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  1799. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  1800. vid);
  1801. }
  1802. /**
  1803. * i40e_vsi_add_pvid - Add pvid for the VSI
  1804. * @vsi: the vsi being adjusted
  1805. * @vid: the vlan id to set as a PVID
  1806. **/
  1807. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  1808. {
  1809. struct i40e_vsi_context ctxt;
  1810. i40e_status aq_ret;
  1811. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1812. vsi->info.pvid = cpu_to_le16(vid);
  1813. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  1814. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  1815. I40E_AQ_VSI_PVLAN_EMOD_STR;
  1816. ctxt.seid = vsi->seid;
  1817. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1818. aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1819. if (aq_ret) {
  1820. dev_info(&vsi->back->pdev->dev,
  1821. "%s: update vsi failed, aq_err=%d\n",
  1822. __func__, vsi->back->hw.aq.asq_last_status);
  1823. return -ENOENT;
  1824. }
  1825. return 0;
  1826. }
  1827. /**
  1828. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  1829. * @vsi: the vsi being adjusted
  1830. *
  1831. * Just use the vlan_rx_register() service to put it back to normal
  1832. **/
  1833. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  1834. {
  1835. i40e_vlan_stripping_disable(vsi);
  1836. vsi->info.pvid = 0;
  1837. }
  1838. /**
  1839. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  1840. * @vsi: ptr to the VSI
  1841. *
  1842. * If this function returns with an error, then it's possible one or
  1843. * more of the rings is populated (while the rest are not). It is the
  1844. * callers duty to clean those orphaned rings.
  1845. *
  1846. * Return 0 on success, negative on failure
  1847. **/
  1848. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  1849. {
  1850. int i, err = 0;
  1851. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  1852. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  1853. return err;
  1854. }
  1855. /**
  1856. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  1857. * @vsi: ptr to the VSI
  1858. *
  1859. * Free VSI's transmit software resources
  1860. **/
  1861. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  1862. {
  1863. int i;
  1864. if (!vsi->tx_rings)
  1865. return;
  1866. for (i = 0; i < vsi->num_queue_pairs; i++)
  1867. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  1868. i40e_free_tx_resources(vsi->tx_rings[i]);
  1869. }
  1870. /**
  1871. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  1872. * @vsi: ptr to the VSI
  1873. *
  1874. * If this function returns with an error, then it's possible one or
  1875. * more of the rings is populated (while the rest are not). It is the
  1876. * callers duty to clean those orphaned rings.
  1877. *
  1878. * Return 0 on success, negative on failure
  1879. **/
  1880. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  1881. {
  1882. int i, err = 0;
  1883. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  1884. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  1885. return err;
  1886. }
  1887. /**
  1888. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  1889. * @vsi: ptr to the VSI
  1890. *
  1891. * Free all receive software resources
  1892. **/
  1893. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  1894. {
  1895. int i;
  1896. if (!vsi->rx_rings)
  1897. return;
  1898. for (i = 0; i < vsi->num_queue_pairs; i++)
  1899. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  1900. i40e_free_rx_resources(vsi->rx_rings[i]);
  1901. }
  1902. /**
  1903. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  1904. * @ring: The Tx ring to configure
  1905. *
  1906. * Configure the Tx descriptor ring in the HMC context.
  1907. **/
  1908. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  1909. {
  1910. struct i40e_vsi *vsi = ring->vsi;
  1911. u16 pf_q = vsi->base_queue + ring->queue_index;
  1912. struct i40e_hw *hw = &vsi->back->hw;
  1913. struct i40e_hmc_obj_txq tx_ctx;
  1914. i40e_status err = 0;
  1915. u32 qtx_ctl = 0;
  1916. /* some ATR related tx ring init */
  1917. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  1918. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  1919. ring->atr_count = 0;
  1920. } else {
  1921. ring->atr_sample_rate = 0;
  1922. }
  1923. /* initialize XPS */
  1924. if (ring->q_vector && ring->netdev &&
  1925. vsi->tc_config.numtc <= 1 &&
  1926. !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  1927. netif_set_xps_queue(ring->netdev,
  1928. &ring->q_vector->affinity_mask,
  1929. ring->queue_index);
  1930. /* clear the context structure first */
  1931. memset(&tx_ctx, 0, sizeof(tx_ctx));
  1932. tx_ctx.new_context = 1;
  1933. tx_ctx.base = (ring->dma / 128);
  1934. tx_ctx.qlen = ring->count;
  1935. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  1936. I40E_FLAG_FD_ATR_ENABLED));
  1937. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  1938. /* FDIR VSI tx ring can still use RS bit and writebacks */
  1939. if (vsi->type != I40E_VSI_FDIR)
  1940. tx_ctx.head_wb_ena = 1;
  1941. tx_ctx.head_wb_addr = ring->dma +
  1942. (ring->count * sizeof(struct i40e_tx_desc));
  1943. /* As part of VSI creation/update, FW allocates certain
  1944. * Tx arbitration queue sets for each TC enabled for
  1945. * the VSI. The FW returns the handles to these queue
  1946. * sets as part of the response buffer to Add VSI,
  1947. * Update VSI, etc. AQ commands. It is expected that
  1948. * these queue set handles be associated with the Tx
  1949. * queues by the driver as part of the TX queue context
  1950. * initialization. This has to be done regardless of
  1951. * DCB as by default everything is mapped to TC0.
  1952. */
  1953. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  1954. tx_ctx.rdylist_act = 0;
  1955. /* clear the context in the HMC */
  1956. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  1957. if (err) {
  1958. dev_info(&vsi->back->pdev->dev,
  1959. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  1960. ring->queue_index, pf_q, err);
  1961. return -ENOMEM;
  1962. }
  1963. /* set the context in the HMC */
  1964. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  1965. if (err) {
  1966. dev_info(&vsi->back->pdev->dev,
  1967. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  1968. ring->queue_index, pf_q, err);
  1969. return -ENOMEM;
  1970. }
  1971. /* Now associate this queue with this PCI function */
  1972. if (vsi->type == I40E_VSI_VMDQ2)
  1973. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  1974. else
  1975. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  1976. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  1977. I40E_QTX_CTL_PF_INDX_MASK);
  1978. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  1979. i40e_flush(hw);
  1980. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  1981. /* cache tail off for easier writes later */
  1982. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  1983. return 0;
  1984. }
  1985. /**
  1986. * i40e_configure_rx_ring - Configure a receive ring context
  1987. * @ring: The Rx ring to configure
  1988. *
  1989. * Configure the Rx descriptor ring in the HMC context.
  1990. **/
  1991. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  1992. {
  1993. struct i40e_vsi *vsi = ring->vsi;
  1994. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  1995. u16 pf_q = vsi->base_queue + ring->queue_index;
  1996. struct i40e_hw *hw = &vsi->back->hw;
  1997. struct i40e_hmc_obj_rxq rx_ctx;
  1998. i40e_status err = 0;
  1999. ring->state = 0;
  2000. /* clear the context structure first */
  2001. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2002. ring->rx_buf_len = vsi->rx_buf_len;
  2003. ring->rx_hdr_len = vsi->rx_hdr_len;
  2004. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2005. rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
  2006. rx_ctx.base = (ring->dma / 128);
  2007. rx_ctx.qlen = ring->count;
  2008. if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
  2009. set_ring_16byte_desc_enabled(ring);
  2010. rx_ctx.dsize = 0;
  2011. } else {
  2012. rx_ctx.dsize = 1;
  2013. }
  2014. rx_ctx.dtype = vsi->dtype;
  2015. if (vsi->dtype) {
  2016. set_ring_ps_enabled(ring);
  2017. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  2018. I40E_RX_SPLIT_IP |
  2019. I40E_RX_SPLIT_TCP_UDP |
  2020. I40E_RX_SPLIT_SCTP;
  2021. } else {
  2022. rx_ctx.hsplit_0 = 0;
  2023. }
  2024. rx_ctx.rxmax = min_t(u16, vsi->max_frame,
  2025. (chain_len * ring->rx_buf_len));
  2026. rx_ctx.tphrdesc_ena = 1;
  2027. rx_ctx.tphwdesc_ena = 1;
  2028. rx_ctx.tphdata_ena = 1;
  2029. rx_ctx.tphhead_ena = 1;
  2030. if (hw->revision_id == 0)
  2031. rx_ctx.lrxqthresh = 0;
  2032. else
  2033. rx_ctx.lrxqthresh = 2;
  2034. rx_ctx.crcstrip = 1;
  2035. rx_ctx.l2tsel = 1;
  2036. rx_ctx.showiv = 1;
  2037. /* set the prefena field to 1 because the manual says to */
  2038. rx_ctx.prefena = 1;
  2039. /* clear the context in the HMC */
  2040. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2041. if (err) {
  2042. dev_info(&vsi->back->pdev->dev,
  2043. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2044. ring->queue_index, pf_q, err);
  2045. return -ENOMEM;
  2046. }
  2047. /* set the context in the HMC */
  2048. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2049. if (err) {
  2050. dev_info(&vsi->back->pdev->dev,
  2051. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2052. ring->queue_index, pf_q, err);
  2053. return -ENOMEM;
  2054. }
  2055. /* cache tail for quicker writes, and clear the reg before use */
  2056. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2057. writel(0, ring->tail);
  2058. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2059. return 0;
  2060. }
  2061. /**
  2062. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2063. * @vsi: VSI structure describing this set of rings and resources
  2064. *
  2065. * Configure the Tx VSI for operation.
  2066. **/
  2067. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2068. {
  2069. int err = 0;
  2070. u16 i;
  2071. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2072. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2073. return err;
  2074. }
  2075. /**
  2076. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2077. * @vsi: the VSI being configured
  2078. *
  2079. * Configure the Rx VSI for operation.
  2080. **/
  2081. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2082. {
  2083. int err = 0;
  2084. u16 i;
  2085. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2086. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2087. + ETH_FCS_LEN + VLAN_HLEN;
  2088. else
  2089. vsi->max_frame = I40E_RXBUFFER_2048;
  2090. /* figure out correct receive buffer length */
  2091. switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
  2092. I40E_FLAG_RX_PS_ENABLED)) {
  2093. case I40E_FLAG_RX_1BUF_ENABLED:
  2094. vsi->rx_hdr_len = 0;
  2095. vsi->rx_buf_len = vsi->max_frame;
  2096. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2097. break;
  2098. case I40E_FLAG_RX_PS_ENABLED:
  2099. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2100. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2101. vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  2102. break;
  2103. default:
  2104. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2105. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2106. vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
  2107. break;
  2108. }
  2109. /* round up for the chip's needs */
  2110. vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
  2111. (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
  2112. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2113. (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
  2114. /* set up individual rings */
  2115. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2116. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2117. return err;
  2118. }
  2119. /**
  2120. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2121. * @vsi: ptr to the VSI
  2122. **/
  2123. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2124. {
  2125. u16 qoffset, qcount;
  2126. int i, n;
  2127. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED))
  2128. return;
  2129. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2130. if (!(vsi->tc_config.enabled_tc & (1 << n)))
  2131. continue;
  2132. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2133. qcount = vsi->tc_config.tc_info[n].qcount;
  2134. for (i = qoffset; i < (qoffset + qcount); i++) {
  2135. struct i40e_ring *rx_ring = vsi->rx_rings[i];
  2136. struct i40e_ring *tx_ring = vsi->tx_rings[i];
  2137. rx_ring->dcb_tc = n;
  2138. tx_ring->dcb_tc = n;
  2139. }
  2140. }
  2141. }
  2142. /**
  2143. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2144. * @vsi: ptr to the VSI
  2145. **/
  2146. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2147. {
  2148. if (vsi->netdev)
  2149. i40e_set_rx_mode(vsi->netdev);
  2150. }
  2151. /**
  2152. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2153. * @vsi: Pointer to the targeted VSI
  2154. *
  2155. * This function replays the hlist on the hw where all the SB Flow Director
  2156. * filters were saved.
  2157. **/
  2158. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2159. {
  2160. struct i40e_fdir_filter *filter;
  2161. struct i40e_pf *pf = vsi->back;
  2162. struct hlist_node *node;
  2163. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2164. return;
  2165. hlist_for_each_entry_safe(filter, node,
  2166. &pf->fdir_filter_list, fdir_node) {
  2167. i40e_add_del_fdir(vsi, filter, true);
  2168. }
  2169. }
  2170. /**
  2171. * i40e_vsi_configure - Set up the VSI for action
  2172. * @vsi: the VSI being configured
  2173. **/
  2174. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2175. {
  2176. int err;
  2177. i40e_set_vsi_rx_mode(vsi);
  2178. i40e_restore_vlan(vsi);
  2179. i40e_vsi_config_dcb_rings(vsi);
  2180. err = i40e_vsi_configure_tx(vsi);
  2181. if (!err)
  2182. err = i40e_vsi_configure_rx(vsi);
  2183. return err;
  2184. }
  2185. /**
  2186. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2187. * @vsi: the VSI being configured
  2188. **/
  2189. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2190. {
  2191. struct i40e_pf *pf = vsi->back;
  2192. struct i40e_q_vector *q_vector;
  2193. struct i40e_hw *hw = &pf->hw;
  2194. u16 vector;
  2195. int i, q;
  2196. u32 val;
  2197. u32 qp;
  2198. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2199. * and PFINT_LNKLSTn registers, e.g.:
  2200. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2201. */
  2202. qp = vsi->base_queue;
  2203. vector = vsi->base_vector;
  2204. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2205. q_vector = vsi->q_vectors[i];
  2206. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2207. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2208. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2209. q_vector->rx.itr);
  2210. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2211. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2212. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2213. q_vector->tx.itr);
  2214. /* Linked list for the queuepairs assigned to this vector */
  2215. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2216. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2217. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2218. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2219. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2220. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2221. (I40E_QUEUE_TYPE_TX
  2222. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2223. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2224. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2225. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2226. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2227. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2228. (I40E_QUEUE_TYPE_RX
  2229. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2230. /* Terminate the linked list */
  2231. if (q == (q_vector->num_ringpairs - 1))
  2232. val |= (I40E_QUEUE_END_OF_LIST
  2233. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2234. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2235. qp++;
  2236. }
  2237. }
  2238. i40e_flush(hw);
  2239. }
  2240. /**
  2241. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2242. * @hw: ptr to the hardware info
  2243. **/
  2244. static void i40e_enable_misc_int_causes(struct i40e_hw *hw)
  2245. {
  2246. u32 val;
  2247. /* clear things first */
  2248. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2249. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2250. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2251. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2252. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2253. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2254. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2255. I40E_PFINT_ICR0_ENA_TIMESYNC_MASK |
  2256. I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK |
  2257. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2258. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2259. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2260. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2261. /* SW_ITR_IDX = 0, but don't change INTENA */
  2262. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2263. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2264. /* OTHER_ITR_IDX = 0 */
  2265. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2266. }
  2267. /**
  2268. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2269. * @vsi: the VSI being configured
  2270. **/
  2271. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2272. {
  2273. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2274. struct i40e_pf *pf = vsi->back;
  2275. struct i40e_hw *hw = &pf->hw;
  2276. u32 val;
  2277. /* set the ITR configuration */
  2278. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2279. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2280. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2281. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2282. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2283. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2284. i40e_enable_misc_int_causes(hw);
  2285. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2286. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2287. /* Associate the queue pair to the vector and enable the queue int */
  2288. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2289. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2290. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2291. wr32(hw, I40E_QINT_RQCTL(0), val);
  2292. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2293. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2294. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2295. wr32(hw, I40E_QINT_TQCTL(0), val);
  2296. i40e_flush(hw);
  2297. }
  2298. /**
  2299. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  2300. * @pf: board private structure
  2301. **/
  2302. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  2303. {
  2304. struct i40e_hw *hw = &pf->hw;
  2305. wr32(hw, I40E_PFINT_DYN_CTL0,
  2306. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2307. i40e_flush(hw);
  2308. }
  2309. /**
  2310. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  2311. * @pf: board private structure
  2312. **/
  2313. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  2314. {
  2315. struct i40e_hw *hw = &pf->hw;
  2316. u32 val;
  2317. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  2318. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  2319. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  2320. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2321. i40e_flush(hw);
  2322. }
  2323. /**
  2324. * i40e_irq_dynamic_enable - Enable default interrupt generation settings
  2325. * @vsi: pointer to a vsi
  2326. * @vector: enable a particular Hw Interrupt vector
  2327. **/
  2328. void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
  2329. {
  2330. struct i40e_pf *pf = vsi->back;
  2331. struct i40e_hw *hw = &pf->hw;
  2332. u32 val;
  2333. val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
  2334. I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
  2335. (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2336. wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
  2337. /* skip the flush */
  2338. }
  2339. /**
  2340. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  2341. * @irq: interrupt number
  2342. * @data: pointer to a q_vector
  2343. **/
  2344. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  2345. {
  2346. struct i40e_q_vector *q_vector = data;
  2347. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2348. return IRQ_HANDLED;
  2349. napi_schedule(&q_vector->napi);
  2350. return IRQ_HANDLED;
  2351. }
  2352. /**
  2353. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  2354. * @vsi: the VSI being configured
  2355. * @basename: name for the vector
  2356. *
  2357. * Allocates MSI-X vectors and requests interrupts from the kernel.
  2358. **/
  2359. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  2360. {
  2361. int q_vectors = vsi->num_q_vectors;
  2362. struct i40e_pf *pf = vsi->back;
  2363. int base = vsi->base_vector;
  2364. int rx_int_idx = 0;
  2365. int tx_int_idx = 0;
  2366. int vector, err;
  2367. for (vector = 0; vector < q_vectors; vector++) {
  2368. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  2369. if (q_vector->tx.ring && q_vector->rx.ring) {
  2370. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2371. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  2372. tx_int_idx++;
  2373. } else if (q_vector->rx.ring) {
  2374. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2375. "%s-%s-%d", basename, "rx", rx_int_idx++);
  2376. } else if (q_vector->tx.ring) {
  2377. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2378. "%s-%s-%d", basename, "tx", tx_int_idx++);
  2379. } else {
  2380. /* skip this unused q_vector */
  2381. continue;
  2382. }
  2383. err = request_irq(pf->msix_entries[base + vector].vector,
  2384. vsi->irq_handler,
  2385. 0,
  2386. q_vector->name,
  2387. q_vector);
  2388. if (err) {
  2389. dev_info(&pf->pdev->dev,
  2390. "%s: request_irq failed, error: %d\n",
  2391. __func__, err);
  2392. goto free_queue_irqs;
  2393. }
  2394. /* assign the mask for this irq */
  2395. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2396. &q_vector->affinity_mask);
  2397. }
  2398. return 0;
  2399. free_queue_irqs:
  2400. while (vector) {
  2401. vector--;
  2402. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2403. NULL);
  2404. free_irq(pf->msix_entries[base + vector].vector,
  2405. &(vsi->q_vectors[vector]));
  2406. }
  2407. return err;
  2408. }
  2409. /**
  2410. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  2411. * @vsi: the VSI being un-configured
  2412. **/
  2413. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  2414. {
  2415. struct i40e_pf *pf = vsi->back;
  2416. struct i40e_hw *hw = &pf->hw;
  2417. int base = vsi->base_vector;
  2418. int i;
  2419. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2420. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  2421. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  2422. }
  2423. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2424. for (i = vsi->base_vector;
  2425. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2426. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  2427. i40e_flush(hw);
  2428. for (i = 0; i < vsi->num_q_vectors; i++)
  2429. synchronize_irq(pf->msix_entries[i + base].vector);
  2430. } else {
  2431. /* Legacy and MSI mode - this stops all interrupt handling */
  2432. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  2433. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  2434. i40e_flush(hw);
  2435. synchronize_irq(pf->pdev->irq);
  2436. }
  2437. }
  2438. /**
  2439. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  2440. * @vsi: the VSI being configured
  2441. **/
  2442. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  2443. {
  2444. struct i40e_pf *pf = vsi->back;
  2445. int i;
  2446. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2447. for (i = vsi->base_vector;
  2448. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2449. i40e_irq_dynamic_enable(vsi, i);
  2450. } else {
  2451. i40e_irq_dynamic_enable_icr0(pf);
  2452. }
  2453. i40e_flush(&pf->hw);
  2454. return 0;
  2455. }
  2456. /**
  2457. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  2458. * @pf: board private structure
  2459. **/
  2460. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  2461. {
  2462. /* Disable ICR 0 */
  2463. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  2464. i40e_flush(&pf->hw);
  2465. }
  2466. /**
  2467. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  2468. * @irq: interrupt number
  2469. * @data: pointer to a q_vector
  2470. *
  2471. * This is the handler used for all MSI/Legacy interrupts, and deals
  2472. * with both queue and non-queue interrupts. This is also used in
  2473. * MSIX mode to handle the non-queue interrupts.
  2474. **/
  2475. static irqreturn_t i40e_intr(int irq, void *data)
  2476. {
  2477. struct i40e_pf *pf = (struct i40e_pf *)data;
  2478. struct i40e_hw *hw = &pf->hw;
  2479. irqreturn_t ret = IRQ_NONE;
  2480. u32 icr0, icr0_remaining;
  2481. u32 val, ena_mask;
  2482. icr0 = rd32(hw, I40E_PFINT_ICR0);
  2483. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  2484. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  2485. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  2486. goto enable_intr;
  2487. /* if interrupt but no bits showing, must be SWINT */
  2488. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  2489. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  2490. pf->sw_int_count++;
  2491. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  2492. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  2493. /* temporarily disable queue cause for NAPI processing */
  2494. u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
  2495. qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  2496. wr32(hw, I40E_QINT_RQCTL(0), qval);
  2497. qval = rd32(hw, I40E_QINT_TQCTL(0));
  2498. qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  2499. wr32(hw, I40E_QINT_TQCTL(0), qval);
  2500. if (!test_bit(__I40E_DOWN, &pf->state))
  2501. napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi);
  2502. }
  2503. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  2504. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2505. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  2506. }
  2507. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  2508. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  2509. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  2510. }
  2511. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  2512. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  2513. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  2514. }
  2515. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  2516. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  2517. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  2518. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  2519. val = rd32(hw, I40E_GLGEN_RSTAT);
  2520. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  2521. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  2522. if (val == I40E_RESET_CORER) {
  2523. pf->corer_count++;
  2524. } else if (val == I40E_RESET_GLOBR) {
  2525. pf->globr_count++;
  2526. } else if (val == I40E_RESET_EMPR) {
  2527. pf->empr_count++;
  2528. set_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
  2529. }
  2530. }
  2531. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  2532. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  2533. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  2534. }
  2535. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  2536. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  2537. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  2538. ena_mask &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2539. i40e_ptp_tx_hwtstamp(pf);
  2540. prttsyn_stat &= ~I40E_PRTTSYN_STAT_0_TXTIME_MASK;
  2541. }
  2542. wr32(hw, I40E_PRTTSYN_STAT_0, prttsyn_stat);
  2543. }
  2544. /* If a critical error is pending we have no choice but to reset the
  2545. * device.
  2546. * Report and mask out any remaining unexpected interrupts.
  2547. */
  2548. icr0_remaining = icr0 & ena_mask;
  2549. if (icr0_remaining) {
  2550. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  2551. icr0_remaining);
  2552. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  2553. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  2554. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  2555. dev_info(&pf->pdev->dev, "device will be reset\n");
  2556. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  2557. i40e_service_event_schedule(pf);
  2558. }
  2559. ena_mask &= ~icr0_remaining;
  2560. }
  2561. ret = IRQ_HANDLED;
  2562. enable_intr:
  2563. /* re-enable interrupt causes */
  2564. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  2565. if (!test_bit(__I40E_DOWN, &pf->state)) {
  2566. i40e_service_event_schedule(pf);
  2567. i40e_irq_dynamic_enable_icr0(pf);
  2568. }
  2569. return ret;
  2570. }
  2571. /**
  2572. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  2573. * @tx_ring: tx ring to clean
  2574. * @budget: how many cleans we're allowed
  2575. *
  2576. * Returns true if there's any budget left (e.g. the clean is finished)
  2577. **/
  2578. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  2579. {
  2580. struct i40e_vsi *vsi = tx_ring->vsi;
  2581. u16 i = tx_ring->next_to_clean;
  2582. struct i40e_tx_buffer *tx_buf;
  2583. struct i40e_tx_desc *tx_desc;
  2584. tx_buf = &tx_ring->tx_bi[i];
  2585. tx_desc = I40E_TX_DESC(tx_ring, i);
  2586. i -= tx_ring->count;
  2587. do {
  2588. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  2589. /* if next_to_watch is not set then there is no work pending */
  2590. if (!eop_desc)
  2591. break;
  2592. /* prevent any other reads prior to eop_desc */
  2593. read_barrier_depends();
  2594. /* if the descriptor isn't done, no work yet to do */
  2595. if (!(eop_desc->cmd_type_offset_bsz &
  2596. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  2597. break;
  2598. /* clear next_to_watch to prevent false hangs */
  2599. tx_buf->next_to_watch = NULL;
  2600. /* unmap skb header data */
  2601. dma_unmap_single(tx_ring->dev,
  2602. dma_unmap_addr(tx_buf, dma),
  2603. dma_unmap_len(tx_buf, len),
  2604. DMA_TO_DEVICE);
  2605. dma_unmap_len_set(tx_buf, len, 0);
  2606. /* move to the next desc and buffer to clean */
  2607. tx_buf++;
  2608. tx_desc++;
  2609. i++;
  2610. if (unlikely(!i)) {
  2611. i -= tx_ring->count;
  2612. tx_buf = tx_ring->tx_bi;
  2613. tx_desc = I40E_TX_DESC(tx_ring, 0);
  2614. }
  2615. /* update budget accounting */
  2616. budget--;
  2617. } while (likely(budget));
  2618. i += tx_ring->count;
  2619. tx_ring->next_to_clean = i;
  2620. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) {
  2621. i40e_irq_dynamic_enable(vsi,
  2622. tx_ring->q_vector->v_idx + vsi->base_vector);
  2623. }
  2624. return budget > 0;
  2625. }
  2626. /**
  2627. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  2628. * @irq: interrupt number
  2629. * @data: pointer to a q_vector
  2630. **/
  2631. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  2632. {
  2633. struct i40e_q_vector *q_vector = data;
  2634. struct i40e_vsi *vsi;
  2635. if (!q_vector->tx.ring)
  2636. return IRQ_HANDLED;
  2637. vsi = q_vector->tx.ring->vsi;
  2638. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  2639. return IRQ_HANDLED;
  2640. }
  2641. /**
  2642. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  2643. * @vsi: the VSI being configured
  2644. * @v_idx: vector index
  2645. * @qp_idx: queue pair index
  2646. **/
  2647. static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  2648. {
  2649. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  2650. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  2651. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  2652. tx_ring->q_vector = q_vector;
  2653. tx_ring->next = q_vector->tx.ring;
  2654. q_vector->tx.ring = tx_ring;
  2655. q_vector->tx.count++;
  2656. rx_ring->q_vector = q_vector;
  2657. rx_ring->next = q_vector->rx.ring;
  2658. q_vector->rx.ring = rx_ring;
  2659. q_vector->rx.count++;
  2660. }
  2661. /**
  2662. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  2663. * @vsi: the VSI being configured
  2664. *
  2665. * This function maps descriptor rings to the queue-specific vectors
  2666. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  2667. * one vector per queue pair, but on a constrained vector budget, we
  2668. * group the queue pairs as "efficiently" as possible.
  2669. **/
  2670. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  2671. {
  2672. int qp_remaining = vsi->num_queue_pairs;
  2673. int q_vectors = vsi->num_q_vectors;
  2674. int num_ringpairs;
  2675. int v_start = 0;
  2676. int qp_idx = 0;
  2677. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  2678. * group them so there are multiple queues per vector.
  2679. */
  2680. for (; v_start < q_vectors && qp_remaining; v_start++) {
  2681. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  2682. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  2683. q_vector->num_ringpairs = num_ringpairs;
  2684. q_vector->rx.count = 0;
  2685. q_vector->tx.count = 0;
  2686. q_vector->rx.ring = NULL;
  2687. q_vector->tx.ring = NULL;
  2688. while (num_ringpairs--) {
  2689. map_vector_to_qp(vsi, v_start, qp_idx);
  2690. qp_idx++;
  2691. qp_remaining--;
  2692. }
  2693. }
  2694. }
  2695. /**
  2696. * i40e_vsi_request_irq - Request IRQ from the OS
  2697. * @vsi: the VSI being configured
  2698. * @basename: name for the vector
  2699. **/
  2700. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  2701. {
  2702. struct i40e_pf *pf = vsi->back;
  2703. int err;
  2704. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  2705. err = i40e_vsi_request_irq_msix(vsi, basename);
  2706. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  2707. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  2708. pf->misc_int_name, pf);
  2709. else
  2710. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  2711. pf->misc_int_name, pf);
  2712. if (err)
  2713. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  2714. return err;
  2715. }
  2716. #ifdef CONFIG_NET_POLL_CONTROLLER
  2717. /**
  2718. * i40e_netpoll - A Polling 'interrupt'handler
  2719. * @netdev: network interface device structure
  2720. *
  2721. * This is used by netconsole to send skbs without having to re-enable
  2722. * interrupts. It's not called while the normal interrupt routine is executing.
  2723. **/
  2724. static void i40e_netpoll(struct net_device *netdev)
  2725. {
  2726. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2727. struct i40e_vsi *vsi = np->vsi;
  2728. struct i40e_pf *pf = vsi->back;
  2729. int i;
  2730. /* if interface is down do nothing */
  2731. if (test_bit(__I40E_DOWN, &vsi->state))
  2732. return;
  2733. pf->flags |= I40E_FLAG_IN_NETPOLL;
  2734. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2735. for (i = 0; i < vsi->num_q_vectors; i++)
  2736. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  2737. } else {
  2738. i40e_intr(pf->pdev->irq, netdev);
  2739. }
  2740. pf->flags &= ~I40E_FLAG_IN_NETPOLL;
  2741. }
  2742. #endif
  2743. /**
  2744. * i40e_vsi_control_tx - Start or stop a VSI's rings
  2745. * @vsi: the VSI being configured
  2746. * @enable: start or stop the rings
  2747. **/
  2748. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  2749. {
  2750. struct i40e_pf *pf = vsi->back;
  2751. struct i40e_hw *hw = &pf->hw;
  2752. int i, j, pf_q;
  2753. u32 tx_reg;
  2754. pf_q = vsi->base_queue;
  2755. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  2756. for (j = 0; j < 50; j++) {
  2757. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  2758. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  2759. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  2760. break;
  2761. usleep_range(1000, 2000);
  2762. }
  2763. /* Skip if the queue is already in the requested state */
  2764. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  2765. continue;
  2766. /* turn on/off the queue */
  2767. if (enable) {
  2768. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  2769. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  2770. } else {
  2771. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  2772. }
  2773. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  2774. /* wait for the change to finish */
  2775. for (j = 0; j < 10; j++) {
  2776. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  2777. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  2778. break;
  2779. udelay(10);
  2780. }
  2781. if (j >= 10) {
  2782. dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n",
  2783. pf_q, (enable ? "en" : "dis"));
  2784. return -ETIMEDOUT;
  2785. }
  2786. }
  2787. if (hw->revision_id == 0)
  2788. mdelay(50);
  2789. return 0;
  2790. }
  2791. /**
  2792. * i40e_vsi_control_rx - Start or stop a VSI's rings
  2793. * @vsi: the VSI being configured
  2794. * @enable: start or stop the rings
  2795. **/
  2796. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  2797. {
  2798. struct i40e_pf *pf = vsi->back;
  2799. struct i40e_hw *hw = &pf->hw;
  2800. int i, j, pf_q;
  2801. u32 rx_reg;
  2802. pf_q = vsi->base_queue;
  2803. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  2804. for (j = 0; j < 50; j++) {
  2805. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  2806. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  2807. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  2808. break;
  2809. usleep_range(1000, 2000);
  2810. }
  2811. /* Skip if the queue is already in the requested state */
  2812. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2813. continue;
  2814. /* turn on/off the queue */
  2815. if (enable)
  2816. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  2817. else
  2818. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  2819. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  2820. /* wait for the change to finish */
  2821. for (j = 0; j < 10; j++) {
  2822. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  2823. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2824. break;
  2825. udelay(10);
  2826. }
  2827. if (j >= 10) {
  2828. dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n",
  2829. pf_q, (enable ? "en" : "dis"));
  2830. return -ETIMEDOUT;
  2831. }
  2832. }
  2833. return 0;
  2834. }
  2835. /**
  2836. * i40e_vsi_control_rings - Start or stop a VSI's rings
  2837. * @vsi: the VSI being configured
  2838. * @enable: start or stop the rings
  2839. **/
  2840. int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
  2841. {
  2842. int ret = 0;
  2843. /* do rx first for enable and last for disable */
  2844. if (request) {
  2845. ret = i40e_vsi_control_rx(vsi, request);
  2846. if (ret)
  2847. return ret;
  2848. ret = i40e_vsi_control_tx(vsi, request);
  2849. } else {
  2850. /* Ignore return value, we need to shutdown whatever we can */
  2851. i40e_vsi_control_tx(vsi, request);
  2852. i40e_vsi_control_rx(vsi, request);
  2853. }
  2854. return ret;
  2855. }
  2856. /**
  2857. * i40e_vsi_free_irq - Free the irq association with the OS
  2858. * @vsi: the VSI being configured
  2859. **/
  2860. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  2861. {
  2862. struct i40e_pf *pf = vsi->back;
  2863. struct i40e_hw *hw = &pf->hw;
  2864. int base = vsi->base_vector;
  2865. u32 val, qp;
  2866. int i;
  2867. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2868. if (!vsi->q_vectors)
  2869. return;
  2870. for (i = 0; i < vsi->num_q_vectors; i++) {
  2871. u16 vector = i + base;
  2872. /* free only the irqs that were actually requested */
  2873. if (!vsi->q_vectors[i] ||
  2874. !vsi->q_vectors[i]->num_ringpairs)
  2875. continue;
  2876. /* clear the affinity_mask in the IRQ descriptor */
  2877. irq_set_affinity_hint(pf->msix_entries[vector].vector,
  2878. NULL);
  2879. free_irq(pf->msix_entries[vector].vector,
  2880. vsi->q_vectors[i]);
  2881. /* Tear down the interrupt queue link list
  2882. *
  2883. * We know that they come in pairs and always
  2884. * the Rx first, then the Tx. To clear the
  2885. * link list, stick the EOL value into the
  2886. * next_q field of the registers.
  2887. */
  2888. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  2889. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  2890. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2891. val |= I40E_QUEUE_END_OF_LIST
  2892. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2893. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  2894. while (qp != I40E_QUEUE_END_OF_LIST) {
  2895. u32 next;
  2896. val = rd32(hw, I40E_QINT_RQCTL(qp));
  2897. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  2898. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  2899. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2900. I40E_QINT_RQCTL_INTEVENT_MASK);
  2901. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  2902. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  2903. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2904. val = rd32(hw, I40E_QINT_TQCTL(qp));
  2905. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  2906. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  2907. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  2908. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  2909. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2910. I40E_QINT_TQCTL_INTEVENT_MASK);
  2911. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  2912. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  2913. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2914. qp = next;
  2915. }
  2916. }
  2917. } else {
  2918. free_irq(pf->pdev->irq, pf);
  2919. val = rd32(hw, I40E_PFINT_LNKLST0);
  2920. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  2921. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2922. val |= I40E_QUEUE_END_OF_LIST
  2923. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  2924. wr32(hw, I40E_PFINT_LNKLST0, val);
  2925. val = rd32(hw, I40E_QINT_RQCTL(qp));
  2926. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  2927. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  2928. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2929. I40E_QINT_RQCTL_INTEVENT_MASK);
  2930. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  2931. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  2932. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2933. val = rd32(hw, I40E_QINT_TQCTL(qp));
  2934. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  2935. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  2936. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2937. I40E_QINT_TQCTL_INTEVENT_MASK);
  2938. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  2939. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  2940. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2941. }
  2942. }
  2943. /**
  2944. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  2945. * @vsi: the VSI being configured
  2946. * @v_idx: Index of vector to be freed
  2947. *
  2948. * This function frees the memory allocated to the q_vector. In addition if
  2949. * NAPI is enabled it will delete any references to the NAPI struct prior
  2950. * to freeing the q_vector.
  2951. **/
  2952. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  2953. {
  2954. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  2955. struct i40e_ring *ring;
  2956. if (!q_vector)
  2957. return;
  2958. /* disassociate q_vector from rings */
  2959. i40e_for_each_ring(ring, q_vector->tx)
  2960. ring->q_vector = NULL;
  2961. i40e_for_each_ring(ring, q_vector->rx)
  2962. ring->q_vector = NULL;
  2963. /* only VSI w/ an associated netdev is set up w/ NAPI */
  2964. if (vsi->netdev)
  2965. netif_napi_del(&q_vector->napi);
  2966. vsi->q_vectors[v_idx] = NULL;
  2967. kfree_rcu(q_vector, rcu);
  2968. }
  2969. /**
  2970. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  2971. * @vsi: the VSI being un-configured
  2972. *
  2973. * This frees the memory allocated to the q_vectors and
  2974. * deletes references to the NAPI struct.
  2975. **/
  2976. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  2977. {
  2978. int v_idx;
  2979. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  2980. i40e_free_q_vector(vsi, v_idx);
  2981. }
  2982. /**
  2983. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  2984. * @pf: board private structure
  2985. **/
  2986. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  2987. {
  2988. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  2989. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2990. pci_disable_msix(pf->pdev);
  2991. kfree(pf->msix_entries);
  2992. pf->msix_entries = NULL;
  2993. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  2994. pci_disable_msi(pf->pdev);
  2995. }
  2996. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  2997. }
  2998. /**
  2999. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3000. * @pf: board private structure
  3001. *
  3002. * We go through and clear interrupt specific resources and reset the structure
  3003. * to pre-load conditions
  3004. **/
  3005. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3006. {
  3007. int i;
  3008. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3009. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  3010. if (pf->vsi[i])
  3011. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3012. i40e_reset_interrupt_capability(pf);
  3013. }
  3014. /**
  3015. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3016. * @vsi: the VSI being configured
  3017. **/
  3018. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3019. {
  3020. int q_idx;
  3021. if (!vsi->netdev)
  3022. return;
  3023. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3024. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3025. }
  3026. /**
  3027. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3028. * @vsi: the VSI being configured
  3029. **/
  3030. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3031. {
  3032. int q_idx;
  3033. if (!vsi->netdev)
  3034. return;
  3035. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3036. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3037. }
  3038. /**
  3039. * i40e_vsi_close - Shut down a VSI
  3040. * @vsi: the vsi to be quelled
  3041. **/
  3042. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3043. {
  3044. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3045. i40e_down(vsi);
  3046. i40e_vsi_free_irq(vsi);
  3047. i40e_vsi_free_tx_resources(vsi);
  3048. i40e_vsi_free_rx_resources(vsi);
  3049. }
  3050. /**
  3051. * i40e_quiesce_vsi - Pause a given VSI
  3052. * @vsi: the VSI being paused
  3053. **/
  3054. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3055. {
  3056. if (test_bit(__I40E_DOWN, &vsi->state))
  3057. return;
  3058. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3059. if (vsi->netdev && netif_running(vsi->netdev)) {
  3060. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3061. } else {
  3062. i40e_vsi_close(vsi);
  3063. }
  3064. }
  3065. /**
  3066. * i40e_unquiesce_vsi - Resume a given VSI
  3067. * @vsi: the VSI being resumed
  3068. **/
  3069. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3070. {
  3071. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3072. return;
  3073. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3074. if (vsi->netdev && netif_running(vsi->netdev))
  3075. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3076. else
  3077. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3078. }
  3079. /**
  3080. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3081. * @pf: the PF
  3082. **/
  3083. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3084. {
  3085. int v;
  3086. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3087. if (pf->vsi[v])
  3088. i40e_quiesce_vsi(pf->vsi[v]);
  3089. }
  3090. }
  3091. /**
  3092. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3093. * @pf: the PF
  3094. **/
  3095. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3096. {
  3097. int v;
  3098. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3099. if (pf->vsi[v])
  3100. i40e_unquiesce_vsi(pf->vsi[v]);
  3101. }
  3102. }
  3103. /**
  3104. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  3105. * @dcbcfg: the corresponding DCBx configuration structure
  3106. *
  3107. * Return the number of TCs from given DCBx configuration
  3108. **/
  3109. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  3110. {
  3111. u8 num_tc = 0;
  3112. int i;
  3113. /* Scan the ETS Config Priority Table to find
  3114. * traffic class enabled for a given priority
  3115. * and use the traffic class index to get the
  3116. * number of traffic classes enabled
  3117. */
  3118. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3119. if (dcbcfg->etscfg.prioritytable[i] > num_tc)
  3120. num_tc = dcbcfg->etscfg.prioritytable[i];
  3121. }
  3122. /* Traffic class index starts from zero so
  3123. * increment to return the actual count
  3124. */
  3125. return num_tc + 1;
  3126. }
  3127. /**
  3128. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  3129. * @dcbcfg: the corresponding DCBx configuration structure
  3130. *
  3131. * Query the current DCB configuration and return the number of
  3132. * traffic classes enabled from the given DCBX config
  3133. **/
  3134. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  3135. {
  3136. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  3137. u8 enabled_tc = 1;
  3138. u8 i;
  3139. for (i = 0; i < num_tc; i++)
  3140. enabled_tc |= 1 << i;
  3141. return enabled_tc;
  3142. }
  3143. /**
  3144. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  3145. * @pf: PF being queried
  3146. *
  3147. * Return number of traffic classes enabled for the given PF
  3148. **/
  3149. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  3150. {
  3151. struct i40e_hw *hw = &pf->hw;
  3152. u8 i, enabled_tc;
  3153. u8 num_tc = 0;
  3154. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3155. /* If DCB is not enabled then always in single TC */
  3156. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3157. return 1;
  3158. /* MFP mode return count of enabled TCs for this PF */
  3159. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3160. enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3161. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3162. if (enabled_tc & (1 << i))
  3163. num_tc++;
  3164. }
  3165. return num_tc;
  3166. }
  3167. /* SFP mode will be enabled for all TCs on port */
  3168. return i40e_dcb_get_num_tc(dcbcfg);
  3169. }
  3170. /**
  3171. * i40e_pf_get_default_tc - Get bitmap for first enabled TC
  3172. * @pf: PF being queried
  3173. *
  3174. * Return a bitmap for first enabled traffic class for this PF.
  3175. **/
  3176. static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
  3177. {
  3178. u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3179. u8 i = 0;
  3180. if (!enabled_tc)
  3181. return 0x1; /* TC0 */
  3182. /* Find the first enabled TC */
  3183. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3184. if (enabled_tc & (1 << i))
  3185. break;
  3186. }
  3187. return 1 << i;
  3188. }
  3189. /**
  3190. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  3191. * @pf: PF being queried
  3192. *
  3193. * Return a bitmap for enabled traffic classes for this PF.
  3194. **/
  3195. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  3196. {
  3197. /* If DCB is not enabled for this PF then just return default TC */
  3198. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3199. return i40e_pf_get_default_tc(pf);
  3200. /* MFP mode will have enabled TCs set by FW */
  3201. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3202. return pf->hw.func_caps.enabled_tcmap;
  3203. /* SFP mode we want PF to be enabled for all TCs */
  3204. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  3205. }
  3206. /**
  3207. * i40e_vsi_get_bw_info - Query VSI BW Information
  3208. * @vsi: the VSI being queried
  3209. *
  3210. * Returns 0 on success, negative value on failure
  3211. **/
  3212. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  3213. {
  3214. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  3215. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  3216. struct i40e_pf *pf = vsi->back;
  3217. struct i40e_hw *hw = &pf->hw;
  3218. i40e_status aq_ret;
  3219. u32 tc_bw_max;
  3220. int i;
  3221. /* Get the VSI level BW configuration */
  3222. aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  3223. if (aq_ret) {
  3224. dev_info(&pf->pdev->dev,
  3225. "couldn't get pf vsi bw config, err %d, aq_err %d\n",
  3226. aq_ret, pf->hw.aq.asq_last_status);
  3227. return -EINVAL;
  3228. }
  3229. /* Get the VSI level BW configuration per TC */
  3230. aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  3231. NULL);
  3232. if (aq_ret) {
  3233. dev_info(&pf->pdev->dev,
  3234. "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
  3235. aq_ret, pf->hw.aq.asq_last_status);
  3236. return -EINVAL;
  3237. }
  3238. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  3239. dev_info(&pf->pdev->dev,
  3240. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  3241. bw_config.tc_valid_bits,
  3242. bw_ets_config.tc_valid_bits);
  3243. /* Still continuing */
  3244. }
  3245. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  3246. vsi->bw_max_quanta = bw_config.max_bw;
  3247. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  3248. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  3249. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3250. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  3251. vsi->bw_ets_limit_credits[i] =
  3252. le16_to_cpu(bw_ets_config.credits[i]);
  3253. /* 3 bits out of 4 for each TC */
  3254. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  3255. }
  3256. return 0;
  3257. }
  3258. /**
  3259. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  3260. * @vsi: the VSI being configured
  3261. * @enabled_tc: TC bitmap
  3262. * @bw_credits: BW shared credits per TC
  3263. *
  3264. * Returns 0 on success, negative value on failure
  3265. **/
  3266. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  3267. u8 *bw_share)
  3268. {
  3269. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  3270. i40e_status aq_ret;
  3271. int i;
  3272. bw_data.tc_valid_bits = enabled_tc;
  3273. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3274. bw_data.tc_bw_credits[i] = bw_share[i];
  3275. aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  3276. NULL);
  3277. if (aq_ret) {
  3278. dev_info(&vsi->back->pdev->dev,
  3279. "AQ command Config VSI BW allocation per TC failed = %d\n",
  3280. vsi->back->hw.aq.asq_last_status);
  3281. return -EINVAL;
  3282. }
  3283. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3284. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  3285. return 0;
  3286. }
  3287. /**
  3288. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  3289. * @vsi: the VSI being configured
  3290. * @enabled_tc: TC map to be enabled
  3291. *
  3292. **/
  3293. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3294. {
  3295. struct net_device *netdev = vsi->netdev;
  3296. struct i40e_pf *pf = vsi->back;
  3297. struct i40e_hw *hw = &pf->hw;
  3298. u8 netdev_tc = 0;
  3299. int i;
  3300. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3301. if (!netdev)
  3302. return;
  3303. if (!enabled_tc) {
  3304. netdev_reset_tc(netdev);
  3305. return;
  3306. }
  3307. /* Set up actual enabled TCs on the VSI */
  3308. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  3309. return;
  3310. /* set per TC queues for the VSI */
  3311. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3312. /* Only set TC queues for enabled tcs
  3313. *
  3314. * e.g. For a VSI that has TC0 and TC3 enabled the
  3315. * enabled_tc bitmap would be 0x00001001; the driver
  3316. * will set the numtc for netdev as 2 that will be
  3317. * referenced by the netdev layer as TC 0 and 1.
  3318. */
  3319. if (vsi->tc_config.enabled_tc & (1 << i))
  3320. netdev_set_tc_queue(netdev,
  3321. vsi->tc_config.tc_info[i].netdev_tc,
  3322. vsi->tc_config.tc_info[i].qcount,
  3323. vsi->tc_config.tc_info[i].qoffset);
  3324. }
  3325. /* Assign UP2TC map for the VSI */
  3326. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3327. /* Get the actual TC# for the UP */
  3328. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  3329. /* Get the mapped netdev TC# for the UP */
  3330. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  3331. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  3332. }
  3333. }
  3334. /**
  3335. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  3336. * @vsi: the VSI being configured
  3337. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  3338. **/
  3339. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  3340. struct i40e_vsi_context *ctxt)
  3341. {
  3342. /* copy just the sections touched not the entire info
  3343. * since not all sections are valid as returned by
  3344. * update vsi params
  3345. */
  3346. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  3347. memcpy(&vsi->info.queue_mapping,
  3348. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  3349. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  3350. sizeof(vsi->info.tc_mapping));
  3351. }
  3352. /**
  3353. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  3354. * @vsi: VSI to be configured
  3355. * @enabled_tc: TC bitmap
  3356. *
  3357. * This configures a particular VSI for TCs that are mapped to the
  3358. * given TC bitmap. It uses default bandwidth share for TCs across
  3359. * VSIs to configure TC for a particular VSI.
  3360. *
  3361. * NOTE:
  3362. * It is expected that the VSI queues have been quisced before calling
  3363. * this function.
  3364. **/
  3365. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3366. {
  3367. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  3368. struct i40e_vsi_context ctxt;
  3369. int ret = 0;
  3370. int i;
  3371. /* Check if enabled_tc is same as existing or new TCs */
  3372. if (vsi->tc_config.enabled_tc == enabled_tc)
  3373. return ret;
  3374. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  3375. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3376. if (enabled_tc & (1 << i))
  3377. bw_share[i] = 1;
  3378. }
  3379. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  3380. if (ret) {
  3381. dev_info(&vsi->back->pdev->dev,
  3382. "Failed configuring TC map %d for VSI %d\n",
  3383. enabled_tc, vsi->seid);
  3384. goto out;
  3385. }
  3386. /* Update Queue Pairs Mapping for currently enabled UPs */
  3387. ctxt.seid = vsi->seid;
  3388. ctxt.pf_num = vsi->back->hw.pf_id;
  3389. ctxt.vf_num = 0;
  3390. ctxt.uplink_seid = vsi->uplink_seid;
  3391. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  3392. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  3393. /* Update the VSI after updating the VSI queue-mapping information */
  3394. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  3395. if (ret) {
  3396. dev_info(&vsi->back->pdev->dev,
  3397. "update vsi failed, aq_err=%d\n",
  3398. vsi->back->hw.aq.asq_last_status);
  3399. goto out;
  3400. }
  3401. /* update the local VSI info with updated queue map */
  3402. i40e_vsi_update_queue_map(vsi, &ctxt);
  3403. vsi->info.valid_sections = 0;
  3404. /* Update current VSI BW information */
  3405. ret = i40e_vsi_get_bw_info(vsi);
  3406. if (ret) {
  3407. dev_info(&vsi->back->pdev->dev,
  3408. "Failed updating vsi bw info, aq_err=%d\n",
  3409. vsi->back->hw.aq.asq_last_status);
  3410. goto out;
  3411. }
  3412. /* Update the netdev TC setup */
  3413. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  3414. out:
  3415. return ret;
  3416. }
  3417. /**
  3418. * i40e_veb_config_tc - Configure TCs for given VEB
  3419. * @veb: given VEB
  3420. * @enabled_tc: TC bitmap
  3421. *
  3422. * Configures given TC bitmap for VEB (switching) element
  3423. **/
  3424. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  3425. {
  3426. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  3427. struct i40e_pf *pf = veb->pf;
  3428. int ret = 0;
  3429. int i;
  3430. /* No TCs or already enabled TCs just return */
  3431. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  3432. return ret;
  3433. bw_data.tc_valid_bits = enabled_tc;
  3434. /* bw_data.absolute_credits is not set (relative) */
  3435. /* Enable ETS TCs with equal BW Share for now */
  3436. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3437. if (enabled_tc & (1 << i))
  3438. bw_data.tc_bw_share_credits[i] = 1;
  3439. }
  3440. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  3441. &bw_data, NULL);
  3442. if (ret) {
  3443. dev_info(&pf->pdev->dev,
  3444. "veb bw config failed, aq_err=%d\n",
  3445. pf->hw.aq.asq_last_status);
  3446. goto out;
  3447. }
  3448. /* Update the BW information */
  3449. ret = i40e_veb_get_bw_info(veb);
  3450. if (ret) {
  3451. dev_info(&pf->pdev->dev,
  3452. "Failed getting veb bw config, aq_err=%d\n",
  3453. pf->hw.aq.asq_last_status);
  3454. }
  3455. out:
  3456. return ret;
  3457. }
  3458. #ifdef CONFIG_I40E_DCB
  3459. /**
  3460. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  3461. * @pf: PF struct
  3462. *
  3463. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  3464. * the caller would've quiesce all the VSIs before calling
  3465. * this function
  3466. **/
  3467. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  3468. {
  3469. u8 tc_map = 0;
  3470. int ret;
  3471. u8 v;
  3472. /* Enable the TCs available on PF to all VEBs */
  3473. tc_map = i40e_pf_get_tc_map(pf);
  3474. for (v = 0; v < I40E_MAX_VEB; v++) {
  3475. if (!pf->veb[v])
  3476. continue;
  3477. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  3478. if (ret) {
  3479. dev_info(&pf->pdev->dev,
  3480. "Failed configuring TC for VEB seid=%d\n",
  3481. pf->veb[v]->seid);
  3482. /* Will try to configure as many components */
  3483. }
  3484. }
  3485. /* Update each VSI */
  3486. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3487. if (!pf->vsi[v])
  3488. continue;
  3489. /* - Enable all TCs for the LAN VSI
  3490. * - For all others keep them at TC0 for now
  3491. */
  3492. if (v == pf->lan_vsi)
  3493. tc_map = i40e_pf_get_tc_map(pf);
  3494. else
  3495. tc_map = i40e_pf_get_default_tc(pf);
  3496. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  3497. if (ret) {
  3498. dev_info(&pf->pdev->dev,
  3499. "Failed configuring TC for VSI seid=%d\n",
  3500. pf->vsi[v]->seid);
  3501. /* Will try to configure as many components */
  3502. } else {
  3503. /* Re-configure VSI vectors based on updated TC map */
  3504. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  3505. if (pf->vsi[v]->netdev)
  3506. i40e_dcbnl_set_all(pf->vsi[v]);
  3507. }
  3508. }
  3509. }
  3510. /**
  3511. * i40e_init_pf_dcb - Initialize DCB configuration
  3512. * @pf: PF being configured
  3513. *
  3514. * Query the current DCB configuration and cache it
  3515. * in the hardware structure
  3516. **/
  3517. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  3518. {
  3519. struct i40e_hw *hw = &pf->hw;
  3520. int err = 0;
  3521. if (pf->hw.func_caps.npar_enable)
  3522. goto out;
  3523. /* Get the initial DCB configuration */
  3524. err = i40e_init_dcb(hw);
  3525. if (!err) {
  3526. /* Device/Function is not DCBX capable */
  3527. if ((!hw->func_caps.dcb) ||
  3528. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  3529. dev_info(&pf->pdev->dev,
  3530. "DCBX offload is not supported or is disabled for this PF.\n");
  3531. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3532. goto out;
  3533. } else {
  3534. /* When status is not DISABLED then DCBX in FW */
  3535. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  3536. DCB_CAP_DCBX_VER_IEEE;
  3537. pf->flags |= I40E_FLAG_DCB_ENABLED;
  3538. }
  3539. } else {
  3540. dev_info(&pf->pdev->dev, "AQ Querying DCB configuration failed: %d\n",
  3541. pf->hw.aq.asq_last_status);
  3542. }
  3543. out:
  3544. return err;
  3545. }
  3546. #endif /* CONFIG_I40E_DCB */
  3547. /**
  3548. * i40e_up_complete - Finish the last steps of bringing up a connection
  3549. * @vsi: the VSI being configured
  3550. **/
  3551. static int i40e_up_complete(struct i40e_vsi *vsi)
  3552. {
  3553. struct i40e_pf *pf = vsi->back;
  3554. int err;
  3555. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3556. i40e_vsi_configure_msix(vsi);
  3557. else
  3558. i40e_configure_msi_and_legacy(vsi);
  3559. /* start rings */
  3560. err = i40e_vsi_control_rings(vsi, true);
  3561. if (err)
  3562. return err;
  3563. clear_bit(__I40E_DOWN, &vsi->state);
  3564. i40e_napi_enable_all(vsi);
  3565. i40e_vsi_enable_irq(vsi);
  3566. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  3567. (vsi->netdev)) {
  3568. netdev_info(vsi->netdev, "NIC Link is Up\n");
  3569. netif_tx_start_all_queues(vsi->netdev);
  3570. netif_carrier_on(vsi->netdev);
  3571. } else if (vsi->netdev) {
  3572. netdev_info(vsi->netdev, "NIC Link is Down\n");
  3573. }
  3574. /* replay FDIR SB filters */
  3575. if (vsi->type == I40E_VSI_FDIR)
  3576. i40e_fdir_filter_restore(vsi);
  3577. i40e_service_event_schedule(pf);
  3578. return 0;
  3579. }
  3580. /**
  3581. * i40e_vsi_reinit_locked - Reset the VSI
  3582. * @vsi: the VSI being configured
  3583. *
  3584. * Rebuild the ring structs after some configuration
  3585. * has changed, e.g. MTU size.
  3586. **/
  3587. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  3588. {
  3589. struct i40e_pf *pf = vsi->back;
  3590. WARN_ON(in_interrupt());
  3591. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  3592. usleep_range(1000, 2000);
  3593. i40e_down(vsi);
  3594. /* Give a VF some time to respond to the reset. The
  3595. * two second wait is based upon the watchdog cycle in
  3596. * the VF driver.
  3597. */
  3598. if (vsi->type == I40E_VSI_SRIOV)
  3599. msleep(2000);
  3600. i40e_up(vsi);
  3601. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  3602. }
  3603. /**
  3604. * i40e_up - Bring the connection back up after being down
  3605. * @vsi: the VSI being configured
  3606. **/
  3607. int i40e_up(struct i40e_vsi *vsi)
  3608. {
  3609. int err;
  3610. err = i40e_vsi_configure(vsi);
  3611. if (!err)
  3612. err = i40e_up_complete(vsi);
  3613. return err;
  3614. }
  3615. /**
  3616. * i40e_down - Shutdown the connection processing
  3617. * @vsi: the VSI being stopped
  3618. **/
  3619. void i40e_down(struct i40e_vsi *vsi)
  3620. {
  3621. int i;
  3622. /* It is assumed that the caller of this function
  3623. * sets the vsi->state __I40E_DOWN bit.
  3624. */
  3625. if (vsi->netdev) {
  3626. netif_carrier_off(vsi->netdev);
  3627. netif_tx_disable(vsi->netdev);
  3628. }
  3629. i40e_vsi_disable_irq(vsi);
  3630. i40e_vsi_control_rings(vsi, false);
  3631. i40e_napi_disable_all(vsi);
  3632. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3633. i40e_clean_tx_ring(vsi->tx_rings[i]);
  3634. i40e_clean_rx_ring(vsi->rx_rings[i]);
  3635. }
  3636. }
  3637. /**
  3638. * i40e_setup_tc - configure multiple traffic classes
  3639. * @netdev: net device to configure
  3640. * @tc: number of traffic classes to enable
  3641. **/
  3642. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  3643. {
  3644. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3645. struct i40e_vsi *vsi = np->vsi;
  3646. struct i40e_pf *pf = vsi->back;
  3647. u8 enabled_tc = 0;
  3648. int ret = -EINVAL;
  3649. int i;
  3650. /* Check if DCB enabled to continue */
  3651. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  3652. netdev_info(netdev, "DCB is not enabled for adapter\n");
  3653. goto exit;
  3654. }
  3655. /* Check if MFP enabled */
  3656. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3657. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  3658. goto exit;
  3659. }
  3660. /* Check whether tc count is within enabled limit */
  3661. if (tc > i40e_pf_get_num_tc(pf)) {
  3662. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  3663. goto exit;
  3664. }
  3665. /* Generate TC map for number of tc requested */
  3666. for (i = 0; i < tc; i++)
  3667. enabled_tc |= (1 << i);
  3668. /* Requesting same TC configuration as already enabled */
  3669. if (enabled_tc == vsi->tc_config.enabled_tc)
  3670. return 0;
  3671. /* Quiesce VSI queues */
  3672. i40e_quiesce_vsi(vsi);
  3673. /* Configure VSI for enabled TCs */
  3674. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  3675. if (ret) {
  3676. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  3677. vsi->seid);
  3678. goto exit;
  3679. }
  3680. /* Unquiesce VSI */
  3681. i40e_unquiesce_vsi(vsi);
  3682. exit:
  3683. return ret;
  3684. }
  3685. /**
  3686. * i40e_open - Called when a network interface is made active
  3687. * @netdev: network interface device structure
  3688. *
  3689. * The open entry point is called when a network interface is made
  3690. * active by the system (IFF_UP). At this point all resources needed
  3691. * for transmit and receive operations are allocated, the interrupt
  3692. * handler is registered with the OS, the netdev watchdog subtask is
  3693. * enabled, and the stack is notified that the interface is ready.
  3694. *
  3695. * Returns 0 on success, negative value on failure
  3696. **/
  3697. static int i40e_open(struct net_device *netdev)
  3698. {
  3699. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3700. struct i40e_vsi *vsi = np->vsi;
  3701. struct i40e_pf *pf = vsi->back;
  3702. int err;
  3703. /* disallow open during test or if eeprom is broken */
  3704. if (test_bit(__I40E_TESTING, &pf->state) ||
  3705. test_bit(__I40E_BAD_EEPROM, &pf->state))
  3706. return -EBUSY;
  3707. netif_carrier_off(netdev);
  3708. err = i40e_vsi_open(vsi);
  3709. if (err)
  3710. return err;
  3711. /* configure global TSO hardware offload settings */
  3712. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  3713. TCP_FLAG_FIN) >> 16);
  3714. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  3715. TCP_FLAG_FIN |
  3716. TCP_FLAG_CWR) >> 16);
  3717. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  3718. #ifdef CONFIG_I40E_VXLAN
  3719. vxlan_get_rx_port(netdev);
  3720. #endif
  3721. return 0;
  3722. }
  3723. /**
  3724. * i40e_vsi_open -
  3725. * @vsi: the VSI to open
  3726. *
  3727. * Finish initialization of the VSI.
  3728. *
  3729. * Returns 0 on success, negative value on failure
  3730. **/
  3731. int i40e_vsi_open(struct i40e_vsi *vsi)
  3732. {
  3733. struct i40e_pf *pf = vsi->back;
  3734. char int_name[IFNAMSIZ];
  3735. int err;
  3736. /* allocate descriptors */
  3737. err = i40e_vsi_setup_tx_resources(vsi);
  3738. if (err)
  3739. goto err_setup_tx;
  3740. err = i40e_vsi_setup_rx_resources(vsi);
  3741. if (err)
  3742. goto err_setup_rx;
  3743. err = i40e_vsi_configure(vsi);
  3744. if (err)
  3745. goto err_setup_rx;
  3746. if (vsi->netdev) {
  3747. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  3748. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  3749. err = i40e_vsi_request_irq(vsi, int_name);
  3750. if (err)
  3751. goto err_setup_rx;
  3752. /* Notify the stack of the actual queue counts. */
  3753. err = netif_set_real_num_tx_queues(vsi->netdev,
  3754. vsi->num_queue_pairs);
  3755. if (err)
  3756. goto err_set_queues;
  3757. err = netif_set_real_num_rx_queues(vsi->netdev,
  3758. vsi->num_queue_pairs);
  3759. if (err)
  3760. goto err_set_queues;
  3761. } else if (vsi->type == I40E_VSI_FDIR) {
  3762. snprintf(int_name, sizeof(int_name) - 1, "%s-fdir",
  3763. dev_driver_string(&pf->pdev->dev));
  3764. err = i40e_vsi_request_irq(vsi, int_name);
  3765. } else {
  3766. err = EINVAL;
  3767. goto err_setup_rx;
  3768. }
  3769. err = i40e_up_complete(vsi);
  3770. if (err)
  3771. goto err_up_complete;
  3772. return 0;
  3773. err_up_complete:
  3774. i40e_down(vsi);
  3775. err_set_queues:
  3776. i40e_vsi_free_irq(vsi);
  3777. err_setup_rx:
  3778. i40e_vsi_free_rx_resources(vsi);
  3779. err_setup_tx:
  3780. i40e_vsi_free_tx_resources(vsi);
  3781. if (vsi == pf->vsi[pf->lan_vsi])
  3782. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  3783. return err;
  3784. }
  3785. /**
  3786. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  3787. * @pf: Pointer to pf
  3788. *
  3789. * This function destroys the hlist where all the Flow Director
  3790. * filters were saved.
  3791. **/
  3792. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  3793. {
  3794. struct i40e_fdir_filter *filter;
  3795. struct hlist_node *node2;
  3796. hlist_for_each_entry_safe(filter, node2,
  3797. &pf->fdir_filter_list, fdir_node) {
  3798. hlist_del(&filter->fdir_node);
  3799. kfree(filter);
  3800. }
  3801. pf->fdir_pf_active_filters = 0;
  3802. }
  3803. /**
  3804. * i40e_close - Disables a network interface
  3805. * @netdev: network interface device structure
  3806. *
  3807. * The close entry point is called when an interface is de-activated
  3808. * by the OS. The hardware is still under the driver's control, but
  3809. * this netdev interface is disabled.
  3810. *
  3811. * Returns 0, this is not allowed to fail
  3812. **/
  3813. static int i40e_close(struct net_device *netdev)
  3814. {
  3815. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3816. struct i40e_vsi *vsi = np->vsi;
  3817. i40e_vsi_close(vsi);
  3818. return 0;
  3819. }
  3820. /**
  3821. * i40e_do_reset - Start a PF or Core Reset sequence
  3822. * @pf: board private structure
  3823. * @reset_flags: which reset is requested
  3824. *
  3825. * The essential difference in resets is that the PF Reset
  3826. * doesn't clear the packet buffers, doesn't reset the PE
  3827. * firmware, and doesn't bother the other PFs on the chip.
  3828. **/
  3829. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  3830. {
  3831. u32 val;
  3832. WARN_ON(in_interrupt());
  3833. /* do the biggest reset indicated */
  3834. if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) {
  3835. /* Request a Global Reset
  3836. *
  3837. * This will start the chip's countdown to the actual full
  3838. * chip reset event, and a warning interrupt to be sent
  3839. * to all PFs, including the requestor. Our handler
  3840. * for the warning interrupt will deal with the shutdown
  3841. * and recovery of the switch setup.
  3842. */
  3843. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  3844. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3845. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  3846. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3847. } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) {
  3848. /* Request a Core Reset
  3849. *
  3850. * Same as Global Reset, except does *not* include the MAC/PHY
  3851. */
  3852. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  3853. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3854. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  3855. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3856. i40e_flush(&pf->hw);
  3857. } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) {
  3858. /* Request a Firmware Reset
  3859. *
  3860. * Same as Global reset, plus restarting the
  3861. * embedded firmware engine.
  3862. */
  3863. /* enable EMP Reset */
  3864. val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP);
  3865. val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK;
  3866. wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val);
  3867. /* force the reset */
  3868. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3869. val |= I40E_GLGEN_RTRIG_EMPFWR_MASK;
  3870. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3871. i40e_flush(&pf->hw);
  3872. } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) {
  3873. /* Request a PF Reset
  3874. *
  3875. * Resets only the PF-specific registers
  3876. *
  3877. * This goes directly to the tear-down and rebuild of
  3878. * the switch, since we need to do all the recovery as
  3879. * for the Core Reset.
  3880. */
  3881. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  3882. i40e_handle_reset_warning(pf);
  3883. } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) {
  3884. int v;
  3885. /* Find the VSI(s) that requested a re-init */
  3886. dev_info(&pf->pdev->dev,
  3887. "VSI reinit requested\n");
  3888. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3889. struct i40e_vsi *vsi = pf->vsi[v];
  3890. if (vsi != NULL &&
  3891. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  3892. i40e_vsi_reinit_locked(pf->vsi[v]);
  3893. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  3894. }
  3895. }
  3896. /* no further action needed, so return now */
  3897. return;
  3898. } else {
  3899. dev_info(&pf->pdev->dev,
  3900. "bad reset request 0x%08x\n", reset_flags);
  3901. return;
  3902. }
  3903. }
  3904. #ifdef CONFIG_I40E_DCB
  3905. /**
  3906. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  3907. * @pf: board private structure
  3908. * @old_cfg: current DCB config
  3909. * @new_cfg: new DCB config
  3910. **/
  3911. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  3912. struct i40e_dcbx_config *old_cfg,
  3913. struct i40e_dcbx_config *new_cfg)
  3914. {
  3915. bool need_reconfig = false;
  3916. /* Check if ETS configuration has changed */
  3917. if (memcmp(&new_cfg->etscfg,
  3918. &old_cfg->etscfg,
  3919. sizeof(new_cfg->etscfg))) {
  3920. /* If Priority Table has changed reconfig is needed */
  3921. if (memcmp(&new_cfg->etscfg.prioritytable,
  3922. &old_cfg->etscfg.prioritytable,
  3923. sizeof(new_cfg->etscfg.prioritytable))) {
  3924. need_reconfig = true;
  3925. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  3926. }
  3927. if (memcmp(&new_cfg->etscfg.tcbwtable,
  3928. &old_cfg->etscfg.tcbwtable,
  3929. sizeof(new_cfg->etscfg.tcbwtable)))
  3930. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  3931. if (memcmp(&new_cfg->etscfg.tsatable,
  3932. &old_cfg->etscfg.tsatable,
  3933. sizeof(new_cfg->etscfg.tsatable)))
  3934. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  3935. }
  3936. /* Check if PFC configuration has changed */
  3937. if (memcmp(&new_cfg->pfc,
  3938. &old_cfg->pfc,
  3939. sizeof(new_cfg->pfc))) {
  3940. need_reconfig = true;
  3941. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  3942. }
  3943. /* Check if APP Table has changed */
  3944. if (memcmp(&new_cfg->app,
  3945. &old_cfg->app,
  3946. sizeof(new_cfg->app))) {
  3947. need_reconfig = true;
  3948. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  3949. }
  3950. return need_reconfig;
  3951. }
  3952. /**
  3953. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  3954. * @pf: board private structure
  3955. * @e: event info posted on ARQ
  3956. **/
  3957. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  3958. struct i40e_arq_event_info *e)
  3959. {
  3960. struct i40e_aqc_lldp_get_mib *mib =
  3961. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  3962. struct i40e_hw *hw = &pf->hw;
  3963. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  3964. struct i40e_dcbx_config tmp_dcbx_cfg;
  3965. bool need_reconfig = false;
  3966. int ret = 0;
  3967. u8 type;
  3968. /* Ignore if event is not for Nearest Bridge */
  3969. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  3970. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  3971. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  3972. return ret;
  3973. /* Check MIB Type and return if event for Remote MIB update */
  3974. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  3975. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  3976. /* Update the remote cached instance and return */
  3977. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  3978. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  3979. &hw->remote_dcbx_config);
  3980. goto exit;
  3981. }
  3982. /* Convert/store the DCBX data from LLDPDU temporarily */
  3983. memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg));
  3984. ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg);
  3985. if (ret) {
  3986. /* Error in LLDPDU parsing return */
  3987. dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n");
  3988. goto exit;
  3989. }
  3990. /* No change detected in DCBX configs */
  3991. if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) {
  3992. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  3993. goto exit;
  3994. }
  3995. need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg);
  3996. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg);
  3997. /* Overwrite the new configuration */
  3998. *dcbx_cfg = tmp_dcbx_cfg;
  3999. if (!need_reconfig)
  4000. goto exit;
  4001. /* Reconfiguration needed quiesce all VSIs */
  4002. i40e_pf_quiesce_all_vsi(pf);
  4003. /* Changes in configuration update VEB/VSI */
  4004. i40e_dcb_reconfigure(pf);
  4005. i40e_pf_unquiesce_all_vsi(pf);
  4006. exit:
  4007. return ret;
  4008. }
  4009. #endif /* CONFIG_I40E_DCB */
  4010. /**
  4011. * i40e_do_reset_safe - Protected reset path for userland calls.
  4012. * @pf: board private structure
  4013. * @reset_flags: which reset is requested
  4014. *
  4015. **/
  4016. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  4017. {
  4018. rtnl_lock();
  4019. i40e_do_reset(pf, reset_flags);
  4020. rtnl_unlock();
  4021. }
  4022. /**
  4023. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  4024. * @pf: board private structure
  4025. * @e: event info posted on ARQ
  4026. *
  4027. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  4028. * and VF queues
  4029. **/
  4030. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  4031. struct i40e_arq_event_info *e)
  4032. {
  4033. struct i40e_aqc_lan_overflow *data =
  4034. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  4035. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  4036. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  4037. struct i40e_hw *hw = &pf->hw;
  4038. struct i40e_vf *vf;
  4039. u16 vf_id;
  4040. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  4041. queue, qtx_ctl);
  4042. /* Queue belongs to VF, find the VF and issue VF reset */
  4043. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  4044. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  4045. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  4046. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  4047. vf_id -= hw->func_caps.vf_base_id;
  4048. vf = &pf->vf[vf_id];
  4049. i40e_vc_notify_vf_reset(vf);
  4050. /* Allow VF to process pending reset notification */
  4051. msleep(20);
  4052. i40e_reset_vf(vf, false);
  4053. }
  4054. }
  4055. /**
  4056. * i40e_service_event_complete - Finish up the service event
  4057. * @pf: board private structure
  4058. **/
  4059. static void i40e_service_event_complete(struct i40e_pf *pf)
  4060. {
  4061. BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
  4062. /* flush memory to make sure state is correct before next watchog */
  4063. smp_mb__before_clear_bit();
  4064. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  4065. }
  4066. /**
  4067. * i40e_get_current_fd_count - Get the count of FD filters programmed in the HW
  4068. * @pf: board private structure
  4069. **/
  4070. int i40e_get_current_fd_count(struct i40e_pf *pf)
  4071. {
  4072. int val, fcnt_prog;
  4073. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  4074. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  4075. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  4076. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  4077. return fcnt_prog;
  4078. }
  4079. /**
  4080. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  4081. * @pf: board private structure
  4082. **/
  4083. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  4084. {
  4085. u32 fcnt_prog, fcnt_avail;
  4086. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  4087. * to re-enable
  4088. */
  4089. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4090. (pf->flags & I40E_FLAG_FD_SB_ENABLED))
  4091. return;
  4092. fcnt_prog = i40e_get_current_fd_count(pf);
  4093. fcnt_avail = pf->hw.fdir_shared_filter_count +
  4094. pf->fdir_pf_filter_count;
  4095. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) {
  4096. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  4097. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  4098. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  4099. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  4100. }
  4101. }
  4102. /* Wait for some more space to be available to turn on ATR */
  4103. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  4104. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4105. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  4106. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  4107. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
  4108. }
  4109. }
  4110. }
  4111. /**
  4112. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  4113. * @pf: board private structure
  4114. **/
  4115. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  4116. {
  4117. if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT))
  4118. return;
  4119. /* if interface is down do nothing */
  4120. if (test_bit(__I40E_DOWN, &pf->state))
  4121. return;
  4122. i40e_fdir_check_and_reenable(pf);
  4123. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4124. (pf->flags & I40E_FLAG_FD_SB_ENABLED))
  4125. pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT;
  4126. }
  4127. /**
  4128. * i40e_vsi_link_event - notify VSI of a link event
  4129. * @vsi: vsi to be notified
  4130. * @link_up: link up or down
  4131. **/
  4132. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  4133. {
  4134. if (!vsi)
  4135. return;
  4136. switch (vsi->type) {
  4137. case I40E_VSI_MAIN:
  4138. if (!vsi->netdev || !vsi->netdev_registered)
  4139. break;
  4140. if (link_up) {
  4141. netif_carrier_on(vsi->netdev);
  4142. netif_tx_wake_all_queues(vsi->netdev);
  4143. } else {
  4144. netif_carrier_off(vsi->netdev);
  4145. netif_tx_stop_all_queues(vsi->netdev);
  4146. }
  4147. break;
  4148. case I40E_VSI_SRIOV:
  4149. break;
  4150. case I40E_VSI_VMDQ2:
  4151. case I40E_VSI_CTRL:
  4152. case I40E_VSI_MIRROR:
  4153. default:
  4154. /* there is no notification for other VSIs */
  4155. break;
  4156. }
  4157. }
  4158. /**
  4159. * i40e_veb_link_event - notify elements on the veb of a link event
  4160. * @veb: veb to be notified
  4161. * @link_up: link up or down
  4162. **/
  4163. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  4164. {
  4165. struct i40e_pf *pf;
  4166. int i;
  4167. if (!veb || !veb->pf)
  4168. return;
  4169. pf = veb->pf;
  4170. /* depth first... */
  4171. for (i = 0; i < I40E_MAX_VEB; i++)
  4172. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  4173. i40e_veb_link_event(pf->veb[i], link_up);
  4174. /* ... now the local VSIs */
  4175. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  4176. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  4177. i40e_vsi_link_event(pf->vsi[i], link_up);
  4178. }
  4179. /**
  4180. * i40e_link_event - Update netif_carrier status
  4181. * @pf: board private structure
  4182. **/
  4183. static void i40e_link_event(struct i40e_pf *pf)
  4184. {
  4185. bool new_link, old_link;
  4186. new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP);
  4187. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  4188. if (new_link == old_link)
  4189. return;
  4190. if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
  4191. netdev_info(pf->vsi[pf->lan_vsi]->netdev,
  4192. "NIC Link is %s\n", (new_link ? "Up" : "Down"));
  4193. /* Notify the base of the switch tree connected to
  4194. * the link. Floating VEBs are not notified.
  4195. */
  4196. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  4197. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  4198. else
  4199. i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link);
  4200. if (pf->vf)
  4201. i40e_vc_notify_link_state(pf);
  4202. if (pf->flags & I40E_FLAG_PTP)
  4203. i40e_ptp_set_increment(pf);
  4204. }
  4205. /**
  4206. * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
  4207. * @pf: board private structure
  4208. *
  4209. * Set the per-queue flags to request a check for stuck queues in the irq
  4210. * clean functions, then force interrupts to be sure the irq clean is called.
  4211. **/
  4212. static void i40e_check_hang_subtask(struct i40e_pf *pf)
  4213. {
  4214. int i, v;
  4215. /* If we're down or resetting, just bail */
  4216. if (test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4217. return;
  4218. /* for each VSI/netdev
  4219. * for each Tx queue
  4220. * set the check flag
  4221. * for each q_vector
  4222. * force an interrupt
  4223. */
  4224. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4225. struct i40e_vsi *vsi = pf->vsi[v];
  4226. int armed = 0;
  4227. if (!pf->vsi[v] ||
  4228. test_bit(__I40E_DOWN, &vsi->state) ||
  4229. (vsi->netdev && !netif_carrier_ok(vsi->netdev)))
  4230. continue;
  4231. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4232. set_check_for_tx_hang(vsi->tx_rings[i]);
  4233. if (test_bit(__I40E_HANG_CHECK_ARMED,
  4234. &vsi->tx_rings[i]->state))
  4235. armed++;
  4236. }
  4237. if (armed) {
  4238. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  4239. wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0,
  4240. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  4241. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  4242. } else {
  4243. u16 vec = vsi->base_vector - 1;
  4244. u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK |
  4245. I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK);
  4246. for (i = 0; i < vsi->num_q_vectors; i++, vec++)
  4247. wr32(&vsi->back->hw,
  4248. I40E_PFINT_DYN_CTLN(vec), val);
  4249. }
  4250. i40e_flush(&vsi->back->hw);
  4251. }
  4252. }
  4253. }
  4254. /**
  4255. * i40e_watchdog_subtask - Check and bring link up
  4256. * @pf: board private structure
  4257. **/
  4258. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  4259. {
  4260. int i;
  4261. /* if interface is down do nothing */
  4262. if (test_bit(__I40E_DOWN, &pf->state) ||
  4263. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4264. return;
  4265. /* Update the stats for active netdevs so the network stack
  4266. * can look at updated numbers whenever it cares to
  4267. */
  4268. for (i = 0; i < pf->hw.func_caps.num_vsis; i++)
  4269. if (pf->vsi[i] && pf->vsi[i]->netdev)
  4270. i40e_update_stats(pf->vsi[i]);
  4271. /* Update the stats for the active switching components */
  4272. for (i = 0; i < I40E_MAX_VEB; i++)
  4273. if (pf->veb[i])
  4274. i40e_update_veb_stats(pf->veb[i]);
  4275. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  4276. }
  4277. /**
  4278. * i40e_reset_subtask - Set up for resetting the device and driver
  4279. * @pf: board private structure
  4280. **/
  4281. static void i40e_reset_subtask(struct i40e_pf *pf)
  4282. {
  4283. u32 reset_flags = 0;
  4284. rtnl_lock();
  4285. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  4286. reset_flags |= (1 << __I40E_REINIT_REQUESTED);
  4287. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  4288. }
  4289. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  4290. reset_flags |= (1 << __I40E_PF_RESET_REQUESTED);
  4291. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4292. }
  4293. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  4294. reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED);
  4295. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  4296. }
  4297. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  4298. reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED);
  4299. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  4300. }
  4301. /* If there's a recovery already waiting, it takes
  4302. * precedence before starting a new reset sequence.
  4303. */
  4304. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  4305. i40e_handle_reset_warning(pf);
  4306. goto unlock;
  4307. }
  4308. /* If we're already down or resetting, just bail */
  4309. if (reset_flags &&
  4310. !test_bit(__I40E_DOWN, &pf->state) &&
  4311. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4312. i40e_do_reset(pf, reset_flags);
  4313. unlock:
  4314. rtnl_unlock();
  4315. }
  4316. /**
  4317. * i40e_handle_link_event - Handle link event
  4318. * @pf: board private structure
  4319. * @e: event info posted on ARQ
  4320. **/
  4321. static void i40e_handle_link_event(struct i40e_pf *pf,
  4322. struct i40e_arq_event_info *e)
  4323. {
  4324. struct i40e_hw *hw = &pf->hw;
  4325. struct i40e_aqc_get_link_status *status =
  4326. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  4327. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  4328. /* save off old link status information */
  4329. memcpy(&pf->hw.phy.link_info_old, hw_link_info,
  4330. sizeof(pf->hw.phy.link_info_old));
  4331. /* update link status */
  4332. hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type;
  4333. hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed;
  4334. hw_link_info->link_info = status->link_info;
  4335. hw_link_info->an_info = status->an_info;
  4336. hw_link_info->ext_info = status->ext_info;
  4337. hw_link_info->lse_enable =
  4338. le16_to_cpu(status->command_flags) &
  4339. I40E_AQ_LSE_ENABLE;
  4340. /* process the event */
  4341. i40e_link_event(pf);
  4342. /* Do a new status request to re-enable LSE reporting
  4343. * and load new status information into the hw struct,
  4344. * then see if the status changed while processing the
  4345. * initial event.
  4346. */
  4347. i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
  4348. i40e_link_event(pf);
  4349. }
  4350. /**
  4351. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  4352. * @pf: board private structure
  4353. **/
  4354. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  4355. {
  4356. struct i40e_arq_event_info event;
  4357. struct i40e_hw *hw = &pf->hw;
  4358. u16 pending, i = 0;
  4359. i40e_status ret;
  4360. u16 opcode;
  4361. u32 val;
  4362. if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state))
  4363. return;
  4364. event.msg_size = I40E_MAX_AQ_BUF_SIZE;
  4365. event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
  4366. if (!event.msg_buf)
  4367. return;
  4368. do {
  4369. event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */
  4370. ret = i40e_clean_arq_element(hw, &event, &pending);
  4371. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
  4372. dev_info(&pf->pdev->dev, "No ARQ event found\n");
  4373. break;
  4374. } else if (ret) {
  4375. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  4376. break;
  4377. }
  4378. opcode = le16_to_cpu(event.desc.opcode);
  4379. switch (opcode) {
  4380. case i40e_aqc_opc_get_link_status:
  4381. i40e_handle_link_event(pf, &event);
  4382. break;
  4383. case i40e_aqc_opc_send_msg_to_pf:
  4384. ret = i40e_vc_process_vf_msg(pf,
  4385. le16_to_cpu(event.desc.retval),
  4386. le32_to_cpu(event.desc.cookie_high),
  4387. le32_to_cpu(event.desc.cookie_low),
  4388. event.msg_buf,
  4389. event.msg_size);
  4390. break;
  4391. case i40e_aqc_opc_lldp_update_mib:
  4392. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  4393. #ifdef CONFIG_I40E_DCB
  4394. rtnl_lock();
  4395. ret = i40e_handle_lldp_event(pf, &event);
  4396. rtnl_unlock();
  4397. #endif /* CONFIG_I40E_DCB */
  4398. break;
  4399. case i40e_aqc_opc_event_lan_overflow:
  4400. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  4401. i40e_handle_lan_overflow_event(pf, &event);
  4402. break;
  4403. case i40e_aqc_opc_send_msg_to_peer:
  4404. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  4405. break;
  4406. default:
  4407. dev_info(&pf->pdev->dev,
  4408. "ARQ Error: Unknown event 0x%04x received\n",
  4409. opcode);
  4410. break;
  4411. }
  4412. } while (pending && (i++ < pf->adminq_work_limit));
  4413. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  4414. /* re-enable Admin queue interrupt cause */
  4415. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  4416. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  4417. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  4418. i40e_flush(hw);
  4419. kfree(event.msg_buf);
  4420. }
  4421. /**
  4422. * i40e_verify_eeprom - make sure eeprom is good to use
  4423. * @pf: board private structure
  4424. **/
  4425. static void i40e_verify_eeprom(struct i40e_pf *pf)
  4426. {
  4427. int err;
  4428. err = i40e_diag_eeprom_test(&pf->hw);
  4429. if (err) {
  4430. /* retry in case of garbage read */
  4431. err = i40e_diag_eeprom_test(&pf->hw);
  4432. if (err) {
  4433. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  4434. err);
  4435. set_bit(__I40E_BAD_EEPROM, &pf->state);
  4436. }
  4437. }
  4438. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  4439. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  4440. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  4441. }
  4442. }
  4443. /**
  4444. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  4445. * @veb: pointer to the VEB instance
  4446. *
  4447. * This is a recursive function that first builds the attached VSIs then
  4448. * recurses in to build the next layer of VEB. We track the connections
  4449. * through our own index numbers because the seid's from the HW could
  4450. * change across the reset.
  4451. **/
  4452. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  4453. {
  4454. struct i40e_vsi *ctl_vsi = NULL;
  4455. struct i40e_pf *pf = veb->pf;
  4456. int v, veb_idx;
  4457. int ret;
  4458. /* build VSI that owns this VEB, temporarily attached to base VEB */
  4459. for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) {
  4460. if (pf->vsi[v] &&
  4461. pf->vsi[v]->veb_idx == veb->idx &&
  4462. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  4463. ctl_vsi = pf->vsi[v];
  4464. break;
  4465. }
  4466. }
  4467. if (!ctl_vsi) {
  4468. dev_info(&pf->pdev->dev,
  4469. "missing owner VSI for veb_idx %d\n", veb->idx);
  4470. ret = -ENOENT;
  4471. goto end_reconstitute;
  4472. }
  4473. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  4474. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  4475. ret = i40e_add_vsi(ctl_vsi);
  4476. if (ret) {
  4477. dev_info(&pf->pdev->dev,
  4478. "rebuild of owner VSI failed: %d\n", ret);
  4479. goto end_reconstitute;
  4480. }
  4481. i40e_vsi_reset_stats(ctl_vsi);
  4482. /* create the VEB in the switch and move the VSI onto the VEB */
  4483. ret = i40e_add_veb(veb, ctl_vsi);
  4484. if (ret)
  4485. goto end_reconstitute;
  4486. /* create the remaining VSIs attached to this VEB */
  4487. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4488. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  4489. continue;
  4490. if (pf->vsi[v]->veb_idx == veb->idx) {
  4491. struct i40e_vsi *vsi = pf->vsi[v];
  4492. vsi->uplink_seid = veb->seid;
  4493. ret = i40e_add_vsi(vsi);
  4494. if (ret) {
  4495. dev_info(&pf->pdev->dev,
  4496. "rebuild of vsi_idx %d failed: %d\n",
  4497. v, ret);
  4498. goto end_reconstitute;
  4499. }
  4500. i40e_vsi_reset_stats(vsi);
  4501. }
  4502. }
  4503. /* create any VEBs attached to this VEB - RECURSION */
  4504. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  4505. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  4506. pf->veb[veb_idx]->uplink_seid = veb->seid;
  4507. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  4508. if (ret)
  4509. break;
  4510. }
  4511. }
  4512. end_reconstitute:
  4513. return ret;
  4514. }
  4515. /**
  4516. * i40e_get_capabilities - get info about the HW
  4517. * @pf: the PF struct
  4518. **/
  4519. static int i40e_get_capabilities(struct i40e_pf *pf)
  4520. {
  4521. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  4522. u16 data_size;
  4523. int buf_len;
  4524. int err;
  4525. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  4526. do {
  4527. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  4528. if (!cap_buf)
  4529. return -ENOMEM;
  4530. /* this loads the data into the hw struct for us */
  4531. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  4532. &data_size,
  4533. i40e_aqc_opc_list_func_capabilities,
  4534. NULL);
  4535. /* data loaded, buffer no longer needed */
  4536. kfree(cap_buf);
  4537. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  4538. /* retry with a larger buffer */
  4539. buf_len = data_size;
  4540. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  4541. dev_info(&pf->pdev->dev,
  4542. "capability discovery failed: aq=%d\n",
  4543. pf->hw.aq.asq_last_status);
  4544. return -ENODEV;
  4545. }
  4546. } while (err);
  4547. if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) ||
  4548. (pf->hw.aq.fw_maj_ver < 2)) {
  4549. pf->hw.func_caps.num_msix_vectors++;
  4550. pf->hw.func_caps.num_msix_vectors_vf++;
  4551. }
  4552. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  4553. dev_info(&pf->pdev->dev,
  4554. "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",
  4555. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  4556. pf->hw.func_caps.num_msix_vectors,
  4557. pf->hw.func_caps.num_msix_vectors_vf,
  4558. pf->hw.func_caps.fd_filters_guaranteed,
  4559. pf->hw.func_caps.fd_filters_best_effort,
  4560. pf->hw.func_caps.num_tx_qp,
  4561. pf->hw.func_caps.num_vsis);
  4562. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  4563. + pf->hw.func_caps.num_vfs)
  4564. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  4565. dev_info(&pf->pdev->dev,
  4566. "got num_vsis %d, setting num_vsis to %d\n",
  4567. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  4568. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  4569. }
  4570. return 0;
  4571. }
  4572. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  4573. /**
  4574. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  4575. * @pf: board private structure
  4576. **/
  4577. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  4578. {
  4579. struct i40e_vsi *vsi;
  4580. int i;
  4581. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  4582. return;
  4583. /* find existing VSI and see if it needs configuring */
  4584. vsi = NULL;
  4585. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  4586. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  4587. vsi = pf->vsi[i];
  4588. break;
  4589. }
  4590. }
  4591. /* create a new VSI if none exists */
  4592. if (!vsi) {
  4593. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  4594. pf->vsi[pf->lan_vsi]->seid, 0);
  4595. if (!vsi) {
  4596. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  4597. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  4598. return;
  4599. }
  4600. }
  4601. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  4602. }
  4603. /**
  4604. * i40e_fdir_teardown - release the Flow Director resources
  4605. * @pf: board private structure
  4606. **/
  4607. static void i40e_fdir_teardown(struct i40e_pf *pf)
  4608. {
  4609. int i;
  4610. i40e_fdir_filter_exit(pf);
  4611. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  4612. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  4613. i40e_vsi_release(pf->vsi[i]);
  4614. break;
  4615. }
  4616. }
  4617. }
  4618. /**
  4619. * i40e_prep_for_reset - prep for the core to reset
  4620. * @pf: board private structure
  4621. *
  4622. * Close up the VFs and other things in prep for pf Reset.
  4623. **/
  4624. static int i40e_prep_for_reset(struct i40e_pf *pf)
  4625. {
  4626. struct i40e_hw *hw = &pf->hw;
  4627. i40e_status ret;
  4628. u32 v;
  4629. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  4630. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  4631. return 0;
  4632. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  4633. if (i40e_check_asq_alive(hw))
  4634. i40e_vc_notify_reset(pf);
  4635. /* quiesce the VSIs and their queues that are not already DOWN */
  4636. i40e_pf_quiesce_all_vsi(pf);
  4637. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4638. if (pf->vsi[v])
  4639. pf->vsi[v]->seid = 0;
  4640. }
  4641. i40e_shutdown_adminq(&pf->hw);
  4642. /* call shutdown HMC */
  4643. ret = i40e_shutdown_lan_hmc(hw);
  4644. if (ret) {
  4645. dev_info(&pf->pdev->dev, "shutdown_lan_hmc failed: %d\n", ret);
  4646. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  4647. }
  4648. return ret;
  4649. }
  4650. /**
  4651. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  4652. * @pf: board private structure
  4653. * @reinit: if the Main VSI needs to re-initialized.
  4654. **/
  4655. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  4656. {
  4657. struct i40e_driver_version dv;
  4658. struct i40e_hw *hw = &pf->hw;
  4659. i40e_status ret;
  4660. u32 v;
  4661. /* Now we wait for GRST to settle out.
  4662. * We don't have to delete the VEBs or VSIs from the hw switch
  4663. * because the reset will make them disappear.
  4664. */
  4665. ret = i40e_pf_reset(hw);
  4666. if (ret)
  4667. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  4668. pf->pfr_count++;
  4669. if (test_bit(__I40E_DOWN, &pf->state))
  4670. goto end_core_reset;
  4671. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  4672. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  4673. ret = i40e_init_adminq(&pf->hw);
  4674. if (ret) {
  4675. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret);
  4676. goto end_core_reset;
  4677. }
  4678. /* re-verify the eeprom if we just had an EMP reset */
  4679. if (test_bit(__I40E_EMP_RESET_REQUESTED, &pf->state)) {
  4680. clear_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
  4681. i40e_verify_eeprom(pf);
  4682. }
  4683. ret = i40e_get_capabilities(pf);
  4684. if (ret) {
  4685. dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n",
  4686. ret);
  4687. goto end_core_reset;
  4688. }
  4689. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  4690. hw->func_caps.num_rx_qp,
  4691. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  4692. if (ret) {
  4693. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  4694. goto end_core_reset;
  4695. }
  4696. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  4697. if (ret) {
  4698. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  4699. goto end_core_reset;
  4700. }
  4701. #ifdef CONFIG_I40E_DCB
  4702. ret = i40e_init_pf_dcb(pf);
  4703. if (ret) {
  4704. dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret);
  4705. goto end_core_reset;
  4706. }
  4707. #endif /* CONFIG_I40E_DCB */
  4708. /* do basic switch setup */
  4709. ret = i40e_setup_pf_switch(pf, reinit);
  4710. if (ret)
  4711. goto end_core_reset;
  4712. /* Rebuild the VSIs and VEBs that existed before reset.
  4713. * They are still in our local switch element arrays, so only
  4714. * need to rebuild the switch model in the HW.
  4715. *
  4716. * If there were VEBs but the reconstitution failed, we'll try
  4717. * try to recover minimal use by getting the basic PF VSI working.
  4718. */
  4719. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  4720. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  4721. /* find the one VEB connected to the MAC, and find orphans */
  4722. for (v = 0; v < I40E_MAX_VEB; v++) {
  4723. if (!pf->veb[v])
  4724. continue;
  4725. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  4726. pf->veb[v]->uplink_seid == 0) {
  4727. ret = i40e_reconstitute_veb(pf->veb[v]);
  4728. if (!ret)
  4729. continue;
  4730. /* If Main VEB failed, we're in deep doodoo,
  4731. * so give up rebuilding the switch and set up
  4732. * for minimal rebuild of PF VSI.
  4733. * If orphan failed, we'll report the error
  4734. * but try to keep going.
  4735. */
  4736. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  4737. dev_info(&pf->pdev->dev,
  4738. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  4739. ret);
  4740. pf->vsi[pf->lan_vsi]->uplink_seid
  4741. = pf->mac_seid;
  4742. break;
  4743. } else if (pf->veb[v]->uplink_seid == 0) {
  4744. dev_info(&pf->pdev->dev,
  4745. "rebuild of orphan VEB failed: %d\n",
  4746. ret);
  4747. }
  4748. }
  4749. }
  4750. }
  4751. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  4752. dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  4753. /* no VEB, so rebuild only the Main VSI */
  4754. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  4755. if (ret) {
  4756. dev_info(&pf->pdev->dev,
  4757. "rebuild of Main VSI failed: %d\n", ret);
  4758. goto end_core_reset;
  4759. }
  4760. }
  4761. /* reinit the misc interrupt */
  4762. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4763. ret = i40e_setup_misc_vector(pf);
  4764. /* restart the VSIs that were rebuilt and running before the reset */
  4765. i40e_pf_unquiesce_all_vsi(pf);
  4766. if (pf->num_alloc_vfs) {
  4767. for (v = 0; v < pf->num_alloc_vfs; v++)
  4768. i40e_reset_vf(&pf->vf[v], true);
  4769. }
  4770. /* tell the firmware that we're starting */
  4771. dv.major_version = DRV_VERSION_MAJOR;
  4772. dv.minor_version = DRV_VERSION_MINOR;
  4773. dv.build_version = DRV_VERSION_BUILD;
  4774. dv.subbuild_version = 0;
  4775. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  4776. dev_info(&pf->pdev->dev, "reset complete\n");
  4777. end_core_reset:
  4778. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  4779. }
  4780. /**
  4781. * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
  4782. * @pf: board private structure
  4783. *
  4784. * Close up the VFs and other things in prep for a Core Reset,
  4785. * then get ready to rebuild the world.
  4786. **/
  4787. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  4788. {
  4789. i40e_status ret;
  4790. ret = i40e_prep_for_reset(pf);
  4791. if (!ret)
  4792. i40e_reset_and_rebuild(pf, false);
  4793. }
  4794. /**
  4795. * i40e_handle_mdd_event
  4796. * @pf: pointer to the pf structure
  4797. *
  4798. * Called from the MDD irq handler to identify possibly malicious vfs
  4799. **/
  4800. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  4801. {
  4802. struct i40e_hw *hw = &pf->hw;
  4803. bool mdd_detected = false;
  4804. struct i40e_vf *vf;
  4805. u32 reg;
  4806. int i;
  4807. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  4808. return;
  4809. /* find what triggered the MDD event */
  4810. reg = rd32(hw, I40E_GL_MDET_TX);
  4811. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  4812. u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK)
  4813. >> I40E_GL_MDET_TX_FUNCTION_SHIFT;
  4814. u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT)
  4815. >> I40E_GL_MDET_TX_EVENT_SHIFT;
  4816. u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK)
  4817. >> I40E_GL_MDET_TX_QUEUE_SHIFT;
  4818. dev_info(&pf->pdev->dev,
  4819. "Malicious Driver Detection event 0x%02x on TX queue %d of function 0x%02x\n",
  4820. event, queue, func);
  4821. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  4822. mdd_detected = true;
  4823. }
  4824. reg = rd32(hw, I40E_GL_MDET_RX);
  4825. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  4826. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK)
  4827. >> I40E_GL_MDET_RX_FUNCTION_SHIFT;
  4828. u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT)
  4829. >> I40E_GL_MDET_RX_EVENT_SHIFT;
  4830. u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK)
  4831. >> I40E_GL_MDET_RX_QUEUE_SHIFT;
  4832. dev_info(&pf->pdev->dev,
  4833. "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  4834. event, queue, func);
  4835. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  4836. mdd_detected = true;
  4837. }
  4838. /* see if one of the VFs needs its hand slapped */
  4839. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  4840. vf = &(pf->vf[i]);
  4841. reg = rd32(hw, I40E_VP_MDET_TX(i));
  4842. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  4843. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  4844. vf->num_mdd_events++;
  4845. dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i);
  4846. }
  4847. reg = rd32(hw, I40E_VP_MDET_RX(i));
  4848. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  4849. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  4850. vf->num_mdd_events++;
  4851. dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i);
  4852. }
  4853. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  4854. dev_info(&pf->pdev->dev,
  4855. "Too many MDD events on VF %d, disabled\n", i);
  4856. dev_info(&pf->pdev->dev,
  4857. "Use PF Control I/F to re-enable the VF\n");
  4858. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  4859. }
  4860. }
  4861. /* re-enable mdd interrupt cause */
  4862. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  4863. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  4864. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  4865. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  4866. i40e_flush(hw);
  4867. }
  4868. #ifdef CONFIG_I40E_VXLAN
  4869. /**
  4870. * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
  4871. * @pf: board private structure
  4872. **/
  4873. static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf)
  4874. {
  4875. struct i40e_hw *hw = &pf->hw;
  4876. i40e_status ret;
  4877. u8 filter_index;
  4878. __be16 port;
  4879. int i;
  4880. if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC))
  4881. return;
  4882. pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC;
  4883. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  4884. if (pf->pending_vxlan_bitmap & (1 << i)) {
  4885. pf->pending_vxlan_bitmap &= ~(1 << i);
  4886. port = pf->vxlan_ports[i];
  4887. ret = port ?
  4888. i40e_aq_add_udp_tunnel(hw, ntohs(port),
  4889. I40E_AQC_TUNNEL_TYPE_VXLAN,
  4890. &filter_index, NULL)
  4891. : i40e_aq_del_udp_tunnel(hw, i, NULL);
  4892. if (ret) {
  4893. dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n",
  4894. port ? "adding" : "deleting",
  4895. ntohs(port), port ? i : i);
  4896. pf->vxlan_ports[i] = 0;
  4897. } else {
  4898. dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n",
  4899. port ? "Added" : "Deleted",
  4900. ntohs(port), port ? i : filter_index);
  4901. }
  4902. }
  4903. }
  4904. }
  4905. #endif
  4906. /**
  4907. * i40e_service_task - Run the driver's async subtasks
  4908. * @work: pointer to work_struct containing our data
  4909. **/
  4910. static void i40e_service_task(struct work_struct *work)
  4911. {
  4912. struct i40e_pf *pf = container_of(work,
  4913. struct i40e_pf,
  4914. service_task);
  4915. unsigned long start_time = jiffies;
  4916. i40e_reset_subtask(pf);
  4917. i40e_handle_mdd_event(pf);
  4918. i40e_vc_process_vflr_event(pf);
  4919. i40e_watchdog_subtask(pf);
  4920. i40e_fdir_reinit_subtask(pf);
  4921. i40e_check_hang_subtask(pf);
  4922. i40e_sync_filters_subtask(pf);
  4923. #ifdef CONFIG_I40E_VXLAN
  4924. i40e_sync_vxlan_filters_subtask(pf);
  4925. #endif
  4926. i40e_clean_adminq_subtask(pf);
  4927. i40e_service_event_complete(pf);
  4928. /* If the tasks have taken longer than one timer cycle or there
  4929. * is more work to be done, reschedule the service task now
  4930. * rather than wait for the timer to tick again.
  4931. */
  4932. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  4933. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  4934. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  4935. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  4936. i40e_service_event_schedule(pf);
  4937. }
  4938. /**
  4939. * i40e_service_timer - timer callback
  4940. * @data: pointer to PF struct
  4941. **/
  4942. static void i40e_service_timer(unsigned long data)
  4943. {
  4944. struct i40e_pf *pf = (struct i40e_pf *)data;
  4945. mod_timer(&pf->service_timer,
  4946. round_jiffies(jiffies + pf->service_timer_period));
  4947. i40e_service_event_schedule(pf);
  4948. }
  4949. /**
  4950. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  4951. * @vsi: the VSI being configured
  4952. **/
  4953. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  4954. {
  4955. struct i40e_pf *pf = vsi->back;
  4956. switch (vsi->type) {
  4957. case I40E_VSI_MAIN:
  4958. vsi->alloc_queue_pairs = pf->num_lan_qps;
  4959. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  4960. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4961. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4962. vsi->num_q_vectors = pf->num_lan_msix;
  4963. else
  4964. vsi->num_q_vectors = 1;
  4965. break;
  4966. case I40E_VSI_FDIR:
  4967. vsi->alloc_queue_pairs = 1;
  4968. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  4969. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4970. vsi->num_q_vectors = 1;
  4971. break;
  4972. case I40E_VSI_VMDQ2:
  4973. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  4974. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  4975. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4976. vsi->num_q_vectors = pf->num_vmdq_msix;
  4977. break;
  4978. case I40E_VSI_SRIOV:
  4979. vsi->alloc_queue_pairs = pf->num_vf_qps;
  4980. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  4981. I40E_REQ_DESCRIPTOR_MULTIPLE);
  4982. break;
  4983. default:
  4984. WARN_ON(1);
  4985. return -ENODATA;
  4986. }
  4987. return 0;
  4988. }
  4989. /**
  4990. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  4991. * @type: VSI pointer
  4992. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  4993. *
  4994. * On error: returns error code (negative)
  4995. * On success: returns 0
  4996. **/
  4997. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  4998. {
  4999. int size;
  5000. int ret = 0;
  5001. /* allocate memory for both Tx and Rx ring pointers */
  5002. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  5003. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  5004. if (!vsi->tx_rings)
  5005. return -ENOMEM;
  5006. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  5007. if (alloc_qvectors) {
  5008. /* allocate memory for q_vector pointers */
  5009. size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;
  5010. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  5011. if (!vsi->q_vectors) {
  5012. ret = -ENOMEM;
  5013. goto err_vectors;
  5014. }
  5015. }
  5016. return ret;
  5017. err_vectors:
  5018. kfree(vsi->tx_rings);
  5019. return ret;
  5020. }
  5021. /**
  5022. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  5023. * @pf: board private structure
  5024. * @type: type of VSI
  5025. *
  5026. * On error: returns error code (negative)
  5027. * On success: returns vsi index in PF (positive)
  5028. **/
  5029. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  5030. {
  5031. int ret = -ENODEV;
  5032. struct i40e_vsi *vsi;
  5033. int vsi_idx;
  5034. int i;
  5035. /* Need to protect the allocation of the VSIs at the PF level */
  5036. mutex_lock(&pf->switch_mutex);
  5037. /* VSI list may be fragmented if VSI creation/destruction has
  5038. * been happening. We can afford to do a quick scan to look
  5039. * for any free VSIs in the list.
  5040. *
  5041. * find next empty vsi slot, looping back around if necessary
  5042. */
  5043. i = pf->next_vsi;
  5044. while (i < pf->hw.func_caps.num_vsis && pf->vsi[i])
  5045. i++;
  5046. if (i >= pf->hw.func_caps.num_vsis) {
  5047. i = 0;
  5048. while (i < pf->next_vsi && pf->vsi[i])
  5049. i++;
  5050. }
  5051. if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) {
  5052. vsi_idx = i; /* Found one! */
  5053. } else {
  5054. ret = -ENODEV;
  5055. goto unlock_pf; /* out of VSI slots! */
  5056. }
  5057. pf->next_vsi = ++i;
  5058. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  5059. if (!vsi) {
  5060. ret = -ENOMEM;
  5061. goto unlock_pf;
  5062. }
  5063. vsi->type = type;
  5064. vsi->back = pf;
  5065. set_bit(__I40E_DOWN, &vsi->state);
  5066. vsi->flags = 0;
  5067. vsi->idx = vsi_idx;
  5068. vsi->rx_itr_setting = pf->rx_itr_default;
  5069. vsi->tx_itr_setting = pf->tx_itr_default;
  5070. vsi->netdev_registered = false;
  5071. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  5072. INIT_LIST_HEAD(&vsi->mac_filter_list);
  5073. ret = i40e_set_num_rings_in_vsi(vsi);
  5074. if (ret)
  5075. goto err_rings;
  5076. ret = i40e_vsi_alloc_arrays(vsi, true);
  5077. if (ret)
  5078. goto err_rings;
  5079. /* Setup default MSIX irq handler for VSI */
  5080. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  5081. pf->vsi[vsi_idx] = vsi;
  5082. ret = vsi_idx;
  5083. goto unlock_pf;
  5084. err_rings:
  5085. pf->next_vsi = i - 1;
  5086. kfree(vsi);
  5087. unlock_pf:
  5088. mutex_unlock(&pf->switch_mutex);
  5089. return ret;
  5090. }
  5091. /**
  5092. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  5093. * @type: VSI pointer
  5094. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  5095. *
  5096. * On error: returns error code (negative)
  5097. * On success: returns 0
  5098. **/
  5099. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  5100. {
  5101. /* free the ring and vector containers */
  5102. if (free_qvectors) {
  5103. kfree(vsi->q_vectors);
  5104. vsi->q_vectors = NULL;
  5105. }
  5106. kfree(vsi->tx_rings);
  5107. vsi->tx_rings = NULL;
  5108. vsi->rx_rings = NULL;
  5109. }
  5110. /**
  5111. * i40e_vsi_clear - Deallocate the VSI provided
  5112. * @vsi: the VSI being un-configured
  5113. **/
  5114. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  5115. {
  5116. struct i40e_pf *pf;
  5117. if (!vsi)
  5118. return 0;
  5119. if (!vsi->back)
  5120. goto free_vsi;
  5121. pf = vsi->back;
  5122. mutex_lock(&pf->switch_mutex);
  5123. if (!pf->vsi[vsi->idx]) {
  5124. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  5125. vsi->idx, vsi->idx, vsi, vsi->type);
  5126. goto unlock_vsi;
  5127. }
  5128. if (pf->vsi[vsi->idx] != vsi) {
  5129. dev_err(&pf->pdev->dev,
  5130. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  5131. pf->vsi[vsi->idx]->idx,
  5132. pf->vsi[vsi->idx],
  5133. pf->vsi[vsi->idx]->type,
  5134. vsi->idx, vsi, vsi->type);
  5135. goto unlock_vsi;
  5136. }
  5137. /* updates the pf for this cleared vsi */
  5138. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  5139. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  5140. i40e_vsi_free_arrays(vsi, true);
  5141. pf->vsi[vsi->idx] = NULL;
  5142. if (vsi->idx < pf->next_vsi)
  5143. pf->next_vsi = vsi->idx;
  5144. unlock_vsi:
  5145. mutex_unlock(&pf->switch_mutex);
  5146. free_vsi:
  5147. kfree(vsi);
  5148. return 0;
  5149. }
  5150. /**
  5151. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  5152. * @vsi: the VSI being cleaned
  5153. **/
  5154. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  5155. {
  5156. int i;
  5157. if (vsi->tx_rings && vsi->tx_rings[0]) {
  5158. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  5159. kfree_rcu(vsi->tx_rings[i], rcu);
  5160. vsi->tx_rings[i] = NULL;
  5161. vsi->rx_rings[i] = NULL;
  5162. }
  5163. }
  5164. }
  5165. /**
  5166. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  5167. * @vsi: the VSI being configured
  5168. **/
  5169. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  5170. {
  5171. struct i40e_pf *pf = vsi->back;
  5172. int i;
  5173. /* Set basic values in the rings to be used later during open() */
  5174. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  5175. struct i40e_ring *tx_ring;
  5176. struct i40e_ring *rx_ring;
  5177. /* allocate space for both Tx and Rx in one shot */
  5178. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  5179. if (!tx_ring)
  5180. goto err_out;
  5181. tx_ring->queue_index = i;
  5182. tx_ring->reg_idx = vsi->base_queue + i;
  5183. tx_ring->ring_active = false;
  5184. tx_ring->vsi = vsi;
  5185. tx_ring->netdev = vsi->netdev;
  5186. tx_ring->dev = &pf->pdev->dev;
  5187. tx_ring->count = vsi->num_desc;
  5188. tx_ring->size = 0;
  5189. tx_ring->dcb_tc = 0;
  5190. vsi->tx_rings[i] = tx_ring;
  5191. rx_ring = &tx_ring[1];
  5192. rx_ring->queue_index = i;
  5193. rx_ring->reg_idx = vsi->base_queue + i;
  5194. rx_ring->ring_active = false;
  5195. rx_ring->vsi = vsi;
  5196. rx_ring->netdev = vsi->netdev;
  5197. rx_ring->dev = &pf->pdev->dev;
  5198. rx_ring->count = vsi->num_desc;
  5199. rx_ring->size = 0;
  5200. rx_ring->dcb_tc = 0;
  5201. if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
  5202. set_ring_16byte_desc_enabled(rx_ring);
  5203. else
  5204. clear_ring_16byte_desc_enabled(rx_ring);
  5205. vsi->rx_rings[i] = rx_ring;
  5206. }
  5207. return 0;
  5208. err_out:
  5209. i40e_vsi_clear_rings(vsi);
  5210. return -ENOMEM;
  5211. }
  5212. /**
  5213. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  5214. * @pf: board private structure
  5215. * @vectors: the number of MSI-X vectors to request
  5216. *
  5217. * Returns the number of vectors reserved, or error
  5218. **/
  5219. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  5220. {
  5221. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  5222. I40E_MIN_MSIX, vectors);
  5223. if (vectors < 0) {
  5224. dev_info(&pf->pdev->dev,
  5225. "MSI-X vector reservation failed: %d\n", vectors);
  5226. vectors = 0;
  5227. }
  5228. pf->num_msix_entries = vectors;
  5229. return vectors;
  5230. }
  5231. /**
  5232. * i40e_init_msix - Setup the MSIX capability
  5233. * @pf: board private structure
  5234. *
  5235. * Work with the OS to set up the MSIX vectors needed.
  5236. *
  5237. * Returns 0 on success, negative on failure
  5238. **/
  5239. static int i40e_init_msix(struct i40e_pf *pf)
  5240. {
  5241. i40e_status err = 0;
  5242. struct i40e_hw *hw = &pf->hw;
  5243. int v_budget, i;
  5244. int vec;
  5245. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5246. return -ENODEV;
  5247. /* The number of vectors we'll request will be comprised of:
  5248. * - Add 1 for "other" cause for Admin Queue events, etc.
  5249. * - The number of LAN queue pairs
  5250. * - Queues being used for RSS.
  5251. * We don't need as many as max_rss_size vectors.
  5252. * use rss_size instead in the calculation since that
  5253. * is governed by number of cpus in the system.
  5254. * - assumes symmetric Tx/Rx pairing
  5255. * - The number of VMDq pairs
  5256. * Once we count this up, try the request.
  5257. *
  5258. * If we can't get what we want, we'll simplify to nearly nothing
  5259. * and try again. If that still fails, we punt.
  5260. */
  5261. pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size);
  5262. pf->num_vmdq_msix = pf->num_vmdq_qps;
  5263. v_budget = 1 + pf->num_lan_msix;
  5264. v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix);
  5265. if (pf->flags & I40E_FLAG_FD_SB_ENABLED)
  5266. v_budget++;
  5267. /* Scale down if necessary, and the rings will share vectors */
  5268. v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors);
  5269. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  5270. GFP_KERNEL);
  5271. if (!pf->msix_entries)
  5272. return -ENOMEM;
  5273. for (i = 0; i < v_budget; i++)
  5274. pf->msix_entries[i].entry = i;
  5275. vec = i40e_reserve_msix_vectors(pf, v_budget);
  5276. if (vec < I40E_MIN_MSIX) {
  5277. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  5278. kfree(pf->msix_entries);
  5279. pf->msix_entries = NULL;
  5280. return -ENODEV;
  5281. } else if (vec == I40E_MIN_MSIX) {
  5282. /* Adjust for minimal MSIX use */
  5283. dev_info(&pf->pdev->dev, "Features disabled, not enough MSI-X vectors\n");
  5284. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  5285. pf->num_vmdq_vsis = 0;
  5286. pf->num_vmdq_qps = 0;
  5287. pf->num_vmdq_msix = 0;
  5288. pf->num_lan_qps = 1;
  5289. pf->num_lan_msix = 1;
  5290. } else if (vec != v_budget) {
  5291. /* Scale vector usage down */
  5292. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  5293. vec--; /* reserve the misc vector */
  5294. /* partition out the remaining vectors */
  5295. switch (vec) {
  5296. case 2:
  5297. pf->num_vmdq_vsis = 1;
  5298. pf->num_lan_msix = 1;
  5299. break;
  5300. case 3:
  5301. pf->num_vmdq_vsis = 1;
  5302. pf->num_lan_msix = 2;
  5303. break;
  5304. default:
  5305. pf->num_lan_msix = min_t(int, (vec / 2),
  5306. pf->num_lan_qps);
  5307. pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix),
  5308. I40E_DEFAULT_NUM_VMDQ_VSI);
  5309. break;
  5310. }
  5311. }
  5312. return err;
  5313. }
  5314. /**
  5315. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  5316. * @vsi: the VSI being configured
  5317. * @v_idx: index of the vector in the vsi struct
  5318. *
  5319. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  5320. **/
  5321. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
  5322. {
  5323. struct i40e_q_vector *q_vector;
  5324. /* allocate q_vector */
  5325. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  5326. if (!q_vector)
  5327. return -ENOMEM;
  5328. q_vector->vsi = vsi;
  5329. q_vector->v_idx = v_idx;
  5330. cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
  5331. if (vsi->netdev)
  5332. netif_napi_add(vsi->netdev, &q_vector->napi,
  5333. i40e_napi_poll, vsi->work_limit);
  5334. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  5335. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  5336. /* tie q_vector and vsi together */
  5337. vsi->q_vectors[v_idx] = q_vector;
  5338. return 0;
  5339. }
  5340. /**
  5341. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  5342. * @vsi: the VSI being configured
  5343. *
  5344. * We allocate one q_vector per queue interrupt. If allocation fails we
  5345. * return -ENOMEM.
  5346. **/
  5347. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  5348. {
  5349. struct i40e_pf *pf = vsi->back;
  5350. int v_idx, num_q_vectors;
  5351. int err;
  5352. /* if not MSIX, give the one vector only to the LAN VSI */
  5353. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5354. num_q_vectors = vsi->num_q_vectors;
  5355. else if (vsi == pf->vsi[pf->lan_vsi])
  5356. num_q_vectors = 1;
  5357. else
  5358. return -EINVAL;
  5359. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  5360. err = i40e_vsi_alloc_q_vector(vsi, v_idx);
  5361. if (err)
  5362. goto err_out;
  5363. }
  5364. return 0;
  5365. err_out:
  5366. while (v_idx--)
  5367. i40e_free_q_vector(vsi, v_idx);
  5368. return err;
  5369. }
  5370. /**
  5371. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  5372. * @pf: board private structure to initialize
  5373. **/
  5374. static void i40e_init_interrupt_scheme(struct i40e_pf *pf)
  5375. {
  5376. int err = 0;
  5377. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  5378. err = i40e_init_msix(pf);
  5379. if (err) {
  5380. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  5381. I40E_FLAG_RSS_ENABLED |
  5382. I40E_FLAG_DCB_ENABLED |
  5383. I40E_FLAG_SRIOV_ENABLED |
  5384. I40E_FLAG_FD_SB_ENABLED |
  5385. I40E_FLAG_FD_ATR_ENABLED |
  5386. I40E_FLAG_VMDQ_ENABLED);
  5387. /* rework the queue expectations without MSIX */
  5388. i40e_determine_queue_usage(pf);
  5389. }
  5390. }
  5391. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  5392. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  5393. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  5394. err = pci_enable_msi(pf->pdev);
  5395. if (err) {
  5396. dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err);
  5397. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  5398. }
  5399. }
  5400. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  5401. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  5402. /* track first vector for misc interrupts */
  5403. err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1);
  5404. }
  5405. /**
  5406. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  5407. * @pf: board private structure
  5408. *
  5409. * This sets up the handler for MSIX 0, which is used to manage the
  5410. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  5411. * when in MSI or Legacy interrupt mode.
  5412. **/
  5413. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  5414. {
  5415. struct i40e_hw *hw = &pf->hw;
  5416. int err = 0;
  5417. /* Only request the irq if this is the first time through, and
  5418. * not when we're rebuilding after a Reset
  5419. */
  5420. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  5421. err = request_irq(pf->msix_entries[0].vector,
  5422. i40e_intr, 0, pf->misc_int_name, pf);
  5423. if (err) {
  5424. dev_info(&pf->pdev->dev,
  5425. "request_irq for %s failed: %d\n",
  5426. pf->misc_int_name, err);
  5427. return -EFAULT;
  5428. }
  5429. }
  5430. i40e_enable_misc_int_causes(hw);
  5431. /* associate no queues to the misc vector */
  5432. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  5433. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  5434. i40e_flush(hw);
  5435. i40e_irq_dynamic_enable_icr0(pf);
  5436. return err;
  5437. }
  5438. /**
  5439. * i40e_config_rss - Prepare for RSS if used
  5440. * @pf: board private structure
  5441. **/
  5442. static int i40e_config_rss(struct i40e_pf *pf)
  5443. {
  5444. /* Set of random keys generated using kernel random number generator */
  5445. static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687,
  5446. 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
  5447. 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
  5448. 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
  5449. struct i40e_hw *hw = &pf->hw;
  5450. u32 lut = 0;
  5451. int i, j;
  5452. u64 hena;
  5453. /* Fill out hash function seed */
  5454. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  5455. wr32(hw, I40E_PFQF_HKEY(i), seed[i]);
  5456. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  5457. hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  5458. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  5459. hena |= I40E_DEFAULT_RSS_HENA;
  5460. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  5461. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  5462. /* Populate the LUT with max no. of queues in round robin fashion */
  5463. for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) {
  5464. /* The assumption is that lan qp count will be the highest
  5465. * qp count for any PF VSI that needs RSS.
  5466. * If multiple VSIs need RSS support, all the qp counts
  5467. * for those VSIs should be a power of 2 for RSS to work.
  5468. * If LAN VSI is the only consumer for RSS then this requirement
  5469. * is not necessary.
  5470. */
  5471. if (j == pf->rss_size)
  5472. j = 0;
  5473. /* lut = 4-byte sliding window of 4 lut entries */
  5474. lut = (lut << 8) | (j &
  5475. ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1));
  5476. /* On i = 3, we have 4 entries in lut; write to the register */
  5477. if ((i & 3) == 3)
  5478. wr32(hw, I40E_PFQF_HLUT(i >> 2), lut);
  5479. }
  5480. i40e_flush(hw);
  5481. return 0;
  5482. }
  5483. /**
  5484. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  5485. * @pf: board private structure
  5486. * @queue_count: the requested queue count for rss.
  5487. *
  5488. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  5489. * count which may be different from the requested queue count.
  5490. **/
  5491. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  5492. {
  5493. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  5494. return 0;
  5495. queue_count = min_t(int, queue_count, pf->rss_size_max);
  5496. queue_count = rounddown_pow_of_two(queue_count);
  5497. if (queue_count != pf->rss_size) {
  5498. i40e_prep_for_reset(pf);
  5499. pf->rss_size = queue_count;
  5500. i40e_reset_and_rebuild(pf, true);
  5501. i40e_config_rss(pf);
  5502. }
  5503. dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size);
  5504. return pf->rss_size;
  5505. }
  5506. /**
  5507. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  5508. * @pf: board private structure to initialize
  5509. *
  5510. * i40e_sw_init initializes the Adapter private data structure.
  5511. * Fields are initialized based on PCI device information and
  5512. * OS network device settings (MTU size).
  5513. **/
  5514. static int i40e_sw_init(struct i40e_pf *pf)
  5515. {
  5516. int err = 0;
  5517. int size;
  5518. pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
  5519. (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
  5520. pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
  5521. if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
  5522. if (I40E_DEBUG_USER & debug)
  5523. pf->hw.debug_mask = debug;
  5524. pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
  5525. I40E_DEFAULT_MSG_ENABLE);
  5526. }
  5527. /* Set default capability flags */
  5528. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  5529. I40E_FLAG_MSI_ENABLED |
  5530. I40E_FLAG_MSIX_ENABLED |
  5531. I40E_FLAG_RX_1BUF_ENABLED;
  5532. /* Depending on PF configurations, it is possible that the RSS
  5533. * maximum might end up larger than the available queues
  5534. */
  5535. pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width;
  5536. pf->rss_size_max = min_t(int, pf->rss_size_max,
  5537. pf->hw.func_caps.num_tx_qp);
  5538. if (pf->hw.func_caps.rss) {
  5539. pf->flags |= I40E_FLAG_RSS_ENABLED;
  5540. pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus());
  5541. pf->rss_size = rounddown_pow_of_two(pf->rss_size);
  5542. } else {
  5543. pf->rss_size = 1;
  5544. }
  5545. /* MFP mode enabled */
  5546. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) {
  5547. pf->flags |= I40E_FLAG_MFP_ENABLED;
  5548. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  5549. }
  5550. /* FW/NVM is not yet fixed in this regard */
  5551. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  5552. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  5553. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  5554. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  5555. if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  5556. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  5557. } else {
  5558. dev_info(&pf->pdev->dev,
  5559. "Flow Director Sideband mode Disabled in MFP mode\n");
  5560. }
  5561. pf->fdir_pf_filter_count =
  5562. pf->hw.func_caps.fd_filters_guaranteed;
  5563. pf->hw.fdir_shared_filter_count =
  5564. pf->hw.func_caps.fd_filters_best_effort;
  5565. }
  5566. if (pf->hw.func_caps.vmdq) {
  5567. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  5568. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  5569. pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ;
  5570. }
  5571. #ifdef CONFIG_PCI_IOV
  5572. if (pf->hw.func_caps.num_vfs) {
  5573. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  5574. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  5575. pf->num_req_vfs = min_t(int,
  5576. pf->hw.func_caps.num_vfs,
  5577. I40E_MAX_VF_COUNT);
  5578. }
  5579. #endif /* CONFIG_PCI_IOV */
  5580. pf->eeprom_version = 0xDEAD;
  5581. pf->lan_veb = I40E_NO_VEB;
  5582. pf->lan_vsi = I40E_NO_VSI;
  5583. /* set up queue assignment tracking */
  5584. size = sizeof(struct i40e_lump_tracking)
  5585. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  5586. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  5587. if (!pf->qp_pile) {
  5588. err = -ENOMEM;
  5589. goto sw_init_done;
  5590. }
  5591. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  5592. pf->qp_pile->search_hint = 0;
  5593. /* set up vector assignment tracking */
  5594. size = sizeof(struct i40e_lump_tracking)
  5595. + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors);
  5596. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  5597. if (!pf->irq_pile) {
  5598. kfree(pf->qp_pile);
  5599. err = -ENOMEM;
  5600. goto sw_init_done;
  5601. }
  5602. pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors;
  5603. pf->irq_pile->search_hint = 0;
  5604. mutex_init(&pf->switch_mutex);
  5605. sw_init_done:
  5606. return err;
  5607. }
  5608. /**
  5609. * i40e_set_ntuple - set the ntuple feature flag and take action
  5610. * @pf: board private structure to initialize
  5611. * @features: the feature set that the stack is suggesting
  5612. *
  5613. * returns a bool to indicate if reset needs to happen
  5614. **/
  5615. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  5616. {
  5617. bool need_reset = false;
  5618. /* Check if Flow Director n-tuple support was enabled or disabled. If
  5619. * the state changed, we need to reset.
  5620. */
  5621. if (features & NETIF_F_NTUPLE) {
  5622. /* Enable filters and mark for reset */
  5623. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  5624. need_reset = true;
  5625. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  5626. } else {
  5627. /* turn off filters, mark for reset and clear SW filter list */
  5628. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  5629. need_reset = true;
  5630. i40e_fdir_filter_exit(pf);
  5631. }
  5632. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5633. /* if ATR was disabled it can be re-enabled. */
  5634. if (!(pf->flags & I40E_FLAG_FD_ATR_ENABLED))
  5635. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  5636. }
  5637. return need_reset;
  5638. }
  5639. /**
  5640. * i40e_set_features - set the netdev feature flags
  5641. * @netdev: ptr to the netdev being adjusted
  5642. * @features: the feature set that the stack is suggesting
  5643. **/
  5644. static int i40e_set_features(struct net_device *netdev,
  5645. netdev_features_t features)
  5646. {
  5647. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5648. struct i40e_vsi *vsi = np->vsi;
  5649. struct i40e_pf *pf = vsi->back;
  5650. bool need_reset;
  5651. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  5652. i40e_vlan_stripping_enable(vsi);
  5653. else
  5654. i40e_vlan_stripping_disable(vsi);
  5655. need_reset = i40e_set_ntuple(pf, features);
  5656. if (need_reset)
  5657. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  5658. return 0;
  5659. }
  5660. #ifdef CONFIG_I40E_VXLAN
  5661. /**
  5662. * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
  5663. * @pf: board private structure
  5664. * @port: The UDP port to look up
  5665. *
  5666. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  5667. **/
  5668. static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port)
  5669. {
  5670. u8 i;
  5671. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  5672. if (pf->vxlan_ports[i] == port)
  5673. return i;
  5674. }
  5675. return i;
  5676. }
  5677. /**
  5678. * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
  5679. * @netdev: This physical port's netdev
  5680. * @sa_family: Socket Family that VXLAN is notifying us about
  5681. * @port: New UDP port number that VXLAN started listening to
  5682. **/
  5683. static void i40e_add_vxlan_port(struct net_device *netdev,
  5684. sa_family_t sa_family, __be16 port)
  5685. {
  5686. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5687. struct i40e_vsi *vsi = np->vsi;
  5688. struct i40e_pf *pf = vsi->back;
  5689. u8 next_idx;
  5690. u8 idx;
  5691. if (sa_family == AF_INET6)
  5692. return;
  5693. idx = i40e_get_vxlan_port_idx(pf, port);
  5694. /* Check if port already exists */
  5695. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  5696. netdev_info(netdev, "Port %d already offloaded\n", ntohs(port));
  5697. return;
  5698. }
  5699. /* Now check if there is space to add the new port */
  5700. next_idx = i40e_get_vxlan_port_idx(pf, 0);
  5701. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  5702. netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n",
  5703. ntohs(port));
  5704. return;
  5705. }
  5706. /* New port: add it and mark its index in the bitmap */
  5707. pf->vxlan_ports[next_idx] = port;
  5708. pf->pending_vxlan_bitmap |= (1 << next_idx);
  5709. pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
  5710. }
  5711. /**
  5712. * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
  5713. * @netdev: This physical port's netdev
  5714. * @sa_family: Socket Family that VXLAN is notifying us about
  5715. * @port: UDP port number that VXLAN stopped listening to
  5716. **/
  5717. static void i40e_del_vxlan_port(struct net_device *netdev,
  5718. sa_family_t sa_family, __be16 port)
  5719. {
  5720. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5721. struct i40e_vsi *vsi = np->vsi;
  5722. struct i40e_pf *pf = vsi->back;
  5723. u8 idx;
  5724. if (sa_family == AF_INET6)
  5725. return;
  5726. idx = i40e_get_vxlan_port_idx(pf, port);
  5727. /* Check if port already exists */
  5728. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  5729. /* if port exists, set it to 0 (mark for deletion)
  5730. * and make it pending
  5731. */
  5732. pf->vxlan_ports[idx] = 0;
  5733. pf->pending_vxlan_bitmap |= (1 << idx);
  5734. pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
  5735. } else {
  5736. netdev_warn(netdev, "Port %d was not found, not deleting\n",
  5737. ntohs(port));
  5738. }
  5739. }
  5740. #endif
  5741. #ifdef HAVE_FDB_OPS
  5742. #ifdef USE_CONST_DEV_UC_CHAR
  5743. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  5744. struct net_device *dev,
  5745. const unsigned char *addr,
  5746. u16 flags)
  5747. #else
  5748. static int i40e_ndo_fdb_add(struct ndmsg *ndm,
  5749. struct net_device *dev,
  5750. unsigned char *addr,
  5751. u16 flags)
  5752. #endif
  5753. {
  5754. struct i40e_netdev_priv *np = netdev_priv(dev);
  5755. struct i40e_pf *pf = np->vsi->back;
  5756. int err = 0;
  5757. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  5758. return -EOPNOTSUPP;
  5759. /* Hardware does not support aging addresses so if a
  5760. * ndm_state is given only allow permanent addresses
  5761. */
  5762. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  5763. netdev_info(dev, "FDB only supports static addresses\n");
  5764. return -EINVAL;
  5765. }
  5766. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  5767. err = dev_uc_add_excl(dev, addr);
  5768. else if (is_multicast_ether_addr(addr))
  5769. err = dev_mc_add_excl(dev, addr);
  5770. else
  5771. err = -EINVAL;
  5772. /* Only return duplicate errors if NLM_F_EXCL is set */
  5773. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  5774. err = 0;
  5775. return err;
  5776. }
  5777. #ifndef USE_DEFAULT_FDB_DEL_DUMP
  5778. #ifdef USE_CONST_DEV_UC_CHAR
  5779. static int i40e_ndo_fdb_del(struct ndmsg *ndm,
  5780. struct net_device *dev,
  5781. const unsigned char *addr)
  5782. #else
  5783. static int i40e_ndo_fdb_del(struct ndmsg *ndm,
  5784. struct net_device *dev,
  5785. unsigned char *addr)
  5786. #endif
  5787. {
  5788. struct i40e_netdev_priv *np = netdev_priv(dev);
  5789. struct i40e_pf *pf = np->vsi->back;
  5790. int err = -EOPNOTSUPP;
  5791. if (ndm->ndm_state & NUD_PERMANENT) {
  5792. netdev_info(dev, "FDB only supports static addresses\n");
  5793. return -EINVAL;
  5794. }
  5795. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  5796. if (is_unicast_ether_addr(addr))
  5797. err = dev_uc_del(dev, addr);
  5798. else if (is_multicast_ether_addr(addr))
  5799. err = dev_mc_del(dev, addr);
  5800. else
  5801. err = -EINVAL;
  5802. }
  5803. return err;
  5804. }
  5805. static int i40e_ndo_fdb_dump(struct sk_buff *skb,
  5806. struct netlink_callback *cb,
  5807. struct net_device *dev,
  5808. int idx)
  5809. {
  5810. struct i40e_netdev_priv *np = netdev_priv(dev);
  5811. struct i40e_pf *pf = np->vsi->back;
  5812. if (pf->flags & I40E_FLAG_SRIOV_ENABLED)
  5813. idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
  5814. return idx;
  5815. }
  5816. #endif /* USE_DEFAULT_FDB_DEL_DUMP */
  5817. #endif /* HAVE_FDB_OPS */
  5818. static const struct net_device_ops i40e_netdev_ops = {
  5819. .ndo_open = i40e_open,
  5820. .ndo_stop = i40e_close,
  5821. .ndo_start_xmit = i40e_lan_xmit_frame,
  5822. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  5823. .ndo_set_rx_mode = i40e_set_rx_mode,
  5824. .ndo_validate_addr = eth_validate_addr,
  5825. .ndo_set_mac_address = i40e_set_mac,
  5826. .ndo_change_mtu = i40e_change_mtu,
  5827. .ndo_do_ioctl = i40e_ioctl,
  5828. .ndo_tx_timeout = i40e_tx_timeout,
  5829. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  5830. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  5831. #ifdef CONFIG_NET_POLL_CONTROLLER
  5832. .ndo_poll_controller = i40e_netpoll,
  5833. #endif
  5834. .ndo_setup_tc = i40e_setup_tc,
  5835. .ndo_set_features = i40e_set_features,
  5836. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  5837. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  5838. .ndo_set_vf_tx_rate = i40e_ndo_set_vf_bw,
  5839. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  5840. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  5841. #ifdef CONFIG_I40E_VXLAN
  5842. .ndo_add_vxlan_port = i40e_add_vxlan_port,
  5843. .ndo_del_vxlan_port = i40e_del_vxlan_port,
  5844. #endif
  5845. #ifdef HAVE_FDB_OPS
  5846. .ndo_fdb_add = i40e_ndo_fdb_add,
  5847. #ifndef USE_DEFAULT_FDB_DEL_DUMP
  5848. .ndo_fdb_del = i40e_ndo_fdb_del,
  5849. .ndo_fdb_dump = i40e_ndo_fdb_dump,
  5850. #endif
  5851. #endif
  5852. };
  5853. /**
  5854. * i40e_config_netdev - Setup the netdev flags
  5855. * @vsi: the VSI being configured
  5856. *
  5857. * Returns 0 on success, negative value on failure
  5858. **/
  5859. static int i40e_config_netdev(struct i40e_vsi *vsi)
  5860. {
  5861. u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  5862. struct i40e_pf *pf = vsi->back;
  5863. struct i40e_hw *hw = &pf->hw;
  5864. struct i40e_netdev_priv *np;
  5865. struct net_device *netdev;
  5866. u8 mac_addr[ETH_ALEN];
  5867. int etherdev_size;
  5868. etherdev_size = sizeof(struct i40e_netdev_priv);
  5869. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  5870. if (!netdev)
  5871. return -ENOMEM;
  5872. vsi->netdev = netdev;
  5873. np = netdev_priv(netdev);
  5874. np->vsi = vsi;
  5875. netdev->hw_enc_features |= NETIF_F_IP_CSUM |
  5876. NETIF_F_GSO_UDP_TUNNEL |
  5877. NETIF_F_TSO;
  5878. netdev->features = NETIF_F_SG |
  5879. NETIF_F_IP_CSUM |
  5880. NETIF_F_SCTP_CSUM |
  5881. NETIF_F_HIGHDMA |
  5882. NETIF_F_GSO_UDP_TUNNEL |
  5883. NETIF_F_HW_VLAN_CTAG_TX |
  5884. NETIF_F_HW_VLAN_CTAG_RX |
  5885. NETIF_F_HW_VLAN_CTAG_FILTER |
  5886. NETIF_F_IPV6_CSUM |
  5887. NETIF_F_TSO |
  5888. NETIF_F_TSO_ECN |
  5889. NETIF_F_TSO6 |
  5890. NETIF_F_RXCSUM |
  5891. NETIF_F_RXHASH |
  5892. 0;
  5893. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  5894. netdev->features |= NETIF_F_NTUPLE;
  5895. /* copy netdev features into list of user selectable features */
  5896. netdev->hw_features |= netdev->features;
  5897. if (vsi->type == I40E_VSI_MAIN) {
  5898. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  5899. memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN);
  5900. } else {
  5901. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  5902. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  5903. pf->vsi[pf->lan_vsi]->netdev->name);
  5904. random_ether_addr(mac_addr);
  5905. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
  5906. }
  5907. i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
  5908. memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
  5909. memcpy(netdev->perm_addr, mac_addr, ETH_ALEN);
  5910. /* vlan gets same features (except vlan offload)
  5911. * after any tweaks for specific VSI types
  5912. */
  5913. netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
  5914. NETIF_F_HW_VLAN_CTAG_RX |
  5915. NETIF_F_HW_VLAN_CTAG_FILTER);
  5916. netdev->priv_flags |= IFF_UNICAST_FLT;
  5917. netdev->priv_flags |= IFF_SUPP_NOFCS;
  5918. /* Setup netdev TC information */
  5919. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  5920. netdev->netdev_ops = &i40e_netdev_ops;
  5921. netdev->watchdog_timeo = 5 * HZ;
  5922. i40e_set_ethtool_ops(netdev);
  5923. return 0;
  5924. }
  5925. /**
  5926. * i40e_vsi_delete - Delete a VSI from the switch
  5927. * @vsi: the VSI being removed
  5928. *
  5929. * Returns 0 on success, negative value on failure
  5930. **/
  5931. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  5932. {
  5933. /* remove default VSI is not allowed */
  5934. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  5935. return;
  5936. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  5937. return;
  5938. }
  5939. /**
  5940. * i40e_add_vsi - Add a VSI to the switch
  5941. * @vsi: the VSI being configured
  5942. *
  5943. * This initializes a VSI context depending on the VSI type to be added and
  5944. * passes it down to the add_vsi aq command.
  5945. **/
  5946. static int i40e_add_vsi(struct i40e_vsi *vsi)
  5947. {
  5948. int ret = -ENODEV;
  5949. struct i40e_mac_filter *f, *ftmp;
  5950. struct i40e_pf *pf = vsi->back;
  5951. struct i40e_hw *hw = &pf->hw;
  5952. struct i40e_vsi_context ctxt;
  5953. u8 enabled_tc = 0x1; /* TC0 enabled */
  5954. int f_count = 0;
  5955. memset(&ctxt, 0, sizeof(ctxt));
  5956. switch (vsi->type) {
  5957. case I40E_VSI_MAIN:
  5958. /* The PF's main VSI is already setup as part of the
  5959. * device initialization, so we'll not bother with
  5960. * the add_vsi call, but we will retrieve the current
  5961. * VSI context.
  5962. */
  5963. ctxt.seid = pf->main_vsi_seid;
  5964. ctxt.pf_num = pf->hw.pf_id;
  5965. ctxt.vf_num = 0;
  5966. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5967. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5968. if (ret) {
  5969. dev_info(&pf->pdev->dev,
  5970. "couldn't get pf vsi config, err %d, aq_err %d\n",
  5971. ret, pf->hw.aq.asq_last_status);
  5972. return -ENOENT;
  5973. }
  5974. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  5975. vsi->info.valid_sections = 0;
  5976. vsi->seid = ctxt.seid;
  5977. vsi->id = ctxt.vsi_number;
  5978. enabled_tc = i40e_pf_get_tc_map(pf);
  5979. /* MFP mode setup queue map and update VSI */
  5980. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  5981. memset(&ctxt, 0, sizeof(ctxt));
  5982. ctxt.seid = pf->main_vsi_seid;
  5983. ctxt.pf_num = pf->hw.pf_id;
  5984. ctxt.vf_num = 0;
  5985. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  5986. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  5987. if (ret) {
  5988. dev_info(&pf->pdev->dev,
  5989. "update vsi failed, aq_err=%d\n",
  5990. pf->hw.aq.asq_last_status);
  5991. ret = -ENOENT;
  5992. goto err;
  5993. }
  5994. /* update the local VSI info queue map */
  5995. i40e_vsi_update_queue_map(vsi, &ctxt);
  5996. vsi->info.valid_sections = 0;
  5997. } else {
  5998. /* Default/Main VSI is only enabled for TC0
  5999. * reconfigure it to enable all TCs that are
  6000. * available on the port in SFP mode.
  6001. */
  6002. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  6003. if (ret) {
  6004. dev_info(&pf->pdev->dev,
  6005. "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
  6006. enabled_tc, ret,
  6007. pf->hw.aq.asq_last_status);
  6008. ret = -ENOENT;
  6009. }
  6010. }
  6011. break;
  6012. case I40E_VSI_FDIR:
  6013. ctxt.pf_num = hw->pf_id;
  6014. ctxt.vf_num = 0;
  6015. ctxt.uplink_seid = vsi->uplink_seid;
  6016. ctxt.connection_type = 0x1; /* regular data port */
  6017. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  6018. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6019. break;
  6020. case I40E_VSI_VMDQ2:
  6021. ctxt.pf_num = hw->pf_id;
  6022. ctxt.vf_num = 0;
  6023. ctxt.uplink_seid = vsi->uplink_seid;
  6024. ctxt.connection_type = 0x1; /* regular data port */
  6025. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  6026. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  6027. /* This VSI is connected to VEB so the switch_id
  6028. * should be set to zero by default.
  6029. */
  6030. ctxt.info.switch_id = 0;
  6031. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  6032. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  6033. /* Setup the VSI tx/rx queue map for TC0 only for now */
  6034. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6035. break;
  6036. case I40E_VSI_SRIOV:
  6037. ctxt.pf_num = hw->pf_id;
  6038. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  6039. ctxt.uplink_seid = vsi->uplink_seid;
  6040. ctxt.connection_type = 0x1; /* regular data port */
  6041. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  6042. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  6043. /* This VSI is connected to VEB so the switch_id
  6044. * should be set to zero by default.
  6045. */
  6046. ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  6047. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  6048. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  6049. /* Setup the VSI tx/rx queue map for TC0 only for now */
  6050. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6051. break;
  6052. default:
  6053. return -ENODEV;
  6054. }
  6055. if (vsi->type != I40E_VSI_MAIN) {
  6056. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  6057. if (ret) {
  6058. dev_info(&vsi->back->pdev->dev,
  6059. "add vsi failed, aq_err=%d\n",
  6060. vsi->back->hw.aq.asq_last_status);
  6061. ret = -ENOENT;
  6062. goto err;
  6063. }
  6064. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  6065. vsi->info.valid_sections = 0;
  6066. vsi->seid = ctxt.seid;
  6067. vsi->id = ctxt.vsi_number;
  6068. }
  6069. /* If macvlan filters already exist, force them to get loaded */
  6070. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  6071. f->changed = true;
  6072. f_count++;
  6073. }
  6074. if (f_count) {
  6075. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  6076. pf->flags |= I40E_FLAG_FILTER_SYNC;
  6077. }
  6078. /* Update VSI BW information */
  6079. ret = i40e_vsi_get_bw_info(vsi);
  6080. if (ret) {
  6081. dev_info(&pf->pdev->dev,
  6082. "couldn't get vsi bw info, err %d, aq_err %d\n",
  6083. ret, pf->hw.aq.asq_last_status);
  6084. /* VSI is already added so not tearing that up */
  6085. ret = 0;
  6086. }
  6087. err:
  6088. return ret;
  6089. }
  6090. /**
  6091. * i40e_vsi_release - Delete a VSI and free its resources
  6092. * @vsi: the VSI being removed
  6093. *
  6094. * Returns 0 on success or < 0 on error
  6095. **/
  6096. int i40e_vsi_release(struct i40e_vsi *vsi)
  6097. {
  6098. struct i40e_mac_filter *f, *ftmp;
  6099. struct i40e_veb *veb = NULL;
  6100. struct i40e_pf *pf;
  6101. u16 uplink_seid;
  6102. int i, n;
  6103. pf = vsi->back;
  6104. /* release of a VEB-owner or last VSI is not allowed */
  6105. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  6106. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  6107. vsi->seid, vsi->uplink_seid);
  6108. return -ENODEV;
  6109. }
  6110. if (vsi == pf->vsi[pf->lan_vsi] &&
  6111. !test_bit(__I40E_DOWN, &pf->state)) {
  6112. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  6113. return -ENODEV;
  6114. }
  6115. uplink_seid = vsi->uplink_seid;
  6116. if (vsi->type != I40E_VSI_SRIOV) {
  6117. if (vsi->netdev_registered) {
  6118. vsi->netdev_registered = false;
  6119. if (vsi->netdev) {
  6120. /* results in a call to i40e_close() */
  6121. unregister_netdev(vsi->netdev);
  6122. }
  6123. } else {
  6124. i40e_vsi_close(vsi);
  6125. }
  6126. i40e_vsi_disable_irq(vsi);
  6127. }
  6128. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  6129. i40e_del_filter(vsi, f->macaddr, f->vlan,
  6130. f->is_vf, f->is_netdev);
  6131. i40e_sync_vsi_filters(vsi);
  6132. i40e_vsi_delete(vsi);
  6133. i40e_vsi_free_q_vectors(vsi);
  6134. if (vsi->netdev) {
  6135. free_netdev(vsi->netdev);
  6136. vsi->netdev = NULL;
  6137. }
  6138. i40e_vsi_clear_rings(vsi);
  6139. i40e_vsi_clear(vsi);
  6140. /* If this was the last thing on the VEB, except for the
  6141. * controlling VSI, remove the VEB, which puts the controlling
  6142. * VSI onto the next level down in the switch.
  6143. *
  6144. * Well, okay, there's one more exception here: don't remove
  6145. * the orphan VEBs yet. We'll wait for an explicit remove request
  6146. * from up the network stack.
  6147. */
  6148. for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  6149. if (pf->vsi[i] &&
  6150. pf->vsi[i]->uplink_seid == uplink_seid &&
  6151. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  6152. n++; /* count the VSIs */
  6153. }
  6154. }
  6155. for (i = 0; i < I40E_MAX_VEB; i++) {
  6156. if (!pf->veb[i])
  6157. continue;
  6158. if (pf->veb[i]->uplink_seid == uplink_seid)
  6159. n++; /* count the VEBs */
  6160. if (pf->veb[i]->seid == uplink_seid)
  6161. veb = pf->veb[i];
  6162. }
  6163. if (n == 0 && veb && veb->uplink_seid != 0)
  6164. i40e_veb_release(veb);
  6165. return 0;
  6166. }
  6167. /**
  6168. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  6169. * @vsi: ptr to the VSI
  6170. *
  6171. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  6172. * corresponding SW VSI structure and initializes num_queue_pairs for the
  6173. * newly allocated VSI.
  6174. *
  6175. * Returns 0 on success or negative on failure
  6176. **/
  6177. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  6178. {
  6179. int ret = -ENOENT;
  6180. struct i40e_pf *pf = vsi->back;
  6181. if (vsi->q_vectors[0]) {
  6182. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  6183. vsi->seid);
  6184. return -EEXIST;
  6185. }
  6186. if (vsi->base_vector) {
  6187. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  6188. vsi->seid, vsi->base_vector);
  6189. return -EEXIST;
  6190. }
  6191. ret = i40e_vsi_alloc_q_vectors(vsi);
  6192. if (ret) {
  6193. dev_info(&pf->pdev->dev,
  6194. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  6195. vsi->num_q_vectors, vsi->seid, ret);
  6196. vsi->num_q_vectors = 0;
  6197. goto vector_setup_out;
  6198. }
  6199. if (vsi->num_q_vectors)
  6200. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  6201. vsi->num_q_vectors, vsi->idx);
  6202. if (vsi->base_vector < 0) {
  6203. dev_info(&pf->pdev->dev,
  6204. "failed to get queue tracking for VSI %d, err=%d\n",
  6205. vsi->seid, vsi->base_vector);
  6206. i40e_vsi_free_q_vectors(vsi);
  6207. ret = -ENOENT;
  6208. goto vector_setup_out;
  6209. }
  6210. vector_setup_out:
  6211. return ret;
  6212. }
  6213. /**
  6214. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  6215. * @vsi: pointer to the vsi.
  6216. *
  6217. * This re-allocates a vsi's queue resources.
  6218. *
  6219. * Returns pointer to the successfully allocated and configured VSI sw struct
  6220. * on success, otherwise returns NULL on failure.
  6221. **/
  6222. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  6223. {
  6224. struct i40e_pf *pf = vsi->back;
  6225. u8 enabled_tc;
  6226. int ret;
  6227. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6228. i40e_vsi_clear_rings(vsi);
  6229. i40e_vsi_free_arrays(vsi, false);
  6230. i40e_set_num_rings_in_vsi(vsi);
  6231. ret = i40e_vsi_alloc_arrays(vsi, false);
  6232. if (ret)
  6233. goto err_vsi;
  6234. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  6235. if (ret < 0) {
  6236. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  6237. vsi->seid, ret);
  6238. goto err_vsi;
  6239. }
  6240. vsi->base_queue = ret;
  6241. /* Update the FW view of the VSI. Force a reset of TC and queue
  6242. * layout configurations.
  6243. */
  6244. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  6245. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  6246. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  6247. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  6248. /* assign it some queues */
  6249. ret = i40e_alloc_rings(vsi);
  6250. if (ret)
  6251. goto err_rings;
  6252. /* map all of the rings to the q_vectors */
  6253. i40e_vsi_map_rings_to_vectors(vsi);
  6254. return vsi;
  6255. err_rings:
  6256. i40e_vsi_free_q_vectors(vsi);
  6257. if (vsi->netdev_registered) {
  6258. vsi->netdev_registered = false;
  6259. unregister_netdev(vsi->netdev);
  6260. free_netdev(vsi->netdev);
  6261. vsi->netdev = NULL;
  6262. }
  6263. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  6264. err_vsi:
  6265. i40e_vsi_clear(vsi);
  6266. return NULL;
  6267. }
  6268. /**
  6269. * i40e_vsi_setup - Set up a VSI by a given type
  6270. * @pf: board private structure
  6271. * @type: VSI type
  6272. * @uplink_seid: the switch element to link to
  6273. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  6274. *
  6275. * This allocates the sw VSI structure and its queue resources, then add a VSI
  6276. * to the identified VEB.
  6277. *
  6278. * Returns pointer to the successfully allocated and configure VSI sw struct on
  6279. * success, otherwise returns NULL on failure.
  6280. **/
  6281. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  6282. u16 uplink_seid, u32 param1)
  6283. {
  6284. struct i40e_vsi *vsi = NULL;
  6285. struct i40e_veb *veb = NULL;
  6286. int ret, i;
  6287. int v_idx;
  6288. /* The requested uplink_seid must be either
  6289. * - the PF's port seid
  6290. * no VEB is needed because this is the PF
  6291. * or this is a Flow Director special case VSI
  6292. * - seid of an existing VEB
  6293. * - seid of a VSI that owns an existing VEB
  6294. * - seid of a VSI that doesn't own a VEB
  6295. * a new VEB is created and the VSI becomes the owner
  6296. * - seid of the PF VSI, which is what creates the first VEB
  6297. * this is a special case of the previous
  6298. *
  6299. * Find which uplink_seid we were given and create a new VEB if needed
  6300. */
  6301. for (i = 0; i < I40E_MAX_VEB; i++) {
  6302. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  6303. veb = pf->veb[i];
  6304. break;
  6305. }
  6306. }
  6307. if (!veb && uplink_seid != pf->mac_seid) {
  6308. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  6309. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  6310. vsi = pf->vsi[i];
  6311. break;
  6312. }
  6313. }
  6314. if (!vsi) {
  6315. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  6316. uplink_seid);
  6317. return NULL;
  6318. }
  6319. if (vsi->uplink_seid == pf->mac_seid)
  6320. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  6321. vsi->tc_config.enabled_tc);
  6322. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  6323. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  6324. vsi->tc_config.enabled_tc);
  6325. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  6326. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  6327. veb = pf->veb[i];
  6328. }
  6329. if (!veb) {
  6330. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  6331. return NULL;
  6332. }
  6333. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  6334. uplink_seid = veb->seid;
  6335. }
  6336. /* get vsi sw struct */
  6337. v_idx = i40e_vsi_mem_alloc(pf, type);
  6338. if (v_idx < 0)
  6339. goto err_alloc;
  6340. vsi = pf->vsi[v_idx];
  6341. if (!vsi)
  6342. goto err_alloc;
  6343. vsi->type = type;
  6344. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  6345. if (type == I40E_VSI_MAIN)
  6346. pf->lan_vsi = v_idx;
  6347. else if (type == I40E_VSI_SRIOV)
  6348. vsi->vf_id = param1;
  6349. /* assign it some queues */
  6350. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  6351. vsi->idx);
  6352. if (ret < 0) {
  6353. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  6354. vsi->seid, ret);
  6355. goto err_vsi;
  6356. }
  6357. vsi->base_queue = ret;
  6358. /* get a VSI from the hardware */
  6359. vsi->uplink_seid = uplink_seid;
  6360. ret = i40e_add_vsi(vsi);
  6361. if (ret)
  6362. goto err_vsi;
  6363. switch (vsi->type) {
  6364. /* setup the netdev if needed */
  6365. case I40E_VSI_MAIN:
  6366. case I40E_VSI_VMDQ2:
  6367. ret = i40e_config_netdev(vsi);
  6368. if (ret)
  6369. goto err_netdev;
  6370. ret = register_netdev(vsi->netdev);
  6371. if (ret)
  6372. goto err_netdev;
  6373. vsi->netdev_registered = true;
  6374. netif_carrier_off(vsi->netdev);
  6375. #ifdef CONFIG_I40E_DCB
  6376. /* Setup DCB netlink interface */
  6377. i40e_dcbnl_setup(vsi);
  6378. #endif /* CONFIG_I40E_DCB */
  6379. /* fall through */
  6380. case I40E_VSI_FDIR:
  6381. /* set up vectors and rings if needed */
  6382. ret = i40e_vsi_setup_vectors(vsi);
  6383. if (ret)
  6384. goto err_msix;
  6385. ret = i40e_alloc_rings(vsi);
  6386. if (ret)
  6387. goto err_rings;
  6388. /* map all of the rings to the q_vectors */
  6389. i40e_vsi_map_rings_to_vectors(vsi);
  6390. i40e_vsi_reset_stats(vsi);
  6391. break;
  6392. default:
  6393. /* no netdev or rings for the other VSI types */
  6394. break;
  6395. }
  6396. return vsi;
  6397. err_rings:
  6398. i40e_vsi_free_q_vectors(vsi);
  6399. err_msix:
  6400. if (vsi->netdev_registered) {
  6401. vsi->netdev_registered = false;
  6402. unregister_netdev(vsi->netdev);
  6403. free_netdev(vsi->netdev);
  6404. vsi->netdev = NULL;
  6405. }
  6406. err_netdev:
  6407. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  6408. err_vsi:
  6409. i40e_vsi_clear(vsi);
  6410. err_alloc:
  6411. return NULL;
  6412. }
  6413. /**
  6414. * i40e_veb_get_bw_info - Query VEB BW information
  6415. * @veb: the veb to query
  6416. *
  6417. * Query the Tx scheduler BW configuration data for given VEB
  6418. **/
  6419. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  6420. {
  6421. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  6422. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  6423. struct i40e_pf *pf = veb->pf;
  6424. struct i40e_hw *hw = &pf->hw;
  6425. u32 tc_bw_max;
  6426. int ret = 0;
  6427. int i;
  6428. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  6429. &bw_data, NULL);
  6430. if (ret) {
  6431. dev_info(&pf->pdev->dev,
  6432. "query veb bw config failed, aq_err=%d\n",
  6433. hw->aq.asq_last_status);
  6434. goto out;
  6435. }
  6436. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  6437. &ets_data, NULL);
  6438. if (ret) {
  6439. dev_info(&pf->pdev->dev,
  6440. "query veb bw ets config failed, aq_err=%d\n",
  6441. hw->aq.asq_last_status);
  6442. goto out;
  6443. }
  6444. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  6445. veb->bw_max_quanta = ets_data.tc_bw_max;
  6446. veb->is_abs_credits = bw_data.absolute_credits_enable;
  6447. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  6448. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  6449. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  6450. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  6451. veb->bw_tc_limit_credits[i] =
  6452. le16_to_cpu(bw_data.tc_bw_limits[i]);
  6453. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  6454. }
  6455. out:
  6456. return ret;
  6457. }
  6458. /**
  6459. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  6460. * @pf: board private structure
  6461. *
  6462. * On error: returns error code (negative)
  6463. * On success: returns vsi index in PF (positive)
  6464. **/
  6465. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  6466. {
  6467. int ret = -ENOENT;
  6468. struct i40e_veb *veb;
  6469. int i;
  6470. /* Need to protect the allocation of switch elements at the PF level */
  6471. mutex_lock(&pf->switch_mutex);
  6472. /* VEB list may be fragmented if VEB creation/destruction has
  6473. * been happening. We can afford to do a quick scan to look
  6474. * for any free slots in the list.
  6475. *
  6476. * find next empty veb slot, looping back around if necessary
  6477. */
  6478. i = 0;
  6479. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  6480. i++;
  6481. if (i >= I40E_MAX_VEB) {
  6482. ret = -ENOMEM;
  6483. goto err_alloc_veb; /* out of VEB slots! */
  6484. }
  6485. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  6486. if (!veb) {
  6487. ret = -ENOMEM;
  6488. goto err_alloc_veb;
  6489. }
  6490. veb->pf = pf;
  6491. veb->idx = i;
  6492. veb->enabled_tc = 1;
  6493. pf->veb[i] = veb;
  6494. ret = i;
  6495. err_alloc_veb:
  6496. mutex_unlock(&pf->switch_mutex);
  6497. return ret;
  6498. }
  6499. /**
  6500. * i40e_switch_branch_release - Delete a branch of the switch tree
  6501. * @branch: where to start deleting
  6502. *
  6503. * This uses recursion to find the tips of the branch to be
  6504. * removed, deleting until we get back to and can delete this VEB.
  6505. **/
  6506. static void i40e_switch_branch_release(struct i40e_veb *branch)
  6507. {
  6508. struct i40e_pf *pf = branch->pf;
  6509. u16 branch_seid = branch->seid;
  6510. u16 veb_idx = branch->idx;
  6511. int i;
  6512. /* release any VEBs on this VEB - RECURSION */
  6513. for (i = 0; i < I40E_MAX_VEB; i++) {
  6514. if (!pf->veb[i])
  6515. continue;
  6516. if (pf->veb[i]->uplink_seid == branch->seid)
  6517. i40e_switch_branch_release(pf->veb[i]);
  6518. }
  6519. /* Release the VSIs on this VEB, but not the owner VSI.
  6520. *
  6521. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  6522. * the VEB itself, so don't use (*branch) after this loop.
  6523. */
  6524. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  6525. if (!pf->vsi[i])
  6526. continue;
  6527. if (pf->vsi[i]->uplink_seid == branch_seid &&
  6528. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  6529. i40e_vsi_release(pf->vsi[i]);
  6530. }
  6531. }
  6532. /* There's one corner case where the VEB might not have been
  6533. * removed, so double check it here and remove it if needed.
  6534. * This case happens if the veb was created from the debugfs
  6535. * commands and no VSIs were added to it.
  6536. */
  6537. if (pf->veb[veb_idx])
  6538. i40e_veb_release(pf->veb[veb_idx]);
  6539. }
  6540. /**
  6541. * i40e_veb_clear - remove veb struct
  6542. * @veb: the veb to remove
  6543. **/
  6544. static void i40e_veb_clear(struct i40e_veb *veb)
  6545. {
  6546. if (!veb)
  6547. return;
  6548. if (veb->pf) {
  6549. struct i40e_pf *pf = veb->pf;
  6550. mutex_lock(&pf->switch_mutex);
  6551. if (pf->veb[veb->idx] == veb)
  6552. pf->veb[veb->idx] = NULL;
  6553. mutex_unlock(&pf->switch_mutex);
  6554. }
  6555. kfree(veb);
  6556. }
  6557. /**
  6558. * i40e_veb_release - Delete a VEB and free its resources
  6559. * @veb: the VEB being removed
  6560. **/
  6561. void i40e_veb_release(struct i40e_veb *veb)
  6562. {
  6563. struct i40e_vsi *vsi = NULL;
  6564. struct i40e_pf *pf;
  6565. int i, n = 0;
  6566. pf = veb->pf;
  6567. /* find the remaining VSI and check for extras */
  6568. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  6569. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  6570. n++;
  6571. vsi = pf->vsi[i];
  6572. }
  6573. }
  6574. if (n != 1) {
  6575. dev_info(&pf->pdev->dev,
  6576. "can't remove VEB %d with %d VSIs left\n",
  6577. veb->seid, n);
  6578. return;
  6579. }
  6580. /* move the remaining VSI to uplink veb */
  6581. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  6582. if (veb->uplink_seid) {
  6583. vsi->uplink_seid = veb->uplink_seid;
  6584. if (veb->uplink_seid == pf->mac_seid)
  6585. vsi->veb_idx = I40E_NO_VEB;
  6586. else
  6587. vsi->veb_idx = veb->veb_idx;
  6588. } else {
  6589. /* floating VEB */
  6590. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  6591. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  6592. }
  6593. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  6594. i40e_veb_clear(veb);
  6595. return;
  6596. }
  6597. /**
  6598. * i40e_add_veb - create the VEB in the switch
  6599. * @veb: the VEB to be instantiated
  6600. * @vsi: the controlling VSI
  6601. **/
  6602. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  6603. {
  6604. bool is_default = false;
  6605. bool is_cloud = false;
  6606. int ret;
  6607. /* get a VEB from the hardware */
  6608. ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid,
  6609. veb->enabled_tc, is_default,
  6610. is_cloud, &veb->seid, NULL);
  6611. if (ret) {
  6612. dev_info(&veb->pf->pdev->dev,
  6613. "couldn't add VEB, err %d, aq_err %d\n",
  6614. ret, veb->pf->hw.aq.asq_last_status);
  6615. return -EPERM;
  6616. }
  6617. /* get statistics counter */
  6618. ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL,
  6619. &veb->stats_idx, NULL, NULL, NULL);
  6620. if (ret) {
  6621. dev_info(&veb->pf->pdev->dev,
  6622. "couldn't get VEB statistics idx, err %d, aq_err %d\n",
  6623. ret, veb->pf->hw.aq.asq_last_status);
  6624. return -EPERM;
  6625. }
  6626. ret = i40e_veb_get_bw_info(veb);
  6627. if (ret) {
  6628. dev_info(&veb->pf->pdev->dev,
  6629. "couldn't get VEB bw info, err %d, aq_err %d\n",
  6630. ret, veb->pf->hw.aq.asq_last_status);
  6631. i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL);
  6632. return -ENOENT;
  6633. }
  6634. vsi->uplink_seid = veb->seid;
  6635. vsi->veb_idx = veb->idx;
  6636. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  6637. return 0;
  6638. }
  6639. /**
  6640. * i40e_veb_setup - Set up a VEB
  6641. * @pf: board private structure
  6642. * @flags: VEB setup flags
  6643. * @uplink_seid: the switch element to link to
  6644. * @vsi_seid: the initial VSI seid
  6645. * @enabled_tc: Enabled TC bit-map
  6646. *
  6647. * This allocates the sw VEB structure and links it into the switch
  6648. * It is possible and legal for this to be a duplicate of an already
  6649. * existing VEB. It is also possible for both uplink and vsi seids
  6650. * to be zero, in order to create a floating VEB.
  6651. *
  6652. * Returns pointer to the successfully allocated VEB sw struct on
  6653. * success, otherwise returns NULL on failure.
  6654. **/
  6655. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  6656. u16 uplink_seid, u16 vsi_seid,
  6657. u8 enabled_tc)
  6658. {
  6659. struct i40e_veb *veb, *uplink_veb = NULL;
  6660. int vsi_idx, veb_idx;
  6661. int ret;
  6662. /* if one seid is 0, the other must be 0 to create a floating relay */
  6663. if ((uplink_seid == 0 || vsi_seid == 0) &&
  6664. (uplink_seid + vsi_seid != 0)) {
  6665. dev_info(&pf->pdev->dev,
  6666. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  6667. uplink_seid, vsi_seid);
  6668. return NULL;
  6669. }
  6670. /* make sure there is such a vsi and uplink */
  6671. for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++)
  6672. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  6673. break;
  6674. if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) {
  6675. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  6676. vsi_seid);
  6677. return NULL;
  6678. }
  6679. if (uplink_seid && uplink_seid != pf->mac_seid) {
  6680. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  6681. if (pf->veb[veb_idx] &&
  6682. pf->veb[veb_idx]->seid == uplink_seid) {
  6683. uplink_veb = pf->veb[veb_idx];
  6684. break;
  6685. }
  6686. }
  6687. if (!uplink_veb) {
  6688. dev_info(&pf->pdev->dev,
  6689. "uplink seid %d not found\n", uplink_seid);
  6690. return NULL;
  6691. }
  6692. }
  6693. /* get veb sw struct */
  6694. veb_idx = i40e_veb_mem_alloc(pf);
  6695. if (veb_idx < 0)
  6696. goto err_alloc;
  6697. veb = pf->veb[veb_idx];
  6698. veb->flags = flags;
  6699. veb->uplink_seid = uplink_seid;
  6700. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  6701. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  6702. /* create the VEB in the switch */
  6703. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  6704. if (ret)
  6705. goto err_veb;
  6706. return veb;
  6707. err_veb:
  6708. i40e_veb_clear(veb);
  6709. err_alloc:
  6710. return NULL;
  6711. }
  6712. /**
  6713. * i40e_setup_pf_switch_element - set pf vars based on switch type
  6714. * @pf: board private structure
  6715. * @ele: element we are building info from
  6716. * @num_reported: total number of elements
  6717. * @printconfig: should we print the contents
  6718. *
  6719. * helper function to assist in extracting a few useful SEID values.
  6720. **/
  6721. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  6722. struct i40e_aqc_switch_config_element_resp *ele,
  6723. u16 num_reported, bool printconfig)
  6724. {
  6725. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  6726. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  6727. u8 element_type = ele->element_type;
  6728. u16 seid = le16_to_cpu(ele->seid);
  6729. if (printconfig)
  6730. dev_info(&pf->pdev->dev,
  6731. "type=%d seid=%d uplink=%d downlink=%d\n",
  6732. element_type, seid, uplink_seid, downlink_seid);
  6733. switch (element_type) {
  6734. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  6735. pf->mac_seid = seid;
  6736. break;
  6737. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  6738. /* Main VEB? */
  6739. if (uplink_seid != pf->mac_seid)
  6740. break;
  6741. if (pf->lan_veb == I40E_NO_VEB) {
  6742. int v;
  6743. /* find existing or else empty VEB */
  6744. for (v = 0; v < I40E_MAX_VEB; v++) {
  6745. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  6746. pf->lan_veb = v;
  6747. break;
  6748. }
  6749. }
  6750. if (pf->lan_veb == I40E_NO_VEB) {
  6751. v = i40e_veb_mem_alloc(pf);
  6752. if (v < 0)
  6753. break;
  6754. pf->lan_veb = v;
  6755. }
  6756. }
  6757. pf->veb[pf->lan_veb]->seid = seid;
  6758. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  6759. pf->veb[pf->lan_veb]->pf = pf;
  6760. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  6761. break;
  6762. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  6763. if (num_reported != 1)
  6764. break;
  6765. /* This is immediately after a reset so we can assume this is
  6766. * the PF's VSI
  6767. */
  6768. pf->mac_seid = uplink_seid;
  6769. pf->pf_seid = downlink_seid;
  6770. pf->main_vsi_seid = seid;
  6771. if (printconfig)
  6772. dev_info(&pf->pdev->dev,
  6773. "pf_seid=%d main_vsi_seid=%d\n",
  6774. pf->pf_seid, pf->main_vsi_seid);
  6775. break;
  6776. case I40E_SWITCH_ELEMENT_TYPE_PF:
  6777. case I40E_SWITCH_ELEMENT_TYPE_VF:
  6778. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  6779. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  6780. case I40E_SWITCH_ELEMENT_TYPE_PE:
  6781. case I40E_SWITCH_ELEMENT_TYPE_PA:
  6782. /* ignore these for now */
  6783. break;
  6784. default:
  6785. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  6786. element_type, seid);
  6787. break;
  6788. }
  6789. }
  6790. /**
  6791. * i40e_fetch_switch_configuration - Get switch config from firmware
  6792. * @pf: board private structure
  6793. * @printconfig: should we print the contents
  6794. *
  6795. * Get the current switch configuration from the device and
  6796. * extract a few useful SEID values.
  6797. **/
  6798. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  6799. {
  6800. struct i40e_aqc_get_switch_config_resp *sw_config;
  6801. u16 next_seid = 0;
  6802. int ret = 0;
  6803. u8 *aq_buf;
  6804. int i;
  6805. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  6806. if (!aq_buf)
  6807. return -ENOMEM;
  6808. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  6809. do {
  6810. u16 num_reported, num_total;
  6811. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  6812. I40E_AQ_LARGE_BUF,
  6813. &next_seid, NULL);
  6814. if (ret) {
  6815. dev_info(&pf->pdev->dev,
  6816. "get switch config failed %d aq_err=%x\n",
  6817. ret, pf->hw.aq.asq_last_status);
  6818. kfree(aq_buf);
  6819. return -ENOENT;
  6820. }
  6821. num_reported = le16_to_cpu(sw_config->header.num_reported);
  6822. num_total = le16_to_cpu(sw_config->header.num_total);
  6823. if (printconfig)
  6824. dev_info(&pf->pdev->dev,
  6825. "header: %d reported %d total\n",
  6826. num_reported, num_total);
  6827. if (num_reported) {
  6828. int sz = sizeof(*sw_config) * num_reported;
  6829. kfree(pf->sw_config);
  6830. pf->sw_config = kzalloc(sz, GFP_KERNEL);
  6831. if (pf->sw_config)
  6832. memcpy(pf->sw_config, sw_config, sz);
  6833. }
  6834. for (i = 0; i < num_reported; i++) {
  6835. struct i40e_aqc_switch_config_element_resp *ele =
  6836. &sw_config->element[i];
  6837. i40e_setup_pf_switch_element(pf, ele, num_reported,
  6838. printconfig);
  6839. }
  6840. } while (next_seid != 0);
  6841. kfree(aq_buf);
  6842. return ret;
  6843. }
  6844. /**
  6845. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  6846. * @pf: board private structure
  6847. * @reinit: if the Main VSI needs to re-initialized.
  6848. *
  6849. * Returns 0 on success, negative value on failure
  6850. **/
  6851. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  6852. {
  6853. u32 rxfc = 0, txfc = 0, rxfc_reg;
  6854. int ret;
  6855. /* find out what's out there already */
  6856. ret = i40e_fetch_switch_configuration(pf, false);
  6857. if (ret) {
  6858. dev_info(&pf->pdev->dev,
  6859. "couldn't fetch switch config, err %d, aq_err %d\n",
  6860. ret, pf->hw.aq.asq_last_status);
  6861. return ret;
  6862. }
  6863. i40e_pf_reset_stats(pf);
  6864. /* first time setup */
  6865. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  6866. struct i40e_vsi *vsi = NULL;
  6867. u16 uplink_seid;
  6868. /* Set up the PF VSI associated with the PF's main VSI
  6869. * that is already in the HW switch
  6870. */
  6871. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  6872. uplink_seid = pf->veb[pf->lan_veb]->seid;
  6873. else
  6874. uplink_seid = pf->mac_seid;
  6875. if (pf->lan_vsi == I40E_NO_VSI)
  6876. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  6877. else if (reinit)
  6878. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  6879. if (!vsi) {
  6880. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  6881. i40e_fdir_teardown(pf);
  6882. return -EAGAIN;
  6883. }
  6884. } else {
  6885. /* force a reset of TC and queue layout configurations */
  6886. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  6887. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  6888. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  6889. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  6890. }
  6891. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  6892. i40e_fdir_sb_setup(pf);
  6893. /* Setup static PF queue filter control settings */
  6894. ret = i40e_setup_pf_filter_control(pf);
  6895. if (ret) {
  6896. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  6897. ret);
  6898. /* Failure here should not stop continuing other steps */
  6899. }
  6900. /* enable RSS in the HW, even for only one queue, as the stack can use
  6901. * the hash
  6902. */
  6903. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  6904. i40e_config_rss(pf);
  6905. /* fill in link information and enable LSE reporting */
  6906. i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
  6907. i40e_link_event(pf);
  6908. /* Initialize user-specific link properties */
  6909. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  6910. I40E_AQ_AN_COMPLETED) ? true : false);
  6911. /* requested_mode is set in probe or by ethtool */
  6912. if (!pf->fc_autoneg_status)
  6913. goto no_autoneg;
  6914. if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) &&
  6915. (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX))
  6916. pf->hw.fc.current_mode = I40E_FC_FULL;
  6917. else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX)
  6918. pf->hw.fc.current_mode = I40E_FC_TX_PAUSE;
  6919. else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)
  6920. pf->hw.fc.current_mode = I40E_FC_RX_PAUSE;
  6921. else
  6922. pf->hw.fc.current_mode = I40E_FC_NONE;
  6923. /* sync the flow control settings with the auto-neg values */
  6924. switch (pf->hw.fc.current_mode) {
  6925. case I40E_FC_FULL:
  6926. txfc = 1;
  6927. rxfc = 1;
  6928. break;
  6929. case I40E_FC_TX_PAUSE:
  6930. txfc = 1;
  6931. rxfc = 0;
  6932. break;
  6933. case I40E_FC_RX_PAUSE:
  6934. txfc = 0;
  6935. rxfc = 1;
  6936. break;
  6937. case I40E_FC_NONE:
  6938. case I40E_FC_DEFAULT:
  6939. txfc = 0;
  6940. rxfc = 0;
  6941. break;
  6942. case I40E_FC_PFC:
  6943. /* TBD */
  6944. break;
  6945. /* no default case, we have to handle all possibilities here */
  6946. }
  6947. wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
  6948. rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
  6949. ~I40E_PRTDCB_MFLCN_RFCE_MASK;
  6950. rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT);
  6951. wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg);
  6952. goto fc_complete;
  6953. no_autoneg:
  6954. /* disable L2 flow control, user can turn it on if they wish */
  6955. wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0);
  6956. wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
  6957. ~I40E_PRTDCB_MFLCN_RFCE_MASK);
  6958. fc_complete:
  6959. i40e_ptp_init(pf);
  6960. return ret;
  6961. }
  6962. /**
  6963. * i40e_determine_queue_usage - Work out queue distribution
  6964. * @pf: board private structure
  6965. **/
  6966. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  6967. {
  6968. int queues_left;
  6969. pf->num_lan_qps = 0;
  6970. /* Find the max queues to be put into basic use. We'll always be
  6971. * using TC0, whether or not DCB is running, and TC0 will get the
  6972. * big RSS set.
  6973. */
  6974. queues_left = pf->hw.func_caps.num_tx_qp;
  6975. if ((queues_left == 1) ||
  6976. !(pf->flags & I40E_FLAG_MSIX_ENABLED) ||
  6977. !(pf->flags & (I40E_FLAG_RSS_ENABLED | I40E_FLAG_FD_SB_ENABLED |
  6978. I40E_FLAG_DCB_ENABLED))) {
  6979. /* one qp for PF, no queues for anything else */
  6980. queues_left = 0;
  6981. pf->rss_size = pf->num_lan_qps = 1;
  6982. /* make sure all the fancies are disabled */
  6983. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  6984. I40E_FLAG_FD_SB_ENABLED |
  6985. I40E_FLAG_FD_ATR_ENABLED |
  6986. I40E_FLAG_DCB_ENABLED |
  6987. I40E_FLAG_SRIOV_ENABLED |
  6988. I40E_FLAG_VMDQ_ENABLED);
  6989. } else {
  6990. /* Not enough queues for all TCs */
  6991. if ((pf->flags & I40E_FLAG_DCB_ENABLED) &&
  6992. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  6993. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  6994. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  6995. }
  6996. pf->num_lan_qps = pf->rss_size_max;
  6997. queues_left -= pf->num_lan_qps;
  6998. }
  6999. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7000. if (queues_left > 1) {
  7001. queues_left -= 1; /* save 1 queue for FD */
  7002. } else {
  7003. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7004. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  7005. }
  7006. }
  7007. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  7008. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  7009. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  7010. (queues_left / pf->num_vf_qps));
  7011. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  7012. }
  7013. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  7014. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  7015. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  7016. (queues_left / pf->num_vmdq_qps));
  7017. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  7018. }
  7019. pf->queues_left = queues_left;
  7020. return;
  7021. }
  7022. /**
  7023. * i40e_setup_pf_filter_control - Setup PF static filter control
  7024. * @pf: PF to be setup
  7025. *
  7026. * i40e_setup_pf_filter_control sets up a pf's initial filter control
  7027. * settings. If PE/FCoE are enabled then it will also set the per PF
  7028. * based filter sizes required for them. It also enables Flow director,
  7029. * ethertype and macvlan type filter settings for the pf.
  7030. *
  7031. * Returns 0 on success, negative on failure
  7032. **/
  7033. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  7034. {
  7035. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  7036. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  7037. /* Flow Director is enabled */
  7038. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  7039. settings->enable_fdir = true;
  7040. /* Ethtype and MACVLAN filters enabled for PF */
  7041. settings->enable_ethtype = true;
  7042. settings->enable_macvlan = true;
  7043. if (i40e_set_filter_control(&pf->hw, settings))
  7044. return -ENOENT;
  7045. return 0;
  7046. }
  7047. #define INFO_STRING_LEN 255
  7048. static void i40e_print_features(struct i40e_pf *pf)
  7049. {
  7050. struct i40e_hw *hw = &pf->hw;
  7051. char *buf, *string;
  7052. string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
  7053. if (!string) {
  7054. dev_err(&pf->pdev->dev, "Features string allocation failed\n");
  7055. return;
  7056. }
  7057. buf = string;
  7058. buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
  7059. #ifdef CONFIG_PCI_IOV
  7060. buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
  7061. #endif
  7062. buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis,
  7063. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  7064. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  7065. buf += sprintf(buf, "RSS ");
  7066. buf += sprintf(buf, "FDir ");
  7067. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  7068. buf += sprintf(buf, "ATR ");
  7069. if (pf->flags & I40E_FLAG_FD_SB_ENABLED)
  7070. buf += sprintf(buf, "NTUPLE ");
  7071. if (pf->flags & I40E_FLAG_DCB_ENABLED)
  7072. buf += sprintf(buf, "DCB ");
  7073. if (pf->flags & I40E_FLAG_PTP)
  7074. buf += sprintf(buf, "PTP ");
  7075. BUG_ON(buf > (string + INFO_STRING_LEN));
  7076. dev_info(&pf->pdev->dev, "%s\n", string);
  7077. kfree(string);
  7078. }
  7079. /**
  7080. * i40e_probe - Device initialization routine
  7081. * @pdev: PCI device information struct
  7082. * @ent: entry in i40e_pci_tbl
  7083. *
  7084. * i40e_probe initializes a pf identified by a pci_dev structure.
  7085. * The OS initialization, configuring of the pf private structure,
  7086. * and a hardware reset occur.
  7087. *
  7088. * Returns 0 on success, negative on failure
  7089. **/
  7090. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  7091. {
  7092. struct i40e_driver_version dv;
  7093. struct i40e_pf *pf;
  7094. struct i40e_hw *hw;
  7095. static u16 pfs_found;
  7096. u16 link_status;
  7097. int err = 0;
  7098. u32 len;
  7099. u32 i;
  7100. err = pci_enable_device_mem(pdev);
  7101. if (err)
  7102. return err;
  7103. /* set up for high or low dma */
  7104. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  7105. if (err) {
  7106. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  7107. if (err) {
  7108. dev_err(&pdev->dev,
  7109. "DMA configuration failed: 0x%x\n", err);
  7110. goto err_dma;
  7111. }
  7112. }
  7113. /* set up pci connections */
  7114. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  7115. IORESOURCE_MEM), i40e_driver_name);
  7116. if (err) {
  7117. dev_info(&pdev->dev,
  7118. "pci_request_selected_regions failed %d\n", err);
  7119. goto err_pci_reg;
  7120. }
  7121. pci_enable_pcie_error_reporting(pdev);
  7122. pci_set_master(pdev);
  7123. /* Now that we have a PCI connection, we need to do the
  7124. * low level device setup. This is primarily setting up
  7125. * the Admin Queue structures and then querying for the
  7126. * device's current profile information.
  7127. */
  7128. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  7129. if (!pf) {
  7130. err = -ENOMEM;
  7131. goto err_pf_alloc;
  7132. }
  7133. pf->next_vsi = 0;
  7134. pf->pdev = pdev;
  7135. set_bit(__I40E_DOWN, &pf->state);
  7136. hw = &pf->hw;
  7137. hw->back = pf;
  7138. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  7139. pci_resource_len(pdev, 0));
  7140. if (!hw->hw_addr) {
  7141. err = -EIO;
  7142. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  7143. (unsigned int)pci_resource_start(pdev, 0),
  7144. (unsigned int)pci_resource_len(pdev, 0), err);
  7145. goto err_ioremap;
  7146. }
  7147. hw->vendor_id = pdev->vendor;
  7148. hw->device_id = pdev->device;
  7149. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  7150. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  7151. hw->subsystem_device_id = pdev->subsystem_device;
  7152. hw->bus.device = PCI_SLOT(pdev->devfn);
  7153. hw->bus.func = PCI_FUNC(pdev->devfn);
  7154. pf->instance = pfs_found;
  7155. /* do a special CORER for clearing PXE mode once at init */
  7156. if (hw->revision_id == 0 &&
  7157. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  7158. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  7159. i40e_flush(hw);
  7160. msleep(200);
  7161. pf->corer_count++;
  7162. i40e_clear_pxe_mode(hw);
  7163. }
  7164. /* Reset here to make sure all is clean and to define PF 'n' */
  7165. err = i40e_pf_reset(hw);
  7166. if (err) {
  7167. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  7168. goto err_pf_reset;
  7169. }
  7170. pf->pfr_count++;
  7171. hw->aq.num_arq_entries = I40E_AQ_LEN;
  7172. hw->aq.num_asq_entries = I40E_AQ_LEN;
  7173. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  7174. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  7175. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  7176. snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1,
  7177. "%s-pf%d:misc",
  7178. dev_driver_string(&pf->pdev->dev), pf->hw.pf_id);
  7179. err = i40e_init_shared_code(hw);
  7180. if (err) {
  7181. dev_info(&pdev->dev, "init_shared_code failed: %d\n", err);
  7182. goto err_pf_reset;
  7183. }
  7184. /* set up a default setting for link flow control */
  7185. pf->hw.fc.requested_mode = I40E_FC_NONE;
  7186. err = i40e_init_adminq(hw);
  7187. dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw));
  7188. if (err) {
  7189. dev_info(&pdev->dev,
  7190. "init_adminq failed: %d expecting API %02x.%02x\n",
  7191. err,
  7192. I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
  7193. goto err_pf_reset;
  7194. }
  7195. i40e_verify_eeprom(pf);
  7196. i40e_clear_pxe_mode(hw);
  7197. err = i40e_get_capabilities(pf);
  7198. if (err)
  7199. goto err_adminq_setup;
  7200. err = i40e_sw_init(pf);
  7201. if (err) {
  7202. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  7203. goto err_sw_init;
  7204. }
  7205. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  7206. hw->func_caps.num_rx_qp,
  7207. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  7208. if (err) {
  7209. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  7210. goto err_init_lan_hmc;
  7211. }
  7212. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  7213. if (err) {
  7214. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  7215. err = -ENOENT;
  7216. goto err_configure_lan_hmc;
  7217. }
  7218. i40e_get_mac_addr(hw, hw->mac.addr);
  7219. if (!is_valid_ether_addr(hw->mac.addr)) {
  7220. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  7221. err = -EIO;
  7222. goto err_mac_addr;
  7223. }
  7224. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  7225. memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
  7226. pci_set_drvdata(pdev, pf);
  7227. pci_save_state(pdev);
  7228. #ifdef CONFIG_I40E_DCB
  7229. err = i40e_init_pf_dcb(pf);
  7230. if (err) {
  7231. dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err);
  7232. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  7233. /* Continue without DCB enabled */
  7234. }
  7235. #endif /* CONFIG_I40E_DCB */
  7236. /* set up periodic task facility */
  7237. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  7238. pf->service_timer_period = HZ;
  7239. INIT_WORK(&pf->service_task, i40e_service_task);
  7240. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  7241. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  7242. pf->link_check_timeout = jiffies;
  7243. /* WoL defaults to disabled */
  7244. pf->wol_en = false;
  7245. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  7246. /* set up the main switch operations */
  7247. i40e_determine_queue_usage(pf);
  7248. i40e_init_interrupt_scheme(pf);
  7249. /* Set up the *vsi struct based on the number of VSIs in the HW,
  7250. * and set up our local tracking of the MAIN PF vsi.
  7251. */
  7252. len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis;
  7253. pf->vsi = kzalloc(len, GFP_KERNEL);
  7254. if (!pf->vsi) {
  7255. err = -ENOMEM;
  7256. goto err_switch_setup;
  7257. }
  7258. err = i40e_setup_pf_switch(pf, false);
  7259. if (err) {
  7260. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  7261. goto err_vsis;
  7262. }
  7263. /* if FDIR VSI was set up, start it now */
  7264. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  7265. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  7266. i40e_vsi_open(pf->vsi[i]);
  7267. break;
  7268. }
  7269. }
  7270. /* The main driver is (mostly) up and happy. We need to set this state
  7271. * before setting up the misc vector or we get a race and the vector
  7272. * ends up disabled forever.
  7273. */
  7274. clear_bit(__I40E_DOWN, &pf->state);
  7275. /* In case of MSIX we are going to setup the misc vector right here
  7276. * to handle admin queue events etc. In case of legacy and MSI
  7277. * the misc functionality and queue processing is combined in
  7278. * the same vector and that gets setup at open.
  7279. */
  7280. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7281. err = i40e_setup_misc_vector(pf);
  7282. if (err) {
  7283. dev_info(&pdev->dev,
  7284. "setup of misc vector failed: %d\n", err);
  7285. goto err_vsis;
  7286. }
  7287. }
  7288. /* prep for VF support */
  7289. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  7290. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  7291. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  7292. u32 val;
  7293. /* disable link interrupts for VFs */
  7294. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  7295. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  7296. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  7297. i40e_flush(hw);
  7298. if (pci_num_vf(pdev)) {
  7299. dev_info(&pdev->dev,
  7300. "Active VFs found, allocating resources.\n");
  7301. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  7302. if (err)
  7303. dev_info(&pdev->dev,
  7304. "Error %d allocating resources for existing VFs\n",
  7305. err);
  7306. }
  7307. }
  7308. pfs_found++;
  7309. i40e_dbg_pf_init(pf);
  7310. /* tell the firmware that we're starting */
  7311. dv.major_version = DRV_VERSION_MAJOR;
  7312. dv.minor_version = DRV_VERSION_MINOR;
  7313. dv.build_version = DRV_VERSION_BUILD;
  7314. dv.subbuild_version = 0;
  7315. strncpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  7316. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  7317. /* since everything's happy, start the service_task timer */
  7318. mod_timer(&pf->service_timer,
  7319. round_jiffies(jiffies + pf->service_timer_period));
  7320. /* Get the negotiated link width and speed from PCI config space */
  7321. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status);
  7322. i40e_set_pci_config_data(hw, link_status);
  7323. dev_info(&pdev->dev, "PCI-Express: %s %s\n",
  7324. (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" :
  7325. hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" :
  7326. hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" :
  7327. "Unknown"),
  7328. (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" :
  7329. hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" :
  7330. hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" :
  7331. hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" :
  7332. "Unknown"));
  7333. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  7334. hw->bus.speed < i40e_bus_speed_8000) {
  7335. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  7336. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  7337. }
  7338. /* print a string summarizing features */
  7339. i40e_print_features(pf);
  7340. return 0;
  7341. /* Unwind what we've done if something failed in the setup */
  7342. err_vsis:
  7343. set_bit(__I40E_DOWN, &pf->state);
  7344. i40e_clear_interrupt_scheme(pf);
  7345. kfree(pf->vsi);
  7346. err_switch_setup:
  7347. i40e_reset_interrupt_capability(pf);
  7348. del_timer_sync(&pf->service_timer);
  7349. err_mac_addr:
  7350. err_configure_lan_hmc:
  7351. (void)i40e_shutdown_lan_hmc(hw);
  7352. err_init_lan_hmc:
  7353. kfree(pf->qp_pile);
  7354. kfree(pf->irq_pile);
  7355. err_sw_init:
  7356. err_adminq_setup:
  7357. (void)i40e_shutdown_adminq(hw);
  7358. err_pf_reset:
  7359. iounmap(hw->hw_addr);
  7360. err_ioremap:
  7361. kfree(pf);
  7362. err_pf_alloc:
  7363. pci_disable_pcie_error_reporting(pdev);
  7364. pci_release_selected_regions(pdev,
  7365. pci_select_bars(pdev, IORESOURCE_MEM));
  7366. err_pci_reg:
  7367. err_dma:
  7368. pci_disable_device(pdev);
  7369. return err;
  7370. }
  7371. /**
  7372. * i40e_remove - Device removal routine
  7373. * @pdev: PCI device information struct
  7374. *
  7375. * i40e_remove is called by the PCI subsystem to alert the driver
  7376. * that is should release a PCI device. This could be caused by a
  7377. * Hot-Plug event, or because the driver is going to be removed from
  7378. * memory.
  7379. **/
  7380. static void i40e_remove(struct pci_dev *pdev)
  7381. {
  7382. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7383. i40e_status ret_code;
  7384. u32 reg;
  7385. int i;
  7386. i40e_dbg_pf_exit(pf);
  7387. i40e_ptp_stop(pf);
  7388. /* no more scheduling of any task */
  7389. set_bit(__I40E_DOWN, &pf->state);
  7390. del_timer_sync(&pf->service_timer);
  7391. cancel_work_sync(&pf->service_task);
  7392. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  7393. i40e_free_vfs(pf);
  7394. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  7395. }
  7396. i40e_fdir_teardown(pf);
  7397. /* If there is a switch structure or any orphans, remove them.
  7398. * This will leave only the PF's VSI remaining.
  7399. */
  7400. for (i = 0; i < I40E_MAX_VEB; i++) {
  7401. if (!pf->veb[i])
  7402. continue;
  7403. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  7404. pf->veb[i]->uplink_seid == 0)
  7405. i40e_switch_branch_release(pf->veb[i]);
  7406. }
  7407. /* Now we can shutdown the PF's VSI, just before we kill
  7408. * adminq and hmc.
  7409. */
  7410. if (pf->vsi[pf->lan_vsi])
  7411. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  7412. i40e_stop_misc_vector(pf);
  7413. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7414. synchronize_irq(pf->msix_entries[0].vector);
  7415. free_irq(pf->msix_entries[0].vector, pf);
  7416. }
  7417. /* shutdown and destroy the HMC */
  7418. ret_code = i40e_shutdown_lan_hmc(&pf->hw);
  7419. if (ret_code)
  7420. dev_warn(&pdev->dev,
  7421. "Failed to destroy the HMC resources: %d\n", ret_code);
  7422. /* shutdown the adminq */
  7423. ret_code = i40e_shutdown_adminq(&pf->hw);
  7424. if (ret_code)
  7425. dev_warn(&pdev->dev,
  7426. "Failed to destroy the Admin Queue resources: %d\n",
  7427. ret_code);
  7428. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  7429. i40e_clear_interrupt_scheme(pf);
  7430. for (i = 0; i < pf->hw.func_caps.num_vsis; i++) {
  7431. if (pf->vsi[i]) {
  7432. i40e_vsi_clear_rings(pf->vsi[i]);
  7433. i40e_vsi_clear(pf->vsi[i]);
  7434. pf->vsi[i] = NULL;
  7435. }
  7436. }
  7437. for (i = 0; i < I40E_MAX_VEB; i++) {
  7438. kfree(pf->veb[i]);
  7439. pf->veb[i] = NULL;
  7440. }
  7441. kfree(pf->qp_pile);
  7442. kfree(pf->irq_pile);
  7443. kfree(pf->sw_config);
  7444. kfree(pf->vsi);
  7445. /* force a PF reset to clean anything leftover */
  7446. reg = rd32(&pf->hw, I40E_PFGEN_CTRL);
  7447. wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  7448. i40e_flush(&pf->hw);
  7449. iounmap(pf->hw.hw_addr);
  7450. kfree(pf);
  7451. pci_release_selected_regions(pdev,
  7452. pci_select_bars(pdev, IORESOURCE_MEM));
  7453. pci_disable_pcie_error_reporting(pdev);
  7454. pci_disable_device(pdev);
  7455. }
  7456. /**
  7457. * i40e_pci_error_detected - warning that something funky happened in PCI land
  7458. * @pdev: PCI device information struct
  7459. *
  7460. * Called to warn that something happened and the error handling steps
  7461. * are in progress. Allows the driver to quiesce things, be ready for
  7462. * remediation.
  7463. **/
  7464. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  7465. enum pci_channel_state error)
  7466. {
  7467. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7468. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  7469. /* shutdown all operations */
  7470. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  7471. rtnl_lock();
  7472. i40e_prep_for_reset(pf);
  7473. rtnl_unlock();
  7474. }
  7475. /* Request a slot reset */
  7476. return PCI_ERS_RESULT_NEED_RESET;
  7477. }
  7478. /**
  7479. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  7480. * @pdev: PCI device information struct
  7481. *
  7482. * Called to find if the driver can work with the device now that
  7483. * the pci slot has been reset. If a basic connection seems good
  7484. * (registers are readable and have sane content) then return a
  7485. * happy little PCI_ERS_RESULT_xxx.
  7486. **/
  7487. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  7488. {
  7489. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7490. pci_ers_result_t result;
  7491. int err;
  7492. u32 reg;
  7493. dev_info(&pdev->dev, "%s\n", __func__);
  7494. if (pci_enable_device_mem(pdev)) {
  7495. dev_info(&pdev->dev,
  7496. "Cannot re-enable PCI device after reset.\n");
  7497. result = PCI_ERS_RESULT_DISCONNECT;
  7498. } else {
  7499. pci_set_master(pdev);
  7500. pci_restore_state(pdev);
  7501. pci_save_state(pdev);
  7502. pci_wake_from_d3(pdev, false);
  7503. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  7504. if (reg == 0)
  7505. result = PCI_ERS_RESULT_RECOVERED;
  7506. else
  7507. result = PCI_ERS_RESULT_DISCONNECT;
  7508. }
  7509. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  7510. if (err) {
  7511. dev_info(&pdev->dev,
  7512. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  7513. err);
  7514. /* non-fatal, continue */
  7515. }
  7516. return result;
  7517. }
  7518. /**
  7519. * i40e_pci_error_resume - restart operations after PCI error recovery
  7520. * @pdev: PCI device information struct
  7521. *
  7522. * Called to allow the driver to bring things back up after PCI error
  7523. * and/or reset recovery has finished.
  7524. **/
  7525. static void i40e_pci_error_resume(struct pci_dev *pdev)
  7526. {
  7527. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7528. dev_info(&pdev->dev, "%s\n", __func__);
  7529. if (test_bit(__I40E_SUSPENDED, &pf->state))
  7530. return;
  7531. rtnl_lock();
  7532. i40e_handle_reset_warning(pf);
  7533. rtnl_lock();
  7534. }
  7535. /**
  7536. * i40e_shutdown - PCI callback for shutting down
  7537. * @pdev: PCI device information struct
  7538. **/
  7539. static void i40e_shutdown(struct pci_dev *pdev)
  7540. {
  7541. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7542. struct i40e_hw *hw = &pf->hw;
  7543. set_bit(__I40E_SUSPENDED, &pf->state);
  7544. set_bit(__I40E_DOWN, &pf->state);
  7545. rtnl_lock();
  7546. i40e_prep_for_reset(pf);
  7547. rtnl_unlock();
  7548. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  7549. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  7550. if (system_state == SYSTEM_POWER_OFF) {
  7551. pci_wake_from_d3(pdev, pf->wol_en);
  7552. pci_set_power_state(pdev, PCI_D3hot);
  7553. }
  7554. }
  7555. #ifdef CONFIG_PM
  7556. /**
  7557. * i40e_suspend - PCI callback for moving to D3
  7558. * @pdev: PCI device information struct
  7559. **/
  7560. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  7561. {
  7562. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7563. struct i40e_hw *hw = &pf->hw;
  7564. set_bit(__I40E_SUSPENDED, &pf->state);
  7565. set_bit(__I40E_DOWN, &pf->state);
  7566. rtnl_lock();
  7567. i40e_prep_for_reset(pf);
  7568. rtnl_unlock();
  7569. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  7570. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  7571. pci_wake_from_d3(pdev, pf->wol_en);
  7572. pci_set_power_state(pdev, PCI_D3hot);
  7573. return 0;
  7574. }
  7575. /**
  7576. * i40e_resume - PCI callback for waking up from D3
  7577. * @pdev: PCI device information struct
  7578. **/
  7579. static int i40e_resume(struct pci_dev *pdev)
  7580. {
  7581. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7582. u32 err;
  7583. pci_set_power_state(pdev, PCI_D0);
  7584. pci_restore_state(pdev);
  7585. /* pci_restore_state() clears dev->state_saves, so
  7586. * call pci_save_state() again to restore it.
  7587. */
  7588. pci_save_state(pdev);
  7589. err = pci_enable_device_mem(pdev);
  7590. if (err) {
  7591. dev_err(&pdev->dev,
  7592. "%s: Cannot enable PCI device from suspend\n",
  7593. __func__);
  7594. return err;
  7595. }
  7596. pci_set_master(pdev);
  7597. /* no wakeup events while running */
  7598. pci_wake_from_d3(pdev, false);
  7599. /* handling the reset will rebuild the device state */
  7600. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  7601. clear_bit(__I40E_DOWN, &pf->state);
  7602. rtnl_lock();
  7603. i40e_reset_and_rebuild(pf, false);
  7604. rtnl_unlock();
  7605. }
  7606. return 0;
  7607. }
  7608. #endif
  7609. static const struct pci_error_handlers i40e_err_handler = {
  7610. .error_detected = i40e_pci_error_detected,
  7611. .slot_reset = i40e_pci_error_slot_reset,
  7612. .resume = i40e_pci_error_resume,
  7613. };
  7614. static struct pci_driver i40e_driver = {
  7615. .name = i40e_driver_name,
  7616. .id_table = i40e_pci_tbl,
  7617. .probe = i40e_probe,
  7618. .remove = i40e_remove,
  7619. #ifdef CONFIG_PM
  7620. .suspend = i40e_suspend,
  7621. .resume = i40e_resume,
  7622. #endif
  7623. .shutdown = i40e_shutdown,
  7624. .err_handler = &i40e_err_handler,
  7625. .sriov_configure = i40e_pci_sriov_configure,
  7626. };
  7627. /**
  7628. * i40e_init_module - Driver registration routine
  7629. *
  7630. * i40e_init_module is the first routine called when the driver is
  7631. * loaded. All it does is register with the PCI subsystem.
  7632. **/
  7633. static int __init i40e_init_module(void)
  7634. {
  7635. pr_info("%s: %s - version %s\n", i40e_driver_name,
  7636. i40e_driver_string, i40e_driver_version_str);
  7637. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  7638. i40e_dbg_init();
  7639. return pci_register_driver(&i40e_driver);
  7640. }
  7641. module_init(i40e_init_module);
  7642. /**
  7643. * i40e_exit_module - Driver exit cleanup routine
  7644. *
  7645. * i40e_exit_module is called just before the driver is removed
  7646. * from memory.
  7647. **/
  7648. static void __exit i40e_exit_module(void)
  7649. {
  7650. pci_unregister_driver(&i40e_driver);
  7651. i40e_dbg_exit();
  7652. }
  7653. module_exit(i40e_exit_module);