i40e_main.c 326 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831
  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 25
  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. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  83. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  84. /* required last entry */
  85. {0, }
  86. };
  87. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  88. #define I40E_MAX_VF_COUNT 128
  89. static int debug = -1;
  90. module_param(debug, uint, 0);
  91. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  92. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  93. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  94. MODULE_LICENSE("GPL");
  95. MODULE_VERSION(DRV_VERSION);
  96. static struct workqueue_struct *i40e_wq;
  97. /**
  98. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  99. * @hw: pointer to the HW structure
  100. * @mem: ptr to mem struct to fill out
  101. * @size: size of memory requested
  102. * @alignment: what to align the allocation to
  103. **/
  104. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  105. u64 size, u32 alignment)
  106. {
  107. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  108. mem->size = ALIGN(size, alignment);
  109. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  110. &mem->pa, GFP_KERNEL);
  111. if (!mem->va)
  112. return -ENOMEM;
  113. return 0;
  114. }
  115. /**
  116. * i40e_free_dma_mem_d - OS specific memory free for shared code
  117. * @hw: pointer to the HW structure
  118. * @mem: ptr to mem struct to free
  119. **/
  120. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  121. {
  122. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  123. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  124. mem->va = NULL;
  125. mem->pa = 0;
  126. mem->size = 0;
  127. return 0;
  128. }
  129. /**
  130. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  131. * @hw: pointer to the HW structure
  132. * @mem: ptr to mem struct to fill out
  133. * @size: size of memory requested
  134. **/
  135. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  136. u32 size)
  137. {
  138. mem->size = size;
  139. mem->va = kzalloc(size, GFP_KERNEL);
  140. if (!mem->va)
  141. return -ENOMEM;
  142. return 0;
  143. }
  144. /**
  145. * i40e_free_virt_mem_d - OS specific memory free for shared code
  146. * @hw: pointer to the HW structure
  147. * @mem: ptr to mem struct to free
  148. **/
  149. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  150. {
  151. /* it's ok to kfree a NULL pointer */
  152. kfree(mem->va);
  153. mem->va = NULL;
  154. mem->size = 0;
  155. return 0;
  156. }
  157. /**
  158. * i40e_get_lump - find a lump of free generic resource
  159. * @pf: board private structure
  160. * @pile: the pile of resource to search
  161. * @needed: the number of items needed
  162. * @id: an owner id to stick on the items assigned
  163. *
  164. * Returns the base item index of the lump, or negative for error
  165. *
  166. * The search_hint trick and lack of advanced fit-finding only work
  167. * because we're highly likely to have all the same size lump requests.
  168. * Linear search time and any fragmentation should be minimal.
  169. **/
  170. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  171. u16 needed, u16 id)
  172. {
  173. int ret = -ENOMEM;
  174. int i, j;
  175. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  176. dev_info(&pf->pdev->dev,
  177. "param err: pile=%p needed=%d id=0x%04x\n",
  178. pile, needed, id);
  179. return -EINVAL;
  180. }
  181. /* start the linear search with an imperfect hint */
  182. i = pile->search_hint;
  183. while (i < pile->num_entries) {
  184. /* skip already allocated entries */
  185. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  186. i++;
  187. continue;
  188. }
  189. /* do we have enough in this lump? */
  190. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  191. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  192. break;
  193. }
  194. if (j == needed) {
  195. /* there was enough, so assign it to the requestor */
  196. for (j = 0; j < needed; j++)
  197. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  198. ret = i;
  199. pile->search_hint = i + j;
  200. break;
  201. }
  202. /* not enough, so skip over it and continue looking */
  203. i += j;
  204. }
  205. return ret;
  206. }
  207. /**
  208. * i40e_put_lump - return a lump of generic resource
  209. * @pile: the pile of resource to search
  210. * @index: the base item index
  211. * @id: the owner id of the items assigned
  212. *
  213. * Returns the count of items in the lump
  214. **/
  215. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  216. {
  217. int valid_id = (id | I40E_PILE_VALID_BIT);
  218. int count = 0;
  219. int i;
  220. if (!pile || index >= pile->num_entries)
  221. return -EINVAL;
  222. for (i = index;
  223. i < pile->num_entries && pile->list[i] == valid_id;
  224. i++) {
  225. pile->list[i] = 0;
  226. count++;
  227. }
  228. if (count && index < pile->search_hint)
  229. pile->search_hint = index;
  230. return count;
  231. }
  232. /**
  233. * i40e_find_vsi_from_id - searches for the vsi with the given id
  234. * @pf - the pf structure to search for the vsi
  235. * @id - id of the vsi it is searching for
  236. **/
  237. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  238. {
  239. int i;
  240. for (i = 0; i < pf->num_alloc_vsi; i++)
  241. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  242. return pf->vsi[i];
  243. return NULL;
  244. }
  245. /**
  246. * i40e_service_event_schedule - Schedule the service task to wake up
  247. * @pf: board private structure
  248. *
  249. * If not already scheduled, this puts the task into the work queue
  250. **/
  251. void i40e_service_event_schedule(struct i40e_pf *pf)
  252. {
  253. if (!test_bit(__I40E_DOWN, &pf->state) &&
  254. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  255. queue_work(i40e_wq, &pf->service_task);
  256. }
  257. /**
  258. * i40e_tx_timeout - Respond to a Tx Hang
  259. * @netdev: network interface device structure
  260. *
  261. * If any port has noticed a Tx timeout, it is likely that the whole
  262. * device is munged, not just the one netdev port, so go for the full
  263. * reset.
  264. **/
  265. #ifdef I40E_FCOE
  266. void i40e_tx_timeout(struct net_device *netdev)
  267. #else
  268. static void i40e_tx_timeout(struct net_device *netdev)
  269. #endif
  270. {
  271. struct i40e_netdev_priv *np = netdev_priv(netdev);
  272. struct i40e_vsi *vsi = np->vsi;
  273. struct i40e_pf *pf = vsi->back;
  274. struct i40e_ring *tx_ring = NULL;
  275. unsigned int i, hung_queue = 0;
  276. u32 head, val;
  277. pf->tx_timeout_count++;
  278. /* find the stopped queue the same way the stack does */
  279. for (i = 0; i < netdev->num_tx_queues; i++) {
  280. struct netdev_queue *q;
  281. unsigned long trans_start;
  282. q = netdev_get_tx_queue(netdev, i);
  283. trans_start = q->trans_start;
  284. if (netif_xmit_stopped(q) &&
  285. time_after(jiffies,
  286. (trans_start + netdev->watchdog_timeo))) {
  287. hung_queue = i;
  288. break;
  289. }
  290. }
  291. if (i == netdev->num_tx_queues) {
  292. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  293. } else {
  294. /* now that we have an index, find the tx_ring struct */
  295. for (i = 0; i < vsi->num_queue_pairs; i++) {
  296. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  297. if (hung_queue ==
  298. vsi->tx_rings[i]->queue_index) {
  299. tx_ring = vsi->tx_rings[i];
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  306. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  307. else if (time_before(jiffies,
  308. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  309. return; /* don't do any new action before the next timeout */
  310. if (tx_ring) {
  311. head = i40e_get_head(tx_ring);
  312. /* Read interrupt register */
  313. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  314. val = rd32(&pf->hw,
  315. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  316. tx_ring->vsi->base_vector - 1));
  317. else
  318. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  319. 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",
  320. vsi->seid, hung_queue, tx_ring->next_to_clean,
  321. head, tx_ring->next_to_use,
  322. readl(tx_ring->tail), val);
  323. }
  324. pf->tx_timeout_last_recovery = jiffies;
  325. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  326. pf->tx_timeout_recovery_level, hung_queue);
  327. switch (pf->tx_timeout_recovery_level) {
  328. case 1:
  329. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  330. break;
  331. case 2:
  332. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  333. break;
  334. case 3:
  335. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  336. break;
  337. default:
  338. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  339. break;
  340. }
  341. i40e_service_event_schedule(pf);
  342. pf->tx_timeout_recovery_level++;
  343. }
  344. /**
  345. * i40e_get_vsi_stats_struct - Get System Network Statistics
  346. * @vsi: the VSI we care about
  347. *
  348. * Returns the address of the device statistics structure.
  349. * The statistics are actually updated from the service task.
  350. **/
  351. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  352. {
  353. return &vsi->net_stats;
  354. }
  355. /**
  356. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  357. * @netdev: network interface device structure
  358. *
  359. * Returns the address of the device statistics structure.
  360. * The statistics are actually updated from the service task.
  361. **/
  362. #ifdef I40E_FCOE
  363. struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  364. struct net_device *netdev,
  365. struct rtnl_link_stats64 *stats)
  366. #else
  367. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  368. struct net_device *netdev,
  369. struct rtnl_link_stats64 *stats)
  370. #endif
  371. {
  372. struct i40e_netdev_priv *np = netdev_priv(netdev);
  373. struct i40e_ring *tx_ring, *rx_ring;
  374. struct i40e_vsi *vsi = np->vsi;
  375. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  376. int i;
  377. if (test_bit(__I40E_DOWN, &vsi->state))
  378. return stats;
  379. if (!vsi->tx_rings)
  380. return stats;
  381. rcu_read_lock();
  382. for (i = 0; i < vsi->num_queue_pairs; i++) {
  383. u64 bytes, packets;
  384. unsigned int start;
  385. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  386. if (!tx_ring)
  387. continue;
  388. do {
  389. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  390. packets = tx_ring->stats.packets;
  391. bytes = tx_ring->stats.bytes;
  392. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  393. stats->tx_packets += packets;
  394. stats->tx_bytes += bytes;
  395. rx_ring = &tx_ring[1];
  396. do {
  397. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  398. packets = rx_ring->stats.packets;
  399. bytes = rx_ring->stats.bytes;
  400. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  401. stats->rx_packets += packets;
  402. stats->rx_bytes += bytes;
  403. }
  404. rcu_read_unlock();
  405. /* following stats updated by i40e_watchdog_subtask() */
  406. stats->multicast = vsi_stats->multicast;
  407. stats->tx_errors = vsi_stats->tx_errors;
  408. stats->tx_dropped = vsi_stats->tx_dropped;
  409. stats->rx_errors = vsi_stats->rx_errors;
  410. stats->rx_dropped = vsi_stats->rx_dropped;
  411. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  412. stats->rx_length_errors = vsi_stats->rx_length_errors;
  413. return stats;
  414. }
  415. /**
  416. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  417. * @vsi: the VSI to have its stats reset
  418. **/
  419. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  420. {
  421. struct rtnl_link_stats64 *ns;
  422. int i;
  423. if (!vsi)
  424. return;
  425. ns = i40e_get_vsi_stats_struct(vsi);
  426. memset(ns, 0, sizeof(*ns));
  427. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  428. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  429. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  430. if (vsi->rx_rings && vsi->rx_rings[0]) {
  431. for (i = 0; i < vsi->num_queue_pairs; i++) {
  432. memset(&vsi->rx_rings[i]->stats, 0,
  433. sizeof(vsi->rx_rings[i]->stats));
  434. memset(&vsi->rx_rings[i]->rx_stats, 0,
  435. sizeof(vsi->rx_rings[i]->rx_stats));
  436. memset(&vsi->tx_rings[i]->stats, 0,
  437. sizeof(vsi->tx_rings[i]->stats));
  438. memset(&vsi->tx_rings[i]->tx_stats, 0,
  439. sizeof(vsi->tx_rings[i]->tx_stats));
  440. }
  441. }
  442. vsi->stat_offsets_loaded = false;
  443. }
  444. /**
  445. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  446. * @pf: the PF to be reset
  447. **/
  448. void i40e_pf_reset_stats(struct i40e_pf *pf)
  449. {
  450. int i;
  451. memset(&pf->stats, 0, sizeof(pf->stats));
  452. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  453. pf->stat_offsets_loaded = false;
  454. for (i = 0; i < I40E_MAX_VEB; i++) {
  455. if (pf->veb[i]) {
  456. memset(&pf->veb[i]->stats, 0,
  457. sizeof(pf->veb[i]->stats));
  458. memset(&pf->veb[i]->stats_offsets, 0,
  459. sizeof(pf->veb[i]->stats_offsets));
  460. pf->veb[i]->stat_offsets_loaded = false;
  461. }
  462. }
  463. pf->hw_csum_rx_error = 0;
  464. }
  465. /**
  466. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  467. * @hw: ptr to the hardware info
  468. * @hireg: the high 32 bit reg to read
  469. * @loreg: the low 32 bit reg to read
  470. * @offset_loaded: has the initial offset been loaded yet
  471. * @offset: ptr to current offset value
  472. * @stat: ptr to the stat
  473. *
  474. * Since the device stats are not reset at PFReset, they likely will not
  475. * be zeroed when the driver starts. We'll save the first values read
  476. * and use them as offsets to be subtracted from the raw values in order
  477. * to report stats that count from zero. In the process, we also manage
  478. * the potential roll-over.
  479. **/
  480. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  481. bool offset_loaded, u64 *offset, u64 *stat)
  482. {
  483. u64 new_data;
  484. if (hw->device_id == I40E_DEV_ID_QEMU) {
  485. new_data = rd32(hw, loreg);
  486. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  487. } else {
  488. new_data = rd64(hw, loreg);
  489. }
  490. if (!offset_loaded)
  491. *offset = new_data;
  492. if (likely(new_data >= *offset))
  493. *stat = new_data - *offset;
  494. else
  495. *stat = (new_data + BIT_ULL(48)) - *offset;
  496. *stat &= 0xFFFFFFFFFFFFULL;
  497. }
  498. /**
  499. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  500. * @hw: ptr to the hardware info
  501. * @reg: the hw reg to read
  502. * @offset_loaded: has the initial offset been loaded yet
  503. * @offset: ptr to current offset value
  504. * @stat: ptr to the stat
  505. **/
  506. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  507. bool offset_loaded, u64 *offset, u64 *stat)
  508. {
  509. u32 new_data;
  510. new_data = rd32(hw, reg);
  511. if (!offset_loaded)
  512. *offset = new_data;
  513. if (likely(new_data >= *offset))
  514. *stat = (u32)(new_data - *offset);
  515. else
  516. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  517. }
  518. /**
  519. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  520. * @vsi: the VSI to be updated
  521. **/
  522. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  523. {
  524. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  525. struct i40e_pf *pf = vsi->back;
  526. struct i40e_hw *hw = &pf->hw;
  527. struct i40e_eth_stats *oes;
  528. struct i40e_eth_stats *es; /* device's eth stats */
  529. es = &vsi->eth_stats;
  530. oes = &vsi->eth_stats_offsets;
  531. /* Gather up the stats that the hw collects */
  532. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  533. vsi->stat_offsets_loaded,
  534. &oes->tx_errors, &es->tx_errors);
  535. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  536. vsi->stat_offsets_loaded,
  537. &oes->rx_discards, &es->rx_discards);
  538. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  539. vsi->stat_offsets_loaded,
  540. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  541. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  542. vsi->stat_offsets_loaded,
  543. &oes->tx_errors, &es->tx_errors);
  544. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  545. I40E_GLV_GORCL(stat_idx),
  546. vsi->stat_offsets_loaded,
  547. &oes->rx_bytes, &es->rx_bytes);
  548. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  549. I40E_GLV_UPRCL(stat_idx),
  550. vsi->stat_offsets_loaded,
  551. &oes->rx_unicast, &es->rx_unicast);
  552. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  553. I40E_GLV_MPRCL(stat_idx),
  554. vsi->stat_offsets_loaded,
  555. &oes->rx_multicast, &es->rx_multicast);
  556. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  557. I40E_GLV_BPRCL(stat_idx),
  558. vsi->stat_offsets_loaded,
  559. &oes->rx_broadcast, &es->rx_broadcast);
  560. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  561. I40E_GLV_GOTCL(stat_idx),
  562. vsi->stat_offsets_loaded,
  563. &oes->tx_bytes, &es->tx_bytes);
  564. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  565. I40E_GLV_UPTCL(stat_idx),
  566. vsi->stat_offsets_loaded,
  567. &oes->tx_unicast, &es->tx_unicast);
  568. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  569. I40E_GLV_MPTCL(stat_idx),
  570. vsi->stat_offsets_loaded,
  571. &oes->tx_multicast, &es->tx_multicast);
  572. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  573. I40E_GLV_BPTCL(stat_idx),
  574. vsi->stat_offsets_loaded,
  575. &oes->tx_broadcast, &es->tx_broadcast);
  576. vsi->stat_offsets_loaded = true;
  577. }
  578. /**
  579. * i40e_update_veb_stats - Update Switch component statistics
  580. * @veb: the VEB being updated
  581. **/
  582. static void i40e_update_veb_stats(struct i40e_veb *veb)
  583. {
  584. struct i40e_pf *pf = veb->pf;
  585. struct i40e_hw *hw = &pf->hw;
  586. struct i40e_eth_stats *oes;
  587. struct i40e_eth_stats *es; /* device's eth stats */
  588. struct i40e_veb_tc_stats *veb_oes;
  589. struct i40e_veb_tc_stats *veb_es;
  590. int i, idx = 0;
  591. idx = veb->stats_idx;
  592. es = &veb->stats;
  593. oes = &veb->stats_offsets;
  594. veb_es = &veb->tc_stats;
  595. veb_oes = &veb->tc_stats_offsets;
  596. /* Gather up the stats that the hw collects */
  597. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  598. veb->stat_offsets_loaded,
  599. &oes->tx_discards, &es->tx_discards);
  600. if (hw->revision_id > 0)
  601. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  602. veb->stat_offsets_loaded,
  603. &oes->rx_unknown_protocol,
  604. &es->rx_unknown_protocol);
  605. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  606. veb->stat_offsets_loaded,
  607. &oes->rx_bytes, &es->rx_bytes);
  608. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  609. veb->stat_offsets_loaded,
  610. &oes->rx_unicast, &es->rx_unicast);
  611. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  612. veb->stat_offsets_loaded,
  613. &oes->rx_multicast, &es->rx_multicast);
  614. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  615. veb->stat_offsets_loaded,
  616. &oes->rx_broadcast, &es->rx_broadcast);
  617. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  618. veb->stat_offsets_loaded,
  619. &oes->tx_bytes, &es->tx_bytes);
  620. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  621. veb->stat_offsets_loaded,
  622. &oes->tx_unicast, &es->tx_unicast);
  623. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  624. veb->stat_offsets_loaded,
  625. &oes->tx_multicast, &es->tx_multicast);
  626. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  627. veb->stat_offsets_loaded,
  628. &oes->tx_broadcast, &es->tx_broadcast);
  629. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  630. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  631. I40E_GLVEBTC_RPCL(i, idx),
  632. veb->stat_offsets_loaded,
  633. &veb_oes->tc_rx_packets[i],
  634. &veb_es->tc_rx_packets[i]);
  635. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  636. I40E_GLVEBTC_RBCL(i, idx),
  637. veb->stat_offsets_loaded,
  638. &veb_oes->tc_rx_bytes[i],
  639. &veb_es->tc_rx_bytes[i]);
  640. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  641. I40E_GLVEBTC_TPCL(i, idx),
  642. veb->stat_offsets_loaded,
  643. &veb_oes->tc_tx_packets[i],
  644. &veb_es->tc_tx_packets[i]);
  645. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  646. I40E_GLVEBTC_TBCL(i, idx),
  647. veb->stat_offsets_loaded,
  648. &veb_oes->tc_tx_bytes[i],
  649. &veb_es->tc_tx_bytes[i]);
  650. }
  651. veb->stat_offsets_loaded = true;
  652. }
  653. #ifdef I40E_FCOE
  654. /**
  655. * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
  656. * @vsi: the VSI that is capable of doing FCoE
  657. **/
  658. static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
  659. {
  660. struct i40e_pf *pf = vsi->back;
  661. struct i40e_hw *hw = &pf->hw;
  662. struct i40e_fcoe_stats *ofs;
  663. struct i40e_fcoe_stats *fs; /* device's eth stats */
  664. int idx;
  665. if (vsi->type != I40E_VSI_FCOE)
  666. return;
  667. idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
  668. fs = &vsi->fcoe_stats;
  669. ofs = &vsi->fcoe_stats_offsets;
  670. i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
  671. vsi->fcoe_stat_offsets_loaded,
  672. &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
  673. i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
  674. vsi->fcoe_stat_offsets_loaded,
  675. &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
  676. i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
  677. vsi->fcoe_stat_offsets_loaded,
  678. &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
  679. i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
  680. vsi->fcoe_stat_offsets_loaded,
  681. &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
  682. i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
  683. vsi->fcoe_stat_offsets_loaded,
  684. &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
  685. i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
  686. vsi->fcoe_stat_offsets_loaded,
  687. &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
  688. i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
  689. vsi->fcoe_stat_offsets_loaded,
  690. &ofs->fcoe_last_error, &fs->fcoe_last_error);
  691. i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
  692. vsi->fcoe_stat_offsets_loaded,
  693. &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
  694. vsi->fcoe_stat_offsets_loaded = true;
  695. }
  696. #endif
  697. /**
  698. * i40e_update_vsi_stats - Update the vsi statistics counters.
  699. * @vsi: the VSI to be updated
  700. *
  701. * There are a few instances where we store the same stat in a
  702. * couple of different structs. This is partly because we have
  703. * the netdev stats that need to be filled out, which is slightly
  704. * different from the "eth_stats" defined by the chip and used in
  705. * VF communications. We sort it out here.
  706. **/
  707. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  708. {
  709. struct i40e_pf *pf = vsi->back;
  710. struct rtnl_link_stats64 *ons;
  711. struct rtnl_link_stats64 *ns; /* netdev stats */
  712. struct i40e_eth_stats *oes;
  713. struct i40e_eth_stats *es; /* device's eth stats */
  714. u32 tx_restart, tx_busy;
  715. u64 tx_lost_interrupt;
  716. struct i40e_ring *p;
  717. u32 rx_page, rx_buf;
  718. u64 bytes, packets;
  719. unsigned int start;
  720. u64 tx_linearize;
  721. u64 tx_force_wb;
  722. u64 rx_p, rx_b;
  723. u64 tx_p, tx_b;
  724. u16 q;
  725. if (test_bit(__I40E_DOWN, &vsi->state) ||
  726. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  727. return;
  728. ns = i40e_get_vsi_stats_struct(vsi);
  729. ons = &vsi->net_stats_offsets;
  730. es = &vsi->eth_stats;
  731. oes = &vsi->eth_stats_offsets;
  732. /* Gather up the netdev and vsi stats that the driver collects
  733. * on the fly during packet processing
  734. */
  735. rx_b = rx_p = 0;
  736. tx_b = tx_p = 0;
  737. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  738. tx_lost_interrupt = 0;
  739. rx_page = 0;
  740. rx_buf = 0;
  741. rcu_read_lock();
  742. for (q = 0; q < vsi->num_queue_pairs; q++) {
  743. /* locate Tx ring */
  744. p = ACCESS_ONCE(vsi->tx_rings[q]);
  745. do {
  746. start = u64_stats_fetch_begin_irq(&p->syncp);
  747. packets = p->stats.packets;
  748. bytes = p->stats.bytes;
  749. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  750. tx_b += bytes;
  751. tx_p += packets;
  752. tx_restart += p->tx_stats.restart_queue;
  753. tx_busy += p->tx_stats.tx_busy;
  754. tx_linearize += p->tx_stats.tx_linearize;
  755. tx_force_wb += p->tx_stats.tx_force_wb;
  756. tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
  757. /* Rx queue is part of the same block as Tx queue */
  758. p = &p[1];
  759. do {
  760. start = u64_stats_fetch_begin_irq(&p->syncp);
  761. packets = p->stats.packets;
  762. bytes = p->stats.bytes;
  763. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  764. rx_b += bytes;
  765. rx_p += packets;
  766. rx_buf += p->rx_stats.alloc_buff_failed;
  767. rx_page += p->rx_stats.alloc_page_failed;
  768. }
  769. rcu_read_unlock();
  770. vsi->tx_restart = tx_restart;
  771. vsi->tx_busy = tx_busy;
  772. vsi->tx_linearize = tx_linearize;
  773. vsi->tx_force_wb = tx_force_wb;
  774. vsi->tx_lost_interrupt = tx_lost_interrupt;
  775. vsi->rx_page_failed = rx_page;
  776. vsi->rx_buf_failed = rx_buf;
  777. ns->rx_packets = rx_p;
  778. ns->rx_bytes = rx_b;
  779. ns->tx_packets = tx_p;
  780. ns->tx_bytes = tx_b;
  781. /* update netdev stats from eth stats */
  782. i40e_update_eth_stats(vsi);
  783. ons->tx_errors = oes->tx_errors;
  784. ns->tx_errors = es->tx_errors;
  785. ons->multicast = oes->rx_multicast;
  786. ns->multicast = es->rx_multicast;
  787. ons->rx_dropped = oes->rx_discards;
  788. ns->rx_dropped = es->rx_discards;
  789. ons->tx_dropped = oes->tx_discards;
  790. ns->tx_dropped = es->tx_discards;
  791. /* pull in a couple PF stats if this is the main vsi */
  792. if (vsi == pf->vsi[pf->lan_vsi]) {
  793. ns->rx_crc_errors = pf->stats.crc_errors;
  794. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  795. ns->rx_length_errors = pf->stats.rx_length_errors;
  796. }
  797. }
  798. /**
  799. * i40e_update_pf_stats - Update the PF statistics counters.
  800. * @pf: the PF to be updated
  801. **/
  802. static void i40e_update_pf_stats(struct i40e_pf *pf)
  803. {
  804. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  805. struct i40e_hw_port_stats *nsd = &pf->stats;
  806. struct i40e_hw *hw = &pf->hw;
  807. u32 val;
  808. int i;
  809. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  810. I40E_GLPRT_GORCL(hw->port),
  811. pf->stat_offsets_loaded,
  812. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  813. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  814. I40E_GLPRT_GOTCL(hw->port),
  815. pf->stat_offsets_loaded,
  816. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  817. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  818. pf->stat_offsets_loaded,
  819. &osd->eth.rx_discards,
  820. &nsd->eth.rx_discards);
  821. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  822. I40E_GLPRT_UPRCL(hw->port),
  823. pf->stat_offsets_loaded,
  824. &osd->eth.rx_unicast,
  825. &nsd->eth.rx_unicast);
  826. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  827. I40E_GLPRT_MPRCL(hw->port),
  828. pf->stat_offsets_loaded,
  829. &osd->eth.rx_multicast,
  830. &nsd->eth.rx_multicast);
  831. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  832. I40E_GLPRT_BPRCL(hw->port),
  833. pf->stat_offsets_loaded,
  834. &osd->eth.rx_broadcast,
  835. &nsd->eth.rx_broadcast);
  836. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  837. I40E_GLPRT_UPTCL(hw->port),
  838. pf->stat_offsets_loaded,
  839. &osd->eth.tx_unicast,
  840. &nsd->eth.tx_unicast);
  841. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  842. I40E_GLPRT_MPTCL(hw->port),
  843. pf->stat_offsets_loaded,
  844. &osd->eth.tx_multicast,
  845. &nsd->eth.tx_multicast);
  846. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  847. I40E_GLPRT_BPTCL(hw->port),
  848. pf->stat_offsets_loaded,
  849. &osd->eth.tx_broadcast,
  850. &nsd->eth.tx_broadcast);
  851. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  852. pf->stat_offsets_loaded,
  853. &osd->tx_dropped_link_down,
  854. &nsd->tx_dropped_link_down);
  855. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  856. pf->stat_offsets_loaded,
  857. &osd->crc_errors, &nsd->crc_errors);
  858. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  859. pf->stat_offsets_loaded,
  860. &osd->illegal_bytes, &nsd->illegal_bytes);
  861. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  862. pf->stat_offsets_loaded,
  863. &osd->mac_local_faults,
  864. &nsd->mac_local_faults);
  865. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  866. pf->stat_offsets_loaded,
  867. &osd->mac_remote_faults,
  868. &nsd->mac_remote_faults);
  869. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  870. pf->stat_offsets_loaded,
  871. &osd->rx_length_errors,
  872. &nsd->rx_length_errors);
  873. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  874. pf->stat_offsets_loaded,
  875. &osd->link_xon_rx, &nsd->link_xon_rx);
  876. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  877. pf->stat_offsets_loaded,
  878. &osd->link_xon_tx, &nsd->link_xon_tx);
  879. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  880. pf->stat_offsets_loaded,
  881. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  882. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  883. pf->stat_offsets_loaded,
  884. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  885. for (i = 0; i < 8; i++) {
  886. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  887. pf->stat_offsets_loaded,
  888. &osd->priority_xoff_rx[i],
  889. &nsd->priority_xoff_rx[i]);
  890. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  891. pf->stat_offsets_loaded,
  892. &osd->priority_xon_rx[i],
  893. &nsd->priority_xon_rx[i]);
  894. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  895. pf->stat_offsets_loaded,
  896. &osd->priority_xon_tx[i],
  897. &nsd->priority_xon_tx[i]);
  898. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  899. pf->stat_offsets_loaded,
  900. &osd->priority_xoff_tx[i],
  901. &nsd->priority_xoff_tx[i]);
  902. i40e_stat_update32(hw,
  903. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  904. pf->stat_offsets_loaded,
  905. &osd->priority_xon_2_xoff[i],
  906. &nsd->priority_xon_2_xoff[i]);
  907. }
  908. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  909. I40E_GLPRT_PRC64L(hw->port),
  910. pf->stat_offsets_loaded,
  911. &osd->rx_size_64, &nsd->rx_size_64);
  912. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  913. I40E_GLPRT_PRC127L(hw->port),
  914. pf->stat_offsets_loaded,
  915. &osd->rx_size_127, &nsd->rx_size_127);
  916. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  917. I40E_GLPRT_PRC255L(hw->port),
  918. pf->stat_offsets_loaded,
  919. &osd->rx_size_255, &nsd->rx_size_255);
  920. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  921. I40E_GLPRT_PRC511L(hw->port),
  922. pf->stat_offsets_loaded,
  923. &osd->rx_size_511, &nsd->rx_size_511);
  924. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  925. I40E_GLPRT_PRC1023L(hw->port),
  926. pf->stat_offsets_loaded,
  927. &osd->rx_size_1023, &nsd->rx_size_1023);
  928. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  929. I40E_GLPRT_PRC1522L(hw->port),
  930. pf->stat_offsets_loaded,
  931. &osd->rx_size_1522, &nsd->rx_size_1522);
  932. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  933. I40E_GLPRT_PRC9522L(hw->port),
  934. pf->stat_offsets_loaded,
  935. &osd->rx_size_big, &nsd->rx_size_big);
  936. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  937. I40E_GLPRT_PTC64L(hw->port),
  938. pf->stat_offsets_loaded,
  939. &osd->tx_size_64, &nsd->tx_size_64);
  940. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  941. I40E_GLPRT_PTC127L(hw->port),
  942. pf->stat_offsets_loaded,
  943. &osd->tx_size_127, &nsd->tx_size_127);
  944. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  945. I40E_GLPRT_PTC255L(hw->port),
  946. pf->stat_offsets_loaded,
  947. &osd->tx_size_255, &nsd->tx_size_255);
  948. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  949. I40E_GLPRT_PTC511L(hw->port),
  950. pf->stat_offsets_loaded,
  951. &osd->tx_size_511, &nsd->tx_size_511);
  952. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  953. I40E_GLPRT_PTC1023L(hw->port),
  954. pf->stat_offsets_loaded,
  955. &osd->tx_size_1023, &nsd->tx_size_1023);
  956. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  957. I40E_GLPRT_PTC1522L(hw->port),
  958. pf->stat_offsets_loaded,
  959. &osd->tx_size_1522, &nsd->tx_size_1522);
  960. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  961. I40E_GLPRT_PTC9522L(hw->port),
  962. pf->stat_offsets_loaded,
  963. &osd->tx_size_big, &nsd->tx_size_big);
  964. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  965. pf->stat_offsets_loaded,
  966. &osd->rx_undersize, &nsd->rx_undersize);
  967. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  968. pf->stat_offsets_loaded,
  969. &osd->rx_fragments, &nsd->rx_fragments);
  970. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  971. pf->stat_offsets_loaded,
  972. &osd->rx_oversize, &nsd->rx_oversize);
  973. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  974. pf->stat_offsets_loaded,
  975. &osd->rx_jabber, &nsd->rx_jabber);
  976. /* FDIR stats */
  977. i40e_stat_update32(hw,
  978. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
  979. pf->stat_offsets_loaded,
  980. &osd->fd_atr_match, &nsd->fd_atr_match);
  981. i40e_stat_update32(hw,
  982. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
  983. pf->stat_offsets_loaded,
  984. &osd->fd_sb_match, &nsd->fd_sb_match);
  985. i40e_stat_update32(hw,
  986. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
  987. pf->stat_offsets_loaded,
  988. &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
  989. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  990. nsd->tx_lpi_status =
  991. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  992. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  993. nsd->rx_lpi_status =
  994. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  995. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  996. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  997. pf->stat_offsets_loaded,
  998. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  999. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  1000. pf->stat_offsets_loaded,
  1001. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  1002. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  1003. !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
  1004. nsd->fd_sb_status = true;
  1005. else
  1006. nsd->fd_sb_status = false;
  1007. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  1008. !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
  1009. nsd->fd_atr_status = true;
  1010. else
  1011. nsd->fd_atr_status = false;
  1012. pf->stat_offsets_loaded = true;
  1013. }
  1014. /**
  1015. * i40e_update_stats - Update the various statistics counters.
  1016. * @vsi: the VSI to be updated
  1017. *
  1018. * Update the various stats for this VSI and its related entities.
  1019. **/
  1020. void i40e_update_stats(struct i40e_vsi *vsi)
  1021. {
  1022. struct i40e_pf *pf = vsi->back;
  1023. if (vsi == pf->vsi[pf->lan_vsi])
  1024. i40e_update_pf_stats(pf);
  1025. i40e_update_vsi_stats(vsi);
  1026. #ifdef I40E_FCOE
  1027. i40e_update_fcoe_stats(vsi);
  1028. #endif
  1029. }
  1030. /**
  1031. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1032. * @vsi: the VSI to be searched
  1033. * @macaddr: the MAC address
  1034. * @vlan: the vlan
  1035. *
  1036. * Returns ptr to the filter object or NULL
  1037. **/
  1038. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1039. const u8 *macaddr, s16 vlan)
  1040. {
  1041. struct i40e_mac_filter *f;
  1042. u64 key;
  1043. if (!vsi || !macaddr)
  1044. return NULL;
  1045. key = i40e_addr_to_hkey(macaddr);
  1046. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1047. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1048. (vlan == f->vlan))
  1049. return f;
  1050. }
  1051. return NULL;
  1052. }
  1053. /**
  1054. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1055. * @vsi: the VSI to be searched
  1056. * @macaddr: the MAC address we are searching for
  1057. *
  1058. * Returns the first filter with the provided MAC address or NULL if
  1059. * MAC address was not found
  1060. **/
  1061. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1062. {
  1063. struct i40e_mac_filter *f;
  1064. u64 key;
  1065. if (!vsi || !macaddr)
  1066. return NULL;
  1067. key = i40e_addr_to_hkey(macaddr);
  1068. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1069. if ((ether_addr_equal(macaddr, f->macaddr)))
  1070. return f;
  1071. }
  1072. return NULL;
  1073. }
  1074. /**
  1075. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1076. * @vsi: the VSI to be searched
  1077. *
  1078. * Returns true if VSI is in vlan mode or false otherwise
  1079. **/
  1080. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1081. {
  1082. /* If we have a PVID, always operate in VLAN mode */
  1083. if (vsi->info.pvid)
  1084. return true;
  1085. /* We need to operate in VLAN mode whenever we have any filters with
  1086. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1087. * time, incurring search cost repeatedly. However, we can notice two
  1088. * things:
  1089. *
  1090. * 1) the only place where we can gain a VLAN filter is in
  1091. * i40e_add_filter.
  1092. *
  1093. * 2) the only place where filters are actually removed is in
  1094. * i40e_sync_filters_subtask.
  1095. *
  1096. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1097. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1098. * we have to perform the full search after deleting filters in
  1099. * i40e_sync_filters_subtask, but we already have to search
  1100. * filters here and can perform the check at the same time. This
  1101. * results in avoiding embedding a loop for VLAN mode inside another
  1102. * loop over all the filters, and should maintain correctness as noted
  1103. * above.
  1104. */
  1105. return vsi->has_vlan_filter;
  1106. }
  1107. /**
  1108. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1109. * @vsi: the VSI to configure
  1110. * @tmp_add_list: list of filters ready to be added
  1111. * @tmp_del_list: list of filters ready to be deleted
  1112. * @vlan_filters: the number of active VLAN filters
  1113. *
  1114. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1115. * behave as expected. If we have any active VLAN filters remaining or about
  1116. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1117. * so that they only match against untagged traffic. If we no longer have any
  1118. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1119. * so that they match against both tagged and untagged traffic. In this way,
  1120. * we ensure that we correctly receive the desired traffic. This ensures that
  1121. * when we have an active VLAN we will receive only untagged traffic and
  1122. * traffic matching active VLANs. If we have no active VLANs then we will
  1123. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1124. *
  1125. * Finally, in a similar fashion, this function also corrects filters when
  1126. * there is an active PVID assigned to this VSI.
  1127. *
  1128. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1129. *
  1130. * This function is only expected to be called from within
  1131. * i40e_sync_vsi_filters.
  1132. *
  1133. * NOTE: This function expects to be called while under the
  1134. * mac_filter_hash_lock
  1135. */
  1136. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1137. struct hlist_head *tmp_add_list,
  1138. struct hlist_head *tmp_del_list,
  1139. int vlan_filters)
  1140. {
  1141. struct i40e_mac_filter *f, *add_head;
  1142. struct hlist_node *h;
  1143. int bkt, new_vlan;
  1144. /* To determine if a particular filter needs to be replaced we
  1145. * have the three following conditions:
  1146. *
  1147. * a) if we have a PVID assigned, then all filters which are
  1148. * not marked as VLAN=PVID must be replaced with filters that
  1149. * are.
  1150. * b) otherwise, if we have any active VLANS, all filters
  1151. * which are marked as VLAN=-1 must be replaced with
  1152. * filters marked as VLAN=0
  1153. * c) finally, if we do not have any active VLANS, all filters
  1154. * which are marked as VLAN=0 must be replaced with filters
  1155. * marked as VLAN=-1
  1156. */
  1157. /* Update the filters about to be added in place */
  1158. hlist_for_each_entry(f, tmp_add_list, hlist) {
  1159. if (vsi->info.pvid && f->vlan != vsi->info.pvid)
  1160. f->vlan = vsi->info.pvid;
  1161. else if (vlan_filters && f->vlan == I40E_VLAN_ANY)
  1162. f->vlan = 0;
  1163. else if (!vlan_filters && f->vlan == 0)
  1164. f->vlan = I40E_VLAN_ANY;
  1165. }
  1166. /* Update the remaining active filters */
  1167. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1168. /* Combine the checks for whether a filter needs to be changed
  1169. * and then determine the new VLAN inside the if block, in
  1170. * order to avoid duplicating code for adding the new filter
  1171. * then deleting the old filter.
  1172. */
  1173. if ((vsi->info.pvid && f->vlan != vsi->info.pvid) ||
  1174. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1175. (!vlan_filters && f->vlan == 0)) {
  1176. /* Determine the new vlan we will be adding */
  1177. if (vsi->info.pvid)
  1178. new_vlan = vsi->info.pvid;
  1179. else if (vlan_filters)
  1180. new_vlan = 0;
  1181. else
  1182. new_vlan = I40E_VLAN_ANY;
  1183. /* Create the new filter */
  1184. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1185. if (!add_head)
  1186. return -ENOMEM;
  1187. /* Put the replacement filter into the add list */
  1188. hash_del(&add_head->hlist);
  1189. hlist_add_head(&add_head->hlist, tmp_add_list);
  1190. /* Put the original filter into the delete list */
  1191. f->state = I40E_FILTER_REMOVE;
  1192. hash_del(&f->hlist);
  1193. hlist_add_head(&f->hlist, tmp_del_list);
  1194. }
  1195. }
  1196. vsi->has_vlan_filter = !!vlan_filters;
  1197. return 0;
  1198. }
  1199. /**
  1200. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1201. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1202. * @macaddr: the MAC address
  1203. *
  1204. * Remove whatever filter the firmware set up so the driver can manage
  1205. * its own filtering intelligently.
  1206. **/
  1207. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1208. {
  1209. struct i40e_aqc_remove_macvlan_element_data element;
  1210. struct i40e_pf *pf = vsi->back;
  1211. /* Only appropriate for the PF main VSI */
  1212. if (vsi->type != I40E_VSI_MAIN)
  1213. return;
  1214. memset(&element, 0, sizeof(element));
  1215. ether_addr_copy(element.mac_addr, macaddr);
  1216. element.vlan_tag = 0;
  1217. /* Ignore error returns, some firmware does it this way... */
  1218. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1219. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1220. memset(&element, 0, sizeof(element));
  1221. ether_addr_copy(element.mac_addr, macaddr);
  1222. element.vlan_tag = 0;
  1223. /* ...and some firmware does it this way. */
  1224. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1225. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1226. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1227. }
  1228. /**
  1229. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1230. * @vsi: the VSI to be searched
  1231. * @macaddr: the MAC address
  1232. * @vlan: the vlan
  1233. *
  1234. * Returns ptr to the filter object or NULL when no memory available.
  1235. *
  1236. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1237. * being held.
  1238. **/
  1239. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1240. const u8 *macaddr, s16 vlan)
  1241. {
  1242. struct i40e_mac_filter *f;
  1243. u64 key;
  1244. if (!vsi || !macaddr)
  1245. return NULL;
  1246. f = i40e_find_filter(vsi, macaddr, vlan);
  1247. if (!f) {
  1248. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1249. if (!f)
  1250. return NULL;
  1251. /* Update the boolean indicating if we need to function in
  1252. * VLAN mode.
  1253. */
  1254. if (vlan >= 0)
  1255. vsi->has_vlan_filter = true;
  1256. ether_addr_copy(f->macaddr, macaddr);
  1257. f->vlan = vlan;
  1258. /* If we're in overflow promisc mode, set the state directly
  1259. * to failed, so we don't bother to try sending the filter
  1260. * to the hardware.
  1261. */
  1262. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))
  1263. f->state = I40E_FILTER_FAILED;
  1264. else
  1265. f->state = I40E_FILTER_NEW;
  1266. INIT_HLIST_NODE(&f->hlist);
  1267. key = i40e_addr_to_hkey(macaddr);
  1268. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1269. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1270. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1271. }
  1272. /* If we're asked to add a filter that has been marked for removal, it
  1273. * is safe to simply restore it to active state. __i40e_del_filter
  1274. * will have simply deleted any filters which were previously marked
  1275. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1276. * previously been ACTIVE. Since we haven't yet run the sync filters
  1277. * task, just restore this filter to the ACTIVE state so that the
  1278. * sync task leaves it in place
  1279. */
  1280. if (f->state == I40E_FILTER_REMOVE)
  1281. f->state = I40E_FILTER_ACTIVE;
  1282. return f;
  1283. }
  1284. /**
  1285. * __i40e_del_filter - Remove a specific filter from the VSI
  1286. * @vsi: VSI to remove from
  1287. * @f: the filter to remove from the list
  1288. *
  1289. * This function should be called instead of i40e_del_filter only if you know
  1290. * the exact filter you will remove already, such as via i40e_find_filter or
  1291. * i40e_find_mac.
  1292. *
  1293. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1294. * being held.
  1295. * ANOTHER NOTE: This function MUST be called from within the context of
  1296. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1297. * instead of list_for_each_entry().
  1298. **/
  1299. static void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1300. {
  1301. if (!f)
  1302. return;
  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. hash_del(&f->hlist);
  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. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1318. * @vsi: the VSI to be searched
  1319. * @macaddr: the MAC address
  1320. * @vlan: the VLAN
  1321. *
  1322. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1323. * being held.
  1324. * ANOTHER NOTE: This function MUST be called from within the context of
  1325. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1326. * instead of list_for_each_entry().
  1327. **/
  1328. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1329. {
  1330. struct i40e_mac_filter *f;
  1331. if (!vsi || !macaddr)
  1332. return;
  1333. f = i40e_find_filter(vsi, macaddr, vlan);
  1334. __i40e_del_filter(vsi, f);
  1335. }
  1336. /**
  1337. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  1338. * @vsi: the VSI to be searched
  1339. * @macaddr: the mac address to be filtered
  1340. *
  1341. * Goes through all the macvlan filters and adds a macvlan filter for each
  1342. * unique vlan that already exists. If a PVID has been assigned, instead only
  1343. * add the macaddr to that VLAN.
  1344. *
  1345. * Returns last filter added on success, else NULL
  1346. **/
  1347. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi,
  1348. const u8 *macaddr)
  1349. {
  1350. struct i40e_mac_filter *f, *add = NULL;
  1351. struct hlist_node *h;
  1352. int bkt;
  1353. if (vsi->info.pvid)
  1354. return i40e_add_filter(vsi, macaddr,
  1355. le16_to_cpu(vsi->info.pvid));
  1356. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1357. if (f->state == I40E_FILTER_REMOVE)
  1358. continue;
  1359. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1360. if (!add)
  1361. return NULL;
  1362. }
  1363. return add;
  1364. }
  1365. /**
  1366. * i40e_del_mac_all_vlan - Remove a MAC filter from all VLANS
  1367. * @vsi: the VSI to be searched
  1368. * @macaddr: the mac address to be removed
  1369. *
  1370. * Removes a given MAC address from a VSI, regardless of VLAN
  1371. *
  1372. * Returns 0 for success, or error
  1373. **/
  1374. int i40e_del_mac_all_vlan(struct i40e_vsi *vsi, const u8 *macaddr)
  1375. {
  1376. struct i40e_mac_filter *f;
  1377. struct hlist_node *h;
  1378. bool found = false;
  1379. int bkt;
  1380. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1381. "Missing mac_filter_hash_lock\n");
  1382. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1383. if (ether_addr_equal(macaddr, f->macaddr)) {
  1384. __i40e_del_filter(vsi, f);
  1385. found = true;
  1386. }
  1387. }
  1388. if (found)
  1389. return 0;
  1390. else
  1391. return -ENOENT;
  1392. }
  1393. /**
  1394. * i40e_set_mac - NDO callback to set mac address
  1395. * @netdev: network interface device structure
  1396. * @p: pointer to an address structure
  1397. *
  1398. * Returns 0 on success, negative on failure
  1399. **/
  1400. #ifdef I40E_FCOE
  1401. int i40e_set_mac(struct net_device *netdev, void *p)
  1402. #else
  1403. static int i40e_set_mac(struct net_device *netdev, void *p)
  1404. #endif
  1405. {
  1406. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1407. struct i40e_vsi *vsi = np->vsi;
  1408. struct i40e_pf *pf = vsi->back;
  1409. struct i40e_hw *hw = &pf->hw;
  1410. struct sockaddr *addr = p;
  1411. if (!is_valid_ether_addr(addr->sa_data))
  1412. return -EADDRNOTAVAIL;
  1413. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1414. netdev_info(netdev, "already using mac address %pM\n",
  1415. addr->sa_data);
  1416. return 0;
  1417. }
  1418. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1419. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1420. return -EADDRNOTAVAIL;
  1421. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1422. netdev_info(netdev, "returning to hw mac address %pM\n",
  1423. hw->mac.addr);
  1424. else
  1425. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1426. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1427. i40e_del_mac_all_vlan(vsi, netdev->dev_addr);
  1428. i40e_put_mac_in_vlan(vsi, addr->sa_data);
  1429. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1430. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1431. if (vsi->type == I40E_VSI_MAIN) {
  1432. i40e_status ret;
  1433. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1434. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1435. addr->sa_data, NULL);
  1436. if (ret)
  1437. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1438. i40e_stat_str(hw, ret),
  1439. i40e_aq_str(hw, hw->aq.asq_last_status));
  1440. }
  1441. /* schedule our worker thread which will take care of
  1442. * applying the new filter changes
  1443. */
  1444. i40e_service_event_schedule(vsi->back);
  1445. return 0;
  1446. }
  1447. /**
  1448. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1449. * @vsi: the VSI being setup
  1450. * @ctxt: VSI context structure
  1451. * @enabled_tc: Enabled TCs bitmap
  1452. * @is_add: True if called before Add VSI
  1453. *
  1454. * Setup VSI queue mapping for enabled traffic classes.
  1455. **/
  1456. #ifdef I40E_FCOE
  1457. void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1458. struct i40e_vsi_context *ctxt,
  1459. u8 enabled_tc,
  1460. bool is_add)
  1461. #else
  1462. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1463. struct i40e_vsi_context *ctxt,
  1464. u8 enabled_tc,
  1465. bool is_add)
  1466. #endif
  1467. {
  1468. struct i40e_pf *pf = vsi->back;
  1469. u16 sections = 0;
  1470. u8 netdev_tc = 0;
  1471. u16 numtc = 0;
  1472. u16 qcount;
  1473. u8 offset;
  1474. u16 qmap;
  1475. int i;
  1476. u16 num_tc_qps = 0;
  1477. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1478. offset = 0;
  1479. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1480. /* Find numtc from enabled TC bitmap */
  1481. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1482. if (enabled_tc & BIT(i)) /* TC is enabled */
  1483. numtc++;
  1484. }
  1485. if (!numtc) {
  1486. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1487. numtc = 1;
  1488. }
  1489. } else {
  1490. /* At least TC0 is enabled in case of non-DCB case */
  1491. numtc = 1;
  1492. }
  1493. vsi->tc_config.numtc = numtc;
  1494. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1495. /* Number of queues per enabled TC */
  1496. qcount = vsi->alloc_queue_pairs;
  1497. num_tc_qps = qcount / numtc;
  1498. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1499. /* Setup queue offset/count for all TCs for given VSI */
  1500. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1501. /* See if the given TC is enabled for the given VSI */
  1502. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1503. /* TC is enabled */
  1504. int pow, num_qps;
  1505. switch (vsi->type) {
  1506. case I40E_VSI_MAIN:
  1507. qcount = min_t(int, pf->alloc_rss_size,
  1508. num_tc_qps);
  1509. break;
  1510. #ifdef I40E_FCOE
  1511. case I40E_VSI_FCOE:
  1512. qcount = num_tc_qps;
  1513. break;
  1514. #endif
  1515. case I40E_VSI_FDIR:
  1516. case I40E_VSI_SRIOV:
  1517. case I40E_VSI_VMDQ2:
  1518. default:
  1519. qcount = num_tc_qps;
  1520. WARN_ON(i != 0);
  1521. break;
  1522. }
  1523. vsi->tc_config.tc_info[i].qoffset = offset;
  1524. vsi->tc_config.tc_info[i].qcount = qcount;
  1525. /* find the next higher power-of-2 of num queue pairs */
  1526. num_qps = qcount;
  1527. pow = 0;
  1528. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1529. pow++;
  1530. num_qps >>= 1;
  1531. }
  1532. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1533. qmap =
  1534. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1535. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1536. offset += qcount;
  1537. } else {
  1538. /* TC is not enabled so set the offset to
  1539. * default queue and allocate one queue
  1540. * for the given TC.
  1541. */
  1542. vsi->tc_config.tc_info[i].qoffset = 0;
  1543. vsi->tc_config.tc_info[i].qcount = 1;
  1544. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1545. qmap = 0;
  1546. }
  1547. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1548. }
  1549. /* Set actual Tx/Rx queue pairs */
  1550. vsi->num_queue_pairs = offset;
  1551. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1552. if (vsi->req_queue_pairs > 0)
  1553. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1554. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1555. vsi->num_queue_pairs = pf->num_lan_msix;
  1556. }
  1557. /* Scheduler section valid can only be set for ADD VSI */
  1558. if (is_add) {
  1559. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1560. ctxt->info.up_enable_bits = enabled_tc;
  1561. }
  1562. if (vsi->type == I40E_VSI_SRIOV) {
  1563. ctxt->info.mapping_flags |=
  1564. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1565. for (i = 0; i < vsi->num_queue_pairs; i++)
  1566. ctxt->info.queue_mapping[i] =
  1567. cpu_to_le16(vsi->base_queue + i);
  1568. } else {
  1569. ctxt->info.mapping_flags |=
  1570. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1571. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1572. }
  1573. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1574. }
  1575. /**
  1576. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1577. * @netdev: the netdevice
  1578. * @addr: address to add
  1579. *
  1580. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1581. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1582. */
  1583. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1584. {
  1585. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1586. struct i40e_vsi *vsi = np->vsi;
  1587. struct i40e_mac_filter *f;
  1588. if (i40e_is_vsi_in_vlan(vsi))
  1589. f = i40e_put_mac_in_vlan(vsi, addr);
  1590. else
  1591. f = i40e_add_filter(vsi, addr, I40E_VLAN_ANY);
  1592. if (f)
  1593. return 0;
  1594. else
  1595. return -ENOMEM;
  1596. }
  1597. /**
  1598. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1599. * @netdev: the netdevice
  1600. * @addr: address to add
  1601. *
  1602. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1603. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1604. */
  1605. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1606. {
  1607. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1608. struct i40e_vsi *vsi = np->vsi;
  1609. if (i40e_is_vsi_in_vlan(vsi))
  1610. i40e_del_mac_all_vlan(vsi, addr);
  1611. else
  1612. i40e_del_filter(vsi, addr, I40E_VLAN_ANY);
  1613. return 0;
  1614. }
  1615. /**
  1616. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1617. * @netdev: network interface device structure
  1618. **/
  1619. #ifdef I40E_FCOE
  1620. void i40e_set_rx_mode(struct net_device *netdev)
  1621. #else
  1622. static void i40e_set_rx_mode(struct net_device *netdev)
  1623. #endif
  1624. {
  1625. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1626. struct i40e_vsi *vsi = np->vsi;
  1627. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1628. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1629. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1630. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1631. /* check for other flag changes */
  1632. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1633. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1634. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1635. }
  1636. /* schedule our worker thread which will take care of
  1637. * applying the new filter changes
  1638. */
  1639. i40e_service_event_schedule(vsi->back);
  1640. }
  1641. /**
  1642. * i40e_undo_filter_entries - Undo the changes made to MAC filter entries
  1643. * @vsi: Pointer to VSI struct
  1644. * @from: Pointer to list which contains MAC filter entries - changes to
  1645. * those entries needs to be undone.
  1646. *
  1647. * MAC filter entries from list were slated to be sent to firmware, either for
  1648. * addition or deletion.
  1649. **/
  1650. static void i40e_undo_filter_entries(struct i40e_vsi *vsi,
  1651. struct hlist_head *from)
  1652. {
  1653. struct i40e_mac_filter *f;
  1654. struct hlist_node *h;
  1655. hlist_for_each_entry_safe(f, h, from, hlist) {
  1656. u64 key = i40e_addr_to_hkey(f->macaddr);
  1657. /* Move the element back into MAC filter list*/
  1658. hlist_del(&f->hlist);
  1659. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1660. }
  1661. }
  1662. /**
  1663. * i40e_update_filter_state - Update filter state based on return data
  1664. * from firmware
  1665. * @count: Number of filters added
  1666. * @add_list: return data from fw
  1667. * @head: pointer to first filter in current batch
  1668. *
  1669. * MAC filter entries from list were slated to be added to device. Returns
  1670. * number of successful filters. Note that 0 does NOT mean success!
  1671. **/
  1672. static int
  1673. i40e_update_filter_state(int count,
  1674. struct i40e_aqc_add_macvlan_element_data *add_list,
  1675. struct i40e_mac_filter *add_head)
  1676. {
  1677. int retval = 0;
  1678. int i;
  1679. for (i = 0; i < count; i++) {
  1680. /* Always check status of each filter. We don't need to check
  1681. * the firmware return status because we pre-set the filter
  1682. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1683. * request to the adminq. Thus, if it no longer matches then
  1684. * we know the filter is active.
  1685. */
  1686. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1687. add_head->state = I40E_FILTER_FAILED;
  1688. } else {
  1689. add_head->state = I40E_FILTER_ACTIVE;
  1690. retval++;
  1691. }
  1692. add_head = hlist_entry(add_head->hlist.next,
  1693. typeof(struct i40e_mac_filter),
  1694. hlist);
  1695. }
  1696. return retval;
  1697. }
  1698. /**
  1699. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1700. * @vsi: ptr to the VSI
  1701. * @vsi_name: name to display in messages
  1702. * @list: the list of filters to send to firmware
  1703. * @num_del: the number of filters to delete
  1704. * @retval: Set to -EIO on failure to delete
  1705. *
  1706. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1707. * *retval instead of a return value so that success does not force ret_val to
  1708. * be set to 0. This ensures that a sequence of calls to this function
  1709. * preserve the previous value of *retval on successful delete.
  1710. */
  1711. static
  1712. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1713. struct i40e_aqc_remove_macvlan_element_data *list,
  1714. int num_del, int *retval)
  1715. {
  1716. struct i40e_hw *hw = &vsi->back->hw;
  1717. i40e_status aq_ret;
  1718. int aq_err;
  1719. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1720. aq_err = hw->aq.asq_last_status;
  1721. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1722. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1723. *retval = -EIO;
  1724. dev_info(&vsi->back->pdev->dev,
  1725. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1726. vsi_name, i40e_stat_str(hw, aq_ret),
  1727. i40e_aq_str(hw, aq_err));
  1728. }
  1729. }
  1730. /**
  1731. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1732. * @vsi: ptr to the VSI
  1733. * @vsi_name: name to display in messages
  1734. * @list: the list of filters to send to firmware
  1735. * @add_head: Position in the add hlist
  1736. * @num_add: the number of filters to add
  1737. * @promisc_change: set to true on exit if promiscuous mode was forced on
  1738. *
  1739. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1740. * promisc_changed to true if the firmware has run out of space for more
  1741. * filters.
  1742. */
  1743. static
  1744. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1745. struct i40e_aqc_add_macvlan_element_data *list,
  1746. struct i40e_mac_filter *add_head,
  1747. int num_add, bool *promisc_changed)
  1748. {
  1749. struct i40e_hw *hw = &vsi->back->hw;
  1750. int aq_err, fcnt;
  1751. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1752. aq_err = hw->aq.asq_last_status;
  1753. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1754. if (fcnt != num_add) {
  1755. *promisc_changed = true;
  1756. set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  1757. dev_warn(&vsi->back->pdev->dev,
  1758. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1759. i40e_aq_str(hw, aq_err),
  1760. vsi_name);
  1761. }
  1762. }
  1763. /**
  1764. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1765. * @vsi: pointer to the VSI
  1766. * @f: filter data
  1767. *
  1768. * This function sets or clears the promiscuous broadcast flags for VLAN
  1769. * filters in order to properly receive broadcast frames. Assumes that only
  1770. * broadcast filters are passed.
  1771. **/
  1772. static
  1773. void i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1774. struct i40e_mac_filter *f)
  1775. {
  1776. bool enable = f->state == I40E_FILTER_NEW;
  1777. struct i40e_hw *hw = &vsi->back->hw;
  1778. i40e_status aq_ret;
  1779. if (f->vlan == I40E_VLAN_ANY) {
  1780. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1781. vsi->seid,
  1782. enable,
  1783. NULL);
  1784. } else {
  1785. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1786. vsi->seid,
  1787. enable,
  1788. f->vlan,
  1789. NULL);
  1790. }
  1791. if (aq_ret) {
  1792. dev_warn(&vsi->back->pdev->dev,
  1793. "Error %s setting broadcast promiscuous mode on %s\n",
  1794. i40e_aq_str(hw, hw->aq.asq_last_status),
  1795. vsi_name);
  1796. f->state = I40E_FILTER_FAILED;
  1797. } else if (enable) {
  1798. f->state = I40E_FILTER_ACTIVE;
  1799. }
  1800. }
  1801. /**
  1802. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1803. * @vsi: ptr to the VSI
  1804. *
  1805. * Push any outstanding VSI filter changes through the AdminQ.
  1806. *
  1807. * Returns 0 or error value
  1808. **/
  1809. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1810. {
  1811. struct hlist_head tmp_add_list, tmp_del_list;
  1812. struct i40e_mac_filter *f, *add_head = NULL;
  1813. struct i40e_hw *hw = &vsi->back->hw;
  1814. unsigned int failed_filters = 0;
  1815. unsigned int vlan_filters = 0;
  1816. bool promisc_changed = false;
  1817. char vsi_name[16] = "PF";
  1818. int filter_list_len = 0;
  1819. i40e_status aq_ret = 0;
  1820. u32 changed_flags = 0;
  1821. struct hlist_node *h;
  1822. struct i40e_pf *pf;
  1823. int num_add = 0;
  1824. int num_del = 0;
  1825. int retval = 0;
  1826. u16 cmd_flags;
  1827. int list_size;
  1828. int bkt;
  1829. /* empty array typed pointers, kcalloc later */
  1830. struct i40e_aqc_add_macvlan_element_data *add_list;
  1831. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1832. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1833. usleep_range(1000, 2000);
  1834. pf = vsi->back;
  1835. if (vsi->netdev) {
  1836. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1837. vsi->current_netdev_flags = vsi->netdev->flags;
  1838. }
  1839. INIT_HLIST_HEAD(&tmp_add_list);
  1840. INIT_HLIST_HEAD(&tmp_del_list);
  1841. if (vsi->type == I40E_VSI_SRIOV)
  1842. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  1843. else if (vsi->type != I40E_VSI_MAIN)
  1844. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  1845. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1846. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1847. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1848. /* Create a list of filters to delete. */
  1849. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1850. if (f->state == I40E_FILTER_REMOVE) {
  1851. /* Move the element into temporary del_list */
  1852. hash_del(&f->hlist);
  1853. hlist_add_head(&f->hlist, &tmp_del_list);
  1854. /* Avoid counting removed filters */
  1855. continue;
  1856. }
  1857. if (f->state == I40E_FILTER_NEW) {
  1858. hash_del(&f->hlist);
  1859. hlist_add_head(&f->hlist, &tmp_add_list);
  1860. }
  1861. /* Count the number of active (current and new) VLAN
  1862. * filters we have now. Does not count filters which
  1863. * are marked for deletion.
  1864. */
  1865. if (f->vlan > 0)
  1866. vlan_filters++;
  1867. }
  1868. retval = i40e_correct_mac_vlan_filters(vsi,
  1869. &tmp_add_list,
  1870. &tmp_del_list,
  1871. vlan_filters);
  1872. if (retval)
  1873. goto err_no_memory_locked;
  1874. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1875. }
  1876. /* Now process 'del_list' outside the lock */
  1877. if (!hlist_empty(&tmp_del_list)) {
  1878. filter_list_len = hw->aq.asq_buf_size /
  1879. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1880. list_size = filter_list_len *
  1881. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1882. del_list = kzalloc(list_size, GFP_ATOMIC);
  1883. if (!del_list)
  1884. goto err_no_memory;
  1885. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  1886. cmd_flags = 0;
  1887. /* handle broadcast filters by updating the broadcast
  1888. * promiscuous flag instead of deleting a MAC filter.
  1889. */
  1890. if (is_broadcast_ether_addr(f->macaddr)) {
  1891. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  1892. hlist_del(&f->hlist);
  1893. kfree(f);
  1894. continue;
  1895. }
  1896. /* add to delete list */
  1897. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1898. if (f->vlan == I40E_VLAN_ANY) {
  1899. del_list[num_del].vlan_tag = 0;
  1900. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1901. } else {
  1902. del_list[num_del].vlan_tag =
  1903. cpu_to_le16((u16)(f->vlan));
  1904. }
  1905. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1906. del_list[num_del].flags = cmd_flags;
  1907. num_del++;
  1908. /* flush a full buffer */
  1909. if (num_del == filter_list_len) {
  1910. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  1911. num_del, &retval);
  1912. memset(del_list, 0, list_size);
  1913. num_del = 0;
  1914. }
  1915. /* Release memory for MAC filter entries which were
  1916. * synced up with HW.
  1917. */
  1918. hlist_del(&f->hlist);
  1919. kfree(f);
  1920. }
  1921. if (num_del) {
  1922. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  1923. num_del, &retval);
  1924. }
  1925. kfree(del_list);
  1926. del_list = NULL;
  1927. }
  1928. if (!hlist_empty(&tmp_add_list)) {
  1929. /* Do all the adds now. */
  1930. filter_list_len = hw->aq.asq_buf_size /
  1931. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1932. list_size = filter_list_len *
  1933. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1934. add_list = kzalloc(list_size, GFP_ATOMIC);
  1935. if (!add_list)
  1936. goto err_no_memory;
  1937. num_add = 0;
  1938. hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) {
  1939. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1940. &vsi->state)) {
  1941. f->state = I40E_FILTER_FAILED;
  1942. continue;
  1943. }
  1944. /* handle broadcast filters by updating the broadcast
  1945. * promiscuous flag instead of adding a MAC filter.
  1946. */
  1947. if (is_broadcast_ether_addr(f->macaddr)) {
  1948. u64 key = i40e_addr_to_hkey(f->macaddr);
  1949. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  1950. hlist_del(&f->hlist);
  1951. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1952. continue;
  1953. }
  1954. /* add to add array */
  1955. if (num_add == 0)
  1956. add_head = f;
  1957. cmd_flags = 0;
  1958. ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
  1959. if (f->vlan == I40E_VLAN_ANY) {
  1960. add_list[num_add].vlan_tag = 0;
  1961. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  1962. } else {
  1963. add_list[num_add].vlan_tag =
  1964. cpu_to_le16((u16)(f->vlan));
  1965. }
  1966. add_list[num_add].queue_number = 0;
  1967. /* set invalid match method for later detection */
  1968. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  1969. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1970. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1971. num_add++;
  1972. /* flush a full buffer */
  1973. if (num_add == filter_list_len) {
  1974. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  1975. add_head, num_add,
  1976. &promisc_changed);
  1977. memset(add_list, 0, list_size);
  1978. num_add = 0;
  1979. }
  1980. }
  1981. if (num_add) {
  1982. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  1983. num_add, &promisc_changed);
  1984. }
  1985. /* Now move all of the filters from the temp add list back to
  1986. * the VSI's list.
  1987. */
  1988. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1989. hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) {
  1990. u64 key = i40e_addr_to_hkey(f->macaddr);
  1991. hlist_del(&f->hlist);
  1992. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1993. }
  1994. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1995. kfree(add_list);
  1996. add_list = NULL;
  1997. }
  1998. /* Determine the number of active and failed filters. */
  1999. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2000. vsi->active_filters = 0;
  2001. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2002. if (f->state == I40E_FILTER_ACTIVE)
  2003. vsi->active_filters++;
  2004. else if (f->state == I40E_FILTER_FAILED)
  2005. failed_filters++;
  2006. }
  2007. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2008. /* If promiscuous mode has changed, we need to calculate a new
  2009. * threshold for when we are safe to exit
  2010. */
  2011. if (promisc_changed)
  2012. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2013. /* Check if we are able to exit overflow promiscuous mode. We can
  2014. * safely exit if we didn't just enter, we no longer have any failed
  2015. * filters, and we have reduced filters below the threshold value.
  2016. */
  2017. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) &&
  2018. !promisc_changed && !failed_filters &&
  2019. (vsi->active_filters < vsi->promisc_threshold)) {
  2020. dev_info(&pf->pdev->dev,
  2021. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2022. vsi_name);
  2023. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  2024. promisc_changed = true;
  2025. vsi->promisc_threshold = 0;
  2026. }
  2027. /* if the VF is not trusted do not do promisc */
  2028. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2029. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  2030. goto out;
  2031. }
  2032. /* check for changes in promiscuous modes */
  2033. if (changed_flags & IFF_ALLMULTI) {
  2034. bool cur_multipromisc;
  2035. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2036. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2037. vsi->seid,
  2038. cur_multipromisc,
  2039. NULL);
  2040. if (aq_ret) {
  2041. retval = i40e_aq_rc_to_posix(aq_ret,
  2042. hw->aq.asq_last_status);
  2043. dev_info(&pf->pdev->dev,
  2044. "set multi promisc failed on %s, err %s aq_err %s\n",
  2045. vsi_name,
  2046. i40e_stat_str(hw, aq_ret),
  2047. i40e_aq_str(hw, hw->aq.asq_last_status));
  2048. }
  2049. }
  2050. if ((changed_flags & IFF_PROMISC) ||
  2051. (promisc_changed &&
  2052. test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) {
  2053. bool cur_promisc;
  2054. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2055. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  2056. &vsi->state));
  2057. if ((vsi->type == I40E_VSI_MAIN) &&
  2058. (pf->lan_veb != I40E_NO_VEB) &&
  2059. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  2060. /* set defport ON for Main VSI instead of true promisc
  2061. * this way we will get all unicast/multicast and VLAN
  2062. * promisc behavior but will not get VF or VMDq traffic
  2063. * replicated on the Main VSI.
  2064. */
  2065. if (pf->cur_promisc != cur_promisc) {
  2066. pf->cur_promisc = cur_promisc;
  2067. if (cur_promisc)
  2068. aq_ret =
  2069. i40e_aq_set_default_vsi(hw,
  2070. vsi->seid,
  2071. NULL);
  2072. else
  2073. aq_ret =
  2074. i40e_aq_clear_default_vsi(hw,
  2075. vsi->seid,
  2076. NULL);
  2077. if (aq_ret) {
  2078. retval = i40e_aq_rc_to_posix(aq_ret,
  2079. hw->aq.asq_last_status);
  2080. dev_info(&pf->pdev->dev,
  2081. "Set default VSI failed on %s, err %s, aq_err %s\n",
  2082. vsi_name,
  2083. i40e_stat_str(hw, aq_ret),
  2084. i40e_aq_str(hw,
  2085. hw->aq.asq_last_status));
  2086. }
  2087. }
  2088. } else {
  2089. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  2090. hw,
  2091. vsi->seid,
  2092. cur_promisc, NULL,
  2093. true);
  2094. if (aq_ret) {
  2095. retval =
  2096. i40e_aq_rc_to_posix(aq_ret,
  2097. hw->aq.asq_last_status);
  2098. dev_info(&pf->pdev->dev,
  2099. "set unicast promisc failed on %s, err %s, aq_err %s\n",
  2100. vsi_name,
  2101. i40e_stat_str(hw, aq_ret),
  2102. i40e_aq_str(hw,
  2103. hw->aq.asq_last_status));
  2104. }
  2105. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  2106. hw,
  2107. vsi->seid,
  2108. cur_promisc, NULL);
  2109. if (aq_ret) {
  2110. retval =
  2111. i40e_aq_rc_to_posix(aq_ret,
  2112. hw->aq.asq_last_status);
  2113. dev_info(&pf->pdev->dev,
  2114. "set multicast promisc failed on %s, err %s, aq_err %s\n",
  2115. vsi_name,
  2116. i40e_stat_str(hw, aq_ret),
  2117. i40e_aq_str(hw,
  2118. hw->aq.asq_last_status));
  2119. }
  2120. }
  2121. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  2122. vsi->seid,
  2123. cur_promisc, NULL);
  2124. if (aq_ret) {
  2125. retval = i40e_aq_rc_to_posix(aq_ret,
  2126. pf->hw.aq.asq_last_status);
  2127. dev_info(&pf->pdev->dev,
  2128. "set brdcast promisc failed, err %s, aq_err %s\n",
  2129. i40e_stat_str(hw, aq_ret),
  2130. i40e_aq_str(hw,
  2131. hw->aq.asq_last_status));
  2132. }
  2133. }
  2134. out:
  2135. /* if something went wrong then set the changed flag so we try again */
  2136. if (retval)
  2137. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2138. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  2139. return retval;
  2140. err_no_memory:
  2141. /* Restore elements on the temporary add and delete lists */
  2142. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2143. err_no_memory_locked:
  2144. i40e_undo_filter_entries(vsi, &tmp_del_list);
  2145. i40e_undo_filter_entries(vsi, &tmp_add_list);
  2146. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2147. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2148. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  2149. return -ENOMEM;
  2150. }
  2151. /**
  2152. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2153. * @pf: board private structure
  2154. **/
  2155. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2156. {
  2157. int v;
  2158. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2159. return;
  2160. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2161. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2162. if (pf->vsi[v] &&
  2163. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2164. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2165. if (ret) {
  2166. /* come back and try again later */
  2167. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2168. break;
  2169. }
  2170. }
  2171. }
  2172. }
  2173. /**
  2174. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2175. * @netdev: network interface device structure
  2176. * @new_mtu: new value for maximum frame size
  2177. *
  2178. * Returns 0 on success, negative on failure
  2179. **/
  2180. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2181. {
  2182. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2183. struct i40e_vsi *vsi = np->vsi;
  2184. netdev_info(netdev, "changing MTU from %d to %d\n",
  2185. netdev->mtu, new_mtu);
  2186. netdev->mtu = new_mtu;
  2187. if (netif_running(netdev))
  2188. i40e_vsi_reinit_locked(vsi);
  2189. i40e_notify_client_of_l2_param_changes(vsi);
  2190. return 0;
  2191. }
  2192. /**
  2193. * i40e_ioctl - Access the hwtstamp interface
  2194. * @netdev: network interface device structure
  2195. * @ifr: interface request data
  2196. * @cmd: ioctl command
  2197. **/
  2198. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2199. {
  2200. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2201. struct i40e_pf *pf = np->vsi->back;
  2202. switch (cmd) {
  2203. case SIOCGHWTSTAMP:
  2204. return i40e_ptp_get_ts_config(pf, ifr);
  2205. case SIOCSHWTSTAMP:
  2206. return i40e_ptp_set_ts_config(pf, ifr);
  2207. default:
  2208. return -EOPNOTSUPP;
  2209. }
  2210. }
  2211. /**
  2212. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2213. * @vsi: the vsi being adjusted
  2214. **/
  2215. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2216. {
  2217. struct i40e_vsi_context ctxt;
  2218. i40e_status ret;
  2219. if ((vsi->info.valid_sections &
  2220. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2221. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2222. return; /* already enabled */
  2223. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2224. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2225. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2226. ctxt.seid = vsi->seid;
  2227. ctxt.info = vsi->info;
  2228. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2229. if (ret) {
  2230. dev_info(&vsi->back->pdev->dev,
  2231. "update vlan stripping failed, err %s aq_err %s\n",
  2232. i40e_stat_str(&vsi->back->hw, ret),
  2233. i40e_aq_str(&vsi->back->hw,
  2234. vsi->back->hw.aq.asq_last_status));
  2235. }
  2236. }
  2237. /**
  2238. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2239. * @vsi: the vsi being adjusted
  2240. **/
  2241. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2242. {
  2243. struct i40e_vsi_context ctxt;
  2244. i40e_status ret;
  2245. if ((vsi->info.valid_sections &
  2246. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2247. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2248. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2249. return; /* already disabled */
  2250. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2251. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2252. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2253. ctxt.seid = vsi->seid;
  2254. ctxt.info = vsi->info;
  2255. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2256. if (ret) {
  2257. dev_info(&vsi->back->pdev->dev,
  2258. "update vlan stripping failed, err %s aq_err %s\n",
  2259. i40e_stat_str(&vsi->back->hw, ret),
  2260. i40e_aq_str(&vsi->back->hw,
  2261. vsi->back->hw.aq.asq_last_status));
  2262. }
  2263. }
  2264. /**
  2265. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2266. * @netdev: network interface to be adjusted
  2267. * @features: netdev features to test if VLAN offload is enabled or not
  2268. **/
  2269. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2270. {
  2271. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2272. struct i40e_vsi *vsi = np->vsi;
  2273. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2274. i40e_vlan_stripping_enable(vsi);
  2275. else
  2276. i40e_vlan_stripping_disable(vsi);
  2277. }
  2278. /**
  2279. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2280. * @vsi: the vsi being configured
  2281. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2282. *
  2283. * This is a helper function for adding a new MAC/VLAN filter with the
  2284. * specified VLAN for each existing MAC address already in the hash table.
  2285. * This function does *not* perform any accounting to update filters based on
  2286. * VLAN mode.
  2287. *
  2288. * NOTE: this function expects to be called while under the
  2289. * mac_filter_hash_lock
  2290. **/
  2291. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2292. {
  2293. struct i40e_mac_filter *f, *add_f;
  2294. struct hlist_node *h;
  2295. int bkt;
  2296. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2297. if (f->state == I40E_FILTER_REMOVE)
  2298. continue;
  2299. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2300. if (!add_f) {
  2301. dev_info(&vsi->back->pdev->dev,
  2302. "Could not add vlan filter %d for %pM\n",
  2303. vid, f->macaddr);
  2304. return -ENOMEM;
  2305. }
  2306. }
  2307. return 0;
  2308. }
  2309. /**
  2310. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2311. * @vsi: the VSI being configured
  2312. * @vid: VLAN id to be added (0 = untagged only , -1 = any)
  2313. **/
  2314. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  2315. {
  2316. int err;
  2317. /* Locked once because all functions invoked below iterates list*/
  2318. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2319. err = i40e_add_vlan_all_mac(vsi, vid);
  2320. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2321. if (err)
  2322. return err;
  2323. /* schedule our worker thread which will take care of
  2324. * applying the new filter changes
  2325. */
  2326. i40e_service_event_schedule(vsi->back);
  2327. return 0;
  2328. }
  2329. /**
  2330. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2331. * @vsi: the vsi being configured
  2332. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2333. *
  2334. * This function should be used to remove all VLAN filters which match the
  2335. * given VID. It does not schedule the service event and does not take the
  2336. * mac_filter_hash_lock so it may be combined with other operations under
  2337. * a single invocation of the mac_filter_hash_lock.
  2338. *
  2339. * NOTE: this function expects to be called while under the
  2340. * mac_filter_hash_lock
  2341. */
  2342. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2343. {
  2344. struct i40e_mac_filter *f;
  2345. struct hlist_node *h;
  2346. int bkt;
  2347. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2348. if (f->vlan == vid)
  2349. __i40e_del_filter(vsi, f);
  2350. }
  2351. }
  2352. /**
  2353. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2354. * @vsi: the VSI being configured
  2355. * @vid: VLAN id to be removed (0 = untagged only , -1 = any)
  2356. **/
  2357. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  2358. {
  2359. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2360. i40e_rm_vlan_all_mac(vsi, vid);
  2361. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2362. /* schedule our worker thread which will take care of
  2363. * applying the new filter changes
  2364. */
  2365. i40e_service_event_schedule(vsi->back);
  2366. }
  2367. /**
  2368. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2369. * @netdev: network interface to be adjusted
  2370. * @vid: vlan id to be added
  2371. *
  2372. * net_device_ops implementation for adding vlan ids
  2373. **/
  2374. #ifdef I40E_FCOE
  2375. int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2376. __always_unused __be16 proto, u16 vid)
  2377. #else
  2378. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2379. __always_unused __be16 proto, u16 vid)
  2380. #endif
  2381. {
  2382. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2383. struct i40e_vsi *vsi = np->vsi;
  2384. int ret = 0;
  2385. if (vid >= VLAN_N_VID)
  2386. return -EINVAL;
  2387. /* If the network stack called us with vid = 0 then
  2388. * it is asking to receive priority tagged packets with
  2389. * vlan id 0. Our HW receives them by default when configured
  2390. * to receive untagged packets so there is no need to add an
  2391. * extra filter for vlan 0 tagged packets.
  2392. */
  2393. if (vid)
  2394. ret = i40e_vsi_add_vlan(vsi, vid);
  2395. if (!ret)
  2396. set_bit(vid, vsi->active_vlans);
  2397. return ret;
  2398. }
  2399. /**
  2400. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2401. * @netdev: network interface to be adjusted
  2402. * @vid: vlan id to be removed
  2403. *
  2404. * net_device_ops implementation for removing vlan ids
  2405. **/
  2406. #ifdef I40E_FCOE
  2407. int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2408. __always_unused __be16 proto, u16 vid)
  2409. #else
  2410. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2411. __always_unused __be16 proto, u16 vid)
  2412. #endif
  2413. {
  2414. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2415. struct i40e_vsi *vsi = np->vsi;
  2416. /* return code is ignored as there is nothing a user
  2417. * can do about failure to remove and a log message was
  2418. * already printed from the other function
  2419. */
  2420. i40e_vsi_kill_vlan(vsi, vid);
  2421. clear_bit(vid, vsi->active_vlans);
  2422. return 0;
  2423. }
  2424. /**
  2425. * i40e_macaddr_init - explicitly write the mac address filters
  2426. *
  2427. * @vsi: pointer to the vsi
  2428. * @macaddr: the MAC address
  2429. *
  2430. * This is needed when the macaddr has been obtained by other
  2431. * means than the default, e.g., from Open Firmware or IDPROM.
  2432. * Returns 0 on success, negative on failure
  2433. **/
  2434. static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
  2435. {
  2436. int ret;
  2437. struct i40e_aqc_add_macvlan_element_data element;
  2438. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  2439. I40E_AQC_WRITE_TYPE_LAA_WOL,
  2440. macaddr, NULL);
  2441. if (ret) {
  2442. dev_info(&vsi->back->pdev->dev,
  2443. "Addr change for VSI failed: %d\n", ret);
  2444. return -EADDRNOTAVAIL;
  2445. }
  2446. memset(&element, 0, sizeof(element));
  2447. ether_addr_copy(element.mac_addr, macaddr);
  2448. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  2449. ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
  2450. if (ret) {
  2451. dev_info(&vsi->back->pdev->dev,
  2452. "add filter failed err %s aq_err %s\n",
  2453. i40e_stat_str(&vsi->back->hw, ret),
  2454. i40e_aq_str(&vsi->back->hw,
  2455. vsi->back->hw.aq.asq_last_status));
  2456. }
  2457. return ret;
  2458. }
  2459. /**
  2460. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2461. * @vsi: the vsi being brought back up
  2462. **/
  2463. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2464. {
  2465. u16 vid;
  2466. if (!vsi->netdev)
  2467. return;
  2468. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2469. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2470. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2471. vid);
  2472. }
  2473. /**
  2474. * i40e_vsi_add_pvid - Add pvid for the VSI
  2475. * @vsi: the vsi being adjusted
  2476. * @vid: the vlan id to set as a PVID
  2477. **/
  2478. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2479. {
  2480. struct i40e_vsi_context ctxt;
  2481. i40e_status ret;
  2482. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2483. vsi->info.pvid = cpu_to_le16(vid);
  2484. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2485. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2486. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2487. ctxt.seid = vsi->seid;
  2488. ctxt.info = vsi->info;
  2489. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2490. if (ret) {
  2491. dev_info(&vsi->back->pdev->dev,
  2492. "add pvid failed, err %s aq_err %s\n",
  2493. i40e_stat_str(&vsi->back->hw, ret),
  2494. i40e_aq_str(&vsi->back->hw,
  2495. vsi->back->hw.aq.asq_last_status));
  2496. return -ENOENT;
  2497. }
  2498. return 0;
  2499. }
  2500. /**
  2501. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2502. * @vsi: the vsi being adjusted
  2503. *
  2504. * Just use the vlan_rx_register() service to put it back to normal
  2505. **/
  2506. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2507. {
  2508. i40e_vlan_stripping_disable(vsi);
  2509. vsi->info.pvid = 0;
  2510. }
  2511. /**
  2512. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2513. * @vsi: ptr to the VSI
  2514. *
  2515. * If this function returns with an error, then it's possible one or
  2516. * more of the rings is populated (while the rest are not). It is the
  2517. * callers duty to clean those orphaned rings.
  2518. *
  2519. * Return 0 on success, negative on failure
  2520. **/
  2521. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2522. {
  2523. int i, err = 0;
  2524. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2525. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2526. return err;
  2527. }
  2528. /**
  2529. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2530. * @vsi: ptr to the VSI
  2531. *
  2532. * Free VSI's transmit software resources
  2533. **/
  2534. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2535. {
  2536. int i;
  2537. if (!vsi->tx_rings)
  2538. return;
  2539. for (i = 0; i < vsi->num_queue_pairs; i++)
  2540. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2541. i40e_free_tx_resources(vsi->tx_rings[i]);
  2542. }
  2543. /**
  2544. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2545. * @vsi: ptr to the VSI
  2546. *
  2547. * If this function returns with an error, then it's possible one or
  2548. * more of the rings is populated (while the rest are not). It is the
  2549. * callers duty to clean those orphaned rings.
  2550. *
  2551. * Return 0 on success, negative on failure
  2552. **/
  2553. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2554. {
  2555. int i, err = 0;
  2556. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2557. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2558. #ifdef I40E_FCOE
  2559. i40e_fcoe_setup_ddp_resources(vsi);
  2560. #endif
  2561. return err;
  2562. }
  2563. /**
  2564. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2565. * @vsi: ptr to the VSI
  2566. *
  2567. * Free all receive software resources
  2568. **/
  2569. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2570. {
  2571. int i;
  2572. if (!vsi->rx_rings)
  2573. return;
  2574. for (i = 0; i < vsi->num_queue_pairs; i++)
  2575. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2576. i40e_free_rx_resources(vsi->rx_rings[i]);
  2577. #ifdef I40E_FCOE
  2578. i40e_fcoe_free_ddp_resources(vsi);
  2579. #endif
  2580. }
  2581. /**
  2582. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2583. * @ring: The Tx ring to configure
  2584. *
  2585. * This enables/disables XPS for a given Tx descriptor ring
  2586. * based on the TCs enabled for the VSI that ring belongs to.
  2587. **/
  2588. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2589. {
  2590. struct i40e_vsi *vsi = ring->vsi;
  2591. cpumask_var_t mask;
  2592. if (!ring->q_vector || !ring->netdev)
  2593. return;
  2594. /* Single TC mode enable XPS */
  2595. if (vsi->tc_config.numtc <= 1) {
  2596. if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2597. netif_set_xps_queue(ring->netdev,
  2598. &ring->q_vector->affinity_mask,
  2599. ring->queue_index);
  2600. } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
  2601. /* Disable XPS to allow selection based on TC */
  2602. bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
  2603. netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
  2604. free_cpumask_var(mask);
  2605. }
  2606. /* schedule our worker thread which will take care of
  2607. * applying the new filter changes
  2608. */
  2609. i40e_service_event_schedule(vsi->back);
  2610. }
  2611. /**
  2612. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2613. * @ring: The Tx ring to configure
  2614. *
  2615. * Configure the Tx descriptor ring in the HMC context.
  2616. **/
  2617. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2618. {
  2619. struct i40e_vsi *vsi = ring->vsi;
  2620. u16 pf_q = vsi->base_queue + ring->queue_index;
  2621. struct i40e_hw *hw = &vsi->back->hw;
  2622. struct i40e_hmc_obj_txq tx_ctx;
  2623. i40e_status err = 0;
  2624. u32 qtx_ctl = 0;
  2625. /* some ATR related tx ring init */
  2626. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2627. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2628. ring->atr_count = 0;
  2629. } else {
  2630. ring->atr_sample_rate = 0;
  2631. }
  2632. /* configure XPS */
  2633. i40e_config_xps_tx_ring(ring);
  2634. /* clear the context structure first */
  2635. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2636. tx_ctx.new_context = 1;
  2637. tx_ctx.base = (ring->dma / 128);
  2638. tx_ctx.qlen = ring->count;
  2639. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2640. I40E_FLAG_FD_ATR_ENABLED));
  2641. #ifdef I40E_FCOE
  2642. tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2643. #endif
  2644. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2645. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2646. if (vsi->type != I40E_VSI_FDIR)
  2647. tx_ctx.head_wb_ena = 1;
  2648. tx_ctx.head_wb_addr = ring->dma +
  2649. (ring->count * sizeof(struct i40e_tx_desc));
  2650. /* As part of VSI creation/update, FW allocates certain
  2651. * Tx arbitration queue sets for each TC enabled for
  2652. * the VSI. The FW returns the handles to these queue
  2653. * sets as part of the response buffer to Add VSI,
  2654. * Update VSI, etc. AQ commands. It is expected that
  2655. * these queue set handles be associated with the Tx
  2656. * queues by the driver as part of the TX queue context
  2657. * initialization. This has to be done regardless of
  2658. * DCB as by default everything is mapped to TC0.
  2659. */
  2660. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2661. tx_ctx.rdylist_act = 0;
  2662. /* clear the context in the HMC */
  2663. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2664. if (err) {
  2665. dev_info(&vsi->back->pdev->dev,
  2666. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2667. ring->queue_index, pf_q, err);
  2668. return -ENOMEM;
  2669. }
  2670. /* set the context in the HMC */
  2671. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2672. if (err) {
  2673. dev_info(&vsi->back->pdev->dev,
  2674. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2675. ring->queue_index, pf_q, err);
  2676. return -ENOMEM;
  2677. }
  2678. /* Now associate this queue with this PCI function */
  2679. if (vsi->type == I40E_VSI_VMDQ2) {
  2680. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2681. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2682. I40E_QTX_CTL_VFVM_INDX_MASK;
  2683. } else {
  2684. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2685. }
  2686. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2687. I40E_QTX_CTL_PF_INDX_MASK);
  2688. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2689. i40e_flush(hw);
  2690. /* cache tail off for easier writes later */
  2691. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2692. return 0;
  2693. }
  2694. /**
  2695. * i40e_configure_rx_ring - Configure a receive ring context
  2696. * @ring: The Rx ring to configure
  2697. *
  2698. * Configure the Rx descriptor ring in the HMC context.
  2699. **/
  2700. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2701. {
  2702. struct i40e_vsi *vsi = ring->vsi;
  2703. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2704. u16 pf_q = vsi->base_queue + ring->queue_index;
  2705. struct i40e_hw *hw = &vsi->back->hw;
  2706. struct i40e_hmc_obj_rxq rx_ctx;
  2707. i40e_status err = 0;
  2708. ring->state = 0;
  2709. /* clear the context structure first */
  2710. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2711. ring->rx_buf_len = vsi->rx_buf_len;
  2712. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2713. rx_ctx.base = (ring->dma / 128);
  2714. rx_ctx.qlen = ring->count;
  2715. /* use 32 byte descriptors */
  2716. rx_ctx.dsize = 1;
  2717. /* descriptor type is always zero
  2718. * rx_ctx.dtype = 0;
  2719. */
  2720. rx_ctx.hsplit_0 = 0;
  2721. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2722. if (hw->revision_id == 0)
  2723. rx_ctx.lrxqthresh = 0;
  2724. else
  2725. rx_ctx.lrxqthresh = 2;
  2726. rx_ctx.crcstrip = 1;
  2727. rx_ctx.l2tsel = 1;
  2728. /* this controls whether VLAN is stripped from inner headers */
  2729. rx_ctx.showiv = 0;
  2730. #ifdef I40E_FCOE
  2731. rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2732. #endif
  2733. /* set the prefena field to 1 because the manual says to */
  2734. rx_ctx.prefena = 1;
  2735. /* clear the context in the HMC */
  2736. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2737. if (err) {
  2738. dev_info(&vsi->back->pdev->dev,
  2739. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2740. ring->queue_index, pf_q, err);
  2741. return -ENOMEM;
  2742. }
  2743. /* set the context in the HMC */
  2744. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2745. if (err) {
  2746. dev_info(&vsi->back->pdev->dev,
  2747. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2748. ring->queue_index, pf_q, err);
  2749. return -ENOMEM;
  2750. }
  2751. /* cache tail for quicker writes, and clear the reg before use */
  2752. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2753. writel(0, ring->tail);
  2754. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2755. return 0;
  2756. }
  2757. /**
  2758. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2759. * @vsi: VSI structure describing this set of rings and resources
  2760. *
  2761. * Configure the Tx VSI for operation.
  2762. **/
  2763. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2764. {
  2765. int err = 0;
  2766. u16 i;
  2767. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2768. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2769. return err;
  2770. }
  2771. /**
  2772. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2773. * @vsi: the VSI being configured
  2774. *
  2775. * Configure the Rx VSI for operation.
  2776. **/
  2777. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2778. {
  2779. int err = 0;
  2780. u16 i;
  2781. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2782. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2783. + ETH_FCS_LEN + VLAN_HLEN;
  2784. else
  2785. vsi->max_frame = I40E_RXBUFFER_2048;
  2786. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2787. #ifdef I40E_FCOE
  2788. /* setup rx buffer for FCoE */
  2789. if ((vsi->type == I40E_VSI_FCOE) &&
  2790. (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
  2791. vsi->rx_buf_len = I40E_RXBUFFER_3072;
  2792. vsi->max_frame = I40E_RXBUFFER_3072;
  2793. }
  2794. #endif /* I40E_FCOE */
  2795. /* round up for the chip's needs */
  2796. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2797. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2798. /* set up individual rings */
  2799. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2800. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2801. return err;
  2802. }
  2803. /**
  2804. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2805. * @vsi: ptr to the VSI
  2806. **/
  2807. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2808. {
  2809. struct i40e_ring *tx_ring, *rx_ring;
  2810. u16 qoffset, qcount;
  2811. int i, n;
  2812. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2813. /* Reset the TC information */
  2814. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2815. rx_ring = vsi->rx_rings[i];
  2816. tx_ring = vsi->tx_rings[i];
  2817. rx_ring->dcb_tc = 0;
  2818. tx_ring->dcb_tc = 0;
  2819. }
  2820. }
  2821. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2822. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2823. continue;
  2824. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2825. qcount = vsi->tc_config.tc_info[n].qcount;
  2826. for (i = qoffset; i < (qoffset + qcount); i++) {
  2827. rx_ring = vsi->rx_rings[i];
  2828. tx_ring = vsi->tx_rings[i];
  2829. rx_ring->dcb_tc = n;
  2830. tx_ring->dcb_tc = n;
  2831. }
  2832. }
  2833. }
  2834. /**
  2835. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2836. * @vsi: ptr to the VSI
  2837. **/
  2838. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2839. {
  2840. struct i40e_pf *pf = vsi->back;
  2841. int err;
  2842. if (vsi->netdev)
  2843. i40e_set_rx_mode(vsi->netdev);
  2844. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  2845. err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  2846. if (err) {
  2847. dev_warn(&pf->pdev->dev,
  2848. "could not set up macaddr; err %d\n", err);
  2849. }
  2850. }
  2851. }
  2852. /**
  2853. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2854. * @vsi: Pointer to the targeted VSI
  2855. *
  2856. * This function replays the hlist on the hw where all the SB Flow Director
  2857. * filters were saved.
  2858. **/
  2859. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2860. {
  2861. struct i40e_fdir_filter *filter;
  2862. struct i40e_pf *pf = vsi->back;
  2863. struct hlist_node *node;
  2864. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2865. return;
  2866. hlist_for_each_entry_safe(filter, node,
  2867. &pf->fdir_filter_list, fdir_node) {
  2868. i40e_add_del_fdir(vsi, filter, true);
  2869. }
  2870. }
  2871. /**
  2872. * i40e_vsi_configure - Set up the VSI for action
  2873. * @vsi: the VSI being configured
  2874. **/
  2875. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2876. {
  2877. int err;
  2878. i40e_set_vsi_rx_mode(vsi);
  2879. i40e_restore_vlan(vsi);
  2880. i40e_vsi_config_dcb_rings(vsi);
  2881. err = i40e_vsi_configure_tx(vsi);
  2882. if (!err)
  2883. err = i40e_vsi_configure_rx(vsi);
  2884. return err;
  2885. }
  2886. /**
  2887. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2888. * @vsi: the VSI being configured
  2889. **/
  2890. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2891. {
  2892. struct i40e_pf *pf = vsi->back;
  2893. struct i40e_hw *hw = &pf->hw;
  2894. u16 vector;
  2895. int i, q;
  2896. u32 qp;
  2897. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2898. * and PFINT_LNKLSTn registers, e.g.:
  2899. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2900. */
  2901. qp = vsi->base_queue;
  2902. vector = vsi->base_vector;
  2903. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2904. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  2905. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2906. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  2907. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2908. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2909. q_vector->rx.itr);
  2910. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  2911. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2912. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2913. q_vector->tx.itr);
  2914. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  2915. INTRL_USEC_TO_REG(vsi->int_rate_limit));
  2916. /* Linked list for the queuepairs assigned to this vector */
  2917. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2918. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2919. u32 val;
  2920. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2921. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2922. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2923. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2924. (I40E_QUEUE_TYPE_TX
  2925. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2926. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2927. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2928. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2929. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2930. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2931. (I40E_QUEUE_TYPE_RX
  2932. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2933. /* Terminate the linked list */
  2934. if (q == (q_vector->num_ringpairs - 1))
  2935. val |= (I40E_QUEUE_END_OF_LIST
  2936. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2937. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2938. qp++;
  2939. }
  2940. }
  2941. i40e_flush(hw);
  2942. }
  2943. /**
  2944. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2945. * @hw: ptr to the hardware info
  2946. **/
  2947. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  2948. {
  2949. struct i40e_hw *hw = &pf->hw;
  2950. u32 val;
  2951. /* clear things first */
  2952. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2953. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2954. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2955. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2956. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2957. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2958. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2959. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2960. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2961. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2962. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  2963. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  2964. if (pf->flags & I40E_FLAG_PTP)
  2965. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2966. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2967. /* SW_ITR_IDX = 0, but don't change INTENA */
  2968. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2969. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2970. /* OTHER_ITR_IDX = 0 */
  2971. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2972. }
  2973. /**
  2974. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2975. * @vsi: the VSI being configured
  2976. **/
  2977. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2978. {
  2979. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2980. struct i40e_pf *pf = vsi->back;
  2981. struct i40e_hw *hw = &pf->hw;
  2982. u32 val;
  2983. /* set the ITR configuration */
  2984. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2985. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  2986. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2987. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2988. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  2989. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2990. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2991. i40e_enable_misc_int_causes(pf);
  2992. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2993. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2994. /* Associate the queue pair to the vector and enable the queue int */
  2995. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2996. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2997. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2998. wr32(hw, I40E_QINT_RQCTL(0), val);
  2999. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3000. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3001. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3002. wr32(hw, I40E_QINT_TQCTL(0), val);
  3003. i40e_flush(hw);
  3004. }
  3005. /**
  3006. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3007. * @pf: board private structure
  3008. **/
  3009. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3010. {
  3011. struct i40e_hw *hw = &pf->hw;
  3012. wr32(hw, I40E_PFINT_DYN_CTL0,
  3013. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3014. i40e_flush(hw);
  3015. }
  3016. /**
  3017. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3018. * @pf: board private structure
  3019. * @clearpba: true when all pending interrupt events should be cleared
  3020. **/
  3021. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
  3022. {
  3023. struct i40e_hw *hw = &pf->hw;
  3024. u32 val;
  3025. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3026. (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
  3027. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3028. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3029. i40e_flush(hw);
  3030. }
  3031. /**
  3032. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3033. * @irq: interrupt number
  3034. * @data: pointer to a q_vector
  3035. **/
  3036. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3037. {
  3038. struct i40e_q_vector *q_vector = data;
  3039. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3040. return IRQ_HANDLED;
  3041. napi_schedule_irqoff(&q_vector->napi);
  3042. return IRQ_HANDLED;
  3043. }
  3044. /**
  3045. * i40e_irq_affinity_notify - Callback for affinity changes
  3046. * @notify: context as to what irq was changed
  3047. * @mask: the new affinity mask
  3048. *
  3049. * This is a callback function used by the irq_set_affinity_notifier function
  3050. * so that we may register to receive changes to the irq affinity masks.
  3051. **/
  3052. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3053. const cpumask_t *mask)
  3054. {
  3055. struct i40e_q_vector *q_vector =
  3056. container_of(notify, struct i40e_q_vector, affinity_notify);
  3057. q_vector->affinity_mask = *mask;
  3058. }
  3059. /**
  3060. * i40e_irq_affinity_release - Callback for affinity notifier release
  3061. * @ref: internal core kernel usage
  3062. *
  3063. * This is a callback function used by the irq_set_affinity_notifier function
  3064. * to inform the current notification subscriber that they will no longer
  3065. * receive notifications.
  3066. **/
  3067. static void i40e_irq_affinity_release(struct kref *ref) {}
  3068. /**
  3069. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3070. * @vsi: the VSI being configured
  3071. * @basename: name for the vector
  3072. *
  3073. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3074. **/
  3075. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3076. {
  3077. int q_vectors = vsi->num_q_vectors;
  3078. struct i40e_pf *pf = vsi->back;
  3079. int base = vsi->base_vector;
  3080. int rx_int_idx = 0;
  3081. int tx_int_idx = 0;
  3082. int vector, err;
  3083. int irq_num;
  3084. for (vector = 0; vector < q_vectors; vector++) {
  3085. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3086. irq_num = pf->msix_entries[base + vector].vector;
  3087. if (q_vector->tx.ring && q_vector->rx.ring) {
  3088. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3089. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3090. tx_int_idx++;
  3091. } else if (q_vector->rx.ring) {
  3092. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3093. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3094. } else if (q_vector->tx.ring) {
  3095. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3096. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3097. } else {
  3098. /* skip this unused q_vector */
  3099. continue;
  3100. }
  3101. err = request_irq(irq_num,
  3102. vsi->irq_handler,
  3103. 0,
  3104. q_vector->name,
  3105. q_vector);
  3106. if (err) {
  3107. dev_info(&pf->pdev->dev,
  3108. "MSIX request_irq failed, error: %d\n", err);
  3109. goto free_queue_irqs;
  3110. }
  3111. /* register for affinity change notifications */
  3112. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3113. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3114. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3115. /* assign the mask for this irq */
  3116. irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
  3117. }
  3118. vsi->irqs_ready = true;
  3119. return 0;
  3120. free_queue_irqs:
  3121. while (vector) {
  3122. vector--;
  3123. irq_num = pf->msix_entries[base + vector].vector;
  3124. irq_set_affinity_notifier(irq_num, NULL);
  3125. irq_set_affinity_hint(irq_num, NULL);
  3126. free_irq(irq_num, &vsi->q_vectors[vector]);
  3127. }
  3128. return err;
  3129. }
  3130. /**
  3131. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3132. * @vsi: the VSI being un-configured
  3133. **/
  3134. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3135. {
  3136. struct i40e_pf *pf = vsi->back;
  3137. struct i40e_hw *hw = &pf->hw;
  3138. int base = vsi->base_vector;
  3139. int i;
  3140. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3141. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  3142. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  3143. }
  3144. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3145. for (i = vsi->base_vector;
  3146. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3147. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3148. i40e_flush(hw);
  3149. for (i = 0; i < vsi->num_q_vectors; i++)
  3150. synchronize_irq(pf->msix_entries[i + base].vector);
  3151. } else {
  3152. /* Legacy and MSI mode - this stops all interrupt handling */
  3153. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3154. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3155. i40e_flush(hw);
  3156. synchronize_irq(pf->pdev->irq);
  3157. }
  3158. }
  3159. /**
  3160. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3161. * @vsi: the VSI being configured
  3162. **/
  3163. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3164. {
  3165. struct i40e_pf *pf = vsi->back;
  3166. int i;
  3167. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3168. for (i = 0; i < vsi->num_q_vectors; i++)
  3169. i40e_irq_dynamic_enable(vsi, i);
  3170. } else {
  3171. i40e_irq_dynamic_enable_icr0(pf, true);
  3172. }
  3173. i40e_flush(&pf->hw);
  3174. return 0;
  3175. }
  3176. /**
  3177. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  3178. * @pf: board private structure
  3179. **/
  3180. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  3181. {
  3182. /* Disable ICR 0 */
  3183. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3184. i40e_flush(&pf->hw);
  3185. }
  3186. /**
  3187. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3188. * @irq: interrupt number
  3189. * @data: pointer to a q_vector
  3190. *
  3191. * This is the handler used for all MSI/Legacy interrupts, and deals
  3192. * with both queue and non-queue interrupts. This is also used in
  3193. * MSIX mode to handle the non-queue interrupts.
  3194. **/
  3195. static irqreturn_t i40e_intr(int irq, void *data)
  3196. {
  3197. struct i40e_pf *pf = (struct i40e_pf *)data;
  3198. struct i40e_hw *hw = &pf->hw;
  3199. irqreturn_t ret = IRQ_NONE;
  3200. u32 icr0, icr0_remaining;
  3201. u32 val, ena_mask;
  3202. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3203. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3204. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3205. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3206. goto enable_intr;
  3207. /* if interrupt but no bits showing, must be SWINT */
  3208. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3209. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3210. pf->sw_int_count++;
  3211. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3212. (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3213. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3214. icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3215. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3216. }
  3217. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3218. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3219. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3220. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3221. /* We do not have a way to disarm Queue causes while leaving
  3222. * interrupt enabled for all other causes, ideally
  3223. * interrupt should be disabled while we are in NAPI but
  3224. * this is not a performance path and napi_schedule()
  3225. * can deal with rescheduling.
  3226. */
  3227. if (!test_bit(__I40E_DOWN, &pf->state))
  3228. napi_schedule_irqoff(&q_vector->napi);
  3229. }
  3230. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3231. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3232. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  3233. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3234. }
  3235. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3236. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3237. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  3238. }
  3239. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3240. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3241. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  3242. }
  3243. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3244. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  3245. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  3246. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3247. val = rd32(hw, I40E_GLGEN_RSTAT);
  3248. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3249. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3250. if (val == I40E_RESET_CORER) {
  3251. pf->corer_count++;
  3252. } else if (val == I40E_RESET_GLOBR) {
  3253. pf->globr_count++;
  3254. } else if (val == I40E_RESET_EMPR) {
  3255. pf->empr_count++;
  3256. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
  3257. }
  3258. }
  3259. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3260. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3261. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3262. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3263. rd32(hw, I40E_PFHMC_ERRORINFO),
  3264. rd32(hw, I40E_PFHMC_ERRORDATA));
  3265. }
  3266. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3267. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3268. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3269. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3270. i40e_ptp_tx_hwtstamp(pf);
  3271. }
  3272. }
  3273. /* If a critical error is pending we have no choice but to reset the
  3274. * device.
  3275. * Report and mask out any remaining unexpected interrupts.
  3276. */
  3277. icr0_remaining = icr0 & ena_mask;
  3278. if (icr0_remaining) {
  3279. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3280. icr0_remaining);
  3281. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3282. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3283. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3284. dev_info(&pf->pdev->dev, "device will be reset\n");
  3285. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  3286. i40e_service_event_schedule(pf);
  3287. }
  3288. ena_mask &= ~icr0_remaining;
  3289. }
  3290. ret = IRQ_HANDLED;
  3291. enable_intr:
  3292. /* re-enable interrupt causes */
  3293. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3294. if (!test_bit(__I40E_DOWN, &pf->state)) {
  3295. i40e_service_event_schedule(pf);
  3296. i40e_irq_dynamic_enable_icr0(pf, false);
  3297. }
  3298. return ret;
  3299. }
  3300. /**
  3301. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3302. * @tx_ring: tx ring to clean
  3303. * @budget: how many cleans we're allowed
  3304. *
  3305. * Returns true if there's any budget left (e.g. the clean is finished)
  3306. **/
  3307. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3308. {
  3309. struct i40e_vsi *vsi = tx_ring->vsi;
  3310. u16 i = tx_ring->next_to_clean;
  3311. struct i40e_tx_buffer *tx_buf;
  3312. struct i40e_tx_desc *tx_desc;
  3313. tx_buf = &tx_ring->tx_bi[i];
  3314. tx_desc = I40E_TX_DESC(tx_ring, i);
  3315. i -= tx_ring->count;
  3316. do {
  3317. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3318. /* if next_to_watch is not set then there is no work pending */
  3319. if (!eop_desc)
  3320. break;
  3321. /* prevent any other reads prior to eop_desc */
  3322. read_barrier_depends();
  3323. /* if the descriptor isn't done, no work yet to do */
  3324. if (!(eop_desc->cmd_type_offset_bsz &
  3325. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3326. break;
  3327. /* clear next_to_watch to prevent false hangs */
  3328. tx_buf->next_to_watch = NULL;
  3329. tx_desc->buffer_addr = 0;
  3330. tx_desc->cmd_type_offset_bsz = 0;
  3331. /* move past filter desc */
  3332. tx_buf++;
  3333. tx_desc++;
  3334. i++;
  3335. if (unlikely(!i)) {
  3336. i -= tx_ring->count;
  3337. tx_buf = tx_ring->tx_bi;
  3338. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3339. }
  3340. /* unmap skb header data */
  3341. dma_unmap_single(tx_ring->dev,
  3342. dma_unmap_addr(tx_buf, dma),
  3343. dma_unmap_len(tx_buf, len),
  3344. DMA_TO_DEVICE);
  3345. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3346. kfree(tx_buf->raw_buf);
  3347. tx_buf->raw_buf = NULL;
  3348. tx_buf->tx_flags = 0;
  3349. tx_buf->next_to_watch = NULL;
  3350. dma_unmap_len_set(tx_buf, len, 0);
  3351. tx_desc->buffer_addr = 0;
  3352. tx_desc->cmd_type_offset_bsz = 0;
  3353. /* move us past the eop_desc for start of next FD desc */
  3354. tx_buf++;
  3355. tx_desc++;
  3356. i++;
  3357. if (unlikely(!i)) {
  3358. i -= tx_ring->count;
  3359. tx_buf = tx_ring->tx_bi;
  3360. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3361. }
  3362. /* update budget accounting */
  3363. budget--;
  3364. } while (likely(budget));
  3365. i += tx_ring->count;
  3366. tx_ring->next_to_clean = i;
  3367. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3368. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3369. return budget > 0;
  3370. }
  3371. /**
  3372. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3373. * @irq: interrupt number
  3374. * @data: pointer to a q_vector
  3375. **/
  3376. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3377. {
  3378. struct i40e_q_vector *q_vector = data;
  3379. struct i40e_vsi *vsi;
  3380. if (!q_vector->tx.ring)
  3381. return IRQ_HANDLED;
  3382. vsi = q_vector->tx.ring->vsi;
  3383. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3384. return IRQ_HANDLED;
  3385. }
  3386. /**
  3387. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3388. * @vsi: the VSI being configured
  3389. * @v_idx: vector index
  3390. * @qp_idx: queue pair index
  3391. **/
  3392. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3393. {
  3394. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3395. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3396. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3397. tx_ring->q_vector = q_vector;
  3398. tx_ring->next = q_vector->tx.ring;
  3399. q_vector->tx.ring = tx_ring;
  3400. q_vector->tx.count++;
  3401. rx_ring->q_vector = q_vector;
  3402. rx_ring->next = q_vector->rx.ring;
  3403. q_vector->rx.ring = rx_ring;
  3404. q_vector->rx.count++;
  3405. }
  3406. /**
  3407. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3408. * @vsi: the VSI being configured
  3409. *
  3410. * This function maps descriptor rings to the queue-specific vectors
  3411. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3412. * one vector per queue pair, but on a constrained vector budget, we
  3413. * group the queue pairs as "efficiently" as possible.
  3414. **/
  3415. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3416. {
  3417. int qp_remaining = vsi->num_queue_pairs;
  3418. int q_vectors = vsi->num_q_vectors;
  3419. int num_ringpairs;
  3420. int v_start = 0;
  3421. int qp_idx = 0;
  3422. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3423. * group them so there are multiple queues per vector.
  3424. * It is also important to go through all the vectors available to be
  3425. * sure that if we don't use all the vectors, that the remaining vectors
  3426. * are cleared. This is especially important when decreasing the
  3427. * number of queues in use.
  3428. */
  3429. for (; v_start < q_vectors; v_start++) {
  3430. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3431. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3432. q_vector->num_ringpairs = num_ringpairs;
  3433. q_vector->rx.count = 0;
  3434. q_vector->tx.count = 0;
  3435. q_vector->rx.ring = NULL;
  3436. q_vector->tx.ring = NULL;
  3437. while (num_ringpairs--) {
  3438. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3439. qp_idx++;
  3440. qp_remaining--;
  3441. }
  3442. }
  3443. }
  3444. /**
  3445. * i40e_vsi_request_irq - Request IRQ from the OS
  3446. * @vsi: the VSI being configured
  3447. * @basename: name for the vector
  3448. **/
  3449. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3450. {
  3451. struct i40e_pf *pf = vsi->back;
  3452. int err;
  3453. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3454. err = i40e_vsi_request_irq_msix(vsi, basename);
  3455. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3456. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3457. pf->int_name, pf);
  3458. else
  3459. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3460. pf->int_name, pf);
  3461. if (err)
  3462. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3463. return err;
  3464. }
  3465. #ifdef CONFIG_NET_POLL_CONTROLLER
  3466. /**
  3467. * i40e_netpoll - A Polling 'interrupt' handler
  3468. * @netdev: network interface device structure
  3469. *
  3470. * This is used by netconsole to send skbs without having to re-enable
  3471. * interrupts. It's not called while the normal interrupt routine is executing.
  3472. **/
  3473. #ifdef I40E_FCOE
  3474. void i40e_netpoll(struct net_device *netdev)
  3475. #else
  3476. static void i40e_netpoll(struct net_device *netdev)
  3477. #endif
  3478. {
  3479. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3480. struct i40e_vsi *vsi = np->vsi;
  3481. struct i40e_pf *pf = vsi->back;
  3482. int i;
  3483. /* if interface is down do nothing */
  3484. if (test_bit(__I40E_DOWN, &vsi->state))
  3485. return;
  3486. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3487. for (i = 0; i < vsi->num_q_vectors; i++)
  3488. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3489. } else {
  3490. i40e_intr(pf->pdev->irq, netdev);
  3491. }
  3492. }
  3493. #endif
  3494. /**
  3495. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3496. * @pf: the PF being configured
  3497. * @pf_q: the PF queue
  3498. * @enable: enable or disable state of the queue
  3499. *
  3500. * This routine will wait for the given Tx queue of the PF to reach the
  3501. * enabled or disabled state.
  3502. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3503. * multiple retries; else will return 0 in case of success.
  3504. **/
  3505. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3506. {
  3507. int i;
  3508. u32 tx_reg;
  3509. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3510. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3511. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3512. break;
  3513. usleep_range(10, 20);
  3514. }
  3515. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3516. return -ETIMEDOUT;
  3517. return 0;
  3518. }
  3519. /**
  3520. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3521. * @vsi: the VSI being configured
  3522. * @enable: start or stop the rings
  3523. **/
  3524. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3525. {
  3526. struct i40e_pf *pf = vsi->back;
  3527. struct i40e_hw *hw = &pf->hw;
  3528. int i, j, pf_q, ret = 0;
  3529. u32 tx_reg;
  3530. pf_q = vsi->base_queue;
  3531. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3532. /* warn the TX unit of coming changes */
  3533. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3534. if (!enable)
  3535. usleep_range(10, 20);
  3536. for (j = 0; j < 50; j++) {
  3537. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3538. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3539. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3540. break;
  3541. usleep_range(1000, 2000);
  3542. }
  3543. /* Skip if the queue is already in the requested state */
  3544. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3545. continue;
  3546. /* turn on/off the queue */
  3547. if (enable) {
  3548. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3549. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3550. } else {
  3551. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3552. }
  3553. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3554. /* No waiting for the Tx queue to disable */
  3555. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3556. continue;
  3557. /* wait for the change to finish */
  3558. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3559. if (ret) {
  3560. dev_info(&pf->pdev->dev,
  3561. "VSI seid %d Tx ring %d %sable timeout\n",
  3562. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3563. break;
  3564. }
  3565. }
  3566. if (hw->revision_id == 0)
  3567. mdelay(50);
  3568. return ret;
  3569. }
  3570. /**
  3571. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3572. * @pf: the PF being configured
  3573. * @pf_q: the PF queue
  3574. * @enable: enable or disable state of the queue
  3575. *
  3576. * This routine will wait for the given Rx queue of the PF to reach the
  3577. * enabled or disabled state.
  3578. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3579. * multiple retries; else will return 0 in case of success.
  3580. **/
  3581. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3582. {
  3583. int i;
  3584. u32 rx_reg;
  3585. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3586. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3587. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3588. break;
  3589. usleep_range(10, 20);
  3590. }
  3591. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3592. return -ETIMEDOUT;
  3593. return 0;
  3594. }
  3595. /**
  3596. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3597. * @vsi: the VSI being configured
  3598. * @enable: start or stop the rings
  3599. **/
  3600. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3601. {
  3602. struct i40e_pf *pf = vsi->back;
  3603. struct i40e_hw *hw = &pf->hw;
  3604. int i, j, pf_q, ret = 0;
  3605. u32 rx_reg;
  3606. pf_q = vsi->base_queue;
  3607. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3608. for (j = 0; j < 50; j++) {
  3609. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3610. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3611. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3612. break;
  3613. usleep_range(1000, 2000);
  3614. }
  3615. /* Skip if the queue is already in the requested state */
  3616. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3617. continue;
  3618. /* turn on/off the queue */
  3619. if (enable)
  3620. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3621. else
  3622. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3623. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3624. /* No waiting for the Tx queue to disable */
  3625. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3626. continue;
  3627. /* wait for the change to finish */
  3628. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3629. if (ret) {
  3630. dev_info(&pf->pdev->dev,
  3631. "VSI seid %d Rx ring %d %sable timeout\n",
  3632. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3633. break;
  3634. }
  3635. }
  3636. return ret;
  3637. }
  3638. /**
  3639. * i40e_vsi_start_rings - Start a VSI's rings
  3640. * @vsi: the VSI being configured
  3641. **/
  3642. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3643. {
  3644. int ret = 0;
  3645. /* do rx first for enable and last for disable */
  3646. ret = i40e_vsi_control_rx(vsi, true);
  3647. if (ret)
  3648. return ret;
  3649. ret = i40e_vsi_control_tx(vsi, true);
  3650. return ret;
  3651. }
  3652. /**
  3653. * i40e_vsi_stop_rings - Stop a VSI's rings
  3654. * @vsi: the VSI being configured
  3655. **/
  3656. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3657. {
  3658. /* do rx first for enable and last for disable
  3659. * Ignore return value, we need to shutdown whatever we can
  3660. */
  3661. i40e_vsi_control_tx(vsi, false);
  3662. i40e_vsi_control_rx(vsi, false);
  3663. }
  3664. /**
  3665. * i40e_vsi_free_irq - Free the irq association with the OS
  3666. * @vsi: the VSI being configured
  3667. **/
  3668. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3669. {
  3670. struct i40e_pf *pf = vsi->back;
  3671. struct i40e_hw *hw = &pf->hw;
  3672. int base = vsi->base_vector;
  3673. u32 val, qp;
  3674. int i;
  3675. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3676. if (!vsi->q_vectors)
  3677. return;
  3678. if (!vsi->irqs_ready)
  3679. return;
  3680. vsi->irqs_ready = false;
  3681. for (i = 0; i < vsi->num_q_vectors; i++) {
  3682. int irq_num;
  3683. u16 vector;
  3684. vector = i + base;
  3685. irq_num = pf->msix_entries[vector].vector;
  3686. /* free only the irqs that were actually requested */
  3687. if (!vsi->q_vectors[i] ||
  3688. !vsi->q_vectors[i]->num_ringpairs)
  3689. continue;
  3690. /* clear the affinity notifier in the IRQ descriptor */
  3691. irq_set_affinity_notifier(irq_num, NULL);
  3692. /* clear the affinity_mask in the IRQ descriptor */
  3693. irq_set_affinity_hint(irq_num, NULL);
  3694. synchronize_irq(irq_num);
  3695. free_irq(irq_num, vsi->q_vectors[i]);
  3696. /* Tear down the interrupt queue link list
  3697. *
  3698. * We know that they come in pairs and always
  3699. * the Rx first, then the Tx. To clear the
  3700. * link list, stick the EOL value into the
  3701. * next_q field of the registers.
  3702. */
  3703. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3704. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3705. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3706. val |= I40E_QUEUE_END_OF_LIST
  3707. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3708. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3709. while (qp != I40E_QUEUE_END_OF_LIST) {
  3710. u32 next;
  3711. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3712. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3713. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3714. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3715. I40E_QINT_RQCTL_INTEVENT_MASK);
  3716. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3717. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3718. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3719. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3720. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3721. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3722. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3723. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3724. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3725. I40E_QINT_TQCTL_INTEVENT_MASK);
  3726. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3727. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3728. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3729. qp = next;
  3730. }
  3731. }
  3732. } else {
  3733. free_irq(pf->pdev->irq, pf);
  3734. val = rd32(hw, I40E_PFINT_LNKLST0);
  3735. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3736. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3737. val |= I40E_QUEUE_END_OF_LIST
  3738. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3739. wr32(hw, I40E_PFINT_LNKLST0, val);
  3740. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3741. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3742. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3743. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3744. I40E_QINT_RQCTL_INTEVENT_MASK);
  3745. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3746. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3747. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3748. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3749. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3750. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3751. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3752. I40E_QINT_TQCTL_INTEVENT_MASK);
  3753. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3754. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3755. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3756. }
  3757. }
  3758. /**
  3759. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3760. * @vsi: the VSI being configured
  3761. * @v_idx: Index of vector to be freed
  3762. *
  3763. * This function frees the memory allocated to the q_vector. In addition if
  3764. * NAPI is enabled it will delete any references to the NAPI struct prior
  3765. * to freeing the q_vector.
  3766. **/
  3767. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3768. {
  3769. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3770. struct i40e_ring *ring;
  3771. if (!q_vector)
  3772. return;
  3773. /* disassociate q_vector from rings */
  3774. i40e_for_each_ring(ring, q_vector->tx)
  3775. ring->q_vector = NULL;
  3776. i40e_for_each_ring(ring, q_vector->rx)
  3777. ring->q_vector = NULL;
  3778. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3779. if (vsi->netdev)
  3780. netif_napi_del(&q_vector->napi);
  3781. vsi->q_vectors[v_idx] = NULL;
  3782. kfree_rcu(q_vector, rcu);
  3783. }
  3784. /**
  3785. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3786. * @vsi: the VSI being un-configured
  3787. *
  3788. * This frees the memory allocated to the q_vectors and
  3789. * deletes references to the NAPI struct.
  3790. **/
  3791. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3792. {
  3793. int v_idx;
  3794. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3795. i40e_free_q_vector(vsi, v_idx);
  3796. }
  3797. /**
  3798. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3799. * @pf: board private structure
  3800. **/
  3801. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3802. {
  3803. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3804. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3805. pci_disable_msix(pf->pdev);
  3806. kfree(pf->msix_entries);
  3807. pf->msix_entries = NULL;
  3808. kfree(pf->irq_pile);
  3809. pf->irq_pile = NULL;
  3810. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3811. pci_disable_msi(pf->pdev);
  3812. }
  3813. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3814. }
  3815. /**
  3816. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3817. * @pf: board private structure
  3818. *
  3819. * We go through and clear interrupt specific resources and reset the structure
  3820. * to pre-load conditions
  3821. **/
  3822. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3823. {
  3824. int i;
  3825. i40e_stop_misc_vector(pf);
  3826. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3827. synchronize_irq(pf->msix_entries[0].vector);
  3828. free_irq(pf->msix_entries[0].vector, pf);
  3829. }
  3830. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  3831. I40E_IWARP_IRQ_PILE_ID);
  3832. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3833. for (i = 0; i < pf->num_alloc_vsi; i++)
  3834. if (pf->vsi[i])
  3835. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3836. i40e_reset_interrupt_capability(pf);
  3837. }
  3838. /**
  3839. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3840. * @vsi: the VSI being configured
  3841. **/
  3842. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3843. {
  3844. int q_idx;
  3845. if (!vsi->netdev)
  3846. return;
  3847. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3848. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3849. }
  3850. /**
  3851. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3852. * @vsi: the VSI being configured
  3853. **/
  3854. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3855. {
  3856. int q_idx;
  3857. if (!vsi->netdev)
  3858. return;
  3859. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3860. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3861. }
  3862. /**
  3863. * i40e_vsi_close - Shut down a VSI
  3864. * @vsi: the vsi to be quelled
  3865. **/
  3866. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3867. {
  3868. bool reset = false;
  3869. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3870. i40e_down(vsi);
  3871. i40e_vsi_free_irq(vsi);
  3872. i40e_vsi_free_tx_resources(vsi);
  3873. i40e_vsi_free_rx_resources(vsi);
  3874. vsi->current_netdev_flags = 0;
  3875. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  3876. reset = true;
  3877. i40e_notify_client_of_netdev_close(vsi, reset);
  3878. }
  3879. /**
  3880. * i40e_quiesce_vsi - Pause a given VSI
  3881. * @vsi: the VSI being paused
  3882. **/
  3883. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3884. {
  3885. if (test_bit(__I40E_DOWN, &vsi->state))
  3886. return;
  3887. /* No need to disable FCoE VSI when Tx suspended */
  3888. if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
  3889. vsi->type == I40E_VSI_FCOE) {
  3890. dev_dbg(&vsi->back->pdev->dev,
  3891. "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
  3892. return;
  3893. }
  3894. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3895. if (vsi->netdev && netif_running(vsi->netdev))
  3896. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3897. else
  3898. i40e_vsi_close(vsi);
  3899. }
  3900. /**
  3901. * i40e_unquiesce_vsi - Resume a given VSI
  3902. * @vsi: the VSI being resumed
  3903. **/
  3904. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3905. {
  3906. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3907. return;
  3908. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3909. if (vsi->netdev && netif_running(vsi->netdev))
  3910. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3911. else
  3912. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3913. }
  3914. /**
  3915. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3916. * @pf: the PF
  3917. **/
  3918. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3919. {
  3920. int v;
  3921. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3922. if (pf->vsi[v])
  3923. i40e_quiesce_vsi(pf->vsi[v]);
  3924. }
  3925. }
  3926. /**
  3927. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3928. * @pf: the PF
  3929. **/
  3930. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3931. {
  3932. int v;
  3933. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3934. if (pf->vsi[v])
  3935. i40e_unquiesce_vsi(pf->vsi[v]);
  3936. }
  3937. }
  3938. #ifdef CONFIG_I40E_DCB
  3939. /**
  3940. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  3941. * @vsi: the VSI being configured
  3942. *
  3943. * This function waits for the given VSI's queues to be disabled.
  3944. **/
  3945. static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  3946. {
  3947. struct i40e_pf *pf = vsi->back;
  3948. int i, pf_q, ret;
  3949. pf_q = vsi->base_queue;
  3950. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3951. /* Check and wait for the disable status of the queue */
  3952. ret = i40e_pf_txq_wait(pf, pf_q, false);
  3953. if (ret) {
  3954. dev_info(&pf->pdev->dev,
  3955. "VSI seid %d Tx ring %d disable timeout\n",
  3956. vsi->seid, pf_q);
  3957. return ret;
  3958. }
  3959. }
  3960. pf_q = vsi->base_queue;
  3961. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3962. /* Check and wait for the disable status of the queue */
  3963. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  3964. if (ret) {
  3965. dev_info(&pf->pdev->dev,
  3966. "VSI seid %d Rx ring %d disable timeout\n",
  3967. vsi->seid, pf_q);
  3968. return ret;
  3969. }
  3970. }
  3971. return 0;
  3972. }
  3973. /**
  3974. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  3975. * @pf: the PF
  3976. *
  3977. * This function waits for the queues to be in disabled state for all the
  3978. * VSIs that are managed by this PF.
  3979. **/
  3980. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  3981. {
  3982. int v, ret = 0;
  3983. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3984. /* No need to wait for FCoE VSI queues */
  3985. if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
  3986. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  3987. if (ret)
  3988. break;
  3989. }
  3990. }
  3991. return ret;
  3992. }
  3993. #endif
  3994. /**
  3995. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  3996. * @q_idx: TX queue number
  3997. * @vsi: Pointer to VSI struct
  3998. *
  3999. * This function checks specified queue for given VSI. Detects hung condition.
  4000. * Sets hung bit since it is two step process. Before next run of service task
  4001. * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
  4002. * hung condition remain unchanged and during subsequent run, this function
  4003. * issues SW interrupt to recover from hung condition.
  4004. **/
  4005. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  4006. {
  4007. struct i40e_ring *tx_ring = NULL;
  4008. struct i40e_pf *pf;
  4009. u32 head, val, tx_pending_hw;
  4010. int i;
  4011. pf = vsi->back;
  4012. /* now that we have an index, find the tx_ring struct */
  4013. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4014. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  4015. if (q_idx == vsi->tx_rings[i]->queue_index) {
  4016. tx_ring = vsi->tx_rings[i];
  4017. break;
  4018. }
  4019. }
  4020. }
  4021. if (!tx_ring)
  4022. return;
  4023. /* Read interrupt register */
  4024. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4025. val = rd32(&pf->hw,
  4026. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  4027. tx_ring->vsi->base_vector - 1));
  4028. else
  4029. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  4030. head = i40e_get_head(tx_ring);
  4031. tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
  4032. /* HW is done executing descriptors, updated HEAD write back,
  4033. * but SW hasn't processed those descriptors. If interrupt is
  4034. * not generated from this point ON, it could result into
  4035. * dev_watchdog detecting timeout on those netdev_queue,
  4036. * hence proactively trigger SW interrupt.
  4037. */
  4038. if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  4039. /* NAPI Poll didn't run and clear since it was set */
  4040. if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
  4041. &tx_ring->q_vector->hung_detected)) {
  4042. 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",
  4043. vsi->seid, q_idx, tx_pending_hw,
  4044. tx_ring->next_to_clean, head,
  4045. tx_ring->next_to_use,
  4046. readl(tx_ring->tail));
  4047. netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
  4048. vsi->seid, q_idx, val);
  4049. i40e_force_wb(vsi, tx_ring->q_vector);
  4050. } else {
  4051. /* First Chance - detected possible hung */
  4052. set_bit(I40E_Q_VECTOR_HUNG_DETECT,
  4053. &tx_ring->q_vector->hung_detected);
  4054. }
  4055. }
  4056. /* This is the case where we have interrupts missing,
  4057. * so the tx_pending in HW will most likely be 0, but we
  4058. * will have tx_pending in SW since the WB happened but the
  4059. * interrupt got lost.
  4060. */
  4061. if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
  4062. (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  4063. if (napi_reschedule(&tx_ring->q_vector->napi))
  4064. tx_ring->tx_stats.tx_lost_interrupt++;
  4065. }
  4066. }
  4067. /**
  4068. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  4069. * @pf: pointer to PF struct
  4070. *
  4071. * LAN VSI has netdev and netdev has TX queues. This function is to check
  4072. * each of those TX queues if they are hung, trigger recovery by issuing
  4073. * SW interrupt.
  4074. **/
  4075. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  4076. {
  4077. struct net_device *netdev;
  4078. struct i40e_vsi *vsi;
  4079. int i;
  4080. /* Only for LAN VSI */
  4081. vsi = pf->vsi[pf->lan_vsi];
  4082. if (!vsi)
  4083. return;
  4084. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  4085. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  4086. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  4087. return;
  4088. /* Make sure type is MAIN VSI */
  4089. if (vsi->type != I40E_VSI_MAIN)
  4090. return;
  4091. netdev = vsi->netdev;
  4092. if (!netdev)
  4093. return;
  4094. /* Bail out if netif_carrier is not OK */
  4095. if (!netif_carrier_ok(netdev))
  4096. return;
  4097. /* Go thru' TX queues for netdev */
  4098. for (i = 0; i < netdev->num_tx_queues; i++) {
  4099. struct netdev_queue *q;
  4100. q = netdev_get_tx_queue(netdev, i);
  4101. if (q)
  4102. i40e_detect_recover_hung_queue(i, vsi);
  4103. }
  4104. }
  4105. /**
  4106. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4107. * @pf: pointer to PF
  4108. *
  4109. * Get TC map for ISCSI PF type that will include iSCSI TC
  4110. * and LAN TC.
  4111. **/
  4112. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4113. {
  4114. struct i40e_dcb_app_priority_table app;
  4115. struct i40e_hw *hw = &pf->hw;
  4116. u8 enabled_tc = 1; /* TC0 is always enabled */
  4117. u8 tc, i;
  4118. /* Get the iSCSI APP TLV */
  4119. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4120. for (i = 0; i < dcbcfg->numapps; i++) {
  4121. app = dcbcfg->app[i];
  4122. if (app.selector == I40E_APP_SEL_TCPIP &&
  4123. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4124. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4125. enabled_tc |= BIT(tc);
  4126. break;
  4127. }
  4128. }
  4129. return enabled_tc;
  4130. }
  4131. /**
  4132. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4133. * @dcbcfg: the corresponding DCBx configuration structure
  4134. *
  4135. * Return the number of TCs from given DCBx configuration
  4136. **/
  4137. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4138. {
  4139. int i, tc_unused = 0;
  4140. u8 num_tc = 0;
  4141. u8 ret = 0;
  4142. /* Scan the ETS Config Priority Table to find
  4143. * traffic class enabled for a given priority
  4144. * and create a bitmask of enabled TCs
  4145. */
  4146. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4147. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4148. /* Now scan the bitmask to check for
  4149. * contiguous TCs starting with TC0
  4150. */
  4151. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4152. if (num_tc & BIT(i)) {
  4153. if (!tc_unused) {
  4154. ret++;
  4155. } else {
  4156. pr_err("Non-contiguous TC - Disabling DCB\n");
  4157. return 1;
  4158. }
  4159. } else {
  4160. tc_unused = 1;
  4161. }
  4162. }
  4163. /* There is always at least TC0 */
  4164. if (!ret)
  4165. ret = 1;
  4166. return ret;
  4167. }
  4168. /**
  4169. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4170. * @dcbcfg: the corresponding DCBx configuration structure
  4171. *
  4172. * Query the current DCB configuration and return the number of
  4173. * traffic classes enabled from the given DCBX config
  4174. **/
  4175. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4176. {
  4177. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4178. u8 enabled_tc = 1;
  4179. u8 i;
  4180. for (i = 0; i < num_tc; i++)
  4181. enabled_tc |= BIT(i);
  4182. return enabled_tc;
  4183. }
  4184. /**
  4185. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4186. * @pf: PF being queried
  4187. *
  4188. * Return number of traffic classes enabled for the given PF
  4189. **/
  4190. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4191. {
  4192. struct i40e_hw *hw = &pf->hw;
  4193. u8 i, enabled_tc = 1;
  4194. u8 num_tc = 0;
  4195. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4196. /* If DCB is not enabled then always in single TC */
  4197. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4198. return 1;
  4199. /* SFP mode will be enabled for all TCs on port */
  4200. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4201. return i40e_dcb_get_num_tc(dcbcfg);
  4202. /* MFP mode return count of enabled TCs for this PF */
  4203. if (pf->hw.func_caps.iscsi)
  4204. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4205. else
  4206. return 1; /* Only TC0 */
  4207. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4208. if (enabled_tc & BIT(i))
  4209. num_tc++;
  4210. }
  4211. return num_tc;
  4212. }
  4213. /**
  4214. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4215. * @pf: PF being queried
  4216. *
  4217. * Return a bitmap for enabled traffic classes for this PF.
  4218. **/
  4219. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4220. {
  4221. /* If DCB is not enabled for this PF then just return default TC */
  4222. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4223. return I40E_DEFAULT_TRAFFIC_CLASS;
  4224. /* SFP mode we want PF to be enabled for all TCs */
  4225. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4226. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4227. /* MFP enabled and iSCSI PF type */
  4228. if (pf->hw.func_caps.iscsi)
  4229. return i40e_get_iscsi_tc_map(pf);
  4230. else
  4231. return I40E_DEFAULT_TRAFFIC_CLASS;
  4232. }
  4233. /**
  4234. * i40e_vsi_get_bw_info - Query VSI BW Information
  4235. * @vsi: the VSI being queried
  4236. *
  4237. * Returns 0 on success, negative value on failure
  4238. **/
  4239. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4240. {
  4241. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4242. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4243. struct i40e_pf *pf = vsi->back;
  4244. struct i40e_hw *hw = &pf->hw;
  4245. i40e_status ret;
  4246. u32 tc_bw_max;
  4247. int i;
  4248. /* Get the VSI level BW configuration */
  4249. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4250. if (ret) {
  4251. dev_info(&pf->pdev->dev,
  4252. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4253. i40e_stat_str(&pf->hw, ret),
  4254. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4255. return -EINVAL;
  4256. }
  4257. /* Get the VSI level BW configuration per TC */
  4258. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4259. NULL);
  4260. if (ret) {
  4261. dev_info(&pf->pdev->dev,
  4262. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4263. i40e_stat_str(&pf->hw, ret),
  4264. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4265. return -EINVAL;
  4266. }
  4267. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4268. dev_info(&pf->pdev->dev,
  4269. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4270. bw_config.tc_valid_bits,
  4271. bw_ets_config.tc_valid_bits);
  4272. /* Still continuing */
  4273. }
  4274. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4275. vsi->bw_max_quanta = bw_config.max_bw;
  4276. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4277. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4278. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4279. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4280. vsi->bw_ets_limit_credits[i] =
  4281. le16_to_cpu(bw_ets_config.credits[i]);
  4282. /* 3 bits out of 4 for each TC */
  4283. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4284. }
  4285. return 0;
  4286. }
  4287. /**
  4288. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4289. * @vsi: the VSI being configured
  4290. * @enabled_tc: TC bitmap
  4291. * @bw_credits: BW shared credits per TC
  4292. *
  4293. * Returns 0 on success, negative value on failure
  4294. **/
  4295. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4296. u8 *bw_share)
  4297. {
  4298. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4299. i40e_status ret;
  4300. int i;
  4301. bw_data.tc_valid_bits = enabled_tc;
  4302. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4303. bw_data.tc_bw_credits[i] = bw_share[i];
  4304. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4305. NULL);
  4306. if (ret) {
  4307. dev_info(&vsi->back->pdev->dev,
  4308. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4309. vsi->back->hw.aq.asq_last_status);
  4310. return -EINVAL;
  4311. }
  4312. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4313. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4314. return 0;
  4315. }
  4316. /**
  4317. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4318. * @vsi: the VSI being configured
  4319. * @enabled_tc: TC map to be enabled
  4320. *
  4321. **/
  4322. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4323. {
  4324. struct net_device *netdev = vsi->netdev;
  4325. struct i40e_pf *pf = vsi->back;
  4326. struct i40e_hw *hw = &pf->hw;
  4327. u8 netdev_tc = 0;
  4328. int i;
  4329. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4330. if (!netdev)
  4331. return;
  4332. if (!enabled_tc) {
  4333. netdev_reset_tc(netdev);
  4334. return;
  4335. }
  4336. /* Set up actual enabled TCs on the VSI */
  4337. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4338. return;
  4339. /* set per TC queues for the VSI */
  4340. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4341. /* Only set TC queues for enabled tcs
  4342. *
  4343. * e.g. For a VSI that has TC0 and TC3 enabled the
  4344. * enabled_tc bitmap would be 0x00001001; the driver
  4345. * will set the numtc for netdev as 2 that will be
  4346. * referenced by the netdev layer as TC 0 and 1.
  4347. */
  4348. if (vsi->tc_config.enabled_tc & BIT(i))
  4349. netdev_set_tc_queue(netdev,
  4350. vsi->tc_config.tc_info[i].netdev_tc,
  4351. vsi->tc_config.tc_info[i].qcount,
  4352. vsi->tc_config.tc_info[i].qoffset);
  4353. }
  4354. /* Assign UP2TC map for the VSI */
  4355. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4356. /* Get the actual TC# for the UP */
  4357. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4358. /* Get the mapped netdev TC# for the UP */
  4359. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4360. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4361. }
  4362. }
  4363. /**
  4364. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4365. * @vsi: the VSI being configured
  4366. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4367. **/
  4368. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4369. struct i40e_vsi_context *ctxt)
  4370. {
  4371. /* copy just the sections touched not the entire info
  4372. * since not all sections are valid as returned by
  4373. * update vsi params
  4374. */
  4375. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4376. memcpy(&vsi->info.queue_mapping,
  4377. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4378. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4379. sizeof(vsi->info.tc_mapping));
  4380. }
  4381. /**
  4382. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4383. * @vsi: VSI to be configured
  4384. * @enabled_tc: TC bitmap
  4385. *
  4386. * This configures a particular VSI for TCs that are mapped to the
  4387. * given TC bitmap. It uses default bandwidth share for TCs across
  4388. * VSIs to configure TC for a particular VSI.
  4389. *
  4390. * NOTE:
  4391. * It is expected that the VSI queues have been quisced before calling
  4392. * this function.
  4393. **/
  4394. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4395. {
  4396. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4397. struct i40e_vsi_context ctxt;
  4398. int ret = 0;
  4399. int i;
  4400. /* Check if enabled_tc is same as existing or new TCs */
  4401. if (vsi->tc_config.enabled_tc == enabled_tc)
  4402. return ret;
  4403. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4404. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4405. if (enabled_tc & BIT(i))
  4406. bw_share[i] = 1;
  4407. }
  4408. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4409. if (ret) {
  4410. dev_info(&vsi->back->pdev->dev,
  4411. "Failed configuring TC map %d for VSI %d\n",
  4412. enabled_tc, vsi->seid);
  4413. goto out;
  4414. }
  4415. /* Update Queue Pairs Mapping for currently enabled UPs */
  4416. ctxt.seid = vsi->seid;
  4417. ctxt.pf_num = vsi->back->hw.pf_id;
  4418. ctxt.vf_num = 0;
  4419. ctxt.uplink_seid = vsi->uplink_seid;
  4420. ctxt.info = vsi->info;
  4421. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4422. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4423. ctxt.info.valid_sections |=
  4424. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4425. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4426. }
  4427. /* Update the VSI after updating the VSI queue-mapping information */
  4428. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4429. if (ret) {
  4430. dev_info(&vsi->back->pdev->dev,
  4431. "Update vsi tc config failed, err %s aq_err %s\n",
  4432. i40e_stat_str(&vsi->back->hw, ret),
  4433. i40e_aq_str(&vsi->back->hw,
  4434. vsi->back->hw.aq.asq_last_status));
  4435. goto out;
  4436. }
  4437. /* update the local VSI info with updated queue map */
  4438. i40e_vsi_update_queue_map(vsi, &ctxt);
  4439. vsi->info.valid_sections = 0;
  4440. /* Update current VSI BW information */
  4441. ret = i40e_vsi_get_bw_info(vsi);
  4442. if (ret) {
  4443. dev_info(&vsi->back->pdev->dev,
  4444. "Failed updating vsi bw info, err %s aq_err %s\n",
  4445. i40e_stat_str(&vsi->back->hw, ret),
  4446. i40e_aq_str(&vsi->back->hw,
  4447. vsi->back->hw.aq.asq_last_status));
  4448. goto out;
  4449. }
  4450. /* Update the netdev TC setup */
  4451. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4452. out:
  4453. return ret;
  4454. }
  4455. /**
  4456. * i40e_veb_config_tc - Configure TCs for given VEB
  4457. * @veb: given VEB
  4458. * @enabled_tc: TC bitmap
  4459. *
  4460. * Configures given TC bitmap for VEB (switching) element
  4461. **/
  4462. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  4463. {
  4464. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  4465. struct i40e_pf *pf = veb->pf;
  4466. int ret = 0;
  4467. int i;
  4468. /* No TCs or already enabled TCs just return */
  4469. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  4470. return ret;
  4471. bw_data.tc_valid_bits = enabled_tc;
  4472. /* bw_data.absolute_credits is not set (relative) */
  4473. /* Enable ETS TCs with equal BW Share for now */
  4474. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4475. if (enabled_tc & BIT(i))
  4476. bw_data.tc_bw_share_credits[i] = 1;
  4477. }
  4478. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  4479. &bw_data, NULL);
  4480. if (ret) {
  4481. dev_info(&pf->pdev->dev,
  4482. "VEB bw config failed, err %s aq_err %s\n",
  4483. i40e_stat_str(&pf->hw, ret),
  4484. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4485. goto out;
  4486. }
  4487. /* Update the BW information */
  4488. ret = i40e_veb_get_bw_info(veb);
  4489. if (ret) {
  4490. dev_info(&pf->pdev->dev,
  4491. "Failed getting veb bw config, err %s aq_err %s\n",
  4492. i40e_stat_str(&pf->hw, ret),
  4493. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4494. }
  4495. out:
  4496. return ret;
  4497. }
  4498. #ifdef CONFIG_I40E_DCB
  4499. /**
  4500. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  4501. * @pf: PF struct
  4502. *
  4503. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  4504. * the caller would've quiesce all the VSIs before calling
  4505. * this function
  4506. **/
  4507. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  4508. {
  4509. u8 tc_map = 0;
  4510. int ret;
  4511. u8 v;
  4512. /* Enable the TCs available on PF to all VEBs */
  4513. tc_map = i40e_pf_get_tc_map(pf);
  4514. for (v = 0; v < I40E_MAX_VEB; v++) {
  4515. if (!pf->veb[v])
  4516. continue;
  4517. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  4518. if (ret) {
  4519. dev_info(&pf->pdev->dev,
  4520. "Failed configuring TC for VEB seid=%d\n",
  4521. pf->veb[v]->seid);
  4522. /* Will try to configure as many components */
  4523. }
  4524. }
  4525. /* Update each VSI */
  4526. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4527. if (!pf->vsi[v])
  4528. continue;
  4529. /* - Enable all TCs for the LAN VSI
  4530. #ifdef I40E_FCOE
  4531. * - For FCoE VSI only enable the TC configured
  4532. * as per the APP TLV
  4533. #endif
  4534. * - For all others keep them at TC0 for now
  4535. */
  4536. if (v == pf->lan_vsi)
  4537. tc_map = i40e_pf_get_tc_map(pf);
  4538. else
  4539. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  4540. #ifdef I40E_FCOE
  4541. if (pf->vsi[v]->type == I40E_VSI_FCOE)
  4542. tc_map = i40e_get_fcoe_tc_map(pf);
  4543. #endif /* #ifdef I40E_FCOE */
  4544. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  4545. if (ret) {
  4546. dev_info(&pf->pdev->dev,
  4547. "Failed configuring TC for VSI seid=%d\n",
  4548. pf->vsi[v]->seid);
  4549. /* Will try to configure as many components */
  4550. } else {
  4551. /* Re-configure VSI vectors based on updated TC map */
  4552. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  4553. if (pf->vsi[v]->netdev)
  4554. i40e_dcbnl_set_all(pf->vsi[v]);
  4555. }
  4556. }
  4557. }
  4558. /**
  4559. * i40e_resume_port_tx - Resume port Tx
  4560. * @pf: PF struct
  4561. *
  4562. * Resume a port's Tx and issue a PF reset in case of failure to
  4563. * resume.
  4564. **/
  4565. static int i40e_resume_port_tx(struct i40e_pf *pf)
  4566. {
  4567. struct i40e_hw *hw = &pf->hw;
  4568. int ret;
  4569. ret = i40e_aq_resume_port_tx(hw, NULL);
  4570. if (ret) {
  4571. dev_info(&pf->pdev->dev,
  4572. "Resume Port Tx failed, err %s aq_err %s\n",
  4573. i40e_stat_str(&pf->hw, ret),
  4574. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4575. /* Schedule PF reset to recover */
  4576. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4577. i40e_service_event_schedule(pf);
  4578. }
  4579. return ret;
  4580. }
  4581. /**
  4582. * i40e_init_pf_dcb - Initialize DCB configuration
  4583. * @pf: PF being configured
  4584. *
  4585. * Query the current DCB configuration and cache it
  4586. * in the hardware structure
  4587. **/
  4588. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  4589. {
  4590. struct i40e_hw *hw = &pf->hw;
  4591. int err = 0;
  4592. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  4593. if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
  4594. goto out;
  4595. /* Get the initial DCB configuration */
  4596. err = i40e_init_dcb(hw);
  4597. if (!err) {
  4598. /* Device/Function is not DCBX capable */
  4599. if ((!hw->func_caps.dcb) ||
  4600. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  4601. dev_info(&pf->pdev->dev,
  4602. "DCBX offload is not supported or is disabled for this PF.\n");
  4603. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  4604. goto out;
  4605. } else {
  4606. /* When status is not DISABLED then DCBX in FW */
  4607. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  4608. DCB_CAP_DCBX_VER_IEEE;
  4609. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  4610. /* Enable DCB tagging only when more than one TC
  4611. * or explicitly disable if only one TC
  4612. */
  4613. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  4614. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4615. else
  4616. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  4617. dev_dbg(&pf->pdev->dev,
  4618. "DCBX offload is supported for this PF.\n");
  4619. }
  4620. } else {
  4621. dev_info(&pf->pdev->dev,
  4622. "Query for DCB configuration failed, err %s aq_err %s\n",
  4623. i40e_stat_str(&pf->hw, err),
  4624. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4625. }
  4626. out:
  4627. return err;
  4628. }
  4629. #endif /* CONFIG_I40E_DCB */
  4630. #define SPEED_SIZE 14
  4631. #define FC_SIZE 8
  4632. /**
  4633. * i40e_print_link_message - print link up or down
  4634. * @vsi: the VSI for which link needs a message
  4635. */
  4636. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  4637. {
  4638. enum i40e_aq_link_speed new_speed;
  4639. char *speed = "Unknown";
  4640. char *fc = "Unknown";
  4641. new_speed = vsi->back->hw.phy.link_info.link_speed;
  4642. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  4643. return;
  4644. vsi->current_isup = isup;
  4645. vsi->current_speed = new_speed;
  4646. if (!isup) {
  4647. netdev_info(vsi->netdev, "NIC Link is Down\n");
  4648. return;
  4649. }
  4650. /* Warn user if link speed on NPAR enabled partition is not at
  4651. * least 10GB
  4652. */
  4653. if (vsi->back->hw.func_caps.npar_enable &&
  4654. (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  4655. vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  4656. netdev_warn(vsi->netdev,
  4657. "The partition detected link speed that is less than 10Gbps\n");
  4658. switch (vsi->back->hw.phy.link_info.link_speed) {
  4659. case I40E_LINK_SPEED_40GB:
  4660. speed = "40 G";
  4661. break;
  4662. case I40E_LINK_SPEED_20GB:
  4663. speed = "20 G";
  4664. break;
  4665. case I40E_LINK_SPEED_25GB:
  4666. speed = "25 G";
  4667. break;
  4668. case I40E_LINK_SPEED_10GB:
  4669. speed = "10 G";
  4670. break;
  4671. case I40E_LINK_SPEED_1GB:
  4672. speed = "1000 M";
  4673. break;
  4674. case I40E_LINK_SPEED_100MB:
  4675. speed = "100 M";
  4676. break;
  4677. default:
  4678. break;
  4679. }
  4680. switch (vsi->back->hw.fc.current_mode) {
  4681. case I40E_FC_FULL:
  4682. fc = "RX/TX";
  4683. break;
  4684. case I40E_FC_TX_PAUSE:
  4685. fc = "TX";
  4686. break;
  4687. case I40E_FC_RX_PAUSE:
  4688. fc = "RX";
  4689. break;
  4690. default:
  4691. fc = "None";
  4692. break;
  4693. }
  4694. netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
  4695. speed, fc);
  4696. }
  4697. /**
  4698. * i40e_up_complete - Finish the last steps of bringing up a connection
  4699. * @vsi: the VSI being configured
  4700. **/
  4701. static int i40e_up_complete(struct i40e_vsi *vsi)
  4702. {
  4703. struct i40e_pf *pf = vsi->back;
  4704. int err;
  4705. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4706. i40e_vsi_configure_msix(vsi);
  4707. else
  4708. i40e_configure_msi_and_legacy(vsi);
  4709. /* start rings */
  4710. err = i40e_vsi_start_rings(vsi);
  4711. if (err)
  4712. return err;
  4713. clear_bit(__I40E_DOWN, &vsi->state);
  4714. i40e_napi_enable_all(vsi);
  4715. i40e_vsi_enable_irq(vsi);
  4716. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  4717. (vsi->netdev)) {
  4718. i40e_print_link_message(vsi, true);
  4719. netif_tx_start_all_queues(vsi->netdev);
  4720. netif_carrier_on(vsi->netdev);
  4721. } else if (vsi->netdev) {
  4722. i40e_print_link_message(vsi, false);
  4723. /* need to check for qualified module here*/
  4724. if ((pf->hw.phy.link_info.link_info &
  4725. I40E_AQ_MEDIA_AVAILABLE) &&
  4726. (!(pf->hw.phy.link_info.an_info &
  4727. I40E_AQ_QUALIFIED_MODULE)))
  4728. netdev_err(vsi->netdev,
  4729. "the driver failed to link because an unqualified module was detected.");
  4730. }
  4731. /* replay FDIR SB filters */
  4732. if (vsi->type == I40E_VSI_FDIR) {
  4733. /* reset fd counters */
  4734. pf->fd_add_err = pf->fd_atr_cnt = 0;
  4735. if (pf->fd_tcp_rule > 0) {
  4736. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  4737. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  4738. dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
  4739. pf->fd_tcp_rule = 0;
  4740. }
  4741. i40e_fdir_filter_restore(vsi);
  4742. }
  4743. /* On the next run of the service_task, notify any clients of the new
  4744. * opened netdev
  4745. */
  4746. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4747. i40e_service_event_schedule(pf);
  4748. return 0;
  4749. }
  4750. /**
  4751. * i40e_vsi_reinit_locked - Reset the VSI
  4752. * @vsi: the VSI being configured
  4753. *
  4754. * Rebuild the ring structs after some configuration
  4755. * has changed, e.g. MTU size.
  4756. **/
  4757. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  4758. {
  4759. struct i40e_pf *pf = vsi->back;
  4760. WARN_ON(in_interrupt());
  4761. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  4762. usleep_range(1000, 2000);
  4763. i40e_down(vsi);
  4764. i40e_up(vsi);
  4765. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  4766. }
  4767. /**
  4768. * i40e_up - Bring the connection back up after being down
  4769. * @vsi: the VSI being configured
  4770. **/
  4771. int i40e_up(struct i40e_vsi *vsi)
  4772. {
  4773. int err;
  4774. err = i40e_vsi_configure(vsi);
  4775. if (!err)
  4776. err = i40e_up_complete(vsi);
  4777. return err;
  4778. }
  4779. /**
  4780. * i40e_down - Shutdown the connection processing
  4781. * @vsi: the VSI being stopped
  4782. **/
  4783. void i40e_down(struct i40e_vsi *vsi)
  4784. {
  4785. int i;
  4786. /* It is assumed that the caller of this function
  4787. * sets the vsi->state __I40E_DOWN bit.
  4788. */
  4789. if (vsi->netdev) {
  4790. netif_carrier_off(vsi->netdev);
  4791. netif_tx_disable(vsi->netdev);
  4792. }
  4793. i40e_vsi_disable_irq(vsi);
  4794. i40e_vsi_stop_rings(vsi);
  4795. i40e_napi_disable_all(vsi);
  4796. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4797. i40e_clean_tx_ring(vsi->tx_rings[i]);
  4798. i40e_clean_rx_ring(vsi->rx_rings[i]);
  4799. }
  4800. i40e_notify_client_of_netdev_close(vsi, false);
  4801. }
  4802. /**
  4803. * i40e_setup_tc - configure multiple traffic classes
  4804. * @netdev: net device to configure
  4805. * @tc: number of traffic classes to enable
  4806. **/
  4807. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4808. {
  4809. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4810. struct i40e_vsi *vsi = np->vsi;
  4811. struct i40e_pf *pf = vsi->back;
  4812. u8 enabled_tc = 0;
  4813. int ret = -EINVAL;
  4814. int i;
  4815. /* Check if DCB enabled to continue */
  4816. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4817. netdev_info(netdev, "DCB is not enabled for adapter\n");
  4818. goto exit;
  4819. }
  4820. /* Check if MFP enabled */
  4821. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  4822. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  4823. goto exit;
  4824. }
  4825. /* Check whether tc count is within enabled limit */
  4826. if (tc > i40e_pf_get_num_tc(pf)) {
  4827. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  4828. goto exit;
  4829. }
  4830. /* Generate TC map for number of tc requested */
  4831. for (i = 0; i < tc; i++)
  4832. enabled_tc |= BIT(i);
  4833. /* Requesting same TC configuration as already enabled */
  4834. if (enabled_tc == vsi->tc_config.enabled_tc)
  4835. return 0;
  4836. /* Quiesce VSI queues */
  4837. i40e_quiesce_vsi(vsi);
  4838. /* Configure VSI for enabled TCs */
  4839. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  4840. if (ret) {
  4841. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  4842. vsi->seid);
  4843. goto exit;
  4844. }
  4845. /* Unquiesce VSI */
  4846. i40e_unquiesce_vsi(vsi);
  4847. exit:
  4848. return ret;
  4849. }
  4850. #ifdef I40E_FCOE
  4851. int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4852. struct tc_to_netdev *tc)
  4853. #else
  4854. static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4855. struct tc_to_netdev *tc)
  4856. #endif
  4857. {
  4858. if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
  4859. return -EINVAL;
  4860. return i40e_setup_tc(netdev, tc->tc);
  4861. }
  4862. /**
  4863. * i40e_open - Called when a network interface is made active
  4864. * @netdev: network interface device structure
  4865. *
  4866. * The open entry point is called when a network interface is made
  4867. * active by the system (IFF_UP). At this point all resources needed
  4868. * for transmit and receive operations are allocated, the interrupt
  4869. * handler is registered with the OS, the netdev watchdog subtask is
  4870. * enabled, and the stack is notified that the interface is ready.
  4871. *
  4872. * Returns 0 on success, negative value on failure
  4873. **/
  4874. int i40e_open(struct net_device *netdev)
  4875. {
  4876. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4877. struct i40e_vsi *vsi = np->vsi;
  4878. struct i40e_pf *pf = vsi->back;
  4879. int err;
  4880. /* disallow open during test or if eeprom is broken */
  4881. if (test_bit(__I40E_TESTING, &pf->state) ||
  4882. test_bit(__I40E_BAD_EEPROM, &pf->state))
  4883. return -EBUSY;
  4884. netif_carrier_off(netdev);
  4885. err = i40e_vsi_open(vsi);
  4886. if (err)
  4887. return err;
  4888. /* configure global TSO hardware offload settings */
  4889. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  4890. TCP_FLAG_FIN) >> 16);
  4891. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  4892. TCP_FLAG_FIN |
  4893. TCP_FLAG_CWR) >> 16);
  4894. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  4895. udp_tunnel_get_rx_info(netdev);
  4896. return 0;
  4897. }
  4898. /**
  4899. * i40e_vsi_open -
  4900. * @vsi: the VSI to open
  4901. *
  4902. * Finish initialization of the VSI.
  4903. *
  4904. * Returns 0 on success, negative value on failure
  4905. **/
  4906. int i40e_vsi_open(struct i40e_vsi *vsi)
  4907. {
  4908. struct i40e_pf *pf = vsi->back;
  4909. char int_name[I40E_INT_NAME_STR_LEN];
  4910. int err;
  4911. /* allocate descriptors */
  4912. err = i40e_vsi_setup_tx_resources(vsi);
  4913. if (err)
  4914. goto err_setup_tx;
  4915. err = i40e_vsi_setup_rx_resources(vsi);
  4916. if (err)
  4917. goto err_setup_rx;
  4918. err = i40e_vsi_configure(vsi);
  4919. if (err)
  4920. goto err_setup_rx;
  4921. if (vsi->netdev) {
  4922. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  4923. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  4924. err = i40e_vsi_request_irq(vsi, int_name);
  4925. if (err)
  4926. goto err_setup_rx;
  4927. /* Notify the stack of the actual queue counts. */
  4928. err = netif_set_real_num_tx_queues(vsi->netdev,
  4929. vsi->num_queue_pairs);
  4930. if (err)
  4931. goto err_set_queues;
  4932. err = netif_set_real_num_rx_queues(vsi->netdev,
  4933. vsi->num_queue_pairs);
  4934. if (err)
  4935. goto err_set_queues;
  4936. } else if (vsi->type == I40E_VSI_FDIR) {
  4937. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  4938. dev_driver_string(&pf->pdev->dev),
  4939. dev_name(&pf->pdev->dev));
  4940. err = i40e_vsi_request_irq(vsi, int_name);
  4941. } else {
  4942. err = -EINVAL;
  4943. goto err_setup_rx;
  4944. }
  4945. err = i40e_up_complete(vsi);
  4946. if (err)
  4947. goto err_up_complete;
  4948. return 0;
  4949. err_up_complete:
  4950. i40e_down(vsi);
  4951. err_set_queues:
  4952. i40e_vsi_free_irq(vsi);
  4953. err_setup_rx:
  4954. i40e_vsi_free_rx_resources(vsi);
  4955. err_setup_tx:
  4956. i40e_vsi_free_tx_resources(vsi);
  4957. if (vsi == pf->vsi[pf->lan_vsi])
  4958. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  4959. return err;
  4960. }
  4961. /**
  4962. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  4963. * @pf: Pointer to PF
  4964. *
  4965. * This function destroys the hlist where all the Flow Director
  4966. * filters were saved.
  4967. **/
  4968. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  4969. {
  4970. struct i40e_fdir_filter *filter;
  4971. struct hlist_node *node2;
  4972. hlist_for_each_entry_safe(filter, node2,
  4973. &pf->fdir_filter_list, fdir_node) {
  4974. hlist_del(&filter->fdir_node);
  4975. kfree(filter);
  4976. }
  4977. pf->fdir_pf_active_filters = 0;
  4978. }
  4979. /**
  4980. * i40e_close - Disables a network interface
  4981. * @netdev: network interface device structure
  4982. *
  4983. * The close entry point is called when an interface is de-activated
  4984. * by the OS. The hardware is still under the driver's control, but
  4985. * this netdev interface is disabled.
  4986. *
  4987. * Returns 0, this is not allowed to fail
  4988. **/
  4989. int i40e_close(struct net_device *netdev)
  4990. {
  4991. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4992. struct i40e_vsi *vsi = np->vsi;
  4993. i40e_vsi_close(vsi);
  4994. return 0;
  4995. }
  4996. /**
  4997. * i40e_do_reset - Start a PF or Core Reset sequence
  4998. * @pf: board private structure
  4999. * @reset_flags: which reset is requested
  5000. *
  5001. * The essential difference in resets is that the PF Reset
  5002. * doesn't clear the packet buffers, doesn't reset the PE
  5003. * firmware, and doesn't bother the other PFs on the chip.
  5004. **/
  5005. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  5006. {
  5007. u32 val;
  5008. WARN_ON(in_interrupt());
  5009. /* do the biggest reset indicated */
  5010. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  5011. /* Request a Global Reset
  5012. *
  5013. * This will start the chip's countdown to the actual full
  5014. * chip reset event, and a warning interrupt to be sent
  5015. * to all PFs, including the requestor. Our handler
  5016. * for the warning interrupt will deal with the shutdown
  5017. * and recovery of the switch setup.
  5018. */
  5019. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  5020. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  5021. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  5022. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  5023. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  5024. /* Request a Core Reset
  5025. *
  5026. * Same as Global Reset, except does *not* include the MAC/PHY
  5027. */
  5028. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  5029. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  5030. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  5031. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  5032. i40e_flush(&pf->hw);
  5033. } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
  5034. /* Request a PF Reset
  5035. *
  5036. * Resets only the PF-specific registers
  5037. *
  5038. * This goes directly to the tear-down and rebuild of
  5039. * the switch, since we need to do all the recovery as
  5040. * for the Core Reset.
  5041. */
  5042. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  5043. i40e_handle_reset_warning(pf);
  5044. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  5045. int v;
  5046. /* Find the VSI(s) that requested a re-init */
  5047. dev_info(&pf->pdev->dev,
  5048. "VSI reinit requested\n");
  5049. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5050. struct i40e_vsi *vsi = pf->vsi[v];
  5051. if (vsi != NULL &&
  5052. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  5053. i40e_vsi_reinit_locked(pf->vsi[v]);
  5054. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  5055. }
  5056. }
  5057. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  5058. int v;
  5059. /* Find the VSI(s) that needs to be brought down */
  5060. dev_info(&pf->pdev->dev, "VSI down requested\n");
  5061. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5062. struct i40e_vsi *vsi = pf->vsi[v];
  5063. if (vsi != NULL &&
  5064. test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
  5065. set_bit(__I40E_DOWN, &vsi->state);
  5066. i40e_down(vsi);
  5067. clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  5068. }
  5069. }
  5070. } else {
  5071. dev_info(&pf->pdev->dev,
  5072. "bad reset request 0x%08x\n", reset_flags);
  5073. }
  5074. }
  5075. #ifdef CONFIG_I40E_DCB
  5076. /**
  5077. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  5078. * @pf: board private structure
  5079. * @old_cfg: current DCB config
  5080. * @new_cfg: new DCB config
  5081. **/
  5082. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  5083. struct i40e_dcbx_config *old_cfg,
  5084. struct i40e_dcbx_config *new_cfg)
  5085. {
  5086. bool need_reconfig = false;
  5087. /* Check if ETS configuration has changed */
  5088. if (memcmp(&new_cfg->etscfg,
  5089. &old_cfg->etscfg,
  5090. sizeof(new_cfg->etscfg))) {
  5091. /* If Priority Table has changed reconfig is needed */
  5092. if (memcmp(&new_cfg->etscfg.prioritytable,
  5093. &old_cfg->etscfg.prioritytable,
  5094. sizeof(new_cfg->etscfg.prioritytable))) {
  5095. need_reconfig = true;
  5096. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  5097. }
  5098. if (memcmp(&new_cfg->etscfg.tcbwtable,
  5099. &old_cfg->etscfg.tcbwtable,
  5100. sizeof(new_cfg->etscfg.tcbwtable)))
  5101. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  5102. if (memcmp(&new_cfg->etscfg.tsatable,
  5103. &old_cfg->etscfg.tsatable,
  5104. sizeof(new_cfg->etscfg.tsatable)))
  5105. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  5106. }
  5107. /* Check if PFC configuration has changed */
  5108. if (memcmp(&new_cfg->pfc,
  5109. &old_cfg->pfc,
  5110. sizeof(new_cfg->pfc))) {
  5111. need_reconfig = true;
  5112. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  5113. }
  5114. /* Check if APP Table has changed */
  5115. if (memcmp(&new_cfg->app,
  5116. &old_cfg->app,
  5117. sizeof(new_cfg->app))) {
  5118. need_reconfig = true;
  5119. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  5120. }
  5121. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  5122. return need_reconfig;
  5123. }
  5124. /**
  5125. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  5126. * @pf: board private structure
  5127. * @e: event info posted on ARQ
  5128. **/
  5129. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  5130. struct i40e_arq_event_info *e)
  5131. {
  5132. struct i40e_aqc_lldp_get_mib *mib =
  5133. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  5134. struct i40e_hw *hw = &pf->hw;
  5135. struct i40e_dcbx_config tmp_dcbx_cfg;
  5136. bool need_reconfig = false;
  5137. int ret = 0;
  5138. u8 type;
  5139. /* Not DCB capable or capability disabled */
  5140. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  5141. return ret;
  5142. /* Ignore if event is not for Nearest Bridge */
  5143. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  5144. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  5145. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  5146. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  5147. return ret;
  5148. /* Check MIB Type and return if event for Remote MIB update */
  5149. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  5150. dev_dbg(&pf->pdev->dev,
  5151. "LLDP event mib type %s\n", type ? "remote" : "local");
  5152. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  5153. /* Update the remote cached instance and return */
  5154. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  5155. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  5156. &hw->remote_dcbx_config);
  5157. goto exit;
  5158. }
  5159. /* Store the old configuration */
  5160. tmp_dcbx_cfg = hw->local_dcbx_config;
  5161. /* Reset the old DCBx configuration data */
  5162. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  5163. /* Get updated DCBX data from firmware */
  5164. ret = i40e_get_dcb_config(&pf->hw);
  5165. if (ret) {
  5166. dev_info(&pf->pdev->dev,
  5167. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  5168. i40e_stat_str(&pf->hw, ret),
  5169. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5170. goto exit;
  5171. }
  5172. /* No change detected in DCBX configs */
  5173. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  5174. sizeof(tmp_dcbx_cfg))) {
  5175. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  5176. goto exit;
  5177. }
  5178. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  5179. &hw->local_dcbx_config);
  5180. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  5181. if (!need_reconfig)
  5182. goto exit;
  5183. /* Enable DCB tagging only when more than one TC */
  5184. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5185. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5186. else
  5187. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5188. set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5189. /* Reconfiguration needed quiesce all VSIs */
  5190. i40e_pf_quiesce_all_vsi(pf);
  5191. /* Changes in configuration update VEB/VSI */
  5192. i40e_dcb_reconfigure(pf);
  5193. ret = i40e_resume_port_tx(pf);
  5194. clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5195. /* In case of error no point in resuming VSIs */
  5196. if (ret)
  5197. goto exit;
  5198. /* Wait for the PF's queues to be disabled */
  5199. ret = i40e_pf_wait_queues_disabled(pf);
  5200. if (ret) {
  5201. /* Schedule PF reset to recover */
  5202. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5203. i40e_service_event_schedule(pf);
  5204. } else {
  5205. i40e_pf_unquiesce_all_vsi(pf);
  5206. /* Notify the client for the DCB changes */
  5207. i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]);
  5208. }
  5209. exit:
  5210. return ret;
  5211. }
  5212. #endif /* CONFIG_I40E_DCB */
  5213. /**
  5214. * i40e_do_reset_safe - Protected reset path for userland calls.
  5215. * @pf: board private structure
  5216. * @reset_flags: which reset is requested
  5217. *
  5218. **/
  5219. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  5220. {
  5221. rtnl_lock();
  5222. i40e_do_reset(pf, reset_flags);
  5223. rtnl_unlock();
  5224. }
  5225. /**
  5226. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  5227. * @pf: board private structure
  5228. * @e: event info posted on ARQ
  5229. *
  5230. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  5231. * and VF queues
  5232. **/
  5233. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  5234. struct i40e_arq_event_info *e)
  5235. {
  5236. struct i40e_aqc_lan_overflow *data =
  5237. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  5238. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  5239. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  5240. struct i40e_hw *hw = &pf->hw;
  5241. struct i40e_vf *vf;
  5242. u16 vf_id;
  5243. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  5244. queue, qtx_ctl);
  5245. /* Queue belongs to VF, find the VF and issue VF reset */
  5246. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  5247. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  5248. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  5249. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  5250. vf_id -= hw->func_caps.vf_base_id;
  5251. vf = &pf->vf[vf_id];
  5252. i40e_vc_notify_vf_reset(vf);
  5253. /* Allow VF to process pending reset notification */
  5254. msleep(20);
  5255. i40e_reset_vf(vf, false);
  5256. }
  5257. }
  5258. /**
  5259. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  5260. * @pf: board private structure
  5261. **/
  5262. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  5263. {
  5264. u32 val, fcnt_prog;
  5265. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5266. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  5267. return fcnt_prog;
  5268. }
  5269. /**
  5270. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  5271. * @pf: board private structure
  5272. **/
  5273. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  5274. {
  5275. u32 val, fcnt_prog;
  5276. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5277. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  5278. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  5279. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  5280. return fcnt_prog;
  5281. }
  5282. /**
  5283. * i40e_get_global_fd_count - Get total FD filters programmed on device
  5284. * @pf: board private structure
  5285. **/
  5286. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  5287. {
  5288. u32 val, fcnt_prog;
  5289. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  5290. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  5291. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  5292. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  5293. return fcnt_prog;
  5294. }
  5295. /**
  5296. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  5297. * @pf: board private structure
  5298. **/
  5299. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  5300. {
  5301. struct i40e_fdir_filter *filter;
  5302. u32 fcnt_prog, fcnt_avail;
  5303. struct hlist_node *node;
  5304. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5305. return;
  5306. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  5307. * to re-enable
  5308. */
  5309. fcnt_prog = i40e_get_global_fd_count(pf);
  5310. fcnt_avail = pf->fdir_pf_filter_count;
  5311. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  5312. (pf->fd_add_err == 0) ||
  5313. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  5314. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  5315. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  5316. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5317. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5318. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  5319. }
  5320. }
  5321. /* Wait for some more space to be available to turn on ATR. We also
  5322. * must check that no existing ntuple rules for TCP are in effect
  5323. */
  5324. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  5325. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5326. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5327. (pf->fd_tcp_rule == 0)) {
  5328. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5329. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5330. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  5331. }
  5332. }
  5333. /* if hw had a problem adding a filter, delete it */
  5334. if (pf->fd_inv > 0) {
  5335. hlist_for_each_entry_safe(filter, node,
  5336. &pf->fdir_filter_list, fdir_node) {
  5337. if (filter->fd_id == pf->fd_inv) {
  5338. hlist_del(&filter->fdir_node);
  5339. kfree(filter);
  5340. pf->fdir_pf_active_filters--;
  5341. }
  5342. }
  5343. }
  5344. }
  5345. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  5346. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  5347. /**
  5348. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  5349. * @pf: board private structure
  5350. **/
  5351. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  5352. {
  5353. unsigned long min_flush_time;
  5354. int flush_wait_retry = 50;
  5355. bool disable_atr = false;
  5356. int fd_room;
  5357. int reg;
  5358. if (!time_after(jiffies, pf->fd_flush_timestamp +
  5359. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  5360. return;
  5361. /* If the flush is happening too quick and we have mostly SB rules we
  5362. * should not re-enable ATR for some time.
  5363. */
  5364. min_flush_time = pf->fd_flush_timestamp +
  5365. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  5366. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  5367. if (!(time_after(jiffies, min_flush_time)) &&
  5368. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  5369. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5370. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  5371. disable_atr = true;
  5372. }
  5373. pf->fd_flush_timestamp = jiffies;
  5374. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  5375. /* flush all filters */
  5376. wr32(&pf->hw, I40E_PFQF_CTL_1,
  5377. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  5378. i40e_flush(&pf->hw);
  5379. pf->fd_flush_cnt++;
  5380. pf->fd_add_err = 0;
  5381. do {
  5382. /* Check FD flush status every 5-6msec */
  5383. usleep_range(5000, 6000);
  5384. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  5385. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  5386. break;
  5387. } while (flush_wait_retry--);
  5388. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  5389. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  5390. } else {
  5391. /* replay sideband filters */
  5392. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  5393. if (!disable_atr)
  5394. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5395. clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  5396. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5397. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  5398. }
  5399. }
  5400. /**
  5401. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  5402. * @pf: board private structure
  5403. **/
  5404. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  5405. {
  5406. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  5407. }
  5408. /* We can see up to 256 filter programming desc in transit if the filters are
  5409. * being applied really fast; before we see the first
  5410. * filter miss error on Rx queue 0. Accumulating enough error messages before
  5411. * reacting will make sure we don't cause flush too often.
  5412. */
  5413. #define I40E_MAX_FD_PROGRAM_ERROR 256
  5414. /**
  5415. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  5416. * @pf: board private structure
  5417. **/
  5418. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  5419. {
  5420. /* if interface is down do nothing */
  5421. if (test_bit(__I40E_DOWN, &pf->state))
  5422. return;
  5423. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5424. i40e_fdir_flush_and_replay(pf);
  5425. i40e_fdir_check_and_reenable(pf);
  5426. }
  5427. /**
  5428. * i40e_vsi_link_event - notify VSI of a link event
  5429. * @vsi: vsi to be notified
  5430. * @link_up: link up or down
  5431. **/
  5432. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  5433. {
  5434. if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
  5435. return;
  5436. switch (vsi->type) {
  5437. case I40E_VSI_MAIN:
  5438. #ifdef I40E_FCOE
  5439. case I40E_VSI_FCOE:
  5440. #endif
  5441. if (!vsi->netdev || !vsi->netdev_registered)
  5442. break;
  5443. if (link_up) {
  5444. netif_carrier_on(vsi->netdev);
  5445. netif_tx_wake_all_queues(vsi->netdev);
  5446. } else {
  5447. netif_carrier_off(vsi->netdev);
  5448. netif_tx_stop_all_queues(vsi->netdev);
  5449. }
  5450. break;
  5451. case I40E_VSI_SRIOV:
  5452. case I40E_VSI_VMDQ2:
  5453. case I40E_VSI_CTRL:
  5454. case I40E_VSI_IWARP:
  5455. case I40E_VSI_MIRROR:
  5456. default:
  5457. /* there is no notification for other VSIs */
  5458. break;
  5459. }
  5460. }
  5461. /**
  5462. * i40e_veb_link_event - notify elements on the veb of a link event
  5463. * @veb: veb to be notified
  5464. * @link_up: link up or down
  5465. **/
  5466. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  5467. {
  5468. struct i40e_pf *pf;
  5469. int i;
  5470. if (!veb || !veb->pf)
  5471. return;
  5472. pf = veb->pf;
  5473. /* depth first... */
  5474. for (i = 0; i < I40E_MAX_VEB; i++)
  5475. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  5476. i40e_veb_link_event(pf->veb[i], link_up);
  5477. /* ... now the local VSIs */
  5478. for (i = 0; i < pf->num_alloc_vsi; i++)
  5479. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  5480. i40e_vsi_link_event(pf->vsi[i], link_up);
  5481. }
  5482. /**
  5483. * i40e_link_event - Update netif_carrier status
  5484. * @pf: board private structure
  5485. **/
  5486. static void i40e_link_event(struct i40e_pf *pf)
  5487. {
  5488. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5489. u8 new_link_speed, old_link_speed;
  5490. i40e_status status;
  5491. bool new_link, old_link;
  5492. /* save off old link status information */
  5493. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  5494. /* set this to force the get_link_status call to refresh state */
  5495. pf->hw.phy.get_link_info = true;
  5496. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  5497. status = i40e_get_link_status(&pf->hw, &new_link);
  5498. if (status) {
  5499. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  5500. status);
  5501. return;
  5502. }
  5503. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  5504. new_link_speed = pf->hw.phy.link_info.link_speed;
  5505. if (new_link == old_link &&
  5506. new_link_speed == old_link_speed &&
  5507. (test_bit(__I40E_DOWN, &vsi->state) ||
  5508. new_link == netif_carrier_ok(vsi->netdev)))
  5509. return;
  5510. if (!test_bit(__I40E_DOWN, &vsi->state))
  5511. i40e_print_link_message(vsi, new_link);
  5512. /* Notify the base of the switch tree connected to
  5513. * the link. Floating VEBs are not notified.
  5514. */
  5515. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  5516. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  5517. else
  5518. i40e_vsi_link_event(vsi, new_link);
  5519. if (pf->vf)
  5520. i40e_vc_notify_link_state(pf);
  5521. if (pf->flags & I40E_FLAG_PTP)
  5522. i40e_ptp_set_increment(pf);
  5523. }
  5524. /**
  5525. * i40e_watchdog_subtask - periodic checks not using event driven response
  5526. * @pf: board private structure
  5527. **/
  5528. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  5529. {
  5530. int i;
  5531. /* if interface is down do nothing */
  5532. if (test_bit(__I40E_DOWN, &pf->state) ||
  5533. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5534. return;
  5535. /* make sure we don't do these things too often */
  5536. if (time_before(jiffies, (pf->service_timer_previous +
  5537. pf->service_timer_period)))
  5538. return;
  5539. pf->service_timer_previous = jiffies;
  5540. if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
  5541. i40e_link_event(pf);
  5542. /* Update the stats for active netdevs so the network stack
  5543. * can look at updated numbers whenever it cares to
  5544. */
  5545. for (i = 0; i < pf->num_alloc_vsi; i++)
  5546. if (pf->vsi[i] && pf->vsi[i]->netdev)
  5547. i40e_update_stats(pf->vsi[i]);
  5548. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  5549. /* Update the stats for the active switching components */
  5550. for (i = 0; i < I40E_MAX_VEB; i++)
  5551. if (pf->veb[i])
  5552. i40e_update_veb_stats(pf->veb[i]);
  5553. }
  5554. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  5555. }
  5556. /**
  5557. * i40e_reset_subtask - Set up for resetting the device and driver
  5558. * @pf: board private structure
  5559. **/
  5560. static void i40e_reset_subtask(struct i40e_pf *pf)
  5561. {
  5562. u32 reset_flags = 0;
  5563. rtnl_lock();
  5564. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  5565. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  5566. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  5567. }
  5568. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  5569. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  5570. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5571. }
  5572. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  5573. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  5574. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  5575. }
  5576. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  5577. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  5578. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  5579. }
  5580. if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
  5581. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  5582. clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
  5583. }
  5584. /* If there's a recovery already waiting, it takes
  5585. * precedence before starting a new reset sequence.
  5586. */
  5587. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  5588. i40e_handle_reset_warning(pf);
  5589. goto unlock;
  5590. }
  5591. /* If we're already down or resetting, just bail */
  5592. if (reset_flags &&
  5593. !test_bit(__I40E_DOWN, &pf->state) &&
  5594. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5595. i40e_do_reset(pf, reset_flags);
  5596. unlock:
  5597. rtnl_unlock();
  5598. }
  5599. /**
  5600. * i40e_handle_link_event - Handle link event
  5601. * @pf: board private structure
  5602. * @e: event info posted on ARQ
  5603. **/
  5604. static void i40e_handle_link_event(struct i40e_pf *pf,
  5605. struct i40e_arq_event_info *e)
  5606. {
  5607. struct i40e_aqc_get_link_status *status =
  5608. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  5609. /* Do a new status request to re-enable LSE reporting
  5610. * and load new status information into the hw struct
  5611. * This completely ignores any state information
  5612. * in the ARQ event info, instead choosing to always
  5613. * issue the AQ update link status command.
  5614. */
  5615. i40e_link_event(pf);
  5616. /* check for unqualified module, if link is down */
  5617. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  5618. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  5619. (!(status->link_info & I40E_AQ_LINK_UP)))
  5620. dev_err(&pf->pdev->dev,
  5621. "The driver failed to link because an unqualified module was detected.\n");
  5622. }
  5623. /**
  5624. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  5625. * @pf: board private structure
  5626. **/
  5627. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  5628. {
  5629. struct i40e_arq_event_info event;
  5630. struct i40e_hw *hw = &pf->hw;
  5631. u16 pending, i = 0;
  5632. i40e_status ret;
  5633. u16 opcode;
  5634. u32 oldval;
  5635. u32 val;
  5636. /* Do not run clean AQ when PF reset fails */
  5637. if (test_bit(__I40E_RESET_FAILED, &pf->state))
  5638. return;
  5639. /* check for error indications */
  5640. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  5641. oldval = val;
  5642. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  5643. if (hw->debug_mask & I40E_DEBUG_AQ)
  5644. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  5645. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  5646. }
  5647. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  5648. if (hw->debug_mask & I40E_DEBUG_AQ)
  5649. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  5650. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  5651. pf->arq_overflows++;
  5652. }
  5653. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  5654. if (hw->debug_mask & I40E_DEBUG_AQ)
  5655. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  5656. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  5657. }
  5658. if (oldval != val)
  5659. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  5660. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  5661. oldval = val;
  5662. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  5663. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5664. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  5665. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  5666. }
  5667. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  5668. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5669. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  5670. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  5671. }
  5672. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  5673. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5674. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  5675. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  5676. }
  5677. if (oldval != val)
  5678. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  5679. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  5680. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  5681. if (!event.msg_buf)
  5682. return;
  5683. do {
  5684. ret = i40e_clean_arq_element(hw, &event, &pending);
  5685. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  5686. break;
  5687. else if (ret) {
  5688. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  5689. break;
  5690. }
  5691. opcode = le16_to_cpu(event.desc.opcode);
  5692. switch (opcode) {
  5693. case i40e_aqc_opc_get_link_status:
  5694. i40e_handle_link_event(pf, &event);
  5695. break;
  5696. case i40e_aqc_opc_send_msg_to_pf:
  5697. ret = i40e_vc_process_vf_msg(pf,
  5698. le16_to_cpu(event.desc.retval),
  5699. le32_to_cpu(event.desc.cookie_high),
  5700. le32_to_cpu(event.desc.cookie_low),
  5701. event.msg_buf,
  5702. event.msg_len);
  5703. break;
  5704. case i40e_aqc_opc_lldp_update_mib:
  5705. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  5706. #ifdef CONFIG_I40E_DCB
  5707. rtnl_lock();
  5708. ret = i40e_handle_lldp_event(pf, &event);
  5709. rtnl_unlock();
  5710. #endif /* CONFIG_I40E_DCB */
  5711. break;
  5712. case i40e_aqc_opc_event_lan_overflow:
  5713. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  5714. i40e_handle_lan_overflow_event(pf, &event);
  5715. break;
  5716. case i40e_aqc_opc_send_msg_to_peer:
  5717. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  5718. break;
  5719. case i40e_aqc_opc_nvm_erase:
  5720. case i40e_aqc_opc_nvm_update:
  5721. case i40e_aqc_opc_oem_post_update:
  5722. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  5723. "ARQ NVM operation 0x%04x completed\n",
  5724. opcode);
  5725. break;
  5726. default:
  5727. dev_info(&pf->pdev->dev,
  5728. "ARQ: Unknown event 0x%04x ignored\n",
  5729. opcode);
  5730. break;
  5731. }
  5732. } while (pending && (i++ < pf->adminq_work_limit));
  5733. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  5734. /* re-enable Admin queue interrupt cause */
  5735. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  5736. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  5737. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  5738. i40e_flush(hw);
  5739. kfree(event.msg_buf);
  5740. }
  5741. /**
  5742. * i40e_verify_eeprom - make sure eeprom is good to use
  5743. * @pf: board private structure
  5744. **/
  5745. static void i40e_verify_eeprom(struct i40e_pf *pf)
  5746. {
  5747. int err;
  5748. err = i40e_diag_eeprom_test(&pf->hw);
  5749. if (err) {
  5750. /* retry in case of garbage read */
  5751. err = i40e_diag_eeprom_test(&pf->hw);
  5752. if (err) {
  5753. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  5754. err);
  5755. set_bit(__I40E_BAD_EEPROM, &pf->state);
  5756. }
  5757. }
  5758. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  5759. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  5760. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  5761. }
  5762. }
  5763. /**
  5764. * i40e_enable_pf_switch_lb
  5765. * @pf: pointer to the PF structure
  5766. *
  5767. * enable switch loop back or die - no point in a return value
  5768. **/
  5769. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  5770. {
  5771. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5772. struct i40e_vsi_context ctxt;
  5773. int ret;
  5774. ctxt.seid = pf->main_vsi_seid;
  5775. ctxt.pf_num = pf->hw.pf_id;
  5776. ctxt.vf_num = 0;
  5777. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5778. if (ret) {
  5779. dev_info(&pf->pdev->dev,
  5780. "couldn't get PF vsi config, err %s aq_err %s\n",
  5781. i40e_stat_str(&pf->hw, ret),
  5782. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5783. return;
  5784. }
  5785. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5786. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5787. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5788. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5789. if (ret) {
  5790. dev_info(&pf->pdev->dev,
  5791. "update vsi switch failed, err %s aq_err %s\n",
  5792. i40e_stat_str(&pf->hw, ret),
  5793. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5794. }
  5795. }
  5796. /**
  5797. * i40e_disable_pf_switch_lb
  5798. * @pf: pointer to the PF structure
  5799. *
  5800. * disable switch loop back or die - no point in a return value
  5801. **/
  5802. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  5803. {
  5804. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5805. struct i40e_vsi_context ctxt;
  5806. int ret;
  5807. ctxt.seid = pf->main_vsi_seid;
  5808. ctxt.pf_num = pf->hw.pf_id;
  5809. ctxt.vf_num = 0;
  5810. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5811. if (ret) {
  5812. dev_info(&pf->pdev->dev,
  5813. "couldn't get PF vsi config, err %s aq_err %s\n",
  5814. i40e_stat_str(&pf->hw, ret),
  5815. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5816. return;
  5817. }
  5818. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5819. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5820. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5821. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5822. if (ret) {
  5823. dev_info(&pf->pdev->dev,
  5824. "update vsi switch failed, err %s aq_err %s\n",
  5825. i40e_stat_str(&pf->hw, ret),
  5826. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5827. }
  5828. }
  5829. /**
  5830. * i40e_config_bridge_mode - Configure the HW bridge mode
  5831. * @veb: pointer to the bridge instance
  5832. *
  5833. * Configure the loop back mode for the LAN VSI that is downlink to the
  5834. * specified HW bridge instance. It is expected this function is called
  5835. * when a new HW bridge is instantiated.
  5836. **/
  5837. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  5838. {
  5839. struct i40e_pf *pf = veb->pf;
  5840. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  5841. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  5842. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  5843. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  5844. i40e_disable_pf_switch_lb(pf);
  5845. else
  5846. i40e_enable_pf_switch_lb(pf);
  5847. }
  5848. /**
  5849. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  5850. * @veb: pointer to the VEB instance
  5851. *
  5852. * This is a recursive function that first builds the attached VSIs then
  5853. * recurses in to build the next layer of VEB. We track the connections
  5854. * through our own index numbers because the seid's from the HW could
  5855. * change across the reset.
  5856. **/
  5857. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  5858. {
  5859. struct i40e_vsi *ctl_vsi = NULL;
  5860. struct i40e_pf *pf = veb->pf;
  5861. int v, veb_idx;
  5862. int ret;
  5863. /* build VSI that owns this VEB, temporarily attached to base VEB */
  5864. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  5865. if (pf->vsi[v] &&
  5866. pf->vsi[v]->veb_idx == veb->idx &&
  5867. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  5868. ctl_vsi = pf->vsi[v];
  5869. break;
  5870. }
  5871. }
  5872. if (!ctl_vsi) {
  5873. dev_info(&pf->pdev->dev,
  5874. "missing owner VSI for veb_idx %d\n", veb->idx);
  5875. ret = -ENOENT;
  5876. goto end_reconstitute;
  5877. }
  5878. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  5879. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5880. ret = i40e_add_vsi(ctl_vsi);
  5881. if (ret) {
  5882. dev_info(&pf->pdev->dev,
  5883. "rebuild of veb_idx %d owner VSI failed: %d\n",
  5884. veb->idx, ret);
  5885. goto end_reconstitute;
  5886. }
  5887. i40e_vsi_reset_stats(ctl_vsi);
  5888. /* create the VEB in the switch and move the VSI onto the VEB */
  5889. ret = i40e_add_veb(veb, ctl_vsi);
  5890. if (ret)
  5891. goto end_reconstitute;
  5892. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  5893. veb->bridge_mode = BRIDGE_MODE_VEB;
  5894. else
  5895. veb->bridge_mode = BRIDGE_MODE_VEPA;
  5896. i40e_config_bridge_mode(veb);
  5897. /* create the remaining VSIs attached to this VEB */
  5898. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5899. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  5900. continue;
  5901. if (pf->vsi[v]->veb_idx == veb->idx) {
  5902. struct i40e_vsi *vsi = pf->vsi[v];
  5903. vsi->uplink_seid = veb->seid;
  5904. ret = i40e_add_vsi(vsi);
  5905. if (ret) {
  5906. dev_info(&pf->pdev->dev,
  5907. "rebuild of vsi_idx %d failed: %d\n",
  5908. v, ret);
  5909. goto end_reconstitute;
  5910. }
  5911. i40e_vsi_reset_stats(vsi);
  5912. }
  5913. }
  5914. /* create any VEBs attached to this VEB - RECURSION */
  5915. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5916. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  5917. pf->veb[veb_idx]->uplink_seid = veb->seid;
  5918. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  5919. if (ret)
  5920. break;
  5921. }
  5922. }
  5923. end_reconstitute:
  5924. return ret;
  5925. }
  5926. /**
  5927. * i40e_get_capabilities - get info about the HW
  5928. * @pf: the PF struct
  5929. **/
  5930. static int i40e_get_capabilities(struct i40e_pf *pf)
  5931. {
  5932. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  5933. u16 data_size;
  5934. int buf_len;
  5935. int err;
  5936. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  5937. do {
  5938. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  5939. if (!cap_buf)
  5940. return -ENOMEM;
  5941. /* this loads the data into the hw struct for us */
  5942. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  5943. &data_size,
  5944. i40e_aqc_opc_list_func_capabilities,
  5945. NULL);
  5946. /* data loaded, buffer no longer needed */
  5947. kfree(cap_buf);
  5948. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  5949. /* retry with a larger buffer */
  5950. buf_len = data_size;
  5951. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  5952. dev_info(&pf->pdev->dev,
  5953. "capability discovery failed, err %s aq_err %s\n",
  5954. i40e_stat_str(&pf->hw, err),
  5955. i40e_aq_str(&pf->hw,
  5956. pf->hw.aq.asq_last_status));
  5957. return -ENODEV;
  5958. }
  5959. } while (err);
  5960. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  5961. dev_info(&pf->pdev->dev,
  5962. "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",
  5963. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  5964. pf->hw.func_caps.num_msix_vectors,
  5965. pf->hw.func_caps.num_msix_vectors_vf,
  5966. pf->hw.func_caps.fd_filters_guaranteed,
  5967. pf->hw.func_caps.fd_filters_best_effort,
  5968. pf->hw.func_caps.num_tx_qp,
  5969. pf->hw.func_caps.num_vsis);
  5970. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  5971. + pf->hw.func_caps.num_vfs)
  5972. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  5973. dev_info(&pf->pdev->dev,
  5974. "got num_vsis %d, setting num_vsis to %d\n",
  5975. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  5976. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  5977. }
  5978. return 0;
  5979. }
  5980. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  5981. /**
  5982. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  5983. * @pf: board private structure
  5984. **/
  5985. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  5986. {
  5987. struct i40e_vsi *vsi;
  5988. /* quick workaround for an NVM issue that leaves a critical register
  5989. * uninitialized
  5990. */
  5991. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  5992. static const u32 hkey[] = {
  5993. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  5994. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  5995. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  5996. 0x95b3a76d};
  5997. int i;
  5998. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  5999. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  6000. }
  6001. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  6002. return;
  6003. /* find existing VSI and see if it needs configuring */
  6004. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  6005. /* create a new VSI if none exists */
  6006. if (!vsi) {
  6007. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  6008. pf->vsi[pf->lan_vsi]->seid, 0);
  6009. if (!vsi) {
  6010. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  6011. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6012. return;
  6013. }
  6014. }
  6015. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  6016. }
  6017. /**
  6018. * i40e_fdir_teardown - release the Flow Director resources
  6019. * @pf: board private structure
  6020. **/
  6021. static void i40e_fdir_teardown(struct i40e_pf *pf)
  6022. {
  6023. struct i40e_vsi *vsi;
  6024. i40e_fdir_filter_exit(pf);
  6025. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  6026. if (vsi)
  6027. i40e_vsi_release(vsi);
  6028. }
  6029. /**
  6030. * i40e_prep_for_reset - prep for the core to reset
  6031. * @pf: board private structure
  6032. *
  6033. * Close up the VFs and other things in prep for PF Reset.
  6034. **/
  6035. static void i40e_prep_for_reset(struct i40e_pf *pf)
  6036. {
  6037. struct i40e_hw *hw = &pf->hw;
  6038. i40e_status ret = 0;
  6039. u32 v;
  6040. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  6041. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  6042. return;
  6043. if (i40e_check_asq_alive(&pf->hw))
  6044. i40e_vc_notify_reset(pf);
  6045. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  6046. /* quiesce the VSIs and their queues that are not already DOWN */
  6047. i40e_pf_quiesce_all_vsi(pf);
  6048. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6049. if (pf->vsi[v])
  6050. pf->vsi[v]->seid = 0;
  6051. }
  6052. i40e_shutdown_adminq(&pf->hw);
  6053. /* call shutdown HMC */
  6054. if (hw->hmc.hmc_obj) {
  6055. ret = i40e_shutdown_lan_hmc(hw);
  6056. if (ret)
  6057. dev_warn(&pf->pdev->dev,
  6058. "shutdown_lan_hmc failed: %d\n", ret);
  6059. }
  6060. }
  6061. /**
  6062. * i40e_send_version - update firmware with driver version
  6063. * @pf: PF struct
  6064. */
  6065. static void i40e_send_version(struct i40e_pf *pf)
  6066. {
  6067. struct i40e_driver_version dv;
  6068. dv.major_version = DRV_VERSION_MAJOR;
  6069. dv.minor_version = DRV_VERSION_MINOR;
  6070. dv.build_version = DRV_VERSION_BUILD;
  6071. dv.subbuild_version = 0;
  6072. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  6073. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  6074. }
  6075. /**
  6076. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  6077. * @pf: board private structure
  6078. * @reinit: if the Main VSI needs to re-initialized.
  6079. **/
  6080. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  6081. {
  6082. struct i40e_hw *hw = &pf->hw;
  6083. u8 set_fc_aq_fail = 0;
  6084. i40e_status ret;
  6085. u32 val;
  6086. u32 v;
  6087. /* Now we wait for GRST to settle out.
  6088. * We don't have to delete the VEBs or VSIs from the hw switch
  6089. * because the reset will make them disappear.
  6090. */
  6091. ret = i40e_pf_reset(hw);
  6092. if (ret) {
  6093. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  6094. set_bit(__I40E_RESET_FAILED, &pf->state);
  6095. goto clear_recovery;
  6096. }
  6097. pf->pfr_count++;
  6098. if (test_bit(__I40E_DOWN, &pf->state))
  6099. goto clear_recovery;
  6100. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  6101. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  6102. ret = i40e_init_adminq(&pf->hw);
  6103. if (ret) {
  6104. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  6105. i40e_stat_str(&pf->hw, ret),
  6106. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6107. goto clear_recovery;
  6108. }
  6109. /* re-verify the eeprom if we just had an EMP reset */
  6110. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
  6111. i40e_verify_eeprom(pf);
  6112. i40e_clear_pxe_mode(hw);
  6113. ret = i40e_get_capabilities(pf);
  6114. if (ret)
  6115. goto end_core_reset;
  6116. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  6117. hw->func_caps.num_rx_qp,
  6118. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  6119. if (ret) {
  6120. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  6121. goto end_core_reset;
  6122. }
  6123. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  6124. if (ret) {
  6125. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  6126. goto end_core_reset;
  6127. }
  6128. #ifdef CONFIG_I40E_DCB
  6129. ret = i40e_init_pf_dcb(pf);
  6130. if (ret) {
  6131. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  6132. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  6133. /* Continue without DCB enabled */
  6134. }
  6135. #endif /* CONFIG_I40E_DCB */
  6136. #ifdef I40E_FCOE
  6137. i40e_init_pf_fcoe(pf);
  6138. #endif
  6139. /* do basic switch setup */
  6140. ret = i40e_setup_pf_switch(pf, reinit);
  6141. if (ret)
  6142. goto end_core_reset;
  6143. /* The driver only wants link up/down and module qualification
  6144. * reports from firmware. Note the negative logic.
  6145. */
  6146. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  6147. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  6148. I40E_AQ_EVENT_MEDIA_NA |
  6149. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  6150. if (ret)
  6151. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  6152. i40e_stat_str(&pf->hw, ret),
  6153. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6154. /* make sure our flow control settings are restored */
  6155. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  6156. if (ret)
  6157. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  6158. i40e_stat_str(&pf->hw, ret),
  6159. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6160. /* Rebuild the VSIs and VEBs that existed before reset.
  6161. * They are still in our local switch element arrays, so only
  6162. * need to rebuild the switch model in the HW.
  6163. *
  6164. * If there were VEBs but the reconstitution failed, we'll try
  6165. * try to recover minimal use by getting the basic PF VSI working.
  6166. */
  6167. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  6168. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  6169. /* find the one VEB connected to the MAC, and find orphans */
  6170. for (v = 0; v < I40E_MAX_VEB; v++) {
  6171. if (!pf->veb[v])
  6172. continue;
  6173. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  6174. pf->veb[v]->uplink_seid == 0) {
  6175. ret = i40e_reconstitute_veb(pf->veb[v]);
  6176. if (!ret)
  6177. continue;
  6178. /* If Main VEB failed, we're in deep doodoo,
  6179. * so give up rebuilding the switch and set up
  6180. * for minimal rebuild of PF VSI.
  6181. * If orphan failed, we'll report the error
  6182. * but try to keep going.
  6183. */
  6184. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  6185. dev_info(&pf->pdev->dev,
  6186. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  6187. ret);
  6188. pf->vsi[pf->lan_vsi]->uplink_seid
  6189. = pf->mac_seid;
  6190. break;
  6191. } else if (pf->veb[v]->uplink_seid == 0) {
  6192. dev_info(&pf->pdev->dev,
  6193. "rebuild of orphan VEB failed: %d\n",
  6194. ret);
  6195. }
  6196. }
  6197. }
  6198. }
  6199. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  6200. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  6201. /* no VEB, so rebuild only the Main VSI */
  6202. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  6203. if (ret) {
  6204. dev_info(&pf->pdev->dev,
  6205. "rebuild of Main VSI failed: %d\n", ret);
  6206. goto end_core_reset;
  6207. }
  6208. }
  6209. /* Reconfigure hardware for allowing smaller MSS in the case
  6210. * of TSO, so that we avoid the MDD being fired and causing
  6211. * a reset in the case of small MSS+TSO.
  6212. */
  6213. #define I40E_REG_MSS 0x000E64DC
  6214. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  6215. #define I40E_64BYTE_MSS 0x400000
  6216. val = rd32(hw, I40E_REG_MSS);
  6217. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  6218. val &= ~I40E_REG_MSS_MIN_MASK;
  6219. val |= I40E_64BYTE_MSS;
  6220. wr32(hw, I40E_REG_MSS, val);
  6221. }
  6222. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  6223. msleep(75);
  6224. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  6225. if (ret)
  6226. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  6227. i40e_stat_str(&pf->hw, ret),
  6228. i40e_aq_str(&pf->hw,
  6229. pf->hw.aq.asq_last_status));
  6230. }
  6231. /* reinit the misc interrupt */
  6232. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6233. ret = i40e_setup_misc_vector(pf);
  6234. /* Add a filter to drop all Flow control frames from any VSI from being
  6235. * transmitted. By doing so we stop a malicious VF from sending out
  6236. * PAUSE or PFC frames and potentially controlling traffic for other
  6237. * PF/VF VSIs.
  6238. * The FW can still send Flow control frames if enabled.
  6239. */
  6240. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  6241. pf->main_vsi_seid);
  6242. /* restart the VSIs that were rebuilt and running before the reset */
  6243. i40e_pf_unquiesce_all_vsi(pf);
  6244. if (pf->num_alloc_vfs) {
  6245. for (v = 0; v < pf->num_alloc_vfs; v++)
  6246. i40e_reset_vf(&pf->vf[v], true);
  6247. }
  6248. /* tell the firmware that we're starting */
  6249. i40e_send_version(pf);
  6250. end_core_reset:
  6251. clear_bit(__I40E_RESET_FAILED, &pf->state);
  6252. clear_recovery:
  6253. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  6254. }
  6255. /**
  6256. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  6257. * @pf: board private structure
  6258. *
  6259. * Close up the VFs and other things in prep for a Core Reset,
  6260. * then get ready to rebuild the world.
  6261. **/
  6262. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  6263. {
  6264. i40e_prep_for_reset(pf);
  6265. i40e_reset_and_rebuild(pf, false);
  6266. }
  6267. /**
  6268. * i40e_handle_mdd_event
  6269. * @pf: pointer to the PF structure
  6270. *
  6271. * Called from the MDD irq handler to identify possibly malicious vfs
  6272. **/
  6273. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  6274. {
  6275. struct i40e_hw *hw = &pf->hw;
  6276. bool mdd_detected = false;
  6277. bool pf_mdd_detected = false;
  6278. struct i40e_vf *vf;
  6279. u32 reg;
  6280. int i;
  6281. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  6282. return;
  6283. /* find what triggered the MDD event */
  6284. reg = rd32(hw, I40E_GL_MDET_TX);
  6285. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  6286. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  6287. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  6288. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  6289. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  6290. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  6291. I40E_GL_MDET_TX_EVENT_SHIFT;
  6292. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  6293. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  6294. pf->hw.func_caps.base_queue;
  6295. if (netif_msg_tx_err(pf))
  6296. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  6297. event, queue, pf_num, vf_num);
  6298. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  6299. mdd_detected = true;
  6300. }
  6301. reg = rd32(hw, I40E_GL_MDET_RX);
  6302. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  6303. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  6304. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  6305. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  6306. I40E_GL_MDET_RX_EVENT_SHIFT;
  6307. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  6308. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  6309. pf->hw.func_caps.base_queue;
  6310. if (netif_msg_rx_err(pf))
  6311. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  6312. event, queue, func);
  6313. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  6314. mdd_detected = true;
  6315. }
  6316. if (mdd_detected) {
  6317. reg = rd32(hw, I40E_PF_MDET_TX);
  6318. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  6319. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  6320. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  6321. pf_mdd_detected = true;
  6322. }
  6323. reg = rd32(hw, I40E_PF_MDET_RX);
  6324. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  6325. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  6326. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  6327. pf_mdd_detected = true;
  6328. }
  6329. /* Queue belongs to the PF, initiate a reset */
  6330. if (pf_mdd_detected) {
  6331. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  6332. i40e_service_event_schedule(pf);
  6333. }
  6334. }
  6335. /* see if one of the VFs needs its hand slapped */
  6336. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  6337. vf = &(pf->vf[i]);
  6338. reg = rd32(hw, I40E_VP_MDET_TX(i));
  6339. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  6340. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  6341. vf->num_mdd_events++;
  6342. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  6343. i);
  6344. }
  6345. reg = rd32(hw, I40E_VP_MDET_RX(i));
  6346. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  6347. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  6348. vf->num_mdd_events++;
  6349. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  6350. i);
  6351. }
  6352. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  6353. dev_info(&pf->pdev->dev,
  6354. "Too many MDD events on VF %d, disabled\n", i);
  6355. dev_info(&pf->pdev->dev,
  6356. "Use PF Control I/F to re-enable the VF\n");
  6357. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  6358. }
  6359. }
  6360. /* re-enable mdd interrupt cause */
  6361. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  6362. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  6363. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  6364. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  6365. i40e_flush(hw);
  6366. }
  6367. /**
  6368. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  6369. * @pf: board private structure
  6370. **/
  6371. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  6372. {
  6373. struct i40e_hw *hw = &pf->hw;
  6374. i40e_status ret;
  6375. __be16 port;
  6376. int i;
  6377. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  6378. return;
  6379. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  6380. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  6381. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  6382. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  6383. port = pf->udp_ports[i].index;
  6384. if (port)
  6385. ret = i40e_aq_add_udp_tunnel(hw, port,
  6386. pf->udp_ports[i].type,
  6387. NULL, NULL);
  6388. else
  6389. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  6390. if (ret) {
  6391. dev_dbg(&pf->pdev->dev,
  6392. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  6393. pf->udp_ports[i].type ? "vxlan" : "geneve",
  6394. port ? "add" : "delete",
  6395. ntohs(port), i,
  6396. i40e_stat_str(&pf->hw, ret),
  6397. i40e_aq_str(&pf->hw,
  6398. pf->hw.aq.asq_last_status));
  6399. pf->udp_ports[i].index = 0;
  6400. }
  6401. }
  6402. }
  6403. }
  6404. /**
  6405. * i40e_service_task - Run the driver's async subtasks
  6406. * @work: pointer to work_struct containing our data
  6407. **/
  6408. static void i40e_service_task(struct work_struct *work)
  6409. {
  6410. struct i40e_pf *pf = container_of(work,
  6411. struct i40e_pf,
  6412. service_task);
  6413. unsigned long start_time = jiffies;
  6414. /* don't bother with service tasks if a reset is in progress */
  6415. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6416. return;
  6417. }
  6418. if (test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  6419. return;
  6420. i40e_detect_recover_hung(pf);
  6421. i40e_sync_filters_subtask(pf);
  6422. i40e_reset_subtask(pf);
  6423. i40e_handle_mdd_event(pf);
  6424. i40e_vc_process_vflr_event(pf);
  6425. i40e_watchdog_subtask(pf);
  6426. i40e_fdir_reinit_subtask(pf);
  6427. i40e_client_subtask(pf);
  6428. i40e_sync_filters_subtask(pf);
  6429. i40e_sync_udp_filters_subtask(pf);
  6430. i40e_clean_adminq_subtask(pf);
  6431. /* flush memory to make sure state is correct before next watchdog */
  6432. smp_mb__before_atomic();
  6433. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  6434. /* If the tasks have taken longer than one timer cycle or there
  6435. * is more work to be done, reschedule the service task now
  6436. * rather than wait for the timer to tick again.
  6437. */
  6438. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  6439. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  6440. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  6441. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  6442. i40e_service_event_schedule(pf);
  6443. }
  6444. /**
  6445. * i40e_service_timer - timer callback
  6446. * @data: pointer to PF struct
  6447. **/
  6448. static void i40e_service_timer(unsigned long data)
  6449. {
  6450. struct i40e_pf *pf = (struct i40e_pf *)data;
  6451. mod_timer(&pf->service_timer,
  6452. round_jiffies(jiffies + pf->service_timer_period));
  6453. i40e_service_event_schedule(pf);
  6454. }
  6455. /**
  6456. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  6457. * @vsi: the VSI being configured
  6458. **/
  6459. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  6460. {
  6461. struct i40e_pf *pf = vsi->back;
  6462. switch (vsi->type) {
  6463. case I40E_VSI_MAIN:
  6464. vsi->alloc_queue_pairs = pf->num_lan_qps;
  6465. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6466. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6467. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6468. vsi->num_q_vectors = pf->num_lan_msix;
  6469. else
  6470. vsi->num_q_vectors = 1;
  6471. break;
  6472. case I40E_VSI_FDIR:
  6473. vsi->alloc_queue_pairs = 1;
  6474. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  6475. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6476. vsi->num_q_vectors = pf->num_fdsb_msix;
  6477. break;
  6478. case I40E_VSI_VMDQ2:
  6479. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  6480. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6481. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6482. vsi->num_q_vectors = pf->num_vmdq_msix;
  6483. break;
  6484. case I40E_VSI_SRIOV:
  6485. vsi->alloc_queue_pairs = pf->num_vf_qps;
  6486. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6487. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6488. break;
  6489. #ifdef I40E_FCOE
  6490. case I40E_VSI_FCOE:
  6491. vsi->alloc_queue_pairs = pf->num_fcoe_qps;
  6492. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6493. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6494. vsi->num_q_vectors = pf->num_fcoe_msix;
  6495. break;
  6496. #endif /* I40E_FCOE */
  6497. default:
  6498. WARN_ON(1);
  6499. return -ENODATA;
  6500. }
  6501. return 0;
  6502. }
  6503. /**
  6504. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  6505. * @type: VSI pointer
  6506. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  6507. *
  6508. * On error: returns error code (negative)
  6509. * On success: returns 0
  6510. **/
  6511. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  6512. {
  6513. int size;
  6514. int ret = 0;
  6515. /* allocate memory for both Tx and Rx ring pointers */
  6516. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  6517. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  6518. if (!vsi->tx_rings)
  6519. return -ENOMEM;
  6520. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  6521. if (alloc_qvectors) {
  6522. /* allocate memory for q_vector pointers */
  6523. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  6524. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  6525. if (!vsi->q_vectors) {
  6526. ret = -ENOMEM;
  6527. goto err_vectors;
  6528. }
  6529. }
  6530. return ret;
  6531. err_vectors:
  6532. kfree(vsi->tx_rings);
  6533. return ret;
  6534. }
  6535. /**
  6536. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  6537. * @pf: board private structure
  6538. * @type: type of VSI
  6539. *
  6540. * On error: returns error code (negative)
  6541. * On success: returns vsi index in PF (positive)
  6542. **/
  6543. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  6544. {
  6545. int ret = -ENODEV;
  6546. struct i40e_vsi *vsi;
  6547. int vsi_idx;
  6548. int i;
  6549. /* Need to protect the allocation of the VSIs at the PF level */
  6550. mutex_lock(&pf->switch_mutex);
  6551. /* VSI list may be fragmented if VSI creation/destruction has
  6552. * been happening. We can afford to do a quick scan to look
  6553. * for any free VSIs in the list.
  6554. *
  6555. * find next empty vsi slot, looping back around if necessary
  6556. */
  6557. i = pf->next_vsi;
  6558. while (i < pf->num_alloc_vsi && pf->vsi[i])
  6559. i++;
  6560. if (i >= pf->num_alloc_vsi) {
  6561. i = 0;
  6562. while (i < pf->next_vsi && pf->vsi[i])
  6563. i++;
  6564. }
  6565. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  6566. vsi_idx = i; /* Found one! */
  6567. } else {
  6568. ret = -ENODEV;
  6569. goto unlock_pf; /* out of VSI slots! */
  6570. }
  6571. pf->next_vsi = ++i;
  6572. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  6573. if (!vsi) {
  6574. ret = -ENOMEM;
  6575. goto unlock_pf;
  6576. }
  6577. vsi->type = type;
  6578. vsi->back = pf;
  6579. set_bit(__I40E_DOWN, &vsi->state);
  6580. vsi->flags = 0;
  6581. vsi->idx = vsi_idx;
  6582. vsi->int_rate_limit = 0;
  6583. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  6584. pf->rss_table_size : 64;
  6585. vsi->netdev_registered = false;
  6586. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  6587. hash_init(vsi->mac_filter_hash);
  6588. vsi->irqs_ready = false;
  6589. ret = i40e_set_num_rings_in_vsi(vsi);
  6590. if (ret)
  6591. goto err_rings;
  6592. ret = i40e_vsi_alloc_arrays(vsi, true);
  6593. if (ret)
  6594. goto err_rings;
  6595. /* Setup default MSIX irq handler for VSI */
  6596. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  6597. /* Initialize VSI lock */
  6598. spin_lock_init(&vsi->mac_filter_hash_lock);
  6599. pf->vsi[vsi_idx] = vsi;
  6600. ret = vsi_idx;
  6601. goto unlock_pf;
  6602. err_rings:
  6603. pf->next_vsi = i - 1;
  6604. kfree(vsi);
  6605. unlock_pf:
  6606. mutex_unlock(&pf->switch_mutex);
  6607. return ret;
  6608. }
  6609. /**
  6610. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  6611. * @type: VSI pointer
  6612. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  6613. *
  6614. * On error: returns error code (negative)
  6615. * On success: returns 0
  6616. **/
  6617. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  6618. {
  6619. /* free the ring and vector containers */
  6620. if (free_qvectors) {
  6621. kfree(vsi->q_vectors);
  6622. vsi->q_vectors = NULL;
  6623. }
  6624. kfree(vsi->tx_rings);
  6625. vsi->tx_rings = NULL;
  6626. vsi->rx_rings = NULL;
  6627. }
  6628. /**
  6629. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  6630. * and lookup table
  6631. * @vsi: Pointer to VSI structure
  6632. */
  6633. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  6634. {
  6635. if (!vsi)
  6636. return;
  6637. kfree(vsi->rss_hkey_user);
  6638. vsi->rss_hkey_user = NULL;
  6639. kfree(vsi->rss_lut_user);
  6640. vsi->rss_lut_user = NULL;
  6641. }
  6642. /**
  6643. * i40e_vsi_clear - Deallocate the VSI provided
  6644. * @vsi: the VSI being un-configured
  6645. **/
  6646. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  6647. {
  6648. struct i40e_pf *pf;
  6649. if (!vsi)
  6650. return 0;
  6651. if (!vsi->back)
  6652. goto free_vsi;
  6653. pf = vsi->back;
  6654. mutex_lock(&pf->switch_mutex);
  6655. if (!pf->vsi[vsi->idx]) {
  6656. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  6657. vsi->idx, vsi->idx, vsi, vsi->type);
  6658. goto unlock_vsi;
  6659. }
  6660. if (pf->vsi[vsi->idx] != vsi) {
  6661. dev_err(&pf->pdev->dev,
  6662. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  6663. pf->vsi[vsi->idx]->idx,
  6664. pf->vsi[vsi->idx],
  6665. pf->vsi[vsi->idx]->type,
  6666. vsi->idx, vsi, vsi->type);
  6667. goto unlock_vsi;
  6668. }
  6669. /* updates the PF for this cleared vsi */
  6670. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6671. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  6672. i40e_vsi_free_arrays(vsi, true);
  6673. i40e_clear_rss_config_user(vsi);
  6674. pf->vsi[vsi->idx] = NULL;
  6675. if (vsi->idx < pf->next_vsi)
  6676. pf->next_vsi = vsi->idx;
  6677. unlock_vsi:
  6678. mutex_unlock(&pf->switch_mutex);
  6679. free_vsi:
  6680. kfree(vsi);
  6681. return 0;
  6682. }
  6683. /**
  6684. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  6685. * @vsi: the VSI being cleaned
  6686. **/
  6687. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  6688. {
  6689. int i;
  6690. if (vsi->tx_rings && vsi->tx_rings[0]) {
  6691. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6692. kfree_rcu(vsi->tx_rings[i], rcu);
  6693. vsi->tx_rings[i] = NULL;
  6694. vsi->rx_rings[i] = NULL;
  6695. }
  6696. }
  6697. }
  6698. /**
  6699. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  6700. * @vsi: the VSI being configured
  6701. **/
  6702. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  6703. {
  6704. struct i40e_ring *tx_ring, *rx_ring;
  6705. struct i40e_pf *pf = vsi->back;
  6706. int i;
  6707. /* Set basic values in the rings to be used later during open() */
  6708. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6709. /* allocate space for both Tx and Rx in one shot */
  6710. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  6711. if (!tx_ring)
  6712. goto err_out;
  6713. tx_ring->queue_index = i;
  6714. tx_ring->reg_idx = vsi->base_queue + i;
  6715. tx_ring->ring_active = false;
  6716. tx_ring->vsi = vsi;
  6717. tx_ring->netdev = vsi->netdev;
  6718. tx_ring->dev = &pf->pdev->dev;
  6719. tx_ring->count = vsi->num_desc;
  6720. tx_ring->size = 0;
  6721. tx_ring->dcb_tc = 0;
  6722. if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  6723. tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  6724. tx_ring->tx_itr_setting = pf->tx_itr_default;
  6725. vsi->tx_rings[i] = tx_ring;
  6726. rx_ring = &tx_ring[1];
  6727. rx_ring->queue_index = i;
  6728. rx_ring->reg_idx = vsi->base_queue + i;
  6729. rx_ring->ring_active = false;
  6730. rx_ring->vsi = vsi;
  6731. rx_ring->netdev = vsi->netdev;
  6732. rx_ring->dev = &pf->pdev->dev;
  6733. rx_ring->count = vsi->num_desc;
  6734. rx_ring->size = 0;
  6735. rx_ring->dcb_tc = 0;
  6736. rx_ring->rx_itr_setting = pf->rx_itr_default;
  6737. vsi->rx_rings[i] = rx_ring;
  6738. }
  6739. return 0;
  6740. err_out:
  6741. i40e_vsi_clear_rings(vsi);
  6742. return -ENOMEM;
  6743. }
  6744. /**
  6745. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  6746. * @pf: board private structure
  6747. * @vectors: the number of MSI-X vectors to request
  6748. *
  6749. * Returns the number of vectors reserved, or error
  6750. **/
  6751. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  6752. {
  6753. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  6754. I40E_MIN_MSIX, vectors);
  6755. if (vectors < 0) {
  6756. dev_info(&pf->pdev->dev,
  6757. "MSI-X vector reservation failed: %d\n", vectors);
  6758. vectors = 0;
  6759. }
  6760. return vectors;
  6761. }
  6762. /**
  6763. * i40e_init_msix - Setup the MSIX capability
  6764. * @pf: board private structure
  6765. *
  6766. * Work with the OS to set up the MSIX vectors needed.
  6767. *
  6768. * Returns the number of vectors reserved or negative on failure
  6769. **/
  6770. static int i40e_init_msix(struct i40e_pf *pf)
  6771. {
  6772. struct i40e_hw *hw = &pf->hw;
  6773. int vectors_left;
  6774. int v_budget, i;
  6775. int v_actual;
  6776. int iwarp_requested = 0;
  6777. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  6778. return -ENODEV;
  6779. /* The number of vectors we'll request will be comprised of:
  6780. * - Add 1 for "other" cause for Admin Queue events, etc.
  6781. * - The number of LAN queue pairs
  6782. * - Queues being used for RSS.
  6783. * We don't need as many as max_rss_size vectors.
  6784. * use rss_size instead in the calculation since that
  6785. * is governed by number of cpus in the system.
  6786. * - assumes symmetric Tx/Rx pairing
  6787. * - The number of VMDq pairs
  6788. * - The CPU count within the NUMA node if iWARP is enabled
  6789. #ifdef I40E_FCOE
  6790. * - The number of FCOE qps.
  6791. #endif
  6792. * Once we count this up, try the request.
  6793. *
  6794. * If we can't get what we want, we'll simplify to nearly nothing
  6795. * and try again. If that still fails, we punt.
  6796. */
  6797. vectors_left = hw->func_caps.num_msix_vectors;
  6798. v_budget = 0;
  6799. /* reserve one vector for miscellaneous handler */
  6800. if (vectors_left) {
  6801. v_budget++;
  6802. vectors_left--;
  6803. }
  6804. /* reserve vectors for the main PF traffic queues */
  6805. pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
  6806. vectors_left -= pf->num_lan_msix;
  6807. v_budget += pf->num_lan_msix;
  6808. /* reserve one vector for sideband flow director */
  6809. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6810. if (vectors_left) {
  6811. pf->num_fdsb_msix = 1;
  6812. v_budget++;
  6813. vectors_left--;
  6814. } else {
  6815. pf->num_fdsb_msix = 0;
  6816. }
  6817. }
  6818. #ifdef I40E_FCOE
  6819. /* can we reserve enough for FCoE? */
  6820. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6821. if (!vectors_left)
  6822. pf->num_fcoe_msix = 0;
  6823. else if (vectors_left >= pf->num_fcoe_qps)
  6824. pf->num_fcoe_msix = pf->num_fcoe_qps;
  6825. else
  6826. pf->num_fcoe_msix = 1;
  6827. v_budget += pf->num_fcoe_msix;
  6828. vectors_left -= pf->num_fcoe_msix;
  6829. }
  6830. #endif
  6831. /* can we reserve enough for iWARP? */
  6832. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6833. iwarp_requested = pf->num_iwarp_msix;
  6834. if (!vectors_left)
  6835. pf->num_iwarp_msix = 0;
  6836. else if (vectors_left < pf->num_iwarp_msix)
  6837. pf->num_iwarp_msix = 1;
  6838. v_budget += pf->num_iwarp_msix;
  6839. vectors_left -= pf->num_iwarp_msix;
  6840. }
  6841. /* any vectors left over go for VMDq support */
  6842. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  6843. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  6844. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  6845. if (!vectors_left) {
  6846. pf->num_vmdq_msix = 0;
  6847. pf->num_vmdq_qps = 0;
  6848. } else {
  6849. /* if we're short on vectors for what's desired, we limit
  6850. * the queues per vmdq. If this is still more than are
  6851. * available, the user will need to change the number of
  6852. * queues/vectors used by the PF later with the ethtool
  6853. * channels command
  6854. */
  6855. if (vmdq_vecs < vmdq_vecs_wanted)
  6856. pf->num_vmdq_qps = 1;
  6857. pf->num_vmdq_msix = pf->num_vmdq_qps;
  6858. v_budget += vmdq_vecs;
  6859. vectors_left -= vmdq_vecs;
  6860. }
  6861. }
  6862. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  6863. GFP_KERNEL);
  6864. if (!pf->msix_entries)
  6865. return -ENOMEM;
  6866. for (i = 0; i < v_budget; i++)
  6867. pf->msix_entries[i].entry = i;
  6868. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  6869. if (v_actual < I40E_MIN_MSIX) {
  6870. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  6871. kfree(pf->msix_entries);
  6872. pf->msix_entries = NULL;
  6873. pci_disable_msix(pf->pdev);
  6874. return -ENODEV;
  6875. } else if (v_actual == I40E_MIN_MSIX) {
  6876. /* Adjust for minimal MSIX use */
  6877. pf->num_vmdq_vsis = 0;
  6878. pf->num_vmdq_qps = 0;
  6879. pf->num_lan_qps = 1;
  6880. pf->num_lan_msix = 1;
  6881. } else if (!vectors_left) {
  6882. /* If we have limited resources, we will start with no vectors
  6883. * for the special features and then allocate vectors to some
  6884. * of these features based on the policy and at the end disable
  6885. * the features that did not get any vectors.
  6886. */
  6887. int vec;
  6888. dev_info(&pf->pdev->dev,
  6889. "MSI-X vector limit reached, attempting to redistribute vectors\n");
  6890. /* reserve the misc vector */
  6891. vec = v_actual - 1;
  6892. /* Scale vector usage down */
  6893. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  6894. pf->num_vmdq_vsis = 1;
  6895. pf->num_vmdq_qps = 1;
  6896. #ifdef I40E_FCOE
  6897. pf->num_fcoe_qps = 0;
  6898. pf->num_fcoe_msix = 0;
  6899. #endif
  6900. /* partition out the remaining vectors */
  6901. switch (vec) {
  6902. case 2:
  6903. pf->num_lan_msix = 1;
  6904. break;
  6905. case 3:
  6906. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6907. pf->num_lan_msix = 1;
  6908. pf->num_iwarp_msix = 1;
  6909. } else {
  6910. pf->num_lan_msix = 2;
  6911. }
  6912. #ifdef I40E_FCOE
  6913. /* give one vector to FCoE */
  6914. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6915. pf->num_lan_msix = 1;
  6916. pf->num_fcoe_msix = 1;
  6917. }
  6918. #endif
  6919. break;
  6920. default:
  6921. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6922. pf->num_iwarp_msix = min_t(int, (vec / 3),
  6923. iwarp_requested);
  6924. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  6925. I40E_DEFAULT_NUM_VMDQ_VSI);
  6926. } else {
  6927. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  6928. I40E_DEFAULT_NUM_VMDQ_VSI);
  6929. }
  6930. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6931. pf->num_fdsb_msix = 1;
  6932. vec--;
  6933. }
  6934. pf->num_lan_msix = min_t(int,
  6935. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  6936. pf->num_lan_msix);
  6937. pf->num_lan_qps = pf->num_lan_msix;
  6938. #ifdef I40E_FCOE
  6939. /* give one vector to FCoE */
  6940. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6941. pf->num_fcoe_msix = 1;
  6942. vec--;
  6943. }
  6944. #endif
  6945. break;
  6946. }
  6947. }
  6948. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  6949. (pf->num_fdsb_msix == 0)) {
  6950. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  6951. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6952. }
  6953. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  6954. (pf->num_vmdq_msix == 0)) {
  6955. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  6956. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  6957. }
  6958. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  6959. (pf->num_iwarp_msix == 0)) {
  6960. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  6961. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  6962. }
  6963. #ifdef I40E_FCOE
  6964. if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
  6965. dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
  6966. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  6967. }
  6968. #endif
  6969. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  6970. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  6971. pf->num_lan_msix,
  6972. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  6973. pf->num_fdsb_msix,
  6974. pf->num_iwarp_msix);
  6975. return v_actual;
  6976. }
  6977. /**
  6978. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  6979. * @vsi: the VSI being configured
  6980. * @v_idx: index of the vector in the vsi struct
  6981. * @cpu: cpu to be used on affinity_mask
  6982. *
  6983. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  6984. **/
  6985. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  6986. {
  6987. struct i40e_q_vector *q_vector;
  6988. /* allocate q_vector */
  6989. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  6990. if (!q_vector)
  6991. return -ENOMEM;
  6992. q_vector->vsi = vsi;
  6993. q_vector->v_idx = v_idx;
  6994. cpumask_set_cpu(cpu, &q_vector->affinity_mask);
  6995. if (vsi->netdev)
  6996. netif_napi_add(vsi->netdev, &q_vector->napi,
  6997. i40e_napi_poll, NAPI_POLL_WEIGHT);
  6998. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  6999. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  7000. /* tie q_vector and vsi together */
  7001. vsi->q_vectors[v_idx] = q_vector;
  7002. return 0;
  7003. }
  7004. /**
  7005. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  7006. * @vsi: the VSI being configured
  7007. *
  7008. * We allocate one q_vector per queue interrupt. If allocation fails we
  7009. * return -ENOMEM.
  7010. **/
  7011. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  7012. {
  7013. struct i40e_pf *pf = vsi->back;
  7014. int err, v_idx, num_q_vectors, current_cpu;
  7015. /* if not MSIX, give the one vector only to the LAN VSI */
  7016. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  7017. num_q_vectors = vsi->num_q_vectors;
  7018. else if (vsi == pf->vsi[pf->lan_vsi])
  7019. num_q_vectors = 1;
  7020. else
  7021. return -EINVAL;
  7022. current_cpu = cpumask_first(cpu_online_mask);
  7023. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  7024. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  7025. if (err)
  7026. goto err_out;
  7027. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  7028. if (unlikely(current_cpu >= nr_cpu_ids))
  7029. current_cpu = cpumask_first(cpu_online_mask);
  7030. }
  7031. return 0;
  7032. err_out:
  7033. while (v_idx--)
  7034. i40e_free_q_vector(vsi, v_idx);
  7035. return err;
  7036. }
  7037. /**
  7038. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  7039. * @pf: board private structure to initialize
  7040. **/
  7041. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  7042. {
  7043. int vectors = 0;
  7044. ssize_t size;
  7045. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7046. vectors = i40e_init_msix(pf);
  7047. if (vectors < 0) {
  7048. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  7049. I40E_FLAG_IWARP_ENABLED |
  7050. #ifdef I40E_FCOE
  7051. I40E_FLAG_FCOE_ENABLED |
  7052. #endif
  7053. I40E_FLAG_RSS_ENABLED |
  7054. I40E_FLAG_DCB_CAPABLE |
  7055. I40E_FLAG_DCB_ENABLED |
  7056. I40E_FLAG_SRIOV_ENABLED |
  7057. I40E_FLAG_FD_SB_ENABLED |
  7058. I40E_FLAG_FD_ATR_ENABLED |
  7059. I40E_FLAG_VMDQ_ENABLED);
  7060. /* rework the queue expectations without MSIX */
  7061. i40e_determine_queue_usage(pf);
  7062. }
  7063. }
  7064. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  7065. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  7066. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  7067. vectors = pci_enable_msi(pf->pdev);
  7068. if (vectors < 0) {
  7069. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  7070. vectors);
  7071. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  7072. }
  7073. vectors = 1; /* one MSI or Legacy vector */
  7074. }
  7075. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  7076. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  7077. /* set up vector assignment tracking */
  7078. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  7079. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  7080. if (!pf->irq_pile) {
  7081. dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
  7082. return -ENOMEM;
  7083. }
  7084. pf->irq_pile->num_entries = vectors;
  7085. pf->irq_pile->search_hint = 0;
  7086. /* track first vector for misc interrupts, ignore return */
  7087. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  7088. return 0;
  7089. }
  7090. /**
  7091. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  7092. * @pf: board private structure
  7093. *
  7094. * This sets up the handler for MSIX 0, which is used to manage the
  7095. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  7096. * when in MSI or Legacy interrupt mode.
  7097. **/
  7098. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  7099. {
  7100. struct i40e_hw *hw = &pf->hw;
  7101. int err = 0;
  7102. /* Only request the irq if this is the first time through, and
  7103. * not when we're rebuilding after a Reset
  7104. */
  7105. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  7106. err = request_irq(pf->msix_entries[0].vector,
  7107. i40e_intr, 0, pf->int_name, pf);
  7108. if (err) {
  7109. dev_info(&pf->pdev->dev,
  7110. "request_irq for %s failed: %d\n",
  7111. pf->int_name, err);
  7112. return -EFAULT;
  7113. }
  7114. }
  7115. i40e_enable_misc_int_causes(pf);
  7116. /* associate no queues to the misc vector */
  7117. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  7118. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  7119. i40e_flush(hw);
  7120. i40e_irq_dynamic_enable_icr0(pf, true);
  7121. return err;
  7122. }
  7123. /**
  7124. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  7125. * @vsi: vsi structure
  7126. * @seed: RSS hash seed
  7127. **/
  7128. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7129. u8 *lut, u16 lut_size)
  7130. {
  7131. struct i40e_pf *pf = vsi->back;
  7132. struct i40e_hw *hw = &pf->hw;
  7133. int ret = 0;
  7134. if (seed) {
  7135. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  7136. (struct i40e_aqc_get_set_rss_key_data *)seed;
  7137. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  7138. if (ret) {
  7139. dev_info(&pf->pdev->dev,
  7140. "Cannot set RSS key, err %s aq_err %s\n",
  7141. i40e_stat_str(hw, ret),
  7142. i40e_aq_str(hw, hw->aq.asq_last_status));
  7143. return ret;
  7144. }
  7145. }
  7146. if (lut) {
  7147. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7148. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7149. if (ret) {
  7150. dev_info(&pf->pdev->dev,
  7151. "Cannot set RSS lut, err %s aq_err %s\n",
  7152. i40e_stat_str(hw, ret),
  7153. i40e_aq_str(hw, hw->aq.asq_last_status));
  7154. return ret;
  7155. }
  7156. }
  7157. return ret;
  7158. }
  7159. /**
  7160. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  7161. * @vsi: Pointer to vsi structure
  7162. * @seed: Buffter to store the hash keys
  7163. * @lut: Buffer to store the lookup table entries
  7164. * @lut_size: Size of buffer to store the lookup table entries
  7165. *
  7166. * Return 0 on success, negative on failure
  7167. */
  7168. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7169. u8 *lut, u16 lut_size)
  7170. {
  7171. struct i40e_pf *pf = vsi->back;
  7172. struct i40e_hw *hw = &pf->hw;
  7173. int ret = 0;
  7174. if (seed) {
  7175. ret = i40e_aq_get_rss_key(hw, vsi->id,
  7176. (struct i40e_aqc_get_set_rss_key_data *)seed);
  7177. if (ret) {
  7178. dev_info(&pf->pdev->dev,
  7179. "Cannot get RSS key, err %s aq_err %s\n",
  7180. i40e_stat_str(&pf->hw, ret),
  7181. i40e_aq_str(&pf->hw,
  7182. pf->hw.aq.asq_last_status));
  7183. return ret;
  7184. }
  7185. }
  7186. if (lut) {
  7187. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7188. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7189. if (ret) {
  7190. dev_info(&pf->pdev->dev,
  7191. "Cannot get RSS lut, err %s aq_err %s\n",
  7192. i40e_stat_str(&pf->hw, ret),
  7193. i40e_aq_str(&pf->hw,
  7194. pf->hw.aq.asq_last_status));
  7195. return ret;
  7196. }
  7197. }
  7198. return ret;
  7199. }
  7200. /**
  7201. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  7202. * @vsi: VSI structure
  7203. **/
  7204. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  7205. {
  7206. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7207. struct i40e_pf *pf = vsi->back;
  7208. u8 *lut;
  7209. int ret;
  7210. if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
  7211. return 0;
  7212. if (!vsi->rss_size)
  7213. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7214. vsi->num_queue_pairs);
  7215. if (!vsi->rss_size)
  7216. return -EINVAL;
  7217. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7218. if (!lut)
  7219. return -ENOMEM;
  7220. /* Use the user configured hash keys and lookup table if there is one,
  7221. * otherwise use default
  7222. */
  7223. if (vsi->rss_lut_user)
  7224. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7225. else
  7226. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7227. if (vsi->rss_hkey_user)
  7228. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7229. else
  7230. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7231. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  7232. kfree(lut);
  7233. return ret;
  7234. }
  7235. /**
  7236. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  7237. * @vsi: Pointer to vsi structure
  7238. * @seed: RSS hash seed
  7239. * @lut: Lookup table
  7240. * @lut_size: Lookup table size
  7241. *
  7242. * Returns 0 on success, negative on failure
  7243. **/
  7244. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  7245. const u8 *lut, u16 lut_size)
  7246. {
  7247. struct i40e_pf *pf = vsi->back;
  7248. struct i40e_hw *hw = &pf->hw;
  7249. u16 vf_id = vsi->vf_id;
  7250. u8 i;
  7251. /* Fill out hash function seed */
  7252. if (seed) {
  7253. u32 *seed_dw = (u32 *)seed;
  7254. if (vsi->type == I40E_VSI_MAIN) {
  7255. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7256. i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i),
  7257. seed_dw[i]);
  7258. } else if (vsi->type == I40E_VSI_SRIOV) {
  7259. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  7260. i40e_write_rx_ctl(hw,
  7261. I40E_VFQF_HKEY1(i, vf_id),
  7262. seed_dw[i]);
  7263. } else {
  7264. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  7265. }
  7266. }
  7267. if (lut) {
  7268. u32 *lut_dw = (u32 *)lut;
  7269. if (vsi->type == I40E_VSI_MAIN) {
  7270. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7271. return -EINVAL;
  7272. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7273. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  7274. } else if (vsi->type == I40E_VSI_SRIOV) {
  7275. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  7276. return -EINVAL;
  7277. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7278. i40e_write_rx_ctl(hw,
  7279. I40E_VFQF_HLUT1(i, vf_id),
  7280. lut_dw[i]);
  7281. } else {
  7282. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7283. }
  7284. }
  7285. i40e_flush(hw);
  7286. return 0;
  7287. }
  7288. /**
  7289. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  7290. * @vsi: Pointer to VSI structure
  7291. * @seed: Buffer to store the keys
  7292. * @lut: Buffer to store the lookup table entries
  7293. * @lut_size: Size of buffer to store the lookup table entries
  7294. *
  7295. * Returns 0 on success, negative on failure
  7296. */
  7297. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  7298. u8 *lut, u16 lut_size)
  7299. {
  7300. struct i40e_pf *pf = vsi->back;
  7301. struct i40e_hw *hw = &pf->hw;
  7302. u16 i;
  7303. if (seed) {
  7304. u32 *seed_dw = (u32 *)seed;
  7305. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7306. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  7307. }
  7308. if (lut) {
  7309. u32 *lut_dw = (u32 *)lut;
  7310. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7311. return -EINVAL;
  7312. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7313. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  7314. }
  7315. return 0;
  7316. }
  7317. /**
  7318. * i40e_config_rss - Configure RSS keys and lut
  7319. * @vsi: Pointer to VSI structure
  7320. * @seed: RSS hash seed
  7321. * @lut: Lookup table
  7322. * @lut_size: Lookup table size
  7323. *
  7324. * Returns 0 on success, negative on failure
  7325. */
  7326. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7327. {
  7328. struct i40e_pf *pf = vsi->back;
  7329. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7330. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  7331. else
  7332. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  7333. }
  7334. /**
  7335. * i40e_get_rss - Get RSS keys and lut
  7336. * @vsi: Pointer to VSI structure
  7337. * @seed: Buffer to store the keys
  7338. * @lut: Buffer to store the lookup table entries
  7339. * lut_size: Size of buffer to store the lookup table entries
  7340. *
  7341. * Returns 0 on success, negative on failure
  7342. */
  7343. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7344. {
  7345. struct i40e_pf *pf = vsi->back;
  7346. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7347. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  7348. else
  7349. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  7350. }
  7351. /**
  7352. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  7353. * @pf: Pointer to board private structure
  7354. * @lut: Lookup table
  7355. * @rss_table_size: Lookup table size
  7356. * @rss_size: Range of queue number for hashing
  7357. */
  7358. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  7359. u16 rss_table_size, u16 rss_size)
  7360. {
  7361. u16 i;
  7362. for (i = 0; i < rss_table_size; i++)
  7363. lut[i] = i % rss_size;
  7364. }
  7365. /**
  7366. * i40e_pf_config_rss - Prepare for RSS if used
  7367. * @pf: board private structure
  7368. **/
  7369. static int i40e_pf_config_rss(struct i40e_pf *pf)
  7370. {
  7371. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7372. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7373. u8 *lut;
  7374. struct i40e_hw *hw = &pf->hw;
  7375. u32 reg_val;
  7376. u64 hena;
  7377. int ret;
  7378. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  7379. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  7380. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  7381. hena |= i40e_pf_get_default_rss_hena(pf);
  7382. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  7383. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  7384. /* Determine the RSS table size based on the hardware capabilities */
  7385. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  7386. reg_val = (pf->rss_table_size == 512) ?
  7387. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  7388. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  7389. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  7390. /* Determine the RSS size of the VSI */
  7391. if (!vsi->rss_size)
  7392. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7393. vsi->num_queue_pairs);
  7394. if (!vsi->rss_size)
  7395. return -EINVAL;
  7396. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7397. if (!lut)
  7398. return -ENOMEM;
  7399. /* Use user configured lut if there is one, otherwise use default */
  7400. if (vsi->rss_lut_user)
  7401. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7402. else
  7403. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7404. /* Use user configured hash key if there is one, otherwise
  7405. * use default.
  7406. */
  7407. if (vsi->rss_hkey_user)
  7408. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7409. else
  7410. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7411. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  7412. kfree(lut);
  7413. return ret;
  7414. }
  7415. /**
  7416. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  7417. * @pf: board private structure
  7418. * @queue_count: the requested queue count for rss.
  7419. *
  7420. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  7421. * count which may be different from the requested queue count.
  7422. **/
  7423. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  7424. {
  7425. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7426. int new_rss_size;
  7427. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  7428. return 0;
  7429. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  7430. if (queue_count != vsi->num_queue_pairs) {
  7431. vsi->req_queue_pairs = queue_count;
  7432. i40e_prep_for_reset(pf);
  7433. pf->alloc_rss_size = new_rss_size;
  7434. i40e_reset_and_rebuild(pf, true);
  7435. /* Discard the user configured hash keys and lut, if less
  7436. * queues are enabled.
  7437. */
  7438. if (queue_count < vsi->rss_size) {
  7439. i40e_clear_rss_config_user(vsi);
  7440. dev_dbg(&pf->pdev->dev,
  7441. "discard user configured hash keys and lut\n");
  7442. }
  7443. /* Reset vsi->rss_size, as number of enabled queues changed */
  7444. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7445. vsi->num_queue_pairs);
  7446. i40e_pf_config_rss(pf);
  7447. }
  7448. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  7449. vsi->req_queue_pairs, pf->rss_size_max);
  7450. return pf->alloc_rss_size;
  7451. }
  7452. /**
  7453. * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
  7454. * @pf: board private structure
  7455. **/
  7456. i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
  7457. {
  7458. i40e_status status;
  7459. bool min_valid, max_valid;
  7460. u32 max_bw, min_bw;
  7461. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  7462. &min_valid, &max_valid);
  7463. if (!status) {
  7464. if (min_valid)
  7465. pf->npar_min_bw = min_bw;
  7466. if (max_valid)
  7467. pf->npar_max_bw = max_bw;
  7468. }
  7469. return status;
  7470. }
  7471. /**
  7472. * i40e_set_npar_bw_setting - Set BW settings for this PF partition
  7473. * @pf: board private structure
  7474. **/
  7475. i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
  7476. {
  7477. struct i40e_aqc_configure_partition_bw_data bw_data;
  7478. i40e_status status;
  7479. /* Set the valid bit for this PF */
  7480. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  7481. bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
  7482. bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
  7483. /* Set the new bandwidths */
  7484. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  7485. return status;
  7486. }
  7487. /**
  7488. * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
  7489. * @pf: board private structure
  7490. **/
  7491. i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
  7492. {
  7493. /* Commit temporary BW setting to permanent NVM image */
  7494. enum i40e_admin_queue_err last_aq_status;
  7495. i40e_status ret;
  7496. u16 nvm_word;
  7497. if (pf->hw.partition_id != 1) {
  7498. dev_info(&pf->pdev->dev,
  7499. "Commit BW only works on partition 1! This is partition %d",
  7500. pf->hw.partition_id);
  7501. ret = I40E_NOT_SUPPORTED;
  7502. goto bw_commit_out;
  7503. }
  7504. /* Acquire NVM for read access */
  7505. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  7506. last_aq_status = pf->hw.aq.asq_last_status;
  7507. if (ret) {
  7508. dev_info(&pf->pdev->dev,
  7509. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  7510. i40e_stat_str(&pf->hw, ret),
  7511. i40e_aq_str(&pf->hw, last_aq_status));
  7512. goto bw_commit_out;
  7513. }
  7514. /* Read word 0x10 of NVM - SW compatibility word 1 */
  7515. ret = i40e_aq_read_nvm(&pf->hw,
  7516. I40E_SR_NVM_CONTROL_WORD,
  7517. 0x10, sizeof(nvm_word), &nvm_word,
  7518. false, NULL);
  7519. /* Save off last admin queue command status before releasing
  7520. * the NVM
  7521. */
  7522. last_aq_status = pf->hw.aq.asq_last_status;
  7523. i40e_release_nvm(&pf->hw);
  7524. if (ret) {
  7525. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  7526. i40e_stat_str(&pf->hw, ret),
  7527. i40e_aq_str(&pf->hw, last_aq_status));
  7528. goto bw_commit_out;
  7529. }
  7530. /* Wait a bit for NVM release to complete */
  7531. msleep(50);
  7532. /* Acquire NVM for write access */
  7533. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  7534. last_aq_status = pf->hw.aq.asq_last_status;
  7535. if (ret) {
  7536. dev_info(&pf->pdev->dev,
  7537. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  7538. i40e_stat_str(&pf->hw, ret),
  7539. i40e_aq_str(&pf->hw, last_aq_status));
  7540. goto bw_commit_out;
  7541. }
  7542. /* Write it back out unchanged to initiate update NVM,
  7543. * which will force a write of the shadow (alt) RAM to
  7544. * the NVM - thus storing the bandwidth values permanently.
  7545. */
  7546. ret = i40e_aq_update_nvm(&pf->hw,
  7547. I40E_SR_NVM_CONTROL_WORD,
  7548. 0x10, sizeof(nvm_word),
  7549. &nvm_word, true, NULL);
  7550. /* Save off last admin queue command status before releasing
  7551. * the NVM
  7552. */
  7553. last_aq_status = pf->hw.aq.asq_last_status;
  7554. i40e_release_nvm(&pf->hw);
  7555. if (ret)
  7556. dev_info(&pf->pdev->dev,
  7557. "BW settings NOT SAVED, err %s aq_err %s\n",
  7558. i40e_stat_str(&pf->hw, ret),
  7559. i40e_aq_str(&pf->hw, last_aq_status));
  7560. bw_commit_out:
  7561. return ret;
  7562. }
  7563. /**
  7564. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  7565. * @pf: board private structure to initialize
  7566. *
  7567. * i40e_sw_init initializes the Adapter private data structure.
  7568. * Fields are initialized based on PCI device information and
  7569. * OS network device settings (MTU size).
  7570. **/
  7571. static int i40e_sw_init(struct i40e_pf *pf)
  7572. {
  7573. int err = 0;
  7574. int size;
  7575. /* Set default capability flags */
  7576. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  7577. I40E_FLAG_MSI_ENABLED |
  7578. I40E_FLAG_MSIX_ENABLED;
  7579. /* Set default ITR */
  7580. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  7581. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  7582. /* Depending on PF configurations, it is possible that the RSS
  7583. * maximum might end up larger than the available queues
  7584. */
  7585. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  7586. pf->alloc_rss_size = 1;
  7587. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  7588. pf->rss_size_max = min_t(int, pf->rss_size_max,
  7589. pf->hw.func_caps.num_tx_qp);
  7590. if (pf->hw.func_caps.rss) {
  7591. pf->flags |= I40E_FLAG_RSS_ENABLED;
  7592. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  7593. num_online_cpus());
  7594. }
  7595. /* MFP mode enabled */
  7596. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  7597. pf->flags |= I40E_FLAG_MFP_ENABLED;
  7598. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  7599. if (i40e_get_npar_bw_setting(pf))
  7600. dev_warn(&pf->pdev->dev,
  7601. "Could not get NPAR bw settings\n");
  7602. else
  7603. dev_info(&pf->pdev->dev,
  7604. "Min BW = %8.8x, Max BW = %8.8x\n",
  7605. pf->npar_min_bw, pf->npar_max_bw);
  7606. }
  7607. /* FW/NVM is not yet fixed in this regard */
  7608. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  7609. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  7610. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  7611. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  7612. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  7613. pf->hw.num_partitions > 1)
  7614. dev_info(&pf->pdev->dev,
  7615. "Flow Director Sideband mode Disabled in MFP mode\n");
  7616. else
  7617. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7618. pf->fdir_pf_filter_count =
  7619. pf->hw.func_caps.fd_filters_guaranteed;
  7620. pf->hw.fdir_shared_filter_count =
  7621. pf->hw.func_caps.fd_filters_best_effort;
  7622. }
  7623. if (i40e_is_mac_710(&pf->hw) &&
  7624. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  7625. (pf->hw.aq.fw_maj_ver < 4))) {
  7626. pf->flags |= I40E_FLAG_RESTART_AUTONEG;
  7627. /* No DCB support for FW < v4.33 */
  7628. pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
  7629. }
  7630. /* Disable FW LLDP if FW < v4.3 */
  7631. if (i40e_is_mac_710(&pf->hw) &&
  7632. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  7633. (pf->hw.aq.fw_maj_ver < 4)))
  7634. pf->flags |= I40E_FLAG_STOP_FW_LLDP;
  7635. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  7636. if (i40e_is_mac_710(&pf->hw) &&
  7637. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  7638. (pf->hw.aq.fw_maj_ver >= 5)))
  7639. pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
  7640. if (pf->hw.func_caps.vmdq) {
  7641. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  7642. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  7643. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  7644. }
  7645. if (pf->hw.func_caps.iwarp) {
  7646. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  7647. /* IWARP needs one extra vector for CQP just like MISC.*/
  7648. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  7649. }
  7650. #ifdef I40E_FCOE
  7651. i40e_init_pf_fcoe(pf);
  7652. #endif /* I40E_FCOE */
  7653. #ifdef CONFIG_PCI_IOV
  7654. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  7655. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  7656. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  7657. pf->num_req_vfs = min_t(int,
  7658. pf->hw.func_caps.num_vfs,
  7659. I40E_MAX_VF_COUNT);
  7660. }
  7661. #endif /* CONFIG_PCI_IOV */
  7662. if (pf->hw.mac.type == I40E_MAC_X722) {
  7663. pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
  7664. I40E_FLAG_128_QP_RSS_CAPABLE |
  7665. I40E_FLAG_HW_ATR_EVICT_CAPABLE |
  7666. I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
  7667. I40E_FLAG_WB_ON_ITR_CAPABLE |
  7668. I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  7669. I40E_FLAG_NO_PCI_LINK_CHECK |
  7670. I40E_FLAG_USE_SET_LLDP_MIB |
  7671. I40E_FLAG_GENEVE_OFFLOAD_CAPABLE |
  7672. I40E_FLAG_PTP_L4_CAPABLE;
  7673. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  7674. ((pf->hw.aq.api_maj_ver == 1) &&
  7675. (pf->hw.aq.api_min_ver > 4))) {
  7676. /* Supported in FW API version higher than 1.4 */
  7677. pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7678. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7679. } else {
  7680. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7681. }
  7682. pf->eeprom_version = 0xDEAD;
  7683. pf->lan_veb = I40E_NO_VEB;
  7684. pf->lan_vsi = I40E_NO_VSI;
  7685. /* By default FW has this off for performance reasons */
  7686. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  7687. /* set up queue assignment tracking */
  7688. size = sizeof(struct i40e_lump_tracking)
  7689. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  7690. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  7691. if (!pf->qp_pile) {
  7692. err = -ENOMEM;
  7693. goto sw_init_done;
  7694. }
  7695. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  7696. pf->qp_pile->search_hint = 0;
  7697. pf->tx_timeout_recovery_level = 1;
  7698. mutex_init(&pf->switch_mutex);
  7699. /* If NPAR is enabled nudge the Tx scheduler */
  7700. if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
  7701. i40e_set_npar_bw_setting(pf);
  7702. sw_init_done:
  7703. return err;
  7704. }
  7705. /**
  7706. * i40e_set_ntuple - set the ntuple feature flag and take action
  7707. * @pf: board private structure to initialize
  7708. * @features: the feature set that the stack is suggesting
  7709. *
  7710. * returns a bool to indicate if reset needs to happen
  7711. **/
  7712. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  7713. {
  7714. bool need_reset = false;
  7715. /* Check if Flow Director n-tuple support was enabled or disabled. If
  7716. * the state changed, we need to reset.
  7717. */
  7718. if (features & NETIF_F_NTUPLE) {
  7719. /* Enable filters and mark for reset */
  7720. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7721. need_reset = true;
  7722. /* enable FD_SB only if there is MSI-X vector */
  7723. if (pf->num_fdsb_msix > 0)
  7724. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7725. } else {
  7726. /* turn off filters, mark for reset and clear SW filter list */
  7727. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7728. need_reset = true;
  7729. i40e_fdir_filter_exit(pf);
  7730. }
  7731. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7732. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7733. /* reset fd counters */
  7734. pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
  7735. pf->fdir_pf_active_filters = 0;
  7736. /* if ATR was auto disabled it can be re-enabled. */
  7737. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7738. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  7739. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  7740. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7741. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  7742. }
  7743. }
  7744. return need_reset;
  7745. }
  7746. /**
  7747. * i40e_clear_rss_lut - clear the rx hash lookup table
  7748. * @vsi: the VSI being configured
  7749. **/
  7750. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  7751. {
  7752. struct i40e_pf *pf = vsi->back;
  7753. struct i40e_hw *hw = &pf->hw;
  7754. u16 vf_id = vsi->vf_id;
  7755. u8 i;
  7756. if (vsi->type == I40E_VSI_MAIN) {
  7757. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7758. wr32(hw, I40E_PFQF_HLUT(i), 0);
  7759. } else if (vsi->type == I40E_VSI_SRIOV) {
  7760. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7761. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  7762. } else {
  7763. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7764. }
  7765. }
  7766. /**
  7767. * i40e_set_features - set the netdev feature flags
  7768. * @netdev: ptr to the netdev being adjusted
  7769. * @features: the feature set that the stack is suggesting
  7770. **/
  7771. static int i40e_set_features(struct net_device *netdev,
  7772. netdev_features_t features)
  7773. {
  7774. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7775. struct i40e_vsi *vsi = np->vsi;
  7776. struct i40e_pf *pf = vsi->back;
  7777. bool need_reset;
  7778. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  7779. i40e_pf_config_rss(pf);
  7780. else if (!(features & NETIF_F_RXHASH) &&
  7781. netdev->features & NETIF_F_RXHASH)
  7782. i40e_clear_rss_lut(vsi);
  7783. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  7784. i40e_vlan_stripping_enable(vsi);
  7785. else
  7786. i40e_vlan_stripping_disable(vsi);
  7787. need_reset = i40e_set_ntuple(pf, features);
  7788. if (need_reset)
  7789. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7790. return 0;
  7791. }
  7792. /**
  7793. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  7794. * @pf: board private structure
  7795. * @port: The UDP port to look up
  7796. *
  7797. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  7798. **/
  7799. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
  7800. {
  7801. u8 i;
  7802. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  7803. if (pf->udp_ports[i].index == port)
  7804. return i;
  7805. }
  7806. return i;
  7807. }
  7808. /**
  7809. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  7810. * @netdev: This physical port's netdev
  7811. * @ti: Tunnel endpoint information
  7812. **/
  7813. static void i40e_udp_tunnel_add(struct net_device *netdev,
  7814. struct udp_tunnel_info *ti)
  7815. {
  7816. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7817. struct i40e_vsi *vsi = np->vsi;
  7818. struct i40e_pf *pf = vsi->back;
  7819. __be16 port = ti->port;
  7820. u8 next_idx;
  7821. u8 idx;
  7822. idx = i40e_get_udp_port_idx(pf, port);
  7823. /* Check if port already exists */
  7824. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7825. netdev_info(netdev, "port %d already offloaded\n",
  7826. ntohs(port));
  7827. return;
  7828. }
  7829. /* Now check if there is space to add the new port */
  7830. next_idx = i40e_get_udp_port_idx(pf, 0);
  7831. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7832. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  7833. ntohs(port));
  7834. return;
  7835. }
  7836. switch (ti->type) {
  7837. case UDP_TUNNEL_TYPE_VXLAN:
  7838. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  7839. break;
  7840. case UDP_TUNNEL_TYPE_GENEVE:
  7841. if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7842. return;
  7843. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  7844. break;
  7845. default:
  7846. return;
  7847. }
  7848. /* New port: add it and mark its index in the bitmap */
  7849. pf->udp_ports[next_idx].index = port;
  7850. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  7851. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7852. }
  7853. /**
  7854. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  7855. * @netdev: This physical port's netdev
  7856. * @ti: Tunnel endpoint information
  7857. **/
  7858. static void i40e_udp_tunnel_del(struct net_device *netdev,
  7859. struct udp_tunnel_info *ti)
  7860. {
  7861. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7862. struct i40e_vsi *vsi = np->vsi;
  7863. struct i40e_pf *pf = vsi->back;
  7864. __be16 port = ti->port;
  7865. u8 idx;
  7866. idx = i40e_get_udp_port_idx(pf, port);
  7867. /* Check if port already exists */
  7868. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  7869. goto not_found;
  7870. switch (ti->type) {
  7871. case UDP_TUNNEL_TYPE_VXLAN:
  7872. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  7873. goto not_found;
  7874. break;
  7875. case UDP_TUNNEL_TYPE_GENEVE:
  7876. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  7877. goto not_found;
  7878. break;
  7879. default:
  7880. goto not_found;
  7881. }
  7882. /* if port exists, set it to 0 (mark for deletion)
  7883. * and make it pending
  7884. */
  7885. pf->udp_ports[idx].index = 0;
  7886. pf->pending_udp_bitmap |= BIT_ULL(idx);
  7887. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7888. return;
  7889. not_found:
  7890. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  7891. ntohs(port));
  7892. }
  7893. static int i40e_get_phys_port_id(struct net_device *netdev,
  7894. struct netdev_phys_item_id *ppid)
  7895. {
  7896. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7897. struct i40e_pf *pf = np->vsi->back;
  7898. struct i40e_hw *hw = &pf->hw;
  7899. if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
  7900. return -EOPNOTSUPP;
  7901. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  7902. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  7903. return 0;
  7904. }
  7905. /**
  7906. * i40e_ndo_fdb_add - add an entry to the hardware database
  7907. * @ndm: the input from the stack
  7908. * @tb: pointer to array of nladdr (unused)
  7909. * @dev: the net device pointer
  7910. * @addr: the MAC address entry being added
  7911. * @flags: instructions from stack about fdb operation
  7912. */
  7913. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  7914. struct net_device *dev,
  7915. const unsigned char *addr, u16 vid,
  7916. u16 flags)
  7917. {
  7918. struct i40e_netdev_priv *np = netdev_priv(dev);
  7919. struct i40e_pf *pf = np->vsi->back;
  7920. int err = 0;
  7921. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  7922. return -EOPNOTSUPP;
  7923. if (vid) {
  7924. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  7925. return -EINVAL;
  7926. }
  7927. /* Hardware does not support aging addresses so if a
  7928. * ndm_state is given only allow permanent addresses
  7929. */
  7930. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  7931. netdev_info(dev, "FDB only supports static addresses\n");
  7932. return -EINVAL;
  7933. }
  7934. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  7935. err = dev_uc_add_excl(dev, addr);
  7936. else if (is_multicast_ether_addr(addr))
  7937. err = dev_mc_add_excl(dev, addr);
  7938. else
  7939. err = -EINVAL;
  7940. /* Only return duplicate errors if NLM_F_EXCL is set */
  7941. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  7942. err = 0;
  7943. return err;
  7944. }
  7945. /**
  7946. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  7947. * @dev: the netdev being configured
  7948. * @nlh: RTNL message
  7949. *
  7950. * Inserts a new hardware bridge if not already created and
  7951. * enables the bridging mode requested (VEB or VEPA). If the
  7952. * hardware bridge has already been inserted and the request
  7953. * is to change the mode then that requires a PF reset to
  7954. * allow rebuild of the components with required hardware
  7955. * bridge mode enabled.
  7956. **/
  7957. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  7958. struct nlmsghdr *nlh,
  7959. u16 flags)
  7960. {
  7961. struct i40e_netdev_priv *np = netdev_priv(dev);
  7962. struct i40e_vsi *vsi = np->vsi;
  7963. struct i40e_pf *pf = vsi->back;
  7964. struct i40e_veb *veb = NULL;
  7965. struct nlattr *attr, *br_spec;
  7966. int i, rem;
  7967. /* Only for PF VSI for now */
  7968. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  7969. return -EOPNOTSUPP;
  7970. /* Find the HW bridge for PF VSI */
  7971. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7972. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7973. veb = pf->veb[i];
  7974. }
  7975. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  7976. nla_for_each_nested(attr, br_spec, rem) {
  7977. __u16 mode;
  7978. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  7979. continue;
  7980. mode = nla_get_u16(attr);
  7981. if ((mode != BRIDGE_MODE_VEPA) &&
  7982. (mode != BRIDGE_MODE_VEB))
  7983. return -EINVAL;
  7984. /* Insert a new HW bridge */
  7985. if (!veb) {
  7986. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  7987. vsi->tc_config.enabled_tc);
  7988. if (veb) {
  7989. veb->bridge_mode = mode;
  7990. i40e_config_bridge_mode(veb);
  7991. } else {
  7992. /* No Bridge HW offload available */
  7993. return -ENOENT;
  7994. }
  7995. break;
  7996. } else if (mode != veb->bridge_mode) {
  7997. /* Existing HW bridge but different mode needs reset */
  7998. veb->bridge_mode = mode;
  7999. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  8000. if (mode == BRIDGE_MODE_VEB)
  8001. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  8002. else
  8003. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8004. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  8005. break;
  8006. }
  8007. }
  8008. return 0;
  8009. }
  8010. /**
  8011. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  8012. * @skb: skb buff
  8013. * @pid: process id
  8014. * @seq: RTNL message seq #
  8015. * @dev: the netdev being configured
  8016. * @filter_mask: unused
  8017. * @nlflags: netlink flags passed in
  8018. *
  8019. * Return the mode in which the hardware bridge is operating in
  8020. * i.e VEB or VEPA.
  8021. **/
  8022. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  8023. struct net_device *dev,
  8024. u32 __always_unused filter_mask,
  8025. int nlflags)
  8026. {
  8027. struct i40e_netdev_priv *np = netdev_priv(dev);
  8028. struct i40e_vsi *vsi = np->vsi;
  8029. struct i40e_pf *pf = vsi->back;
  8030. struct i40e_veb *veb = NULL;
  8031. int i;
  8032. /* Only for PF VSI for now */
  8033. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  8034. return -EOPNOTSUPP;
  8035. /* Find the HW bridge for the PF VSI */
  8036. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8037. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8038. veb = pf->veb[i];
  8039. }
  8040. if (!veb)
  8041. return 0;
  8042. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  8043. 0, 0, nlflags, filter_mask, NULL);
  8044. }
  8045. /**
  8046. * i40e_features_check - Validate encapsulated packet conforms to limits
  8047. * @skb: skb buff
  8048. * @dev: This physical port's netdev
  8049. * @features: Offload features that the stack believes apply
  8050. **/
  8051. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  8052. struct net_device *dev,
  8053. netdev_features_t features)
  8054. {
  8055. size_t len;
  8056. /* No point in doing any of this if neither checksum nor GSO are
  8057. * being requested for this frame. We can rule out both by just
  8058. * checking for CHECKSUM_PARTIAL
  8059. */
  8060. if (skb->ip_summed != CHECKSUM_PARTIAL)
  8061. return features;
  8062. /* We cannot support GSO if the MSS is going to be less than
  8063. * 64 bytes. If it is then we need to drop support for GSO.
  8064. */
  8065. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  8066. features &= ~NETIF_F_GSO_MASK;
  8067. /* MACLEN can support at most 63 words */
  8068. len = skb_network_header(skb) - skb->data;
  8069. if (len & ~(63 * 2))
  8070. goto out_err;
  8071. /* IPLEN and EIPLEN can support at most 127 dwords */
  8072. len = skb_transport_header(skb) - skb_network_header(skb);
  8073. if (len & ~(127 * 4))
  8074. goto out_err;
  8075. if (skb->encapsulation) {
  8076. /* L4TUNLEN can support 127 words */
  8077. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  8078. if (len & ~(127 * 2))
  8079. goto out_err;
  8080. /* IPLEN can support at most 127 dwords */
  8081. len = skb_inner_transport_header(skb) -
  8082. skb_inner_network_header(skb);
  8083. if (len & ~(127 * 4))
  8084. goto out_err;
  8085. }
  8086. /* No need to validate L4LEN as TCP is the only protocol with a
  8087. * a flexible value and we support all possible values supported
  8088. * by TCP, which is at most 15 dwords
  8089. */
  8090. return features;
  8091. out_err:
  8092. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  8093. }
  8094. static const struct net_device_ops i40e_netdev_ops = {
  8095. .ndo_open = i40e_open,
  8096. .ndo_stop = i40e_close,
  8097. .ndo_start_xmit = i40e_lan_xmit_frame,
  8098. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  8099. .ndo_set_rx_mode = i40e_set_rx_mode,
  8100. .ndo_validate_addr = eth_validate_addr,
  8101. .ndo_set_mac_address = i40e_set_mac,
  8102. .ndo_change_mtu = i40e_change_mtu,
  8103. .ndo_do_ioctl = i40e_ioctl,
  8104. .ndo_tx_timeout = i40e_tx_timeout,
  8105. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  8106. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  8107. #ifdef CONFIG_NET_POLL_CONTROLLER
  8108. .ndo_poll_controller = i40e_netpoll,
  8109. #endif
  8110. .ndo_setup_tc = __i40e_setup_tc,
  8111. #ifdef I40E_FCOE
  8112. .ndo_fcoe_enable = i40e_fcoe_enable,
  8113. .ndo_fcoe_disable = i40e_fcoe_disable,
  8114. #endif
  8115. .ndo_set_features = i40e_set_features,
  8116. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  8117. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  8118. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  8119. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  8120. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  8121. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  8122. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  8123. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  8124. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  8125. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  8126. .ndo_fdb_add = i40e_ndo_fdb_add,
  8127. .ndo_features_check = i40e_features_check,
  8128. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  8129. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  8130. };
  8131. /**
  8132. * i40e_config_netdev - Setup the netdev flags
  8133. * @vsi: the VSI being configured
  8134. *
  8135. * Returns 0 on success, negative value on failure
  8136. **/
  8137. static int i40e_config_netdev(struct i40e_vsi *vsi)
  8138. {
  8139. struct i40e_pf *pf = vsi->back;
  8140. struct i40e_hw *hw = &pf->hw;
  8141. struct i40e_netdev_priv *np;
  8142. struct net_device *netdev;
  8143. u8 broadcast[ETH_ALEN];
  8144. u8 mac_addr[ETH_ALEN];
  8145. int etherdev_size;
  8146. etherdev_size = sizeof(struct i40e_netdev_priv);
  8147. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  8148. if (!netdev)
  8149. return -ENOMEM;
  8150. vsi->netdev = netdev;
  8151. np = netdev_priv(netdev);
  8152. np->vsi = vsi;
  8153. netdev->hw_enc_features |= NETIF_F_SG |
  8154. NETIF_F_IP_CSUM |
  8155. NETIF_F_IPV6_CSUM |
  8156. NETIF_F_HIGHDMA |
  8157. NETIF_F_SOFT_FEATURES |
  8158. NETIF_F_TSO |
  8159. NETIF_F_TSO_ECN |
  8160. NETIF_F_TSO6 |
  8161. NETIF_F_GSO_GRE |
  8162. NETIF_F_GSO_GRE_CSUM |
  8163. NETIF_F_GSO_IPXIP4 |
  8164. NETIF_F_GSO_IPXIP6 |
  8165. NETIF_F_GSO_UDP_TUNNEL |
  8166. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  8167. NETIF_F_GSO_PARTIAL |
  8168. NETIF_F_SCTP_CRC |
  8169. NETIF_F_RXHASH |
  8170. NETIF_F_RXCSUM |
  8171. 0;
  8172. if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
  8173. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  8174. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  8175. /* record features VLANs can make use of */
  8176. netdev->vlan_features |= netdev->hw_enc_features |
  8177. NETIF_F_TSO_MANGLEID;
  8178. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  8179. netdev->hw_features |= NETIF_F_NTUPLE;
  8180. netdev->hw_features |= netdev->hw_enc_features |
  8181. NETIF_F_HW_VLAN_CTAG_TX |
  8182. NETIF_F_HW_VLAN_CTAG_RX;
  8183. netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  8184. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  8185. if (vsi->type == I40E_VSI_MAIN) {
  8186. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  8187. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  8188. /* The following steps are necessary to prevent reception
  8189. * of tagged packets - some older NVM configurations load a
  8190. * default a MAC-VLAN filter that accepts any tagged packet
  8191. * which must be replaced by a normal filter.
  8192. */
  8193. i40e_rm_default_mac_filter(vsi, mac_addr);
  8194. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8195. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY);
  8196. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8197. } else {
  8198. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  8199. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  8200. pf->vsi[pf->lan_vsi]->netdev->name);
  8201. random_ether_addr(mac_addr);
  8202. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8203. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY);
  8204. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8205. }
  8206. /* Add the broadcast filter so that we initially will receive
  8207. * broadcast packets. Note that when a new VLAN is first added the
  8208. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  8209. * specific filters as part of transitioning into "vlan" operation.
  8210. * When more VLANs are added, the driver will copy each existing MAC
  8211. * filter and add it for the new VLAN.
  8212. *
  8213. * Broadcast filters are handled specially by
  8214. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  8215. * promiscuous bit instead of adding this directly as a MAC/VLAN
  8216. * filter. The subtask will update the correct broadcast promiscuous
  8217. * bits as VLANs become active or inactive.
  8218. */
  8219. eth_broadcast_addr(broadcast);
  8220. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8221. i40e_add_filter(vsi, broadcast, I40E_VLAN_ANY);
  8222. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8223. ether_addr_copy(netdev->dev_addr, mac_addr);
  8224. ether_addr_copy(netdev->perm_addr, mac_addr);
  8225. netdev->priv_flags |= IFF_UNICAST_FLT;
  8226. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8227. /* Setup netdev TC information */
  8228. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  8229. netdev->netdev_ops = &i40e_netdev_ops;
  8230. netdev->watchdog_timeo = 5 * HZ;
  8231. i40e_set_ethtool_ops(netdev);
  8232. #ifdef I40E_FCOE
  8233. i40e_fcoe_config_netdev(netdev, vsi);
  8234. #endif
  8235. /* MTU range: 68 - 9706 */
  8236. netdev->min_mtu = ETH_MIN_MTU;
  8237. netdev->max_mtu = I40E_MAX_RXBUFFER -
  8238. (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
  8239. return 0;
  8240. }
  8241. /**
  8242. * i40e_vsi_delete - Delete a VSI from the switch
  8243. * @vsi: the VSI being removed
  8244. *
  8245. * Returns 0 on success, negative value on failure
  8246. **/
  8247. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  8248. {
  8249. /* remove default VSI is not allowed */
  8250. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  8251. return;
  8252. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  8253. }
  8254. /**
  8255. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  8256. * @vsi: the VSI being queried
  8257. *
  8258. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  8259. **/
  8260. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  8261. {
  8262. struct i40e_veb *veb;
  8263. struct i40e_pf *pf = vsi->back;
  8264. /* Uplink is not a bridge so default to VEB */
  8265. if (vsi->veb_idx == I40E_NO_VEB)
  8266. return 1;
  8267. veb = pf->veb[vsi->veb_idx];
  8268. if (!veb) {
  8269. dev_info(&pf->pdev->dev,
  8270. "There is no veb associated with the bridge\n");
  8271. return -ENOENT;
  8272. }
  8273. /* Uplink is a bridge in VEPA mode */
  8274. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  8275. return 0;
  8276. } else {
  8277. /* Uplink is a bridge in VEB mode */
  8278. return 1;
  8279. }
  8280. /* VEPA is now default bridge, so return 0 */
  8281. return 0;
  8282. }
  8283. /**
  8284. * i40e_add_vsi - Add a VSI to the switch
  8285. * @vsi: the VSI being configured
  8286. *
  8287. * This initializes a VSI context depending on the VSI type to be added and
  8288. * passes it down to the add_vsi aq command.
  8289. **/
  8290. static int i40e_add_vsi(struct i40e_vsi *vsi)
  8291. {
  8292. int ret = -ENODEV;
  8293. struct i40e_pf *pf = vsi->back;
  8294. struct i40e_hw *hw = &pf->hw;
  8295. struct i40e_vsi_context ctxt;
  8296. struct i40e_mac_filter *f;
  8297. struct hlist_node *h;
  8298. int bkt;
  8299. u8 enabled_tc = 0x1; /* TC0 enabled */
  8300. int f_count = 0;
  8301. memset(&ctxt, 0, sizeof(ctxt));
  8302. switch (vsi->type) {
  8303. case I40E_VSI_MAIN:
  8304. /* The PF's main VSI is already setup as part of the
  8305. * device initialization, so we'll not bother with
  8306. * the add_vsi call, but we will retrieve the current
  8307. * VSI context.
  8308. */
  8309. ctxt.seid = pf->main_vsi_seid;
  8310. ctxt.pf_num = pf->hw.pf_id;
  8311. ctxt.vf_num = 0;
  8312. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  8313. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8314. if (ret) {
  8315. dev_info(&pf->pdev->dev,
  8316. "couldn't get PF vsi config, err %s aq_err %s\n",
  8317. i40e_stat_str(&pf->hw, ret),
  8318. i40e_aq_str(&pf->hw,
  8319. pf->hw.aq.asq_last_status));
  8320. return -ENOENT;
  8321. }
  8322. vsi->info = ctxt.info;
  8323. vsi->info.valid_sections = 0;
  8324. vsi->seid = ctxt.seid;
  8325. vsi->id = ctxt.vsi_number;
  8326. enabled_tc = i40e_pf_get_tc_map(pf);
  8327. /* MFP mode setup queue map and update VSI */
  8328. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  8329. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  8330. memset(&ctxt, 0, sizeof(ctxt));
  8331. ctxt.seid = pf->main_vsi_seid;
  8332. ctxt.pf_num = pf->hw.pf_id;
  8333. ctxt.vf_num = 0;
  8334. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  8335. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  8336. if (ret) {
  8337. dev_info(&pf->pdev->dev,
  8338. "update vsi failed, err %s aq_err %s\n",
  8339. i40e_stat_str(&pf->hw, ret),
  8340. i40e_aq_str(&pf->hw,
  8341. pf->hw.aq.asq_last_status));
  8342. ret = -ENOENT;
  8343. goto err;
  8344. }
  8345. /* update the local VSI info queue map */
  8346. i40e_vsi_update_queue_map(vsi, &ctxt);
  8347. vsi->info.valid_sections = 0;
  8348. } else {
  8349. /* Default/Main VSI is only enabled for TC0
  8350. * reconfigure it to enable all TCs that are
  8351. * available on the port in SFP mode.
  8352. * For MFP case the iSCSI PF would use this
  8353. * flow to enable LAN+iSCSI TC.
  8354. */
  8355. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  8356. if (ret) {
  8357. dev_info(&pf->pdev->dev,
  8358. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  8359. enabled_tc,
  8360. i40e_stat_str(&pf->hw, ret),
  8361. i40e_aq_str(&pf->hw,
  8362. pf->hw.aq.asq_last_status));
  8363. ret = -ENOENT;
  8364. }
  8365. }
  8366. break;
  8367. case I40E_VSI_FDIR:
  8368. ctxt.pf_num = hw->pf_id;
  8369. ctxt.vf_num = 0;
  8370. ctxt.uplink_seid = vsi->uplink_seid;
  8371. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8372. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8373. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  8374. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  8375. ctxt.info.valid_sections |=
  8376. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8377. ctxt.info.switch_id =
  8378. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8379. }
  8380. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8381. break;
  8382. case I40E_VSI_VMDQ2:
  8383. ctxt.pf_num = hw->pf_id;
  8384. ctxt.vf_num = 0;
  8385. ctxt.uplink_seid = vsi->uplink_seid;
  8386. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8387. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  8388. /* This VSI is connected to VEB so the switch_id
  8389. * should be set to zero by default.
  8390. */
  8391. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8392. ctxt.info.valid_sections |=
  8393. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8394. ctxt.info.switch_id =
  8395. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8396. }
  8397. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8398. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8399. break;
  8400. case I40E_VSI_SRIOV:
  8401. ctxt.pf_num = hw->pf_id;
  8402. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  8403. ctxt.uplink_seid = vsi->uplink_seid;
  8404. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8405. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  8406. /* This VSI is connected to VEB so the switch_id
  8407. * should be set to zero by default.
  8408. */
  8409. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8410. ctxt.info.valid_sections |=
  8411. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8412. ctxt.info.switch_id =
  8413. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8414. }
  8415. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  8416. ctxt.info.valid_sections |=
  8417. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  8418. ctxt.info.queueing_opt_flags |=
  8419. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  8420. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  8421. }
  8422. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  8423. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  8424. if (pf->vf[vsi->vf_id].spoofchk) {
  8425. ctxt.info.valid_sections |=
  8426. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  8427. ctxt.info.sec_flags |=
  8428. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  8429. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  8430. }
  8431. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8432. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8433. break;
  8434. #ifdef I40E_FCOE
  8435. case I40E_VSI_FCOE:
  8436. ret = i40e_fcoe_vsi_init(vsi, &ctxt);
  8437. if (ret) {
  8438. dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
  8439. return ret;
  8440. }
  8441. break;
  8442. #endif /* I40E_FCOE */
  8443. case I40E_VSI_IWARP:
  8444. /* send down message to iWARP */
  8445. break;
  8446. default:
  8447. return -ENODEV;
  8448. }
  8449. if (vsi->type != I40E_VSI_MAIN) {
  8450. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  8451. if (ret) {
  8452. dev_info(&vsi->back->pdev->dev,
  8453. "add vsi failed, err %s aq_err %s\n",
  8454. i40e_stat_str(&pf->hw, ret),
  8455. i40e_aq_str(&pf->hw,
  8456. pf->hw.aq.asq_last_status));
  8457. ret = -ENOENT;
  8458. goto err;
  8459. }
  8460. vsi->info = ctxt.info;
  8461. vsi->info.valid_sections = 0;
  8462. vsi->seid = ctxt.seid;
  8463. vsi->id = ctxt.vsi_number;
  8464. }
  8465. vsi->active_filters = 0;
  8466. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  8467. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8468. /* If macvlan filters already exist, force them to get loaded */
  8469. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  8470. f->state = I40E_FILTER_NEW;
  8471. f_count++;
  8472. }
  8473. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8474. if (f_count) {
  8475. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  8476. pf->flags |= I40E_FLAG_FILTER_SYNC;
  8477. }
  8478. /* Update VSI BW information */
  8479. ret = i40e_vsi_get_bw_info(vsi);
  8480. if (ret) {
  8481. dev_info(&pf->pdev->dev,
  8482. "couldn't get vsi bw info, err %s aq_err %s\n",
  8483. i40e_stat_str(&pf->hw, ret),
  8484. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8485. /* VSI is already added so not tearing that up */
  8486. ret = 0;
  8487. }
  8488. err:
  8489. return ret;
  8490. }
  8491. /**
  8492. * i40e_vsi_release - Delete a VSI and free its resources
  8493. * @vsi: the VSI being removed
  8494. *
  8495. * Returns 0 on success or < 0 on error
  8496. **/
  8497. int i40e_vsi_release(struct i40e_vsi *vsi)
  8498. {
  8499. struct i40e_mac_filter *f;
  8500. struct hlist_node *h;
  8501. struct i40e_veb *veb = NULL;
  8502. struct i40e_pf *pf;
  8503. u16 uplink_seid;
  8504. int i, n, bkt;
  8505. pf = vsi->back;
  8506. /* release of a VEB-owner or last VSI is not allowed */
  8507. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  8508. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  8509. vsi->seid, vsi->uplink_seid);
  8510. return -ENODEV;
  8511. }
  8512. if (vsi == pf->vsi[pf->lan_vsi] &&
  8513. !test_bit(__I40E_DOWN, &pf->state)) {
  8514. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  8515. return -ENODEV;
  8516. }
  8517. uplink_seid = vsi->uplink_seid;
  8518. if (vsi->type != I40E_VSI_SRIOV) {
  8519. if (vsi->netdev_registered) {
  8520. vsi->netdev_registered = false;
  8521. if (vsi->netdev) {
  8522. /* results in a call to i40e_close() */
  8523. unregister_netdev(vsi->netdev);
  8524. }
  8525. } else {
  8526. i40e_vsi_close(vsi);
  8527. }
  8528. i40e_vsi_disable_irq(vsi);
  8529. }
  8530. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8531. /* clear the sync flag on all filters */
  8532. if (vsi->netdev) {
  8533. __dev_uc_unsync(vsi->netdev, NULL);
  8534. __dev_mc_unsync(vsi->netdev, NULL);
  8535. }
  8536. /* make sure any remaining filters are marked for deletion */
  8537. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  8538. __i40e_del_filter(vsi, f);
  8539. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8540. i40e_sync_vsi_filters(vsi);
  8541. i40e_vsi_delete(vsi);
  8542. i40e_vsi_free_q_vectors(vsi);
  8543. if (vsi->netdev) {
  8544. free_netdev(vsi->netdev);
  8545. vsi->netdev = NULL;
  8546. }
  8547. i40e_vsi_clear_rings(vsi);
  8548. i40e_vsi_clear(vsi);
  8549. /* If this was the last thing on the VEB, except for the
  8550. * controlling VSI, remove the VEB, which puts the controlling
  8551. * VSI onto the next level down in the switch.
  8552. *
  8553. * Well, okay, there's one more exception here: don't remove
  8554. * the orphan VEBs yet. We'll wait for an explicit remove request
  8555. * from up the network stack.
  8556. */
  8557. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  8558. if (pf->vsi[i] &&
  8559. pf->vsi[i]->uplink_seid == uplink_seid &&
  8560. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8561. n++; /* count the VSIs */
  8562. }
  8563. }
  8564. for (i = 0; i < I40E_MAX_VEB; i++) {
  8565. if (!pf->veb[i])
  8566. continue;
  8567. if (pf->veb[i]->uplink_seid == uplink_seid)
  8568. n++; /* count the VEBs */
  8569. if (pf->veb[i]->seid == uplink_seid)
  8570. veb = pf->veb[i];
  8571. }
  8572. if (n == 0 && veb && veb->uplink_seid != 0)
  8573. i40e_veb_release(veb);
  8574. return 0;
  8575. }
  8576. /**
  8577. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  8578. * @vsi: ptr to the VSI
  8579. *
  8580. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  8581. * corresponding SW VSI structure and initializes num_queue_pairs for the
  8582. * newly allocated VSI.
  8583. *
  8584. * Returns 0 on success or negative on failure
  8585. **/
  8586. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  8587. {
  8588. int ret = -ENOENT;
  8589. struct i40e_pf *pf = vsi->back;
  8590. if (vsi->q_vectors[0]) {
  8591. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  8592. vsi->seid);
  8593. return -EEXIST;
  8594. }
  8595. if (vsi->base_vector) {
  8596. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  8597. vsi->seid, vsi->base_vector);
  8598. return -EEXIST;
  8599. }
  8600. ret = i40e_vsi_alloc_q_vectors(vsi);
  8601. if (ret) {
  8602. dev_info(&pf->pdev->dev,
  8603. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  8604. vsi->num_q_vectors, vsi->seid, ret);
  8605. vsi->num_q_vectors = 0;
  8606. goto vector_setup_out;
  8607. }
  8608. /* In Legacy mode, we do not have to get any other vector since we
  8609. * piggyback on the misc/ICR0 for queue interrupts.
  8610. */
  8611. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8612. return ret;
  8613. if (vsi->num_q_vectors)
  8614. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  8615. vsi->num_q_vectors, vsi->idx);
  8616. if (vsi->base_vector < 0) {
  8617. dev_info(&pf->pdev->dev,
  8618. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  8619. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  8620. i40e_vsi_free_q_vectors(vsi);
  8621. ret = -ENOENT;
  8622. goto vector_setup_out;
  8623. }
  8624. vector_setup_out:
  8625. return ret;
  8626. }
  8627. /**
  8628. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  8629. * @vsi: pointer to the vsi.
  8630. *
  8631. * This re-allocates a vsi's queue resources.
  8632. *
  8633. * Returns pointer to the successfully allocated and configured VSI sw struct
  8634. * on success, otherwise returns NULL on failure.
  8635. **/
  8636. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  8637. {
  8638. struct i40e_pf *pf;
  8639. u8 enabled_tc;
  8640. int ret;
  8641. if (!vsi)
  8642. return NULL;
  8643. pf = vsi->back;
  8644. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8645. i40e_vsi_clear_rings(vsi);
  8646. i40e_vsi_free_arrays(vsi, false);
  8647. i40e_set_num_rings_in_vsi(vsi);
  8648. ret = i40e_vsi_alloc_arrays(vsi, false);
  8649. if (ret)
  8650. goto err_vsi;
  8651. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  8652. if (ret < 0) {
  8653. dev_info(&pf->pdev->dev,
  8654. "failed to get tracking for %d queues for VSI %d err %d\n",
  8655. vsi->alloc_queue_pairs, vsi->seid, ret);
  8656. goto err_vsi;
  8657. }
  8658. vsi->base_queue = ret;
  8659. /* Update the FW view of the VSI. Force a reset of TC and queue
  8660. * layout configurations.
  8661. */
  8662. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  8663. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  8664. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  8665. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  8666. if (vsi->type == I40E_VSI_MAIN)
  8667. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  8668. /* assign it some queues */
  8669. ret = i40e_alloc_rings(vsi);
  8670. if (ret)
  8671. goto err_rings;
  8672. /* map all of the rings to the q_vectors */
  8673. i40e_vsi_map_rings_to_vectors(vsi);
  8674. return vsi;
  8675. err_rings:
  8676. i40e_vsi_free_q_vectors(vsi);
  8677. if (vsi->netdev_registered) {
  8678. vsi->netdev_registered = false;
  8679. unregister_netdev(vsi->netdev);
  8680. free_netdev(vsi->netdev);
  8681. vsi->netdev = NULL;
  8682. }
  8683. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8684. err_vsi:
  8685. i40e_vsi_clear(vsi);
  8686. return NULL;
  8687. }
  8688. /**
  8689. * i40e_vsi_setup - Set up a VSI by a given type
  8690. * @pf: board private structure
  8691. * @type: VSI type
  8692. * @uplink_seid: the switch element to link to
  8693. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  8694. *
  8695. * This allocates the sw VSI structure and its queue resources, then add a VSI
  8696. * to the identified VEB.
  8697. *
  8698. * Returns pointer to the successfully allocated and configure VSI sw struct on
  8699. * success, otherwise returns NULL on failure.
  8700. **/
  8701. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  8702. u16 uplink_seid, u32 param1)
  8703. {
  8704. struct i40e_vsi *vsi = NULL;
  8705. struct i40e_veb *veb = NULL;
  8706. int ret, i;
  8707. int v_idx;
  8708. /* The requested uplink_seid must be either
  8709. * - the PF's port seid
  8710. * no VEB is needed because this is the PF
  8711. * or this is a Flow Director special case VSI
  8712. * - seid of an existing VEB
  8713. * - seid of a VSI that owns an existing VEB
  8714. * - seid of a VSI that doesn't own a VEB
  8715. * a new VEB is created and the VSI becomes the owner
  8716. * - seid of the PF VSI, which is what creates the first VEB
  8717. * this is a special case of the previous
  8718. *
  8719. * Find which uplink_seid we were given and create a new VEB if needed
  8720. */
  8721. for (i = 0; i < I40E_MAX_VEB; i++) {
  8722. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  8723. veb = pf->veb[i];
  8724. break;
  8725. }
  8726. }
  8727. if (!veb && uplink_seid != pf->mac_seid) {
  8728. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8729. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  8730. vsi = pf->vsi[i];
  8731. break;
  8732. }
  8733. }
  8734. if (!vsi) {
  8735. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  8736. uplink_seid);
  8737. return NULL;
  8738. }
  8739. if (vsi->uplink_seid == pf->mac_seid)
  8740. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  8741. vsi->tc_config.enabled_tc);
  8742. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  8743. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  8744. vsi->tc_config.enabled_tc);
  8745. if (veb) {
  8746. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  8747. dev_info(&vsi->back->pdev->dev,
  8748. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  8749. return NULL;
  8750. }
  8751. /* We come up by default in VEPA mode if SRIOV is not
  8752. * already enabled, in which case we can't force VEPA
  8753. * mode.
  8754. */
  8755. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  8756. veb->bridge_mode = BRIDGE_MODE_VEPA;
  8757. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8758. }
  8759. i40e_config_bridge_mode(veb);
  8760. }
  8761. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8762. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8763. veb = pf->veb[i];
  8764. }
  8765. if (!veb) {
  8766. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  8767. return NULL;
  8768. }
  8769. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8770. uplink_seid = veb->seid;
  8771. }
  8772. /* get vsi sw struct */
  8773. v_idx = i40e_vsi_mem_alloc(pf, type);
  8774. if (v_idx < 0)
  8775. goto err_alloc;
  8776. vsi = pf->vsi[v_idx];
  8777. if (!vsi)
  8778. goto err_alloc;
  8779. vsi->type = type;
  8780. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  8781. if (type == I40E_VSI_MAIN)
  8782. pf->lan_vsi = v_idx;
  8783. else if (type == I40E_VSI_SRIOV)
  8784. vsi->vf_id = param1;
  8785. /* assign it some queues */
  8786. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  8787. vsi->idx);
  8788. if (ret < 0) {
  8789. dev_info(&pf->pdev->dev,
  8790. "failed to get tracking for %d queues for VSI %d err=%d\n",
  8791. vsi->alloc_queue_pairs, vsi->seid, ret);
  8792. goto err_vsi;
  8793. }
  8794. vsi->base_queue = ret;
  8795. /* get a VSI from the hardware */
  8796. vsi->uplink_seid = uplink_seid;
  8797. ret = i40e_add_vsi(vsi);
  8798. if (ret)
  8799. goto err_vsi;
  8800. switch (vsi->type) {
  8801. /* setup the netdev if needed */
  8802. case I40E_VSI_MAIN:
  8803. /* Apply relevant filters if a platform-specific mac
  8804. * address was selected.
  8805. */
  8806. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  8807. ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  8808. if (ret) {
  8809. dev_warn(&pf->pdev->dev,
  8810. "could not set up macaddr; err %d\n",
  8811. ret);
  8812. }
  8813. }
  8814. case I40E_VSI_VMDQ2:
  8815. case I40E_VSI_FCOE:
  8816. ret = i40e_config_netdev(vsi);
  8817. if (ret)
  8818. goto err_netdev;
  8819. ret = register_netdev(vsi->netdev);
  8820. if (ret)
  8821. goto err_netdev;
  8822. vsi->netdev_registered = true;
  8823. netif_carrier_off(vsi->netdev);
  8824. #ifdef CONFIG_I40E_DCB
  8825. /* Setup DCB netlink interface */
  8826. i40e_dcbnl_setup(vsi);
  8827. #endif /* CONFIG_I40E_DCB */
  8828. /* fall through */
  8829. case I40E_VSI_FDIR:
  8830. /* set up vectors and rings if needed */
  8831. ret = i40e_vsi_setup_vectors(vsi);
  8832. if (ret)
  8833. goto err_msix;
  8834. ret = i40e_alloc_rings(vsi);
  8835. if (ret)
  8836. goto err_rings;
  8837. /* map all of the rings to the q_vectors */
  8838. i40e_vsi_map_rings_to_vectors(vsi);
  8839. i40e_vsi_reset_stats(vsi);
  8840. break;
  8841. default:
  8842. /* no netdev or rings for the other VSI types */
  8843. break;
  8844. }
  8845. if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
  8846. (vsi->type == I40E_VSI_VMDQ2)) {
  8847. ret = i40e_vsi_config_rss(vsi);
  8848. }
  8849. return vsi;
  8850. err_rings:
  8851. i40e_vsi_free_q_vectors(vsi);
  8852. err_msix:
  8853. if (vsi->netdev_registered) {
  8854. vsi->netdev_registered = false;
  8855. unregister_netdev(vsi->netdev);
  8856. free_netdev(vsi->netdev);
  8857. vsi->netdev = NULL;
  8858. }
  8859. err_netdev:
  8860. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8861. err_vsi:
  8862. i40e_vsi_clear(vsi);
  8863. err_alloc:
  8864. return NULL;
  8865. }
  8866. /**
  8867. * i40e_veb_get_bw_info - Query VEB BW information
  8868. * @veb: the veb to query
  8869. *
  8870. * Query the Tx scheduler BW configuration data for given VEB
  8871. **/
  8872. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  8873. {
  8874. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  8875. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  8876. struct i40e_pf *pf = veb->pf;
  8877. struct i40e_hw *hw = &pf->hw;
  8878. u32 tc_bw_max;
  8879. int ret = 0;
  8880. int i;
  8881. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  8882. &bw_data, NULL);
  8883. if (ret) {
  8884. dev_info(&pf->pdev->dev,
  8885. "query veb bw config failed, err %s aq_err %s\n",
  8886. i40e_stat_str(&pf->hw, ret),
  8887. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8888. goto out;
  8889. }
  8890. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  8891. &ets_data, NULL);
  8892. if (ret) {
  8893. dev_info(&pf->pdev->dev,
  8894. "query veb bw ets config failed, err %s aq_err %s\n",
  8895. i40e_stat_str(&pf->hw, ret),
  8896. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8897. goto out;
  8898. }
  8899. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  8900. veb->bw_max_quanta = ets_data.tc_bw_max;
  8901. veb->is_abs_credits = bw_data.absolute_credits_enable;
  8902. veb->enabled_tc = ets_data.tc_valid_bits;
  8903. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  8904. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  8905. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  8906. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  8907. veb->bw_tc_limit_credits[i] =
  8908. le16_to_cpu(bw_data.tc_bw_limits[i]);
  8909. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  8910. }
  8911. out:
  8912. return ret;
  8913. }
  8914. /**
  8915. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  8916. * @pf: board private structure
  8917. *
  8918. * On error: returns error code (negative)
  8919. * On success: returns vsi index in PF (positive)
  8920. **/
  8921. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  8922. {
  8923. int ret = -ENOENT;
  8924. struct i40e_veb *veb;
  8925. int i;
  8926. /* Need to protect the allocation of switch elements at the PF level */
  8927. mutex_lock(&pf->switch_mutex);
  8928. /* VEB list may be fragmented if VEB creation/destruction has
  8929. * been happening. We can afford to do a quick scan to look
  8930. * for any free slots in the list.
  8931. *
  8932. * find next empty veb slot, looping back around if necessary
  8933. */
  8934. i = 0;
  8935. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  8936. i++;
  8937. if (i >= I40E_MAX_VEB) {
  8938. ret = -ENOMEM;
  8939. goto err_alloc_veb; /* out of VEB slots! */
  8940. }
  8941. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  8942. if (!veb) {
  8943. ret = -ENOMEM;
  8944. goto err_alloc_veb;
  8945. }
  8946. veb->pf = pf;
  8947. veb->idx = i;
  8948. veb->enabled_tc = 1;
  8949. pf->veb[i] = veb;
  8950. ret = i;
  8951. err_alloc_veb:
  8952. mutex_unlock(&pf->switch_mutex);
  8953. return ret;
  8954. }
  8955. /**
  8956. * i40e_switch_branch_release - Delete a branch of the switch tree
  8957. * @branch: where to start deleting
  8958. *
  8959. * This uses recursion to find the tips of the branch to be
  8960. * removed, deleting until we get back to and can delete this VEB.
  8961. **/
  8962. static void i40e_switch_branch_release(struct i40e_veb *branch)
  8963. {
  8964. struct i40e_pf *pf = branch->pf;
  8965. u16 branch_seid = branch->seid;
  8966. u16 veb_idx = branch->idx;
  8967. int i;
  8968. /* release any VEBs on this VEB - RECURSION */
  8969. for (i = 0; i < I40E_MAX_VEB; i++) {
  8970. if (!pf->veb[i])
  8971. continue;
  8972. if (pf->veb[i]->uplink_seid == branch->seid)
  8973. i40e_switch_branch_release(pf->veb[i]);
  8974. }
  8975. /* Release the VSIs on this VEB, but not the owner VSI.
  8976. *
  8977. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  8978. * the VEB itself, so don't use (*branch) after this loop.
  8979. */
  8980. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8981. if (!pf->vsi[i])
  8982. continue;
  8983. if (pf->vsi[i]->uplink_seid == branch_seid &&
  8984. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8985. i40e_vsi_release(pf->vsi[i]);
  8986. }
  8987. }
  8988. /* There's one corner case where the VEB might not have been
  8989. * removed, so double check it here and remove it if needed.
  8990. * This case happens if the veb was created from the debugfs
  8991. * commands and no VSIs were added to it.
  8992. */
  8993. if (pf->veb[veb_idx])
  8994. i40e_veb_release(pf->veb[veb_idx]);
  8995. }
  8996. /**
  8997. * i40e_veb_clear - remove veb struct
  8998. * @veb: the veb to remove
  8999. **/
  9000. static void i40e_veb_clear(struct i40e_veb *veb)
  9001. {
  9002. if (!veb)
  9003. return;
  9004. if (veb->pf) {
  9005. struct i40e_pf *pf = veb->pf;
  9006. mutex_lock(&pf->switch_mutex);
  9007. if (pf->veb[veb->idx] == veb)
  9008. pf->veb[veb->idx] = NULL;
  9009. mutex_unlock(&pf->switch_mutex);
  9010. }
  9011. kfree(veb);
  9012. }
  9013. /**
  9014. * i40e_veb_release - Delete a VEB and free its resources
  9015. * @veb: the VEB being removed
  9016. **/
  9017. void i40e_veb_release(struct i40e_veb *veb)
  9018. {
  9019. struct i40e_vsi *vsi = NULL;
  9020. struct i40e_pf *pf;
  9021. int i, n = 0;
  9022. pf = veb->pf;
  9023. /* find the remaining VSI and check for extras */
  9024. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9025. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  9026. n++;
  9027. vsi = pf->vsi[i];
  9028. }
  9029. }
  9030. if (n != 1) {
  9031. dev_info(&pf->pdev->dev,
  9032. "can't remove VEB %d with %d VSIs left\n",
  9033. veb->seid, n);
  9034. return;
  9035. }
  9036. /* move the remaining VSI to uplink veb */
  9037. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  9038. if (veb->uplink_seid) {
  9039. vsi->uplink_seid = veb->uplink_seid;
  9040. if (veb->uplink_seid == pf->mac_seid)
  9041. vsi->veb_idx = I40E_NO_VEB;
  9042. else
  9043. vsi->veb_idx = veb->veb_idx;
  9044. } else {
  9045. /* floating VEB */
  9046. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  9047. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  9048. }
  9049. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  9050. i40e_veb_clear(veb);
  9051. }
  9052. /**
  9053. * i40e_add_veb - create the VEB in the switch
  9054. * @veb: the VEB to be instantiated
  9055. * @vsi: the controlling VSI
  9056. **/
  9057. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  9058. {
  9059. struct i40e_pf *pf = veb->pf;
  9060. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  9061. int ret;
  9062. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  9063. veb->enabled_tc, false,
  9064. &veb->seid, enable_stats, NULL);
  9065. /* get a VEB from the hardware */
  9066. if (ret) {
  9067. dev_info(&pf->pdev->dev,
  9068. "couldn't add VEB, err %s aq_err %s\n",
  9069. i40e_stat_str(&pf->hw, ret),
  9070. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9071. return -EPERM;
  9072. }
  9073. /* get statistics counter */
  9074. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  9075. &veb->stats_idx, NULL, NULL, NULL);
  9076. if (ret) {
  9077. dev_info(&pf->pdev->dev,
  9078. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  9079. i40e_stat_str(&pf->hw, ret),
  9080. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9081. return -EPERM;
  9082. }
  9083. ret = i40e_veb_get_bw_info(veb);
  9084. if (ret) {
  9085. dev_info(&pf->pdev->dev,
  9086. "couldn't get VEB bw info, err %s aq_err %s\n",
  9087. i40e_stat_str(&pf->hw, ret),
  9088. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9089. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  9090. return -ENOENT;
  9091. }
  9092. vsi->uplink_seid = veb->seid;
  9093. vsi->veb_idx = veb->idx;
  9094. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  9095. return 0;
  9096. }
  9097. /**
  9098. * i40e_veb_setup - Set up a VEB
  9099. * @pf: board private structure
  9100. * @flags: VEB setup flags
  9101. * @uplink_seid: the switch element to link to
  9102. * @vsi_seid: the initial VSI seid
  9103. * @enabled_tc: Enabled TC bit-map
  9104. *
  9105. * This allocates the sw VEB structure and links it into the switch
  9106. * It is possible and legal for this to be a duplicate of an already
  9107. * existing VEB. It is also possible for both uplink and vsi seids
  9108. * to be zero, in order to create a floating VEB.
  9109. *
  9110. * Returns pointer to the successfully allocated VEB sw struct on
  9111. * success, otherwise returns NULL on failure.
  9112. **/
  9113. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  9114. u16 uplink_seid, u16 vsi_seid,
  9115. u8 enabled_tc)
  9116. {
  9117. struct i40e_veb *veb, *uplink_veb = NULL;
  9118. int vsi_idx, veb_idx;
  9119. int ret;
  9120. /* if one seid is 0, the other must be 0 to create a floating relay */
  9121. if ((uplink_seid == 0 || vsi_seid == 0) &&
  9122. (uplink_seid + vsi_seid != 0)) {
  9123. dev_info(&pf->pdev->dev,
  9124. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  9125. uplink_seid, vsi_seid);
  9126. return NULL;
  9127. }
  9128. /* make sure there is such a vsi and uplink */
  9129. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  9130. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  9131. break;
  9132. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  9133. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  9134. vsi_seid);
  9135. return NULL;
  9136. }
  9137. if (uplink_seid && uplink_seid != pf->mac_seid) {
  9138. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  9139. if (pf->veb[veb_idx] &&
  9140. pf->veb[veb_idx]->seid == uplink_seid) {
  9141. uplink_veb = pf->veb[veb_idx];
  9142. break;
  9143. }
  9144. }
  9145. if (!uplink_veb) {
  9146. dev_info(&pf->pdev->dev,
  9147. "uplink seid %d not found\n", uplink_seid);
  9148. return NULL;
  9149. }
  9150. }
  9151. /* get veb sw struct */
  9152. veb_idx = i40e_veb_mem_alloc(pf);
  9153. if (veb_idx < 0)
  9154. goto err_alloc;
  9155. veb = pf->veb[veb_idx];
  9156. veb->flags = flags;
  9157. veb->uplink_seid = uplink_seid;
  9158. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  9159. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  9160. /* create the VEB in the switch */
  9161. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  9162. if (ret)
  9163. goto err_veb;
  9164. if (vsi_idx == pf->lan_vsi)
  9165. pf->lan_veb = veb->idx;
  9166. return veb;
  9167. err_veb:
  9168. i40e_veb_clear(veb);
  9169. err_alloc:
  9170. return NULL;
  9171. }
  9172. /**
  9173. * i40e_setup_pf_switch_element - set PF vars based on switch type
  9174. * @pf: board private structure
  9175. * @ele: element we are building info from
  9176. * @num_reported: total number of elements
  9177. * @printconfig: should we print the contents
  9178. *
  9179. * helper function to assist in extracting a few useful SEID values.
  9180. **/
  9181. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  9182. struct i40e_aqc_switch_config_element_resp *ele,
  9183. u16 num_reported, bool printconfig)
  9184. {
  9185. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  9186. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  9187. u8 element_type = ele->element_type;
  9188. u16 seid = le16_to_cpu(ele->seid);
  9189. if (printconfig)
  9190. dev_info(&pf->pdev->dev,
  9191. "type=%d seid=%d uplink=%d downlink=%d\n",
  9192. element_type, seid, uplink_seid, downlink_seid);
  9193. switch (element_type) {
  9194. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  9195. pf->mac_seid = seid;
  9196. break;
  9197. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  9198. /* Main VEB? */
  9199. if (uplink_seid != pf->mac_seid)
  9200. break;
  9201. if (pf->lan_veb == I40E_NO_VEB) {
  9202. int v;
  9203. /* find existing or else empty VEB */
  9204. for (v = 0; v < I40E_MAX_VEB; v++) {
  9205. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  9206. pf->lan_veb = v;
  9207. break;
  9208. }
  9209. }
  9210. if (pf->lan_veb == I40E_NO_VEB) {
  9211. v = i40e_veb_mem_alloc(pf);
  9212. if (v < 0)
  9213. break;
  9214. pf->lan_veb = v;
  9215. }
  9216. }
  9217. pf->veb[pf->lan_veb]->seid = seid;
  9218. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  9219. pf->veb[pf->lan_veb]->pf = pf;
  9220. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  9221. break;
  9222. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  9223. if (num_reported != 1)
  9224. break;
  9225. /* This is immediately after a reset so we can assume this is
  9226. * the PF's VSI
  9227. */
  9228. pf->mac_seid = uplink_seid;
  9229. pf->pf_seid = downlink_seid;
  9230. pf->main_vsi_seid = seid;
  9231. if (printconfig)
  9232. dev_info(&pf->pdev->dev,
  9233. "pf_seid=%d main_vsi_seid=%d\n",
  9234. pf->pf_seid, pf->main_vsi_seid);
  9235. break;
  9236. case I40E_SWITCH_ELEMENT_TYPE_PF:
  9237. case I40E_SWITCH_ELEMENT_TYPE_VF:
  9238. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  9239. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  9240. case I40E_SWITCH_ELEMENT_TYPE_PE:
  9241. case I40E_SWITCH_ELEMENT_TYPE_PA:
  9242. /* ignore these for now */
  9243. break;
  9244. default:
  9245. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  9246. element_type, seid);
  9247. break;
  9248. }
  9249. }
  9250. /**
  9251. * i40e_fetch_switch_configuration - Get switch config from firmware
  9252. * @pf: board private structure
  9253. * @printconfig: should we print the contents
  9254. *
  9255. * Get the current switch configuration from the device and
  9256. * extract a few useful SEID values.
  9257. **/
  9258. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  9259. {
  9260. struct i40e_aqc_get_switch_config_resp *sw_config;
  9261. u16 next_seid = 0;
  9262. int ret = 0;
  9263. u8 *aq_buf;
  9264. int i;
  9265. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  9266. if (!aq_buf)
  9267. return -ENOMEM;
  9268. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  9269. do {
  9270. u16 num_reported, num_total;
  9271. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  9272. I40E_AQ_LARGE_BUF,
  9273. &next_seid, NULL);
  9274. if (ret) {
  9275. dev_info(&pf->pdev->dev,
  9276. "get switch config failed err %s aq_err %s\n",
  9277. i40e_stat_str(&pf->hw, ret),
  9278. i40e_aq_str(&pf->hw,
  9279. pf->hw.aq.asq_last_status));
  9280. kfree(aq_buf);
  9281. return -ENOENT;
  9282. }
  9283. num_reported = le16_to_cpu(sw_config->header.num_reported);
  9284. num_total = le16_to_cpu(sw_config->header.num_total);
  9285. if (printconfig)
  9286. dev_info(&pf->pdev->dev,
  9287. "header: %d reported %d total\n",
  9288. num_reported, num_total);
  9289. for (i = 0; i < num_reported; i++) {
  9290. struct i40e_aqc_switch_config_element_resp *ele =
  9291. &sw_config->element[i];
  9292. i40e_setup_pf_switch_element(pf, ele, num_reported,
  9293. printconfig);
  9294. }
  9295. } while (next_seid != 0);
  9296. kfree(aq_buf);
  9297. return ret;
  9298. }
  9299. /**
  9300. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  9301. * @pf: board private structure
  9302. * @reinit: if the Main VSI needs to re-initialized.
  9303. *
  9304. * Returns 0 on success, negative value on failure
  9305. **/
  9306. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  9307. {
  9308. u16 flags = 0;
  9309. int ret;
  9310. /* find out what's out there already */
  9311. ret = i40e_fetch_switch_configuration(pf, false);
  9312. if (ret) {
  9313. dev_info(&pf->pdev->dev,
  9314. "couldn't fetch switch config, err %s aq_err %s\n",
  9315. i40e_stat_str(&pf->hw, ret),
  9316. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9317. return ret;
  9318. }
  9319. i40e_pf_reset_stats(pf);
  9320. /* set the switch config bit for the whole device to
  9321. * support limited promisc or true promisc
  9322. * when user requests promisc. The default is limited
  9323. * promisc.
  9324. */
  9325. if ((pf->hw.pf_id == 0) &&
  9326. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  9327. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9328. if (pf->hw.pf_id == 0) {
  9329. u16 valid_flags;
  9330. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9331. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
  9332. NULL);
  9333. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  9334. dev_info(&pf->pdev->dev,
  9335. "couldn't set switch config bits, err %s aq_err %s\n",
  9336. i40e_stat_str(&pf->hw, ret),
  9337. i40e_aq_str(&pf->hw,
  9338. pf->hw.aq.asq_last_status));
  9339. /* not a fatal problem, just keep going */
  9340. }
  9341. }
  9342. /* first time setup */
  9343. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  9344. struct i40e_vsi *vsi = NULL;
  9345. u16 uplink_seid;
  9346. /* Set up the PF VSI associated with the PF's main VSI
  9347. * that is already in the HW switch
  9348. */
  9349. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  9350. uplink_seid = pf->veb[pf->lan_veb]->seid;
  9351. else
  9352. uplink_seid = pf->mac_seid;
  9353. if (pf->lan_vsi == I40E_NO_VSI)
  9354. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  9355. else if (reinit)
  9356. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  9357. if (!vsi) {
  9358. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  9359. i40e_fdir_teardown(pf);
  9360. return -EAGAIN;
  9361. }
  9362. } else {
  9363. /* force a reset of TC and queue layout configurations */
  9364. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  9365. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  9366. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  9367. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  9368. }
  9369. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  9370. i40e_fdir_sb_setup(pf);
  9371. /* Setup static PF queue filter control settings */
  9372. ret = i40e_setup_pf_filter_control(pf);
  9373. if (ret) {
  9374. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  9375. ret);
  9376. /* Failure here should not stop continuing other steps */
  9377. }
  9378. /* enable RSS in the HW, even for only one queue, as the stack can use
  9379. * the hash
  9380. */
  9381. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  9382. i40e_pf_config_rss(pf);
  9383. /* fill in link information and enable LSE reporting */
  9384. i40e_update_link_info(&pf->hw);
  9385. i40e_link_event(pf);
  9386. /* Initialize user-specific link properties */
  9387. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  9388. I40E_AQ_AN_COMPLETED) ? true : false);
  9389. i40e_ptp_init(pf);
  9390. return ret;
  9391. }
  9392. /**
  9393. * i40e_determine_queue_usage - Work out queue distribution
  9394. * @pf: board private structure
  9395. **/
  9396. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  9397. {
  9398. int queues_left;
  9399. pf->num_lan_qps = 0;
  9400. #ifdef I40E_FCOE
  9401. pf->num_fcoe_qps = 0;
  9402. #endif
  9403. /* Find the max queues to be put into basic use. We'll always be
  9404. * using TC0, whether or not DCB is running, and TC0 will get the
  9405. * big RSS set.
  9406. */
  9407. queues_left = pf->hw.func_caps.num_tx_qp;
  9408. if ((queues_left == 1) ||
  9409. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  9410. /* one qp for PF, no queues for anything else */
  9411. queues_left = 0;
  9412. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9413. /* make sure all the fancies are disabled */
  9414. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9415. I40E_FLAG_IWARP_ENABLED |
  9416. #ifdef I40E_FCOE
  9417. I40E_FLAG_FCOE_ENABLED |
  9418. #endif
  9419. I40E_FLAG_FD_SB_ENABLED |
  9420. I40E_FLAG_FD_ATR_ENABLED |
  9421. I40E_FLAG_DCB_CAPABLE |
  9422. I40E_FLAG_DCB_ENABLED |
  9423. I40E_FLAG_SRIOV_ENABLED |
  9424. I40E_FLAG_VMDQ_ENABLED);
  9425. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  9426. I40E_FLAG_FD_SB_ENABLED |
  9427. I40E_FLAG_FD_ATR_ENABLED |
  9428. I40E_FLAG_DCB_CAPABLE))) {
  9429. /* one qp for PF */
  9430. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9431. queues_left -= pf->num_lan_qps;
  9432. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9433. I40E_FLAG_IWARP_ENABLED |
  9434. #ifdef I40E_FCOE
  9435. I40E_FLAG_FCOE_ENABLED |
  9436. #endif
  9437. I40E_FLAG_FD_SB_ENABLED |
  9438. I40E_FLAG_FD_ATR_ENABLED |
  9439. I40E_FLAG_DCB_ENABLED |
  9440. I40E_FLAG_VMDQ_ENABLED);
  9441. } else {
  9442. /* Not enough queues for all TCs */
  9443. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  9444. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  9445. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  9446. I40E_FLAG_DCB_ENABLED);
  9447. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  9448. }
  9449. pf->num_lan_qps = max_t(int, pf->rss_size_max,
  9450. num_online_cpus());
  9451. pf->num_lan_qps = min_t(int, pf->num_lan_qps,
  9452. pf->hw.func_caps.num_tx_qp);
  9453. queues_left -= pf->num_lan_qps;
  9454. }
  9455. #ifdef I40E_FCOE
  9456. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  9457. if (I40E_DEFAULT_FCOE <= queues_left) {
  9458. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  9459. } else if (I40E_MINIMUM_FCOE <= queues_left) {
  9460. pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
  9461. } else {
  9462. pf->num_fcoe_qps = 0;
  9463. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  9464. dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
  9465. }
  9466. queues_left -= pf->num_fcoe_qps;
  9467. }
  9468. #endif
  9469. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9470. if (queues_left > 1) {
  9471. queues_left -= 1; /* save 1 queue for FD */
  9472. } else {
  9473. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9474. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  9475. }
  9476. }
  9477. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9478. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  9479. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  9480. (queues_left / pf->num_vf_qps));
  9481. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  9482. }
  9483. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9484. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  9485. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  9486. (queues_left / pf->num_vmdq_qps));
  9487. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  9488. }
  9489. pf->queues_left = queues_left;
  9490. dev_dbg(&pf->pdev->dev,
  9491. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  9492. pf->hw.func_caps.num_tx_qp,
  9493. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  9494. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  9495. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  9496. queues_left);
  9497. #ifdef I40E_FCOE
  9498. dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
  9499. #endif
  9500. }
  9501. /**
  9502. * i40e_setup_pf_filter_control - Setup PF static filter control
  9503. * @pf: PF to be setup
  9504. *
  9505. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  9506. * settings. If PE/FCoE are enabled then it will also set the per PF
  9507. * based filter sizes required for them. It also enables Flow director,
  9508. * ethertype and macvlan type filter settings for the pf.
  9509. *
  9510. * Returns 0 on success, negative on failure
  9511. **/
  9512. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  9513. {
  9514. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  9515. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  9516. /* Flow Director is enabled */
  9517. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  9518. settings->enable_fdir = true;
  9519. /* Ethtype and MACVLAN filters enabled for PF */
  9520. settings->enable_ethtype = true;
  9521. settings->enable_macvlan = true;
  9522. if (i40e_set_filter_control(&pf->hw, settings))
  9523. return -ENOENT;
  9524. return 0;
  9525. }
  9526. #define INFO_STRING_LEN 255
  9527. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  9528. static void i40e_print_features(struct i40e_pf *pf)
  9529. {
  9530. struct i40e_hw *hw = &pf->hw;
  9531. char *buf;
  9532. int i;
  9533. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  9534. if (!buf)
  9535. return;
  9536. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  9537. #ifdef CONFIG_PCI_IOV
  9538. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  9539. #endif
  9540. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  9541. pf->hw.func_caps.num_vsis,
  9542. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  9543. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  9544. i += snprintf(&buf[i], REMAIN(i), " RSS");
  9545. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  9546. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  9547. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9548. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  9549. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  9550. }
  9551. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  9552. i += snprintf(&buf[i], REMAIN(i), " DCB");
  9553. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  9554. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  9555. if (pf->flags & I40E_FLAG_PTP)
  9556. i += snprintf(&buf[i], REMAIN(i), " PTP");
  9557. #ifdef I40E_FCOE
  9558. if (pf->flags & I40E_FLAG_FCOE_ENABLED)
  9559. i += snprintf(&buf[i], REMAIN(i), " FCOE");
  9560. #endif
  9561. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  9562. i += snprintf(&buf[i], REMAIN(i), " VEB");
  9563. else
  9564. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  9565. dev_info(&pf->pdev->dev, "%s\n", buf);
  9566. kfree(buf);
  9567. WARN_ON(i > INFO_STRING_LEN);
  9568. }
  9569. /**
  9570. * i40e_get_platform_mac_addr - get platform-specific MAC address
  9571. *
  9572. * @pdev: PCI device information struct
  9573. * @pf: board private structure
  9574. *
  9575. * Look up the MAC address in Open Firmware on systems that support it,
  9576. * and use IDPROM on SPARC if no OF address is found. On return, the
  9577. * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
  9578. * has been selected.
  9579. **/
  9580. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  9581. {
  9582. pf->flags &= ~I40E_FLAG_PF_MAC;
  9583. if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  9584. pf->flags |= I40E_FLAG_PF_MAC;
  9585. }
  9586. /**
  9587. * i40e_probe - Device initialization routine
  9588. * @pdev: PCI device information struct
  9589. * @ent: entry in i40e_pci_tbl
  9590. *
  9591. * i40e_probe initializes a PF identified by a pci_dev structure.
  9592. * The OS initialization, configuring of the PF private structure,
  9593. * and a hardware reset occur.
  9594. *
  9595. * Returns 0 on success, negative on failure
  9596. **/
  9597. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9598. {
  9599. struct i40e_aq_get_phy_abilities_resp abilities;
  9600. struct i40e_pf *pf;
  9601. struct i40e_hw *hw;
  9602. static u16 pfs_found;
  9603. u16 wol_nvm_bits;
  9604. u16 link_status;
  9605. int err;
  9606. u32 val;
  9607. u32 i;
  9608. u8 set_fc_aq_fail;
  9609. err = pci_enable_device_mem(pdev);
  9610. if (err)
  9611. return err;
  9612. /* set up for high or low dma */
  9613. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  9614. if (err) {
  9615. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  9616. if (err) {
  9617. dev_err(&pdev->dev,
  9618. "DMA configuration failed: 0x%x\n", err);
  9619. goto err_dma;
  9620. }
  9621. }
  9622. /* set up pci connections */
  9623. err = pci_request_mem_regions(pdev, i40e_driver_name);
  9624. if (err) {
  9625. dev_info(&pdev->dev,
  9626. "pci_request_selected_regions failed %d\n", err);
  9627. goto err_pci_reg;
  9628. }
  9629. pci_enable_pcie_error_reporting(pdev);
  9630. pci_set_master(pdev);
  9631. /* Now that we have a PCI connection, we need to do the
  9632. * low level device setup. This is primarily setting up
  9633. * the Admin Queue structures and then querying for the
  9634. * device's current profile information.
  9635. */
  9636. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  9637. if (!pf) {
  9638. err = -ENOMEM;
  9639. goto err_pf_alloc;
  9640. }
  9641. pf->next_vsi = 0;
  9642. pf->pdev = pdev;
  9643. set_bit(__I40E_DOWN, &pf->state);
  9644. hw = &pf->hw;
  9645. hw->back = pf;
  9646. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  9647. I40E_MAX_CSR_SPACE);
  9648. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  9649. if (!hw->hw_addr) {
  9650. err = -EIO;
  9651. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  9652. (unsigned int)pci_resource_start(pdev, 0),
  9653. pf->ioremap_len, err);
  9654. goto err_ioremap;
  9655. }
  9656. hw->vendor_id = pdev->vendor;
  9657. hw->device_id = pdev->device;
  9658. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  9659. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  9660. hw->subsystem_device_id = pdev->subsystem_device;
  9661. hw->bus.device = PCI_SLOT(pdev->devfn);
  9662. hw->bus.func = PCI_FUNC(pdev->devfn);
  9663. pf->instance = pfs_found;
  9664. /* set up the locks for the AQ, do this only once in probe
  9665. * and destroy them only once in remove
  9666. */
  9667. mutex_init(&hw->aq.asq_mutex);
  9668. mutex_init(&hw->aq.arq_mutex);
  9669. pf->msg_enable = netif_msg_init(debug,
  9670. NETIF_MSG_DRV |
  9671. NETIF_MSG_PROBE |
  9672. NETIF_MSG_LINK);
  9673. if (debug < -1)
  9674. pf->hw.debug_mask = debug;
  9675. /* do a special CORER for clearing PXE mode once at init */
  9676. if (hw->revision_id == 0 &&
  9677. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  9678. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  9679. i40e_flush(hw);
  9680. msleep(200);
  9681. pf->corer_count++;
  9682. i40e_clear_pxe_mode(hw);
  9683. }
  9684. /* Reset here to make sure all is clean and to define PF 'n' */
  9685. i40e_clear_hw(hw);
  9686. err = i40e_pf_reset(hw);
  9687. if (err) {
  9688. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  9689. goto err_pf_reset;
  9690. }
  9691. pf->pfr_count++;
  9692. hw->aq.num_arq_entries = I40E_AQ_LEN;
  9693. hw->aq.num_asq_entries = I40E_AQ_LEN;
  9694. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9695. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9696. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  9697. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  9698. "%s-%s:misc",
  9699. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  9700. err = i40e_init_shared_code(hw);
  9701. if (err) {
  9702. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  9703. err);
  9704. goto err_pf_reset;
  9705. }
  9706. /* set up a default setting for link flow control */
  9707. pf->hw.fc.requested_mode = I40E_FC_NONE;
  9708. err = i40e_init_adminq(hw);
  9709. if (err) {
  9710. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  9711. dev_info(&pdev->dev,
  9712. "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");
  9713. else
  9714. dev_info(&pdev->dev,
  9715. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  9716. goto err_pf_reset;
  9717. }
  9718. /* provide nvm, fw, api versions */
  9719. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  9720. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  9721. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  9722. i40e_nvm_version_str(hw));
  9723. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  9724. hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
  9725. dev_info(&pdev->dev,
  9726. "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");
  9727. else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
  9728. hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
  9729. dev_info(&pdev->dev,
  9730. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  9731. i40e_verify_eeprom(pf);
  9732. /* Rev 0 hardware was never productized */
  9733. if (hw->revision_id < 1)
  9734. 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");
  9735. i40e_clear_pxe_mode(hw);
  9736. err = i40e_get_capabilities(pf);
  9737. if (err)
  9738. goto err_adminq_setup;
  9739. err = i40e_sw_init(pf);
  9740. if (err) {
  9741. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  9742. goto err_sw_init;
  9743. }
  9744. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  9745. hw->func_caps.num_rx_qp,
  9746. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  9747. if (err) {
  9748. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  9749. goto err_init_lan_hmc;
  9750. }
  9751. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  9752. if (err) {
  9753. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  9754. err = -ENOENT;
  9755. goto err_configure_lan_hmc;
  9756. }
  9757. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  9758. * Ignore error return codes because if it was already disabled via
  9759. * hardware settings this will fail
  9760. */
  9761. if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
  9762. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  9763. i40e_aq_stop_lldp(hw, true, NULL);
  9764. }
  9765. i40e_get_mac_addr(hw, hw->mac.addr);
  9766. /* allow a platform config to override the HW addr */
  9767. i40e_get_platform_mac_addr(pdev, pf);
  9768. if (!is_valid_ether_addr(hw->mac.addr)) {
  9769. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  9770. err = -EIO;
  9771. goto err_mac_addr;
  9772. }
  9773. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  9774. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  9775. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  9776. if (is_valid_ether_addr(hw->mac.port_addr))
  9777. pf->flags |= I40E_FLAG_PORT_ID_VALID;
  9778. #ifdef I40E_FCOE
  9779. err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
  9780. if (err)
  9781. dev_info(&pdev->dev,
  9782. "(non-fatal) SAN MAC retrieval failed: %d\n", err);
  9783. if (!is_valid_ether_addr(hw->mac.san_addr)) {
  9784. dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
  9785. hw->mac.san_addr);
  9786. ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
  9787. }
  9788. dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
  9789. #endif /* I40E_FCOE */
  9790. pci_set_drvdata(pdev, pf);
  9791. pci_save_state(pdev);
  9792. #ifdef CONFIG_I40E_DCB
  9793. err = i40e_init_pf_dcb(pf);
  9794. if (err) {
  9795. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  9796. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  9797. /* Continue without DCB enabled */
  9798. }
  9799. #endif /* CONFIG_I40E_DCB */
  9800. /* set up periodic task facility */
  9801. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  9802. pf->service_timer_period = HZ;
  9803. INIT_WORK(&pf->service_task, i40e_service_task);
  9804. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  9805. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  9806. /* NVM bit on means WoL disabled for the port */
  9807. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  9808. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  9809. pf->wol_en = false;
  9810. else
  9811. pf->wol_en = true;
  9812. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  9813. /* set up the main switch operations */
  9814. i40e_determine_queue_usage(pf);
  9815. err = i40e_init_interrupt_scheme(pf);
  9816. if (err)
  9817. goto err_switch_setup;
  9818. /* The number of VSIs reported by the FW is the minimum guaranteed
  9819. * to us; HW supports far more and we share the remaining pool with
  9820. * the other PFs. We allocate space for more than the guarantee with
  9821. * the understanding that we might not get them all later.
  9822. */
  9823. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  9824. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  9825. else
  9826. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  9827. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  9828. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  9829. GFP_KERNEL);
  9830. if (!pf->vsi) {
  9831. err = -ENOMEM;
  9832. goto err_switch_setup;
  9833. }
  9834. #ifdef CONFIG_PCI_IOV
  9835. /* prep for VF support */
  9836. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9837. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9838. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9839. if (pci_num_vf(pdev))
  9840. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  9841. }
  9842. #endif
  9843. err = i40e_setup_pf_switch(pf, false);
  9844. if (err) {
  9845. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  9846. goto err_vsis;
  9847. }
  9848. /* Make sure flow control is set according to current settings */
  9849. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  9850. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  9851. dev_dbg(&pf->pdev->dev,
  9852. "Set fc with err %s aq_err %s on get_phy_cap\n",
  9853. i40e_stat_str(hw, err),
  9854. i40e_aq_str(hw, hw->aq.asq_last_status));
  9855. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  9856. dev_dbg(&pf->pdev->dev,
  9857. "Set fc with err %s aq_err %s on set_phy_config\n",
  9858. i40e_stat_str(hw, err),
  9859. i40e_aq_str(hw, hw->aq.asq_last_status));
  9860. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  9861. dev_dbg(&pf->pdev->dev,
  9862. "Set fc with err %s aq_err %s on get_link_info\n",
  9863. i40e_stat_str(hw, err),
  9864. i40e_aq_str(hw, hw->aq.asq_last_status));
  9865. /* if FDIR VSI was set up, start it now */
  9866. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9867. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  9868. i40e_vsi_open(pf->vsi[i]);
  9869. break;
  9870. }
  9871. }
  9872. /* The driver only wants link up/down and module qualification
  9873. * reports from firmware. Note the negative logic.
  9874. */
  9875. err = i40e_aq_set_phy_int_mask(&pf->hw,
  9876. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  9877. I40E_AQ_EVENT_MEDIA_NA |
  9878. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  9879. if (err)
  9880. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  9881. i40e_stat_str(&pf->hw, err),
  9882. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9883. /* Reconfigure hardware for allowing smaller MSS in the case
  9884. * of TSO, so that we avoid the MDD being fired and causing
  9885. * a reset in the case of small MSS+TSO.
  9886. */
  9887. val = rd32(hw, I40E_REG_MSS);
  9888. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  9889. val &= ~I40E_REG_MSS_MIN_MASK;
  9890. val |= I40E_64BYTE_MSS;
  9891. wr32(hw, I40E_REG_MSS, val);
  9892. }
  9893. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  9894. msleep(75);
  9895. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  9896. if (err)
  9897. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  9898. i40e_stat_str(&pf->hw, err),
  9899. i40e_aq_str(&pf->hw,
  9900. pf->hw.aq.asq_last_status));
  9901. }
  9902. /* The main driver is (mostly) up and happy. We need to set this state
  9903. * before setting up the misc vector or we get a race and the vector
  9904. * ends up disabled forever.
  9905. */
  9906. clear_bit(__I40E_DOWN, &pf->state);
  9907. /* In case of MSIX we are going to setup the misc vector right here
  9908. * to handle admin queue events etc. In case of legacy and MSI
  9909. * the misc functionality and queue processing is combined in
  9910. * the same vector and that gets setup at open.
  9911. */
  9912. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9913. err = i40e_setup_misc_vector(pf);
  9914. if (err) {
  9915. dev_info(&pdev->dev,
  9916. "setup of misc vector failed: %d\n", err);
  9917. goto err_vsis;
  9918. }
  9919. }
  9920. #ifdef CONFIG_PCI_IOV
  9921. /* prep for VF support */
  9922. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9923. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9924. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9925. /* disable link interrupts for VFs */
  9926. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  9927. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  9928. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  9929. i40e_flush(hw);
  9930. if (pci_num_vf(pdev)) {
  9931. dev_info(&pdev->dev,
  9932. "Active VFs found, allocating resources.\n");
  9933. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  9934. if (err)
  9935. dev_info(&pdev->dev,
  9936. "Error %d allocating resources for existing VFs\n",
  9937. err);
  9938. }
  9939. }
  9940. #endif /* CONFIG_PCI_IOV */
  9941. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9942. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  9943. pf->num_iwarp_msix,
  9944. I40E_IWARP_IRQ_PILE_ID);
  9945. if (pf->iwarp_base_vector < 0) {
  9946. dev_info(&pdev->dev,
  9947. "failed to get tracking for %d vectors for IWARP err=%d\n",
  9948. pf->num_iwarp_msix, pf->iwarp_base_vector);
  9949. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9950. }
  9951. }
  9952. i40e_dbg_pf_init(pf);
  9953. /* tell the firmware that we're starting */
  9954. i40e_send_version(pf);
  9955. /* since everything's happy, start the service_task timer */
  9956. mod_timer(&pf->service_timer,
  9957. round_jiffies(jiffies + pf->service_timer_period));
  9958. /* add this PF to client device list and launch a client service task */
  9959. err = i40e_lan_add_device(pf);
  9960. if (err)
  9961. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  9962. err);
  9963. #ifdef I40E_FCOE
  9964. /* create FCoE interface */
  9965. i40e_fcoe_vsi_setup(pf);
  9966. #endif
  9967. #define PCI_SPEED_SIZE 8
  9968. #define PCI_WIDTH_SIZE 8
  9969. /* Devices on the IOSF bus do not have this information
  9970. * and will report PCI Gen 1 x 1 by default so don't bother
  9971. * checking them.
  9972. */
  9973. if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
  9974. char speed[PCI_SPEED_SIZE] = "Unknown";
  9975. char width[PCI_WIDTH_SIZE] = "Unknown";
  9976. /* Get the negotiated link width and speed from PCI config
  9977. * space
  9978. */
  9979. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  9980. &link_status);
  9981. i40e_set_pci_config_data(hw, link_status);
  9982. switch (hw->bus.speed) {
  9983. case i40e_bus_speed_8000:
  9984. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  9985. case i40e_bus_speed_5000:
  9986. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  9987. case i40e_bus_speed_2500:
  9988. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  9989. default:
  9990. break;
  9991. }
  9992. switch (hw->bus.width) {
  9993. case i40e_bus_width_pcie_x8:
  9994. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  9995. case i40e_bus_width_pcie_x4:
  9996. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  9997. case i40e_bus_width_pcie_x2:
  9998. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  9999. case i40e_bus_width_pcie_x1:
  10000. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  10001. default:
  10002. break;
  10003. }
  10004. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  10005. speed, width);
  10006. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  10007. hw->bus.speed < i40e_bus_speed_8000) {
  10008. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  10009. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  10010. }
  10011. }
  10012. /* get the requested speeds from the fw */
  10013. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  10014. if (err)
  10015. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  10016. i40e_stat_str(&pf->hw, err),
  10017. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10018. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  10019. /* get the supported phy types from the fw */
  10020. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  10021. if (err)
  10022. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  10023. i40e_stat_str(&pf->hw, err),
  10024. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10025. /* Add a filter to drop all Flow control frames from any VSI from being
  10026. * transmitted. By doing so we stop a malicious VF from sending out
  10027. * PAUSE or PFC frames and potentially controlling traffic for other
  10028. * PF/VF VSIs.
  10029. * The FW can still send Flow control frames if enabled.
  10030. */
  10031. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  10032. pf->main_vsi_seid);
  10033. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  10034. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  10035. pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS;
  10036. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  10037. pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER;
  10038. /* print a string summarizing features */
  10039. i40e_print_features(pf);
  10040. return 0;
  10041. /* Unwind what we've done if something failed in the setup */
  10042. err_vsis:
  10043. set_bit(__I40E_DOWN, &pf->state);
  10044. i40e_clear_interrupt_scheme(pf);
  10045. kfree(pf->vsi);
  10046. err_switch_setup:
  10047. i40e_reset_interrupt_capability(pf);
  10048. del_timer_sync(&pf->service_timer);
  10049. err_mac_addr:
  10050. err_configure_lan_hmc:
  10051. (void)i40e_shutdown_lan_hmc(hw);
  10052. err_init_lan_hmc:
  10053. kfree(pf->qp_pile);
  10054. err_sw_init:
  10055. err_adminq_setup:
  10056. err_pf_reset:
  10057. iounmap(hw->hw_addr);
  10058. err_ioremap:
  10059. kfree(pf);
  10060. err_pf_alloc:
  10061. pci_disable_pcie_error_reporting(pdev);
  10062. pci_release_mem_regions(pdev);
  10063. err_pci_reg:
  10064. err_dma:
  10065. pci_disable_device(pdev);
  10066. return err;
  10067. }
  10068. /**
  10069. * i40e_remove - Device removal routine
  10070. * @pdev: PCI device information struct
  10071. *
  10072. * i40e_remove is called by the PCI subsystem to alert the driver
  10073. * that is should release a PCI device. This could be caused by a
  10074. * Hot-Plug event, or because the driver is going to be removed from
  10075. * memory.
  10076. **/
  10077. static void i40e_remove(struct pci_dev *pdev)
  10078. {
  10079. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10080. struct i40e_hw *hw = &pf->hw;
  10081. i40e_status ret_code;
  10082. int i;
  10083. i40e_dbg_pf_exit(pf);
  10084. i40e_ptp_stop(pf);
  10085. /* Disable RSS in hw */
  10086. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  10087. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  10088. /* no more scheduling of any task */
  10089. set_bit(__I40E_SUSPENDED, &pf->state);
  10090. set_bit(__I40E_DOWN, &pf->state);
  10091. if (pf->service_timer.data)
  10092. del_timer_sync(&pf->service_timer);
  10093. if (pf->service_task.func)
  10094. cancel_work_sync(&pf->service_task);
  10095. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  10096. i40e_free_vfs(pf);
  10097. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  10098. }
  10099. i40e_fdir_teardown(pf);
  10100. /* If there is a switch structure or any orphans, remove them.
  10101. * This will leave only the PF's VSI remaining.
  10102. */
  10103. for (i = 0; i < I40E_MAX_VEB; i++) {
  10104. if (!pf->veb[i])
  10105. continue;
  10106. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  10107. pf->veb[i]->uplink_seid == 0)
  10108. i40e_switch_branch_release(pf->veb[i]);
  10109. }
  10110. /* Now we can shutdown the PF's VSI, just before we kill
  10111. * adminq and hmc.
  10112. */
  10113. if (pf->vsi[pf->lan_vsi])
  10114. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  10115. /* remove attached clients */
  10116. ret_code = i40e_lan_del_device(pf);
  10117. if (ret_code) {
  10118. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  10119. ret_code);
  10120. }
  10121. /* shutdown and destroy the HMC */
  10122. if (hw->hmc.hmc_obj) {
  10123. ret_code = i40e_shutdown_lan_hmc(hw);
  10124. if (ret_code)
  10125. dev_warn(&pdev->dev,
  10126. "Failed to destroy the HMC resources: %d\n",
  10127. ret_code);
  10128. }
  10129. /* shutdown the adminq */
  10130. i40e_shutdown_adminq(hw);
  10131. /* destroy the locks only once, here */
  10132. mutex_destroy(&hw->aq.arq_mutex);
  10133. mutex_destroy(&hw->aq.asq_mutex);
  10134. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  10135. i40e_clear_interrupt_scheme(pf);
  10136. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10137. if (pf->vsi[i]) {
  10138. i40e_vsi_clear_rings(pf->vsi[i]);
  10139. i40e_vsi_clear(pf->vsi[i]);
  10140. pf->vsi[i] = NULL;
  10141. }
  10142. }
  10143. for (i = 0; i < I40E_MAX_VEB; i++) {
  10144. kfree(pf->veb[i]);
  10145. pf->veb[i] = NULL;
  10146. }
  10147. kfree(pf->qp_pile);
  10148. kfree(pf->vsi);
  10149. iounmap(hw->hw_addr);
  10150. kfree(pf);
  10151. pci_release_mem_regions(pdev);
  10152. pci_disable_pcie_error_reporting(pdev);
  10153. pci_disable_device(pdev);
  10154. }
  10155. /**
  10156. * i40e_pci_error_detected - warning that something funky happened in PCI land
  10157. * @pdev: PCI device information struct
  10158. *
  10159. * Called to warn that something happened and the error handling steps
  10160. * are in progress. Allows the driver to quiesce things, be ready for
  10161. * remediation.
  10162. **/
  10163. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  10164. enum pci_channel_state error)
  10165. {
  10166. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10167. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  10168. if (!pf) {
  10169. dev_info(&pdev->dev,
  10170. "Cannot recover - error happened during device probe\n");
  10171. return PCI_ERS_RESULT_DISCONNECT;
  10172. }
  10173. /* shutdown all operations */
  10174. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  10175. rtnl_lock();
  10176. i40e_prep_for_reset(pf);
  10177. rtnl_unlock();
  10178. }
  10179. /* Request a slot reset */
  10180. return PCI_ERS_RESULT_NEED_RESET;
  10181. }
  10182. /**
  10183. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  10184. * @pdev: PCI device information struct
  10185. *
  10186. * Called to find if the driver can work with the device now that
  10187. * the pci slot has been reset. If a basic connection seems good
  10188. * (registers are readable and have sane content) then return a
  10189. * happy little PCI_ERS_RESULT_xxx.
  10190. **/
  10191. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  10192. {
  10193. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10194. pci_ers_result_t result;
  10195. int err;
  10196. u32 reg;
  10197. dev_dbg(&pdev->dev, "%s\n", __func__);
  10198. if (pci_enable_device_mem(pdev)) {
  10199. dev_info(&pdev->dev,
  10200. "Cannot re-enable PCI device after reset.\n");
  10201. result = PCI_ERS_RESULT_DISCONNECT;
  10202. } else {
  10203. pci_set_master(pdev);
  10204. pci_restore_state(pdev);
  10205. pci_save_state(pdev);
  10206. pci_wake_from_d3(pdev, false);
  10207. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  10208. if (reg == 0)
  10209. result = PCI_ERS_RESULT_RECOVERED;
  10210. else
  10211. result = PCI_ERS_RESULT_DISCONNECT;
  10212. }
  10213. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  10214. if (err) {
  10215. dev_info(&pdev->dev,
  10216. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  10217. err);
  10218. /* non-fatal, continue */
  10219. }
  10220. return result;
  10221. }
  10222. /**
  10223. * i40e_pci_error_resume - restart operations after PCI error recovery
  10224. * @pdev: PCI device information struct
  10225. *
  10226. * Called to allow the driver to bring things back up after PCI error
  10227. * and/or reset recovery has finished.
  10228. **/
  10229. static void i40e_pci_error_resume(struct pci_dev *pdev)
  10230. {
  10231. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10232. dev_dbg(&pdev->dev, "%s\n", __func__);
  10233. if (test_bit(__I40E_SUSPENDED, &pf->state))
  10234. return;
  10235. rtnl_lock();
  10236. i40e_handle_reset_warning(pf);
  10237. rtnl_unlock();
  10238. }
  10239. /**
  10240. * i40e_shutdown - PCI callback for shutting down
  10241. * @pdev: PCI device information struct
  10242. **/
  10243. static void i40e_shutdown(struct pci_dev *pdev)
  10244. {
  10245. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10246. struct i40e_hw *hw = &pf->hw;
  10247. set_bit(__I40E_SUSPENDED, &pf->state);
  10248. set_bit(__I40E_DOWN, &pf->state);
  10249. rtnl_lock();
  10250. i40e_prep_for_reset(pf);
  10251. rtnl_unlock();
  10252. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10253. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10254. del_timer_sync(&pf->service_timer);
  10255. cancel_work_sync(&pf->service_task);
  10256. i40e_fdir_teardown(pf);
  10257. rtnl_lock();
  10258. i40e_prep_for_reset(pf);
  10259. rtnl_unlock();
  10260. wr32(hw, I40E_PFPM_APM,
  10261. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10262. wr32(hw, I40E_PFPM_WUFC,
  10263. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10264. i40e_clear_interrupt_scheme(pf);
  10265. if (system_state == SYSTEM_POWER_OFF) {
  10266. pci_wake_from_d3(pdev, pf->wol_en);
  10267. pci_set_power_state(pdev, PCI_D3hot);
  10268. }
  10269. }
  10270. #ifdef CONFIG_PM
  10271. /**
  10272. * i40e_suspend - PCI callback for moving to D3
  10273. * @pdev: PCI device information struct
  10274. **/
  10275. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  10276. {
  10277. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10278. struct i40e_hw *hw = &pf->hw;
  10279. int retval = 0;
  10280. set_bit(__I40E_SUSPENDED, &pf->state);
  10281. set_bit(__I40E_DOWN, &pf->state);
  10282. rtnl_lock();
  10283. i40e_prep_for_reset(pf);
  10284. rtnl_unlock();
  10285. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10286. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10287. i40e_stop_misc_vector(pf);
  10288. retval = pci_save_state(pdev);
  10289. if (retval)
  10290. return retval;
  10291. pci_wake_from_d3(pdev, pf->wol_en);
  10292. pci_set_power_state(pdev, PCI_D3hot);
  10293. return retval;
  10294. }
  10295. /**
  10296. * i40e_resume - PCI callback for waking up from D3
  10297. * @pdev: PCI device information struct
  10298. **/
  10299. static int i40e_resume(struct pci_dev *pdev)
  10300. {
  10301. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10302. u32 err;
  10303. pci_set_power_state(pdev, PCI_D0);
  10304. pci_restore_state(pdev);
  10305. /* pci_restore_state() clears dev->state_saves, so
  10306. * call pci_save_state() again to restore it.
  10307. */
  10308. pci_save_state(pdev);
  10309. err = pci_enable_device_mem(pdev);
  10310. if (err) {
  10311. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  10312. return err;
  10313. }
  10314. pci_set_master(pdev);
  10315. /* no wakeup events while running */
  10316. pci_wake_from_d3(pdev, false);
  10317. /* handling the reset will rebuild the device state */
  10318. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  10319. clear_bit(__I40E_DOWN, &pf->state);
  10320. rtnl_lock();
  10321. i40e_reset_and_rebuild(pf, false);
  10322. rtnl_unlock();
  10323. }
  10324. return 0;
  10325. }
  10326. #endif
  10327. static const struct pci_error_handlers i40e_err_handler = {
  10328. .error_detected = i40e_pci_error_detected,
  10329. .slot_reset = i40e_pci_error_slot_reset,
  10330. .resume = i40e_pci_error_resume,
  10331. };
  10332. static struct pci_driver i40e_driver = {
  10333. .name = i40e_driver_name,
  10334. .id_table = i40e_pci_tbl,
  10335. .probe = i40e_probe,
  10336. .remove = i40e_remove,
  10337. #ifdef CONFIG_PM
  10338. .suspend = i40e_suspend,
  10339. .resume = i40e_resume,
  10340. #endif
  10341. .shutdown = i40e_shutdown,
  10342. .err_handler = &i40e_err_handler,
  10343. .sriov_configure = i40e_pci_sriov_configure,
  10344. };
  10345. /**
  10346. * i40e_init_module - Driver registration routine
  10347. *
  10348. * i40e_init_module is the first routine called when the driver is
  10349. * loaded. All it does is register with the PCI subsystem.
  10350. **/
  10351. static int __init i40e_init_module(void)
  10352. {
  10353. pr_info("%s: %s - version %s\n", i40e_driver_name,
  10354. i40e_driver_string, i40e_driver_version_str);
  10355. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  10356. /* we will see if single thread per module is enough for now,
  10357. * it can't be any worse than using the system workqueue which
  10358. * was already single threaded
  10359. */
  10360. i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  10361. i40e_driver_name);
  10362. if (!i40e_wq) {
  10363. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  10364. return -ENOMEM;
  10365. }
  10366. i40e_dbg_init();
  10367. return pci_register_driver(&i40e_driver);
  10368. }
  10369. module_init(i40e_init_module);
  10370. /**
  10371. * i40e_exit_module - Driver exit cleanup routine
  10372. *
  10373. * i40e_exit_module is called just before the driver is removed
  10374. * from memory.
  10375. **/
  10376. static void __exit i40e_exit_module(void)
  10377. {
  10378. pci_unregister_driver(&i40e_driver);
  10379. destroy_workqueue(i40e_wq);
  10380. i40e_dbg_exit();
  10381. }
  10382. module_exit(i40e_exit_module);