i40e_main.c 279 KB

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