i40e_main.c 279 KB

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