i40e_main.c 316 KB

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