i40e_main.c 319 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include <linux/etherdevice.h>
  27. #include <linux/of_net.h>
  28. #include <linux/pci.h>
  29. /* Local includes */
  30. #include "i40e.h"
  31. #include "i40e_diag.h"
  32. #include <net/udp_tunnel.h>
  33. const char i40e_driver_name[] = "i40e";
  34. static const char i40e_driver_string[] =
  35. "Intel(R) Ethernet Connection XL710 Network Driver";
  36. #define DRV_KERN "-k"
  37. #define DRV_VERSION_MAJOR 1
  38. #define DRV_VERSION_MINOR 6
  39. #define DRV_VERSION_BUILD 16
  40. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  41. __stringify(DRV_VERSION_MINOR) "." \
  42. __stringify(DRV_VERSION_BUILD) DRV_KERN
  43. const char i40e_driver_version_str[] = DRV_VERSION;
  44. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  45. /* a bit of forward declarations */
  46. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  47. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  48. static int i40e_add_vsi(struct i40e_vsi *vsi);
  49. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  50. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  51. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  52. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  53. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  54. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  55. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  56. /* i40e_pci_tbl - PCI Device ID Table
  57. *
  58. * Last entry must be all 0s
  59. *
  60. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  61. * Class, Class Mask, private data (not used) }
  62. */
  63. static const struct pci_device_id i40e_pci_tbl[] = {
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  71. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  72. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  73. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  74. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  75. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  76. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  77. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  78. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  79. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  80. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  81. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  82. /* required last entry */
  83. {0, }
  84. };
  85. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  86. #define I40E_MAX_VF_COUNT 128
  87. static int debug = -1;
  88. module_param(debug, int, 0);
  89. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  90. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  91. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  92. MODULE_LICENSE("GPL");
  93. MODULE_VERSION(DRV_VERSION);
  94. static struct workqueue_struct *i40e_wq;
  95. /**
  96. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  97. * @hw: pointer to the HW structure
  98. * @mem: ptr to mem struct to fill out
  99. * @size: size of memory requested
  100. * @alignment: what to align the allocation to
  101. **/
  102. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  103. u64 size, u32 alignment)
  104. {
  105. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  106. mem->size = ALIGN(size, alignment);
  107. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  108. &mem->pa, GFP_KERNEL);
  109. if (!mem->va)
  110. return -ENOMEM;
  111. return 0;
  112. }
  113. /**
  114. * i40e_free_dma_mem_d - OS specific memory free for shared code
  115. * @hw: pointer to the HW structure
  116. * @mem: ptr to mem struct to free
  117. **/
  118. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  119. {
  120. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  121. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  122. mem->va = NULL;
  123. mem->pa = 0;
  124. mem->size = 0;
  125. return 0;
  126. }
  127. /**
  128. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  129. * @hw: pointer to the HW structure
  130. * @mem: ptr to mem struct to fill out
  131. * @size: size of memory requested
  132. **/
  133. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  134. u32 size)
  135. {
  136. mem->size = size;
  137. mem->va = kzalloc(size, GFP_KERNEL);
  138. if (!mem->va)
  139. return -ENOMEM;
  140. return 0;
  141. }
  142. /**
  143. * i40e_free_virt_mem_d - OS specific memory free for shared code
  144. * @hw: pointer to the HW structure
  145. * @mem: ptr to mem struct to free
  146. **/
  147. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  148. {
  149. /* it's ok to kfree a NULL pointer */
  150. kfree(mem->va);
  151. mem->va = NULL;
  152. mem->size = 0;
  153. return 0;
  154. }
  155. /**
  156. * i40e_get_lump - find a lump of free generic resource
  157. * @pf: board private structure
  158. * @pile: the pile of resource to search
  159. * @needed: the number of items needed
  160. * @id: an owner id to stick on the items assigned
  161. *
  162. * Returns the base item index of the lump, or negative for error
  163. *
  164. * The search_hint trick and lack of advanced fit-finding only work
  165. * because we're highly likely to have all the same size lump requests.
  166. * Linear search time and any fragmentation should be minimal.
  167. **/
  168. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  169. u16 needed, u16 id)
  170. {
  171. int ret = -ENOMEM;
  172. int i, j;
  173. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  174. dev_info(&pf->pdev->dev,
  175. "param err: pile=%p needed=%d id=0x%04x\n",
  176. pile, needed, id);
  177. return -EINVAL;
  178. }
  179. /* start the linear search with an imperfect hint */
  180. i = pile->search_hint;
  181. while (i < pile->num_entries) {
  182. /* skip already allocated entries */
  183. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  184. i++;
  185. continue;
  186. }
  187. /* do we have enough in this lump? */
  188. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  189. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  190. break;
  191. }
  192. if (j == needed) {
  193. /* there was enough, so assign it to the requestor */
  194. for (j = 0; j < needed; j++)
  195. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  196. ret = i;
  197. pile->search_hint = i + j;
  198. break;
  199. }
  200. /* not enough, so skip over it and continue looking */
  201. i += j;
  202. }
  203. return ret;
  204. }
  205. /**
  206. * i40e_put_lump - return a lump of generic resource
  207. * @pile: the pile of resource to search
  208. * @index: the base item index
  209. * @id: the owner id of the items assigned
  210. *
  211. * Returns the count of items in the lump
  212. **/
  213. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  214. {
  215. int valid_id = (id | I40E_PILE_VALID_BIT);
  216. int count = 0;
  217. int i;
  218. if (!pile || index >= pile->num_entries)
  219. return -EINVAL;
  220. for (i = index;
  221. i < pile->num_entries && pile->list[i] == valid_id;
  222. i++) {
  223. pile->list[i] = 0;
  224. count++;
  225. }
  226. if (count && index < pile->search_hint)
  227. pile->search_hint = index;
  228. return count;
  229. }
  230. /**
  231. * i40e_find_vsi_from_id - searches for the vsi with the given id
  232. * @pf - the pf structure to search for the vsi
  233. * @id - id of the vsi it is searching for
  234. **/
  235. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  236. {
  237. int i;
  238. for (i = 0; i < pf->num_alloc_vsi; i++)
  239. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  240. return pf->vsi[i];
  241. return NULL;
  242. }
  243. /**
  244. * i40e_service_event_schedule - Schedule the service task to wake up
  245. * @pf: board private structure
  246. *
  247. * If not already scheduled, this puts the task into the work queue
  248. **/
  249. void i40e_service_event_schedule(struct i40e_pf *pf)
  250. {
  251. if (!test_bit(__I40E_DOWN, &pf->state) &&
  252. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
  253. !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  254. queue_work(i40e_wq, &pf->service_task);
  255. }
  256. /**
  257. * i40e_tx_timeout - Respond to a Tx Hang
  258. * @netdev: network interface device structure
  259. *
  260. * If any port has noticed a Tx timeout, it is likely that the whole
  261. * device is munged, not just the one netdev port, so go for the full
  262. * reset.
  263. **/
  264. #ifdef I40E_FCOE
  265. void i40e_tx_timeout(struct net_device *netdev)
  266. #else
  267. static void i40e_tx_timeout(struct net_device *netdev)
  268. #endif
  269. {
  270. struct i40e_netdev_priv *np = netdev_priv(netdev);
  271. struct i40e_vsi *vsi = np->vsi;
  272. struct i40e_pf *pf = vsi->back;
  273. struct i40e_ring *tx_ring = NULL;
  274. unsigned int i, hung_queue = 0;
  275. u32 head, val;
  276. pf->tx_timeout_count++;
  277. /* find the stopped queue the same way the stack does */
  278. for (i = 0; i < netdev->num_tx_queues; i++) {
  279. struct netdev_queue *q;
  280. unsigned long trans_start;
  281. q = netdev_get_tx_queue(netdev, i);
  282. trans_start = q->trans_start;
  283. if (netif_xmit_stopped(q) &&
  284. time_after(jiffies,
  285. (trans_start + netdev->watchdog_timeo))) {
  286. hung_queue = i;
  287. break;
  288. }
  289. }
  290. if (i == netdev->num_tx_queues) {
  291. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  292. } else {
  293. /* now that we have an index, find the tx_ring struct */
  294. for (i = 0; i < vsi->num_queue_pairs; i++) {
  295. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  296. if (hung_queue ==
  297. vsi->tx_rings[i]->queue_index) {
  298. tx_ring = vsi->tx_rings[i];
  299. break;
  300. }
  301. }
  302. }
  303. }
  304. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  305. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  306. else if (time_before(jiffies,
  307. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  308. return; /* don't do any new action before the next timeout */
  309. if (tx_ring) {
  310. head = i40e_get_head(tx_ring);
  311. /* Read interrupt register */
  312. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  313. val = rd32(&pf->hw,
  314. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  315. tx_ring->vsi->base_vector - 1));
  316. else
  317. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  318. netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
  319. vsi->seid, hung_queue, tx_ring->next_to_clean,
  320. head, tx_ring->next_to_use,
  321. readl(tx_ring->tail), val);
  322. }
  323. pf->tx_timeout_last_recovery = jiffies;
  324. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  325. pf->tx_timeout_recovery_level, hung_queue);
  326. switch (pf->tx_timeout_recovery_level) {
  327. case 1:
  328. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  329. break;
  330. case 2:
  331. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  332. break;
  333. case 3:
  334. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  335. break;
  336. default:
  337. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  338. break;
  339. }
  340. i40e_service_event_schedule(pf);
  341. pf->tx_timeout_recovery_level++;
  342. }
  343. /**
  344. * i40e_get_vsi_stats_struct - Get System Network Statistics
  345. * @vsi: the VSI we care about
  346. *
  347. * Returns the address of the device statistics structure.
  348. * The statistics are actually updated from the service task.
  349. **/
  350. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  351. {
  352. return &vsi->net_stats;
  353. }
  354. /**
  355. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  356. * @netdev: network interface device structure
  357. *
  358. * Returns the address of the device statistics structure.
  359. * The statistics are actually updated from the service task.
  360. **/
  361. #ifdef I40E_FCOE
  362. struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  363. struct net_device *netdev,
  364. struct rtnl_link_stats64 *stats)
  365. #else
  366. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  367. struct net_device *netdev,
  368. struct rtnl_link_stats64 *stats)
  369. #endif
  370. {
  371. struct i40e_netdev_priv *np = netdev_priv(netdev);
  372. struct i40e_ring *tx_ring, *rx_ring;
  373. struct i40e_vsi *vsi = np->vsi;
  374. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  375. int i;
  376. if (test_bit(__I40E_DOWN, &vsi->state))
  377. return stats;
  378. if (!vsi->tx_rings)
  379. return stats;
  380. rcu_read_lock();
  381. for (i = 0; i < vsi->num_queue_pairs; i++) {
  382. u64 bytes, packets;
  383. unsigned int start;
  384. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  385. if (!tx_ring)
  386. continue;
  387. do {
  388. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  389. packets = tx_ring->stats.packets;
  390. bytes = tx_ring->stats.bytes;
  391. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  392. stats->tx_packets += packets;
  393. stats->tx_bytes += bytes;
  394. rx_ring = &tx_ring[1];
  395. do {
  396. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  397. packets = rx_ring->stats.packets;
  398. bytes = rx_ring->stats.bytes;
  399. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  400. stats->rx_packets += packets;
  401. stats->rx_bytes += bytes;
  402. }
  403. rcu_read_unlock();
  404. /* following stats updated by i40e_watchdog_subtask() */
  405. stats->multicast = vsi_stats->multicast;
  406. stats->tx_errors = vsi_stats->tx_errors;
  407. stats->tx_dropped = vsi_stats->tx_dropped;
  408. stats->rx_errors = vsi_stats->rx_errors;
  409. stats->rx_dropped = vsi_stats->rx_dropped;
  410. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  411. stats->rx_length_errors = vsi_stats->rx_length_errors;
  412. return stats;
  413. }
  414. /**
  415. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  416. * @vsi: the VSI to have its stats reset
  417. **/
  418. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  419. {
  420. struct rtnl_link_stats64 *ns;
  421. int i;
  422. if (!vsi)
  423. return;
  424. ns = i40e_get_vsi_stats_struct(vsi);
  425. memset(ns, 0, sizeof(*ns));
  426. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  427. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  428. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  429. if (vsi->rx_rings && vsi->rx_rings[0]) {
  430. for (i = 0; i < vsi->num_queue_pairs; i++) {
  431. memset(&vsi->rx_rings[i]->stats, 0,
  432. sizeof(vsi->rx_rings[i]->stats));
  433. memset(&vsi->rx_rings[i]->rx_stats, 0,
  434. sizeof(vsi->rx_rings[i]->rx_stats));
  435. memset(&vsi->tx_rings[i]->stats, 0,
  436. sizeof(vsi->tx_rings[i]->stats));
  437. memset(&vsi->tx_rings[i]->tx_stats, 0,
  438. sizeof(vsi->tx_rings[i]->tx_stats));
  439. }
  440. }
  441. vsi->stat_offsets_loaded = false;
  442. }
  443. /**
  444. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  445. * @pf: the PF to be reset
  446. **/
  447. void i40e_pf_reset_stats(struct i40e_pf *pf)
  448. {
  449. int i;
  450. memset(&pf->stats, 0, sizeof(pf->stats));
  451. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  452. pf->stat_offsets_loaded = false;
  453. for (i = 0; i < I40E_MAX_VEB; i++) {
  454. if (pf->veb[i]) {
  455. memset(&pf->veb[i]->stats, 0,
  456. sizeof(pf->veb[i]->stats));
  457. memset(&pf->veb[i]->stats_offsets, 0,
  458. sizeof(pf->veb[i]->stats_offsets));
  459. pf->veb[i]->stat_offsets_loaded = false;
  460. }
  461. }
  462. pf->hw_csum_rx_error = 0;
  463. }
  464. /**
  465. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  466. * @hw: ptr to the hardware info
  467. * @hireg: the high 32 bit reg to read
  468. * @loreg: the low 32 bit reg to read
  469. * @offset_loaded: has the initial offset been loaded yet
  470. * @offset: ptr to current offset value
  471. * @stat: ptr to the stat
  472. *
  473. * Since the device stats are not reset at PFReset, they likely will not
  474. * be zeroed when the driver starts. We'll save the first values read
  475. * and use them as offsets to be subtracted from the raw values in order
  476. * to report stats that count from zero. In the process, we also manage
  477. * the potential roll-over.
  478. **/
  479. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  480. bool offset_loaded, u64 *offset, u64 *stat)
  481. {
  482. u64 new_data;
  483. if (hw->device_id == I40E_DEV_ID_QEMU) {
  484. new_data = rd32(hw, loreg);
  485. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  486. } else {
  487. new_data = rd64(hw, loreg);
  488. }
  489. if (!offset_loaded)
  490. *offset = new_data;
  491. if (likely(new_data >= *offset))
  492. *stat = new_data - *offset;
  493. else
  494. *stat = (new_data + BIT_ULL(48)) - *offset;
  495. *stat &= 0xFFFFFFFFFFFFULL;
  496. }
  497. /**
  498. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  499. * @hw: ptr to the hardware info
  500. * @reg: the hw reg to read
  501. * @offset_loaded: has the initial offset been loaded yet
  502. * @offset: ptr to current offset value
  503. * @stat: ptr to the stat
  504. **/
  505. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  506. bool offset_loaded, u64 *offset, u64 *stat)
  507. {
  508. u32 new_data;
  509. new_data = rd32(hw, reg);
  510. if (!offset_loaded)
  511. *offset = new_data;
  512. if (likely(new_data >= *offset))
  513. *stat = (u32)(new_data - *offset);
  514. else
  515. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  516. }
  517. /**
  518. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  519. * @vsi: the VSI to be updated
  520. **/
  521. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  522. {
  523. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  524. struct i40e_pf *pf = vsi->back;
  525. struct i40e_hw *hw = &pf->hw;
  526. struct i40e_eth_stats *oes;
  527. struct i40e_eth_stats *es; /* device's eth stats */
  528. es = &vsi->eth_stats;
  529. oes = &vsi->eth_stats_offsets;
  530. /* Gather up the stats that the hw collects */
  531. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  532. vsi->stat_offsets_loaded,
  533. &oes->tx_errors, &es->tx_errors);
  534. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  535. vsi->stat_offsets_loaded,
  536. &oes->rx_discards, &es->rx_discards);
  537. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  538. vsi->stat_offsets_loaded,
  539. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  540. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  541. vsi->stat_offsets_loaded,
  542. &oes->tx_errors, &es->tx_errors);
  543. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  544. I40E_GLV_GORCL(stat_idx),
  545. vsi->stat_offsets_loaded,
  546. &oes->rx_bytes, &es->rx_bytes);
  547. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  548. I40E_GLV_UPRCL(stat_idx),
  549. vsi->stat_offsets_loaded,
  550. &oes->rx_unicast, &es->rx_unicast);
  551. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  552. I40E_GLV_MPRCL(stat_idx),
  553. vsi->stat_offsets_loaded,
  554. &oes->rx_multicast, &es->rx_multicast);
  555. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  556. I40E_GLV_BPRCL(stat_idx),
  557. vsi->stat_offsets_loaded,
  558. &oes->rx_broadcast, &es->rx_broadcast);
  559. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  560. I40E_GLV_GOTCL(stat_idx),
  561. vsi->stat_offsets_loaded,
  562. &oes->tx_bytes, &es->tx_bytes);
  563. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  564. I40E_GLV_UPTCL(stat_idx),
  565. vsi->stat_offsets_loaded,
  566. &oes->tx_unicast, &es->tx_unicast);
  567. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  568. I40E_GLV_MPTCL(stat_idx),
  569. vsi->stat_offsets_loaded,
  570. &oes->tx_multicast, &es->tx_multicast);
  571. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  572. I40E_GLV_BPTCL(stat_idx),
  573. vsi->stat_offsets_loaded,
  574. &oes->tx_broadcast, &es->tx_broadcast);
  575. vsi->stat_offsets_loaded = true;
  576. }
  577. /**
  578. * i40e_update_veb_stats - Update Switch component statistics
  579. * @veb: the VEB being updated
  580. **/
  581. static void i40e_update_veb_stats(struct i40e_veb *veb)
  582. {
  583. struct i40e_pf *pf = veb->pf;
  584. struct i40e_hw *hw = &pf->hw;
  585. struct i40e_eth_stats *oes;
  586. struct i40e_eth_stats *es; /* device's eth stats */
  587. struct i40e_veb_tc_stats *veb_oes;
  588. struct i40e_veb_tc_stats *veb_es;
  589. int i, idx = 0;
  590. idx = veb->stats_idx;
  591. es = &veb->stats;
  592. oes = &veb->stats_offsets;
  593. veb_es = &veb->tc_stats;
  594. veb_oes = &veb->tc_stats_offsets;
  595. /* Gather up the stats that the hw collects */
  596. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  597. veb->stat_offsets_loaded,
  598. &oes->tx_discards, &es->tx_discards);
  599. if (hw->revision_id > 0)
  600. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  601. veb->stat_offsets_loaded,
  602. &oes->rx_unknown_protocol,
  603. &es->rx_unknown_protocol);
  604. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  605. veb->stat_offsets_loaded,
  606. &oes->rx_bytes, &es->rx_bytes);
  607. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  608. veb->stat_offsets_loaded,
  609. &oes->rx_unicast, &es->rx_unicast);
  610. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  611. veb->stat_offsets_loaded,
  612. &oes->rx_multicast, &es->rx_multicast);
  613. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  614. veb->stat_offsets_loaded,
  615. &oes->rx_broadcast, &es->rx_broadcast);
  616. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  617. veb->stat_offsets_loaded,
  618. &oes->tx_bytes, &es->tx_bytes);
  619. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  620. veb->stat_offsets_loaded,
  621. &oes->tx_unicast, &es->tx_unicast);
  622. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  623. veb->stat_offsets_loaded,
  624. &oes->tx_multicast, &es->tx_multicast);
  625. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  626. veb->stat_offsets_loaded,
  627. &oes->tx_broadcast, &es->tx_broadcast);
  628. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  629. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  630. I40E_GLVEBTC_RPCL(i, idx),
  631. veb->stat_offsets_loaded,
  632. &veb_oes->tc_rx_packets[i],
  633. &veb_es->tc_rx_packets[i]);
  634. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  635. I40E_GLVEBTC_RBCL(i, idx),
  636. veb->stat_offsets_loaded,
  637. &veb_oes->tc_rx_bytes[i],
  638. &veb_es->tc_rx_bytes[i]);
  639. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  640. I40E_GLVEBTC_TPCL(i, idx),
  641. veb->stat_offsets_loaded,
  642. &veb_oes->tc_tx_packets[i],
  643. &veb_es->tc_tx_packets[i]);
  644. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  645. I40E_GLVEBTC_TBCL(i, idx),
  646. veb->stat_offsets_loaded,
  647. &veb_oes->tc_tx_bytes[i],
  648. &veb_es->tc_tx_bytes[i]);
  649. }
  650. veb->stat_offsets_loaded = true;
  651. }
  652. #ifdef I40E_FCOE
  653. /**
  654. * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
  655. * @vsi: the VSI that is capable of doing FCoE
  656. **/
  657. static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
  658. {
  659. struct i40e_pf *pf = vsi->back;
  660. struct i40e_hw *hw = &pf->hw;
  661. struct i40e_fcoe_stats *ofs;
  662. struct i40e_fcoe_stats *fs; /* device's eth stats */
  663. int idx;
  664. if (vsi->type != I40E_VSI_FCOE)
  665. return;
  666. idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
  667. fs = &vsi->fcoe_stats;
  668. ofs = &vsi->fcoe_stats_offsets;
  669. i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
  670. vsi->fcoe_stat_offsets_loaded,
  671. &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
  672. i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
  673. vsi->fcoe_stat_offsets_loaded,
  674. &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
  675. i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
  676. vsi->fcoe_stat_offsets_loaded,
  677. &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
  678. i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
  679. vsi->fcoe_stat_offsets_loaded,
  680. &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
  681. i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
  682. vsi->fcoe_stat_offsets_loaded,
  683. &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
  684. i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
  685. vsi->fcoe_stat_offsets_loaded,
  686. &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
  687. i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
  688. vsi->fcoe_stat_offsets_loaded,
  689. &ofs->fcoe_last_error, &fs->fcoe_last_error);
  690. i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
  691. vsi->fcoe_stat_offsets_loaded,
  692. &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
  693. vsi->fcoe_stat_offsets_loaded = true;
  694. }
  695. #endif
  696. /**
  697. * i40e_update_vsi_stats - Update the vsi statistics counters.
  698. * @vsi: the VSI to be updated
  699. *
  700. * There are a few instances where we store the same stat in a
  701. * couple of different structs. This is partly because we have
  702. * the netdev stats that need to be filled out, which is slightly
  703. * different from the "eth_stats" defined by the chip and used in
  704. * VF communications. We sort it out here.
  705. **/
  706. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  707. {
  708. struct i40e_pf *pf = vsi->back;
  709. struct rtnl_link_stats64 *ons;
  710. struct rtnl_link_stats64 *ns; /* netdev stats */
  711. struct i40e_eth_stats *oes;
  712. struct i40e_eth_stats *es; /* device's eth stats */
  713. u32 tx_restart, tx_busy;
  714. u64 tx_lost_interrupt;
  715. struct i40e_ring *p;
  716. u32 rx_page, rx_buf;
  717. u64 bytes, packets;
  718. unsigned int start;
  719. u64 tx_linearize;
  720. u64 tx_force_wb;
  721. u64 rx_p, rx_b;
  722. u64 tx_p, tx_b;
  723. u16 q;
  724. if (test_bit(__I40E_DOWN, &vsi->state) ||
  725. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  726. return;
  727. ns = i40e_get_vsi_stats_struct(vsi);
  728. ons = &vsi->net_stats_offsets;
  729. es = &vsi->eth_stats;
  730. oes = &vsi->eth_stats_offsets;
  731. /* Gather up the netdev and vsi stats that the driver collects
  732. * on the fly during packet processing
  733. */
  734. rx_b = rx_p = 0;
  735. tx_b = tx_p = 0;
  736. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  737. tx_lost_interrupt = 0;
  738. rx_page = 0;
  739. rx_buf = 0;
  740. rcu_read_lock();
  741. for (q = 0; q < vsi->num_queue_pairs; q++) {
  742. /* locate Tx ring */
  743. p = ACCESS_ONCE(vsi->tx_rings[q]);
  744. do {
  745. start = u64_stats_fetch_begin_irq(&p->syncp);
  746. packets = p->stats.packets;
  747. bytes = p->stats.bytes;
  748. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  749. tx_b += bytes;
  750. tx_p += packets;
  751. tx_restart += p->tx_stats.restart_queue;
  752. tx_busy += p->tx_stats.tx_busy;
  753. tx_linearize += p->tx_stats.tx_linearize;
  754. tx_force_wb += p->tx_stats.tx_force_wb;
  755. tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
  756. /* Rx queue is part of the same block as Tx queue */
  757. p = &p[1];
  758. do {
  759. start = u64_stats_fetch_begin_irq(&p->syncp);
  760. packets = p->stats.packets;
  761. bytes = p->stats.bytes;
  762. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  763. rx_b += bytes;
  764. rx_p += packets;
  765. rx_buf += p->rx_stats.alloc_buff_failed;
  766. rx_page += p->rx_stats.alloc_page_failed;
  767. }
  768. rcu_read_unlock();
  769. vsi->tx_restart = tx_restart;
  770. vsi->tx_busy = tx_busy;
  771. vsi->tx_linearize = tx_linearize;
  772. vsi->tx_force_wb = tx_force_wb;
  773. vsi->tx_lost_interrupt = tx_lost_interrupt;
  774. vsi->rx_page_failed = rx_page;
  775. vsi->rx_buf_failed = rx_buf;
  776. ns->rx_packets = rx_p;
  777. ns->rx_bytes = rx_b;
  778. ns->tx_packets = tx_p;
  779. ns->tx_bytes = tx_b;
  780. /* update netdev stats from eth stats */
  781. i40e_update_eth_stats(vsi);
  782. ons->tx_errors = oes->tx_errors;
  783. ns->tx_errors = es->tx_errors;
  784. ons->multicast = oes->rx_multicast;
  785. ns->multicast = es->rx_multicast;
  786. ons->rx_dropped = oes->rx_discards;
  787. ns->rx_dropped = es->rx_discards;
  788. ons->tx_dropped = oes->tx_discards;
  789. ns->tx_dropped = es->tx_discards;
  790. /* pull in a couple PF stats if this is the main vsi */
  791. if (vsi == pf->vsi[pf->lan_vsi]) {
  792. ns->rx_crc_errors = pf->stats.crc_errors;
  793. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  794. ns->rx_length_errors = pf->stats.rx_length_errors;
  795. }
  796. }
  797. /**
  798. * i40e_update_pf_stats - Update the PF statistics counters.
  799. * @pf: the PF to be updated
  800. **/
  801. static void i40e_update_pf_stats(struct i40e_pf *pf)
  802. {
  803. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  804. struct i40e_hw_port_stats *nsd = &pf->stats;
  805. struct i40e_hw *hw = &pf->hw;
  806. u32 val;
  807. int i;
  808. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  809. I40E_GLPRT_GORCL(hw->port),
  810. pf->stat_offsets_loaded,
  811. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  812. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  813. I40E_GLPRT_GOTCL(hw->port),
  814. pf->stat_offsets_loaded,
  815. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  816. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  817. pf->stat_offsets_loaded,
  818. &osd->eth.rx_discards,
  819. &nsd->eth.rx_discards);
  820. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  821. I40E_GLPRT_UPRCL(hw->port),
  822. pf->stat_offsets_loaded,
  823. &osd->eth.rx_unicast,
  824. &nsd->eth.rx_unicast);
  825. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  826. I40E_GLPRT_MPRCL(hw->port),
  827. pf->stat_offsets_loaded,
  828. &osd->eth.rx_multicast,
  829. &nsd->eth.rx_multicast);
  830. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  831. I40E_GLPRT_BPRCL(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->eth.rx_broadcast,
  834. &nsd->eth.rx_broadcast);
  835. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  836. I40E_GLPRT_UPTCL(hw->port),
  837. pf->stat_offsets_loaded,
  838. &osd->eth.tx_unicast,
  839. &nsd->eth.tx_unicast);
  840. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  841. I40E_GLPRT_MPTCL(hw->port),
  842. pf->stat_offsets_loaded,
  843. &osd->eth.tx_multicast,
  844. &nsd->eth.tx_multicast);
  845. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  846. I40E_GLPRT_BPTCL(hw->port),
  847. pf->stat_offsets_loaded,
  848. &osd->eth.tx_broadcast,
  849. &nsd->eth.tx_broadcast);
  850. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  851. pf->stat_offsets_loaded,
  852. &osd->tx_dropped_link_down,
  853. &nsd->tx_dropped_link_down);
  854. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  855. pf->stat_offsets_loaded,
  856. &osd->crc_errors, &nsd->crc_errors);
  857. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  858. pf->stat_offsets_loaded,
  859. &osd->illegal_bytes, &nsd->illegal_bytes);
  860. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  861. pf->stat_offsets_loaded,
  862. &osd->mac_local_faults,
  863. &nsd->mac_local_faults);
  864. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  865. pf->stat_offsets_loaded,
  866. &osd->mac_remote_faults,
  867. &nsd->mac_remote_faults);
  868. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  869. pf->stat_offsets_loaded,
  870. &osd->rx_length_errors,
  871. &nsd->rx_length_errors);
  872. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  873. pf->stat_offsets_loaded,
  874. &osd->link_xon_rx, &nsd->link_xon_rx);
  875. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  876. pf->stat_offsets_loaded,
  877. &osd->link_xon_tx, &nsd->link_xon_tx);
  878. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  879. pf->stat_offsets_loaded,
  880. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  881. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  882. pf->stat_offsets_loaded,
  883. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  884. for (i = 0; i < 8; i++) {
  885. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  886. pf->stat_offsets_loaded,
  887. &osd->priority_xoff_rx[i],
  888. &nsd->priority_xoff_rx[i]);
  889. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  890. pf->stat_offsets_loaded,
  891. &osd->priority_xon_rx[i],
  892. &nsd->priority_xon_rx[i]);
  893. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  894. pf->stat_offsets_loaded,
  895. &osd->priority_xon_tx[i],
  896. &nsd->priority_xon_tx[i]);
  897. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  898. pf->stat_offsets_loaded,
  899. &osd->priority_xoff_tx[i],
  900. &nsd->priority_xoff_tx[i]);
  901. i40e_stat_update32(hw,
  902. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  903. pf->stat_offsets_loaded,
  904. &osd->priority_xon_2_xoff[i],
  905. &nsd->priority_xon_2_xoff[i]);
  906. }
  907. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  908. I40E_GLPRT_PRC64L(hw->port),
  909. pf->stat_offsets_loaded,
  910. &osd->rx_size_64, &nsd->rx_size_64);
  911. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  912. I40E_GLPRT_PRC127L(hw->port),
  913. pf->stat_offsets_loaded,
  914. &osd->rx_size_127, &nsd->rx_size_127);
  915. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  916. I40E_GLPRT_PRC255L(hw->port),
  917. pf->stat_offsets_loaded,
  918. &osd->rx_size_255, &nsd->rx_size_255);
  919. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  920. I40E_GLPRT_PRC511L(hw->port),
  921. pf->stat_offsets_loaded,
  922. &osd->rx_size_511, &nsd->rx_size_511);
  923. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  924. I40E_GLPRT_PRC1023L(hw->port),
  925. pf->stat_offsets_loaded,
  926. &osd->rx_size_1023, &nsd->rx_size_1023);
  927. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  928. I40E_GLPRT_PRC1522L(hw->port),
  929. pf->stat_offsets_loaded,
  930. &osd->rx_size_1522, &nsd->rx_size_1522);
  931. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  932. I40E_GLPRT_PRC9522L(hw->port),
  933. pf->stat_offsets_loaded,
  934. &osd->rx_size_big, &nsd->rx_size_big);
  935. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  936. I40E_GLPRT_PTC64L(hw->port),
  937. pf->stat_offsets_loaded,
  938. &osd->tx_size_64, &nsd->tx_size_64);
  939. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  940. I40E_GLPRT_PTC127L(hw->port),
  941. pf->stat_offsets_loaded,
  942. &osd->tx_size_127, &nsd->tx_size_127);
  943. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  944. I40E_GLPRT_PTC255L(hw->port),
  945. pf->stat_offsets_loaded,
  946. &osd->tx_size_255, &nsd->tx_size_255);
  947. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  948. I40E_GLPRT_PTC511L(hw->port),
  949. pf->stat_offsets_loaded,
  950. &osd->tx_size_511, &nsd->tx_size_511);
  951. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  952. I40E_GLPRT_PTC1023L(hw->port),
  953. pf->stat_offsets_loaded,
  954. &osd->tx_size_1023, &nsd->tx_size_1023);
  955. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  956. I40E_GLPRT_PTC1522L(hw->port),
  957. pf->stat_offsets_loaded,
  958. &osd->tx_size_1522, &nsd->tx_size_1522);
  959. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  960. I40E_GLPRT_PTC9522L(hw->port),
  961. pf->stat_offsets_loaded,
  962. &osd->tx_size_big, &nsd->tx_size_big);
  963. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  964. pf->stat_offsets_loaded,
  965. &osd->rx_undersize, &nsd->rx_undersize);
  966. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  967. pf->stat_offsets_loaded,
  968. &osd->rx_fragments, &nsd->rx_fragments);
  969. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  970. pf->stat_offsets_loaded,
  971. &osd->rx_oversize, &nsd->rx_oversize);
  972. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  973. pf->stat_offsets_loaded,
  974. &osd->rx_jabber, &nsd->rx_jabber);
  975. /* FDIR stats */
  976. i40e_stat_update32(hw,
  977. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
  978. pf->stat_offsets_loaded,
  979. &osd->fd_atr_match, &nsd->fd_atr_match);
  980. i40e_stat_update32(hw,
  981. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
  982. pf->stat_offsets_loaded,
  983. &osd->fd_sb_match, &nsd->fd_sb_match);
  984. i40e_stat_update32(hw,
  985. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
  986. pf->stat_offsets_loaded,
  987. &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
  988. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  989. nsd->tx_lpi_status =
  990. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  991. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  992. nsd->rx_lpi_status =
  993. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  994. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  995. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  996. pf->stat_offsets_loaded,
  997. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  998. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  999. pf->stat_offsets_loaded,
  1000. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  1001. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  1002. !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
  1003. nsd->fd_sb_status = true;
  1004. else
  1005. nsd->fd_sb_status = false;
  1006. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  1007. !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
  1008. nsd->fd_atr_status = true;
  1009. else
  1010. nsd->fd_atr_status = false;
  1011. pf->stat_offsets_loaded = true;
  1012. }
  1013. /**
  1014. * i40e_update_stats - Update the various statistics counters.
  1015. * @vsi: the VSI to be updated
  1016. *
  1017. * Update the various stats for this VSI and its related entities.
  1018. **/
  1019. void i40e_update_stats(struct i40e_vsi *vsi)
  1020. {
  1021. struct i40e_pf *pf = vsi->back;
  1022. if (vsi == pf->vsi[pf->lan_vsi])
  1023. i40e_update_pf_stats(pf);
  1024. i40e_update_vsi_stats(vsi);
  1025. #ifdef I40E_FCOE
  1026. i40e_update_fcoe_stats(vsi);
  1027. #endif
  1028. }
  1029. /**
  1030. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1031. * @vsi: the VSI to be searched
  1032. * @macaddr: the MAC address
  1033. * @vlan: the vlan
  1034. * @is_vf: make sure its a VF filter, else doesn't matter
  1035. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1036. *
  1037. * Returns ptr to the filter object or NULL
  1038. **/
  1039. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1040. u8 *macaddr, s16 vlan,
  1041. bool is_vf, bool is_netdev)
  1042. {
  1043. struct i40e_mac_filter *f;
  1044. if (!vsi || !macaddr)
  1045. return NULL;
  1046. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1047. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1048. (vlan == f->vlan) &&
  1049. (!is_vf || f->is_vf) &&
  1050. (!is_netdev || f->is_netdev))
  1051. return f;
  1052. }
  1053. return NULL;
  1054. }
  1055. /**
  1056. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1057. * @vsi: the VSI to be searched
  1058. * @macaddr: the MAC address we are searching for
  1059. * @is_vf: make sure its a VF filter, else doesn't matter
  1060. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1061. *
  1062. * Returns the first filter with the provided MAC address or NULL if
  1063. * MAC address was not found
  1064. **/
  1065. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
  1066. bool is_vf, bool is_netdev)
  1067. {
  1068. struct i40e_mac_filter *f;
  1069. if (!vsi || !macaddr)
  1070. return NULL;
  1071. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1072. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1073. (!is_vf || f->is_vf) &&
  1074. (!is_netdev || f->is_netdev))
  1075. return f;
  1076. }
  1077. return NULL;
  1078. }
  1079. /**
  1080. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1081. * @vsi: the VSI to be searched
  1082. *
  1083. * Returns true if VSI is in vlan mode or false otherwise
  1084. **/
  1085. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1086. {
  1087. struct i40e_mac_filter *f;
  1088. /* Only -1 for all the filters denotes not in vlan mode
  1089. * so we have to go through all the list in order to make sure
  1090. */
  1091. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1092. if (f->vlan >= 0 || vsi->info.pvid)
  1093. return true;
  1094. }
  1095. return false;
  1096. }
  1097. /**
  1098. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  1099. * @vsi: the VSI to be searched
  1100. * @macaddr: the mac address to be filtered
  1101. * @is_vf: true if it is a VF
  1102. * @is_netdev: true if it is a netdev
  1103. *
  1104. * Goes through all the macvlan filters and adds a
  1105. * macvlan filter for each unique vlan that already exists
  1106. *
  1107. * Returns first filter found on success, else NULL
  1108. **/
  1109. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  1110. bool is_vf, bool is_netdev)
  1111. {
  1112. struct i40e_mac_filter *f;
  1113. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1114. if (vsi->info.pvid)
  1115. f->vlan = le16_to_cpu(vsi->info.pvid);
  1116. if (!i40e_find_filter(vsi, macaddr, f->vlan,
  1117. is_vf, is_netdev)) {
  1118. if (!i40e_add_filter(vsi, macaddr, f->vlan,
  1119. is_vf, is_netdev))
  1120. return NULL;
  1121. }
  1122. }
  1123. return list_first_entry_or_null(&vsi->mac_filter_list,
  1124. struct i40e_mac_filter, list);
  1125. }
  1126. /**
  1127. * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
  1128. * @vsi: the VSI to be searched
  1129. * @macaddr: the mac address to be removed
  1130. * @is_vf: true if it is a VF
  1131. * @is_netdev: true if it is a netdev
  1132. *
  1133. * Removes a given MAC address from a VSI, regardless of VLAN
  1134. *
  1135. * Returns 0 for success, or error
  1136. **/
  1137. int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  1138. bool is_vf, bool is_netdev)
  1139. {
  1140. struct i40e_mac_filter *f = NULL;
  1141. int changed = 0;
  1142. WARN(!spin_is_locked(&vsi->mac_filter_list_lock),
  1143. "Missing mac_filter_list_lock\n");
  1144. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1145. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1146. (is_vf == f->is_vf) &&
  1147. (is_netdev == f->is_netdev)) {
  1148. f->counter--;
  1149. changed = 1;
  1150. if (f->counter == 0)
  1151. f->state = I40E_FILTER_REMOVE;
  1152. }
  1153. }
  1154. if (changed) {
  1155. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1156. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1157. return 0;
  1158. }
  1159. return -ENOENT;
  1160. }
  1161. /**
  1162. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1163. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1164. * @macaddr: the MAC address
  1165. *
  1166. * Remove whatever filter the firmware set up so the driver can manage
  1167. * its own filtering intelligently.
  1168. **/
  1169. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1170. {
  1171. struct i40e_aqc_remove_macvlan_element_data element;
  1172. struct i40e_pf *pf = vsi->back;
  1173. /* Only appropriate for the PF main VSI */
  1174. if (vsi->type != I40E_VSI_MAIN)
  1175. return;
  1176. memset(&element, 0, sizeof(element));
  1177. ether_addr_copy(element.mac_addr, macaddr);
  1178. element.vlan_tag = 0;
  1179. /* Ignore error returns, some firmware does it this way... */
  1180. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1181. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1182. memset(&element, 0, sizeof(element));
  1183. ether_addr_copy(element.mac_addr, macaddr);
  1184. element.vlan_tag = 0;
  1185. /* ...and some firmware does it this way. */
  1186. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1187. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1188. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1189. }
  1190. /**
  1191. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1192. * @vsi: the VSI to be searched
  1193. * @macaddr: the MAC address
  1194. * @vlan: the vlan
  1195. * @is_vf: make sure its a VF filter, else doesn't matter
  1196. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1197. *
  1198. * Returns ptr to the filter object or NULL when no memory available.
  1199. *
  1200. * NOTE: This function is expected to be called with mac_filter_list_lock
  1201. * being held.
  1202. **/
  1203. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1204. u8 *macaddr, s16 vlan,
  1205. bool is_vf, bool is_netdev)
  1206. {
  1207. struct i40e_mac_filter *f;
  1208. int changed = false;
  1209. if (!vsi || !macaddr)
  1210. return NULL;
  1211. /* Do not allow broadcast filter to be added since broadcast filter
  1212. * is added as part of add VSI for any newly created VSI except
  1213. * FDIR VSI
  1214. */
  1215. if (is_broadcast_ether_addr(macaddr))
  1216. return NULL;
  1217. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1218. if (!f) {
  1219. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1220. if (!f)
  1221. goto add_filter_out;
  1222. ether_addr_copy(f->macaddr, macaddr);
  1223. f->vlan = vlan;
  1224. /* If we're in overflow promisc mode, set the state directly
  1225. * to failed, so we don't bother to try sending the filter
  1226. * to the hardware.
  1227. */
  1228. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))
  1229. f->state = I40E_FILTER_FAILED;
  1230. else
  1231. f->state = I40E_FILTER_NEW;
  1232. changed = true;
  1233. INIT_LIST_HEAD(&f->list);
  1234. list_add_tail(&f->list, &vsi->mac_filter_list);
  1235. }
  1236. /* increment counter and add a new flag if needed */
  1237. if (is_vf) {
  1238. if (!f->is_vf) {
  1239. f->is_vf = true;
  1240. f->counter++;
  1241. }
  1242. } else if (is_netdev) {
  1243. if (!f->is_netdev) {
  1244. f->is_netdev = true;
  1245. f->counter++;
  1246. }
  1247. } else {
  1248. f->counter++;
  1249. }
  1250. if (changed) {
  1251. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1252. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1253. }
  1254. add_filter_out:
  1255. return f;
  1256. }
  1257. /**
  1258. * i40e_del_filter - Remove a mac/vlan filter from the VSI
  1259. * @vsi: the VSI to be searched
  1260. * @macaddr: the MAC address
  1261. * @vlan: the vlan
  1262. * @is_vf: make sure it's a VF filter, else doesn't matter
  1263. * @is_netdev: make sure it's a netdev filter, else doesn't matter
  1264. *
  1265. * NOTE: This function is expected to be called with mac_filter_list_lock
  1266. * being held.
  1267. * ANOTHER NOTE: This function MUST be called from within the context of
  1268. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1269. * instead of list_for_each_entry().
  1270. **/
  1271. void i40e_del_filter(struct i40e_vsi *vsi,
  1272. u8 *macaddr, s16 vlan,
  1273. bool is_vf, bool is_netdev)
  1274. {
  1275. struct i40e_mac_filter *f;
  1276. if (!vsi || !macaddr)
  1277. return;
  1278. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1279. if (!f || f->counter == 0)
  1280. return;
  1281. if (is_vf) {
  1282. if (f->is_vf) {
  1283. f->is_vf = false;
  1284. f->counter--;
  1285. }
  1286. } else if (is_netdev) {
  1287. if (f->is_netdev) {
  1288. f->is_netdev = false;
  1289. f->counter--;
  1290. }
  1291. } else {
  1292. /* make sure we don't remove a filter in use by VF or netdev */
  1293. int min_f = 0;
  1294. min_f += (f->is_vf ? 1 : 0);
  1295. min_f += (f->is_netdev ? 1 : 0);
  1296. if (f->counter > min_f)
  1297. f->counter--;
  1298. }
  1299. /* counter == 0 tells sync_filters_subtask to
  1300. * remove the filter from the firmware's list
  1301. */
  1302. if (f->counter == 0) {
  1303. if ((f->state == I40E_FILTER_FAILED) ||
  1304. (f->state == I40E_FILTER_NEW)) {
  1305. /* this one never got added by the FW. Just remove it,
  1306. * no need to sync anything.
  1307. */
  1308. list_del(&f->list);
  1309. kfree(f);
  1310. } else {
  1311. f->state = I40E_FILTER_REMOVE;
  1312. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1313. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1314. }
  1315. }
  1316. }
  1317. /**
  1318. * i40e_set_mac - NDO callback to set mac address
  1319. * @netdev: network interface device structure
  1320. * @p: pointer to an address structure
  1321. *
  1322. * Returns 0 on success, negative on failure
  1323. **/
  1324. #ifdef I40E_FCOE
  1325. int i40e_set_mac(struct net_device *netdev, void *p)
  1326. #else
  1327. static int i40e_set_mac(struct net_device *netdev, void *p)
  1328. #endif
  1329. {
  1330. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1331. struct i40e_vsi *vsi = np->vsi;
  1332. struct i40e_pf *pf = vsi->back;
  1333. struct i40e_hw *hw = &pf->hw;
  1334. struct sockaddr *addr = p;
  1335. if (!is_valid_ether_addr(addr->sa_data))
  1336. return -EADDRNOTAVAIL;
  1337. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1338. netdev_info(netdev, "already using mac address %pM\n",
  1339. addr->sa_data);
  1340. return 0;
  1341. }
  1342. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1343. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1344. return -EADDRNOTAVAIL;
  1345. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1346. netdev_info(netdev, "returning to hw mac address %pM\n",
  1347. hw->mac.addr);
  1348. else
  1349. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1350. spin_lock_bh(&vsi->mac_filter_list_lock);
  1351. i40e_del_mac_all_vlan(vsi, netdev->dev_addr, false, true);
  1352. i40e_put_mac_in_vlan(vsi, addr->sa_data, false, true);
  1353. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1354. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1355. if (vsi->type == I40E_VSI_MAIN) {
  1356. i40e_status ret;
  1357. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1358. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1359. addr->sa_data, NULL);
  1360. if (ret)
  1361. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1362. i40e_stat_str(hw, ret),
  1363. i40e_aq_str(hw, hw->aq.asq_last_status));
  1364. }
  1365. /* schedule our worker thread which will take care of
  1366. * applying the new filter changes
  1367. */
  1368. i40e_service_event_schedule(vsi->back);
  1369. return 0;
  1370. }
  1371. /**
  1372. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1373. * @vsi: the VSI being setup
  1374. * @ctxt: VSI context structure
  1375. * @enabled_tc: Enabled TCs bitmap
  1376. * @is_add: True if called before Add VSI
  1377. *
  1378. * Setup VSI queue mapping for enabled traffic classes.
  1379. **/
  1380. #ifdef I40E_FCOE
  1381. void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1382. struct i40e_vsi_context *ctxt,
  1383. u8 enabled_tc,
  1384. bool is_add)
  1385. #else
  1386. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1387. struct i40e_vsi_context *ctxt,
  1388. u8 enabled_tc,
  1389. bool is_add)
  1390. #endif
  1391. {
  1392. struct i40e_pf *pf = vsi->back;
  1393. u16 sections = 0;
  1394. u8 netdev_tc = 0;
  1395. u16 numtc = 0;
  1396. u16 qcount;
  1397. u8 offset;
  1398. u16 qmap;
  1399. int i;
  1400. u16 num_tc_qps = 0;
  1401. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1402. offset = 0;
  1403. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1404. /* Find numtc from enabled TC bitmap */
  1405. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1406. if (enabled_tc & BIT(i)) /* TC is enabled */
  1407. numtc++;
  1408. }
  1409. if (!numtc) {
  1410. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1411. numtc = 1;
  1412. }
  1413. } else {
  1414. /* At least TC0 is enabled in case of non-DCB case */
  1415. numtc = 1;
  1416. }
  1417. vsi->tc_config.numtc = numtc;
  1418. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1419. /* Number of queues per enabled TC */
  1420. qcount = vsi->alloc_queue_pairs;
  1421. num_tc_qps = qcount / numtc;
  1422. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1423. /* Setup queue offset/count for all TCs for given VSI */
  1424. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1425. /* See if the given TC is enabled for the given VSI */
  1426. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1427. /* TC is enabled */
  1428. int pow, num_qps;
  1429. switch (vsi->type) {
  1430. case I40E_VSI_MAIN:
  1431. qcount = min_t(int, pf->alloc_rss_size,
  1432. num_tc_qps);
  1433. break;
  1434. #ifdef I40E_FCOE
  1435. case I40E_VSI_FCOE:
  1436. qcount = num_tc_qps;
  1437. break;
  1438. #endif
  1439. case I40E_VSI_FDIR:
  1440. case I40E_VSI_SRIOV:
  1441. case I40E_VSI_VMDQ2:
  1442. default:
  1443. qcount = num_tc_qps;
  1444. WARN_ON(i != 0);
  1445. break;
  1446. }
  1447. vsi->tc_config.tc_info[i].qoffset = offset;
  1448. vsi->tc_config.tc_info[i].qcount = qcount;
  1449. /* find the next higher power-of-2 of num queue pairs */
  1450. num_qps = qcount;
  1451. pow = 0;
  1452. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1453. pow++;
  1454. num_qps >>= 1;
  1455. }
  1456. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1457. qmap =
  1458. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1459. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1460. offset += qcount;
  1461. } else {
  1462. /* TC is not enabled so set the offset to
  1463. * default queue and allocate one queue
  1464. * for the given TC.
  1465. */
  1466. vsi->tc_config.tc_info[i].qoffset = 0;
  1467. vsi->tc_config.tc_info[i].qcount = 1;
  1468. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1469. qmap = 0;
  1470. }
  1471. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1472. }
  1473. /* Set actual Tx/Rx queue pairs */
  1474. vsi->num_queue_pairs = offset;
  1475. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1476. if (vsi->req_queue_pairs > 0)
  1477. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1478. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1479. vsi->num_queue_pairs = pf->num_lan_msix;
  1480. }
  1481. /* Scheduler section valid can only be set for ADD VSI */
  1482. if (is_add) {
  1483. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1484. ctxt->info.up_enable_bits = enabled_tc;
  1485. }
  1486. if (vsi->type == I40E_VSI_SRIOV) {
  1487. ctxt->info.mapping_flags |=
  1488. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1489. for (i = 0; i < vsi->num_queue_pairs; i++)
  1490. ctxt->info.queue_mapping[i] =
  1491. cpu_to_le16(vsi->base_queue + i);
  1492. } else {
  1493. ctxt->info.mapping_flags |=
  1494. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1495. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1496. }
  1497. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1498. }
  1499. /**
  1500. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1501. * @netdev: network interface device structure
  1502. **/
  1503. #ifdef I40E_FCOE
  1504. void i40e_set_rx_mode(struct net_device *netdev)
  1505. #else
  1506. static void i40e_set_rx_mode(struct net_device *netdev)
  1507. #endif
  1508. {
  1509. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1510. struct i40e_mac_filter *f, *ftmp;
  1511. struct i40e_vsi *vsi = np->vsi;
  1512. struct netdev_hw_addr *uca;
  1513. struct netdev_hw_addr *mca;
  1514. struct netdev_hw_addr *ha;
  1515. spin_lock_bh(&vsi->mac_filter_list_lock);
  1516. /* add addr if not already in the filter list */
  1517. netdev_for_each_uc_addr(uca, netdev) {
  1518. if (!i40e_find_mac(vsi, uca->addr, false, true)) {
  1519. if (i40e_is_vsi_in_vlan(vsi))
  1520. i40e_put_mac_in_vlan(vsi, uca->addr,
  1521. false, true);
  1522. else
  1523. i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
  1524. false, true);
  1525. }
  1526. }
  1527. netdev_for_each_mc_addr(mca, netdev) {
  1528. if (!i40e_find_mac(vsi, mca->addr, false, true)) {
  1529. if (i40e_is_vsi_in_vlan(vsi))
  1530. i40e_put_mac_in_vlan(vsi, mca->addr,
  1531. false, true);
  1532. else
  1533. i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
  1534. false, true);
  1535. }
  1536. }
  1537. /* remove filter if not in netdev list */
  1538. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1539. if (!f->is_netdev)
  1540. continue;
  1541. netdev_for_each_mc_addr(mca, netdev)
  1542. if (ether_addr_equal(mca->addr, f->macaddr))
  1543. goto bottom_of_search_loop;
  1544. netdev_for_each_uc_addr(uca, netdev)
  1545. if (ether_addr_equal(uca->addr, f->macaddr))
  1546. goto bottom_of_search_loop;
  1547. for_each_dev_addr(netdev, ha)
  1548. if (ether_addr_equal(ha->addr, f->macaddr))
  1549. goto bottom_of_search_loop;
  1550. /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
  1551. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
  1552. bottom_of_search_loop:
  1553. continue;
  1554. }
  1555. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1556. /* check for other flag changes */
  1557. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1558. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1559. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1560. }
  1561. /* schedule our worker thread which will take care of
  1562. * applying the new filter changes
  1563. */
  1564. i40e_service_event_schedule(vsi->back);
  1565. }
  1566. /**
  1567. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1568. * @vsi: pointer to vsi struct
  1569. * @from: Pointer to list which contains MAC filter entries - changes to
  1570. * those entries needs to be undone.
  1571. *
  1572. * MAC filter entries from list were slated to be removed from device.
  1573. **/
  1574. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1575. struct list_head *from)
  1576. {
  1577. struct i40e_mac_filter *f, *ftmp;
  1578. list_for_each_entry_safe(f, ftmp, from, list) {
  1579. /* Move the element back into MAC filter list*/
  1580. list_move_tail(&f->list, &vsi->mac_filter_list);
  1581. }
  1582. }
  1583. /**
  1584. * i40e_update_filter_state - Update filter state based on return data
  1585. * from firmware
  1586. * @count: Number of filters added
  1587. * @add_list: return data from fw
  1588. * @head: pointer to first filter in current batch
  1589. * @aq_err: status from fw
  1590. *
  1591. * MAC filter entries from list were slated to be added to device. Returns
  1592. * number of successful filters. Note that 0 does NOT mean success!
  1593. **/
  1594. static int
  1595. i40e_update_filter_state(int count,
  1596. struct i40e_aqc_add_macvlan_element_data *add_list,
  1597. struct i40e_mac_filter *add_head, int aq_err)
  1598. {
  1599. int retval = 0;
  1600. int i;
  1601. if (!aq_err) {
  1602. retval = count;
  1603. /* Everything's good, mark all filters active. */
  1604. for (i = 0; i < count ; i++) {
  1605. add_head->state = I40E_FILTER_ACTIVE;
  1606. add_head = list_next_entry(add_head, list);
  1607. }
  1608. } else if (aq_err == I40E_AQ_RC_ENOSPC) {
  1609. /* Device ran out of filter space. Check the return value
  1610. * for each filter to see which ones are active.
  1611. */
  1612. for (i = 0; i < count ; i++) {
  1613. if (add_list[i].match_method ==
  1614. I40E_AQC_MM_ERR_NO_RES) {
  1615. add_head->state = I40E_FILTER_FAILED;
  1616. } else {
  1617. add_head->state = I40E_FILTER_ACTIVE;
  1618. retval++;
  1619. }
  1620. add_head = list_next_entry(add_head, list);
  1621. }
  1622. } else {
  1623. /* Some other horrible thing happened, fail all filters */
  1624. retval = 0;
  1625. for (i = 0; i < count ; i++) {
  1626. add_head->state = I40E_FILTER_FAILED;
  1627. add_head = list_next_entry(add_head, list);
  1628. }
  1629. }
  1630. return retval;
  1631. }
  1632. /**
  1633. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1634. * @vsi: ptr to the VSI
  1635. *
  1636. * Push any outstanding VSI filter changes through the AdminQ.
  1637. *
  1638. * Returns 0 or error value
  1639. **/
  1640. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1641. {
  1642. struct i40e_mac_filter *f, *ftmp, *add_head = NULL;
  1643. struct list_head tmp_add_list, tmp_del_list;
  1644. struct i40e_hw *hw = &vsi->back->hw;
  1645. bool promisc_changed = false;
  1646. char vsi_name[16] = "PF";
  1647. int filter_list_len = 0;
  1648. u32 changed_flags = 0;
  1649. i40e_status aq_ret = 0;
  1650. int retval = 0;
  1651. struct i40e_pf *pf;
  1652. int num_add = 0;
  1653. int num_del = 0;
  1654. int aq_err = 0;
  1655. u16 cmd_flags;
  1656. int list_size;
  1657. int fcnt;
  1658. /* empty array typed pointers, kcalloc later */
  1659. struct i40e_aqc_add_macvlan_element_data *add_list;
  1660. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1661. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1662. usleep_range(1000, 2000);
  1663. pf = vsi->back;
  1664. if (vsi->netdev) {
  1665. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1666. vsi->current_netdev_flags = vsi->netdev->flags;
  1667. }
  1668. INIT_LIST_HEAD(&tmp_add_list);
  1669. INIT_LIST_HEAD(&tmp_del_list);
  1670. if (vsi->type == I40E_VSI_SRIOV)
  1671. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  1672. else if (vsi->type != I40E_VSI_MAIN)
  1673. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  1674. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1675. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1676. spin_lock_bh(&vsi->mac_filter_list_lock);
  1677. /* Create a list of filters to delete. */
  1678. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1679. if (f->state == I40E_FILTER_REMOVE) {
  1680. WARN_ON(f->counter != 0);
  1681. /* Move the element into temporary del_list */
  1682. list_move_tail(&f->list, &tmp_del_list);
  1683. vsi->active_filters--;
  1684. }
  1685. if (f->state == I40E_FILTER_NEW) {
  1686. WARN_ON(f->counter == 0);
  1687. /* Move the element into temporary add_list */
  1688. list_move_tail(&f->list, &tmp_add_list);
  1689. }
  1690. }
  1691. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1692. }
  1693. /* Now process 'del_list' outside the lock */
  1694. if (!list_empty(&tmp_del_list)) {
  1695. filter_list_len = hw->aq.asq_buf_size /
  1696. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1697. list_size = filter_list_len *
  1698. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1699. del_list = kzalloc(list_size, GFP_ATOMIC);
  1700. if (!del_list) {
  1701. /* Undo VSI's MAC filter entry element updates */
  1702. spin_lock_bh(&vsi->mac_filter_list_lock);
  1703. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  1704. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1705. retval = -ENOMEM;
  1706. goto out;
  1707. }
  1708. list_for_each_entry_safe(f, ftmp, &tmp_del_list, list) {
  1709. cmd_flags = 0;
  1710. /* add to delete list */
  1711. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1712. if (f->vlan == I40E_VLAN_ANY) {
  1713. del_list[num_del].vlan_tag = 0;
  1714. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1715. } else {
  1716. del_list[num_del].vlan_tag =
  1717. cpu_to_le16((u16)(f->vlan));
  1718. }
  1719. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1720. del_list[num_del].flags = cmd_flags;
  1721. num_del++;
  1722. /* flush a full buffer */
  1723. if (num_del == filter_list_len) {
  1724. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid,
  1725. del_list,
  1726. num_del, NULL);
  1727. aq_err = hw->aq.asq_last_status;
  1728. num_del = 0;
  1729. memset(del_list, 0, list_size);
  1730. /* Explicitly ignore and do not report when
  1731. * firmware returns ENOENT.
  1732. */
  1733. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1734. retval = -EIO;
  1735. dev_info(&pf->pdev->dev,
  1736. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1737. vsi_name,
  1738. i40e_stat_str(hw, aq_ret),
  1739. i40e_aq_str(hw, aq_err));
  1740. }
  1741. }
  1742. /* Release memory for MAC filter entries which were
  1743. * synced up with HW.
  1744. */
  1745. list_del(&f->list);
  1746. kfree(f);
  1747. }
  1748. if (num_del) {
  1749. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list,
  1750. num_del, NULL);
  1751. aq_err = hw->aq.asq_last_status;
  1752. num_del = 0;
  1753. /* Explicitly ignore and do not report when firmware
  1754. * returns ENOENT.
  1755. */
  1756. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1757. retval = -EIO;
  1758. dev_info(&pf->pdev->dev,
  1759. "ignoring delete macvlan error on %s, err %s aq_err %s\n",
  1760. vsi_name,
  1761. i40e_stat_str(hw, aq_ret),
  1762. i40e_aq_str(hw, aq_err));
  1763. }
  1764. }
  1765. kfree(del_list);
  1766. del_list = NULL;
  1767. }
  1768. if (!list_empty(&tmp_add_list)) {
  1769. /* Do all the adds now. */
  1770. filter_list_len = hw->aq.asq_buf_size /
  1771. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1772. list_size = filter_list_len *
  1773. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1774. add_list = kzalloc(list_size, GFP_ATOMIC);
  1775. if (!add_list) {
  1776. retval = -ENOMEM;
  1777. goto out;
  1778. }
  1779. num_add = 0;
  1780. list_for_each_entry(f, &tmp_add_list, list) {
  1781. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1782. &vsi->state)) {
  1783. f->state = I40E_FILTER_FAILED;
  1784. continue;
  1785. }
  1786. /* add to add array */
  1787. if (num_add == 0)
  1788. add_head = f;
  1789. cmd_flags = 0;
  1790. ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
  1791. if (f->vlan == I40E_VLAN_ANY) {
  1792. add_list[num_add].vlan_tag = 0;
  1793. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  1794. } else {
  1795. add_list[num_add].vlan_tag =
  1796. cpu_to_le16((u16)(f->vlan));
  1797. }
  1798. add_list[num_add].queue_number = 0;
  1799. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1800. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1801. num_add++;
  1802. /* flush a full buffer */
  1803. if (num_add == filter_list_len) {
  1804. aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
  1805. add_list, num_add,
  1806. NULL);
  1807. aq_err = hw->aq.asq_last_status;
  1808. fcnt = i40e_update_filter_state(num_add,
  1809. add_list,
  1810. add_head,
  1811. aq_ret);
  1812. vsi->active_filters += fcnt;
  1813. if (fcnt != num_add) {
  1814. promisc_changed = true;
  1815. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1816. &vsi->state);
  1817. vsi->promisc_threshold =
  1818. (vsi->active_filters * 3) / 4;
  1819. dev_warn(&pf->pdev->dev,
  1820. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1821. i40e_aq_str(hw, aq_err),
  1822. vsi_name);
  1823. }
  1824. memset(add_list, 0, list_size);
  1825. num_add = 0;
  1826. }
  1827. }
  1828. if (num_add) {
  1829. aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
  1830. add_list, num_add, NULL);
  1831. aq_err = hw->aq.asq_last_status;
  1832. fcnt = i40e_update_filter_state(num_add, add_list,
  1833. add_head, aq_ret);
  1834. vsi->active_filters += fcnt;
  1835. if (fcnt != num_add) {
  1836. promisc_changed = true;
  1837. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1838. &vsi->state);
  1839. vsi->promisc_threshold =
  1840. (vsi->active_filters * 3) / 4;
  1841. dev_warn(&pf->pdev->dev,
  1842. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1843. i40e_aq_str(hw, aq_err), vsi_name);
  1844. }
  1845. }
  1846. /* Now move all of the filters from the temp add list back to
  1847. * the VSI's list.
  1848. */
  1849. spin_lock_bh(&vsi->mac_filter_list_lock);
  1850. list_for_each_entry_safe(f, ftmp, &tmp_add_list, list) {
  1851. list_move_tail(&f->list, &vsi->mac_filter_list);
  1852. }
  1853. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1854. kfree(add_list);
  1855. add_list = NULL;
  1856. }
  1857. /* Check to see if we can drop out of overflow promiscuous mode. */
  1858. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) &&
  1859. (vsi->active_filters < vsi->promisc_threshold)) {
  1860. int failed_count = 0;
  1861. /* See if we have any failed filters. We can't drop out of
  1862. * promiscuous until these have all been deleted.
  1863. */
  1864. spin_lock_bh(&vsi->mac_filter_list_lock);
  1865. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1866. if (f->state == I40E_FILTER_FAILED)
  1867. failed_count++;
  1868. }
  1869. spin_unlock_bh(&vsi->mac_filter_list_lock);
  1870. if (!failed_count) {
  1871. dev_info(&pf->pdev->dev,
  1872. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  1873. vsi_name);
  1874. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  1875. promisc_changed = true;
  1876. vsi->promisc_threshold = 0;
  1877. }
  1878. }
  1879. /* if the VF is not trusted do not do promisc */
  1880. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  1881. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  1882. goto out;
  1883. }
  1884. /* check for changes in promiscuous modes */
  1885. if (changed_flags & IFF_ALLMULTI) {
  1886. bool cur_multipromisc;
  1887. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  1888. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  1889. vsi->seid,
  1890. cur_multipromisc,
  1891. NULL);
  1892. if (aq_ret) {
  1893. retval = i40e_aq_rc_to_posix(aq_ret,
  1894. hw->aq.asq_last_status);
  1895. dev_info(&pf->pdev->dev,
  1896. "set multi promisc failed on %s, err %s aq_err %s\n",
  1897. vsi_name,
  1898. i40e_stat_str(hw, aq_ret),
  1899. i40e_aq_str(hw, hw->aq.asq_last_status));
  1900. }
  1901. }
  1902. if ((changed_flags & IFF_PROMISC) ||
  1903. (promisc_changed &&
  1904. test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) {
  1905. bool cur_promisc;
  1906. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  1907. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1908. &vsi->state));
  1909. if ((vsi->type == I40E_VSI_MAIN) &&
  1910. (pf->lan_veb != I40E_NO_VEB) &&
  1911. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  1912. /* set defport ON for Main VSI instead of true promisc
  1913. * this way we will get all unicast/multicast and VLAN
  1914. * promisc behavior but will not get VF or VMDq traffic
  1915. * replicated on the Main VSI.
  1916. */
  1917. if (pf->cur_promisc != cur_promisc) {
  1918. pf->cur_promisc = cur_promisc;
  1919. if (cur_promisc)
  1920. aq_ret =
  1921. i40e_aq_set_default_vsi(hw,
  1922. vsi->seid,
  1923. NULL);
  1924. else
  1925. aq_ret =
  1926. i40e_aq_clear_default_vsi(hw,
  1927. vsi->seid,
  1928. NULL);
  1929. if (aq_ret) {
  1930. retval = i40e_aq_rc_to_posix(aq_ret,
  1931. hw->aq.asq_last_status);
  1932. dev_info(&pf->pdev->dev,
  1933. "Set default VSI failed on %s, err %s, aq_err %s\n",
  1934. vsi_name,
  1935. i40e_stat_str(hw, aq_ret),
  1936. i40e_aq_str(hw,
  1937. hw->aq.asq_last_status));
  1938. }
  1939. }
  1940. } else {
  1941. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  1942. hw,
  1943. vsi->seid,
  1944. cur_promisc, NULL,
  1945. true);
  1946. if (aq_ret) {
  1947. retval =
  1948. i40e_aq_rc_to_posix(aq_ret,
  1949. hw->aq.asq_last_status);
  1950. dev_info(&pf->pdev->dev,
  1951. "set unicast promisc failed on %s, err %s, aq_err %s\n",
  1952. vsi_name,
  1953. i40e_stat_str(hw, aq_ret),
  1954. i40e_aq_str(hw,
  1955. hw->aq.asq_last_status));
  1956. }
  1957. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  1958. hw,
  1959. vsi->seid,
  1960. cur_promisc, NULL);
  1961. if (aq_ret) {
  1962. retval =
  1963. i40e_aq_rc_to_posix(aq_ret,
  1964. hw->aq.asq_last_status);
  1965. dev_info(&pf->pdev->dev,
  1966. "set multicast promisc failed on %s, err %s, aq_err %s\n",
  1967. vsi_name,
  1968. i40e_stat_str(hw, aq_ret),
  1969. i40e_aq_str(hw,
  1970. hw->aq.asq_last_status));
  1971. }
  1972. }
  1973. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  1974. vsi->seid,
  1975. cur_promisc, NULL);
  1976. if (aq_ret) {
  1977. retval = i40e_aq_rc_to_posix(aq_ret,
  1978. pf->hw.aq.asq_last_status);
  1979. dev_info(&pf->pdev->dev,
  1980. "set brdcast promisc failed, err %s, aq_err %s\n",
  1981. i40e_stat_str(hw, aq_ret),
  1982. i40e_aq_str(hw,
  1983. hw->aq.asq_last_status));
  1984. }
  1985. }
  1986. out:
  1987. /* if something went wrong then set the changed flag so we try again */
  1988. if (retval)
  1989. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1990. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  1991. return retval;
  1992. }
  1993. /**
  1994. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  1995. * @pf: board private structure
  1996. **/
  1997. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  1998. {
  1999. int v;
  2000. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2001. return;
  2002. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2003. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2004. if (pf->vsi[v] &&
  2005. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2006. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2007. if (ret) {
  2008. /* come back and try again later */
  2009. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2010. break;
  2011. }
  2012. }
  2013. }
  2014. }
  2015. /**
  2016. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2017. * @netdev: network interface device structure
  2018. * @new_mtu: new value for maximum frame size
  2019. *
  2020. * Returns 0 on success, negative on failure
  2021. **/
  2022. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2023. {
  2024. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2025. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  2026. struct i40e_vsi *vsi = np->vsi;
  2027. /* MTU < 68 is an error and causes problems on some kernels */
  2028. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  2029. return -EINVAL;
  2030. netdev_info(netdev, "changing MTU from %d to %d\n",
  2031. netdev->mtu, new_mtu);
  2032. netdev->mtu = new_mtu;
  2033. if (netif_running(netdev))
  2034. i40e_vsi_reinit_locked(vsi);
  2035. i40e_notify_client_of_l2_param_changes(vsi);
  2036. return 0;
  2037. }
  2038. /**
  2039. * i40e_ioctl - Access the hwtstamp interface
  2040. * @netdev: network interface device structure
  2041. * @ifr: interface request data
  2042. * @cmd: ioctl command
  2043. **/
  2044. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2045. {
  2046. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2047. struct i40e_pf *pf = np->vsi->back;
  2048. switch (cmd) {
  2049. case SIOCGHWTSTAMP:
  2050. return i40e_ptp_get_ts_config(pf, ifr);
  2051. case SIOCSHWTSTAMP:
  2052. return i40e_ptp_set_ts_config(pf, ifr);
  2053. default:
  2054. return -EOPNOTSUPP;
  2055. }
  2056. }
  2057. /**
  2058. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2059. * @vsi: the vsi being adjusted
  2060. **/
  2061. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2062. {
  2063. struct i40e_vsi_context ctxt;
  2064. i40e_status ret;
  2065. if ((vsi->info.valid_sections &
  2066. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2067. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2068. return; /* already enabled */
  2069. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2070. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2071. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2072. ctxt.seid = vsi->seid;
  2073. ctxt.info = vsi->info;
  2074. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2075. if (ret) {
  2076. dev_info(&vsi->back->pdev->dev,
  2077. "update vlan stripping failed, err %s aq_err %s\n",
  2078. i40e_stat_str(&vsi->back->hw, ret),
  2079. i40e_aq_str(&vsi->back->hw,
  2080. vsi->back->hw.aq.asq_last_status));
  2081. }
  2082. }
  2083. /**
  2084. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2085. * @vsi: the vsi being adjusted
  2086. **/
  2087. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2088. {
  2089. struct i40e_vsi_context ctxt;
  2090. i40e_status ret;
  2091. if ((vsi->info.valid_sections &
  2092. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2093. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2094. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2095. return; /* already disabled */
  2096. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2097. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2098. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2099. ctxt.seid = vsi->seid;
  2100. ctxt.info = vsi->info;
  2101. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2102. if (ret) {
  2103. dev_info(&vsi->back->pdev->dev,
  2104. "update vlan stripping failed, err %s aq_err %s\n",
  2105. i40e_stat_str(&vsi->back->hw, ret),
  2106. i40e_aq_str(&vsi->back->hw,
  2107. vsi->back->hw.aq.asq_last_status));
  2108. }
  2109. }
  2110. /**
  2111. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2112. * @netdev: network interface to be adjusted
  2113. * @features: netdev features to test if VLAN offload is enabled or not
  2114. **/
  2115. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2116. {
  2117. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2118. struct i40e_vsi *vsi = np->vsi;
  2119. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2120. i40e_vlan_stripping_enable(vsi);
  2121. else
  2122. i40e_vlan_stripping_disable(vsi);
  2123. }
  2124. /**
  2125. * i40e_vsi_add_vlan - Add vsi membership for given vlan
  2126. * @vsi: the vsi being configured
  2127. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2128. **/
  2129. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  2130. {
  2131. struct i40e_mac_filter *f, *ftmp, *add_f;
  2132. bool is_netdev, is_vf;
  2133. is_vf = (vsi->type == I40E_VSI_SRIOV);
  2134. is_netdev = !!(vsi->netdev);
  2135. /* Locked once because all functions invoked below iterates list*/
  2136. spin_lock_bh(&vsi->mac_filter_list_lock);
  2137. if (is_netdev) {
  2138. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
  2139. is_vf, is_netdev);
  2140. if (!add_f) {
  2141. dev_info(&vsi->back->pdev->dev,
  2142. "Could not add vlan filter %d for %pM\n",
  2143. vid, vsi->netdev->dev_addr);
  2144. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2145. return -ENOMEM;
  2146. }
  2147. }
  2148. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  2149. add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  2150. if (!add_f) {
  2151. dev_info(&vsi->back->pdev->dev,
  2152. "Could not add vlan filter %d for %pM\n",
  2153. vid, f->macaddr);
  2154. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2155. return -ENOMEM;
  2156. }
  2157. }
  2158. /* Now if we add a vlan tag, make sure to check if it is the first
  2159. * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
  2160. * with 0, so we now accept untagged and specified tagged traffic
  2161. * (and not all tags along with untagged)
  2162. */
  2163. if (vid > 0) {
  2164. if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
  2165. I40E_VLAN_ANY,
  2166. is_vf, is_netdev)) {
  2167. i40e_del_filter(vsi, vsi->netdev->dev_addr,
  2168. I40E_VLAN_ANY, is_vf, is_netdev);
  2169. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
  2170. is_vf, is_netdev);
  2171. if (!add_f) {
  2172. dev_info(&vsi->back->pdev->dev,
  2173. "Could not add filter 0 for %pM\n",
  2174. vsi->netdev->dev_addr);
  2175. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2176. return -ENOMEM;
  2177. }
  2178. }
  2179. }
  2180. /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
  2181. if (vid > 0 && !vsi->info.pvid) {
  2182. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  2183. if (!i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  2184. is_vf, is_netdev))
  2185. continue;
  2186. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  2187. is_vf, is_netdev);
  2188. add_f = i40e_add_filter(vsi, f->macaddr,
  2189. 0, is_vf, is_netdev);
  2190. if (!add_f) {
  2191. dev_info(&vsi->back->pdev->dev,
  2192. "Could not add filter 0 for %pM\n",
  2193. f->macaddr);
  2194. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2195. return -ENOMEM;
  2196. }
  2197. }
  2198. }
  2199. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2200. /* schedule our worker thread which will take care of
  2201. * applying the new filter changes
  2202. */
  2203. i40e_service_event_schedule(vsi->back);
  2204. return 0;
  2205. }
  2206. /**
  2207. * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
  2208. * @vsi: the vsi being configured
  2209. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2210. *
  2211. * Return: 0 on success or negative otherwise
  2212. **/
  2213. int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  2214. {
  2215. struct net_device *netdev = vsi->netdev;
  2216. struct i40e_mac_filter *f, *ftmp, *add_f;
  2217. bool is_vf, is_netdev;
  2218. int filter_count = 0;
  2219. is_vf = (vsi->type == I40E_VSI_SRIOV);
  2220. is_netdev = !!(netdev);
  2221. /* Locked once because all functions invoked below iterates list */
  2222. spin_lock_bh(&vsi->mac_filter_list_lock);
  2223. if (is_netdev)
  2224. i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
  2225. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  2226. i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  2227. /* go through all the filters for this VSI and if there is only
  2228. * vid == 0 it means there are no other filters, so vid 0 must
  2229. * be replaced with -1. This signifies that we should from now
  2230. * on accept any traffic (with any tag present, or untagged)
  2231. */
  2232. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  2233. if (is_netdev) {
  2234. if (f->vlan &&
  2235. ether_addr_equal(netdev->dev_addr, f->macaddr))
  2236. filter_count++;
  2237. }
  2238. if (f->vlan)
  2239. filter_count++;
  2240. }
  2241. if (!filter_count && is_netdev) {
  2242. i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
  2243. f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  2244. is_vf, is_netdev);
  2245. if (!f) {
  2246. dev_info(&vsi->back->pdev->dev,
  2247. "Could not add filter %d for %pM\n",
  2248. I40E_VLAN_ANY, netdev->dev_addr);
  2249. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2250. return -ENOMEM;
  2251. }
  2252. }
  2253. if (!filter_count) {
  2254. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  2255. i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
  2256. add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  2257. is_vf, is_netdev);
  2258. if (!add_f) {
  2259. dev_info(&vsi->back->pdev->dev,
  2260. "Could not add filter %d for %pM\n",
  2261. I40E_VLAN_ANY, f->macaddr);
  2262. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2263. return -ENOMEM;
  2264. }
  2265. }
  2266. }
  2267. spin_unlock_bh(&vsi->mac_filter_list_lock);
  2268. /* schedule our worker thread which will take care of
  2269. * applying the new filter changes
  2270. */
  2271. i40e_service_event_schedule(vsi->back);
  2272. return 0;
  2273. }
  2274. /**
  2275. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2276. * @netdev: network interface to be adjusted
  2277. * @vid: vlan id to be added
  2278. *
  2279. * net_device_ops implementation for adding vlan ids
  2280. **/
  2281. #ifdef I40E_FCOE
  2282. int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2283. __always_unused __be16 proto, u16 vid)
  2284. #else
  2285. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2286. __always_unused __be16 proto, u16 vid)
  2287. #endif
  2288. {
  2289. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2290. struct i40e_vsi *vsi = np->vsi;
  2291. int ret = 0;
  2292. if (vid > 4095)
  2293. return -EINVAL;
  2294. /* If the network stack called us with vid = 0 then
  2295. * it is asking to receive priority tagged packets with
  2296. * vlan id 0. Our HW receives them by default when configured
  2297. * to receive untagged packets so there is no need to add an
  2298. * extra filter for vlan 0 tagged packets.
  2299. */
  2300. if (vid)
  2301. ret = i40e_vsi_add_vlan(vsi, vid);
  2302. if (!ret && (vid < VLAN_N_VID))
  2303. set_bit(vid, vsi->active_vlans);
  2304. return ret;
  2305. }
  2306. /**
  2307. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2308. * @netdev: network interface to be adjusted
  2309. * @vid: vlan id to be removed
  2310. *
  2311. * net_device_ops implementation for removing vlan ids
  2312. **/
  2313. #ifdef I40E_FCOE
  2314. int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2315. __always_unused __be16 proto, u16 vid)
  2316. #else
  2317. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2318. __always_unused __be16 proto, u16 vid)
  2319. #endif
  2320. {
  2321. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2322. struct i40e_vsi *vsi = np->vsi;
  2323. /* return code is ignored as there is nothing a user
  2324. * can do about failure to remove and a log message was
  2325. * already printed from the other function
  2326. */
  2327. i40e_vsi_kill_vlan(vsi, vid);
  2328. clear_bit(vid, vsi->active_vlans);
  2329. return 0;
  2330. }
  2331. /**
  2332. * i40e_macaddr_init - explicitly write the mac address filters
  2333. *
  2334. * @vsi: pointer to the vsi
  2335. * @macaddr: the MAC address
  2336. *
  2337. * This is needed when the macaddr has been obtained by other
  2338. * means than the default, e.g., from Open Firmware or IDPROM.
  2339. * Returns 0 on success, negative on failure
  2340. **/
  2341. static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
  2342. {
  2343. int ret;
  2344. struct i40e_aqc_add_macvlan_element_data element;
  2345. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  2346. I40E_AQC_WRITE_TYPE_LAA_WOL,
  2347. macaddr, NULL);
  2348. if (ret) {
  2349. dev_info(&vsi->back->pdev->dev,
  2350. "Addr change for VSI failed: %d\n", ret);
  2351. return -EADDRNOTAVAIL;
  2352. }
  2353. memset(&element, 0, sizeof(element));
  2354. ether_addr_copy(element.mac_addr, macaddr);
  2355. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  2356. ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
  2357. if (ret) {
  2358. dev_info(&vsi->back->pdev->dev,
  2359. "add filter failed err %s aq_err %s\n",
  2360. i40e_stat_str(&vsi->back->hw, ret),
  2361. i40e_aq_str(&vsi->back->hw,
  2362. vsi->back->hw.aq.asq_last_status));
  2363. }
  2364. return ret;
  2365. }
  2366. /**
  2367. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2368. * @vsi: the vsi being brought back up
  2369. **/
  2370. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2371. {
  2372. u16 vid;
  2373. if (!vsi->netdev)
  2374. return;
  2375. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2376. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2377. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2378. vid);
  2379. }
  2380. /**
  2381. * i40e_vsi_add_pvid - Add pvid for the VSI
  2382. * @vsi: the vsi being adjusted
  2383. * @vid: the vlan id to set as a PVID
  2384. **/
  2385. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2386. {
  2387. struct i40e_vsi_context ctxt;
  2388. i40e_status ret;
  2389. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2390. vsi->info.pvid = cpu_to_le16(vid);
  2391. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2392. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2393. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2394. ctxt.seid = vsi->seid;
  2395. ctxt.info = vsi->info;
  2396. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2397. if (ret) {
  2398. dev_info(&vsi->back->pdev->dev,
  2399. "add pvid failed, err %s aq_err %s\n",
  2400. i40e_stat_str(&vsi->back->hw, ret),
  2401. i40e_aq_str(&vsi->back->hw,
  2402. vsi->back->hw.aq.asq_last_status));
  2403. return -ENOENT;
  2404. }
  2405. return 0;
  2406. }
  2407. /**
  2408. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2409. * @vsi: the vsi being adjusted
  2410. *
  2411. * Just use the vlan_rx_register() service to put it back to normal
  2412. **/
  2413. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2414. {
  2415. i40e_vlan_stripping_disable(vsi);
  2416. vsi->info.pvid = 0;
  2417. }
  2418. /**
  2419. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2420. * @vsi: ptr to the VSI
  2421. *
  2422. * If this function returns with an error, then it's possible one or
  2423. * more of the rings is populated (while the rest are not). It is the
  2424. * callers duty to clean those orphaned rings.
  2425. *
  2426. * Return 0 on success, negative on failure
  2427. **/
  2428. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2429. {
  2430. int i, err = 0;
  2431. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2432. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2433. return err;
  2434. }
  2435. /**
  2436. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2437. * @vsi: ptr to the VSI
  2438. *
  2439. * Free VSI's transmit software resources
  2440. **/
  2441. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2442. {
  2443. int i;
  2444. if (!vsi->tx_rings)
  2445. return;
  2446. for (i = 0; i < vsi->num_queue_pairs; i++)
  2447. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2448. i40e_free_tx_resources(vsi->tx_rings[i]);
  2449. }
  2450. /**
  2451. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2452. * @vsi: ptr to the VSI
  2453. *
  2454. * If this function returns with an error, then it's possible one or
  2455. * more of the rings is populated (while the rest are not). It is the
  2456. * callers duty to clean those orphaned rings.
  2457. *
  2458. * Return 0 on success, negative on failure
  2459. **/
  2460. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2461. {
  2462. int i, err = 0;
  2463. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2464. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2465. #ifdef I40E_FCOE
  2466. i40e_fcoe_setup_ddp_resources(vsi);
  2467. #endif
  2468. return err;
  2469. }
  2470. /**
  2471. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2472. * @vsi: ptr to the VSI
  2473. *
  2474. * Free all receive software resources
  2475. **/
  2476. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2477. {
  2478. int i;
  2479. if (!vsi->rx_rings)
  2480. return;
  2481. for (i = 0; i < vsi->num_queue_pairs; i++)
  2482. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2483. i40e_free_rx_resources(vsi->rx_rings[i]);
  2484. #ifdef I40E_FCOE
  2485. i40e_fcoe_free_ddp_resources(vsi);
  2486. #endif
  2487. }
  2488. /**
  2489. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2490. * @ring: The Tx ring to configure
  2491. *
  2492. * This enables/disables XPS for a given Tx descriptor ring
  2493. * based on the TCs enabled for the VSI that ring belongs to.
  2494. **/
  2495. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2496. {
  2497. struct i40e_vsi *vsi = ring->vsi;
  2498. cpumask_var_t mask;
  2499. if (!ring->q_vector || !ring->netdev)
  2500. return;
  2501. /* Single TC mode enable XPS */
  2502. if (vsi->tc_config.numtc <= 1) {
  2503. if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2504. netif_set_xps_queue(ring->netdev,
  2505. &ring->q_vector->affinity_mask,
  2506. ring->queue_index);
  2507. } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
  2508. /* Disable XPS to allow selection based on TC */
  2509. bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
  2510. netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
  2511. free_cpumask_var(mask);
  2512. }
  2513. /* schedule our worker thread which will take care of
  2514. * applying the new filter changes
  2515. */
  2516. i40e_service_event_schedule(vsi->back);
  2517. }
  2518. /**
  2519. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2520. * @ring: The Tx ring to configure
  2521. *
  2522. * Configure the Tx descriptor ring in the HMC context.
  2523. **/
  2524. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2525. {
  2526. struct i40e_vsi *vsi = ring->vsi;
  2527. u16 pf_q = vsi->base_queue + ring->queue_index;
  2528. struct i40e_hw *hw = &vsi->back->hw;
  2529. struct i40e_hmc_obj_txq tx_ctx;
  2530. i40e_status err = 0;
  2531. u32 qtx_ctl = 0;
  2532. /* some ATR related tx ring init */
  2533. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2534. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2535. ring->atr_count = 0;
  2536. } else {
  2537. ring->atr_sample_rate = 0;
  2538. }
  2539. /* configure XPS */
  2540. i40e_config_xps_tx_ring(ring);
  2541. /* clear the context structure first */
  2542. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2543. tx_ctx.new_context = 1;
  2544. tx_ctx.base = (ring->dma / 128);
  2545. tx_ctx.qlen = ring->count;
  2546. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2547. I40E_FLAG_FD_ATR_ENABLED));
  2548. #ifdef I40E_FCOE
  2549. tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2550. #endif
  2551. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2552. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2553. if (vsi->type != I40E_VSI_FDIR)
  2554. tx_ctx.head_wb_ena = 1;
  2555. tx_ctx.head_wb_addr = ring->dma +
  2556. (ring->count * sizeof(struct i40e_tx_desc));
  2557. /* As part of VSI creation/update, FW allocates certain
  2558. * Tx arbitration queue sets for each TC enabled for
  2559. * the VSI. The FW returns the handles to these queue
  2560. * sets as part of the response buffer to Add VSI,
  2561. * Update VSI, etc. AQ commands. It is expected that
  2562. * these queue set handles be associated with the Tx
  2563. * queues by the driver as part of the TX queue context
  2564. * initialization. This has to be done regardless of
  2565. * DCB as by default everything is mapped to TC0.
  2566. */
  2567. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2568. tx_ctx.rdylist_act = 0;
  2569. /* clear the context in the HMC */
  2570. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2571. if (err) {
  2572. dev_info(&vsi->back->pdev->dev,
  2573. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2574. ring->queue_index, pf_q, err);
  2575. return -ENOMEM;
  2576. }
  2577. /* set the context in the HMC */
  2578. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2579. if (err) {
  2580. dev_info(&vsi->back->pdev->dev,
  2581. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2582. ring->queue_index, pf_q, err);
  2583. return -ENOMEM;
  2584. }
  2585. /* Now associate this queue with this PCI function */
  2586. if (vsi->type == I40E_VSI_VMDQ2) {
  2587. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2588. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2589. I40E_QTX_CTL_VFVM_INDX_MASK;
  2590. } else {
  2591. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2592. }
  2593. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2594. I40E_QTX_CTL_PF_INDX_MASK);
  2595. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2596. i40e_flush(hw);
  2597. /* cache tail off for easier writes later */
  2598. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2599. return 0;
  2600. }
  2601. /**
  2602. * i40e_configure_rx_ring - Configure a receive ring context
  2603. * @ring: The Rx ring to configure
  2604. *
  2605. * Configure the Rx descriptor ring in the HMC context.
  2606. **/
  2607. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2608. {
  2609. struct i40e_vsi *vsi = ring->vsi;
  2610. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2611. u16 pf_q = vsi->base_queue + ring->queue_index;
  2612. struct i40e_hw *hw = &vsi->back->hw;
  2613. struct i40e_hmc_obj_rxq rx_ctx;
  2614. i40e_status err = 0;
  2615. ring->state = 0;
  2616. /* clear the context structure first */
  2617. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2618. ring->rx_buf_len = vsi->rx_buf_len;
  2619. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2620. rx_ctx.base = (ring->dma / 128);
  2621. rx_ctx.qlen = ring->count;
  2622. /* use 32 byte descriptors */
  2623. rx_ctx.dsize = 1;
  2624. /* descriptor type is always zero
  2625. * rx_ctx.dtype = 0;
  2626. */
  2627. rx_ctx.hsplit_0 = 0;
  2628. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2629. if (hw->revision_id == 0)
  2630. rx_ctx.lrxqthresh = 0;
  2631. else
  2632. rx_ctx.lrxqthresh = 2;
  2633. rx_ctx.crcstrip = 1;
  2634. rx_ctx.l2tsel = 1;
  2635. /* this controls whether VLAN is stripped from inner headers */
  2636. rx_ctx.showiv = 0;
  2637. #ifdef I40E_FCOE
  2638. rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2639. #endif
  2640. /* set the prefena field to 1 because the manual says to */
  2641. rx_ctx.prefena = 1;
  2642. /* clear the context in the HMC */
  2643. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2644. if (err) {
  2645. dev_info(&vsi->back->pdev->dev,
  2646. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2647. ring->queue_index, pf_q, err);
  2648. return -ENOMEM;
  2649. }
  2650. /* set the context in the HMC */
  2651. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2652. if (err) {
  2653. dev_info(&vsi->back->pdev->dev,
  2654. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2655. ring->queue_index, pf_q, err);
  2656. return -ENOMEM;
  2657. }
  2658. /* cache tail for quicker writes, and clear the reg before use */
  2659. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2660. writel(0, ring->tail);
  2661. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2662. return 0;
  2663. }
  2664. /**
  2665. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2666. * @vsi: VSI structure describing this set of rings and resources
  2667. *
  2668. * Configure the Tx VSI for operation.
  2669. **/
  2670. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2671. {
  2672. int err = 0;
  2673. u16 i;
  2674. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2675. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2676. return err;
  2677. }
  2678. /**
  2679. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2680. * @vsi: the VSI being configured
  2681. *
  2682. * Configure the Rx VSI for operation.
  2683. **/
  2684. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2685. {
  2686. int err = 0;
  2687. u16 i;
  2688. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2689. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2690. + ETH_FCS_LEN + VLAN_HLEN;
  2691. else
  2692. vsi->max_frame = I40E_RXBUFFER_2048;
  2693. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2694. #ifdef I40E_FCOE
  2695. /* setup rx buffer for FCoE */
  2696. if ((vsi->type == I40E_VSI_FCOE) &&
  2697. (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
  2698. vsi->rx_buf_len = I40E_RXBUFFER_3072;
  2699. vsi->max_frame = I40E_RXBUFFER_3072;
  2700. }
  2701. #endif /* I40E_FCOE */
  2702. /* round up for the chip's needs */
  2703. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2704. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2705. /* set up individual rings */
  2706. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2707. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2708. return err;
  2709. }
  2710. /**
  2711. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2712. * @vsi: ptr to the VSI
  2713. **/
  2714. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2715. {
  2716. struct i40e_ring *tx_ring, *rx_ring;
  2717. u16 qoffset, qcount;
  2718. int i, n;
  2719. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2720. /* Reset the TC information */
  2721. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2722. rx_ring = vsi->rx_rings[i];
  2723. tx_ring = vsi->tx_rings[i];
  2724. rx_ring->dcb_tc = 0;
  2725. tx_ring->dcb_tc = 0;
  2726. }
  2727. }
  2728. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2729. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2730. continue;
  2731. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2732. qcount = vsi->tc_config.tc_info[n].qcount;
  2733. for (i = qoffset; i < (qoffset + qcount); i++) {
  2734. rx_ring = vsi->rx_rings[i];
  2735. tx_ring = vsi->tx_rings[i];
  2736. rx_ring->dcb_tc = n;
  2737. tx_ring->dcb_tc = n;
  2738. }
  2739. }
  2740. }
  2741. /**
  2742. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2743. * @vsi: ptr to the VSI
  2744. **/
  2745. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2746. {
  2747. struct i40e_pf *pf = vsi->back;
  2748. int err;
  2749. if (vsi->netdev)
  2750. i40e_set_rx_mode(vsi->netdev);
  2751. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  2752. err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  2753. if (err) {
  2754. dev_warn(&pf->pdev->dev,
  2755. "could not set up macaddr; err %d\n", err);
  2756. }
  2757. }
  2758. }
  2759. /**
  2760. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2761. * @vsi: Pointer to the targeted VSI
  2762. *
  2763. * This function replays the hlist on the hw where all the SB Flow Director
  2764. * filters were saved.
  2765. **/
  2766. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2767. {
  2768. struct i40e_fdir_filter *filter;
  2769. struct i40e_pf *pf = vsi->back;
  2770. struct hlist_node *node;
  2771. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2772. return;
  2773. hlist_for_each_entry_safe(filter, node,
  2774. &pf->fdir_filter_list, fdir_node) {
  2775. i40e_add_del_fdir(vsi, filter, true);
  2776. }
  2777. }
  2778. /**
  2779. * i40e_vsi_configure - Set up the VSI for action
  2780. * @vsi: the VSI being configured
  2781. **/
  2782. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2783. {
  2784. int err;
  2785. i40e_set_vsi_rx_mode(vsi);
  2786. i40e_restore_vlan(vsi);
  2787. i40e_vsi_config_dcb_rings(vsi);
  2788. err = i40e_vsi_configure_tx(vsi);
  2789. if (!err)
  2790. err = i40e_vsi_configure_rx(vsi);
  2791. return err;
  2792. }
  2793. /**
  2794. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2795. * @vsi: the VSI being configured
  2796. **/
  2797. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2798. {
  2799. struct i40e_pf *pf = vsi->back;
  2800. struct i40e_hw *hw = &pf->hw;
  2801. u16 vector;
  2802. int i, q;
  2803. u32 qp;
  2804. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2805. * and PFINT_LNKLSTn registers, e.g.:
  2806. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2807. */
  2808. qp = vsi->base_queue;
  2809. vector = vsi->base_vector;
  2810. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2811. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  2812. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2813. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  2814. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2815. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2816. q_vector->rx.itr);
  2817. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  2818. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2819. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2820. q_vector->tx.itr);
  2821. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  2822. INTRL_USEC_TO_REG(vsi->int_rate_limit));
  2823. /* Linked list for the queuepairs assigned to this vector */
  2824. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2825. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2826. u32 val;
  2827. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2828. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2829. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2830. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2831. (I40E_QUEUE_TYPE_TX
  2832. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2833. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2834. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2835. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2836. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2837. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2838. (I40E_QUEUE_TYPE_RX
  2839. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2840. /* Terminate the linked list */
  2841. if (q == (q_vector->num_ringpairs - 1))
  2842. val |= (I40E_QUEUE_END_OF_LIST
  2843. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2844. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2845. qp++;
  2846. }
  2847. }
  2848. i40e_flush(hw);
  2849. }
  2850. /**
  2851. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2852. * @hw: ptr to the hardware info
  2853. **/
  2854. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  2855. {
  2856. struct i40e_hw *hw = &pf->hw;
  2857. u32 val;
  2858. /* clear things first */
  2859. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2860. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2861. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2862. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2863. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2864. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2865. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2866. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2867. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2868. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2869. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  2870. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  2871. if (pf->flags & I40E_FLAG_PTP)
  2872. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2873. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2874. /* SW_ITR_IDX = 0, but don't change INTENA */
  2875. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2876. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2877. /* OTHER_ITR_IDX = 0 */
  2878. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2879. }
  2880. /**
  2881. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2882. * @vsi: the VSI being configured
  2883. **/
  2884. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2885. {
  2886. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2887. struct i40e_pf *pf = vsi->back;
  2888. struct i40e_hw *hw = &pf->hw;
  2889. u32 val;
  2890. /* set the ITR configuration */
  2891. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2892. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  2893. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2894. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2895. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  2896. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2897. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2898. i40e_enable_misc_int_causes(pf);
  2899. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2900. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2901. /* Associate the queue pair to the vector and enable the queue int */
  2902. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2903. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2904. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2905. wr32(hw, I40E_QINT_RQCTL(0), val);
  2906. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2907. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2908. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2909. wr32(hw, I40E_QINT_TQCTL(0), val);
  2910. i40e_flush(hw);
  2911. }
  2912. /**
  2913. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  2914. * @pf: board private structure
  2915. **/
  2916. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  2917. {
  2918. struct i40e_hw *hw = &pf->hw;
  2919. wr32(hw, I40E_PFINT_DYN_CTL0,
  2920. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2921. i40e_flush(hw);
  2922. }
  2923. /**
  2924. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  2925. * @pf: board private structure
  2926. * @clearpba: true when all pending interrupt events should be cleared
  2927. **/
  2928. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
  2929. {
  2930. struct i40e_hw *hw = &pf->hw;
  2931. u32 val;
  2932. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  2933. (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
  2934. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  2935. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2936. i40e_flush(hw);
  2937. }
  2938. /**
  2939. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  2940. * @irq: interrupt number
  2941. * @data: pointer to a q_vector
  2942. **/
  2943. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  2944. {
  2945. struct i40e_q_vector *q_vector = data;
  2946. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2947. return IRQ_HANDLED;
  2948. napi_schedule_irqoff(&q_vector->napi);
  2949. return IRQ_HANDLED;
  2950. }
  2951. /**
  2952. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  2953. * @vsi: the VSI being configured
  2954. * @basename: name for the vector
  2955. *
  2956. * Allocates MSI-X vectors and requests interrupts from the kernel.
  2957. **/
  2958. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  2959. {
  2960. int q_vectors = vsi->num_q_vectors;
  2961. struct i40e_pf *pf = vsi->back;
  2962. int base = vsi->base_vector;
  2963. int rx_int_idx = 0;
  2964. int tx_int_idx = 0;
  2965. int vector, err;
  2966. for (vector = 0; vector < q_vectors; vector++) {
  2967. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  2968. if (q_vector->tx.ring && q_vector->rx.ring) {
  2969. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2970. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  2971. tx_int_idx++;
  2972. } else if (q_vector->rx.ring) {
  2973. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2974. "%s-%s-%d", basename, "rx", rx_int_idx++);
  2975. } else if (q_vector->tx.ring) {
  2976. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2977. "%s-%s-%d", basename, "tx", tx_int_idx++);
  2978. } else {
  2979. /* skip this unused q_vector */
  2980. continue;
  2981. }
  2982. err = request_irq(pf->msix_entries[base + vector].vector,
  2983. vsi->irq_handler,
  2984. 0,
  2985. q_vector->name,
  2986. q_vector);
  2987. if (err) {
  2988. dev_info(&pf->pdev->dev,
  2989. "MSIX request_irq failed, error: %d\n", err);
  2990. goto free_queue_irqs;
  2991. }
  2992. /* assign the mask for this irq */
  2993. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2994. &q_vector->affinity_mask);
  2995. }
  2996. vsi->irqs_ready = true;
  2997. return 0;
  2998. free_queue_irqs:
  2999. while (vector) {
  3000. vector--;
  3001. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  3002. NULL);
  3003. free_irq(pf->msix_entries[base + vector].vector,
  3004. &(vsi->q_vectors[vector]));
  3005. }
  3006. return err;
  3007. }
  3008. /**
  3009. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3010. * @vsi: the VSI being un-configured
  3011. **/
  3012. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3013. {
  3014. struct i40e_pf *pf = vsi->back;
  3015. struct i40e_hw *hw = &pf->hw;
  3016. int base = vsi->base_vector;
  3017. int i;
  3018. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3019. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  3020. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  3021. }
  3022. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3023. for (i = vsi->base_vector;
  3024. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3025. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3026. i40e_flush(hw);
  3027. for (i = 0; i < vsi->num_q_vectors; i++)
  3028. synchronize_irq(pf->msix_entries[i + base].vector);
  3029. } else {
  3030. /* Legacy and MSI mode - this stops all interrupt handling */
  3031. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3032. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3033. i40e_flush(hw);
  3034. synchronize_irq(pf->pdev->irq);
  3035. }
  3036. }
  3037. /**
  3038. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3039. * @vsi: the VSI being configured
  3040. **/
  3041. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3042. {
  3043. struct i40e_pf *pf = vsi->back;
  3044. int i;
  3045. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3046. for (i = 0; i < vsi->num_q_vectors; i++)
  3047. i40e_irq_dynamic_enable(vsi, i);
  3048. } else {
  3049. i40e_irq_dynamic_enable_icr0(pf, true);
  3050. }
  3051. i40e_flush(&pf->hw);
  3052. return 0;
  3053. }
  3054. /**
  3055. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  3056. * @pf: board private structure
  3057. **/
  3058. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  3059. {
  3060. /* Disable ICR 0 */
  3061. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3062. i40e_flush(&pf->hw);
  3063. }
  3064. /**
  3065. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3066. * @irq: interrupt number
  3067. * @data: pointer to a q_vector
  3068. *
  3069. * This is the handler used for all MSI/Legacy interrupts, and deals
  3070. * with both queue and non-queue interrupts. This is also used in
  3071. * MSIX mode to handle the non-queue interrupts.
  3072. **/
  3073. static irqreturn_t i40e_intr(int irq, void *data)
  3074. {
  3075. struct i40e_pf *pf = (struct i40e_pf *)data;
  3076. struct i40e_hw *hw = &pf->hw;
  3077. irqreturn_t ret = IRQ_NONE;
  3078. u32 icr0, icr0_remaining;
  3079. u32 val, ena_mask;
  3080. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3081. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3082. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3083. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3084. goto enable_intr;
  3085. /* if interrupt but no bits showing, must be SWINT */
  3086. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3087. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3088. pf->sw_int_count++;
  3089. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3090. (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3091. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3092. icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3093. dev_info(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3094. }
  3095. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3096. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3097. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3098. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3099. /* We do not have a way to disarm Queue causes while leaving
  3100. * interrupt enabled for all other causes, ideally
  3101. * interrupt should be disabled while we are in NAPI but
  3102. * this is not a performance path and napi_schedule()
  3103. * can deal with rescheduling.
  3104. */
  3105. if (!test_bit(__I40E_DOWN, &pf->state))
  3106. napi_schedule_irqoff(&q_vector->napi);
  3107. }
  3108. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3109. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3110. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  3111. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3112. }
  3113. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3114. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3115. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  3116. }
  3117. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3118. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3119. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  3120. }
  3121. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3122. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  3123. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  3124. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3125. val = rd32(hw, I40E_GLGEN_RSTAT);
  3126. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3127. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3128. if (val == I40E_RESET_CORER) {
  3129. pf->corer_count++;
  3130. } else if (val == I40E_RESET_GLOBR) {
  3131. pf->globr_count++;
  3132. } else if (val == I40E_RESET_EMPR) {
  3133. pf->empr_count++;
  3134. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
  3135. }
  3136. }
  3137. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3138. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3139. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3140. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3141. rd32(hw, I40E_PFHMC_ERRORINFO),
  3142. rd32(hw, I40E_PFHMC_ERRORDATA));
  3143. }
  3144. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3145. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3146. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3147. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3148. i40e_ptp_tx_hwtstamp(pf);
  3149. }
  3150. }
  3151. /* If a critical error is pending we have no choice but to reset the
  3152. * device.
  3153. * Report and mask out any remaining unexpected interrupts.
  3154. */
  3155. icr0_remaining = icr0 & ena_mask;
  3156. if (icr0_remaining) {
  3157. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3158. icr0_remaining);
  3159. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3160. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3161. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3162. dev_info(&pf->pdev->dev, "device will be reset\n");
  3163. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  3164. i40e_service_event_schedule(pf);
  3165. }
  3166. ena_mask &= ~icr0_remaining;
  3167. }
  3168. ret = IRQ_HANDLED;
  3169. enable_intr:
  3170. /* re-enable interrupt causes */
  3171. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3172. if (!test_bit(__I40E_DOWN, &pf->state)) {
  3173. i40e_service_event_schedule(pf);
  3174. i40e_irq_dynamic_enable_icr0(pf, false);
  3175. }
  3176. return ret;
  3177. }
  3178. /**
  3179. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3180. * @tx_ring: tx ring to clean
  3181. * @budget: how many cleans we're allowed
  3182. *
  3183. * Returns true if there's any budget left (e.g. the clean is finished)
  3184. **/
  3185. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3186. {
  3187. struct i40e_vsi *vsi = tx_ring->vsi;
  3188. u16 i = tx_ring->next_to_clean;
  3189. struct i40e_tx_buffer *tx_buf;
  3190. struct i40e_tx_desc *tx_desc;
  3191. tx_buf = &tx_ring->tx_bi[i];
  3192. tx_desc = I40E_TX_DESC(tx_ring, i);
  3193. i -= tx_ring->count;
  3194. do {
  3195. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3196. /* if next_to_watch is not set then there is no work pending */
  3197. if (!eop_desc)
  3198. break;
  3199. /* prevent any other reads prior to eop_desc */
  3200. smp_rmb();
  3201. /* if the descriptor isn't done, no work yet to do */
  3202. if (!(eop_desc->cmd_type_offset_bsz &
  3203. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3204. break;
  3205. /* clear next_to_watch to prevent false hangs */
  3206. tx_buf->next_to_watch = NULL;
  3207. tx_desc->buffer_addr = 0;
  3208. tx_desc->cmd_type_offset_bsz = 0;
  3209. /* move past filter desc */
  3210. tx_buf++;
  3211. tx_desc++;
  3212. i++;
  3213. if (unlikely(!i)) {
  3214. i -= tx_ring->count;
  3215. tx_buf = tx_ring->tx_bi;
  3216. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3217. }
  3218. /* unmap skb header data */
  3219. dma_unmap_single(tx_ring->dev,
  3220. dma_unmap_addr(tx_buf, dma),
  3221. dma_unmap_len(tx_buf, len),
  3222. DMA_TO_DEVICE);
  3223. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3224. kfree(tx_buf->raw_buf);
  3225. tx_buf->raw_buf = NULL;
  3226. tx_buf->tx_flags = 0;
  3227. tx_buf->next_to_watch = NULL;
  3228. dma_unmap_len_set(tx_buf, len, 0);
  3229. tx_desc->buffer_addr = 0;
  3230. tx_desc->cmd_type_offset_bsz = 0;
  3231. /* move us past the eop_desc for start of next FD desc */
  3232. tx_buf++;
  3233. tx_desc++;
  3234. i++;
  3235. if (unlikely(!i)) {
  3236. i -= tx_ring->count;
  3237. tx_buf = tx_ring->tx_bi;
  3238. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3239. }
  3240. /* update budget accounting */
  3241. budget--;
  3242. } while (likely(budget));
  3243. i += tx_ring->count;
  3244. tx_ring->next_to_clean = i;
  3245. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3246. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3247. return budget > 0;
  3248. }
  3249. /**
  3250. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3251. * @irq: interrupt number
  3252. * @data: pointer to a q_vector
  3253. **/
  3254. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3255. {
  3256. struct i40e_q_vector *q_vector = data;
  3257. struct i40e_vsi *vsi;
  3258. if (!q_vector->tx.ring)
  3259. return IRQ_HANDLED;
  3260. vsi = q_vector->tx.ring->vsi;
  3261. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3262. return IRQ_HANDLED;
  3263. }
  3264. /**
  3265. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3266. * @vsi: the VSI being configured
  3267. * @v_idx: vector index
  3268. * @qp_idx: queue pair index
  3269. **/
  3270. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3271. {
  3272. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3273. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3274. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3275. tx_ring->q_vector = q_vector;
  3276. tx_ring->next = q_vector->tx.ring;
  3277. q_vector->tx.ring = tx_ring;
  3278. q_vector->tx.count++;
  3279. rx_ring->q_vector = q_vector;
  3280. rx_ring->next = q_vector->rx.ring;
  3281. q_vector->rx.ring = rx_ring;
  3282. q_vector->rx.count++;
  3283. }
  3284. /**
  3285. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3286. * @vsi: the VSI being configured
  3287. *
  3288. * This function maps descriptor rings to the queue-specific vectors
  3289. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3290. * one vector per queue pair, but on a constrained vector budget, we
  3291. * group the queue pairs as "efficiently" as possible.
  3292. **/
  3293. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3294. {
  3295. int qp_remaining = vsi->num_queue_pairs;
  3296. int q_vectors = vsi->num_q_vectors;
  3297. int num_ringpairs;
  3298. int v_start = 0;
  3299. int qp_idx = 0;
  3300. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3301. * group them so there are multiple queues per vector.
  3302. * It is also important to go through all the vectors available to be
  3303. * sure that if we don't use all the vectors, that the remaining vectors
  3304. * are cleared. This is especially important when decreasing the
  3305. * number of queues in use.
  3306. */
  3307. for (; v_start < q_vectors; v_start++) {
  3308. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3309. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3310. q_vector->num_ringpairs = num_ringpairs;
  3311. q_vector->rx.count = 0;
  3312. q_vector->tx.count = 0;
  3313. q_vector->rx.ring = NULL;
  3314. q_vector->tx.ring = NULL;
  3315. while (num_ringpairs--) {
  3316. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3317. qp_idx++;
  3318. qp_remaining--;
  3319. }
  3320. }
  3321. }
  3322. /**
  3323. * i40e_vsi_request_irq - Request IRQ from the OS
  3324. * @vsi: the VSI being configured
  3325. * @basename: name for the vector
  3326. **/
  3327. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3328. {
  3329. struct i40e_pf *pf = vsi->back;
  3330. int err;
  3331. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3332. err = i40e_vsi_request_irq_msix(vsi, basename);
  3333. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3334. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3335. pf->int_name, pf);
  3336. else
  3337. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3338. pf->int_name, pf);
  3339. if (err)
  3340. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3341. return err;
  3342. }
  3343. #ifdef CONFIG_NET_POLL_CONTROLLER
  3344. /**
  3345. * i40e_netpoll - A Polling 'interrupt' handler
  3346. * @netdev: network interface device structure
  3347. *
  3348. * This is used by netconsole to send skbs without having to re-enable
  3349. * interrupts. It's not called while the normal interrupt routine is executing.
  3350. **/
  3351. #ifdef I40E_FCOE
  3352. void i40e_netpoll(struct net_device *netdev)
  3353. #else
  3354. static void i40e_netpoll(struct net_device *netdev)
  3355. #endif
  3356. {
  3357. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3358. struct i40e_vsi *vsi = np->vsi;
  3359. struct i40e_pf *pf = vsi->back;
  3360. int i;
  3361. /* if interface is down do nothing */
  3362. if (test_bit(__I40E_DOWN, &vsi->state))
  3363. return;
  3364. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3365. for (i = 0; i < vsi->num_q_vectors; i++)
  3366. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3367. } else {
  3368. i40e_intr(pf->pdev->irq, netdev);
  3369. }
  3370. }
  3371. #endif
  3372. /**
  3373. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3374. * @pf: the PF being configured
  3375. * @pf_q: the PF queue
  3376. * @enable: enable or disable state of the queue
  3377. *
  3378. * This routine will wait for the given Tx queue of the PF to reach the
  3379. * enabled or disabled state.
  3380. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3381. * multiple retries; else will return 0 in case of success.
  3382. **/
  3383. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3384. {
  3385. int i;
  3386. u32 tx_reg;
  3387. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3388. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3389. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3390. break;
  3391. usleep_range(10, 20);
  3392. }
  3393. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3394. return -ETIMEDOUT;
  3395. return 0;
  3396. }
  3397. /**
  3398. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3399. * @vsi: the VSI being configured
  3400. * @enable: start or stop the rings
  3401. **/
  3402. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3403. {
  3404. struct i40e_pf *pf = vsi->back;
  3405. struct i40e_hw *hw = &pf->hw;
  3406. int i, j, pf_q, ret = 0;
  3407. u32 tx_reg;
  3408. pf_q = vsi->base_queue;
  3409. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3410. /* warn the TX unit of coming changes */
  3411. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3412. if (!enable)
  3413. usleep_range(10, 20);
  3414. for (j = 0; j < 50; j++) {
  3415. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3416. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3417. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3418. break;
  3419. usleep_range(1000, 2000);
  3420. }
  3421. /* Skip if the queue is already in the requested state */
  3422. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3423. continue;
  3424. /* turn on/off the queue */
  3425. if (enable) {
  3426. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3427. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3428. } else {
  3429. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3430. }
  3431. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3432. /* No waiting for the Tx queue to disable */
  3433. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3434. continue;
  3435. /* wait for the change to finish */
  3436. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3437. if (ret) {
  3438. dev_info(&pf->pdev->dev,
  3439. "VSI seid %d Tx ring %d %sable timeout\n",
  3440. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3441. break;
  3442. }
  3443. }
  3444. if (hw->revision_id == 0)
  3445. mdelay(50);
  3446. return ret;
  3447. }
  3448. /**
  3449. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3450. * @pf: the PF being configured
  3451. * @pf_q: the PF queue
  3452. * @enable: enable or disable state of the queue
  3453. *
  3454. * This routine will wait for the given Rx queue of the PF to reach the
  3455. * enabled or disabled state.
  3456. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3457. * multiple retries; else will return 0 in case of success.
  3458. **/
  3459. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3460. {
  3461. int i;
  3462. u32 rx_reg;
  3463. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3464. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3465. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3466. break;
  3467. usleep_range(10, 20);
  3468. }
  3469. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3470. return -ETIMEDOUT;
  3471. return 0;
  3472. }
  3473. /**
  3474. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3475. * @vsi: the VSI being configured
  3476. * @enable: start or stop the rings
  3477. **/
  3478. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3479. {
  3480. struct i40e_pf *pf = vsi->back;
  3481. struct i40e_hw *hw = &pf->hw;
  3482. int i, j, pf_q, ret = 0;
  3483. u32 rx_reg;
  3484. pf_q = vsi->base_queue;
  3485. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3486. for (j = 0; j < 50; j++) {
  3487. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3488. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3489. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3490. break;
  3491. usleep_range(1000, 2000);
  3492. }
  3493. /* Skip if the queue is already in the requested state */
  3494. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3495. continue;
  3496. /* turn on/off the queue */
  3497. if (enable)
  3498. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3499. else
  3500. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3501. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3502. /* No waiting for the Tx queue to disable */
  3503. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3504. continue;
  3505. /* wait for the change to finish */
  3506. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3507. if (ret) {
  3508. dev_info(&pf->pdev->dev,
  3509. "VSI seid %d Rx ring %d %sable timeout\n",
  3510. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3511. break;
  3512. }
  3513. }
  3514. return ret;
  3515. }
  3516. /**
  3517. * i40e_vsi_control_rings - Start or stop a VSI's rings
  3518. * @vsi: the VSI being configured
  3519. * @enable: start or stop the rings
  3520. **/
  3521. int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
  3522. {
  3523. int ret = 0;
  3524. /* do rx first for enable and last for disable */
  3525. if (request) {
  3526. ret = i40e_vsi_control_rx(vsi, request);
  3527. if (ret)
  3528. return ret;
  3529. ret = i40e_vsi_control_tx(vsi, request);
  3530. } else {
  3531. /* Ignore return value, we need to shutdown whatever we can */
  3532. i40e_vsi_control_tx(vsi, request);
  3533. i40e_vsi_control_rx(vsi, request);
  3534. }
  3535. return ret;
  3536. }
  3537. /**
  3538. * i40e_vsi_free_irq - Free the irq association with the OS
  3539. * @vsi: the VSI being configured
  3540. **/
  3541. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3542. {
  3543. struct i40e_pf *pf = vsi->back;
  3544. struct i40e_hw *hw = &pf->hw;
  3545. int base = vsi->base_vector;
  3546. u32 val, qp;
  3547. int i;
  3548. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3549. if (!vsi->q_vectors)
  3550. return;
  3551. if (!vsi->irqs_ready)
  3552. return;
  3553. vsi->irqs_ready = false;
  3554. for (i = 0; i < vsi->num_q_vectors; i++) {
  3555. u16 vector = i + base;
  3556. /* free only the irqs that were actually requested */
  3557. if (!vsi->q_vectors[i] ||
  3558. !vsi->q_vectors[i]->num_ringpairs)
  3559. continue;
  3560. /* clear the affinity_mask in the IRQ descriptor */
  3561. irq_set_affinity_hint(pf->msix_entries[vector].vector,
  3562. NULL);
  3563. synchronize_irq(pf->msix_entries[vector].vector);
  3564. free_irq(pf->msix_entries[vector].vector,
  3565. vsi->q_vectors[i]);
  3566. /* Tear down the interrupt queue link list
  3567. *
  3568. * We know that they come in pairs and always
  3569. * the Rx first, then the Tx. To clear the
  3570. * link list, stick the EOL value into the
  3571. * next_q field of the registers.
  3572. */
  3573. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3574. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3575. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3576. val |= I40E_QUEUE_END_OF_LIST
  3577. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3578. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3579. while (qp != I40E_QUEUE_END_OF_LIST) {
  3580. u32 next;
  3581. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3582. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3583. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3584. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3585. I40E_QINT_RQCTL_INTEVENT_MASK);
  3586. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3587. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3588. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3589. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3590. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3591. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3592. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3593. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3594. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3595. I40E_QINT_TQCTL_INTEVENT_MASK);
  3596. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3597. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3598. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3599. qp = next;
  3600. }
  3601. }
  3602. } else {
  3603. free_irq(pf->pdev->irq, pf);
  3604. val = rd32(hw, I40E_PFINT_LNKLST0);
  3605. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3606. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3607. val |= I40E_QUEUE_END_OF_LIST
  3608. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3609. wr32(hw, I40E_PFINT_LNKLST0, val);
  3610. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3611. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3612. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3613. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3614. I40E_QINT_RQCTL_INTEVENT_MASK);
  3615. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3616. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3617. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3618. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3619. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3620. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3621. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3622. I40E_QINT_TQCTL_INTEVENT_MASK);
  3623. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3624. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3625. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3626. }
  3627. }
  3628. /**
  3629. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3630. * @vsi: the VSI being configured
  3631. * @v_idx: Index of vector to be freed
  3632. *
  3633. * This function frees the memory allocated to the q_vector. In addition if
  3634. * NAPI is enabled it will delete any references to the NAPI struct prior
  3635. * to freeing the q_vector.
  3636. **/
  3637. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3638. {
  3639. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3640. struct i40e_ring *ring;
  3641. if (!q_vector)
  3642. return;
  3643. /* disassociate q_vector from rings */
  3644. i40e_for_each_ring(ring, q_vector->tx)
  3645. ring->q_vector = NULL;
  3646. i40e_for_each_ring(ring, q_vector->rx)
  3647. ring->q_vector = NULL;
  3648. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3649. if (vsi->netdev)
  3650. netif_napi_del(&q_vector->napi);
  3651. vsi->q_vectors[v_idx] = NULL;
  3652. kfree_rcu(q_vector, rcu);
  3653. }
  3654. /**
  3655. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3656. * @vsi: the VSI being un-configured
  3657. *
  3658. * This frees the memory allocated to the q_vectors and
  3659. * deletes references to the NAPI struct.
  3660. **/
  3661. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3662. {
  3663. int v_idx;
  3664. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3665. i40e_free_q_vector(vsi, v_idx);
  3666. }
  3667. /**
  3668. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3669. * @pf: board private structure
  3670. **/
  3671. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3672. {
  3673. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3674. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3675. pci_disable_msix(pf->pdev);
  3676. kfree(pf->msix_entries);
  3677. pf->msix_entries = NULL;
  3678. kfree(pf->irq_pile);
  3679. pf->irq_pile = NULL;
  3680. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3681. pci_disable_msi(pf->pdev);
  3682. }
  3683. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3684. }
  3685. /**
  3686. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3687. * @pf: board private structure
  3688. *
  3689. * We go through and clear interrupt specific resources and reset the structure
  3690. * to pre-load conditions
  3691. **/
  3692. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3693. {
  3694. int i;
  3695. i40e_stop_misc_vector(pf);
  3696. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3697. synchronize_irq(pf->msix_entries[0].vector);
  3698. free_irq(pf->msix_entries[0].vector, pf);
  3699. }
  3700. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  3701. I40E_IWARP_IRQ_PILE_ID);
  3702. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3703. for (i = 0; i < pf->num_alloc_vsi; i++)
  3704. if (pf->vsi[i])
  3705. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3706. i40e_reset_interrupt_capability(pf);
  3707. }
  3708. /**
  3709. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3710. * @vsi: the VSI being configured
  3711. **/
  3712. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3713. {
  3714. int q_idx;
  3715. if (!vsi->netdev)
  3716. return;
  3717. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  3718. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  3719. if (q_vector->rx.ring || q_vector->tx.ring)
  3720. napi_enable(&q_vector->napi);
  3721. }
  3722. }
  3723. /**
  3724. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3725. * @vsi: the VSI being configured
  3726. **/
  3727. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3728. {
  3729. int q_idx;
  3730. if (!vsi->netdev)
  3731. return;
  3732. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
  3733. struct i40e_q_vector *q_vector = vsi->q_vectors[q_idx];
  3734. if (q_vector->rx.ring || q_vector->tx.ring)
  3735. napi_disable(&q_vector->napi);
  3736. }
  3737. }
  3738. /**
  3739. * i40e_vsi_close - Shut down a VSI
  3740. * @vsi: the vsi to be quelled
  3741. **/
  3742. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3743. {
  3744. bool reset = false;
  3745. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3746. i40e_down(vsi);
  3747. i40e_vsi_free_irq(vsi);
  3748. i40e_vsi_free_tx_resources(vsi);
  3749. i40e_vsi_free_rx_resources(vsi);
  3750. vsi->current_netdev_flags = 0;
  3751. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  3752. reset = true;
  3753. i40e_notify_client_of_netdev_close(vsi, reset);
  3754. }
  3755. /**
  3756. * i40e_quiesce_vsi - Pause a given VSI
  3757. * @vsi: the VSI being paused
  3758. **/
  3759. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3760. {
  3761. if (test_bit(__I40E_DOWN, &vsi->state))
  3762. return;
  3763. /* No need to disable FCoE VSI when Tx suspended */
  3764. if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
  3765. vsi->type == I40E_VSI_FCOE) {
  3766. dev_dbg(&vsi->back->pdev->dev,
  3767. "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
  3768. return;
  3769. }
  3770. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3771. if (vsi->netdev && netif_running(vsi->netdev))
  3772. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3773. else
  3774. i40e_vsi_close(vsi);
  3775. }
  3776. /**
  3777. * i40e_unquiesce_vsi - Resume a given VSI
  3778. * @vsi: the VSI being resumed
  3779. **/
  3780. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3781. {
  3782. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3783. return;
  3784. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3785. if (vsi->netdev && netif_running(vsi->netdev))
  3786. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3787. else
  3788. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3789. }
  3790. /**
  3791. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3792. * @pf: the PF
  3793. **/
  3794. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3795. {
  3796. int v;
  3797. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3798. if (pf->vsi[v])
  3799. i40e_quiesce_vsi(pf->vsi[v]);
  3800. }
  3801. }
  3802. /**
  3803. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3804. * @pf: the PF
  3805. **/
  3806. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3807. {
  3808. int v;
  3809. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3810. if (pf->vsi[v])
  3811. i40e_unquiesce_vsi(pf->vsi[v]);
  3812. }
  3813. }
  3814. #ifdef CONFIG_I40E_DCB
  3815. /**
  3816. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  3817. * @vsi: the VSI being configured
  3818. *
  3819. * This function waits for the given VSI's queues to be disabled.
  3820. **/
  3821. static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  3822. {
  3823. struct i40e_pf *pf = vsi->back;
  3824. int i, pf_q, ret;
  3825. pf_q = vsi->base_queue;
  3826. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3827. /* Check and wait for the disable status of the queue */
  3828. ret = i40e_pf_txq_wait(pf, pf_q, false);
  3829. if (ret) {
  3830. dev_info(&pf->pdev->dev,
  3831. "VSI seid %d Tx ring %d disable timeout\n",
  3832. vsi->seid, pf_q);
  3833. return ret;
  3834. }
  3835. }
  3836. pf_q = vsi->base_queue;
  3837. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3838. /* Check and wait for the disable status of the queue */
  3839. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  3840. if (ret) {
  3841. dev_info(&pf->pdev->dev,
  3842. "VSI seid %d Rx ring %d disable timeout\n",
  3843. vsi->seid, pf_q);
  3844. return ret;
  3845. }
  3846. }
  3847. return 0;
  3848. }
  3849. /**
  3850. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  3851. * @pf: the PF
  3852. *
  3853. * This function waits for the queues to be in disabled state for all the
  3854. * VSIs that are managed by this PF.
  3855. **/
  3856. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  3857. {
  3858. int v, ret = 0;
  3859. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3860. /* No need to wait for FCoE VSI queues */
  3861. if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
  3862. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  3863. if (ret)
  3864. break;
  3865. }
  3866. }
  3867. return ret;
  3868. }
  3869. #endif
  3870. /**
  3871. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  3872. * @q_idx: TX queue number
  3873. * @vsi: Pointer to VSI struct
  3874. *
  3875. * This function checks specified queue for given VSI. Detects hung condition.
  3876. * Sets hung bit since it is two step process. Before next run of service task
  3877. * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
  3878. * hung condition remain unchanged and during subsequent run, this function
  3879. * issues SW interrupt to recover from hung condition.
  3880. **/
  3881. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  3882. {
  3883. struct i40e_ring *tx_ring = NULL;
  3884. struct i40e_pf *pf;
  3885. u32 head, val, tx_pending_hw;
  3886. int i;
  3887. pf = vsi->back;
  3888. /* now that we have an index, find the tx_ring struct */
  3889. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3890. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  3891. if (q_idx == vsi->tx_rings[i]->queue_index) {
  3892. tx_ring = vsi->tx_rings[i];
  3893. break;
  3894. }
  3895. }
  3896. }
  3897. if (!tx_ring)
  3898. return;
  3899. /* Read interrupt register */
  3900. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3901. val = rd32(&pf->hw,
  3902. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  3903. tx_ring->vsi->base_vector - 1));
  3904. else
  3905. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  3906. head = i40e_get_head(tx_ring);
  3907. tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
  3908. /* HW is done executing descriptors, updated HEAD write back,
  3909. * but SW hasn't processed those descriptors. If interrupt is
  3910. * not generated from this point ON, it could result into
  3911. * dev_watchdog detecting timeout on those netdev_queue,
  3912. * hence proactively trigger SW interrupt.
  3913. */
  3914. if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  3915. /* NAPI Poll didn't run and clear since it was set */
  3916. if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
  3917. &tx_ring->q_vector->hung_detected)) {
  3918. netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
  3919. vsi->seid, q_idx, tx_pending_hw,
  3920. tx_ring->next_to_clean, head,
  3921. tx_ring->next_to_use,
  3922. readl(tx_ring->tail));
  3923. netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
  3924. vsi->seid, q_idx, val);
  3925. i40e_force_wb(vsi, tx_ring->q_vector);
  3926. } else {
  3927. /* First Chance - detected possible hung */
  3928. set_bit(I40E_Q_VECTOR_HUNG_DETECT,
  3929. &tx_ring->q_vector->hung_detected);
  3930. }
  3931. }
  3932. /* This is the case where we have interrupts missing,
  3933. * so the tx_pending in HW will most likely be 0, but we
  3934. * will have tx_pending in SW since the WB happened but the
  3935. * interrupt got lost.
  3936. */
  3937. if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
  3938. (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  3939. if (napi_reschedule(&tx_ring->q_vector->napi))
  3940. tx_ring->tx_stats.tx_lost_interrupt++;
  3941. }
  3942. }
  3943. /**
  3944. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  3945. * @pf: pointer to PF struct
  3946. *
  3947. * LAN VSI has netdev and netdev has TX queues. This function is to check
  3948. * each of those TX queues if they are hung, trigger recovery by issuing
  3949. * SW interrupt.
  3950. **/
  3951. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  3952. {
  3953. struct net_device *netdev;
  3954. struct i40e_vsi *vsi;
  3955. int i;
  3956. /* Only for LAN VSI */
  3957. vsi = pf->vsi[pf->lan_vsi];
  3958. if (!vsi)
  3959. return;
  3960. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  3961. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  3962. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  3963. return;
  3964. /* Make sure type is MAIN VSI */
  3965. if (vsi->type != I40E_VSI_MAIN)
  3966. return;
  3967. netdev = vsi->netdev;
  3968. if (!netdev)
  3969. return;
  3970. /* Bail out if netif_carrier is not OK */
  3971. if (!netif_carrier_ok(netdev))
  3972. return;
  3973. /* Go thru' TX queues for netdev */
  3974. for (i = 0; i < netdev->num_tx_queues; i++) {
  3975. struct netdev_queue *q;
  3976. q = netdev_get_tx_queue(netdev, i);
  3977. if (q)
  3978. i40e_detect_recover_hung_queue(i, vsi);
  3979. }
  3980. }
  3981. /**
  3982. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  3983. * @pf: pointer to PF
  3984. *
  3985. * Get TC map for ISCSI PF type that will include iSCSI TC
  3986. * and LAN TC.
  3987. **/
  3988. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  3989. {
  3990. struct i40e_dcb_app_priority_table app;
  3991. struct i40e_hw *hw = &pf->hw;
  3992. u8 enabled_tc = 1; /* TC0 is always enabled */
  3993. u8 tc, i;
  3994. /* Get the iSCSI APP TLV */
  3995. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3996. for (i = 0; i < dcbcfg->numapps; i++) {
  3997. app = dcbcfg->app[i];
  3998. if (app.selector == I40E_APP_SEL_TCPIP &&
  3999. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4000. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4001. enabled_tc |= BIT(tc);
  4002. break;
  4003. }
  4004. }
  4005. return enabled_tc;
  4006. }
  4007. /**
  4008. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4009. * @dcbcfg: the corresponding DCBx configuration structure
  4010. *
  4011. * Return the number of TCs from given DCBx configuration
  4012. **/
  4013. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4014. {
  4015. int i, tc_unused = 0;
  4016. u8 num_tc = 0;
  4017. u8 ret = 0;
  4018. /* Scan the ETS Config Priority Table to find
  4019. * traffic class enabled for a given priority
  4020. * and create a bitmask of enabled TCs
  4021. */
  4022. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4023. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4024. /* Now scan the bitmask to check for
  4025. * contiguous TCs starting with TC0
  4026. */
  4027. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4028. if (num_tc & BIT(i)) {
  4029. if (!tc_unused) {
  4030. ret++;
  4031. } else {
  4032. pr_err("Non-contiguous TC - Disabling DCB\n");
  4033. return 1;
  4034. }
  4035. } else {
  4036. tc_unused = 1;
  4037. }
  4038. }
  4039. /* There is always at least TC0 */
  4040. if (!ret)
  4041. ret = 1;
  4042. return ret;
  4043. }
  4044. /**
  4045. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4046. * @dcbcfg: the corresponding DCBx configuration structure
  4047. *
  4048. * Query the current DCB configuration and return the number of
  4049. * traffic classes enabled from the given DCBX config
  4050. **/
  4051. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4052. {
  4053. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4054. u8 enabled_tc = 1;
  4055. u8 i;
  4056. for (i = 0; i < num_tc; i++)
  4057. enabled_tc |= BIT(i);
  4058. return enabled_tc;
  4059. }
  4060. /**
  4061. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4062. * @pf: PF being queried
  4063. *
  4064. * Return number of traffic classes enabled for the given PF
  4065. **/
  4066. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4067. {
  4068. struct i40e_hw *hw = &pf->hw;
  4069. u8 i, enabled_tc = 1;
  4070. u8 num_tc = 0;
  4071. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4072. /* If DCB is not enabled then always in single TC */
  4073. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4074. return 1;
  4075. /* SFP mode will be enabled for all TCs on port */
  4076. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4077. return i40e_dcb_get_num_tc(dcbcfg);
  4078. /* MFP mode return count of enabled TCs for this PF */
  4079. if (pf->hw.func_caps.iscsi)
  4080. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4081. else
  4082. return 1; /* Only TC0 */
  4083. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4084. if (enabled_tc & BIT(i))
  4085. num_tc++;
  4086. }
  4087. return num_tc;
  4088. }
  4089. /**
  4090. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4091. * @pf: PF being queried
  4092. *
  4093. * Return a bitmap for enabled traffic classes for this PF.
  4094. **/
  4095. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4096. {
  4097. /* If DCB is not enabled for this PF then just return default TC */
  4098. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4099. return I40E_DEFAULT_TRAFFIC_CLASS;
  4100. /* SFP mode we want PF to be enabled for all TCs */
  4101. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4102. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4103. /* MFP enabled and iSCSI PF type */
  4104. if (pf->hw.func_caps.iscsi)
  4105. return i40e_get_iscsi_tc_map(pf);
  4106. else
  4107. return I40E_DEFAULT_TRAFFIC_CLASS;
  4108. }
  4109. /**
  4110. * i40e_vsi_get_bw_info - Query VSI BW Information
  4111. * @vsi: the VSI being queried
  4112. *
  4113. * Returns 0 on success, negative value on failure
  4114. **/
  4115. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4116. {
  4117. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4118. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4119. struct i40e_pf *pf = vsi->back;
  4120. struct i40e_hw *hw = &pf->hw;
  4121. i40e_status ret;
  4122. u32 tc_bw_max;
  4123. int i;
  4124. /* Get the VSI level BW configuration */
  4125. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4126. if (ret) {
  4127. dev_info(&pf->pdev->dev,
  4128. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4129. i40e_stat_str(&pf->hw, ret),
  4130. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4131. return -EINVAL;
  4132. }
  4133. /* Get the VSI level BW configuration per TC */
  4134. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4135. NULL);
  4136. if (ret) {
  4137. dev_info(&pf->pdev->dev,
  4138. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4139. i40e_stat_str(&pf->hw, ret),
  4140. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4141. return -EINVAL;
  4142. }
  4143. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4144. dev_info(&pf->pdev->dev,
  4145. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4146. bw_config.tc_valid_bits,
  4147. bw_ets_config.tc_valid_bits);
  4148. /* Still continuing */
  4149. }
  4150. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4151. vsi->bw_max_quanta = bw_config.max_bw;
  4152. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4153. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4154. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4155. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4156. vsi->bw_ets_limit_credits[i] =
  4157. le16_to_cpu(bw_ets_config.credits[i]);
  4158. /* 3 bits out of 4 for each TC */
  4159. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4160. }
  4161. return 0;
  4162. }
  4163. /**
  4164. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4165. * @vsi: the VSI being configured
  4166. * @enabled_tc: TC bitmap
  4167. * @bw_credits: BW shared credits per TC
  4168. *
  4169. * Returns 0 on success, negative value on failure
  4170. **/
  4171. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4172. u8 *bw_share)
  4173. {
  4174. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4175. i40e_status ret;
  4176. int i;
  4177. bw_data.tc_valid_bits = enabled_tc;
  4178. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4179. bw_data.tc_bw_credits[i] = bw_share[i];
  4180. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4181. NULL);
  4182. if (ret) {
  4183. dev_info(&vsi->back->pdev->dev,
  4184. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4185. vsi->back->hw.aq.asq_last_status);
  4186. return -EINVAL;
  4187. }
  4188. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4189. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4190. return 0;
  4191. }
  4192. /**
  4193. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4194. * @vsi: the VSI being configured
  4195. * @enabled_tc: TC map to be enabled
  4196. *
  4197. **/
  4198. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4199. {
  4200. struct net_device *netdev = vsi->netdev;
  4201. struct i40e_pf *pf = vsi->back;
  4202. struct i40e_hw *hw = &pf->hw;
  4203. u8 netdev_tc = 0;
  4204. int i;
  4205. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4206. if (!netdev)
  4207. return;
  4208. if (!enabled_tc) {
  4209. netdev_reset_tc(netdev);
  4210. return;
  4211. }
  4212. /* Set up actual enabled TCs on the VSI */
  4213. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4214. return;
  4215. /* set per TC queues for the VSI */
  4216. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4217. /* Only set TC queues for enabled tcs
  4218. *
  4219. * e.g. For a VSI that has TC0 and TC3 enabled the
  4220. * enabled_tc bitmap would be 0x00001001; the driver
  4221. * will set the numtc for netdev as 2 that will be
  4222. * referenced by the netdev layer as TC 0 and 1.
  4223. */
  4224. if (vsi->tc_config.enabled_tc & BIT(i))
  4225. netdev_set_tc_queue(netdev,
  4226. vsi->tc_config.tc_info[i].netdev_tc,
  4227. vsi->tc_config.tc_info[i].qcount,
  4228. vsi->tc_config.tc_info[i].qoffset);
  4229. }
  4230. /* Assign UP2TC map for the VSI */
  4231. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4232. /* Get the actual TC# for the UP */
  4233. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4234. /* Get the mapped netdev TC# for the UP */
  4235. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4236. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4237. }
  4238. }
  4239. /**
  4240. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4241. * @vsi: the VSI being configured
  4242. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4243. **/
  4244. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4245. struct i40e_vsi_context *ctxt)
  4246. {
  4247. /* copy just the sections touched not the entire info
  4248. * since not all sections are valid as returned by
  4249. * update vsi params
  4250. */
  4251. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4252. memcpy(&vsi->info.queue_mapping,
  4253. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4254. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4255. sizeof(vsi->info.tc_mapping));
  4256. }
  4257. /**
  4258. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4259. * @vsi: VSI to be configured
  4260. * @enabled_tc: TC bitmap
  4261. *
  4262. * This configures a particular VSI for TCs that are mapped to the
  4263. * given TC bitmap. It uses default bandwidth share for TCs across
  4264. * VSIs to configure TC for a particular VSI.
  4265. *
  4266. * NOTE:
  4267. * It is expected that the VSI queues have been quisced before calling
  4268. * this function.
  4269. **/
  4270. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4271. {
  4272. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4273. struct i40e_vsi_context ctxt;
  4274. int ret = 0;
  4275. int i;
  4276. /* Check if enabled_tc is same as existing or new TCs */
  4277. if (vsi->tc_config.enabled_tc == enabled_tc)
  4278. return ret;
  4279. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4280. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4281. if (enabled_tc & BIT(i))
  4282. bw_share[i] = 1;
  4283. }
  4284. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4285. if (ret) {
  4286. dev_info(&vsi->back->pdev->dev,
  4287. "Failed configuring TC map %d for VSI %d\n",
  4288. enabled_tc, vsi->seid);
  4289. goto out;
  4290. }
  4291. /* Update Queue Pairs Mapping for currently enabled UPs */
  4292. ctxt.seid = vsi->seid;
  4293. ctxt.pf_num = vsi->back->hw.pf_id;
  4294. ctxt.vf_num = 0;
  4295. ctxt.uplink_seid = vsi->uplink_seid;
  4296. ctxt.info = vsi->info;
  4297. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4298. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4299. ctxt.info.valid_sections |=
  4300. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4301. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4302. }
  4303. /* Update the VSI after updating the VSI queue-mapping information */
  4304. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4305. if (ret) {
  4306. dev_info(&vsi->back->pdev->dev,
  4307. "Update vsi tc config failed, err %s aq_err %s\n",
  4308. i40e_stat_str(&vsi->back->hw, ret),
  4309. i40e_aq_str(&vsi->back->hw,
  4310. vsi->back->hw.aq.asq_last_status));
  4311. goto out;
  4312. }
  4313. /* update the local VSI info with updated queue map */
  4314. i40e_vsi_update_queue_map(vsi, &ctxt);
  4315. vsi->info.valid_sections = 0;
  4316. /* Update current VSI BW information */
  4317. ret = i40e_vsi_get_bw_info(vsi);
  4318. if (ret) {
  4319. dev_info(&vsi->back->pdev->dev,
  4320. "Failed updating vsi bw info, err %s aq_err %s\n",
  4321. i40e_stat_str(&vsi->back->hw, ret),
  4322. i40e_aq_str(&vsi->back->hw,
  4323. vsi->back->hw.aq.asq_last_status));
  4324. goto out;
  4325. }
  4326. /* Update the netdev TC setup */
  4327. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4328. out:
  4329. return ret;
  4330. }
  4331. /**
  4332. * i40e_veb_config_tc - Configure TCs for given VEB
  4333. * @veb: given VEB
  4334. * @enabled_tc: TC bitmap
  4335. *
  4336. * Configures given TC bitmap for VEB (switching) element
  4337. **/
  4338. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  4339. {
  4340. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  4341. struct i40e_pf *pf = veb->pf;
  4342. int ret = 0;
  4343. int i;
  4344. /* No TCs or already enabled TCs just return */
  4345. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  4346. return ret;
  4347. bw_data.tc_valid_bits = enabled_tc;
  4348. /* bw_data.absolute_credits is not set (relative) */
  4349. /* Enable ETS TCs with equal BW Share for now */
  4350. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4351. if (enabled_tc & BIT(i))
  4352. bw_data.tc_bw_share_credits[i] = 1;
  4353. }
  4354. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  4355. &bw_data, NULL);
  4356. if (ret) {
  4357. dev_info(&pf->pdev->dev,
  4358. "VEB bw config failed, err %s aq_err %s\n",
  4359. i40e_stat_str(&pf->hw, ret),
  4360. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4361. goto out;
  4362. }
  4363. /* Update the BW information */
  4364. ret = i40e_veb_get_bw_info(veb);
  4365. if (ret) {
  4366. dev_info(&pf->pdev->dev,
  4367. "Failed getting veb bw config, err %s aq_err %s\n",
  4368. i40e_stat_str(&pf->hw, ret),
  4369. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4370. }
  4371. out:
  4372. return ret;
  4373. }
  4374. #ifdef CONFIG_I40E_DCB
  4375. /**
  4376. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  4377. * @pf: PF struct
  4378. *
  4379. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  4380. * the caller would've quiesce all the VSIs before calling
  4381. * this function
  4382. **/
  4383. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  4384. {
  4385. u8 tc_map = 0;
  4386. int ret;
  4387. u8 v;
  4388. /* Enable the TCs available on PF to all VEBs */
  4389. tc_map = i40e_pf_get_tc_map(pf);
  4390. for (v = 0; v < I40E_MAX_VEB; v++) {
  4391. if (!pf->veb[v])
  4392. continue;
  4393. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  4394. if (ret) {
  4395. dev_info(&pf->pdev->dev,
  4396. "Failed configuring TC for VEB seid=%d\n",
  4397. pf->veb[v]->seid);
  4398. /* Will try to configure as many components */
  4399. }
  4400. }
  4401. /* Update each VSI */
  4402. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4403. if (!pf->vsi[v])
  4404. continue;
  4405. /* - Enable all TCs for the LAN VSI
  4406. #ifdef I40E_FCOE
  4407. * - For FCoE VSI only enable the TC configured
  4408. * as per the APP TLV
  4409. #endif
  4410. * - For all others keep them at TC0 for now
  4411. */
  4412. if (v == pf->lan_vsi)
  4413. tc_map = i40e_pf_get_tc_map(pf);
  4414. else
  4415. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  4416. #ifdef I40E_FCOE
  4417. if (pf->vsi[v]->type == I40E_VSI_FCOE)
  4418. tc_map = i40e_get_fcoe_tc_map(pf);
  4419. #endif /* #ifdef I40E_FCOE */
  4420. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  4421. if (ret) {
  4422. dev_info(&pf->pdev->dev,
  4423. "Failed configuring TC for VSI seid=%d\n",
  4424. pf->vsi[v]->seid);
  4425. /* Will try to configure as many components */
  4426. } else {
  4427. /* Re-configure VSI vectors based on updated TC map */
  4428. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  4429. if (pf->vsi[v]->netdev)
  4430. i40e_dcbnl_set_all(pf->vsi[v]);
  4431. }
  4432. }
  4433. }
  4434. /**
  4435. * i40e_resume_port_tx - Resume port Tx
  4436. * @pf: PF struct
  4437. *
  4438. * Resume a port's Tx and issue a PF reset in case of failure to
  4439. * resume.
  4440. **/
  4441. static int i40e_resume_port_tx(struct i40e_pf *pf)
  4442. {
  4443. struct i40e_hw *hw = &pf->hw;
  4444. int ret;
  4445. ret = i40e_aq_resume_port_tx(hw, NULL);
  4446. if (ret) {
  4447. dev_info(&pf->pdev->dev,
  4448. "Resume Port Tx failed, err %s aq_err %s\n",
  4449. i40e_stat_str(&pf->hw, ret),
  4450. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4451. /* Schedule PF reset to recover */
  4452. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4453. i40e_service_event_schedule(pf);
  4454. }
  4455. return ret;
  4456. }
  4457. /**
  4458. * i40e_init_pf_dcb - Initialize DCB configuration
  4459. * @pf: PF being configured
  4460. *
  4461. * Query the current DCB configuration and cache it
  4462. * in the hardware structure
  4463. **/
  4464. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  4465. {
  4466. struct i40e_hw *hw = &pf->hw;
  4467. int err = 0;
  4468. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  4469. if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
  4470. goto out;
  4471. /* Get the initial DCB configuration */
  4472. err = i40e_init_dcb(hw);
  4473. if (!err) {
  4474. /* Device/Function is not DCBX capable */
  4475. if ((!hw->func_caps.dcb) ||
  4476. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  4477. dev_info(&pf->pdev->dev,
  4478. "DCBX offload is not supported or is disabled for this PF.\n");
  4479. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  4480. goto out;
  4481. } else {
  4482. /* When status is not DISABLED then DCBX in FW */
  4483. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  4484. DCB_CAP_DCBX_VER_IEEE;
  4485. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  4486. /* Enable DCB tagging only when more than one TC
  4487. * or explicitly disable if only one TC
  4488. */
  4489. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  4490. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4491. else
  4492. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  4493. dev_dbg(&pf->pdev->dev,
  4494. "DCBX offload is supported for this PF.\n");
  4495. }
  4496. } else {
  4497. dev_info(&pf->pdev->dev,
  4498. "Query for DCB configuration failed, err %s aq_err %s\n",
  4499. i40e_stat_str(&pf->hw, err),
  4500. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4501. }
  4502. out:
  4503. return err;
  4504. }
  4505. #endif /* CONFIG_I40E_DCB */
  4506. #define SPEED_SIZE 14
  4507. #define FC_SIZE 8
  4508. /**
  4509. * i40e_print_link_message - print link up or down
  4510. * @vsi: the VSI for which link needs a message
  4511. */
  4512. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  4513. {
  4514. char *speed = "Unknown";
  4515. char *fc = "Unknown";
  4516. if (vsi->current_isup == isup)
  4517. return;
  4518. vsi->current_isup = isup;
  4519. if (!isup) {
  4520. netdev_info(vsi->netdev, "NIC Link is Down\n");
  4521. return;
  4522. }
  4523. /* Warn user if link speed on NPAR enabled partition is not at
  4524. * least 10GB
  4525. */
  4526. if (vsi->back->hw.func_caps.npar_enable &&
  4527. (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  4528. vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  4529. netdev_warn(vsi->netdev,
  4530. "The partition detected link speed that is less than 10Gbps\n");
  4531. switch (vsi->back->hw.phy.link_info.link_speed) {
  4532. case I40E_LINK_SPEED_40GB:
  4533. speed = "40 G";
  4534. break;
  4535. case I40E_LINK_SPEED_20GB:
  4536. speed = "20 G";
  4537. break;
  4538. case I40E_LINK_SPEED_10GB:
  4539. speed = "10 G";
  4540. break;
  4541. case I40E_LINK_SPEED_1GB:
  4542. speed = "1000 M";
  4543. break;
  4544. case I40E_LINK_SPEED_100MB:
  4545. speed = "100 M";
  4546. break;
  4547. default:
  4548. break;
  4549. }
  4550. switch (vsi->back->hw.fc.current_mode) {
  4551. case I40E_FC_FULL:
  4552. fc = "RX/TX";
  4553. break;
  4554. case I40E_FC_TX_PAUSE:
  4555. fc = "TX";
  4556. break;
  4557. case I40E_FC_RX_PAUSE:
  4558. fc = "RX";
  4559. break;
  4560. default:
  4561. fc = "None";
  4562. break;
  4563. }
  4564. netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
  4565. speed, fc);
  4566. }
  4567. /**
  4568. * i40e_up_complete - Finish the last steps of bringing up a connection
  4569. * @vsi: the VSI being configured
  4570. **/
  4571. static int i40e_up_complete(struct i40e_vsi *vsi)
  4572. {
  4573. struct i40e_pf *pf = vsi->back;
  4574. int err;
  4575. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4576. i40e_vsi_configure_msix(vsi);
  4577. else
  4578. i40e_configure_msi_and_legacy(vsi);
  4579. /* start rings */
  4580. err = i40e_vsi_control_rings(vsi, true);
  4581. if (err)
  4582. return err;
  4583. clear_bit(__I40E_DOWN, &vsi->state);
  4584. i40e_napi_enable_all(vsi);
  4585. i40e_vsi_enable_irq(vsi);
  4586. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  4587. (vsi->netdev)) {
  4588. i40e_print_link_message(vsi, true);
  4589. netif_tx_start_all_queues(vsi->netdev);
  4590. netif_carrier_on(vsi->netdev);
  4591. } else if (vsi->netdev) {
  4592. i40e_print_link_message(vsi, false);
  4593. /* need to check for qualified module here*/
  4594. if ((pf->hw.phy.link_info.link_info &
  4595. I40E_AQ_MEDIA_AVAILABLE) &&
  4596. (!(pf->hw.phy.link_info.an_info &
  4597. I40E_AQ_QUALIFIED_MODULE)))
  4598. netdev_err(vsi->netdev,
  4599. "the driver failed to link because an unqualified module was detected.");
  4600. }
  4601. /* replay FDIR SB filters */
  4602. if (vsi->type == I40E_VSI_FDIR) {
  4603. /* reset fd counters */
  4604. pf->fd_add_err = pf->fd_atr_cnt = 0;
  4605. if (pf->fd_tcp_rule > 0) {
  4606. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  4607. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  4608. dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
  4609. pf->fd_tcp_rule = 0;
  4610. }
  4611. i40e_fdir_filter_restore(vsi);
  4612. }
  4613. /* On the next run of the service_task, notify any clients of the new
  4614. * opened netdev
  4615. */
  4616. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4617. i40e_service_event_schedule(pf);
  4618. return 0;
  4619. }
  4620. /**
  4621. * i40e_vsi_reinit_locked - Reset the VSI
  4622. * @vsi: the VSI being configured
  4623. *
  4624. * Rebuild the ring structs after some configuration
  4625. * has changed, e.g. MTU size.
  4626. **/
  4627. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  4628. {
  4629. struct i40e_pf *pf = vsi->back;
  4630. WARN_ON(in_interrupt());
  4631. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  4632. usleep_range(1000, 2000);
  4633. i40e_down(vsi);
  4634. i40e_up(vsi);
  4635. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  4636. }
  4637. /**
  4638. * i40e_up - Bring the connection back up after being down
  4639. * @vsi: the VSI being configured
  4640. **/
  4641. int i40e_up(struct i40e_vsi *vsi)
  4642. {
  4643. int err;
  4644. err = i40e_vsi_configure(vsi);
  4645. if (!err)
  4646. err = i40e_up_complete(vsi);
  4647. return err;
  4648. }
  4649. /**
  4650. * i40e_down - Shutdown the connection processing
  4651. * @vsi: the VSI being stopped
  4652. **/
  4653. void i40e_down(struct i40e_vsi *vsi)
  4654. {
  4655. int i;
  4656. /* It is assumed that the caller of this function
  4657. * sets the vsi->state __I40E_DOWN bit.
  4658. */
  4659. if (vsi->netdev) {
  4660. netif_carrier_off(vsi->netdev);
  4661. netif_tx_disable(vsi->netdev);
  4662. }
  4663. i40e_vsi_disable_irq(vsi);
  4664. i40e_vsi_control_rings(vsi, false);
  4665. i40e_napi_disable_all(vsi);
  4666. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4667. i40e_clean_tx_ring(vsi->tx_rings[i]);
  4668. i40e_clean_rx_ring(vsi->rx_rings[i]);
  4669. }
  4670. i40e_notify_client_of_netdev_close(vsi, false);
  4671. }
  4672. /**
  4673. * i40e_setup_tc - configure multiple traffic classes
  4674. * @netdev: net device to configure
  4675. * @tc: number of traffic classes to enable
  4676. **/
  4677. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4678. {
  4679. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4680. struct i40e_vsi *vsi = np->vsi;
  4681. struct i40e_pf *pf = vsi->back;
  4682. u8 enabled_tc = 0;
  4683. int ret = -EINVAL;
  4684. int i;
  4685. /* Check if DCB enabled to continue */
  4686. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4687. netdev_info(netdev, "DCB is not enabled for adapter\n");
  4688. goto exit;
  4689. }
  4690. /* Check if MFP enabled */
  4691. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  4692. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  4693. goto exit;
  4694. }
  4695. /* Check whether tc count is within enabled limit */
  4696. if (tc > i40e_pf_get_num_tc(pf)) {
  4697. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  4698. goto exit;
  4699. }
  4700. /* Generate TC map for number of tc requested */
  4701. for (i = 0; i < tc; i++)
  4702. enabled_tc |= BIT(i);
  4703. /* Requesting same TC configuration as already enabled */
  4704. if (enabled_tc == vsi->tc_config.enabled_tc)
  4705. return 0;
  4706. /* Quiesce VSI queues */
  4707. i40e_quiesce_vsi(vsi);
  4708. /* Configure VSI for enabled TCs */
  4709. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  4710. if (ret) {
  4711. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  4712. vsi->seid);
  4713. goto exit;
  4714. }
  4715. /* Unquiesce VSI */
  4716. i40e_unquiesce_vsi(vsi);
  4717. exit:
  4718. return ret;
  4719. }
  4720. #ifdef I40E_FCOE
  4721. int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4722. struct tc_to_netdev *tc)
  4723. #else
  4724. static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4725. struct tc_to_netdev *tc)
  4726. #endif
  4727. {
  4728. if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
  4729. return -EINVAL;
  4730. return i40e_setup_tc(netdev, tc->tc);
  4731. }
  4732. /**
  4733. * i40e_open - Called when a network interface is made active
  4734. * @netdev: network interface device structure
  4735. *
  4736. * The open entry point is called when a network interface is made
  4737. * active by the system (IFF_UP). At this point all resources needed
  4738. * for transmit and receive operations are allocated, the interrupt
  4739. * handler is registered with the OS, the netdev watchdog subtask is
  4740. * enabled, and the stack is notified that the interface is ready.
  4741. *
  4742. * Returns 0 on success, negative value on failure
  4743. **/
  4744. int i40e_open(struct net_device *netdev)
  4745. {
  4746. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4747. struct i40e_vsi *vsi = np->vsi;
  4748. struct i40e_pf *pf = vsi->back;
  4749. int err;
  4750. /* disallow open during test or if eeprom is broken */
  4751. if (test_bit(__I40E_TESTING, &pf->state) ||
  4752. test_bit(__I40E_BAD_EEPROM, &pf->state))
  4753. return -EBUSY;
  4754. netif_carrier_off(netdev);
  4755. err = i40e_vsi_open(vsi);
  4756. if (err)
  4757. return err;
  4758. /* configure global TSO hardware offload settings */
  4759. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  4760. TCP_FLAG_FIN) >> 16);
  4761. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  4762. TCP_FLAG_FIN |
  4763. TCP_FLAG_CWR) >> 16);
  4764. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  4765. udp_tunnel_get_rx_info(netdev);
  4766. return 0;
  4767. }
  4768. /**
  4769. * i40e_vsi_open -
  4770. * @vsi: the VSI to open
  4771. *
  4772. * Finish initialization of the VSI.
  4773. *
  4774. * Returns 0 on success, negative value on failure
  4775. **/
  4776. int i40e_vsi_open(struct i40e_vsi *vsi)
  4777. {
  4778. struct i40e_pf *pf = vsi->back;
  4779. char int_name[I40E_INT_NAME_STR_LEN];
  4780. int err;
  4781. /* allocate descriptors */
  4782. err = i40e_vsi_setup_tx_resources(vsi);
  4783. if (err)
  4784. goto err_setup_tx;
  4785. err = i40e_vsi_setup_rx_resources(vsi);
  4786. if (err)
  4787. goto err_setup_rx;
  4788. err = i40e_vsi_configure(vsi);
  4789. if (err)
  4790. goto err_setup_rx;
  4791. if (vsi->netdev) {
  4792. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  4793. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  4794. err = i40e_vsi_request_irq(vsi, int_name);
  4795. if (err)
  4796. goto err_setup_rx;
  4797. /* Notify the stack of the actual queue counts. */
  4798. err = netif_set_real_num_tx_queues(vsi->netdev,
  4799. vsi->num_queue_pairs);
  4800. if (err)
  4801. goto err_set_queues;
  4802. err = netif_set_real_num_rx_queues(vsi->netdev,
  4803. vsi->num_queue_pairs);
  4804. if (err)
  4805. goto err_set_queues;
  4806. } else if (vsi->type == I40E_VSI_FDIR) {
  4807. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  4808. dev_driver_string(&pf->pdev->dev),
  4809. dev_name(&pf->pdev->dev));
  4810. err = i40e_vsi_request_irq(vsi, int_name);
  4811. } else {
  4812. err = -EINVAL;
  4813. goto err_setup_rx;
  4814. }
  4815. err = i40e_up_complete(vsi);
  4816. if (err)
  4817. goto err_up_complete;
  4818. return 0;
  4819. err_up_complete:
  4820. i40e_down(vsi);
  4821. err_set_queues:
  4822. i40e_vsi_free_irq(vsi);
  4823. err_setup_rx:
  4824. i40e_vsi_free_rx_resources(vsi);
  4825. err_setup_tx:
  4826. i40e_vsi_free_tx_resources(vsi);
  4827. if (vsi == pf->vsi[pf->lan_vsi])
  4828. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  4829. return err;
  4830. }
  4831. /**
  4832. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  4833. * @pf: Pointer to PF
  4834. *
  4835. * This function destroys the hlist where all the Flow Director
  4836. * filters were saved.
  4837. **/
  4838. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  4839. {
  4840. struct i40e_fdir_filter *filter;
  4841. struct hlist_node *node2;
  4842. hlist_for_each_entry_safe(filter, node2,
  4843. &pf->fdir_filter_list, fdir_node) {
  4844. hlist_del(&filter->fdir_node);
  4845. kfree(filter);
  4846. }
  4847. pf->fdir_pf_active_filters = 0;
  4848. }
  4849. /**
  4850. * i40e_close - Disables a network interface
  4851. * @netdev: network interface device structure
  4852. *
  4853. * The close entry point is called when an interface is de-activated
  4854. * by the OS. The hardware is still under the driver's control, but
  4855. * this netdev interface is disabled.
  4856. *
  4857. * Returns 0, this is not allowed to fail
  4858. **/
  4859. int i40e_close(struct net_device *netdev)
  4860. {
  4861. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4862. struct i40e_vsi *vsi = np->vsi;
  4863. i40e_vsi_close(vsi);
  4864. return 0;
  4865. }
  4866. /**
  4867. * i40e_do_reset - Start a PF or Core Reset sequence
  4868. * @pf: board private structure
  4869. * @reset_flags: which reset is requested
  4870. *
  4871. * The essential difference in resets is that the PF Reset
  4872. * doesn't clear the packet buffers, doesn't reset the PE
  4873. * firmware, and doesn't bother the other PFs on the chip.
  4874. **/
  4875. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  4876. {
  4877. u32 val;
  4878. WARN_ON(in_interrupt());
  4879. /* do the biggest reset indicated */
  4880. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  4881. /* Request a Global Reset
  4882. *
  4883. * This will start the chip's countdown to the actual full
  4884. * chip reset event, and a warning interrupt to be sent
  4885. * to all PFs, including the requestor. Our handler
  4886. * for the warning interrupt will deal with the shutdown
  4887. * and recovery of the switch setup.
  4888. */
  4889. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  4890. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4891. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  4892. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4893. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  4894. /* Request a Core Reset
  4895. *
  4896. * Same as Global Reset, except does *not* include the MAC/PHY
  4897. */
  4898. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  4899. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4900. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  4901. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4902. i40e_flush(&pf->hw);
  4903. } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
  4904. /* Request a PF Reset
  4905. *
  4906. * Resets only the PF-specific registers
  4907. *
  4908. * This goes directly to the tear-down and rebuild of
  4909. * the switch, since we need to do all the recovery as
  4910. * for the Core Reset.
  4911. */
  4912. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  4913. i40e_handle_reset_warning(pf);
  4914. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  4915. int v;
  4916. /* Find the VSI(s) that requested a re-init */
  4917. dev_info(&pf->pdev->dev,
  4918. "VSI reinit requested\n");
  4919. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4920. struct i40e_vsi *vsi = pf->vsi[v];
  4921. if (vsi != NULL &&
  4922. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  4923. i40e_vsi_reinit_locked(pf->vsi[v]);
  4924. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  4925. }
  4926. }
  4927. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  4928. int v;
  4929. /* Find the VSI(s) that needs to be brought down */
  4930. dev_info(&pf->pdev->dev, "VSI down requested\n");
  4931. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4932. struct i40e_vsi *vsi = pf->vsi[v];
  4933. if (vsi != NULL &&
  4934. test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
  4935. set_bit(__I40E_DOWN, &vsi->state);
  4936. i40e_down(vsi);
  4937. clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  4938. }
  4939. }
  4940. } else {
  4941. dev_info(&pf->pdev->dev,
  4942. "bad reset request 0x%08x\n", reset_flags);
  4943. }
  4944. }
  4945. #ifdef CONFIG_I40E_DCB
  4946. /**
  4947. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  4948. * @pf: board private structure
  4949. * @old_cfg: current DCB config
  4950. * @new_cfg: new DCB config
  4951. **/
  4952. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  4953. struct i40e_dcbx_config *old_cfg,
  4954. struct i40e_dcbx_config *new_cfg)
  4955. {
  4956. bool need_reconfig = false;
  4957. /* Check if ETS configuration has changed */
  4958. if (memcmp(&new_cfg->etscfg,
  4959. &old_cfg->etscfg,
  4960. sizeof(new_cfg->etscfg))) {
  4961. /* If Priority Table has changed reconfig is needed */
  4962. if (memcmp(&new_cfg->etscfg.prioritytable,
  4963. &old_cfg->etscfg.prioritytable,
  4964. sizeof(new_cfg->etscfg.prioritytable))) {
  4965. need_reconfig = true;
  4966. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  4967. }
  4968. if (memcmp(&new_cfg->etscfg.tcbwtable,
  4969. &old_cfg->etscfg.tcbwtable,
  4970. sizeof(new_cfg->etscfg.tcbwtable)))
  4971. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  4972. if (memcmp(&new_cfg->etscfg.tsatable,
  4973. &old_cfg->etscfg.tsatable,
  4974. sizeof(new_cfg->etscfg.tsatable)))
  4975. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  4976. }
  4977. /* Check if PFC configuration has changed */
  4978. if (memcmp(&new_cfg->pfc,
  4979. &old_cfg->pfc,
  4980. sizeof(new_cfg->pfc))) {
  4981. need_reconfig = true;
  4982. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  4983. }
  4984. /* Check if APP Table has changed */
  4985. if (memcmp(&new_cfg->app,
  4986. &old_cfg->app,
  4987. sizeof(new_cfg->app))) {
  4988. need_reconfig = true;
  4989. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  4990. }
  4991. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  4992. return need_reconfig;
  4993. }
  4994. /**
  4995. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  4996. * @pf: board private structure
  4997. * @e: event info posted on ARQ
  4998. **/
  4999. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  5000. struct i40e_arq_event_info *e)
  5001. {
  5002. struct i40e_aqc_lldp_get_mib *mib =
  5003. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  5004. struct i40e_hw *hw = &pf->hw;
  5005. struct i40e_dcbx_config tmp_dcbx_cfg;
  5006. bool need_reconfig = false;
  5007. int ret = 0;
  5008. u8 type;
  5009. /* Not DCB capable or capability disabled */
  5010. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  5011. return ret;
  5012. /* Ignore if event is not for Nearest Bridge */
  5013. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  5014. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  5015. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  5016. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  5017. return ret;
  5018. /* Check MIB Type and return if event for Remote MIB update */
  5019. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  5020. dev_dbg(&pf->pdev->dev,
  5021. "LLDP event mib type %s\n", type ? "remote" : "local");
  5022. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  5023. /* Update the remote cached instance and return */
  5024. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  5025. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  5026. &hw->remote_dcbx_config);
  5027. goto exit;
  5028. }
  5029. /* Store the old configuration */
  5030. tmp_dcbx_cfg = hw->local_dcbx_config;
  5031. /* Reset the old DCBx configuration data */
  5032. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  5033. /* Get updated DCBX data from firmware */
  5034. ret = i40e_get_dcb_config(&pf->hw);
  5035. if (ret) {
  5036. dev_info(&pf->pdev->dev,
  5037. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  5038. i40e_stat_str(&pf->hw, ret),
  5039. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5040. goto exit;
  5041. }
  5042. /* No change detected in DCBX configs */
  5043. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  5044. sizeof(tmp_dcbx_cfg))) {
  5045. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  5046. goto exit;
  5047. }
  5048. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  5049. &hw->local_dcbx_config);
  5050. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  5051. if (!need_reconfig)
  5052. goto exit;
  5053. /* Enable DCB tagging only when more than one TC */
  5054. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5055. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5056. else
  5057. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5058. set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5059. /* Reconfiguration needed quiesce all VSIs */
  5060. i40e_pf_quiesce_all_vsi(pf);
  5061. /* Changes in configuration update VEB/VSI */
  5062. i40e_dcb_reconfigure(pf);
  5063. ret = i40e_resume_port_tx(pf);
  5064. clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5065. /* In case of error no point in resuming VSIs */
  5066. if (ret)
  5067. goto exit;
  5068. /* Wait for the PF's queues to be disabled */
  5069. ret = i40e_pf_wait_queues_disabled(pf);
  5070. if (ret) {
  5071. /* Schedule PF reset to recover */
  5072. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5073. i40e_service_event_schedule(pf);
  5074. } else {
  5075. i40e_pf_unquiesce_all_vsi(pf);
  5076. /* Notify the client for the DCB changes */
  5077. i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]);
  5078. }
  5079. exit:
  5080. return ret;
  5081. }
  5082. #endif /* CONFIG_I40E_DCB */
  5083. /**
  5084. * i40e_do_reset_safe - Protected reset path for userland calls.
  5085. * @pf: board private structure
  5086. * @reset_flags: which reset is requested
  5087. *
  5088. **/
  5089. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  5090. {
  5091. rtnl_lock();
  5092. i40e_do_reset(pf, reset_flags);
  5093. rtnl_unlock();
  5094. }
  5095. /**
  5096. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  5097. * @pf: board private structure
  5098. * @e: event info posted on ARQ
  5099. *
  5100. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  5101. * and VF queues
  5102. **/
  5103. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  5104. struct i40e_arq_event_info *e)
  5105. {
  5106. struct i40e_aqc_lan_overflow *data =
  5107. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  5108. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  5109. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  5110. struct i40e_hw *hw = &pf->hw;
  5111. struct i40e_vf *vf;
  5112. u16 vf_id;
  5113. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  5114. queue, qtx_ctl);
  5115. /* Queue belongs to VF, find the VF and issue VF reset */
  5116. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  5117. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  5118. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  5119. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  5120. vf_id -= hw->func_caps.vf_base_id;
  5121. vf = &pf->vf[vf_id];
  5122. i40e_vc_notify_vf_reset(vf);
  5123. /* Allow VF to process pending reset notification */
  5124. msleep(20);
  5125. i40e_reset_vf(vf, false);
  5126. }
  5127. }
  5128. /**
  5129. * i40e_service_event_complete - Finish up the service event
  5130. * @pf: board private structure
  5131. **/
  5132. static void i40e_service_event_complete(struct i40e_pf *pf)
  5133. {
  5134. WARN_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
  5135. /* flush memory to make sure state is correct before next watchog */
  5136. smp_mb__before_atomic();
  5137. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  5138. }
  5139. /**
  5140. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  5141. * @pf: board private structure
  5142. **/
  5143. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  5144. {
  5145. u32 val, fcnt_prog;
  5146. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5147. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  5148. return fcnt_prog;
  5149. }
  5150. /**
  5151. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  5152. * @pf: board private structure
  5153. **/
  5154. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  5155. {
  5156. u32 val, fcnt_prog;
  5157. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5158. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  5159. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  5160. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  5161. return fcnt_prog;
  5162. }
  5163. /**
  5164. * i40e_get_global_fd_count - Get total FD filters programmed on device
  5165. * @pf: board private structure
  5166. **/
  5167. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  5168. {
  5169. u32 val, fcnt_prog;
  5170. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  5171. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  5172. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  5173. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  5174. return fcnt_prog;
  5175. }
  5176. /**
  5177. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  5178. * @pf: board private structure
  5179. **/
  5180. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  5181. {
  5182. struct i40e_fdir_filter *filter;
  5183. u32 fcnt_prog, fcnt_avail;
  5184. struct hlist_node *node;
  5185. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5186. return;
  5187. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  5188. * to re-enable
  5189. */
  5190. fcnt_prog = i40e_get_global_fd_count(pf);
  5191. fcnt_avail = pf->fdir_pf_filter_count;
  5192. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  5193. (pf->fd_add_err == 0) ||
  5194. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  5195. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  5196. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  5197. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5198. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5199. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  5200. }
  5201. }
  5202. /* Wait for some more space to be available to turn on ATR. We also
  5203. * must check that no existing ntuple rules for TCP are in effect
  5204. */
  5205. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  5206. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5207. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5208. (pf->fd_tcp_rule == 0)) {
  5209. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5210. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5211. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  5212. }
  5213. }
  5214. /* if hw had a problem adding a filter, delete it */
  5215. if (pf->fd_inv > 0) {
  5216. hlist_for_each_entry_safe(filter, node,
  5217. &pf->fdir_filter_list, fdir_node) {
  5218. if (filter->fd_id == pf->fd_inv) {
  5219. hlist_del(&filter->fdir_node);
  5220. kfree(filter);
  5221. pf->fdir_pf_active_filters--;
  5222. }
  5223. }
  5224. }
  5225. }
  5226. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  5227. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  5228. /**
  5229. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  5230. * @pf: board private structure
  5231. **/
  5232. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  5233. {
  5234. unsigned long min_flush_time;
  5235. int flush_wait_retry = 50;
  5236. bool disable_atr = false;
  5237. int fd_room;
  5238. int reg;
  5239. if (!time_after(jiffies, pf->fd_flush_timestamp +
  5240. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  5241. return;
  5242. /* If the flush is happening too quick and we have mostly SB rules we
  5243. * should not re-enable ATR for some time.
  5244. */
  5245. min_flush_time = pf->fd_flush_timestamp +
  5246. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  5247. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  5248. if (!(time_after(jiffies, min_flush_time)) &&
  5249. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  5250. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5251. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  5252. disable_atr = true;
  5253. }
  5254. pf->fd_flush_timestamp = jiffies;
  5255. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  5256. /* flush all filters */
  5257. wr32(&pf->hw, I40E_PFQF_CTL_1,
  5258. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  5259. i40e_flush(&pf->hw);
  5260. pf->fd_flush_cnt++;
  5261. pf->fd_add_err = 0;
  5262. do {
  5263. /* Check FD flush status every 5-6msec */
  5264. usleep_range(5000, 6000);
  5265. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  5266. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  5267. break;
  5268. } while (flush_wait_retry--);
  5269. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  5270. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  5271. } else {
  5272. /* replay sideband filters */
  5273. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  5274. if (!disable_atr)
  5275. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5276. clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  5277. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5278. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  5279. }
  5280. }
  5281. /**
  5282. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  5283. * @pf: board private structure
  5284. **/
  5285. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  5286. {
  5287. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  5288. }
  5289. /* We can see up to 256 filter programming desc in transit if the filters are
  5290. * being applied really fast; before we see the first
  5291. * filter miss error on Rx queue 0. Accumulating enough error messages before
  5292. * reacting will make sure we don't cause flush too often.
  5293. */
  5294. #define I40E_MAX_FD_PROGRAM_ERROR 256
  5295. /**
  5296. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  5297. * @pf: board private structure
  5298. **/
  5299. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  5300. {
  5301. /* if interface is down do nothing */
  5302. if (test_bit(__I40E_DOWN, &pf->state))
  5303. return;
  5304. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5305. i40e_fdir_flush_and_replay(pf);
  5306. i40e_fdir_check_and_reenable(pf);
  5307. }
  5308. /**
  5309. * i40e_vsi_link_event - notify VSI of a link event
  5310. * @vsi: vsi to be notified
  5311. * @link_up: link up or down
  5312. **/
  5313. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  5314. {
  5315. if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
  5316. return;
  5317. switch (vsi->type) {
  5318. case I40E_VSI_MAIN:
  5319. #ifdef I40E_FCOE
  5320. case I40E_VSI_FCOE:
  5321. #endif
  5322. if (!vsi->netdev || !vsi->netdev_registered)
  5323. break;
  5324. if (link_up) {
  5325. netif_carrier_on(vsi->netdev);
  5326. netif_tx_wake_all_queues(vsi->netdev);
  5327. } else {
  5328. netif_carrier_off(vsi->netdev);
  5329. netif_tx_stop_all_queues(vsi->netdev);
  5330. }
  5331. break;
  5332. case I40E_VSI_SRIOV:
  5333. case I40E_VSI_VMDQ2:
  5334. case I40E_VSI_CTRL:
  5335. case I40E_VSI_IWARP:
  5336. case I40E_VSI_MIRROR:
  5337. default:
  5338. /* there is no notification for other VSIs */
  5339. break;
  5340. }
  5341. }
  5342. /**
  5343. * i40e_veb_link_event - notify elements on the veb of a link event
  5344. * @veb: veb to be notified
  5345. * @link_up: link up or down
  5346. **/
  5347. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  5348. {
  5349. struct i40e_pf *pf;
  5350. int i;
  5351. if (!veb || !veb->pf)
  5352. return;
  5353. pf = veb->pf;
  5354. /* depth first... */
  5355. for (i = 0; i < I40E_MAX_VEB; i++)
  5356. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  5357. i40e_veb_link_event(pf->veb[i], link_up);
  5358. /* ... now the local VSIs */
  5359. for (i = 0; i < pf->num_alloc_vsi; i++)
  5360. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  5361. i40e_vsi_link_event(pf->vsi[i], link_up);
  5362. }
  5363. /**
  5364. * i40e_link_event - Update netif_carrier status
  5365. * @pf: board private structure
  5366. **/
  5367. static void i40e_link_event(struct i40e_pf *pf)
  5368. {
  5369. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5370. u8 new_link_speed, old_link_speed;
  5371. i40e_status status;
  5372. bool new_link, old_link;
  5373. /* save off old link status information */
  5374. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  5375. /* set this to force the get_link_status call to refresh state */
  5376. pf->hw.phy.get_link_info = true;
  5377. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  5378. status = i40e_get_link_status(&pf->hw, &new_link);
  5379. if (status) {
  5380. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  5381. status);
  5382. return;
  5383. }
  5384. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  5385. new_link_speed = pf->hw.phy.link_info.link_speed;
  5386. if (new_link == old_link &&
  5387. new_link_speed == old_link_speed &&
  5388. (test_bit(__I40E_DOWN, &vsi->state) ||
  5389. new_link == netif_carrier_ok(vsi->netdev)))
  5390. return;
  5391. if (!test_bit(__I40E_DOWN, &vsi->state))
  5392. i40e_print_link_message(vsi, new_link);
  5393. /* Notify the base of the switch tree connected to
  5394. * the link. Floating VEBs are not notified.
  5395. */
  5396. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  5397. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  5398. else
  5399. i40e_vsi_link_event(vsi, new_link);
  5400. if (pf->vf)
  5401. i40e_vc_notify_link_state(pf);
  5402. if (pf->flags & I40E_FLAG_PTP)
  5403. i40e_ptp_set_increment(pf);
  5404. }
  5405. /**
  5406. * i40e_watchdog_subtask - periodic checks not using event driven response
  5407. * @pf: board private structure
  5408. **/
  5409. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  5410. {
  5411. int i;
  5412. /* if interface is down do nothing */
  5413. if (test_bit(__I40E_DOWN, &pf->state) ||
  5414. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5415. return;
  5416. /* make sure we don't do these things too often */
  5417. if (time_before(jiffies, (pf->service_timer_previous +
  5418. pf->service_timer_period)))
  5419. return;
  5420. pf->service_timer_previous = jiffies;
  5421. if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
  5422. i40e_link_event(pf);
  5423. /* Update the stats for active netdevs so the network stack
  5424. * can look at updated numbers whenever it cares to
  5425. */
  5426. for (i = 0; i < pf->num_alloc_vsi; i++)
  5427. if (pf->vsi[i] && pf->vsi[i]->netdev)
  5428. i40e_update_stats(pf->vsi[i]);
  5429. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  5430. /* Update the stats for the active switching components */
  5431. for (i = 0; i < I40E_MAX_VEB; i++)
  5432. if (pf->veb[i])
  5433. i40e_update_veb_stats(pf->veb[i]);
  5434. }
  5435. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  5436. }
  5437. /**
  5438. * i40e_reset_subtask - Set up for resetting the device and driver
  5439. * @pf: board private structure
  5440. **/
  5441. static void i40e_reset_subtask(struct i40e_pf *pf)
  5442. {
  5443. u32 reset_flags = 0;
  5444. rtnl_lock();
  5445. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  5446. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  5447. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  5448. }
  5449. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  5450. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  5451. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5452. }
  5453. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  5454. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  5455. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  5456. }
  5457. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  5458. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  5459. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  5460. }
  5461. if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
  5462. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  5463. clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
  5464. }
  5465. /* If there's a recovery already waiting, it takes
  5466. * precedence before starting a new reset sequence.
  5467. */
  5468. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  5469. i40e_handle_reset_warning(pf);
  5470. goto unlock;
  5471. }
  5472. /* If we're already down or resetting, just bail */
  5473. if (reset_flags &&
  5474. !test_bit(__I40E_DOWN, &pf->state) &&
  5475. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5476. i40e_do_reset(pf, reset_flags);
  5477. unlock:
  5478. rtnl_unlock();
  5479. }
  5480. /**
  5481. * i40e_handle_link_event - Handle link event
  5482. * @pf: board private structure
  5483. * @e: event info posted on ARQ
  5484. **/
  5485. static void i40e_handle_link_event(struct i40e_pf *pf,
  5486. struct i40e_arq_event_info *e)
  5487. {
  5488. struct i40e_aqc_get_link_status *status =
  5489. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  5490. /* Do a new status request to re-enable LSE reporting
  5491. * and load new status information into the hw struct
  5492. * This completely ignores any state information
  5493. * in the ARQ event info, instead choosing to always
  5494. * issue the AQ update link status command.
  5495. */
  5496. i40e_link_event(pf);
  5497. /* check for unqualified module, if link is down */
  5498. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  5499. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  5500. (!(status->link_info & I40E_AQ_LINK_UP)))
  5501. dev_err(&pf->pdev->dev,
  5502. "The driver failed to link because an unqualified module was detected.\n");
  5503. }
  5504. /**
  5505. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  5506. * @pf: board private structure
  5507. **/
  5508. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  5509. {
  5510. struct i40e_arq_event_info event;
  5511. struct i40e_hw *hw = &pf->hw;
  5512. u16 pending, i = 0;
  5513. i40e_status ret;
  5514. u16 opcode;
  5515. u32 oldval;
  5516. u32 val;
  5517. /* Do not run clean AQ when PF reset fails */
  5518. if (test_bit(__I40E_RESET_FAILED, &pf->state))
  5519. return;
  5520. /* check for error indications */
  5521. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  5522. oldval = val;
  5523. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  5524. if (hw->debug_mask & I40E_DEBUG_AQ)
  5525. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  5526. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  5527. }
  5528. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  5529. if (hw->debug_mask & I40E_DEBUG_AQ)
  5530. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  5531. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  5532. pf->arq_overflows++;
  5533. }
  5534. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  5535. if (hw->debug_mask & I40E_DEBUG_AQ)
  5536. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  5537. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  5538. }
  5539. if (oldval != val)
  5540. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  5541. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  5542. oldval = val;
  5543. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  5544. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5545. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  5546. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  5547. }
  5548. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  5549. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5550. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  5551. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  5552. }
  5553. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  5554. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5555. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  5556. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  5557. }
  5558. if (oldval != val)
  5559. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  5560. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  5561. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  5562. if (!event.msg_buf)
  5563. return;
  5564. do {
  5565. ret = i40e_clean_arq_element(hw, &event, &pending);
  5566. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  5567. break;
  5568. else if (ret) {
  5569. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  5570. break;
  5571. }
  5572. opcode = le16_to_cpu(event.desc.opcode);
  5573. switch (opcode) {
  5574. case i40e_aqc_opc_get_link_status:
  5575. i40e_handle_link_event(pf, &event);
  5576. break;
  5577. case i40e_aqc_opc_send_msg_to_pf:
  5578. ret = i40e_vc_process_vf_msg(pf,
  5579. le16_to_cpu(event.desc.retval),
  5580. le32_to_cpu(event.desc.cookie_high),
  5581. le32_to_cpu(event.desc.cookie_low),
  5582. event.msg_buf,
  5583. event.msg_len);
  5584. break;
  5585. case i40e_aqc_opc_lldp_update_mib:
  5586. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  5587. #ifdef CONFIG_I40E_DCB
  5588. rtnl_lock();
  5589. ret = i40e_handle_lldp_event(pf, &event);
  5590. rtnl_unlock();
  5591. #endif /* CONFIG_I40E_DCB */
  5592. break;
  5593. case i40e_aqc_opc_event_lan_overflow:
  5594. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  5595. i40e_handle_lan_overflow_event(pf, &event);
  5596. break;
  5597. case i40e_aqc_opc_send_msg_to_peer:
  5598. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  5599. break;
  5600. case i40e_aqc_opc_nvm_erase:
  5601. case i40e_aqc_opc_nvm_update:
  5602. case i40e_aqc_opc_oem_post_update:
  5603. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  5604. "ARQ NVM operation 0x%04x completed\n",
  5605. opcode);
  5606. break;
  5607. default:
  5608. dev_info(&pf->pdev->dev,
  5609. "ARQ: Unknown event 0x%04x ignored\n",
  5610. opcode);
  5611. break;
  5612. }
  5613. } while (pending && (i++ < pf->adminq_work_limit));
  5614. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  5615. /* re-enable Admin queue interrupt cause */
  5616. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  5617. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  5618. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  5619. i40e_flush(hw);
  5620. kfree(event.msg_buf);
  5621. }
  5622. /**
  5623. * i40e_verify_eeprom - make sure eeprom is good to use
  5624. * @pf: board private structure
  5625. **/
  5626. static void i40e_verify_eeprom(struct i40e_pf *pf)
  5627. {
  5628. int err;
  5629. err = i40e_diag_eeprom_test(&pf->hw);
  5630. if (err) {
  5631. /* retry in case of garbage read */
  5632. err = i40e_diag_eeprom_test(&pf->hw);
  5633. if (err) {
  5634. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  5635. err);
  5636. set_bit(__I40E_BAD_EEPROM, &pf->state);
  5637. }
  5638. }
  5639. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  5640. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  5641. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  5642. }
  5643. }
  5644. /**
  5645. * i40e_enable_pf_switch_lb
  5646. * @pf: pointer to the PF structure
  5647. *
  5648. * enable switch loop back or die - no point in a return value
  5649. **/
  5650. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  5651. {
  5652. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5653. struct i40e_vsi_context ctxt;
  5654. int ret;
  5655. ctxt.seid = pf->main_vsi_seid;
  5656. ctxt.pf_num = pf->hw.pf_id;
  5657. ctxt.vf_num = 0;
  5658. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5659. if (ret) {
  5660. dev_info(&pf->pdev->dev,
  5661. "couldn't get PF vsi config, err %s aq_err %s\n",
  5662. i40e_stat_str(&pf->hw, ret),
  5663. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5664. return;
  5665. }
  5666. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5667. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5668. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5669. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5670. if (ret) {
  5671. dev_info(&pf->pdev->dev,
  5672. "update vsi switch failed, err %s aq_err %s\n",
  5673. i40e_stat_str(&pf->hw, ret),
  5674. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5675. }
  5676. }
  5677. /**
  5678. * i40e_disable_pf_switch_lb
  5679. * @pf: pointer to the PF structure
  5680. *
  5681. * disable switch loop back or die - no point in a return value
  5682. **/
  5683. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  5684. {
  5685. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5686. struct i40e_vsi_context ctxt;
  5687. int ret;
  5688. ctxt.seid = pf->main_vsi_seid;
  5689. ctxt.pf_num = pf->hw.pf_id;
  5690. ctxt.vf_num = 0;
  5691. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5692. if (ret) {
  5693. dev_info(&pf->pdev->dev,
  5694. "couldn't get PF vsi config, err %s aq_err %s\n",
  5695. i40e_stat_str(&pf->hw, ret),
  5696. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5697. return;
  5698. }
  5699. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5700. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5701. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5702. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5703. if (ret) {
  5704. dev_info(&pf->pdev->dev,
  5705. "update vsi switch failed, err %s aq_err %s\n",
  5706. i40e_stat_str(&pf->hw, ret),
  5707. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5708. }
  5709. }
  5710. /**
  5711. * i40e_config_bridge_mode - Configure the HW bridge mode
  5712. * @veb: pointer to the bridge instance
  5713. *
  5714. * Configure the loop back mode for the LAN VSI that is downlink to the
  5715. * specified HW bridge instance. It is expected this function is called
  5716. * when a new HW bridge is instantiated.
  5717. **/
  5718. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  5719. {
  5720. struct i40e_pf *pf = veb->pf;
  5721. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  5722. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  5723. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  5724. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  5725. i40e_disable_pf_switch_lb(pf);
  5726. else
  5727. i40e_enable_pf_switch_lb(pf);
  5728. }
  5729. /**
  5730. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  5731. * @veb: pointer to the VEB instance
  5732. *
  5733. * This is a recursive function that first builds the attached VSIs then
  5734. * recurses in to build the next layer of VEB. We track the connections
  5735. * through our own index numbers because the seid's from the HW could
  5736. * change across the reset.
  5737. **/
  5738. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  5739. {
  5740. struct i40e_vsi *ctl_vsi = NULL;
  5741. struct i40e_pf *pf = veb->pf;
  5742. int v, veb_idx;
  5743. int ret;
  5744. /* build VSI that owns this VEB, temporarily attached to base VEB */
  5745. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  5746. if (pf->vsi[v] &&
  5747. pf->vsi[v]->veb_idx == veb->idx &&
  5748. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  5749. ctl_vsi = pf->vsi[v];
  5750. break;
  5751. }
  5752. }
  5753. if (!ctl_vsi) {
  5754. dev_info(&pf->pdev->dev,
  5755. "missing owner VSI for veb_idx %d\n", veb->idx);
  5756. ret = -ENOENT;
  5757. goto end_reconstitute;
  5758. }
  5759. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  5760. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5761. ret = i40e_add_vsi(ctl_vsi);
  5762. if (ret) {
  5763. dev_info(&pf->pdev->dev,
  5764. "rebuild of veb_idx %d owner VSI failed: %d\n",
  5765. veb->idx, ret);
  5766. goto end_reconstitute;
  5767. }
  5768. i40e_vsi_reset_stats(ctl_vsi);
  5769. /* create the VEB in the switch and move the VSI onto the VEB */
  5770. ret = i40e_add_veb(veb, ctl_vsi);
  5771. if (ret)
  5772. goto end_reconstitute;
  5773. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  5774. veb->bridge_mode = BRIDGE_MODE_VEB;
  5775. else
  5776. veb->bridge_mode = BRIDGE_MODE_VEPA;
  5777. i40e_config_bridge_mode(veb);
  5778. /* create the remaining VSIs attached to this VEB */
  5779. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5780. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  5781. continue;
  5782. if (pf->vsi[v]->veb_idx == veb->idx) {
  5783. struct i40e_vsi *vsi = pf->vsi[v];
  5784. vsi->uplink_seid = veb->seid;
  5785. ret = i40e_add_vsi(vsi);
  5786. if (ret) {
  5787. dev_info(&pf->pdev->dev,
  5788. "rebuild of vsi_idx %d failed: %d\n",
  5789. v, ret);
  5790. goto end_reconstitute;
  5791. }
  5792. i40e_vsi_reset_stats(vsi);
  5793. }
  5794. }
  5795. /* create any VEBs attached to this VEB - RECURSION */
  5796. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5797. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  5798. pf->veb[veb_idx]->uplink_seid = veb->seid;
  5799. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  5800. if (ret)
  5801. break;
  5802. }
  5803. }
  5804. end_reconstitute:
  5805. return ret;
  5806. }
  5807. /**
  5808. * i40e_get_capabilities - get info about the HW
  5809. * @pf: the PF struct
  5810. **/
  5811. static int i40e_get_capabilities(struct i40e_pf *pf)
  5812. {
  5813. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  5814. u16 data_size;
  5815. int buf_len;
  5816. int err;
  5817. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  5818. do {
  5819. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  5820. if (!cap_buf)
  5821. return -ENOMEM;
  5822. /* this loads the data into the hw struct for us */
  5823. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  5824. &data_size,
  5825. i40e_aqc_opc_list_func_capabilities,
  5826. NULL);
  5827. /* data loaded, buffer no longer needed */
  5828. kfree(cap_buf);
  5829. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  5830. /* retry with a larger buffer */
  5831. buf_len = data_size;
  5832. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  5833. dev_info(&pf->pdev->dev,
  5834. "capability discovery failed, err %s aq_err %s\n",
  5835. i40e_stat_str(&pf->hw, err),
  5836. i40e_aq_str(&pf->hw,
  5837. pf->hw.aq.asq_last_status));
  5838. return -ENODEV;
  5839. }
  5840. } while (err);
  5841. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  5842. dev_info(&pf->pdev->dev,
  5843. "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",
  5844. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  5845. pf->hw.func_caps.num_msix_vectors,
  5846. pf->hw.func_caps.num_msix_vectors_vf,
  5847. pf->hw.func_caps.fd_filters_guaranteed,
  5848. pf->hw.func_caps.fd_filters_best_effort,
  5849. pf->hw.func_caps.num_tx_qp,
  5850. pf->hw.func_caps.num_vsis);
  5851. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  5852. + pf->hw.func_caps.num_vfs)
  5853. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  5854. dev_info(&pf->pdev->dev,
  5855. "got num_vsis %d, setting num_vsis to %d\n",
  5856. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  5857. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  5858. }
  5859. return 0;
  5860. }
  5861. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  5862. /**
  5863. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  5864. * @pf: board private structure
  5865. **/
  5866. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  5867. {
  5868. struct i40e_vsi *vsi;
  5869. int i;
  5870. /* quick workaround for an NVM issue that leaves a critical register
  5871. * uninitialized
  5872. */
  5873. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  5874. static const u32 hkey[] = {
  5875. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  5876. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  5877. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  5878. 0x95b3a76d};
  5879. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  5880. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  5881. }
  5882. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  5883. return;
  5884. /* find existing VSI and see if it needs configuring */
  5885. vsi = NULL;
  5886. for (i = 0; i < pf->num_alloc_vsi; i++) {
  5887. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  5888. vsi = pf->vsi[i];
  5889. break;
  5890. }
  5891. }
  5892. /* create a new VSI if none exists */
  5893. if (!vsi) {
  5894. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  5895. pf->vsi[pf->lan_vsi]->seid, 0);
  5896. if (!vsi) {
  5897. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  5898. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5899. return;
  5900. }
  5901. }
  5902. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  5903. }
  5904. /**
  5905. * i40e_fdir_teardown - release the Flow Director resources
  5906. * @pf: board private structure
  5907. **/
  5908. static void i40e_fdir_teardown(struct i40e_pf *pf)
  5909. {
  5910. int i;
  5911. i40e_fdir_filter_exit(pf);
  5912. for (i = 0; i < pf->num_alloc_vsi; i++) {
  5913. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  5914. i40e_vsi_release(pf->vsi[i]);
  5915. break;
  5916. }
  5917. }
  5918. }
  5919. /**
  5920. * i40e_prep_for_reset - prep for the core to reset
  5921. * @pf: board private structure
  5922. *
  5923. * Close up the VFs and other things in prep for PF Reset.
  5924. **/
  5925. static void i40e_prep_for_reset(struct i40e_pf *pf)
  5926. {
  5927. struct i40e_hw *hw = &pf->hw;
  5928. i40e_status ret = 0;
  5929. u32 v;
  5930. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  5931. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  5932. return;
  5933. if (i40e_check_asq_alive(&pf->hw))
  5934. i40e_vc_notify_reset(pf);
  5935. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  5936. /* quiesce the VSIs and their queues that are not already DOWN */
  5937. i40e_pf_quiesce_all_vsi(pf);
  5938. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5939. if (pf->vsi[v])
  5940. pf->vsi[v]->seid = 0;
  5941. }
  5942. i40e_shutdown_adminq(&pf->hw);
  5943. /* call shutdown HMC */
  5944. if (hw->hmc.hmc_obj) {
  5945. ret = i40e_shutdown_lan_hmc(hw);
  5946. if (ret)
  5947. dev_warn(&pf->pdev->dev,
  5948. "shutdown_lan_hmc failed: %d\n", ret);
  5949. }
  5950. }
  5951. /**
  5952. * i40e_send_version - update firmware with driver version
  5953. * @pf: PF struct
  5954. */
  5955. static void i40e_send_version(struct i40e_pf *pf)
  5956. {
  5957. struct i40e_driver_version dv;
  5958. dv.major_version = DRV_VERSION_MAJOR;
  5959. dv.minor_version = DRV_VERSION_MINOR;
  5960. dv.build_version = DRV_VERSION_BUILD;
  5961. dv.subbuild_version = 0;
  5962. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  5963. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  5964. }
  5965. /**
  5966. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  5967. * @pf: board private structure
  5968. * @reinit: if the Main VSI needs to re-initialized.
  5969. **/
  5970. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  5971. {
  5972. struct i40e_hw *hw = &pf->hw;
  5973. u8 set_fc_aq_fail = 0;
  5974. i40e_status ret;
  5975. u32 val;
  5976. u32 v;
  5977. /* Now we wait for GRST to settle out.
  5978. * We don't have to delete the VEBs or VSIs from the hw switch
  5979. * because the reset will make them disappear.
  5980. */
  5981. ret = i40e_pf_reset(hw);
  5982. if (ret) {
  5983. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  5984. set_bit(__I40E_RESET_FAILED, &pf->state);
  5985. goto clear_recovery;
  5986. }
  5987. pf->pfr_count++;
  5988. if (test_bit(__I40E_DOWN, &pf->state))
  5989. goto clear_recovery;
  5990. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  5991. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  5992. ret = i40e_init_adminq(&pf->hw);
  5993. if (ret) {
  5994. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  5995. i40e_stat_str(&pf->hw, ret),
  5996. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5997. goto clear_recovery;
  5998. }
  5999. /* re-verify the eeprom if we just had an EMP reset */
  6000. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
  6001. i40e_verify_eeprom(pf);
  6002. i40e_clear_pxe_mode(hw);
  6003. ret = i40e_get_capabilities(pf);
  6004. if (ret)
  6005. goto end_core_reset;
  6006. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  6007. hw->func_caps.num_rx_qp,
  6008. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  6009. if (ret) {
  6010. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  6011. goto end_core_reset;
  6012. }
  6013. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  6014. if (ret) {
  6015. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  6016. goto end_core_reset;
  6017. }
  6018. #ifdef CONFIG_I40E_DCB
  6019. ret = i40e_init_pf_dcb(pf);
  6020. if (ret) {
  6021. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  6022. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  6023. /* Continue without DCB enabled */
  6024. }
  6025. #endif /* CONFIG_I40E_DCB */
  6026. #ifdef I40E_FCOE
  6027. i40e_init_pf_fcoe(pf);
  6028. #endif
  6029. /* do basic switch setup */
  6030. ret = i40e_setup_pf_switch(pf, reinit);
  6031. if (ret)
  6032. goto end_core_reset;
  6033. /* The driver only wants link up/down and module qualification
  6034. * reports from firmware. Note the negative logic.
  6035. */
  6036. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  6037. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  6038. I40E_AQ_EVENT_MEDIA_NA |
  6039. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  6040. if (ret)
  6041. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  6042. i40e_stat_str(&pf->hw, ret),
  6043. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6044. /* make sure our flow control settings are restored */
  6045. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  6046. if (ret)
  6047. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  6048. i40e_stat_str(&pf->hw, ret),
  6049. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6050. /* Rebuild the VSIs and VEBs that existed before reset.
  6051. * They are still in our local switch element arrays, so only
  6052. * need to rebuild the switch model in the HW.
  6053. *
  6054. * If there were VEBs but the reconstitution failed, we'll try
  6055. * try to recover minimal use by getting the basic PF VSI working.
  6056. */
  6057. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  6058. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  6059. /* find the one VEB connected to the MAC, and find orphans */
  6060. for (v = 0; v < I40E_MAX_VEB; v++) {
  6061. if (!pf->veb[v])
  6062. continue;
  6063. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  6064. pf->veb[v]->uplink_seid == 0) {
  6065. ret = i40e_reconstitute_veb(pf->veb[v]);
  6066. if (!ret)
  6067. continue;
  6068. /* If Main VEB failed, we're in deep doodoo,
  6069. * so give up rebuilding the switch and set up
  6070. * for minimal rebuild of PF VSI.
  6071. * If orphan failed, we'll report the error
  6072. * but try to keep going.
  6073. */
  6074. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  6075. dev_info(&pf->pdev->dev,
  6076. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  6077. ret);
  6078. pf->vsi[pf->lan_vsi]->uplink_seid
  6079. = pf->mac_seid;
  6080. break;
  6081. } else if (pf->veb[v]->uplink_seid == 0) {
  6082. dev_info(&pf->pdev->dev,
  6083. "rebuild of orphan VEB failed: %d\n",
  6084. ret);
  6085. }
  6086. }
  6087. }
  6088. }
  6089. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  6090. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  6091. /* no VEB, so rebuild only the Main VSI */
  6092. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  6093. if (ret) {
  6094. dev_info(&pf->pdev->dev,
  6095. "rebuild of Main VSI failed: %d\n", ret);
  6096. goto end_core_reset;
  6097. }
  6098. }
  6099. /* Reconfigure hardware for allowing smaller MSS in the case
  6100. * of TSO, so that we avoid the MDD being fired and causing
  6101. * a reset in the case of small MSS+TSO.
  6102. */
  6103. #define I40E_REG_MSS 0x000E64DC
  6104. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  6105. #define I40E_64BYTE_MSS 0x400000
  6106. val = rd32(hw, I40E_REG_MSS);
  6107. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  6108. val &= ~I40E_REG_MSS_MIN_MASK;
  6109. val |= I40E_64BYTE_MSS;
  6110. wr32(hw, I40E_REG_MSS, val);
  6111. }
  6112. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  6113. msleep(75);
  6114. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  6115. if (ret)
  6116. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  6117. i40e_stat_str(&pf->hw, ret),
  6118. i40e_aq_str(&pf->hw,
  6119. pf->hw.aq.asq_last_status));
  6120. }
  6121. /* reinit the misc interrupt */
  6122. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6123. ret = i40e_setup_misc_vector(pf);
  6124. /* Add a filter to drop all Flow control frames from any VSI from being
  6125. * transmitted. By doing so we stop a malicious VF from sending out
  6126. * PAUSE or PFC frames and potentially controlling traffic for other
  6127. * PF/VF VSIs.
  6128. * The FW can still send Flow control frames if enabled.
  6129. */
  6130. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  6131. pf->main_vsi_seid);
  6132. /* restart the VSIs that were rebuilt and running before the reset */
  6133. i40e_pf_unquiesce_all_vsi(pf);
  6134. if (pf->num_alloc_vfs) {
  6135. for (v = 0; v < pf->num_alloc_vfs; v++)
  6136. i40e_reset_vf(&pf->vf[v], true);
  6137. }
  6138. /* tell the firmware that we're starting */
  6139. i40e_send_version(pf);
  6140. end_core_reset:
  6141. clear_bit(__I40E_RESET_FAILED, &pf->state);
  6142. clear_recovery:
  6143. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  6144. }
  6145. /**
  6146. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  6147. * @pf: board private structure
  6148. *
  6149. * Close up the VFs and other things in prep for a Core Reset,
  6150. * then get ready to rebuild the world.
  6151. **/
  6152. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  6153. {
  6154. i40e_prep_for_reset(pf);
  6155. i40e_reset_and_rebuild(pf, false);
  6156. }
  6157. /**
  6158. * i40e_handle_mdd_event
  6159. * @pf: pointer to the PF structure
  6160. *
  6161. * Called from the MDD irq handler to identify possibly malicious vfs
  6162. **/
  6163. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  6164. {
  6165. struct i40e_hw *hw = &pf->hw;
  6166. bool mdd_detected = false;
  6167. bool pf_mdd_detected = false;
  6168. struct i40e_vf *vf;
  6169. u32 reg;
  6170. int i;
  6171. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  6172. return;
  6173. /* find what triggered the MDD event */
  6174. reg = rd32(hw, I40E_GL_MDET_TX);
  6175. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  6176. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  6177. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  6178. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  6179. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  6180. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  6181. I40E_GL_MDET_TX_EVENT_SHIFT;
  6182. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  6183. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  6184. pf->hw.func_caps.base_queue;
  6185. if (netif_msg_tx_err(pf))
  6186. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  6187. event, queue, pf_num, vf_num);
  6188. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  6189. mdd_detected = true;
  6190. }
  6191. reg = rd32(hw, I40E_GL_MDET_RX);
  6192. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  6193. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  6194. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  6195. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  6196. I40E_GL_MDET_RX_EVENT_SHIFT;
  6197. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  6198. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  6199. pf->hw.func_caps.base_queue;
  6200. if (netif_msg_rx_err(pf))
  6201. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  6202. event, queue, func);
  6203. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  6204. mdd_detected = true;
  6205. }
  6206. if (mdd_detected) {
  6207. reg = rd32(hw, I40E_PF_MDET_TX);
  6208. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  6209. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  6210. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  6211. pf_mdd_detected = true;
  6212. }
  6213. reg = rd32(hw, I40E_PF_MDET_RX);
  6214. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  6215. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  6216. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  6217. pf_mdd_detected = true;
  6218. }
  6219. /* Queue belongs to the PF, initiate a reset */
  6220. if (pf_mdd_detected) {
  6221. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  6222. i40e_service_event_schedule(pf);
  6223. }
  6224. }
  6225. /* see if one of the VFs needs its hand slapped */
  6226. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  6227. vf = &(pf->vf[i]);
  6228. reg = rd32(hw, I40E_VP_MDET_TX(i));
  6229. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  6230. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  6231. vf->num_mdd_events++;
  6232. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  6233. i);
  6234. }
  6235. reg = rd32(hw, I40E_VP_MDET_RX(i));
  6236. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  6237. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  6238. vf->num_mdd_events++;
  6239. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  6240. i);
  6241. }
  6242. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  6243. dev_info(&pf->pdev->dev,
  6244. "Too many MDD events on VF %d, disabled\n", i);
  6245. dev_info(&pf->pdev->dev,
  6246. "Use PF Control I/F to re-enable the VF\n");
  6247. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  6248. }
  6249. }
  6250. /* re-enable mdd interrupt cause */
  6251. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  6252. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  6253. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  6254. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  6255. i40e_flush(hw);
  6256. }
  6257. /**
  6258. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  6259. * @pf: board private structure
  6260. **/
  6261. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  6262. {
  6263. struct i40e_hw *hw = &pf->hw;
  6264. i40e_status ret;
  6265. __be16 port;
  6266. int i;
  6267. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  6268. return;
  6269. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  6270. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  6271. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  6272. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  6273. port = pf->udp_ports[i].index;
  6274. if (port)
  6275. ret = i40e_aq_add_udp_tunnel(hw, port,
  6276. pf->udp_ports[i].type,
  6277. NULL, NULL);
  6278. else
  6279. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  6280. if (ret) {
  6281. dev_dbg(&pf->pdev->dev,
  6282. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  6283. pf->udp_ports[i].type ? "vxlan" : "geneve",
  6284. port ? "add" : "delete",
  6285. ntohs(port), i,
  6286. i40e_stat_str(&pf->hw, ret),
  6287. i40e_aq_str(&pf->hw,
  6288. pf->hw.aq.asq_last_status));
  6289. pf->udp_ports[i].index = 0;
  6290. }
  6291. }
  6292. }
  6293. }
  6294. /**
  6295. * i40e_service_task - Run the driver's async subtasks
  6296. * @work: pointer to work_struct containing our data
  6297. **/
  6298. static void i40e_service_task(struct work_struct *work)
  6299. {
  6300. struct i40e_pf *pf = container_of(work,
  6301. struct i40e_pf,
  6302. service_task);
  6303. unsigned long start_time = jiffies;
  6304. /* don't bother with service tasks if a reset is in progress */
  6305. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6306. i40e_service_event_complete(pf);
  6307. return;
  6308. }
  6309. i40e_detect_recover_hung(pf);
  6310. i40e_sync_filters_subtask(pf);
  6311. i40e_reset_subtask(pf);
  6312. i40e_handle_mdd_event(pf);
  6313. i40e_vc_process_vflr_event(pf);
  6314. i40e_watchdog_subtask(pf);
  6315. i40e_fdir_reinit_subtask(pf);
  6316. i40e_client_subtask(pf);
  6317. i40e_sync_filters_subtask(pf);
  6318. i40e_sync_udp_filters_subtask(pf);
  6319. i40e_clean_adminq_subtask(pf);
  6320. i40e_service_event_complete(pf);
  6321. /* If the tasks have taken longer than one timer cycle or there
  6322. * is more work to be done, reschedule the service task now
  6323. * rather than wait for the timer to tick again.
  6324. */
  6325. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  6326. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  6327. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  6328. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  6329. i40e_service_event_schedule(pf);
  6330. }
  6331. /**
  6332. * i40e_service_timer - timer callback
  6333. * @data: pointer to PF struct
  6334. **/
  6335. static void i40e_service_timer(unsigned long data)
  6336. {
  6337. struct i40e_pf *pf = (struct i40e_pf *)data;
  6338. mod_timer(&pf->service_timer,
  6339. round_jiffies(jiffies + pf->service_timer_period));
  6340. i40e_service_event_schedule(pf);
  6341. }
  6342. /**
  6343. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  6344. * @vsi: the VSI being configured
  6345. **/
  6346. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  6347. {
  6348. struct i40e_pf *pf = vsi->back;
  6349. switch (vsi->type) {
  6350. case I40E_VSI_MAIN:
  6351. vsi->alloc_queue_pairs = pf->num_lan_qps;
  6352. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6353. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6354. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6355. vsi->num_q_vectors = pf->num_lan_msix;
  6356. else
  6357. vsi->num_q_vectors = 1;
  6358. break;
  6359. case I40E_VSI_FDIR:
  6360. vsi->alloc_queue_pairs = 1;
  6361. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  6362. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6363. vsi->num_q_vectors = pf->num_fdsb_msix;
  6364. break;
  6365. case I40E_VSI_VMDQ2:
  6366. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  6367. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6368. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6369. vsi->num_q_vectors = pf->num_vmdq_msix;
  6370. break;
  6371. case I40E_VSI_SRIOV:
  6372. vsi->alloc_queue_pairs = pf->num_vf_qps;
  6373. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6374. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6375. break;
  6376. #ifdef I40E_FCOE
  6377. case I40E_VSI_FCOE:
  6378. vsi->alloc_queue_pairs = pf->num_fcoe_qps;
  6379. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6380. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6381. vsi->num_q_vectors = pf->num_fcoe_msix;
  6382. break;
  6383. #endif /* I40E_FCOE */
  6384. default:
  6385. WARN_ON(1);
  6386. return -ENODATA;
  6387. }
  6388. return 0;
  6389. }
  6390. /**
  6391. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  6392. * @type: VSI pointer
  6393. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  6394. *
  6395. * On error: returns error code (negative)
  6396. * On success: returns 0
  6397. **/
  6398. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  6399. {
  6400. int size;
  6401. int ret = 0;
  6402. /* allocate memory for both Tx and Rx ring pointers */
  6403. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  6404. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  6405. if (!vsi->tx_rings)
  6406. return -ENOMEM;
  6407. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  6408. if (alloc_qvectors) {
  6409. /* allocate memory for q_vector pointers */
  6410. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  6411. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  6412. if (!vsi->q_vectors) {
  6413. ret = -ENOMEM;
  6414. goto err_vectors;
  6415. }
  6416. }
  6417. return ret;
  6418. err_vectors:
  6419. kfree(vsi->tx_rings);
  6420. return ret;
  6421. }
  6422. /**
  6423. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  6424. * @pf: board private structure
  6425. * @type: type of VSI
  6426. *
  6427. * On error: returns error code (negative)
  6428. * On success: returns vsi index in PF (positive)
  6429. **/
  6430. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  6431. {
  6432. int ret = -ENODEV;
  6433. struct i40e_vsi *vsi;
  6434. int vsi_idx;
  6435. int i;
  6436. /* Need to protect the allocation of the VSIs at the PF level */
  6437. mutex_lock(&pf->switch_mutex);
  6438. /* VSI list may be fragmented if VSI creation/destruction has
  6439. * been happening. We can afford to do a quick scan to look
  6440. * for any free VSIs in the list.
  6441. *
  6442. * find next empty vsi slot, looping back around if necessary
  6443. */
  6444. i = pf->next_vsi;
  6445. while (i < pf->num_alloc_vsi && pf->vsi[i])
  6446. i++;
  6447. if (i >= pf->num_alloc_vsi) {
  6448. i = 0;
  6449. while (i < pf->next_vsi && pf->vsi[i])
  6450. i++;
  6451. }
  6452. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  6453. vsi_idx = i; /* Found one! */
  6454. } else {
  6455. ret = -ENODEV;
  6456. goto unlock_pf; /* out of VSI slots! */
  6457. }
  6458. pf->next_vsi = ++i;
  6459. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  6460. if (!vsi) {
  6461. ret = -ENOMEM;
  6462. goto unlock_pf;
  6463. }
  6464. vsi->type = type;
  6465. vsi->back = pf;
  6466. set_bit(__I40E_DOWN, &vsi->state);
  6467. vsi->flags = 0;
  6468. vsi->idx = vsi_idx;
  6469. vsi->int_rate_limit = 0;
  6470. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  6471. pf->rss_table_size : 64;
  6472. vsi->netdev_registered = false;
  6473. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  6474. INIT_LIST_HEAD(&vsi->mac_filter_list);
  6475. vsi->irqs_ready = false;
  6476. ret = i40e_set_num_rings_in_vsi(vsi);
  6477. if (ret)
  6478. goto err_rings;
  6479. ret = i40e_vsi_alloc_arrays(vsi, true);
  6480. if (ret)
  6481. goto err_rings;
  6482. /* Setup default MSIX irq handler for VSI */
  6483. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  6484. /* Initialize VSI lock */
  6485. spin_lock_init(&vsi->mac_filter_list_lock);
  6486. pf->vsi[vsi_idx] = vsi;
  6487. ret = vsi_idx;
  6488. goto unlock_pf;
  6489. err_rings:
  6490. pf->next_vsi = i - 1;
  6491. kfree(vsi);
  6492. unlock_pf:
  6493. mutex_unlock(&pf->switch_mutex);
  6494. return ret;
  6495. }
  6496. /**
  6497. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  6498. * @type: VSI pointer
  6499. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  6500. *
  6501. * On error: returns error code (negative)
  6502. * On success: returns 0
  6503. **/
  6504. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  6505. {
  6506. /* free the ring and vector containers */
  6507. if (free_qvectors) {
  6508. kfree(vsi->q_vectors);
  6509. vsi->q_vectors = NULL;
  6510. }
  6511. kfree(vsi->tx_rings);
  6512. vsi->tx_rings = NULL;
  6513. vsi->rx_rings = NULL;
  6514. }
  6515. /**
  6516. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  6517. * and lookup table
  6518. * @vsi: Pointer to VSI structure
  6519. */
  6520. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  6521. {
  6522. if (!vsi)
  6523. return;
  6524. kfree(vsi->rss_hkey_user);
  6525. vsi->rss_hkey_user = NULL;
  6526. kfree(vsi->rss_lut_user);
  6527. vsi->rss_lut_user = NULL;
  6528. }
  6529. /**
  6530. * i40e_vsi_clear - Deallocate the VSI provided
  6531. * @vsi: the VSI being un-configured
  6532. **/
  6533. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  6534. {
  6535. struct i40e_pf *pf;
  6536. if (!vsi)
  6537. return 0;
  6538. if (!vsi->back)
  6539. goto free_vsi;
  6540. pf = vsi->back;
  6541. mutex_lock(&pf->switch_mutex);
  6542. if (!pf->vsi[vsi->idx]) {
  6543. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  6544. vsi->idx, vsi->idx, vsi, vsi->type);
  6545. goto unlock_vsi;
  6546. }
  6547. if (pf->vsi[vsi->idx] != vsi) {
  6548. dev_err(&pf->pdev->dev,
  6549. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  6550. pf->vsi[vsi->idx]->idx,
  6551. pf->vsi[vsi->idx],
  6552. pf->vsi[vsi->idx]->type,
  6553. vsi->idx, vsi, vsi->type);
  6554. goto unlock_vsi;
  6555. }
  6556. /* updates the PF for this cleared vsi */
  6557. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6558. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  6559. i40e_vsi_free_arrays(vsi, true);
  6560. i40e_clear_rss_config_user(vsi);
  6561. pf->vsi[vsi->idx] = NULL;
  6562. if (vsi->idx < pf->next_vsi)
  6563. pf->next_vsi = vsi->idx;
  6564. unlock_vsi:
  6565. mutex_unlock(&pf->switch_mutex);
  6566. free_vsi:
  6567. kfree(vsi);
  6568. return 0;
  6569. }
  6570. /**
  6571. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  6572. * @vsi: the VSI being cleaned
  6573. **/
  6574. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  6575. {
  6576. int i;
  6577. if (vsi->tx_rings && vsi->tx_rings[0]) {
  6578. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6579. kfree_rcu(vsi->tx_rings[i], rcu);
  6580. vsi->tx_rings[i] = NULL;
  6581. vsi->rx_rings[i] = NULL;
  6582. }
  6583. }
  6584. }
  6585. /**
  6586. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  6587. * @vsi: the VSI being configured
  6588. **/
  6589. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  6590. {
  6591. struct i40e_ring *tx_ring, *rx_ring;
  6592. struct i40e_pf *pf = vsi->back;
  6593. int i;
  6594. /* Set basic values in the rings to be used later during open() */
  6595. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6596. /* allocate space for both Tx and Rx in one shot */
  6597. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  6598. if (!tx_ring)
  6599. goto err_out;
  6600. tx_ring->queue_index = i;
  6601. tx_ring->reg_idx = vsi->base_queue + i;
  6602. tx_ring->ring_active = false;
  6603. tx_ring->vsi = vsi;
  6604. tx_ring->netdev = vsi->netdev;
  6605. tx_ring->dev = &pf->pdev->dev;
  6606. tx_ring->count = vsi->num_desc;
  6607. tx_ring->size = 0;
  6608. tx_ring->dcb_tc = 0;
  6609. if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  6610. tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  6611. tx_ring->tx_itr_setting = pf->tx_itr_default;
  6612. vsi->tx_rings[i] = tx_ring;
  6613. rx_ring = &tx_ring[1];
  6614. rx_ring->queue_index = i;
  6615. rx_ring->reg_idx = vsi->base_queue + i;
  6616. rx_ring->ring_active = false;
  6617. rx_ring->vsi = vsi;
  6618. rx_ring->netdev = vsi->netdev;
  6619. rx_ring->dev = &pf->pdev->dev;
  6620. rx_ring->count = vsi->num_desc;
  6621. rx_ring->size = 0;
  6622. rx_ring->dcb_tc = 0;
  6623. rx_ring->rx_itr_setting = pf->rx_itr_default;
  6624. vsi->rx_rings[i] = rx_ring;
  6625. }
  6626. return 0;
  6627. err_out:
  6628. i40e_vsi_clear_rings(vsi);
  6629. return -ENOMEM;
  6630. }
  6631. /**
  6632. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  6633. * @pf: board private structure
  6634. * @vectors: the number of MSI-X vectors to request
  6635. *
  6636. * Returns the number of vectors reserved, or error
  6637. **/
  6638. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  6639. {
  6640. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  6641. I40E_MIN_MSIX, vectors);
  6642. if (vectors < 0) {
  6643. dev_info(&pf->pdev->dev,
  6644. "MSI-X vector reservation failed: %d\n", vectors);
  6645. vectors = 0;
  6646. }
  6647. return vectors;
  6648. }
  6649. /**
  6650. * i40e_init_msix - Setup the MSIX capability
  6651. * @pf: board private structure
  6652. *
  6653. * Work with the OS to set up the MSIX vectors needed.
  6654. *
  6655. * Returns the number of vectors reserved or negative on failure
  6656. **/
  6657. static int i40e_init_msix(struct i40e_pf *pf)
  6658. {
  6659. struct i40e_hw *hw = &pf->hw;
  6660. int vectors_left;
  6661. int v_budget, i;
  6662. int v_actual;
  6663. int iwarp_requested = 0;
  6664. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  6665. return -ENODEV;
  6666. /* The number of vectors we'll request will be comprised of:
  6667. * - Add 1 for "other" cause for Admin Queue events, etc.
  6668. * - The number of LAN queue pairs
  6669. * - Queues being used for RSS.
  6670. * We don't need as many as max_rss_size vectors.
  6671. * use rss_size instead in the calculation since that
  6672. * is governed by number of cpus in the system.
  6673. * - assumes symmetric Tx/Rx pairing
  6674. * - The number of VMDq pairs
  6675. * - The CPU count within the NUMA node if iWARP is enabled
  6676. #ifdef I40E_FCOE
  6677. * - The number of FCOE qps.
  6678. #endif
  6679. * Once we count this up, try the request.
  6680. *
  6681. * If we can't get what we want, we'll simplify to nearly nothing
  6682. * and try again. If that still fails, we punt.
  6683. */
  6684. vectors_left = hw->func_caps.num_msix_vectors;
  6685. v_budget = 0;
  6686. /* reserve one vector for miscellaneous handler */
  6687. if (vectors_left) {
  6688. v_budget++;
  6689. vectors_left--;
  6690. }
  6691. /* reserve vectors for the main PF traffic queues */
  6692. pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
  6693. vectors_left -= pf->num_lan_msix;
  6694. v_budget += pf->num_lan_msix;
  6695. /* reserve one vector for sideband flow director */
  6696. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6697. if (vectors_left) {
  6698. pf->num_fdsb_msix = 1;
  6699. v_budget++;
  6700. vectors_left--;
  6701. } else {
  6702. pf->num_fdsb_msix = 0;
  6703. }
  6704. }
  6705. #ifdef I40E_FCOE
  6706. /* can we reserve enough for FCoE? */
  6707. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6708. if (!vectors_left)
  6709. pf->num_fcoe_msix = 0;
  6710. else if (vectors_left >= pf->num_fcoe_qps)
  6711. pf->num_fcoe_msix = pf->num_fcoe_qps;
  6712. else
  6713. pf->num_fcoe_msix = 1;
  6714. v_budget += pf->num_fcoe_msix;
  6715. vectors_left -= pf->num_fcoe_msix;
  6716. }
  6717. #endif
  6718. /* can we reserve enough for iWARP? */
  6719. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6720. iwarp_requested = pf->num_iwarp_msix;
  6721. if (!vectors_left)
  6722. pf->num_iwarp_msix = 0;
  6723. else if (vectors_left < pf->num_iwarp_msix)
  6724. pf->num_iwarp_msix = 1;
  6725. v_budget += pf->num_iwarp_msix;
  6726. vectors_left -= pf->num_iwarp_msix;
  6727. }
  6728. /* any vectors left over go for VMDq support */
  6729. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  6730. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  6731. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  6732. if (!vectors_left) {
  6733. pf->num_vmdq_msix = 0;
  6734. pf->num_vmdq_qps = 0;
  6735. } else {
  6736. /* if we're short on vectors for what's desired, we limit
  6737. * the queues per vmdq. If this is still more than are
  6738. * available, the user will need to change the number of
  6739. * queues/vectors used by the PF later with the ethtool
  6740. * channels command
  6741. */
  6742. if (vmdq_vecs < vmdq_vecs_wanted)
  6743. pf->num_vmdq_qps = 1;
  6744. pf->num_vmdq_msix = pf->num_vmdq_qps;
  6745. v_budget += vmdq_vecs;
  6746. vectors_left -= vmdq_vecs;
  6747. }
  6748. }
  6749. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  6750. GFP_KERNEL);
  6751. if (!pf->msix_entries)
  6752. return -ENOMEM;
  6753. for (i = 0; i < v_budget; i++)
  6754. pf->msix_entries[i].entry = i;
  6755. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  6756. if (v_actual < I40E_MIN_MSIX) {
  6757. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  6758. kfree(pf->msix_entries);
  6759. pf->msix_entries = NULL;
  6760. pci_disable_msix(pf->pdev);
  6761. return -ENODEV;
  6762. } else if (v_actual == I40E_MIN_MSIX) {
  6763. /* Adjust for minimal MSIX use */
  6764. pf->num_vmdq_vsis = 0;
  6765. pf->num_vmdq_qps = 0;
  6766. pf->num_lan_qps = 1;
  6767. pf->num_lan_msix = 1;
  6768. } else if (!vectors_left) {
  6769. /* If we have limited resources, we will start with no vectors
  6770. * for the special features and then allocate vectors to some
  6771. * of these features based on the policy and at the end disable
  6772. * the features that did not get any vectors.
  6773. */
  6774. int vec;
  6775. dev_info(&pf->pdev->dev,
  6776. "MSI-X vector limit reached, attempting to redistribute vectors\n");
  6777. /* reserve the misc vector */
  6778. vec = v_actual - 1;
  6779. /* Scale vector usage down */
  6780. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  6781. pf->num_vmdq_vsis = 1;
  6782. pf->num_vmdq_qps = 1;
  6783. #ifdef I40E_FCOE
  6784. pf->num_fcoe_qps = 0;
  6785. pf->num_fcoe_msix = 0;
  6786. #endif
  6787. /* partition out the remaining vectors */
  6788. switch (vec) {
  6789. case 2:
  6790. pf->num_lan_msix = 1;
  6791. break;
  6792. case 3:
  6793. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6794. pf->num_lan_msix = 1;
  6795. pf->num_iwarp_msix = 1;
  6796. } else {
  6797. pf->num_lan_msix = 2;
  6798. }
  6799. #ifdef I40E_FCOE
  6800. /* give one vector to FCoE */
  6801. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6802. pf->num_lan_msix = 1;
  6803. pf->num_fcoe_msix = 1;
  6804. }
  6805. #endif
  6806. break;
  6807. default:
  6808. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6809. pf->num_iwarp_msix = min_t(int, (vec / 3),
  6810. iwarp_requested);
  6811. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  6812. I40E_DEFAULT_NUM_VMDQ_VSI);
  6813. } else {
  6814. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  6815. I40E_DEFAULT_NUM_VMDQ_VSI);
  6816. }
  6817. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6818. pf->num_fdsb_msix = 1;
  6819. vec--;
  6820. }
  6821. pf->num_lan_msix = min_t(int,
  6822. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  6823. pf->num_lan_msix);
  6824. pf->num_lan_qps = pf->num_lan_msix;
  6825. #ifdef I40E_FCOE
  6826. /* give one vector to FCoE */
  6827. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6828. pf->num_fcoe_msix = 1;
  6829. vec--;
  6830. }
  6831. #endif
  6832. break;
  6833. }
  6834. }
  6835. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  6836. (pf->num_fdsb_msix == 0)) {
  6837. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  6838. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6839. }
  6840. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  6841. (pf->num_vmdq_msix == 0)) {
  6842. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  6843. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  6844. }
  6845. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  6846. (pf->num_iwarp_msix == 0)) {
  6847. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  6848. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  6849. }
  6850. #ifdef I40E_FCOE
  6851. if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
  6852. dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
  6853. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  6854. }
  6855. #endif
  6856. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  6857. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  6858. pf->num_lan_msix,
  6859. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  6860. pf->num_fdsb_msix,
  6861. pf->num_iwarp_msix);
  6862. return v_actual;
  6863. }
  6864. /**
  6865. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  6866. * @vsi: the VSI being configured
  6867. * @v_idx: index of the vector in the vsi struct
  6868. * @cpu: cpu to be used on affinity_mask
  6869. *
  6870. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  6871. **/
  6872. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  6873. {
  6874. struct i40e_q_vector *q_vector;
  6875. /* allocate q_vector */
  6876. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  6877. if (!q_vector)
  6878. return -ENOMEM;
  6879. q_vector->vsi = vsi;
  6880. q_vector->v_idx = v_idx;
  6881. cpumask_set_cpu(cpu, &q_vector->affinity_mask);
  6882. if (vsi->netdev)
  6883. netif_napi_add(vsi->netdev, &q_vector->napi,
  6884. i40e_napi_poll, NAPI_POLL_WEIGHT);
  6885. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  6886. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  6887. /* tie q_vector and vsi together */
  6888. vsi->q_vectors[v_idx] = q_vector;
  6889. return 0;
  6890. }
  6891. /**
  6892. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  6893. * @vsi: the VSI being configured
  6894. *
  6895. * We allocate one q_vector per queue interrupt. If allocation fails we
  6896. * return -ENOMEM.
  6897. **/
  6898. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  6899. {
  6900. struct i40e_pf *pf = vsi->back;
  6901. int err, v_idx, num_q_vectors, current_cpu;
  6902. /* if not MSIX, give the one vector only to the LAN VSI */
  6903. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6904. num_q_vectors = vsi->num_q_vectors;
  6905. else if (vsi == pf->vsi[pf->lan_vsi])
  6906. num_q_vectors = 1;
  6907. else
  6908. return -EINVAL;
  6909. current_cpu = cpumask_first(cpu_online_mask);
  6910. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  6911. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  6912. if (err)
  6913. goto err_out;
  6914. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  6915. if (unlikely(current_cpu >= nr_cpu_ids))
  6916. current_cpu = cpumask_first(cpu_online_mask);
  6917. }
  6918. return 0;
  6919. err_out:
  6920. while (v_idx--)
  6921. i40e_free_q_vector(vsi, v_idx);
  6922. return err;
  6923. }
  6924. /**
  6925. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  6926. * @pf: board private structure to initialize
  6927. **/
  6928. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  6929. {
  6930. int vectors = 0;
  6931. ssize_t size;
  6932. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  6933. vectors = i40e_init_msix(pf);
  6934. if (vectors < 0) {
  6935. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  6936. I40E_FLAG_IWARP_ENABLED |
  6937. #ifdef I40E_FCOE
  6938. I40E_FLAG_FCOE_ENABLED |
  6939. #endif
  6940. I40E_FLAG_RSS_ENABLED |
  6941. I40E_FLAG_DCB_CAPABLE |
  6942. I40E_FLAG_DCB_ENABLED |
  6943. I40E_FLAG_SRIOV_ENABLED |
  6944. I40E_FLAG_FD_SB_ENABLED |
  6945. I40E_FLAG_FD_ATR_ENABLED |
  6946. I40E_FLAG_VMDQ_ENABLED);
  6947. /* rework the queue expectations without MSIX */
  6948. i40e_determine_queue_usage(pf);
  6949. }
  6950. }
  6951. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  6952. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  6953. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  6954. vectors = pci_enable_msi(pf->pdev);
  6955. if (vectors < 0) {
  6956. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  6957. vectors);
  6958. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  6959. }
  6960. vectors = 1; /* one MSI or Legacy vector */
  6961. }
  6962. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  6963. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  6964. /* set up vector assignment tracking */
  6965. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  6966. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  6967. if (!pf->irq_pile) {
  6968. dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
  6969. return -ENOMEM;
  6970. }
  6971. pf->irq_pile->num_entries = vectors;
  6972. pf->irq_pile->search_hint = 0;
  6973. /* track first vector for misc interrupts, ignore return */
  6974. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  6975. return 0;
  6976. }
  6977. /**
  6978. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  6979. * @pf: board private structure
  6980. *
  6981. * This sets up the handler for MSIX 0, which is used to manage the
  6982. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  6983. * when in MSI or Legacy interrupt mode.
  6984. **/
  6985. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  6986. {
  6987. struct i40e_hw *hw = &pf->hw;
  6988. int err = 0;
  6989. /* Only request the irq if this is the first time through, and
  6990. * not when we're rebuilding after a Reset
  6991. */
  6992. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6993. err = request_irq(pf->msix_entries[0].vector,
  6994. i40e_intr, 0, pf->int_name, pf);
  6995. if (err) {
  6996. dev_info(&pf->pdev->dev,
  6997. "request_irq for %s failed: %d\n",
  6998. pf->int_name, err);
  6999. return -EFAULT;
  7000. }
  7001. }
  7002. i40e_enable_misc_int_causes(pf);
  7003. /* associate no queues to the misc vector */
  7004. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  7005. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  7006. i40e_flush(hw);
  7007. i40e_irq_dynamic_enable_icr0(pf, true);
  7008. return err;
  7009. }
  7010. /**
  7011. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  7012. * @vsi: vsi structure
  7013. * @seed: RSS hash seed
  7014. **/
  7015. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7016. u8 *lut, u16 lut_size)
  7017. {
  7018. struct i40e_pf *pf = vsi->back;
  7019. struct i40e_hw *hw = &pf->hw;
  7020. int ret = 0;
  7021. if (seed) {
  7022. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  7023. (struct i40e_aqc_get_set_rss_key_data *)seed;
  7024. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  7025. if (ret) {
  7026. dev_info(&pf->pdev->dev,
  7027. "Cannot set RSS key, err %s aq_err %s\n",
  7028. i40e_stat_str(hw, ret),
  7029. i40e_aq_str(hw, hw->aq.asq_last_status));
  7030. return ret;
  7031. }
  7032. }
  7033. if (lut) {
  7034. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7035. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7036. if (ret) {
  7037. dev_info(&pf->pdev->dev,
  7038. "Cannot set RSS lut, err %s aq_err %s\n",
  7039. i40e_stat_str(hw, ret),
  7040. i40e_aq_str(hw, hw->aq.asq_last_status));
  7041. return ret;
  7042. }
  7043. }
  7044. return ret;
  7045. }
  7046. /**
  7047. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  7048. * @vsi: Pointer to vsi structure
  7049. * @seed: Buffter to store the hash keys
  7050. * @lut: Buffer to store the lookup table entries
  7051. * @lut_size: Size of buffer to store the lookup table entries
  7052. *
  7053. * Return 0 on success, negative on failure
  7054. */
  7055. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7056. u8 *lut, u16 lut_size)
  7057. {
  7058. struct i40e_pf *pf = vsi->back;
  7059. struct i40e_hw *hw = &pf->hw;
  7060. int ret = 0;
  7061. if (seed) {
  7062. ret = i40e_aq_get_rss_key(hw, vsi->id,
  7063. (struct i40e_aqc_get_set_rss_key_data *)seed);
  7064. if (ret) {
  7065. dev_info(&pf->pdev->dev,
  7066. "Cannot get RSS key, err %s aq_err %s\n",
  7067. i40e_stat_str(&pf->hw, ret),
  7068. i40e_aq_str(&pf->hw,
  7069. pf->hw.aq.asq_last_status));
  7070. return ret;
  7071. }
  7072. }
  7073. if (lut) {
  7074. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7075. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7076. if (ret) {
  7077. dev_info(&pf->pdev->dev,
  7078. "Cannot get RSS lut, err %s aq_err %s\n",
  7079. i40e_stat_str(&pf->hw, ret),
  7080. i40e_aq_str(&pf->hw,
  7081. pf->hw.aq.asq_last_status));
  7082. return ret;
  7083. }
  7084. }
  7085. return ret;
  7086. }
  7087. /**
  7088. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  7089. * @vsi: VSI structure
  7090. **/
  7091. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  7092. {
  7093. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7094. struct i40e_pf *pf = vsi->back;
  7095. u8 *lut;
  7096. int ret;
  7097. if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
  7098. return 0;
  7099. if (!vsi->rss_size)
  7100. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7101. vsi->num_queue_pairs);
  7102. if (!vsi->rss_size)
  7103. return -EINVAL;
  7104. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7105. if (!lut)
  7106. return -ENOMEM;
  7107. /* Use the user configured hash keys and lookup table if there is one,
  7108. * otherwise use default
  7109. */
  7110. if (vsi->rss_lut_user)
  7111. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7112. else
  7113. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7114. if (vsi->rss_hkey_user)
  7115. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7116. else
  7117. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7118. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  7119. kfree(lut);
  7120. return ret;
  7121. }
  7122. /**
  7123. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  7124. * @vsi: Pointer to vsi structure
  7125. * @seed: RSS hash seed
  7126. * @lut: Lookup table
  7127. * @lut_size: Lookup table size
  7128. *
  7129. * Returns 0 on success, negative on failure
  7130. **/
  7131. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  7132. const u8 *lut, u16 lut_size)
  7133. {
  7134. struct i40e_pf *pf = vsi->back;
  7135. struct i40e_hw *hw = &pf->hw;
  7136. u16 vf_id = vsi->vf_id;
  7137. u8 i;
  7138. /* Fill out hash function seed */
  7139. if (seed) {
  7140. u32 *seed_dw = (u32 *)seed;
  7141. if (vsi->type == I40E_VSI_MAIN) {
  7142. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7143. i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i),
  7144. seed_dw[i]);
  7145. } else if (vsi->type == I40E_VSI_SRIOV) {
  7146. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  7147. i40e_write_rx_ctl(hw,
  7148. I40E_VFQF_HKEY1(i, vf_id),
  7149. seed_dw[i]);
  7150. } else {
  7151. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  7152. }
  7153. }
  7154. if (lut) {
  7155. u32 *lut_dw = (u32 *)lut;
  7156. if (vsi->type == I40E_VSI_MAIN) {
  7157. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7158. return -EINVAL;
  7159. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7160. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  7161. } else if (vsi->type == I40E_VSI_SRIOV) {
  7162. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  7163. return -EINVAL;
  7164. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7165. i40e_write_rx_ctl(hw,
  7166. I40E_VFQF_HLUT1(i, vf_id),
  7167. lut_dw[i]);
  7168. } else {
  7169. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7170. }
  7171. }
  7172. i40e_flush(hw);
  7173. return 0;
  7174. }
  7175. /**
  7176. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  7177. * @vsi: Pointer to VSI structure
  7178. * @seed: Buffer to store the keys
  7179. * @lut: Buffer to store the lookup table entries
  7180. * @lut_size: Size of buffer to store the lookup table entries
  7181. *
  7182. * Returns 0 on success, negative on failure
  7183. */
  7184. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  7185. u8 *lut, u16 lut_size)
  7186. {
  7187. struct i40e_pf *pf = vsi->back;
  7188. struct i40e_hw *hw = &pf->hw;
  7189. u16 i;
  7190. if (seed) {
  7191. u32 *seed_dw = (u32 *)seed;
  7192. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7193. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  7194. }
  7195. if (lut) {
  7196. u32 *lut_dw = (u32 *)lut;
  7197. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7198. return -EINVAL;
  7199. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7200. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  7201. }
  7202. return 0;
  7203. }
  7204. /**
  7205. * i40e_config_rss - Configure RSS keys and lut
  7206. * @vsi: Pointer to VSI structure
  7207. * @seed: RSS hash seed
  7208. * @lut: Lookup table
  7209. * @lut_size: Lookup table size
  7210. *
  7211. * Returns 0 on success, negative on failure
  7212. */
  7213. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7214. {
  7215. struct i40e_pf *pf = vsi->back;
  7216. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7217. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  7218. else
  7219. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  7220. }
  7221. /**
  7222. * i40e_get_rss - Get RSS keys and lut
  7223. * @vsi: Pointer to VSI structure
  7224. * @seed: Buffer to store the keys
  7225. * @lut: Buffer to store the lookup table entries
  7226. * lut_size: Size of buffer to store the lookup table entries
  7227. *
  7228. * Returns 0 on success, negative on failure
  7229. */
  7230. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7231. {
  7232. struct i40e_pf *pf = vsi->back;
  7233. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7234. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  7235. else
  7236. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  7237. }
  7238. /**
  7239. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  7240. * @pf: Pointer to board private structure
  7241. * @lut: Lookup table
  7242. * @rss_table_size: Lookup table size
  7243. * @rss_size: Range of queue number for hashing
  7244. */
  7245. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  7246. u16 rss_table_size, u16 rss_size)
  7247. {
  7248. u16 i;
  7249. for (i = 0; i < rss_table_size; i++)
  7250. lut[i] = i % rss_size;
  7251. }
  7252. /**
  7253. * i40e_pf_config_rss - Prepare for RSS if used
  7254. * @pf: board private structure
  7255. **/
  7256. static int i40e_pf_config_rss(struct i40e_pf *pf)
  7257. {
  7258. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7259. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7260. u8 *lut;
  7261. struct i40e_hw *hw = &pf->hw;
  7262. u32 reg_val;
  7263. u64 hena;
  7264. int ret;
  7265. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  7266. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  7267. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  7268. hena |= i40e_pf_get_default_rss_hena(pf);
  7269. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  7270. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  7271. /* Determine the RSS table size based on the hardware capabilities */
  7272. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  7273. reg_val = (pf->rss_table_size == 512) ?
  7274. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  7275. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  7276. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  7277. /* Determine the RSS size of the VSI */
  7278. if (!vsi->rss_size)
  7279. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7280. vsi->num_queue_pairs);
  7281. if (!vsi->rss_size)
  7282. return -EINVAL;
  7283. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7284. if (!lut)
  7285. return -ENOMEM;
  7286. /* Use user configured lut if there is one, otherwise use default */
  7287. if (vsi->rss_lut_user)
  7288. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7289. else
  7290. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7291. /* Use user configured hash key if there is one, otherwise
  7292. * use default.
  7293. */
  7294. if (vsi->rss_hkey_user)
  7295. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7296. else
  7297. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7298. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  7299. kfree(lut);
  7300. return ret;
  7301. }
  7302. /**
  7303. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  7304. * @pf: board private structure
  7305. * @queue_count: the requested queue count for rss.
  7306. *
  7307. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  7308. * count which may be different from the requested queue count.
  7309. **/
  7310. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  7311. {
  7312. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7313. int new_rss_size;
  7314. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  7315. return 0;
  7316. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  7317. if (queue_count != vsi->num_queue_pairs) {
  7318. vsi->req_queue_pairs = queue_count;
  7319. i40e_prep_for_reset(pf);
  7320. pf->alloc_rss_size = new_rss_size;
  7321. i40e_reset_and_rebuild(pf, true);
  7322. /* Discard the user configured hash keys and lut, if less
  7323. * queues are enabled.
  7324. */
  7325. if (queue_count < vsi->rss_size) {
  7326. i40e_clear_rss_config_user(vsi);
  7327. dev_dbg(&pf->pdev->dev,
  7328. "discard user configured hash keys and lut\n");
  7329. }
  7330. /* Reset vsi->rss_size, as number of enabled queues changed */
  7331. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7332. vsi->num_queue_pairs);
  7333. i40e_pf_config_rss(pf);
  7334. }
  7335. dev_info(&pf->pdev->dev, "RSS count/HW max RSS count: %d/%d\n",
  7336. pf->alloc_rss_size, pf->rss_size_max);
  7337. return pf->alloc_rss_size;
  7338. }
  7339. /**
  7340. * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
  7341. * @pf: board private structure
  7342. **/
  7343. i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
  7344. {
  7345. i40e_status status;
  7346. bool min_valid, max_valid;
  7347. u32 max_bw, min_bw;
  7348. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  7349. &min_valid, &max_valid);
  7350. if (!status) {
  7351. if (min_valid)
  7352. pf->npar_min_bw = min_bw;
  7353. if (max_valid)
  7354. pf->npar_max_bw = max_bw;
  7355. }
  7356. return status;
  7357. }
  7358. /**
  7359. * i40e_set_npar_bw_setting - Set BW settings for this PF partition
  7360. * @pf: board private structure
  7361. **/
  7362. i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
  7363. {
  7364. struct i40e_aqc_configure_partition_bw_data bw_data;
  7365. i40e_status status;
  7366. /* Set the valid bit for this PF */
  7367. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  7368. bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
  7369. bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
  7370. /* Set the new bandwidths */
  7371. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  7372. return status;
  7373. }
  7374. /**
  7375. * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
  7376. * @pf: board private structure
  7377. **/
  7378. i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
  7379. {
  7380. /* Commit temporary BW setting to permanent NVM image */
  7381. enum i40e_admin_queue_err last_aq_status;
  7382. i40e_status ret;
  7383. u16 nvm_word;
  7384. if (pf->hw.partition_id != 1) {
  7385. dev_info(&pf->pdev->dev,
  7386. "Commit BW only works on partition 1! This is partition %d",
  7387. pf->hw.partition_id);
  7388. ret = I40E_NOT_SUPPORTED;
  7389. goto bw_commit_out;
  7390. }
  7391. /* Acquire NVM for read access */
  7392. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  7393. last_aq_status = pf->hw.aq.asq_last_status;
  7394. if (ret) {
  7395. dev_info(&pf->pdev->dev,
  7396. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  7397. i40e_stat_str(&pf->hw, ret),
  7398. i40e_aq_str(&pf->hw, last_aq_status));
  7399. goto bw_commit_out;
  7400. }
  7401. /* Read word 0x10 of NVM - SW compatibility word 1 */
  7402. ret = i40e_aq_read_nvm(&pf->hw,
  7403. I40E_SR_NVM_CONTROL_WORD,
  7404. 0x10, sizeof(nvm_word), &nvm_word,
  7405. false, NULL);
  7406. /* Save off last admin queue command status before releasing
  7407. * the NVM
  7408. */
  7409. last_aq_status = pf->hw.aq.asq_last_status;
  7410. i40e_release_nvm(&pf->hw);
  7411. if (ret) {
  7412. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  7413. i40e_stat_str(&pf->hw, ret),
  7414. i40e_aq_str(&pf->hw, last_aq_status));
  7415. goto bw_commit_out;
  7416. }
  7417. /* Wait a bit for NVM release to complete */
  7418. msleep(50);
  7419. /* Acquire NVM for write access */
  7420. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  7421. last_aq_status = pf->hw.aq.asq_last_status;
  7422. if (ret) {
  7423. dev_info(&pf->pdev->dev,
  7424. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  7425. i40e_stat_str(&pf->hw, ret),
  7426. i40e_aq_str(&pf->hw, last_aq_status));
  7427. goto bw_commit_out;
  7428. }
  7429. /* Write it back out unchanged to initiate update NVM,
  7430. * which will force a write of the shadow (alt) RAM to
  7431. * the NVM - thus storing the bandwidth values permanently.
  7432. */
  7433. ret = i40e_aq_update_nvm(&pf->hw,
  7434. I40E_SR_NVM_CONTROL_WORD,
  7435. 0x10, sizeof(nvm_word),
  7436. &nvm_word, true, NULL);
  7437. /* Save off last admin queue command status before releasing
  7438. * the NVM
  7439. */
  7440. last_aq_status = pf->hw.aq.asq_last_status;
  7441. i40e_release_nvm(&pf->hw);
  7442. if (ret)
  7443. dev_info(&pf->pdev->dev,
  7444. "BW settings NOT SAVED, err %s aq_err %s\n",
  7445. i40e_stat_str(&pf->hw, ret),
  7446. i40e_aq_str(&pf->hw, last_aq_status));
  7447. bw_commit_out:
  7448. return ret;
  7449. }
  7450. /**
  7451. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  7452. * @pf: board private structure to initialize
  7453. *
  7454. * i40e_sw_init initializes the Adapter private data structure.
  7455. * Fields are initialized based on PCI device information and
  7456. * OS network device settings (MTU size).
  7457. **/
  7458. static int i40e_sw_init(struct i40e_pf *pf)
  7459. {
  7460. int err = 0;
  7461. int size;
  7462. pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
  7463. (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
  7464. if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
  7465. if (I40E_DEBUG_USER & debug)
  7466. pf->hw.debug_mask = debug;
  7467. pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
  7468. I40E_DEFAULT_MSG_ENABLE);
  7469. }
  7470. /* Set default capability flags */
  7471. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  7472. I40E_FLAG_MSI_ENABLED |
  7473. I40E_FLAG_MSIX_ENABLED;
  7474. /* Set default ITR */
  7475. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  7476. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  7477. /* Depending on PF configurations, it is possible that the RSS
  7478. * maximum might end up larger than the available queues
  7479. */
  7480. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  7481. pf->alloc_rss_size = 1;
  7482. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  7483. pf->rss_size_max = min_t(int, pf->rss_size_max,
  7484. pf->hw.func_caps.num_tx_qp);
  7485. if (pf->hw.func_caps.rss) {
  7486. pf->flags |= I40E_FLAG_RSS_ENABLED;
  7487. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  7488. num_online_cpus());
  7489. }
  7490. /* MFP mode enabled */
  7491. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  7492. pf->flags |= I40E_FLAG_MFP_ENABLED;
  7493. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  7494. if (i40e_get_npar_bw_setting(pf))
  7495. dev_warn(&pf->pdev->dev,
  7496. "Could not get NPAR bw settings\n");
  7497. else
  7498. dev_info(&pf->pdev->dev,
  7499. "Min BW = %8.8x, Max BW = %8.8x\n",
  7500. pf->npar_min_bw, pf->npar_max_bw);
  7501. }
  7502. /* FW/NVM is not yet fixed in this regard */
  7503. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  7504. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  7505. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  7506. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  7507. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  7508. pf->hw.num_partitions > 1)
  7509. dev_info(&pf->pdev->dev,
  7510. "Flow Director Sideband mode Disabled in MFP mode\n");
  7511. else
  7512. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7513. pf->fdir_pf_filter_count =
  7514. pf->hw.func_caps.fd_filters_guaranteed;
  7515. pf->hw.fdir_shared_filter_count =
  7516. pf->hw.func_caps.fd_filters_best_effort;
  7517. }
  7518. if (i40e_is_mac_710(&pf->hw) &&
  7519. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  7520. (pf->hw.aq.fw_maj_ver < 4))) {
  7521. pf->flags |= I40E_FLAG_RESTART_AUTONEG;
  7522. /* No DCB support for FW < v4.33 */
  7523. pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
  7524. }
  7525. /* Disable FW LLDP if FW < v4.3 */
  7526. if (i40e_is_mac_710(&pf->hw) &&
  7527. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  7528. (pf->hw.aq.fw_maj_ver < 4)))
  7529. pf->flags |= I40E_FLAG_STOP_FW_LLDP;
  7530. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  7531. if (i40e_is_mac_710(&pf->hw) &&
  7532. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  7533. (pf->hw.aq.fw_maj_ver >= 5)))
  7534. pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
  7535. if (pf->hw.func_caps.vmdq) {
  7536. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  7537. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  7538. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  7539. }
  7540. if (pf->hw.func_caps.iwarp) {
  7541. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  7542. /* IWARP needs one extra vector for CQP just like MISC.*/
  7543. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  7544. }
  7545. #ifdef I40E_FCOE
  7546. i40e_init_pf_fcoe(pf);
  7547. #endif /* I40E_FCOE */
  7548. #ifdef CONFIG_PCI_IOV
  7549. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  7550. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  7551. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  7552. pf->num_req_vfs = min_t(int,
  7553. pf->hw.func_caps.num_vfs,
  7554. I40E_MAX_VF_COUNT);
  7555. }
  7556. #endif /* CONFIG_PCI_IOV */
  7557. if (pf->hw.mac.type == I40E_MAC_X722) {
  7558. pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
  7559. I40E_FLAG_128_QP_RSS_CAPABLE |
  7560. I40E_FLAG_HW_ATR_EVICT_CAPABLE |
  7561. I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
  7562. I40E_FLAG_WB_ON_ITR_CAPABLE |
  7563. I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  7564. I40E_FLAG_NO_PCI_LINK_CHECK |
  7565. I40E_FLAG_USE_SET_LLDP_MIB |
  7566. I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7567. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  7568. ((pf->hw.aq.api_maj_ver == 1) &&
  7569. (pf->hw.aq.api_min_ver > 4))) {
  7570. /* Supported in FW API version higher than 1.4 */
  7571. pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7572. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7573. } else {
  7574. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7575. }
  7576. pf->eeprom_version = 0xDEAD;
  7577. pf->lan_veb = I40E_NO_VEB;
  7578. pf->lan_vsi = I40E_NO_VSI;
  7579. /* By default FW has this off for performance reasons */
  7580. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  7581. /* set up queue assignment tracking */
  7582. size = sizeof(struct i40e_lump_tracking)
  7583. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  7584. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  7585. if (!pf->qp_pile) {
  7586. err = -ENOMEM;
  7587. goto sw_init_done;
  7588. }
  7589. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  7590. pf->qp_pile->search_hint = 0;
  7591. pf->tx_timeout_recovery_level = 1;
  7592. mutex_init(&pf->switch_mutex);
  7593. /* If NPAR is enabled nudge the Tx scheduler */
  7594. if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
  7595. i40e_set_npar_bw_setting(pf);
  7596. sw_init_done:
  7597. return err;
  7598. }
  7599. /**
  7600. * i40e_set_ntuple - set the ntuple feature flag and take action
  7601. * @pf: board private structure to initialize
  7602. * @features: the feature set that the stack is suggesting
  7603. *
  7604. * returns a bool to indicate if reset needs to happen
  7605. **/
  7606. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  7607. {
  7608. bool need_reset = false;
  7609. /* Check if Flow Director n-tuple support was enabled or disabled. If
  7610. * the state changed, we need to reset.
  7611. */
  7612. if (features & NETIF_F_NTUPLE) {
  7613. /* Enable filters and mark for reset */
  7614. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7615. need_reset = true;
  7616. /* enable FD_SB only if there is MSI-X vector */
  7617. if (pf->num_fdsb_msix > 0)
  7618. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7619. } else {
  7620. /* turn off filters, mark for reset and clear SW filter list */
  7621. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7622. need_reset = true;
  7623. i40e_fdir_filter_exit(pf);
  7624. }
  7625. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7626. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7627. /* reset fd counters */
  7628. pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
  7629. pf->fdir_pf_active_filters = 0;
  7630. /* if ATR was auto disabled it can be re-enabled. */
  7631. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7632. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  7633. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  7634. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7635. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  7636. }
  7637. }
  7638. return need_reset;
  7639. }
  7640. /**
  7641. * i40e_clear_rss_lut - clear the rx hash lookup table
  7642. * @vsi: the VSI being configured
  7643. **/
  7644. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  7645. {
  7646. struct i40e_pf *pf = vsi->back;
  7647. struct i40e_hw *hw = &pf->hw;
  7648. u16 vf_id = vsi->vf_id;
  7649. u8 i;
  7650. if (vsi->type == I40E_VSI_MAIN) {
  7651. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7652. wr32(hw, I40E_PFQF_HLUT(i), 0);
  7653. } else if (vsi->type == I40E_VSI_SRIOV) {
  7654. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7655. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  7656. } else {
  7657. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7658. }
  7659. }
  7660. /**
  7661. * i40e_set_features - set the netdev feature flags
  7662. * @netdev: ptr to the netdev being adjusted
  7663. * @features: the feature set that the stack is suggesting
  7664. **/
  7665. static int i40e_set_features(struct net_device *netdev,
  7666. netdev_features_t features)
  7667. {
  7668. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7669. struct i40e_vsi *vsi = np->vsi;
  7670. struct i40e_pf *pf = vsi->back;
  7671. bool need_reset;
  7672. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  7673. i40e_pf_config_rss(pf);
  7674. else if (!(features & NETIF_F_RXHASH) &&
  7675. netdev->features & NETIF_F_RXHASH)
  7676. i40e_clear_rss_lut(vsi);
  7677. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  7678. i40e_vlan_stripping_enable(vsi);
  7679. else
  7680. i40e_vlan_stripping_disable(vsi);
  7681. need_reset = i40e_set_ntuple(pf, features);
  7682. if (need_reset)
  7683. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7684. return 0;
  7685. }
  7686. /**
  7687. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  7688. * @pf: board private structure
  7689. * @port: The UDP port to look up
  7690. *
  7691. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  7692. **/
  7693. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
  7694. {
  7695. u8 i;
  7696. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  7697. if (pf->udp_ports[i].index == port)
  7698. return i;
  7699. }
  7700. return i;
  7701. }
  7702. /**
  7703. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  7704. * @netdev: This physical port's netdev
  7705. * @ti: Tunnel endpoint information
  7706. **/
  7707. static void i40e_udp_tunnel_add(struct net_device *netdev,
  7708. struct udp_tunnel_info *ti)
  7709. {
  7710. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7711. struct i40e_vsi *vsi = np->vsi;
  7712. struct i40e_pf *pf = vsi->back;
  7713. __be16 port = ti->port;
  7714. u8 next_idx;
  7715. u8 idx;
  7716. idx = i40e_get_udp_port_idx(pf, port);
  7717. /* Check if port already exists */
  7718. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7719. netdev_info(netdev, "port %d already offloaded\n",
  7720. ntohs(port));
  7721. return;
  7722. }
  7723. /* Now check if there is space to add the new port */
  7724. next_idx = i40e_get_udp_port_idx(pf, 0);
  7725. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7726. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  7727. ntohs(port));
  7728. return;
  7729. }
  7730. switch (ti->type) {
  7731. case UDP_TUNNEL_TYPE_VXLAN:
  7732. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  7733. break;
  7734. case UDP_TUNNEL_TYPE_GENEVE:
  7735. if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7736. return;
  7737. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  7738. break;
  7739. default:
  7740. return;
  7741. }
  7742. /* New port: add it and mark its index in the bitmap */
  7743. pf->udp_ports[next_idx].index = port;
  7744. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  7745. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7746. }
  7747. /**
  7748. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  7749. * @netdev: This physical port's netdev
  7750. * @ti: Tunnel endpoint information
  7751. **/
  7752. static void i40e_udp_tunnel_del(struct net_device *netdev,
  7753. struct udp_tunnel_info *ti)
  7754. {
  7755. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7756. struct i40e_vsi *vsi = np->vsi;
  7757. struct i40e_pf *pf = vsi->back;
  7758. __be16 port = ti->port;
  7759. u8 idx;
  7760. idx = i40e_get_udp_port_idx(pf, port);
  7761. /* Check if port already exists */
  7762. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  7763. goto not_found;
  7764. switch (ti->type) {
  7765. case UDP_TUNNEL_TYPE_VXLAN:
  7766. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  7767. goto not_found;
  7768. break;
  7769. case UDP_TUNNEL_TYPE_GENEVE:
  7770. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  7771. goto not_found;
  7772. break;
  7773. default:
  7774. goto not_found;
  7775. }
  7776. /* if port exists, set it to 0 (mark for deletion)
  7777. * and make it pending
  7778. */
  7779. pf->udp_ports[idx].index = 0;
  7780. pf->pending_udp_bitmap |= BIT_ULL(idx);
  7781. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7782. return;
  7783. not_found:
  7784. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  7785. ntohs(port));
  7786. }
  7787. static int i40e_get_phys_port_id(struct net_device *netdev,
  7788. struct netdev_phys_item_id *ppid)
  7789. {
  7790. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7791. struct i40e_pf *pf = np->vsi->back;
  7792. struct i40e_hw *hw = &pf->hw;
  7793. if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
  7794. return -EOPNOTSUPP;
  7795. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  7796. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  7797. return 0;
  7798. }
  7799. /**
  7800. * i40e_ndo_fdb_add - add an entry to the hardware database
  7801. * @ndm: the input from the stack
  7802. * @tb: pointer to array of nladdr (unused)
  7803. * @dev: the net device pointer
  7804. * @addr: the MAC address entry being added
  7805. * @flags: instructions from stack about fdb operation
  7806. */
  7807. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  7808. struct net_device *dev,
  7809. const unsigned char *addr, u16 vid,
  7810. u16 flags)
  7811. {
  7812. struct i40e_netdev_priv *np = netdev_priv(dev);
  7813. struct i40e_pf *pf = np->vsi->back;
  7814. int err = 0;
  7815. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  7816. return -EOPNOTSUPP;
  7817. if (vid) {
  7818. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  7819. return -EINVAL;
  7820. }
  7821. /* Hardware does not support aging addresses so if a
  7822. * ndm_state is given only allow permanent addresses
  7823. */
  7824. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  7825. netdev_info(dev, "FDB only supports static addresses\n");
  7826. return -EINVAL;
  7827. }
  7828. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  7829. err = dev_uc_add_excl(dev, addr);
  7830. else if (is_multicast_ether_addr(addr))
  7831. err = dev_mc_add_excl(dev, addr);
  7832. else
  7833. err = -EINVAL;
  7834. /* Only return duplicate errors if NLM_F_EXCL is set */
  7835. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  7836. err = 0;
  7837. return err;
  7838. }
  7839. /**
  7840. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  7841. * @dev: the netdev being configured
  7842. * @nlh: RTNL message
  7843. *
  7844. * Inserts a new hardware bridge if not already created and
  7845. * enables the bridging mode requested (VEB or VEPA). If the
  7846. * hardware bridge has already been inserted and the request
  7847. * is to change the mode then that requires a PF reset to
  7848. * allow rebuild of the components with required hardware
  7849. * bridge mode enabled.
  7850. **/
  7851. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  7852. struct nlmsghdr *nlh,
  7853. u16 flags)
  7854. {
  7855. struct i40e_netdev_priv *np = netdev_priv(dev);
  7856. struct i40e_vsi *vsi = np->vsi;
  7857. struct i40e_pf *pf = vsi->back;
  7858. struct i40e_veb *veb = NULL;
  7859. struct nlattr *attr, *br_spec;
  7860. int i, rem;
  7861. /* Only for PF VSI for now */
  7862. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  7863. return -EOPNOTSUPP;
  7864. /* Find the HW bridge for PF VSI */
  7865. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7866. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7867. veb = pf->veb[i];
  7868. }
  7869. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  7870. nla_for_each_nested(attr, br_spec, rem) {
  7871. __u16 mode;
  7872. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  7873. continue;
  7874. mode = nla_get_u16(attr);
  7875. if ((mode != BRIDGE_MODE_VEPA) &&
  7876. (mode != BRIDGE_MODE_VEB))
  7877. return -EINVAL;
  7878. /* Insert a new HW bridge */
  7879. if (!veb) {
  7880. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  7881. vsi->tc_config.enabled_tc);
  7882. if (veb) {
  7883. veb->bridge_mode = mode;
  7884. i40e_config_bridge_mode(veb);
  7885. } else {
  7886. /* No Bridge HW offload available */
  7887. return -ENOENT;
  7888. }
  7889. break;
  7890. } else if (mode != veb->bridge_mode) {
  7891. /* Existing HW bridge but different mode needs reset */
  7892. veb->bridge_mode = mode;
  7893. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  7894. if (mode == BRIDGE_MODE_VEB)
  7895. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  7896. else
  7897. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  7898. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7899. break;
  7900. }
  7901. }
  7902. return 0;
  7903. }
  7904. /**
  7905. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  7906. * @skb: skb buff
  7907. * @pid: process id
  7908. * @seq: RTNL message seq #
  7909. * @dev: the netdev being configured
  7910. * @filter_mask: unused
  7911. * @nlflags: netlink flags passed in
  7912. *
  7913. * Return the mode in which the hardware bridge is operating in
  7914. * i.e VEB or VEPA.
  7915. **/
  7916. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  7917. struct net_device *dev,
  7918. u32 __always_unused filter_mask,
  7919. int nlflags)
  7920. {
  7921. struct i40e_netdev_priv *np = netdev_priv(dev);
  7922. struct i40e_vsi *vsi = np->vsi;
  7923. struct i40e_pf *pf = vsi->back;
  7924. struct i40e_veb *veb = NULL;
  7925. int i;
  7926. /* Only for PF VSI for now */
  7927. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  7928. return -EOPNOTSUPP;
  7929. /* Find the HW bridge for the PF VSI */
  7930. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7931. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7932. veb = pf->veb[i];
  7933. }
  7934. if (!veb)
  7935. return 0;
  7936. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  7937. 0, 0, nlflags, filter_mask, NULL);
  7938. }
  7939. /* Hardware supports L4 tunnel length of 128B (=2^7) which includes
  7940. * inner mac plus all inner ethertypes.
  7941. */
  7942. #define I40E_MAX_TUNNEL_HDR_LEN 128
  7943. /**
  7944. * i40e_features_check - Validate encapsulated packet conforms to limits
  7945. * @skb: skb buff
  7946. * @dev: This physical port's netdev
  7947. * @features: Offload features that the stack believes apply
  7948. **/
  7949. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  7950. struct net_device *dev,
  7951. netdev_features_t features)
  7952. {
  7953. if (skb->encapsulation &&
  7954. ((skb_inner_network_header(skb) - skb_transport_header(skb)) >
  7955. I40E_MAX_TUNNEL_HDR_LEN))
  7956. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  7957. return features;
  7958. }
  7959. static const struct net_device_ops i40e_netdev_ops = {
  7960. .ndo_open = i40e_open,
  7961. .ndo_stop = i40e_close,
  7962. .ndo_start_xmit = i40e_lan_xmit_frame,
  7963. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  7964. .ndo_set_rx_mode = i40e_set_rx_mode,
  7965. .ndo_validate_addr = eth_validate_addr,
  7966. .ndo_set_mac_address = i40e_set_mac,
  7967. .ndo_change_mtu = i40e_change_mtu,
  7968. .ndo_do_ioctl = i40e_ioctl,
  7969. .ndo_tx_timeout = i40e_tx_timeout,
  7970. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  7971. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  7972. #ifdef CONFIG_NET_POLL_CONTROLLER
  7973. .ndo_poll_controller = i40e_netpoll,
  7974. #endif
  7975. .ndo_setup_tc = __i40e_setup_tc,
  7976. #ifdef I40E_FCOE
  7977. .ndo_fcoe_enable = i40e_fcoe_enable,
  7978. .ndo_fcoe_disable = i40e_fcoe_disable,
  7979. #endif
  7980. .ndo_set_features = i40e_set_features,
  7981. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  7982. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  7983. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  7984. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  7985. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  7986. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  7987. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  7988. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  7989. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  7990. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  7991. .ndo_fdb_add = i40e_ndo_fdb_add,
  7992. .ndo_features_check = i40e_features_check,
  7993. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  7994. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  7995. };
  7996. /**
  7997. * i40e_config_netdev - Setup the netdev flags
  7998. * @vsi: the VSI being configured
  7999. *
  8000. * Returns 0 on success, negative value on failure
  8001. **/
  8002. static int i40e_config_netdev(struct i40e_vsi *vsi)
  8003. {
  8004. struct i40e_pf *pf = vsi->back;
  8005. struct i40e_hw *hw = &pf->hw;
  8006. struct i40e_netdev_priv *np;
  8007. struct net_device *netdev;
  8008. u8 mac_addr[ETH_ALEN];
  8009. int etherdev_size;
  8010. etherdev_size = sizeof(struct i40e_netdev_priv);
  8011. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  8012. if (!netdev)
  8013. return -ENOMEM;
  8014. vsi->netdev = netdev;
  8015. np = netdev_priv(netdev);
  8016. np->vsi = vsi;
  8017. netdev->hw_enc_features |= NETIF_F_SG |
  8018. NETIF_F_IP_CSUM |
  8019. NETIF_F_IPV6_CSUM |
  8020. NETIF_F_HIGHDMA |
  8021. NETIF_F_SOFT_FEATURES |
  8022. NETIF_F_TSO |
  8023. NETIF_F_TSO_ECN |
  8024. NETIF_F_TSO6 |
  8025. NETIF_F_GSO_GRE |
  8026. NETIF_F_GSO_GRE_CSUM |
  8027. NETIF_F_GSO_IPXIP4 |
  8028. NETIF_F_GSO_IPXIP6 |
  8029. NETIF_F_GSO_UDP_TUNNEL |
  8030. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  8031. NETIF_F_GSO_PARTIAL |
  8032. NETIF_F_SCTP_CRC |
  8033. NETIF_F_RXHASH |
  8034. NETIF_F_RXCSUM |
  8035. 0;
  8036. if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
  8037. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  8038. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  8039. /* record features VLANs can make use of */
  8040. netdev->vlan_features |= netdev->hw_enc_features |
  8041. NETIF_F_TSO_MANGLEID;
  8042. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  8043. netdev->hw_features |= NETIF_F_NTUPLE;
  8044. netdev->hw_features |= netdev->hw_enc_features |
  8045. NETIF_F_HW_VLAN_CTAG_TX |
  8046. NETIF_F_HW_VLAN_CTAG_RX;
  8047. netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  8048. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  8049. if (vsi->type == I40E_VSI_MAIN) {
  8050. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  8051. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  8052. /* The following steps are necessary to prevent reception
  8053. * of tagged packets - some older NVM configurations load a
  8054. * default a MAC-VLAN filter that accepts any tagged packet
  8055. * which must be replaced by a normal filter.
  8056. */
  8057. i40e_rm_default_mac_filter(vsi, mac_addr);
  8058. spin_lock_bh(&vsi->mac_filter_list_lock);
  8059. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, true);
  8060. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8061. } else {
  8062. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  8063. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  8064. pf->vsi[pf->lan_vsi]->netdev->name);
  8065. random_ether_addr(mac_addr);
  8066. spin_lock_bh(&vsi->mac_filter_list_lock);
  8067. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
  8068. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8069. }
  8070. ether_addr_copy(netdev->dev_addr, mac_addr);
  8071. ether_addr_copy(netdev->perm_addr, mac_addr);
  8072. netdev->priv_flags |= IFF_UNICAST_FLT;
  8073. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8074. /* Setup netdev TC information */
  8075. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  8076. netdev->netdev_ops = &i40e_netdev_ops;
  8077. netdev->watchdog_timeo = 5 * HZ;
  8078. i40e_set_ethtool_ops(netdev);
  8079. #ifdef I40E_FCOE
  8080. i40e_fcoe_config_netdev(netdev, vsi);
  8081. #endif
  8082. return 0;
  8083. }
  8084. /**
  8085. * i40e_vsi_delete - Delete a VSI from the switch
  8086. * @vsi: the VSI being removed
  8087. *
  8088. * Returns 0 on success, negative value on failure
  8089. **/
  8090. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  8091. {
  8092. /* remove default VSI is not allowed */
  8093. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  8094. return;
  8095. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  8096. }
  8097. /**
  8098. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  8099. * @vsi: the VSI being queried
  8100. *
  8101. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  8102. **/
  8103. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  8104. {
  8105. struct i40e_veb *veb;
  8106. struct i40e_pf *pf = vsi->back;
  8107. /* Uplink is not a bridge so default to VEB */
  8108. if (vsi->veb_idx == I40E_NO_VEB)
  8109. return 1;
  8110. veb = pf->veb[vsi->veb_idx];
  8111. if (!veb) {
  8112. dev_info(&pf->pdev->dev,
  8113. "There is no veb associated with the bridge\n");
  8114. return -ENOENT;
  8115. }
  8116. /* Uplink is a bridge in VEPA mode */
  8117. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  8118. return 0;
  8119. } else {
  8120. /* Uplink is a bridge in VEB mode */
  8121. return 1;
  8122. }
  8123. /* VEPA is now default bridge, so return 0 */
  8124. return 0;
  8125. }
  8126. /**
  8127. * i40e_add_vsi - Add a VSI to the switch
  8128. * @vsi: the VSI being configured
  8129. *
  8130. * This initializes a VSI context depending on the VSI type to be added and
  8131. * passes it down to the add_vsi aq command.
  8132. **/
  8133. static int i40e_add_vsi(struct i40e_vsi *vsi)
  8134. {
  8135. int ret = -ENODEV;
  8136. i40e_status aq_ret = 0;
  8137. struct i40e_pf *pf = vsi->back;
  8138. struct i40e_hw *hw = &pf->hw;
  8139. struct i40e_vsi_context ctxt;
  8140. struct i40e_mac_filter *f, *ftmp;
  8141. u8 enabled_tc = 0x1; /* TC0 enabled */
  8142. int f_count = 0;
  8143. memset(&ctxt, 0, sizeof(ctxt));
  8144. switch (vsi->type) {
  8145. case I40E_VSI_MAIN:
  8146. /* The PF's main VSI is already setup as part of the
  8147. * device initialization, so we'll not bother with
  8148. * the add_vsi call, but we will retrieve the current
  8149. * VSI context.
  8150. */
  8151. ctxt.seid = pf->main_vsi_seid;
  8152. ctxt.pf_num = pf->hw.pf_id;
  8153. ctxt.vf_num = 0;
  8154. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  8155. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8156. if (ret) {
  8157. dev_info(&pf->pdev->dev,
  8158. "couldn't get PF vsi config, err %s aq_err %s\n",
  8159. i40e_stat_str(&pf->hw, ret),
  8160. i40e_aq_str(&pf->hw,
  8161. pf->hw.aq.asq_last_status));
  8162. return -ENOENT;
  8163. }
  8164. vsi->info = ctxt.info;
  8165. vsi->info.valid_sections = 0;
  8166. vsi->seid = ctxt.seid;
  8167. vsi->id = ctxt.vsi_number;
  8168. enabled_tc = i40e_pf_get_tc_map(pf);
  8169. /* MFP mode setup queue map and update VSI */
  8170. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  8171. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  8172. memset(&ctxt, 0, sizeof(ctxt));
  8173. ctxt.seid = pf->main_vsi_seid;
  8174. ctxt.pf_num = pf->hw.pf_id;
  8175. ctxt.vf_num = 0;
  8176. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  8177. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  8178. if (ret) {
  8179. dev_info(&pf->pdev->dev,
  8180. "update vsi failed, err %s aq_err %s\n",
  8181. i40e_stat_str(&pf->hw, ret),
  8182. i40e_aq_str(&pf->hw,
  8183. pf->hw.aq.asq_last_status));
  8184. ret = -ENOENT;
  8185. goto err;
  8186. }
  8187. /* update the local VSI info queue map */
  8188. i40e_vsi_update_queue_map(vsi, &ctxt);
  8189. vsi->info.valid_sections = 0;
  8190. } else {
  8191. /* Default/Main VSI is only enabled for TC0
  8192. * reconfigure it to enable all TCs that are
  8193. * available on the port in SFP mode.
  8194. * For MFP case the iSCSI PF would use this
  8195. * flow to enable LAN+iSCSI TC.
  8196. */
  8197. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  8198. if (ret) {
  8199. dev_info(&pf->pdev->dev,
  8200. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  8201. enabled_tc,
  8202. i40e_stat_str(&pf->hw, ret),
  8203. i40e_aq_str(&pf->hw,
  8204. pf->hw.aq.asq_last_status));
  8205. ret = -ENOENT;
  8206. }
  8207. }
  8208. break;
  8209. case I40E_VSI_FDIR:
  8210. ctxt.pf_num = hw->pf_id;
  8211. ctxt.vf_num = 0;
  8212. ctxt.uplink_seid = vsi->uplink_seid;
  8213. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8214. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8215. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  8216. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  8217. ctxt.info.valid_sections |=
  8218. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8219. ctxt.info.switch_id =
  8220. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8221. }
  8222. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8223. break;
  8224. case I40E_VSI_VMDQ2:
  8225. ctxt.pf_num = hw->pf_id;
  8226. ctxt.vf_num = 0;
  8227. ctxt.uplink_seid = vsi->uplink_seid;
  8228. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8229. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  8230. /* This VSI is connected to VEB so the switch_id
  8231. * should be set to zero by default.
  8232. */
  8233. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8234. ctxt.info.valid_sections |=
  8235. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8236. ctxt.info.switch_id =
  8237. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8238. }
  8239. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8240. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8241. break;
  8242. case I40E_VSI_SRIOV:
  8243. ctxt.pf_num = hw->pf_id;
  8244. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  8245. ctxt.uplink_seid = vsi->uplink_seid;
  8246. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8247. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  8248. /* This VSI is connected to VEB so the switch_id
  8249. * should be set to zero by default.
  8250. */
  8251. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8252. ctxt.info.valid_sections |=
  8253. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8254. ctxt.info.switch_id =
  8255. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8256. }
  8257. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  8258. ctxt.info.valid_sections |=
  8259. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  8260. ctxt.info.queueing_opt_flags |=
  8261. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  8262. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  8263. }
  8264. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  8265. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  8266. if (pf->vf[vsi->vf_id].spoofchk) {
  8267. ctxt.info.valid_sections |=
  8268. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  8269. ctxt.info.sec_flags |=
  8270. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  8271. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  8272. }
  8273. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8274. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8275. break;
  8276. #ifdef I40E_FCOE
  8277. case I40E_VSI_FCOE:
  8278. ret = i40e_fcoe_vsi_init(vsi, &ctxt);
  8279. if (ret) {
  8280. dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
  8281. return ret;
  8282. }
  8283. break;
  8284. #endif /* I40E_FCOE */
  8285. case I40E_VSI_IWARP:
  8286. /* send down message to iWARP */
  8287. break;
  8288. default:
  8289. return -ENODEV;
  8290. }
  8291. if (vsi->type != I40E_VSI_MAIN) {
  8292. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  8293. if (ret) {
  8294. dev_info(&vsi->back->pdev->dev,
  8295. "add vsi failed, err %s aq_err %s\n",
  8296. i40e_stat_str(&pf->hw, ret),
  8297. i40e_aq_str(&pf->hw,
  8298. pf->hw.aq.asq_last_status));
  8299. ret = -ENOENT;
  8300. goto err;
  8301. }
  8302. vsi->info = ctxt.info;
  8303. vsi->info.valid_sections = 0;
  8304. vsi->seid = ctxt.seid;
  8305. vsi->id = ctxt.vsi_number;
  8306. }
  8307. /* Except FDIR VSI, for all othet VSI set the broadcast filter */
  8308. if (vsi->type != I40E_VSI_FDIR) {
  8309. aq_ret = i40e_aq_set_vsi_broadcast(hw, vsi->seid, true, NULL);
  8310. if (aq_ret) {
  8311. ret = i40e_aq_rc_to_posix(aq_ret,
  8312. hw->aq.asq_last_status);
  8313. dev_info(&pf->pdev->dev,
  8314. "set brdcast promisc failed, err %s, aq_err %s\n",
  8315. i40e_stat_str(hw, aq_ret),
  8316. i40e_aq_str(hw, hw->aq.asq_last_status));
  8317. }
  8318. }
  8319. vsi->active_filters = 0;
  8320. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  8321. spin_lock_bh(&vsi->mac_filter_list_lock);
  8322. /* If macvlan filters already exist, force them to get loaded */
  8323. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  8324. f->state = I40E_FILTER_NEW;
  8325. f_count++;
  8326. }
  8327. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8328. if (f_count) {
  8329. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  8330. pf->flags |= I40E_FLAG_FILTER_SYNC;
  8331. }
  8332. /* Update VSI BW information */
  8333. ret = i40e_vsi_get_bw_info(vsi);
  8334. if (ret) {
  8335. dev_info(&pf->pdev->dev,
  8336. "couldn't get vsi bw info, err %s aq_err %s\n",
  8337. i40e_stat_str(&pf->hw, ret),
  8338. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8339. /* VSI is already added so not tearing that up */
  8340. ret = 0;
  8341. }
  8342. err:
  8343. return ret;
  8344. }
  8345. /**
  8346. * i40e_vsi_release - Delete a VSI and free its resources
  8347. * @vsi: the VSI being removed
  8348. *
  8349. * Returns 0 on success or < 0 on error
  8350. **/
  8351. int i40e_vsi_release(struct i40e_vsi *vsi)
  8352. {
  8353. struct i40e_mac_filter *f, *ftmp;
  8354. struct i40e_veb *veb = NULL;
  8355. struct i40e_pf *pf;
  8356. u16 uplink_seid;
  8357. int i, n;
  8358. pf = vsi->back;
  8359. /* release of a VEB-owner or last VSI is not allowed */
  8360. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  8361. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  8362. vsi->seid, vsi->uplink_seid);
  8363. return -ENODEV;
  8364. }
  8365. if (vsi == pf->vsi[pf->lan_vsi] &&
  8366. !test_bit(__I40E_DOWN, &pf->state)) {
  8367. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  8368. return -ENODEV;
  8369. }
  8370. uplink_seid = vsi->uplink_seid;
  8371. if (vsi->type != I40E_VSI_SRIOV) {
  8372. if (vsi->netdev_registered) {
  8373. vsi->netdev_registered = false;
  8374. if (vsi->netdev) {
  8375. /* results in a call to i40e_close() */
  8376. unregister_netdev(vsi->netdev);
  8377. }
  8378. } else {
  8379. i40e_vsi_close(vsi);
  8380. }
  8381. i40e_vsi_disable_irq(vsi);
  8382. }
  8383. spin_lock_bh(&vsi->mac_filter_list_lock);
  8384. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  8385. i40e_del_filter(vsi, f->macaddr, f->vlan,
  8386. f->is_vf, f->is_netdev);
  8387. spin_unlock_bh(&vsi->mac_filter_list_lock);
  8388. i40e_sync_vsi_filters(vsi);
  8389. i40e_vsi_delete(vsi);
  8390. i40e_vsi_free_q_vectors(vsi);
  8391. if (vsi->netdev) {
  8392. free_netdev(vsi->netdev);
  8393. vsi->netdev = NULL;
  8394. }
  8395. i40e_vsi_clear_rings(vsi);
  8396. i40e_vsi_clear(vsi);
  8397. /* If this was the last thing on the VEB, except for the
  8398. * controlling VSI, remove the VEB, which puts the controlling
  8399. * VSI onto the next level down in the switch.
  8400. *
  8401. * Well, okay, there's one more exception here: don't remove
  8402. * the orphan VEBs yet. We'll wait for an explicit remove request
  8403. * from up the network stack.
  8404. */
  8405. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  8406. if (pf->vsi[i] &&
  8407. pf->vsi[i]->uplink_seid == uplink_seid &&
  8408. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8409. n++; /* count the VSIs */
  8410. }
  8411. }
  8412. for (i = 0; i < I40E_MAX_VEB; i++) {
  8413. if (!pf->veb[i])
  8414. continue;
  8415. if (pf->veb[i]->uplink_seid == uplink_seid)
  8416. n++; /* count the VEBs */
  8417. if (pf->veb[i]->seid == uplink_seid)
  8418. veb = pf->veb[i];
  8419. }
  8420. if (n == 0 && veb && veb->uplink_seid != 0)
  8421. i40e_veb_release(veb);
  8422. return 0;
  8423. }
  8424. /**
  8425. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  8426. * @vsi: ptr to the VSI
  8427. *
  8428. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  8429. * corresponding SW VSI structure and initializes num_queue_pairs for the
  8430. * newly allocated VSI.
  8431. *
  8432. * Returns 0 on success or negative on failure
  8433. **/
  8434. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  8435. {
  8436. int ret = -ENOENT;
  8437. struct i40e_pf *pf = vsi->back;
  8438. if (vsi->q_vectors[0]) {
  8439. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  8440. vsi->seid);
  8441. return -EEXIST;
  8442. }
  8443. if (vsi->base_vector) {
  8444. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  8445. vsi->seid, vsi->base_vector);
  8446. return -EEXIST;
  8447. }
  8448. ret = i40e_vsi_alloc_q_vectors(vsi);
  8449. if (ret) {
  8450. dev_info(&pf->pdev->dev,
  8451. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  8452. vsi->num_q_vectors, vsi->seid, ret);
  8453. vsi->num_q_vectors = 0;
  8454. goto vector_setup_out;
  8455. }
  8456. /* In Legacy mode, we do not have to get any other vector since we
  8457. * piggyback on the misc/ICR0 for queue interrupts.
  8458. */
  8459. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8460. return ret;
  8461. if (vsi->num_q_vectors)
  8462. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  8463. vsi->num_q_vectors, vsi->idx);
  8464. if (vsi->base_vector < 0) {
  8465. dev_info(&pf->pdev->dev,
  8466. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  8467. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  8468. i40e_vsi_free_q_vectors(vsi);
  8469. ret = -ENOENT;
  8470. goto vector_setup_out;
  8471. }
  8472. vector_setup_out:
  8473. return ret;
  8474. }
  8475. /**
  8476. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  8477. * @vsi: pointer to the vsi.
  8478. *
  8479. * This re-allocates a vsi's queue resources.
  8480. *
  8481. * Returns pointer to the successfully allocated and configured VSI sw struct
  8482. * on success, otherwise returns NULL on failure.
  8483. **/
  8484. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  8485. {
  8486. struct i40e_pf *pf;
  8487. u8 enabled_tc;
  8488. int ret;
  8489. if (!vsi)
  8490. return NULL;
  8491. pf = vsi->back;
  8492. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8493. i40e_vsi_clear_rings(vsi);
  8494. i40e_vsi_free_arrays(vsi, false);
  8495. i40e_set_num_rings_in_vsi(vsi);
  8496. ret = i40e_vsi_alloc_arrays(vsi, false);
  8497. if (ret)
  8498. goto err_vsi;
  8499. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  8500. if (ret < 0) {
  8501. dev_info(&pf->pdev->dev,
  8502. "failed to get tracking for %d queues for VSI %d err %d\n",
  8503. vsi->alloc_queue_pairs, vsi->seid, ret);
  8504. goto err_vsi;
  8505. }
  8506. vsi->base_queue = ret;
  8507. /* Update the FW view of the VSI. Force a reset of TC and queue
  8508. * layout configurations.
  8509. */
  8510. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  8511. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  8512. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  8513. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  8514. if (vsi->type == I40E_VSI_MAIN)
  8515. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  8516. /* assign it some queues */
  8517. ret = i40e_alloc_rings(vsi);
  8518. if (ret)
  8519. goto err_rings;
  8520. /* map all of the rings to the q_vectors */
  8521. i40e_vsi_map_rings_to_vectors(vsi);
  8522. return vsi;
  8523. err_rings:
  8524. i40e_vsi_free_q_vectors(vsi);
  8525. if (vsi->netdev_registered) {
  8526. vsi->netdev_registered = false;
  8527. unregister_netdev(vsi->netdev);
  8528. free_netdev(vsi->netdev);
  8529. vsi->netdev = NULL;
  8530. }
  8531. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8532. err_vsi:
  8533. i40e_vsi_clear(vsi);
  8534. return NULL;
  8535. }
  8536. /**
  8537. * i40e_vsi_setup - Set up a VSI by a given type
  8538. * @pf: board private structure
  8539. * @type: VSI type
  8540. * @uplink_seid: the switch element to link to
  8541. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  8542. *
  8543. * This allocates the sw VSI structure and its queue resources, then add a VSI
  8544. * to the identified VEB.
  8545. *
  8546. * Returns pointer to the successfully allocated and configure VSI sw struct on
  8547. * success, otherwise returns NULL on failure.
  8548. **/
  8549. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  8550. u16 uplink_seid, u32 param1)
  8551. {
  8552. struct i40e_vsi *vsi = NULL;
  8553. struct i40e_veb *veb = NULL;
  8554. int ret, i;
  8555. int v_idx;
  8556. /* The requested uplink_seid must be either
  8557. * - the PF's port seid
  8558. * no VEB is needed because this is the PF
  8559. * or this is a Flow Director special case VSI
  8560. * - seid of an existing VEB
  8561. * - seid of a VSI that owns an existing VEB
  8562. * - seid of a VSI that doesn't own a VEB
  8563. * a new VEB is created and the VSI becomes the owner
  8564. * - seid of the PF VSI, which is what creates the first VEB
  8565. * this is a special case of the previous
  8566. *
  8567. * Find which uplink_seid we were given and create a new VEB if needed
  8568. */
  8569. for (i = 0; i < I40E_MAX_VEB; i++) {
  8570. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  8571. veb = pf->veb[i];
  8572. break;
  8573. }
  8574. }
  8575. if (!veb && uplink_seid != pf->mac_seid) {
  8576. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8577. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  8578. vsi = pf->vsi[i];
  8579. break;
  8580. }
  8581. }
  8582. if (!vsi) {
  8583. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  8584. uplink_seid);
  8585. return NULL;
  8586. }
  8587. if (vsi->uplink_seid == pf->mac_seid)
  8588. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  8589. vsi->tc_config.enabled_tc);
  8590. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  8591. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  8592. vsi->tc_config.enabled_tc);
  8593. if (veb) {
  8594. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  8595. dev_info(&vsi->back->pdev->dev,
  8596. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  8597. return NULL;
  8598. }
  8599. /* We come up by default in VEPA mode if SRIOV is not
  8600. * already enabled, in which case we can't force VEPA
  8601. * mode.
  8602. */
  8603. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  8604. veb->bridge_mode = BRIDGE_MODE_VEPA;
  8605. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8606. }
  8607. i40e_config_bridge_mode(veb);
  8608. }
  8609. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8610. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8611. veb = pf->veb[i];
  8612. }
  8613. if (!veb) {
  8614. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  8615. return NULL;
  8616. }
  8617. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8618. uplink_seid = veb->seid;
  8619. }
  8620. /* get vsi sw struct */
  8621. v_idx = i40e_vsi_mem_alloc(pf, type);
  8622. if (v_idx < 0)
  8623. goto err_alloc;
  8624. vsi = pf->vsi[v_idx];
  8625. if (!vsi)
  8626. goto err_alloc;
  8627. vsi->type = type;
  8628. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  8629. if (type == I40E_VSI_MAIN)
  8630. pf->lan_vsi = v_idx;
  8631. else if (type == I40E_VSI_SRIOV)
  8632. vsi->vf_id = param1;
  8633. /* assign it some queues */
  8634. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  8635. vsi->idx);
  8636. if (ret < 0) {
  8637. dev_info(&pf->pdev->dev,
  8638. "failed to get tracking for %d queues for VSI %d err=%d\n",
  8639. vsi->alloc_queue_pairs, vsi->seid, ret);
  8640. goto err_vsi;
  8641. }
  8642. vsi->base_queue = ret;
  8643. /* get a VSI from the hardware */
  8644. vsi->uplink_seid = uplink_seid;
  8645. ret = i40e_add_vsi(vsi);
  8646. if (ret)
  8647. goto err_vsi;
  8648. switch (vsi->type) {
  8649. /* setup the netdev if needed */
  8650. case I40E_VSI_MAIN:
  8651. /* Apply relevant filters if a platform-specific mac
  8652. * address was selected.
  8653. */
  8654. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  8655. ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  8656. if (ret) {
  8657. dev_warn(&pf->pdev->dev,
  8658. "could not set up macaddr; err %d\n",
  8659. ret);
  8660. }
  8661. }
  8662. case I40E_VSI_VMDQ2:
  8663. case I40E_VSI_FCOE:
  8664. ret = i40e_config_netdev(vsi);
  8665. if (ret)
  8666. goto err_netdev;
  8667. ret = register_netdev(vsi->netdev);
  8668. if (ret)
  8669. goto err_netdev;
  8670. vsi->netdev_registered = true;
  8671. netif_carrier_off(vsi->netdev);
  8672. #ifdef CONFIG_I40E_DCB
  8673. /* Setup DCB netlink interface */
  8674. i40e_dcbnl_setup(vsi);
  8675. #endif /* CONFIG_I40E_DCB */
  8676. /* fall through */
  8677. case I40E_VSI_FDIR:
  8678. /* set up vectors and rings if needed */
  8679. ret = i40e_vsi_setup_vectors(vsi);
  8680. if (ret)
  8681. goto err_msix;
  8682. ret = i40e_alloc_rings(vsi);
  8683. if (ret)
  8684. goto err_rings;
  8685. /* map all of the rings to the q_vectors */
  8686. i40e_vsi_map_rings_to_vectors(vsi);
  8687. i40e_vsi_reset_stats(vsi);
  8688. break;
  8689. default:
  8690. /* no netdev or rings for the other VSI types */
  8691. break;
  8692. }
  8693. if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
  8694. (vsi->type == I40E_VSI_VMDQ2)) {
  8695. ret = i40e_vsi_config_rss(vsi);
  8696. }
  8697. return vsi;
  8698. err_rings:
  8699. i40e_vsi_free_q_vectors(vsi);
  8700. err_msix:
  8701. if (vsi->netdev_registered) {
  8702. vsi->netdev_registered = false;
  8703. unregister_netdev(vsi->netdev);
  8704. free_netdev(vsi->netdev);
  8705. vsi->netdev = NULL;
  8706. }
  8707. err_netdev:
  8708. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8709. err_vsi:
  8710. i40e_vsi_clear(vsi);
  8711. err_alloc:
  8712. return NULL;
  8713. }
  8714. /**
  8715. * i40e_veb_get_bw_info - Query VEB BW information
  8716. * @veb: the veb to query
  8717. *
  8718. * Query the Tx scheduler BW configuration data for given VEB
  8719. **/
  8720. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  8721. {
  8722. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  8723. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  8724. struct i40e_pf *pf = veb->pf;
  8725. struct i40e_hw *hw = &pf->hw;
  8726. u32 tc_bw_max;
  8727. int ret = 0;
  8728. int i;
  8729. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  8730. &bw_data, NULL);
  8731. if (ret) {
  8732. dev_info(&pf->pdev->dev,
  8733. "query veb bw config failed, err %s aq_err %s\n",
  8734. i40e_stat_str(&pf->hw, ret),
  8735. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8736. goto out;
  8737. }
  8738. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  8739. &ets_data, NULL);
  8740. if (ret) {
  8741. dev_info(&pf->pdev->dev,
  8742. "query veb bw ets config failed, err %s aq_err %s\n",
  8743. i40e_stat_str(&pf->hw, ret),
  8744. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8745. goto out;
  8746. }
  8747. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  8748. veb->bw_max_quanta = ets_data.tc_bw_max;
  8749. veb->is_abs_credits = bw_data.absolute_credits_enable;
  8750. veb->enabled_tc = ets_data.tc_valid_bits;
  8751. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  8752. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  8753. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  8754. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  8755. veb->bw_tc_limit_credits[i] =
  8756. le16_to_cpu(bw_data.tc_bw_limits[i]);
  8757. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  8758. }
  8759. out:
  8760. return ret;
  8761. }
  8762. /**
  8763. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  8764. * @pf: board private structure
  8765. *
  8766. * On error: returns error code (negative)
  8767. * On success: returns vsi index in PF (positive)
  8768. **/
  8769. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  8770. {
  8771. int ret = -ENOENT;
  8772. struct i40e_veb *veb;
  8773. int i;
  8774. /* Need to protect the allocation of switch elements at the PF level */
  8775. mutex_lock(&pf->switch_mutex);
  8776. /* VEB list may be fragmented if VEB creation/destruction has
  8777. * been happening. We can afford to do a quick scan to look
  8778. * for any free slots in the list.
  8779. *
  8780. * find next empty veb slot, looping back around if necessary
  8781. */
  8782. i = 0;
  8783. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  8784. i++;
  8785. if (i >= I40E_MAX_VEB) {
  8786. ret = -ENOMEM;
  8787. goto err_alloc_veb; /* out of VEB slots! */
  8788. }
  8789. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  8790. if (!veb) {
  8791. ret = -ENOMEM;
  8792. goto err_alloc_veb;
  8793. }
  8794. veb->pf = pf;
  8795. veb->idx = i;
  8796. veb->enabled_tc = 1;
  8797. pf->veb[i] = veb;
  8798. ret = i;
  8799. err_alloc_veb:
  8800. mutex_unlock(&pf->switch_mutex);
  8801. return ret;
  8802. }
  8803. /**
  8804. * i40e_switch_branch_release - Delete a branch of the switch tree
  8805. * @branch: where to start deleting
  8806. *
  8807. * This uses recursion to find the tips of the branch to be
  8808. * removed, deleting until we get back to and can delete this VEB.
  8809. **/
  8810. static void i40e_switch_branch_release(struct i40e_veb *branch)
  8811. {
  8812. struct i40e_pf *pf = branch->pf;
  8813. u16 branch_seid = branch->seid;
  8814. u16 veb_idx = branch->idx;
  8815. int i;
  8816. /* release any VEBs on this VEB - RECURSION */
  8817. for (i = 0; i < I40E_MAX_VEB; i++) {
  8818. if (!pf->veb[i])
  8819. continue;
  8820. if (pf->veb[i]->uplink_seid == branch->seid)
  8821. i40e_switch_branch_release(pf->veb[i]);
  8822. }
  8823. /* Release the VSIs on this VEB, but not the owner VSI.
  8824. *
  8825. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  8826. * the VEB itself, so don't use (*branch) after this loop.
  8827. */
  8828. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8829. if (!pf->vsi[i])
  8830. continue;
  8831. if (pf->vsi[i]->uplink_seid == branch_seid &&
  8832. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8833. i40e_vsi_release(pf->vsi[i]);
  8834. }
  8835. }
  8836. /* There's one corner case where the VEB might not have been
  8837. * removed, so double check it here and remove it if needed.
  8838. * This case happens if the veb was created from the debugfs
  8839. * commands and no VSIs were added to it.
  8840. */
  8841. if (pf->veb[veb_idx])
  8842. i40e_veb_release(pf->veb[veb_idx]);
  8843. }
  8844. /**
  8845. * i40e_veb_clear - remove veb struct
  8846. * @veb: the veb to remove
  8847. **/
  8848. static void i40e_veb_clear(struct i40e_veb *veb)
  8849. {
  8850. if (!veb)
  8851. return;
  8852. if (veb->pf) {
  8853. struct i40e_pf *pf = veb->pf;
  8854. mutex_lock(&pf->switch_mutex);
  8855. if (pf->veb[veb->idx] == veb)
  8856. pf->veb[veb->idx] = NULL;
  8857. mutex_unlock(&pf->switch_mutex);
  8858. }
  8859. kfree(veb);
  8860. }
  8861. /**
  8862. * i40e_veb_release - Delete a VEB and free its resources
  8863. * @veb: the VEB being removed
  8864. **/
  8865. void i40e_veb_release(struct i40e_veb *veb)
  8866. {
  8867. struct i40e_vsi *vsi = NULL;
  8868. struct i40e_pf *pf;
  8869. int i, n = 0;
  8870. pf = veb->pf;
  8871. /* find the remaining VSI and check for extras */
  8872. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8873. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  8874. n++;
  8875. vsi = pf->vsi[i];
  8876. }
  8877. }
  8878. if (n != 1) {
  8879. dev_info(&pf->pdev->dev,
  8880. "can't remove VEB %d with %d VSIs left\n",
  8881. veb->seid, n);
  8882. return;
  8883. }
  8884. /* move the remaining VSI to uplink veb */
  8885. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  8886. if (veb->uplink_seid) {
  8887. vsi->uplink_seid = veb->uplink_seid;
  8888. if (veb->uplink_seid == pf->mac_seid)
  8889. vsi->veb_idx = I40E_NO_VEB;
  8890. else
  8891. vsi->veb_idx = veb->veb_idx;
  8892. } else {
  8893. /* floating VEB */
  8894. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  8895. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  8896. }
  8897. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  8898. i40e_veb_clear(veb);
  8899. }
  8900. /**
  8901. * i40e_add_veb - create the VEB in the switch
  8902. * @veb: the VEB to be instantiated
  8903. * @vsi: the controlling VSI
  8904. **/
  8905. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  8906. {
  8907. struct i40e_pf *pf = veb->pf;
  8908. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  8909. int ret;
  8910. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  8911. veb->enabled_tc, false,
  8912. &veb->seid, enable_stats, NULL);
  8913. /* get a VEB from the hardware */
  8914. if (ret) {
  8915. dev_info(&pf->pdev->dev,
  8916. "couldn't add VEB, err %s aq_err %s\n",
  8917. i40e_stat_str(&pf->hw, ret),
  8918. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8919. return -EPERM;
  8920. }
  8921. /* get statistics counter */
  8922. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  8923. &veb->stats_idx, NULL, NULL, NULL);
  8924. if (ret) {
  8925. dev_info(&pf->pdev->dev,
  8926. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  8927. i40e_stat_str(&pf->hw, ret),
  8928. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8929. return -EPERM;
  8930. }
  8931. ret = i40e_veb_get_bw_info(veb);
  8932. if (ret) {
  8933. dev_info(&pf->pdev->dev,
  8934. "couldn't get VEB bw info, err %s aq_err %s\n",
  8935. i40e_stat_str(&pf->hw, ret),
  8936. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8937. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  8938. return -ENOENT;
  8939. }
  8940. vsi->uplink_seid = veb->seid;
  8941. vsi->veb_idx = veb->idx;
  8942. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8943. return 0;
  8944. }
  8945. /**
  8946. * i40e_veb_setup - Set up a VEB
  8947. * @pf: board private structure
  8948. * @flags: VEB setup flags
  8949. * @uplink_seid: the switch element to link to
  8950. * @vsi_seid: the initial VSI seid
  8951. * @enabled_tc: Enabled TC bit-map
  8952. *
  8953. * This allocates the sw VEB structure and links it into the switch
  8954. * It is possible and legal for this to be a duplicate of an already
  8955. * existing VEB. It is also possible for both uplink and vsi seids
  8956. * to be zero, in order to create a floating VEB.
  8957. *
  8958. * Returns pointer to the successfully allocated VEB sw struct on
  8959. * success, otherwise returns NULL on failure.
  8960. **/
  8961. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  8962. u16 uplink_seid, u16 vsi_seid,
  8963. u8 enabled_tc)
  8964. {
  8965. struct i40e_veb *veb, *uplink_veb = NULL;
  8966. int vsi_idx, veb_idx;
  8967. int ret;
  8968. /* if one seid is 0, the other must be 0 to create a floating relay */
  8969. if ((uplink_seid == 0 || vsi_seid == 0) &&
  8970. (uplink_seid + vsi_seid != 0)) {
  8971. dev_info(&pf->pdev->dev,
  8972. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  8973. uplink_seid, vsi_seid);
  8974. return NULL;
  8975. }
  8976. /* make sure there is such a vsi and uplink */
  8977. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  8978. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  8979. break;
  8980. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  8981. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  8982. vsi_seid);
  8983. return NULL;
  8984. }
  8985. if (uplink_seid && uplink_seid != pf->mac_seid) {
  8986. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  8987. if (pf->veb[veb_idx] &&
  8988. pf->veb[veb_idx]->seid == uplink_seid) {
  8989. uplink_veb = pf->veb[veb_idx];
  8990. break;
  8991. }
  8992. }
  8993. if (!uplink_veb) {
  8994. dev_info(&pf->pdev->dev,
  8995. "uplink seid %d not found\n", uplink_seid);
  8996. return NULL;
  8997. }
  8998. }
  8999. /* get veb sw struct */
  9000. veb_idx = i40e_veb_mem_alloc(pf);
  9001. if (veb_idx < 0)
  9002. goto err_alloc;
  9003. veb = pf->veb[veb_idx];
  9004. veb->flags = flags;
  9005. veb->uplink_seid = uplink_seid;
  9006. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  9007. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  9008. /* create the VEB in the switch */
  9009. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  9010. if (ret)
  9011. goto err_veb;
  9012. if (vsi_idx == pf->lan_vsi)
  9013. pf->lan_veb = veb->idx;
  9014. return veb;
  9015. err_veb:
  9016. i40e_veb_clear(veb);
  9017. err_alloc:
  9018. return NULL;
  9019. }
  9020. /**
  9021. * i40e_setup_pf_switch_element - set PF vars based on switch type
  9022. * @pf: board private structure
  9023. * @ele: element we are building info from
  9024. * @num_reported: total number of elements
  9025. * @printconfig: should we print the contents
  9026. *
  9027. * helper function to assist in extracting a few useful SEID values.
  9028. **/
  9029. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  9030. struct i40e_aqc_switch_config_element_resp *ele,
  9031. u16 num_reported, bool printconfig)
  9032. {
  9033. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  9034. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  9035. u8 element_type = ele->element_type;
  9036. u16 seid = le16_to_cpu(ele->seid);
  9037. if (printconfig)
  9038. dev_info(&pf->pdev->dev,
  9039. "type=%d seid=%d uplink=%d downlink=%d\n",
  9040. element_type, seid, uplink_seid, downlink_seid);
  9041. switch (element_type) {
  9042. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  9043. pf->mac_seid = seid;
  9044. break;
  9045. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  9046. /* Main VEB? */
  9047. if (uplink_seid != pf->mac_seid)
  9048. break;
  9049. if (pf->lan_veb == I40E_NO_VEB) {
  9050. int v;
  9051. /* find existing or else empty VEB */
  9052. for (v = 0; v < I40E_MAX_VEB; v++) {
  9053. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  9054. pf->lan_veb = v;
  9055. break;
  9056. }
  9057. }
  9058. if (pf->lan_veb == I40E_NO_VEB) {
  9059. v = i40e_veb_mem_alloc(pf);
  9060. if (v < 0)
  9061. break;
  9062. pf->lan_veb = v;
  9063. }
  9064. }
  9065. pf->veb[pf->lan_veb]->seid = seid;
  9066. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  9067. pf->veb[pf->lan_veb]->pf = pf;
  9068. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  9069. break;
  9070. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  9071. if (num_reported != 1)
  9072. break;
  9073. /* This is immediately after a reset so we can assume this is
  9074. * the PF's VSI
  9075. */
  9076. pf->mac_seid = uplink_seid;
  9077. pf->pf_seid = downlink_seid;
  9078. pf->main_vsi_seid = seid;
  9079. if (printconfig)
  9080. dev_info(&pf->pdev->dev,
  9081. "pf_seid=%d main_vsi_seid=%d\n",
  9082. pf->pf_seid, pf->main_vsi_seid);
  9083. break;
  9084. case I40E_SWITCH_ELEMENT_TYPE_PF:
  9085. case I40E_SWITCH_ELEMENT_TYPE_VF:
  9086. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  9087. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  9088. case I40E_SWITCH_ELEMENT_TYPE_PE:
  9089. case I40E_SWITCH_ELEMENT_TYPE_PA:
  9090. /* ignore these for now */
  9091. break;
  9092. default:
  9093. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  9094. element_type, seid);
  9095. break;
  9096. }
  9097. }
  9098. /**
  9099. * i40e_fetch_switch_configuration - Get switch config from firmware
  9100. * @pf: board private structure
  9101. * @printconfig: should we print the contents
  9102. *
  9103. * Get the current switch configuration from the device and
  9104. * extract a few useful SEID values.
  9105. **/
  9106. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  9107. {
  9108. struct i40e_aqc_get_switch_config_resp *sw_config;
  9109. u16 next_seid = 0;
  9110. int ret = 0;
  9111. u8 *aq_buf;
  9112. int i;
  9113. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  9114. if (!aq_buf)
  9115. return -ENOMEM;
  9116. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  9117. do {
  9118. u16 num_reported, num_total;
  9119. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  9120. I40E_AQ_LARGE_BUF,
  9121. &next_seid, NULL);
  9122. if (ret) {
  9123. dev_info(&pf->pdev->dev,
  9124. "get switch config failed err %s aq_err %s\n",
  9125. i40e_stat_str(&pf->hw, ret),
  9126. i40e_aq_str(&pf->hw,
  9127. pf->hw.aq.asq_last_status));
  9128. kfree(aq_buf);
  9129. return -ENOENT;
  9130. }
  9131. num_reported = le16_to_cpu(sw_config->header.num_reported);
  9132. num_total = le16_to_cpu(sw_config->header.num_total);
  9133. if (printconfig)
  9134. dev_info(&pf->pdev->dev,
  9135. "header: %d reported %d total\n",
  9136. num_reported, num_total);
  9137. for (i = 0; i < num_reported; i++) {
  9138. struct i40e_aqc_switch_config_element_resp *ele =
  9139. &sw_config->element[i];
  9140. i40e_setup_pf_switch_element(pf, ele, num_reported,
  9141. printconfig);
  9142. }
  9143. } while (next_seid != 0);
  9144. kfree(aq_buf);
  9145. return ret;
  9146. }
  9147. /**
  9148. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  9149. * @pf: board private structure
  9150. * @reinit: if the Main VSI needs to re-initialized.
  9151. *
  9152. * Returns 0 on success, negative value on failure
  9153. **/
  9154. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  9155. {
  9156. u16 flags = 0;
  9157. int ret;
  9158. /* find out what's out there already */
  9159. ret = i40e_fetch_switch_configuration(pf, false);
  9160. if (ret) {
  9161. dev_info(&pf->pdev->dev,
  9162. "couldn't fetch switch config, err %s aq_err %s\n",
  9163. i40e_stat_str(&pf->hw, ret),
  9164. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9165. return ret;
  9166. }
  9167. i40e_pf_reset_stats(pf);
  9168. /* set the switch config bit for the whole device to
  9169. * support limited promisc or true promisc
  9170. * when user requests promisc. The default is limited
  9171. * promisc.
  9172. */
  9173. if ((pf->hw.pf_id == 0) &&
  9174. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  9175. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9176. if (pf->hw.pf_id == 0) {
  9177. u16 valid_flags;
  9178. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9179. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
  9180. NULL);
  9181. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  9182. dev_info(&pf->pdev->dev,
  9183. "couldn't set switch config bits, err %s aq_err %s\n",
  9184. i40e_stat_str(&pf->hw, ret),
  9185. i40e_aq_str(&pf->hw,
  9186. pf->hw.aq.asq_last_status));
  9187. /* not a fatal problem, just keep going */
  9188. }
  9189. }
  9190. /* first time setup */
  9191. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  9192. struct i40e_vsi *vsi = NULL;
  9193. u16 uplink_seid;
  9194. /* Set up the PF VSI associated with the PF's main VSI
  9195. * that is already in the HW switch
  9196. */
  9197. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  9198. uplink_seid = pf->veb[pf->lan_veb]->seid;
  9199. else
  9200. uplink_seid = pf->mac_seid;
  9201. if (pf->lan_vsi == I40E_NO_VSI)
  9202. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  9203. else if (reinit)
  9204. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  9205. if (!vsi) {
  9206. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  9207. i40e_fdir_teardown(pf);
  9208. return -EAGAIN;
  9209. }
  9210. } else {
  9211. /* force a reset of TC and queue layout configurations */
  9212. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  9213. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  9214. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  9215. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  9216. }
  9217. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  9218. i40e_fdir_sb_setup(pf);
  9219. /* Setup static PF queue filter control settings */
  9220. ret = i40e_setup_pf_filter_control(pf);
  9221. if (ret) {
  9222. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  9223. ret);
  9224. /* Failure here should not stop continuing other steps */
  9225. }
  9226. /* enable RSS in the HW, even for only one queue, as the stack can use
  9227. * the hash
  9228. */
  9229. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  9230. i40e_pf_config_rss(pf);
  9231. /* fill in link information and enable LSE reporting */
  9232. i40e_update_link_info(&pf->hw);
  9233. i40e_link_event(pf);
  9234. /* Initialize user-specific link properties */
  9235. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  9236. I40E_AQ_AN_COMPLETED) ? true : false);
  9237. i40e_ptp_init(pf);
  9238. return ret;
  9239. }
  9240. /**
  9241. * i40e_determine_queue_usage - Work out queue distribution
  9242. * @pf: board private structure
  9243. **/
  9244. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  9245. {
  9246. int queues_left;
  9247. pf->num_lan_qps = 0;
  9248. #ifdef I40E_FCOE
  9249. pf->num_fcoe_qps = 0;
  9250. #endif
  9251. /* Find the max queues to be put into basic use. We'll always be
  9252. * using TC0, whether or not DCB is running, and TC0 will get the
  9253. * big RSS set.
  9254. */
  9255. queues_left = pf->hw.func_caps.num_tx_qp;
  9256. if ((queues_left == 1) ||
  9257. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  9258. /* one qp for PF, no queues for anything else */
  9259. queues_left = 0;
  9260. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9261. /* make sure all the fancies are disabled */
  9262. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9263. I40E_FLAG_IWARP_ENABLED |
  9264. #ifdef I40E_FCOE
  9265. I40E_FLAG_FCOE_ENABLED |
  9266. #endif
  9267. I40E_FLAG_FD_SB_ENABLED |
  9268. I40E_FLAG_FD_ATR_ENABLED |
  9269. I40E_FLAG_DCB_CAPABLE |
  9270. I40E_FLAG_DCB_ENABLED |
  9271. I40E_FLAG_SRIOV_ENABLED |
  9272. I40E_FLAG_VMDQ_ENABLED);
  9273. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  9274. I40E_FLAG_FD_SB_ENABLED |
  9275. I40E_FLAG_FD_ATR_ENABLED |
  9276. I40E_FLAG_DCB_CAPABLE))) {
  9277. /* one qp for PF */
  9278. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9279. queues_left -= pf->num_lan_qps;
  9280. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9281. I40E_FLAG_IWARP_ENABLED |
  9282. #ifdef I40E_FCOE
  9283. I40E_FLAG_FCOE_ENABLED |
  9284. #endif
  9285. I40E_FLAG_FD_SB_ENABLED |
  9286. I40E_FLAG_FD_ATR_ENABLED |
  9287. I40E_FLAG_DCB_ENABLED |
  9288. I40E_FLAG_VMDQ_ENABLED);
  9289. } else {
  9290. /* Not enough queues for all TCs */
  9291. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  9292. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  9293. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  9294. I40E_FLAG_DCB_ENABLED);
  9295. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  9296. }
  9297. pf->num_lan_qps = max_t(int, pf->rss_size_max,
  9298. num_online_cpus());
  9299. pf->num_lan_qps = min_t(int, pf->num_lan_qps,
  9300. pf->hw.func_caps.num_tx_qp);
  9301. queues_left -= pf->num_lan_qps;
  9302. }
  9303. #ifdef I40E_FCOE
  9304. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  9305. if (I40E_DEFAULT_FCOE <= queues_left) {
  9306. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  9307. } else if (I40E_MINIMUM_FCOE <= queues_left) {
  9308. pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
  9309. } else {
  9310. pf->num_fcoe_qps = 0;
  9311. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  9312. dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
  9313. }
  9314. queues_left -= pf->num_fcoe_qps;
  9315. }
  9316. #endif
  9317. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9318. if (queues_left > 1) {
  9319. queues_left -= 1; /* save 1 queue for FD */
  9320. } else {
  9321. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9322. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  9323. }
  9324. }
  9325. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9326. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  9327. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  9328. (queues_left / pf->num_vf_qps));
  9329. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  9330. }
  9331. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9332. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  9333. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  9334. (queues_left / pf->num_vmdq_qps));
  9335. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  9336. }
  9337. pf->queues_left = queues_left;
  9338. dev_dbg(&pf->pdev->dev,
  9339. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  9340. pf->hw.func_caps.num_tx_qp,
  9341. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  9342. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  9343. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  9344. queues_left);
  9345. #ifdef I40E_FCOE
  9346. dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
  9347. #endif
  9348. }
  9349. /**
  9350. * i40e_setup_pf_filter_control - Setup PF static filter control
  9351. * @pf: PF to be setup
  9352. *
  9353. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  9354. * settings. If PE/FCoE are enabled then it will also set the per PF
  9355. * based filter sizes required for them. It also enables Flow director,
  9356. * ethertype and macvlan type filter settings for the pf.
  9357. *
  9358. * Returns 0 on success, negative on failure
  9359. **/
  9360. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  9361. {
  9362. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  9363. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  9364. /* Flow Director is enabled */
  9365. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  9366. settings->enable_fdir = true;
  9367. /* Ethtype and MACVLAN filters enabled for PF */
  9368. settings->enable_ethtype = true;
  9369. settings->enable_macvlan = true;
  9370. if (i40e_set_filter_control(&pf->hw, settings))
  9371. return -ENOENT;
  9372. return 0;
  9373. }
  9374. #define INFO_STRING_LEN 255
  9375. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  9376. static void i40e_print_features(struct i40e_pf *pf)
  9377. {
  9378. struct i40e_hw *hw = &pf->hw;
  9379. char *buf;
  9380. int i;
  9381. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  9382. if (!buf)
  9383. return;
  9384. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  9385. #ifdef CONFIG_PCI_IOV
  9386. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  9387. #endif
  9388. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  9389. pf->hw.func_caps.num_vsis,
  9390. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  9391. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  9392. i += snprintf(&buf[i], REMAIN(i), " RSS");
  9393. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  9394. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  9395. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9396. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  9397. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  9398. }
  9399. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  9400. i += snprintf(&buf[i], REMAIN(i), " DCB");
  9401. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  9402. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  9403. if (pf->flags & I40E_FLAG_PTP)
  9404. i += snprintf(&buf[i], REMAIN(i), " PTP");
  9405. #ifdef I40E_FCOE
  9406. if (pf->flags & I40E_FLAG_FCOE_ENABLED)
  9407. i += snprintf(&buf[i], REMAIN(i), " FCOE");
  9408. #endif
  9409. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  9410. i += snprintf(&buf[i], REMAIN(i), " VEB");
  9411. else
  9412. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  9413. dev_info(&pf->pdev->dev, "%s\n", buf);
  9414. kfree(buf);
  9415. WARN_ON(i > INFO_STRING_LEN);
  9416. }
  9417. /**
  9418. * i40e_get_platform_mac_addr - get platform-specific MAC address
  9419. *
  9420. * @pdev: PCI device information struct
  9421. * @pf: board private structure
  9422. *
  9423. * Look up the MAC address in Open Firmware on systems that support it,
  9424. * and use IDPROM on SPARC if no OF address is found. On return, the
  9425. * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
  9426. * has been selected.
  9427. **/
  9428. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  9429. {
  9430. pf->flags &= ~I40E_FLAG_PF_MAC;
  9431. if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  9432. pf->flags |= I40E_FLAG_PF_MAC;
  9433. }
  9434. /**
  9435. * i40e_probe - Device initialization routine
  9436. * @pdev: PCI device information struct
  9437. * @ent: entry in i40e_pci_tbl
  9438. *
  9439. * i40e_probe initializes a PF identified by a pci_dev structure.
  9440. * The OS initialization, configuring of the PF private structure,
  9441. * and a hardware reset occur.
  9442. *
  9443. * Returns 0 on success, negative on failure
  9444. **/
  9445. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9446. {
  9447. struct i40e_aq_get_phy_abilities_resp abilities;
  9448. struct i40e_pf *pf;
  9449. struct i40e_hw *hw;
  9450. static u16 pfs_found;
  9451. u16 wol_nvm_bits;
  9452. u16 link_status;
  9453. int err;
  9454. u32 val;
  9455. u32 i;
  9456. u8 set_fc_aq_fail;
  9457. err = pci_enable_device_mem(pdev);
  9458. if (err)
  9459. return err;
  9460. /* set up for high or low dma */
  9461. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  9462. if (err) {
  9463. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  9464. if (err) {
  9465. dev_err(&pdev->dev,
  9466. "DMA configuration failed: 0x%x\n", err);
  9467. goto err_dma;
  9468. }
  9469. }
  9470. /* set up pci connections */
  9471. err = pci_request_mem_regions(pdev, i40e_driver_name);
  9472. if (err) {
  9473. dev_info(&pdev->dev,
  9474. "pci_request_selected_regions failed %d\n", err);
  9475. goto err_pci_reg;
  9476. }
  9477. pci_enable_pcie_error_reporting(pdev);
  9478. pci_set_master(pdev);
  9479. /* Now that we have a PCI connection, we need to do the
  9480. * low level device setup. This is primarily setting up
  9481. * the Admin Queue structures and then querying for the
  9482. * device's current profile information.
  9483. */
  9484. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  9485. if (!pf) {
  9486. err = -ENOMEM;
  9487. goto err_pf_alloc;
  9488. }
  9489. pf->next_vsi = 0;
  9490. pf->pdev = pdev;
  9491. set_bit(__I40E_DOWN, &pf->state);
  9492. hw = &pf->hw;
  9493. hw->back = pf;
  9494. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  9495. I40E_MAX_CSR_SPACE);
  9496. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  9497. if (!hw->hw_addr) {
  9498. err = -EIO;
  9499. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  9500. (unsigned int)pci_resource_start(pdev, 0),
  9501. pf->ioremap_len, err);
  9502. goto err_ioremap;
  9503. }
  9504. hw->vendor_id = pdev->vendor;
  9505. hw->device_id = pdev->device;
  9506. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  9507. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  9508. hw->subsystem_device_id = pdev->subsystem_device;
  9509. hw->bus.device = PCI_SLOT(pdev->devfn);
  9510. hw->bus.func = PCI_FUNC(pdev->devfn);
  9511. pf->instance = pfs_found;
  9512. /* set up the locks for the AQ, do this only once in probe
  9513. * and destroy them only once in remove
  9514. */
  9515. mutex_init(&hw->aq.asq_mutex);
  9516. mutex_init(&hw->aq.arq_mutex);
  9517. if (debug != -1) {
  9518. pf->msg_enable = pf->hw.debug_mask;
  9519. pf->msg_enable = debug;
  9520. }
  9521. /* do a special CORER for clearing PXE mode once at init */
  9522. if (hw->revision_id == 0 &&
  9523. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  9524. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  9525. i40e_flush(hw);
  9526. msleep(200);
  9527. pf->corer_count++;
  9528. i40e_clear_pxe_mode(hw);
  9529. }
  9530. /* Reset here to make sure all is clean and to define PF 'n' */
  9531. i40e_clear_hw(hw);
  9532. err = i40e_pf_reset(hw);
  9533. if (err) {
  9534. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  9535. goto err_pf_reset;
  9536. }
  9537. pf->pfr_count++;
  9538. hw->aq.num_arq_entries = I40E_AQ_LEN;
  9539. hw->aq.num_asq_entries = I40E_AQ_LEN;
  9540. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9541. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9542. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  9543. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  9544. "%s-%s:misc",
  9545. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  9546. err = i40e_init_shared_code(hw);
  9547. if (err) {
  9548. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  9549. err);
  9550. goto err_pf_reset;
  9551. }
  9552. /* set up a default setting for link flow control */
  9553. pf->hw.fc.requested_mode = I40E_FC_NONE;
  9554. err = i40e_init_adminq(hw);
  9555. if (err) {
  9556. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  9557. dev_info(&pdev->dev,
  9558. "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");
  9559. else
  9560. dev_info(&pdev->dev,
  9561. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  9562. goto err_pf_reset;
  9563. }
  9564. /* provide nvm, fw, api versions */
  9565. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  9566. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  9567. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  9568. i40e_nvm_version_str(hw));
  9569. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  9570. hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
  9571. dev_info(&pdev->dev,
  9572. "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");
  9573. else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
  9574. hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
  9575. dev_info(&pdev->dev,
  9576. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  9577. i40e_verify_eeprom(pf);
  9578. /* Rev 0 hardware was never productized */
  9579. if (hw->revision_id < 1)
  9580. 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");
  9581. i40e_clear_pxe_mode(hw);
  9582. err = i40e_get_capabilities(pf);
  9583. if (err)
  9584. goto err_adminq_setup;
  9585. err = i40e_sw_init(pf);
  9586. if (err) {
  9587. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  9588. goto err_sw_init;
  9589. }
  9590. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  9591. hw->func_caps.num_rx_qp,
  9592. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  9593. if (err) {
  9594. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  9595. goto err_init_lan_hmc;
  9596. }
  9597. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  9598. if (err) {
  9599. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  9600. err = -ENOENT;
  9601. goto err_configure_lan_hmc;
  9602. }
  9603. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  9604. * Ignore error return codes because if it was already disabled via
  9605. * hardware settings this will fail
  9606. */
  9607. if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
  9608. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  9609. i40e_aq_stop_lldp(hw, true, NULL);
  9610. }
  9611. i40e_get_mac_addr(hw, hw->mac.addr);
  9612. /* allow a platform config to override the HW addr */
  9613. i40e_get_platform_mac_addr(pdev, pf);
  9614. if (!is_valid_ether_addr(hw->mac.addr)) {
  9615. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  9616. err = -EIO;
  9617. goto err_mac_addr;
  9618. }
  9619. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  9620. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  9621. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  9622. if (is_valid_ether_addr(hw->mac.port_addr))
  9623. pf->flags |= I40E_FLAG_PORT_ID_VALID;
  9624. #ifdef I40E_FCOE
  9625. err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
  9626. if (err)
  9627. dev_info(&pdev->dev,
  9628. "(non-fatal) SAN MAC retrieval failed: %d\n", err);
  9629. if (!is_valid_ether_addr(hw->mac.san_addr)) {
  9630. dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
  9631. hw->mac.san_addr);
  9632. ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
  9633. }
  9634. dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
  9635. #endif /* I40E_FCOE */
  9636. pci_set_drvdata(pdev, pf);
  9637. pci_save_state(pdev);
  9638. #ifdef CONFIG_I40E_DCB
  9639. err = i40e_init_pf_dcb(pf);
  9640. if (err) {
  9641. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  9642. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE & I40E_FLAG_DCB_ENABLED);
  9643. /* Continue without DCB enabled */
  9644. }
  9645. #endif /* CONFIG_I40E_DCB */
  9646. /* set up periodic task facility */
  9647. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  9648. pf->service_timer_period = HZ;
  9649. INIT_WORK(&pf->service_task, i40e_service_task);
  9650. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  9651. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  9652. /* NVM bit on means WoL disabled for the port */
  9653. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  9654. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  9655. pf->wol_en = false;
  9656. else
  9657. pf->wol_en = true;
  9658. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  9659. /* set up the main switch operations */
  9660. i40e_determine_queue_usage(pf);
  9661. err = i40e_init_interrupt_scheme(pf);
  9662. if (err)
  9663. goto err_switch_setup;
  9664. /* The number of VSIs reported by the FW is the minimum guaranteed
  9665. * to us; HW supports far more and we share the remaining pool with
  9666. * the other PFs. We allocate space for more than the guarantee with
  9667. * the understanding that we might not get them all later.
  9668. */
  9669. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  9670. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  9671. else
  9672. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  9673. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  9674. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  9675. GFP_KERNEL);
  9676. if (!pf->vsi) {
  9677. err = -ENOMEM;
  9678. goto err_switch_setup;
  9679. }
  9680. #ifdef CONFIG_PCI_IOV
  9681. /* prep for VF support */
  9682. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9683. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9684. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9685. if (pci_num_vf(pdev))
  9686. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  9687. }
  9688. #endif
  9689. err = i40e_setup_pf_switch(pf, false);
  9690. if (err) {
  9691. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  9692. goto err_vsis;
  9693. }
  9694. /* Make sure flow control is set according to current settings */
  9695. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  9696. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  9697. dev_dbg(&pf->pdev->dev,
  9698. "Set fc with err %s aq_err %s on get_phy_cap\n",
  9699. i40e_stat_str(hw, err),
  9700. i40e_aq_str(hw, hw->aq.asq_last_status));
  9701. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  9702. dev_dbg(&pf->pdev->dev,
  9703. "Set fc with err %s aq_err %s on set_phy_config\n",
  9704. i40e_stat_str(hw, err),
  9705. i40e_aq_str(hw, hw->aq.asq_last_status));
  9706. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  9707. dev_dbg(&pf->pdev->dev,
  9708. "Set fc with err %s aq_err %s on get_link_info\n",
  9709. i40e_stat_str(hw, err),
  9710. i40e_aq_str(hw, hw->aq.asq_last_status));
  9711. /* if FDIR VSI was set up, start it now */
  9712. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9713. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  9714. i40e_vsi_open(pf->vsi[i]);
  9715. break;
  9716. }
  9717. }
  9718. /* The driver only wants link up/down and module qualification
  9719. * reports from firmware. Note the negative logic.
  9720. */
  9721. err = i40e_aq_set_phy_int_mask(&pf->hw,
  9722. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  9723. I40E_AQ_EVENT_MEDIA_NA |
  9724. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  9725. if (err)
  9726. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  9727. i40e_stat_str(&pf->hw, err),
  9728. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9729. /* Reconfigure hardware for allowing smaller MSS in the case
  9730. * of TSO, so that we avoid the MDD being fired and causing
  9731. * a reset in the case of small MSS+TSO.
  9732. */
  9733. val = rd32(hw, I40E_REG_MSS);
  9734. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  9735. val &= ~I40E_REG_MSS_MIN_MASK;
  9736. val |= I40E_64BYTE_MSS;
  9737. wr32(hw, I40E_REG_MSS, val);
  9738. }
  9739. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  9740. msleep(75);
  9741. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  9742. if (err)
  9743. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  9744. i40e_stat_str(&pf->hw, err),
  9745. i40e_aq_str(&pf->hw,
  9746. pf->hw.aq.asq_last_status));
  9747. }
  9748. /* The main driver is (mostly) up and happy. We need to set this state
  9749. * before setting up the misc vector or we get a race and the vector
  9750. * ends up disabled forever.
  9751. */
  9752. clear_bit(__I40E_DOWN, &pf->state);
  9753. /* In case of MSIX we are going to setup the misc vector right here
  9754. * to handle admin queue events etc. In case of legacy and MSI
  9755. * the misc functionality and queue processing is combined in
  9756. * the same vector and that gets setup at open.
  9757. */
  9758. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9759. err = i40e_setup_misc_vector(pf);
  9760. if (err) {
  9761. dev_info(&pdev->dev,
  9762. "setup of misc vector failed: %d\n", err);
  9763. goto err_vsis;
  9764. }
  9765. }
  9766. #ifdef CONFIG_PCI_IOV
  9767. /* prep for VF support */
  9768. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9769. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9770. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9771. /* disable link interrupts for VFs */
  9772. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  9773. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  9774. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  9775. i40e_flush(hw);
  9776. if (pci_num_vf(pdev)) {
  9777. dev_info(&pdev->dev,
  9778. "Active VFs found, allocating resources.\n");
  9779. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  9780. if (err)
  9781. dev_info(&pdev->dev,
  9782. "Error %d allocating resources for existing VFs\n",
  9783. err);
  9784. }
  9785. }
  9786. #endif /* CONFIG_PCI_IOV */
  9787. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9788. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  9789. pf->num_iwarp_msix,
  9790. I40E_IWARP_IRQ_PILE_ID);
  9791. if (pf->iwarp_base_vector < 0) {
  9792. dev_info(&pdev->dev,
  9793. "failed to get tracking for %d vectors for IWARP err=%d\n",
  9794. pf->num_iwarp_msix, pf->iwarp_base_vector);
  9795. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9796. }
  9797. }
  9798. i40e_dbg_pf_init(pf);
  9799. /* tell the firmware that we're starting */
  9800. i40e_send_version(pf);
  9801. /* since everything's happy, start the service_task timer */
  9802. mod_timer(&pf->service_timer,
  9803. round_jiffies(jiffies + pf->service_timer_period));
  9804. /* add this PF to client device list and launch a client service task */
  9805. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9806. err = i40e_lan_add_device(pf);
  9807. if (err)
  9808. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  9809. err);
  9810. }
  9811. #ifdef I40E_FCOE
  9812. /* create FCoE interface */
  9813. i40e_fcoe_vsi_setup(pf);
  9814. #endif
  9815. #define PCI_SPEED_SIZE 8
  9816. #define PCI_WIDTH_SIZE 8
  9817. /* Devices on the IOSF bus do not have this information
  9818. * and will report PCI Gen 1 x 1 by default so don't bother
  9819. * checking them.
  9820. */
  9821. if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
  9822. char speed[PCI_SPEED_SIZE] = "Unknown";
  9823. char width[PCI_WIDTH_SIZE] = "Unknown";
  9824. /* Get the negotiated link width and speed from PCI config
  9825. * space
  9826. */
  9827. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  9828. &link_status);
  9829. i40e_set_pci_config_data(hw, link_status);
  9830. switch (hw->bus.speed) {
  9831. case i40e_bus_speed_8000:
  9832. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  9833. case i40e_bus_speed_5000:
  9834. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  9835. case i40e_bus_speed_2500:
  9836. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  9837. default:
  9838. break;
  9839. }
  9840. switch (hw->bus.width) {
  9841. case i40e_bus_width_pcie_x8:
  9842. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  9843. case i40e_bus_width_pcie_x4:
  9844. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  9845. case i40e_bus_width_pcie_x2:
  9846. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  9847. case i40e_bus_width_pcie_x1:
  9848. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  9849. default:
  9850. break;
  9851. }
  9852. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  9853. speed, width);
  9854. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  9855. hw->bus.speed < i40e_bus_speed_8000) {
  9856. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  9857. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  9858. }
  9859. }
  9860. /* get the requested speeds from the fw */
  9861. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  9862. if (err)
  9863. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  9864. i40e_stat_str(&pf->hw, err),
  9865. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9866. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  9867. /* get the supported phy types from the fw */
  9868. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  9869. if (err)
  9870. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  9871. i40e_stat_str(&pf->hw, err),
  9872. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9873. pf->hw.phy.phy_types = le32_to_cpu(abilities.phy_type);
  9874. /* Add a filter to drop all Flow control frames from any VSI from being
  9875. * transmitted. By doing so we stop a malicious VF from sending out
  9876. * PAUSE or PFC frames and potentially controlling traffic for other
  9877. * PF/VF VSIs.
  9878. * The FW can still send Flow control frames if enabled.
  9879. */
  9880. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  9881. pf->main_vsi_seid);
  9882. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  9883. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  9884. pf->flags |= I40E_FLAG_HAVE_10GBASET_PHY;
  9885. /* print a string summarizing features */
  9886. i40e_print_features(pf);
  9887. return 0;
  9888. /* Unwind what we've done if something failed in the setup */
  9889. err_vsis:
  9890. set_bit(__I40E_DOWN, &pf->state);
  9891. i40e_clear_interrupt_scheme(pf);
  9892. kfree(pf->vsi);
  9893. err_switch_setup:
  9894. i40e_reset_interrupt_capability(pf);
  9895. del_timer_sync(&pf->service_timer);
  9896. err_mac_addr:
  9897. err_configure_lan_hmc:
  9898. (void)i40e_shutdown_lan_hmc(hw);
  9899. err_init_lan_hmc:
  9900. kfree(pf->qp_pile);
  9901. err_sw_init:
  9902. err_adminq_setup:
  9903. err_pf_reset:
  9904. iounmap(hw->hw_addr);
  9905. err_ioremap:
  9906. kfree(pf);
  9907. err_pf_alloc:
  9908. pci_disable_pcie_error_reporting(pdev);
  9909. pci_release_mem_regions(pdev);
  9910. err_pci_reg:
  9911. err_dma:
  9912. pci_disable_device(pdev);
  9913. return err;
  9914. }
  9915. /**
  9916. * i40e_remove - Device removal routine
  9917. * @pdev: PCI device information struct
  9918. *
  9919. * i40e_remove is called by the PCI subsystem to alert the driver
  9920. * that is should release a PCI device. This could be caused by a
  9921. * Hot-Plug event, or because the driver is going to be removed from
  9922. * memory.
  9923. **/
  9924. static void i40e_remove(struct pci_dev *pdev)
  9925. {
  9926. struct i40e_pf *pf = pci_get_drvdata(pdev);
  9927. struct i40e_hw *hw = &pf->hw;
  9928. i40e_status ret_code;
  9929. int i;
  9930. i40e_dbg_pf_exit(pf);
  9931. i40e_ptp_stop(pf);
  9932. /* Disable RSS in hw */
  9933. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  9934. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  9935. /* no more scheduling of any task */
  9936. set_bit(__I40E_SUSPENDED, &pf->state);
  9937. set_bit(__I40E_DOWN, &pf->state);
  9938. if (pf->service_timer.data)
  9939. del_timer_sync(&pf->service_timer);
  9940. if (pf->service_task.func)
  9941. cancel_work_sync(&pf->service_task);
  9942. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  9943. i40e_free_vfs(pf);
  9944. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  9945. }
  9946. i40e_fdir_teardown(pf);
  9947. /* If there is a switch structure or any orphans, remove them.
  9948. * This will leave only the PF's VSI remaining.
  9949. */
  9950. for (i = 0; i < I40E_MAX_VEB; i++) {
  9951. if (!pf->veb[i])
  9952. continue;
  9953. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  9954. pf->veb[i]->uplink_seid == 0)
  9955. i40e_switch_branch_release(pf->veb[i]);
  9956. }
  9957. /* Now we can shutdown the PF's VSI, just before we kill
  9958. * adminq and hmc.
  9959. */
  9960. if (pf->vsi[pf->lan_vsi])
  9961. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  9962. /* remove attached clients */
  9963. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9964. ret_code = i40e_lan_del_device(pf);
  9965. if (ret_code)
  9966. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  9967. ret_code);
  9968. }
  9969. /* shutdown and destroy the HMC */
  9970. if (hw->hmc.hmc_obj) {
  9971. ret_code = i40e_shutdown_lan_hmc(hw);
  9972. if (ret_code)
  9973. dev_warn(&pdev->dev,
  9974. "Failed to destroy the HMC resources: %d\n",
  9975. ret_code);
  9976. }
  9977. /* shutdown the adminq */
  9978. i40e_shutdown_adminq(hw);
  9979. /* destroy the locks only once, here */
  9980. mutex_destroy(&hw->aq.arq_mutex);
  9981. mutex_destroy(&hw->aq.asq_mutex);
  9982. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  9983. i40e_clear_interrupt_scheme(pf);
  9984. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9985. if (pf->vsi[i]) {
  9986. i40e_vsi_clear_rings(pf->vsi[i]);
  9987. i40e_vsi_clear(pf->vsi[i]);
  9988. pf->vsi[i] = NULL;
  9989. }
  9990. }
  9991. for (i = 0; i < I40E_MAX_VEB; i++) {
  9992. kfree(pf->veb[i]);
  9993. pf->veb[i] = NULL;
  9994. }
  9995. kfree(pf->qp_pile);
  9996. kfree(pf->vsi);
  9997. iounmap(hw->hw_addr);
  9998. kfree(pf);
  9999. pci_release_mem_regions(pdev);
  10000. pci_disable_pcie_error_reporting(pdev);
  10001. pci_disable_device(pdev);
  10002. }
  10003. /**
  10004. * i40e_pci_error_detected - warning that something funky happened in PCI land
  10005. * @pdev: PCI device information struct
  10006. *
  10007. * Called to warn that something happened and the error handling steps
  10008. * are in progress. Allows the driver to quiesce things, be ready for
  10009. * remediation.
  10010. **/
  10011. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  10012. enum pci_channel_state error)
  10013. {
  10014. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10015. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  10016. if (!pf) {
  10017. dev_info(&pdev->dev,
  10018. "Cannot recover - error happened during device probe\n");
  10019. return PCI_ERS_RESULT_DISCONNECT;
  10020. }
  10021. /* shutdown all operations */
  10022. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  10023. rtnl_lock();
  10024. i40e_prep_for_reset(pf);
  10025. rtnl_unlock();
  10026. }
  10027. /* Request a slot reset */
  10028. return PCI_ERS_RESULT_NEED_RESET;
  10029. }
  10030. /**
  10031. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  10032. * @pdev: PCI device information struct
  10033. *
  10034. * Called to find if the driver can work with the device now that
  10035. * the pci slot has been reset. If a basic connection seems good
  10036. * (registers are readable and have sane content) then return a
  10037. * happy little PCI_ERS_RESULT_xxx.
  10038. **/
  10039. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  10040. {
  10041. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10042. pci_ers_result_t result;
  10043. int err;
  10044. u32 reg;
  10045. dev_dbg(&pdev->dev, "%s\n", __func__);
  10046. if (pci_enable_device_mem(pdev)) {
  10047. dev_info(&pdev->dev,
  10048. "Cannot re-enable PCI device after reset.\n");
  10049. result = PCI_ERS_RESULT_DISCONNECT;
  10050. } else {
  10051. pci_set_master(pdev);
  10052. pci_restore_state(pdev);
  10053. pci_save_state(pdev);
  10054. pci_wake_from_d3(pdev, false);
  10055. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  10056. if (reg == 0)
  10057. result = PCI_ERS_RESULT_RECOVERED;
  10058. else
  10059. result = PCI_ERS_RESULT_DISCONNECT;
  10060. }
  10061. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  10062. if (err) {
  10063. dev_info(&pdev->dev,
  10064. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  10065. err);
  10066. /* non-fatal, continue */
  10067. }
  10068. return result;
  10069. }
  10070. /**
  10071. * i40e_pci_error_resume - restart operations after PCI error recovery
  10072. * @pdev: PCI device information struct
  10073. *
  10074. * Called to allow the driver to bring things back up after PCI error
  10075. * and/or reset recovery has finished.
  10076. **/
  10077. static void i40e_pci_error_resume(struct pci_dev *pdev)
  10078. {
  10079. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10080. dev_dbg(&pdev->dev, "%s\n", __func__);
  10081. if (test_bit(__I40E_SUSPENDED, &pf->state))
  10082. return;
  10083. rtnl_lock();
  10084. i40e_handle_reset_warning(pf);
  10085. rtnl_unlock();
  10086. }
  10087. /**
  10088. * i40e_shutdown - PCI callback for shutting down
  10089. * @pdev: PCI device information struct
  10090. **/
  10091. static void i40e_shutdown(struct pci_dev *pdev)
  10092. {
  10093. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10094. struct i40e_hw *hw = &pf->hw;
  10095. set_bit(__I40E_SUSPENDED, &pf->state);
  10096. set_bit(__I40E_DOWN, &pf->state);
  10097. rtnl_lock();
  10098. i40e_prep_for_reset(pf);
  10099. rtnl_unlock();
  10100. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10101. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10102. del_timer_sync(&pf->service_timer);
  10103. cancel_work_sync(&pf->service_task);
  10104. i40e_fdir_teardown(pf);
  10105. rtnl_lock();
  10106. i40e_prep_for_reset(pf);
  10107. rtnl_unlock();
  10108. wr32(hw, I40E_PFPM_APM,
  10109. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10110. wr32(hw, I40E_PFPM_WUFC,
  10111. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10112. i40e_clear_interrupt_scheme(pf);
  10113. if (system_state == SYSTEM_POWER_OFF) {
  10114. pci_wake_from_d3(pdev, pf->wol_en);
  10115. pci_set_power_state(pdev, PCI_D3hot);
  10116. }
  10117. }
  10118. #ifdef CONFIG_PM
  10119. /**
  10120. * i40e_suspend - PCI callback for moving to D3
  10121. * @pdev: PCI device information struct
  10122. **/
  10123. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  10124. {
  10125. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10126. struct i40e_hw *hw = &pf->hw;
  10127. int retval = 0;
  10128. set_bit(__I40E_SUSPENDED, &pf->state);
  10129. set_bit(__I40E_DOWN, &pf->state);
  10130. rtnl_lock();
  10131. i40e_prep_for_reset(pf);
  10132. rtnl_unlock();
  10133. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10134. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10135. i40e_stop_misc_vector(pf);
  10136. retval = pci_save_state(pdev);
  10137. if (retval)
  10138. return retval;
  10139. pci_wake_from_d3(pdev, pf->wol_en);
  10140. pci_set_power_state(pdev, PCI_D3hot);
  10141. return retval;
  10142. }
  10143. /**
  10144. * i40e_resume - PCI callback for waking up from D3
  10145. * @pdev: PCI device information struct
  10146. **/
  10147. static int i40e_resume(struct pci_dev *pdev)
  10148. {
  10149. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10150. u32 err;
  10151. pci_set_power_state(pdev, PCI_D0);
  10152. pci_restore_state(pdev);
  10153. /* pci_restore_state() clears dev->state_saves, so
  10154. * call pci_save_state() again to restore it.
  10155. */
  10156. pci_save_state(pdev);
  10157. err = pci_enable_device_mem(pdev);
  10158. if (err) {
  10159. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  10160. return err;
  10161. }
  10162. pci_set_master(pdev);
  10163. /* no wakeup events while running */
  10164. pci_wake_from_d3(pdev, false);
  10165. /* handling the reset will rebuild the device state */
  10166. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  10167. clear_bit(__I40E_DOWN, &pf->state);
  10168. rtnl_lock();
  10169. i40e_reset_and_rebuild(pf, false);
  10170. rtnl_unlock();
  10171. }
  10172. return 0;
  10173. }
  10174. #endif
  10175. static const struct pci_error_handlers i40e_err_handler = {
  10176. .error_detected = i40e_pci_error_detected,
  10177. .slot_reset = i40e_pci_error_slot_reset,
  10178. .resume = i40e_pci_error_resume,
  10179. };
  10180. static struct pci_driver i40e_driver = {
  10181. .name = i40e_driver_name,
  10182. .id_table = i40e_pci_tbl,
  10183. .probe = i40e_probe,
  10184. .remove = i40e_remove,
  10185. #ifdef CONFIG_PM
  10186. .suspend = i40e_suspend,
  10187. .resume = i40e_resume,
  10188. #endif
  10189. .shutdown = i40e_shutdown,
  10190. .err_handler = &i40e_err_handler,
  10191. .sriov_configure = i40e_pci_sriov_configure,
  10192. };
  10193. /**
  10194. * i40e_init_module - Driver registration routine
  10195. *
  10196. * i40e_init_module is the first routine called when the driver is
  10197. * loaded. All it does is register with the PCI subsystem.
  10198. **/
  10199. static int __init i40e_init_module(void)
  10200. {
  10201. pr_info("%s: %s - version %s\n", i40e_driver_name,
  10202. i40e_driver_string, i40e_driver_version_str);
  10203. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  10204. /* we will see if single thread per module is enough for now,
  10205. * it can't be any worse than using the system workqueue which
  10206. * was already single threaded
  10207. */
  10208. i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  10209. i40e_driver_name);
  10210. if (!i40e_wq) {
  10211. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  10212. return -ENOMEM;
  10213. }
  10214. i40e_dbg_init();
  10215. return pci_register_driver(&i40e_driver);
  10216. }
  10217. module_init(i40e_init_module);
  10218. /**
  10219. * i40e_exit_module - Driver exit cleanup routine
  10220. *
  10221. * i40e_exit_module is called just before the driver is removed
  10222. * from memory.
  10223. **/
  10224. static void __exit i40e_exit_module(void)
  10225. {
  10226. pci_unregister_driver(&i40e_driver);
  10227. destroy_workqueue(i40e_wq);
  10228. i40e_dbg_exit();
  10229. }
  10230. module_exit(i40e_exit_module);