i40e_main.c 305 KB

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