i40e_main.c 318 KB

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