i40e_main.c 290 KB

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