i40e_main.c 266 KB

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