ixgbe_main.c 306 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include <linux/types.h>
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/netdevice.h>
  7. #include <linux/vmalloc.h>
  8. #include <linux/string.h>
  9. #include <linux/in.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/ip.h>
  12. #include <linux/tcp.h>
  13. #include <linux/sctp.h>
  14. #include <linux/pkt_sched.h>
  15. #include <linux/ipv6.h>
  16. #include <linux/slab.h>
  17. #include <net/checksum.h>
  18. #include <net/ip6_checksum.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/if.h>
  22. #include <linux/if_vlan.h>
  23. #include <linux/if_macvlan.h>
  24. #include <linux/if_bridge.h>
  25. #include <linux/prefetch.h>
  26. #include <linux/bpf.h>
  27. #include <linux/bpf_trace.h>
  28. #include <linux/atomic.h>
  29. #include <scsi/fc/fc_fcoe.h>
  30. #include <net/udp_tunnel.h>
  31. #include <net/pkt_cls.h>
  32. #include <net/tc_act/tc_gact.h>
  33. #include <net/tc_act/tc_mirred.h>
  34. #include <net/vxlan.h>
  35. #include <net/mpls.h>
  36. #include "ixgbe.h"
  37. #include "ixgbe_common.h"
  38. #include "ixgbe_dcb_82599.h"
  39. #include "ixgbe_sriov.h"
  40. #include "ixgbe_model.h"
  41. char ixgbe_driver_name[] = "ixgbe";
  42. static const char ixgbe_driver_string[] =
  43. "Intel(R) 10 Gigabit PCI Express Network Driver";
  44. #ifdef IXGBE_FCOE
  45. char ixgbe_default_device_descr[] =
  46. "Intel(R) 10 Gigabit Network Connection";
  47. #else
  48. static char ixgbe_default_device_descr[] =
  49. "Intel(R) 10 Gigabit Network Connection";
  50. #endif
  51. #define DRV_VERSION "5.1.0-k"
  52. const char ixgbe_driver_version[] = DRV_VERSION;
  53. static const char ixgbe_copyright[] =
  54. "Copyright (c) 1999-2016 Intel Corporation.";
  55. static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
  56. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  57. [board_82598] = &ixgbe_82598_info,
  58. [board_82599] = &ixgbe_82599_info,
  59. [board_X540] = &ixgbe_X540_info,
  60. [board_X550] = &ixgbe_X550_info,
  61. [board_X550EM_x] = &ixgbe_X550EM_x_info,
  62. [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info,
  63. [board_x550em_a] = &ixgbe_x550em_a_info,
  64. [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
  65. };
  66. /* ixgbe_pci_tbl - PCI Device ID Table
  67. *
  68. * Wildcard entries (PCI_ANY_ID) should come last
  69. * Last entry must be all 0s
  70. *
  71. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  72. * Class, Class Mask, private data (not used) }
  73. */
  74. static const struct pci_device_id ixgbe_pci_tbl[] = {
  75. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  77. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  79. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  81. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  83. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  85. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  87. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  89. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  103. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  104. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  105. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
  106. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
  107. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
  108. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
  109. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
  110. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
  111. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
  112. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw},
  113. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
  114. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
  115. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
  116. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
  117. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
  118. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
  119. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
  120. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
  121. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
  122. /* required last entry */
  123. {0, }
  124. };
  125. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  126. #ifdef CONFIG_IXGBE_DCA
  127. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  128. void *p);
  129. static struct notifier_block dca_notifier = {
  130. .notifier_call = ixgbe_notify_dca,
  131. .next = NULL,
  132. .priority = 0
  133. };
  134. #endif
  135. #ifdef CONFIG_PCI_IOV
  136. static unsigned int max_vfs;
  137. module_param(max_vfs, uint, 0);
  138. MODULE_PARM_DESC(max_vfs,
  139. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
  140. #endif /* CONFIG_PCI_IOV */
  141. static unsigned int allow_unsupported_sfp;
  142. module_param(allow_unsupported_sfp, uint, 0);
  143. MODULE_PARM_DESC(allow_unsupported_sfp,
  144. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  145. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  146. static int debug = -1;
  147. module_param(debug, int, 0);
  148. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  149. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  150. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  151. MODULE_LICENSE("GPL");
  152. MODULE_VERSION(DRV_VERSION);
  153. static struct workqueue_struct *ixgbe_wq;
  154. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
  155. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
  156. static const struct net_device_ops ixgbe_netdev_ops;
  157. static bool netif_is_ixgbe(struct net_device *dev)
  158. {
  159. return dev && (dev->netdev_ops == &ixgbe_netdev_ops);
  160. }
  161. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  162. u32 reg, u16 *value)
  163. {
  164. struct pci_dev *parent_dev;
  165. struct pci_bus *parent_bus;
  166. parent_bus = adapter->pdev->bus->parent;
  167. if (!parent_bus)
  168. return -1;
  169. parent_dev = parent_bus->self;
  170. if (!parent_dev)
  171. return -1;
  172. if (!pci_is_pcie(parent_dev))
  173. return -1;
  174. pcie_capability_read_word(parent_dev, reg, value);
  175. if (*value == IXGBE_FAILED_READ_CFG_WORD &&
  176. ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
  177. return -1;
  178. return 0;
  179. }
  180. static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  181. {
  182. struct ixgbe_hw *hw = &adapter->hw;
  183. u16 link_status = 0;
  184. int err;
  185. hw->bus.type = ixgbe_bus_type_pci_express;
  186. /* Get the negotiated link width and speed from PCI config space of the
  187. * parent, as this device is behind a switch
  188. */
  189. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  190. /* assume caller will handle error case */
  191. if (err)
  192. return err;
  193. hw->bus.width = ixgbe_convert_bus_width(link_status);
  194. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  195. return 0;
  196. }
  197. /**
  198. * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
  199. * @hw: hw specific details
  200. *
  201. * This function is used by probe to determine whether a device's PCI-Express
  202. * bandwidth details should be gathered from the parent bus instead of from the
  203. * device. Used to ensure that various locations all have the correct device ID
  204. * checks.
  205. */
  206. static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
  207. {
  208. switch (hw->device_id) {
  209. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  210. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  211. return true;
  212. default:
  213. return false;
  214. }
  215. }
  216. static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
  217. int expected_gts)
  218. {
  219. struct ixgbe_hw *hw = &adapter->hw;
  220. struct pci_dev *pdev;
  221. /* Some devices are not connected over PCIe and thus do not negotiate
  222. * speed. These devices do not have valid bus info, and thus any report
  223. * we generate may not be correct.
  224. */
  225. if (hw->bus.type == ixgbe_bus_type_internal)
  226. return;
  227. /* determine whether to use the parent device */
  228. if (ixgbe_pcie_from_parent(&adapter->hw))
  229. pdev = adapter->pdev->bus->parent->self;
  230. else
  231. pdev = adapter->pdev;
  232. pcie_print_link_status(pdev);
  233. }
  234. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  235. {
  236. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  237. !test_bit(__IXGBE_REMOVING, &adapter->state) &&
  238. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  239. queue_work(ixgbe_wq, &adapter->service_task);
  240. }
  241. static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
  242. {
  243. struct ixgbe_adapter *adapter = hw->back;
  244. if (!hw->hw_addr)
  245. return;
  246. hw->hw_addr = NULL;
  247. e_dev_err("Adapter removed\n");
  248. if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  249. ixgbe_service_event_schedule(adapter);
  250. }
  251. static u32 ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
  252. {
  253. u8 __iomem *reg_addr;
  254. u32 value;
  255. int i;
  256. reg_addr = READ_ONCE(hw->hw_addr);
  257. if (ixgbe_removed(reg_addr))
  258. return IXGBE_FAILED_READ_REG;
  259. /* Register read of 0xFFFFFFF can indicate the adapter has been removed,
  260. * so perform several status register reads to determine if the adapter
  261. * has been removed.
  262. */
  263. for (i = 0; i < IXGBE_FAILED_READ_RETRIES; i++) {
  264. value = readl(reg_addr + IXGBE_STATUS);
  265. if (value != IXGBE_FAILED_READ_REG)
  266. break;
  267. mdelay(3);
  268. }
  269. if (value == IXGBE_FAILED_READ_REG)
  270. ixgbe_remove_adapter(hw);
  271. else
  272. value = readl(reg_addr + reg);
  273. return value;
  274. }
  275. /**
  276. * ixgbe_read_reg - Read from device register
  277. * @hw: hw specific details
  278. * @reg: offset of register to read
  279. *
  280. * Returns : value read or IXGBE_FAILED_READ_REG if removed
  281. *
  282. * This function is used to read device registers. It checks for device
  283. * removal by confirming any read that returns all ones by checking the
  284. * status register value for all ones. This function avoids reading from
  285. * the hardware if a removal was previously detected in which case it
  286. * returns IXGBE_FAILED_READ_REG (all ones).
  287. */
  288. u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
  289. {
  290. u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
  291. u32 value;
  292. if (ixgbe_removed(reg_addr))
  293. return IXGBE_FAILED_READ_REG;
  294. if (unlikely(hw->phy.nw_mng_if_sel &
  295. IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
  296. struct ixgbe_adapter *adapter;
  297. int i;
  298. for (i = 0; i < 200; ++i) {
  299. value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
  300. if (likely(!value))
  301. goto writes_completed;
  302. if (value == IXGBE_FAILED_READ_REG) {
  303. ixgbe_remove_adapter(hw);
  304. return IXGBE_FAILED_READ_REG;
  305. }
  306. udelay(5);
  307. }
  308. adapter = hw->back;
  309. e_warn(hw, "register writes incomplete %08x\n", value);
  310. }
  311. writes_completed:
  312. value = readl(reg_addr + reg);
  313. if (unlikely(value == IXGBE_FAILED_READ_REG))
  314. value = ixgbe_check_remove(hw, reg);
  315. return value;
  316. }
  317. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
  318. {
  319. u16 value;
  320. pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
  321. if (value == IXGBE_FAILED_READ_CFG_WORD) {
  322. ixgbe_remove_adapter(hw);
  323. return true;
  324. }
  325. return false;
  326. }
  327. u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
  328. {
  329. struct ixgbe_adapter *adapter = hw->back;
  330. u16 value;
  331. if (ixgbe_removed(hw->hw_addr))
  332. return IXGBE_FAILED_READ_CFG_WORD;
  333. pci_read_config_word(adapter->pdev, reg, &value);
  334. if (value == IXGBE_FAILED_READ_CFG_WORD &&
  335. ixgbe_check_cfg_remove(hw, adapter->pdev))
  336. return IXGBE_FAILED_READ_CFG_WORD;
  337. return value;
  338. }
  339. #ifdef CONFIG_PCI_IOV
  340. static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
  341. {
  342. struct ixgbe_adapter *adapter = hw->back;
  343. u32 value;
  344. if (ixgbe_removed(hw->hw_addr))
  345. return IXGBE_FAILED_READ_CFG_DWORD;
  346. pci_read_config_dword(adapter->pdev, reg, &value);
  347. if (value == IXGBE_FAILED_READ_CFG_DWORD &&
  348. ixgbe_check_cfg_remove(hw, adapter->pdev))
  349. return IXGBE_FAILED_READ_CFG_DWORD;
  350. return value;
  351. }
  352. #endif /* CONFIG_PCI_IOV */
  353. void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
  354. {
  355. struct ixgbe_adapter *adapter = hw->back;
  356. if (ixgbe_removed(hw->hw_addr))
  357. return;
  358. pci_write_config_word(adapter->pdev, reg, value);
  359. }
  360. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  361. {
  362. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  363. /* flush memory to make sure state is correct before next watchdog */
  364. smp_mb__before_atomic();
  365. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  366. }
  367. struct ixgbe_reg_info {
  368. u32 ofs;
  369. char *name;
  370. };
  371. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  372. /* General Registers */
  373. {IXGBE_CTRL, "CTRL"},
  374. {IXGBE_STATUS, "STATUS"},
  375. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  376. /* Interrupt Registers */
  377. {IXGBE_EICR, "EICR"},
  378. /* RX Registers */
  379. {IXGBE_SRRCTL(0), "SRRCTL"},
  380. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  381. {IXGBE_RDLEN(0), "RDLEN"},
  382. {IXGBE_RDH(0), "RDH"},
  383. {IXGBE_RDT(0), "RDT"},
  384. {IXGBE_RXDCTL(0), "RXDCTL"},
  385. {IXGBE_RDBAL(0), "RDBAL"},
  386. {IXGBE_RDBAH(0), "RDBAH"},
  387. /* TX Registers */
  388. {IXGBE_TDBAL(0), "TDBAL"},
  389. {IXGBE_TDBAH(0), "TDBAH"},
  390. {IXGBE_TDLEN(0), "TDLEN"},
  391. {IXGBE_TDH(0), "TDH"},
  392. {IXGBE_TDT(0), "TDT"},
  393. {IXGBE_TXDCTL(0), "TXDCTL"},
  394. /* List Terminator */
  395. { .name = NULL }
  396. };
  397. /*
  398. * ixgbe_regdump - register printout routine
  399. */
  400. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  401. {
  402. int i;
  403. char rname[16];
  404. u32 regs[64];
  405. switch (reginfo->ofs) {
  406. case IXGBE_SRRCTL(0):
  407. for (i = 0; i < 64; i++)
  408. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  409. break;
  410. case IXGBE_DCA_RXCTRL(0):
  411. for (i = 0; i < 64; i++)
  412. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  413. break;
  414. case IXGBE_RDLEN(0):
  415. for (i = 0; i < 64; i++)
  416. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  417. break;
  418. case IXGBE_RDH(0):
  419. for (i = 0; i < 64; i++)
  420. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  421. break;
  422. case IXGBE_RDT(0):
  423. for (i = 0; i < 64; i++)
  424. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  425. break;
  426. case IXGBE_RXDCTL(0):
  427. for (i = 0; i < 64; i++)
  428. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  429. break;
  430. case IXGBE_RDBAL(0):
  431. for (i = 0; i < 64; i++)
  432. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  433. break;
  434. case IXGBE_RDBAH(0):
  435. for (i = 0; i < 64; i++)
  436. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  437. break;
  438. case IXGBE_TDBAL(0):
  439. for (i = 0; i < 64; i++)
  440. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  441. break;
  442. case IXGBE_TDBAH(0):
  443. for (i = 0; i < 64; i++)
  444. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  445. break;
  446. case IXGBE_TDLEN(0):
  447. for (i = 0; i < 64; i++)
  448. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  449. break;
  450. case IXGBE_TDH(0):
  451. for (i = 0; i < 64; i++)
  452. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  453. break;
  454. case IXGBE_TDT(0):
  455. for (i = 0; i < 64; i++)
  456. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  457. break;
  458. case IXGBE_TXDCTL(0):
  459. for (i = 0; i < 64; i++)
  460. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  461. break;
  462. default:
  463. pr_info("%-15s %08x\n",
  464. reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
  465. return;
  466. }
  467. i = 0;
  468. while (i < 64) {
  469. int j;
  470. char buf[9 * 8 + 1];
  471. char *p = buf;
  472. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
  473. for (j = 0; j < 8; j++)
  474. p += sprintf(p, " %08x", regs[i++]);
  475. pr_err("%-15s%s\n", rname, buf);
  476. }
  477. }
  478. static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
  479. {
  480. struct ixgbe_tx_buffer *tx_buffer;
  481. tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
  482. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  483. n, ring->next_to_use, ring->next_to_clean,
  484. (u64)dma_unmap_addr(tx_buffer, dma),
  485. dma_unmap_len(tx_buffer, len),
  486. tx_buffer->next_to_watch,
  487. (u64)tx_buffer->time_stamp);
  488. }
  489. /*
  490. * ixgbe_dump - Print registers, tx-rings and rx-rings
  491. */
  492. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  493. {
  494. struct net_device *netdev = adapter->netdev;
  495. struct ixgbe_hw *hw = &adapter->hw;
  496. struct ixgbe_reg_info *reginfo;
  497. int n = 0;
  498. struct ixgbe_ring *ring;
  499. struct ixgbe_tx_buffer *tx_buffer;
  500. union ixgbe_adv_tx_desc *tx_desc;
  501. struct my_u0 { u64 a; u64 b; } *u0;
  502. struct ixgbe_ring *rx_ring;
  503. union ixgbe_adv_rx_desc *rx_desc;
  504. struct ixgbe_rx_buffer *rx_buffer_info;
  505. int i = 0;
  506. if (!netif_msg_hw(adapter))
  507. return;
  508. /* Print netdevice Info */
  509. if (netdev) {
  510. dev_info(&adapter->pdev->dev, "Net device Info\n");
  511. pr_info("Device Name state "
  512. "trans_start\n");
  513. pr_info("%-15s %016lX %016lX\n",
  514. netdev->name,
  515. netdev->state,
  516. dev_trans_start(netdev));
  517. }
  518. /* Print Registers */
  519. dev_info(&adapter->pdev->dev, "Register Dump\n");
  520. pr_info(" Register Name Value\n");
  521. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  522. reginfo->name; reginfo++) {
  523. ixgbe_regdump(hw, reginfo);
  524. }
  525. /* Print TX Ring Summary */
  526. if (!netdev || !netif_running(netdev))
  527. return;
  528. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  529. pr_info(" %s %s %s %s\n",
  530. "Queue [NTU] [NTC] [bi(ntc)->dma ]",
  531. "leng", "ntw", "timestamp");
  532. for (n = 0; n < adapter->num_tx_queues; n++) {
  533. ring = adapter->tx_ring[n];
  534. ixgbe_print_buffer(ring, n);
  535. }
  536. for (n = 0; n < adapter->num_xdp_queues; n++) {
  537. ring = adapter->xdp_ring[n];
  538. ixgbe_print_buffer(ring, n);
  539. }
  540. /* Print TX Rings */
  541. if (!netif_msg_tx_done(adapter))
  542. goto rx_ring_summary;
  543. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  544. /* Transmit Descriptor Formats
  545. *
  546. * 82598 Advanced Transmit Descriptor
  547. * +--------------------------------------------------------------+
  548. * 0 | Buffer Address [63:0] |
  549. * +--------------------------------------------------------------+
  550. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  551. * +--------------------------------------------------------------+
  552. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  553. *
  554. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  555. * +--------------------------------------------------------------+
  556. * 0 | RSV [63:0] |
  557. * +--------------------------------------------------------------+
  558. * 8 | RSV | STA | NXTSEQ |
  559. * +--------------------------------------------------------------+
  560. * 63 36 35 32 31 0
  561. *
  562. * 82599+ Advanced Transmit Descriptor
  563. * +--------------------------------------------------------------+
  564. * 0 | Buffer Address [63:0] |
  565. * +--------------------------------------------------------------+
  566. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  567. * +--------------------------------------------------------------+
  568. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  569. *
  570. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  571. * +--------------------------------------------------------------+
  572. * 0 | RSV [63:0] |
  573. * +--------------------------------------------------------------+
  574. * 8 | RSV | STA | RSV |
  575. * +--------------------------------------------------------------+
  576. * 63 36 35 32 31 0
  577. */
  578. for (n = 0; n < adapter->num_tx_queues; n++) {
  579. ring = adapter->tx_ring[n];
  580. pr_info("------------------------------------\n");
  581. pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
  582. pr_info("------------------------------------\n");
  583. pr_info("%s%s %s %s %s %s\n",
  584. "T [desc] [address 63:0 ] ",
  585. "[PlPOIdStDDt Ln] [bi->dma ] ",
  586. "leng", "ntw", "timestamp", "bi->skb");
  587. for (i = 0; ring->desc && (i < ring->count); i++) {
  588. tx_desc = IXGBE_TX_DESC(ring, i);
  589. tx_buffer = &ring->tx_buffer_info[i];
  590. u0 = (struct my_u0 *)tx_desc;
  591. if (dma_unmap_len(tx_buffer, len) > 0) {
  592. const char *ring_desc;
  593. if (i == ring->next_to_use &&
  594. i == ring->next_to_clean)
  595. ring_desc = " NTC/U";
  596. else if (i == ring->next_to_use)
  597. ring_desc = " NTU";
  598. else if (i == ring->next_to_clean)
  599. ring_desc = " NTC";
  600. else
  601. ring_desc = "";
  602. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
  603. i,
  604. le64_to_cpu((__force __le64)u0->a),
  605. le64_to_cpu((__force __le64)u0->b),
  606. (u64)dma_unmap_addr(tx_buffer, dma),
  607. dma_unmap_len(tx_buffer, len),
  608. tx_buffer->next_to_watch,
  609. (u64)tx_buffer->time_stamp,
  610. tx_buffer->skb,
  611. ring_desc);
  612. if (netif_msg_pktdata(adapter) &&
  613. tx_buffer->skb)
  614. print_hex_dump(KERN_INFO, "",
  615. DUMP_PREFIX_ADDRESS, 16, 1,
  616. tx_buffer->skb->data,
  617. dma_unmap_len(tx_buffer, len),
  618. true);
  619. }
  620. }
  621. }
  622. /* Print RX Rings Summary */
  623. rx_ring_summary:
  624. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  625. pr_info("Queue [NTU] [NTC]\n");
  626. for (n = 0; n < adapter->num_rx_queues; n++) {
  627. rx_ring = adapter->rx_ring[n];
  628. pr_info("%5d %5X %5X\n",
  629. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  630. }
  631. /* Print RX Rings */
  632. if (!netif_msg_rx_status(adapter))
  633. return;
  634. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  635. /* Receive Descriptor Formats
  636. *
  637. * 82598 Advanced Receive Descriptor (Read) Format
  638. * 63 1 0
  639. * +-----------------------------------------------------+
  640. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  641. * +----------------------------------------------+------+
  642. * 8 | Header Buffer Address [63:1] | DD |
  643. * +-----------------------------------------------------+
  644. *
  645. *
  646. * 82598 Advanced Receive Descriptor (Write-Back) Format
  647. *
  648. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  649. * +------------------------------------------------------+
  650. * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
  651. * | Packet | IP | | | | Type | Type |
  652. * | Checksum | Ident | | | | | |
  653. * +------------------------------------------------------+
  654. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  655. * +------------------------------------------------------+
  656. * 63 48 47 32 31 20 19 0
  657. *
  658. * 82599+ Advanced Receive Descriptor (Read) Format
  659. * 63 1 0
  660. * +-----------------------------------------------------+
  661. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  662. * +----------------------------------------------+------+
  663. * 8 | Header Buffer Address [63:1] | DD |
  664. * +-----------------------------------------------------+
  665. *
  666. *
  667. * 82599+ Advanced Receive Descriptor (Write-Back) Format
  668. *
  669. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  670. * +------------------------------------------------------+
  671. * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
  672. * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
  673. * |/ Flow Dir Flt ID | | | | | |
  674. * +------------------------------------------------------+
  675. * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
  676. * +------------------------------------------------------+
  677. * 63 48 47 32 31 20 19 0
  678. */
  679. for (n = 0; n < adapter->num_rx_queues; n++) {
  680. rx_ring = adapter->rx_ring[n];
  681. pr_info("------------------------------------\n");
  682. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  683. pr_info("------------------------------------\n");
  684. pr_info("%s%s%s\n",
  685. "R [desc] [ PktBuf A0] ",
  686. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  687. "<-- Adv Rx Read format");
  688. pr_info("%s%s%s\n",
  689. "RWB[desc] [PcsmIpSHl PtRs] ",
  690. "[vl er S cks ln] ---------------- [bi->skb ] ",
  691. "<-- Adv Rx Write-Back format");
  692. for (i = 0; i < rx_ring->count; i++) {
  693. const char *ring_desc;
  694. if (i == rx_ring->next_to_use)
  695. ring_desc = " NTU";
  696. else if (i == rx_ring->next_to_clean)
  697. ring_desc = " NTC";
  698. else
  699. ring_desc = "";
  700. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  701. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  702. u0 = (struct my_u0 *)rx_desc;
  703. if (rx_desc->wb.upper.length) {
  704. /* Descriptor Done */
  705. pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
  706. i,
  707. le64_to_cpu((__force __le64)u0->a),
  708. le64_to_cpu((__force __le64)u0->b),
  709. rx_buffer_info->skb,
  710. ring_desc);
  711. } else {
  712. pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
  713. i,
  714. le64_to_cpu((__force __le64)u0->a),
  715. le64_to_cpu((__force __le64)u0->b),
  716. (u64)rx_buffer_info->dma,
  717. rx_buffer_info->skb,
  718. ring_desc);
  719. if (netif_msg_pktdata(adapter) &&
  720. rx_buffer_info->dma) {
  721. print_hex_dump(KERN_INFO, "",
  722. DUMP_PREFIX_ADDRESS, 16, 1,
  723. page_address(rx_buffer_info->page) +
  724. rx_buffer_info->page_offset,
  725. ixgbe_rx_bufsz(rx_ring), true);
  726. }
  727. }
  728. }
  729. }
  730. }
  731. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  732. {
  733. u32 ctrl_ext;
  734. /* Let firmware take over control of h/w */
  735. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  736. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  737. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  738. }
  739. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  740. {
  741. u32 ctrl_ext;
  742. /* Let firmware know the driver has taken over */
  743. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  744. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  745. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  746. }
  747. /**
  748. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  749. * @adapter: pointer to adapter struct
  750. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  751. * @queue: queue to map the corresponding interrupt to
  752. * @msix_vector: the vector to map to the corresponding queue
  753. *
  754. */
  755. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  756. u8 queue, u8 msix_vector)
  757. {
  758. u32 ivar, index;
  759. struct ixgbe_hw *hw = &adapter->hw;
  760. switch (hw->mac.type) {
  761. case ixgbe_mac_82598EB:
  762. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  763. if (direction == -1)
  764. direction = 0;
  765. index = (((direction * 64) + queue) >> 2) & 0x1F;
  766. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  767. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  768. ivar |= (msix_vector << (8 * (queue & 0x3)));
  769. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  770. break;
  771. case ixgbe_mac_82599EB:
  772. case ixgbe_mac_X540:
  773. case ixgbe_mac_X550:
  774. case ixgbe_mac_X550EM_x:
  775. case ixgbe_mac_x550em_a:
  776. if (direction == -1) {
  777. /* other causes */
  778. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  779. index = ((queue & 1) * 8);
  780. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  781. ivar &= ~(0xFF << index);
  782. ivar |= (msix_vector << index);
  783. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  784. break;
  785. } else {
  786. /* tx or rx causes */
  787. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  788. index = ((16 * (queue & 1)) + (8 * direction));
  789. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  790. ivar &= ~(0xFF << index);
  791. ivar |= (msix_vector << index);
  792. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  793. break;
  794. }
  795. default:
  796. break;
  797. }
  798. }
  799. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  800. u64 qmask)
  801. {
  802. u32 mask;
  803. switch (adapter->hw.mac.type) {
  804. case ixgbe_mac_82598EB:
  805. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  806. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  807. break;
  808. case ixgbe_mac_82599EB:
  809. case ixgbe_mac_X540:
  810. case ixgbe_mac_X550:
  811. case ixgbe_mac_X550EM_x:
  812. case ixgbe_mac_x550em_a:
  813. mask = (qmask & 0xFFFFFFFF);
  814. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  815. mask = (qmask >> 32);
  816. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  817. break;
  818. default:
  819. break;
  820. }
  821. }
  822. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  823. {
  824. struct ixgbe_hw *hw = &adapter->hw;
  825. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  826. int i;
  827. u32 data;
  828. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  829. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  830. return;
  831. switch (hw->mac.type) {
  832. case ixgbe_mac_82598EB:
  833. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  834. break;
  835. default:
  836. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  837. }
  838. hwstats->lxoffrxc += data;
  839. /* refill credits (no tx hang) if we received xoff */
  840. if (!data)
  841. return;
  842. for (i = 0; i < adapter->num_tx_queues; i++)
  843. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  844. &adapter->tx_ring[i]->state);
  845. for (i = 0; i < adapter->num_xdp_queues; i++)
  846. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  847. &adapter->xdp_ring[i]->state);
  848. }
  849. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  850. {
  851. struct ixgbe_hw *hw = &adapter->hw;
  852. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  853. u32 xoff[8] = {0};
  854. u8 tc;
  855. int i;
  856. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  857. if (adapter->ixgbe_ieee_pfc)
  858. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  859. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  860. ixgbe_update_xoff_rx_lfc(adapter);
  861. return;
  862. }
  863. /* update stats for each tc, only valid with PFC enabled */
  864. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  865. u32 pxoffrxc;
  866. switch (hw->mac.type) {
  867. case ixgbe_mac_82598EB:
  868. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  869. break;
  870. default:
  871. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  872. }
  873. hwstats->pxoffrxc[i] += pxoffrxc;
  874. /* Get the TC for given UP */
  875. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  876. xoff[tc] += pxoffrxc;
  877. }
  878. /* disarm tx queues that have received xoff frames */
  879. for (i = 0; i < adapter->num_tx_queues; i++) {
  880. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  881. tc = tx_ring->dcb_tc;
  882. if (xoff[tc])
  883. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  884. }
  885. for (i = 0; i < adapter->num_xdp_queues; i++) {
  886. struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
  887. tc = xdp_ring->dcb_tc;
  888. if (xoff[tc])
  889. clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
  890. }
  891. }
  892. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  893. {
  894. return ring->stats.packets;
  895. }
  896. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  897. {
  898. unsigned int head, tail;
  899. head = ring->next_to_clean;
  900. tail = ring->next_to_use;
  901. return ((head <= tail) ? tail : tail + ring->count) - head;
  902. }
  903. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  904. {
  905. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  906. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  907. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  908. clear_check_for_tx_hang(tx_ring);
  909. /*
  910. * Check for a hung queue, but be thorough. This verifies
  911. * that a transmit has been completed since the previous
  912. * check AND there is at least one packet pending. The
  913. * ARMED bit is set to indicate a potential hang. The
  914. * bit is cleared if a pause frame is received to remove
  915. * false hang detection due to PFC or 802.3x frames. By
  916. * requiring this to fail twice we avoid races with
  917. * pfc clearing the ARMED bit and conditions where we
  918. * run the check_tx_hang logic with a transmit completion
  919. * pending but without time to complete it yet.
  920. */
  921. if (tx_done_old == tx_done && tx_pending)
  922. /* make sure it is true for two checks in a row */
  923. return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  924. &tx_ring->state);
  925. /* update completed stats and continue */
  926. tx_ring->tx_stats.tx_done_old = tx_done;
  927. /* reset the countdown */
  928. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  929. return false;
  930. }
  931. /**
  932. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  933. * @adapter: driver private struct
  934. **/
  935. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  936. {
  937. /* Do the reset outside of interrupt context */
  938. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  939. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  940. e_warn(drv, "initiating reset due to tx timeout\n");
  941. ixgbe_service_event_schedule(adapter);
  942. }
  943. }
  944. /**
  945. * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
  946. * @netdev: network interface device structure
  947. * @queue_index: Tx queue to set
  948. * @maxrate: desired maximum transmit bitrate
  949. **/
  950. static int ixgbe_tx_maxrate(struct net_device *netdev,
  951. int queue_index, u32 maxrate)
  952. {
  953. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  954. struct ixgbe_hw *hw = &adapter->hw;
  955. u32 bcnrc_val = ixgbe_link_mbps(adapter);
  956. if (!maxrate)
  957. return 0;
  958. /* Calculate the rate factor values to set */
  959. bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
  960. bcnrc_val /= maxrate;
  961. /* clear everything but the rate factor */
  962. bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
  963. IXGBE_RTTBCNRC_RF_DEC_MASK;
  964. /* enable the rate scheduler */
  965. bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
  966. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
  967. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
  968. return 0;
  969. }
  970. /**
  971. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  972. * @q_vector: structure containing interrupt and ring information
  973. * @tx_ring: tx ring to clean
  974. * @napi_budget: Used to determine if we are in netpoll
  975. **/
  976. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  977. struct ixgbe_ring *tx_ring, int napi_budget)
  978. {
  979. struct ixgbe_adapter *adapter = q_vector->adapter;
  980. struct ixgbe_tx_buffer *tx_buffer;
  981. union ixgbe_adv_tx_desc *tx_desc;
  982. unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
  983. unsigned int budget = q_vector->tx.work_limit;
  984. unsigned int i = tx_ring->next_to_clean;
  985. if (test_bit(__IXGBE_DOWN, &adapter->state))
  986. return true;
  987. tx_buffer = &tx_ring->tx_buffer_info[i];
  988. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  989. i -= tx_ring->count;
  990. do {
  991. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  992. /* if next_to_watch is not set then there is no work pending */
  993. if (!eop_desc)
  994. break;
  995. /* prevent any other reads prior to eop_desc */
  996. smp_rmb();
  997. /* if DD is not set pending work has not been completed */
  998. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  999. break;
  1000. /* clear next_to_watch to prevent false hangs */
  1001. tx_buffer->next_to_watch = NULL;
  1002. /* update the statistics for this packet */
  1003. total_bytes += tx_buffer->bytecount;
  1004. total_packets += tx_buffer->gso_segs;
  1005. if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
  1006. total_ipsec++;
  1007. /* free the skb */
  1008. if (ring_is_xdp(tx_ring))
  1009. xdp_return_frame(tx_buffer->xdpf);
  1010. else
  1011. napi_consume_skb(tx_buffer->skb, napi_budget);
  1012. /* unmap skb header data */
  1013. dma_unmap_single(tx_ring->dev,
  1014. dma_unmap_addr(tx_buffer, dma),
  1015. dma_unmap_len(tx_buffer, len),
  1016. DMA_TO_DEVICE);
  1017. /* clear tx_buffer data */
  1018. dma_unmap_len_set(tx_buffer, len, 0);
  1019. /* unmap remaining buffers */
  1020. while (tx_desc != eop_desc) {
  1021. tx_buffer++;
  1022. tx_desc++;
  1023. i++;
  1024. if (unlikely(!i)) {
  1025. i -= tx_ring->count;
  1026. tx_buffer = tx_ring->tx_buffer_info;
  1027. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1028. }
  1029. /* unmap any remaining paged data */
  1030. if (dma_unmap_len(tx_buffer, len)) {
  1031. dma_unmap_page(tx_ring->dev,
  1032. dma_unmap_addr(tx_buffer, dma),
  1033. dma_unmap_len(tx_buffer, len),
  1034. DMA_TO_DEVICE);
  1035. dma_unmap_len_set(tx_buffer, len, 0);
  1036. }
  1037. }
  1038. /* move us one more past the eop_desc for start of next pkt */
  1039. tx_buffer++;
  1040. tx_desc++;
  1041. i++;
  1042. if (unlikely(!i)) {
  1043. i -= tx_ring->count;
  1044. tx_buffer = tx_ring->tx_buffer_info;
  1045. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1046. }
  1047. /* issue prefetch for next Tx descriptor */
  1048. prefetch(tx_desc);
  1049. /* update budget accounting */
  1050. budget--;
  1051. } while (likely(budget));
  1052. i += tx_ring->count;
  1053. tx_ring->next_to_clean = i;
  1054. u64_stats_update_begin(&tx_ring->syncp);
  1055. tx_ring->stats.bytes += total_bytes;
  1056. tx_ring->stats.packets += total_packets;
  1057. u64_stats_update_end(&tx_ring->syncp);
  1058. q_vector->tx.total_bytes += total_bytes;
  1059. q_vector->tx.total_packets += total_packets;
  1060. adapter->tx_ipsec += total_ipsec;
  1061. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  1062. /* schedule immediate reset if we believe we hung */
  1063. struct ixgbe_hw *hw = &adapter->hw;
  1064. e_err(drv, "Detected Tx Unit Hang %s\n"
  1065. " Tx Queue <%d>\n"
  1066. " TDH, TDT <%x>, <%x>\n"
  1067. " next_to_use <%x>\n"
  1068. " next_to_clean <%x>\n"
  1069. "tx_buffer_info[next_to_clean]\n"
  1070. " time_stamp <%lx>\n"
  1071. " jiffies <%lx>\n",
  1072. ring_is_xdp(tx_ring) ? "(XDP)" : "",
  1073. tx_ring->queue_index,
  1074. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  1075. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  1076. tx_ring->next_to_use, i,
  1077. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  1078. if (!ring_is_xdp(tx_ring))
  1079. netif_stop_subqueue(tx_ring->netdev,
  1080. tx_ring->queue_index);
  1081. e_info(probe,
  1082. "tx hang %d detected on queue %d, resetting adapter\n",
  1083. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  1084. /* schedule immediate reset if we believe we hung */
  1085. ixgbe_tx_timeout_reset(adapter);
  1086. /* the adapter is about to reset, no point in enabling stuff */
  1087. return true;
  1088. }
  1089. if (ring_is_xdp(tx_ring))
  1090. return !!budget;
  1091. netdev_tx_completed_queue(txring_txq(tx_ring),
  1092. total_packets, total_bytes);
  1093. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  1094. if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
  1095. (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
  1096. /* Make sure that anybody stopping the queue after this
  1097. * sees the new next_to_clean.
  1098. */
  1099. smp_mb();
  1100. if (__netif_subqueue_stopped(tx_ring->netdev,
  1101. tx_ring->queue_index)
  1102. && !test_bit(__IXGBE_DOWN, &adapter->state)) {
  1103. netif_wake_subqueue(tx_ring->netdev,
  1104. tx_ring->queue_index);
  1105. ++tx_ring->tx_stats.restart_queue;
  1106. }
  1107. }
  1108. return !!budget;
  1109. }
  1110. #ifdef CONFIG_IXGBE_DCA
  1111. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  1112. struct ixgbe_ring *tx_ring,
  1113. int cpu)
  1114. {
  1115. struct ixgbe_hw *hw = &adapter->hw;
  1116. u32 txctrl = 0;
  1117. u16 reg_offset;
  1118. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1119. txctrl = dca3_get_tag(tx_ring->dev, cpu);
  1120. switch (hw->mac.type) {
  1121. case ixgbe_mac_82598EB:
  1122. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  1123. break;
  1124. case ixgbe_mac_82599EB:
  1125. case ixgbe_mac_X540:
  1126. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  1127. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  1128. break;
  1129. default:
  1130. /* for unknown hardware do not write register */
  1131. return;
  1132. }
  1133. /*
  1134. * We can enable relaxed ordering for reads, but not writes when
  1135. * DCA is enabled. This is due to a known issue in some chipsets
  1136. * which will cause the DCA tag to be cleared.
  1137. */
  1138. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  1139. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  1140. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  1141. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  1142. }
  1143. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  1144. struct ixgbe_ring *rx_ring,
  1145. int cpu)
  1146. {
  1147. struct ixgbe_hw *hw = &adapter->hw;
  1148. u32 rxctrl = 0;
  1149. u8 reg_idx = rx_ring->reg_idx;
  1150. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1151. rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  1152. switch (hw->mac.type) {
  1153. case ixgbe_mac_82599EB:
  1154. case ixgbe_mac_X540:
  1155. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  1156. break;
  1157. default:
  1158. break;
  1159. }
  1160. /*
  1161. * We can enable relaxed ordering for reads, but not writes when
  1162. * DCA is enabled. This is due to a known issue in some chipsets
  1163. * which will cause the DCA tag to be cleared.
  1164. */
  1165. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  1166. IXGBE_DCA_RXCTRL_DATA_DCA_EN |
  1167. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  1168. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  1169. }
  1170. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  1171. {
  1172. struct ixgbe_adapter *adapter = q_vector->adapter;
  1173. struct ixgbe_ring *ring;
  1174. int cpu = get_cpu();
  1175. if (q_vector->cpu == cpu)
  1176. goto out_no_update;
  1177. ixgbe_for_each_ring(ring, q_vector->tx)
  1178. ixgbe_update_tx_dca(adapter, ring, cpu);
  1179. ixgbe_for_each_ring(ring, q_vector->rx)
  1180. ixgbe_update_rx_dca(adapter, ring, cpu);
  1181. q_vector->cpu = cpu;
  1182. out_no_update:
  1183. put_cpu();
  1184. }
  1185. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  1186. {
  1187. int i;
  1188. /* always use CB2 mode, difference is masked in the CB driver */
  1189. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1190. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1191. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1192. else
  1193. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1194. IXGBE_DCA_CTRL_DCA_DISABLE);
  1195. for (i = 0; i < adapter->num_q_vectors; i++) {
  1196. adapter->q_vector[i]->cpu = -1;
  1197. ixgbe_update_dca(adapter->q_vector[i]);
  1198. }
  1199. }
  1200. static int __ixgbe_notify_dca(struct device *dev, void *data)
  1201. {
  1202. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  1203. unsigned long event = *(unsigned long *)data;
  1204. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  1205. return 0;
  1206. switch (event) {
  1207. case DCA_PROVIDER_ADD:
  1208. /* if we're already enabled, don't do it again */
  1209. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1210. break;
  1211. if (dca_add_requester(dev) == 0) {
  1212. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  1213. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1214. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1215. break;
  1216. }
  1217. /* fall through - DCA is disabled. */
  1218. case DCA_PROVIDER_REMOVE:
  1219. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  1220. dca_remove_requester(dev);
  1221. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  1222. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1223. IXGBE_DCA_CTRL_DCA_DISABLE);
  1224. }
  1225. break;
  1226. }
  1227. return 0;
  1228. }
  1229. #endif /* CONFIG_IXGBE_DCA */
  1230. #define IXGBE_RSS_L4_TYPES_MASK \
  1231. ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
  1232. (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
  1233. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
  1234. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
  1235. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1236. union ixgbe_adv_rx_desc *rx_desc,
  1237. struct sk_buff *skb)
  1238. {
  1239. u16 rss_type;
  1240. if (!(ring->netdev->features & NETIF_F_RXHASH))
  1241. return;
  1242. rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
  1243. IXGBE_RXDADV_RSSTYPE_MASK;
  1244. if (!rss_type)
  1245. return;
  1246. skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
  1247. (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
  1248. PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
  1249. }
  1250. #ifdef IXGBE_FCOE
  1251. /**
  1252. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1253. * @ring: structure containing ring specific data
  1254. * @rx_desc: advanced rx descriptor
  1255. *
  1256. * Returns : true if it is FCoE pkt
  1257. */
  1258. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1259. union ixgbe_adv_rx_desc *rx_desc)
  1260. {
  1261. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1262. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1263. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1264. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1265. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1266. }
  1267. #endif /* IXGBE_FCOE */
  1268. /**
  1269. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1270. * @ring: structure containing ring specific data
  1271. * @rx_desc: current Rx descriptor being processed
  1272. * @skb: skb currently being received and modified
  1273. **/
  1274. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1275. union ixgbe_adv_rx_desc *rx_desc,
  1276. struct sk_buff *skb)
  1277. {
  1278. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1279. bool encap_pkt = false;
  1280. skb_checksum_none_assert(skb);
  1281. /* Rx csum disabled */
  1282. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1283. return;
  1284. /* check for VXLAN and Geneve packets */
  1285. if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
  1286. encap_pkt = true;
  1287. skb->encapsulation = 1;
  1288. }
  1289. /* if IP and error */
  1290. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1291. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1292. ring->rx_stats.csum_err++;
  1293. return;
  1294. }
  1295. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1296. return;
  1297. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1298. /*
  1299. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1300. * checksum errors.
  1301. */
  1302. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1303. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1304. return;
  1305. ring->rx_stats.csum_err++;
  1306. return;
  1307. }
  1308. /* It must be a TCP or UDP packet with a valid checksum */
  1309. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1310. if (encap_pkt) {
  1311. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
  1312. return;
  1313. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
  1314. skb->ip_summed = CHECKSUM_NONE;
  1315. return;
  1316. }
  1317. /* If we checked the outer header let the stack know */
  1318. skb->csum_level = 1;
  1319. }
  1320. }
  1321. static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
  1322. {
  1323. return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
  1324. }
  1325. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1326. struct ixgbe_rx_buffer *bi)
  1327. {
  1328. struct page *page = bi->page;
  1329. dma_addr_t dma;
  1330. /* since we are recycling buffers we should seldom need to alloc */
  1331. if (likely(page))
  1332. return true;
  1333. /* alloc new page for storage */
  1334. page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
  1335. if (unlikely(!page)) {
  1336. rx_ring->rx_stats.alloc_rx_page_failed++;
  1337. return false;
  1338. }
  1339. /* map page for use */
  1340. dma = dma_map_page_attrs(rx_ring->dev, page, 0,
  1341. ixgbe_rx_pg_size(rx_ring),
  1342. DMA_FROM_DEVICE,
  1343. IXGBE_RX_DMA_ATTR);
  1344. /*
  1345. * if mapping failed free memory back to system since
  1346. * there isn't much point in holding memory we can't use
  1347. */
  1348. if (dma_mapping_error(rx_ring->dev, dma)) {
  1349. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1350. rx_ring->rx_stats.alloc_rx_page_failed++;
  1351. return false;
  1352. }
  1353. bi->dma = dma;
  1354. bi->page = page;
  1355. bi->page_offset = ixgbe_rx_offset(rx_ring);
  1356. page_ref_add(page, USHRT_MAX - 1);
  1357. bi->pagecnt_bias = USHRT_MAX;
  1358. rx_ring->rx_stats.alloc_rx_page++;
  1359. return true;
  1360. }
  1361. /**
  1362. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1363. * @rx_ring: ring to place buffers on
  1364. * @cleaned_count: number of buffers to replace
  1365. **/
  1366. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1367. {
  1368. union ixgbe_adv_rx_desc *rx_desc;
  1369. struct ixgbe_rx_buffer *bi;
  1370. u16 i = rx_ring->next_to_use;
  1371. u16 bufsz;
  1372. /* nothing to do */
  1373. if (!cleaned_count)
  1374. return;
  1375. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1376. bi = &rx_ring->rx_buffer_info[i];
  1377. i -= rx_ring->count;
  1378. bufsz = ixgbe_rx_bufsz(rx_ring);
  1379. do {
  1380. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1381. break;
  1382. /* sync the buffer for use by the device */
  1383. dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
  1384. bi->page_offset, bufsz,
  1385. DMA_FROM_DEVICE);
  1386. /*
  1387. * Refresh the desc even if buffer_addrs didn't change
  1388. * because each write-back erases this info.
  1389. */
  1390. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1391. rx_desc++;
  1392. bi++;
  1393. i++;
  1394. if (unlikely(!i)) {
  1395. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1396. bi = rx_ring->rx_buffer_info;
  1397. i -= rx_ring->count;
  1398. }
  1399. /* clear the length for the next_to_use descriptor */
  1400. rx_desc->wb.upper.length = 0;
  1401. cleaned_count--;
  1402. } while (cleaned_count);
  1403. i += rx_ring->count;
  1404. if (rx_ring->next_to_use != i) {
  1405. rx_ring->next_to_use = i;
  1406. /* update next to alloc since we have filled the ring */
  1407. rx_ring->next_to_alloc = i;
  1408. /* Force memory writes to complete before letting h/w
  1409. * know there are new descriptors to fetch. (Only
  1410. * applicable for weak-ordered memory model archs,
  1411. * such as IA-64).
  1412. */
  1413. wmb();
  1414. writel(i, rx_ring->tail);
  1415. }
  1416. }
  1417. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1418. struct sk_buff *skb)
  1419. {
  1420. u16 hdr_len = skb_headlen(skb);
  1421. /* set gso_size to avoid messing up TCP MSS */
  1422. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1423. IXGBE_CB(skb)->append_cnt);
  1424. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1425. }
  1426. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1427. struct sk_buff *skb)
  1428. {
  1429. /* if append_cnt is 0 then frame is not RSC */
  1430. if (!IXGBE_CB(skb)->append_cnt)
  1431. return;
  1432. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1433. rx_ring->rx_stats.rsc_flush++;
  1434. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1435. /* gso_size is computed using append_cnt so always clear it last */
  1436. IXGBE_CB(skb)->append_cnt = 0;
  1437. }
  1438. /**
  1439. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1440. * @rx_ring: rx descriptor ring packet is being transacted on
  1441. * @rx_desc: pointer to the EOP Rx descriptor
  1442. * @skb: pointer to current skb being populated
  1443. *
  1444. * This function checks the ring, descriptor, and packet information in
  1445. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1446. * other fields within the skb.
  1447. **/
  1448. static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1449. union ixgbe_adv_rx_desc *rx_desc,
  1450. struct sk_buff *skb)
  1451. {
  1452. struct net_device *dev = rx_ring->netdev;
  1453. u32 flags = rx_ring->q_vector->adapter->flags;
  1454. ixgbe_update_rsc_stats(rx_ring, skb);
  1455. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1456. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1457. if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
  1458. ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
  1459. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1460. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1461. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1462. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1463. }
  1464. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
  1465. ixgbe_ipsec_rx(rx_ring, rx_desc, skb);
  1466. /* record Rx queue, or update MACVLAN statistics */
  1467. if (netif_is_ixgbe(dev))
  1468. skb_record_rx_queue(skb, rx_ring->queue_index);
  1469. else
  1470. macvlan_count_rx(netdev_priv(dev), skb->len + ETH_HLEN, true,
  1471. false);
  1472. skb->protocol = eth_type_trans(skb, dev);
  1473. }
  1474. static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1475. struct sk_buff *skb)
  1476. {
  1477. napi_gro_receive(&q_vector->napi, skb);
  1478. }
  1479. /**
  1480. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1481. * @rx_ring: Rx ring being processed
  1482. * @rx_desc: Rx descriptor for current buffer
  1483. * @skb: Current socket buffer containing buffer in progress
  1484. *
  1485. * This function updates next to clean. If the buffer is an EOP buffer
  1486. * this function exits returning false, otherwise it will place the
  1487. * sk_buff in the next buffer to be chained and return true indicating
  1488. * that this is in fact a non-EOP buffer.
  1489. **/
  1490. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1491. union ixgbe_adv_rx_desc *rx_desc,
  1492. struct sk_buff *skb)
  1493. {
  1494. u32 ntc = rx_ring->next_to_clean + 1;
  1495. /* fetch, update, and store next to clean */
  1496. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1497. rx_ring->next_to_clean = ntc;
  1498. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1499. /* update RSC append count if present */
  1500. if (ring_is_rsc_enabled(rx_ring)) {
  1501. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1502. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1503. if (unlikely(rsc_enabled)) {
  1504. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1505. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1506. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1507. /* update ntc based on RSC value */
  1508. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1509. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1510. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1511. }
  1512. }
  1513. /* if we are the last buffer then there is nothing else to do */
  1514. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1515. return false;
  1516. /* place skb in next buffer to be received */
  1517. rx_ring->rx_buffer_info[ntc].skb = skb;
  1518. rx_ring->rx_stats.non_eop_descs++;
  1519. return true;
  1520. }
  1521. /**
  1522. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1523. * @rx_ring: rx descriptor ring packet is being transacted on
  1524. * @skb: pointer to current skb being adjusted
  1525. *
  1526. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1527. * main difference between this version and the original function is that
  1528. * this function can make several assumptions about the state of things
  1529. * that allow for significant optimizations versus the standard function.
  1530. * As a result we can do things like drop a frag and maintain an accurate
  1531. * truesize for the skb.
  1532. */
  1533. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1534. struct sk_buff *skb)
  1535. {
  1536. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1537. unsigned char *va;
  1538. unsigned int pull_len;
  1539. /*
  1540. * it is valid to use page_address instead of kmap since we are
  1541. * working with pages allocated out of the lomem pool per
  1542. * alloc_page(GFP_ATOMIC)
  1543. */
  1544. va = skb_frag_address(frag);
  1545. /*
  1546. * we need the header to contain the greater of either ETH_HLEN or
  1547. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1548. */
  1549. pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
  1550. /* align pull length to size of long to optimize memcpy performance */
  1551. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1552. /* update all of the pointers */
  1553. skb_frag_size_sub(frag, pull_len);
  1554. frag->page_offset += pull_len;
  1555. skb->data_len -= pull_len;
  1556. skb->tail += pull_len;
  1557. }
  1558. /**
  1559. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1560. * @rx_ring: rx descriptor ring packet is being transacted on
  1561. * @skb: pointer to current skb being updated
  1562. *
  1563. * This function provides a basic DMA sync up for the first fragment of an
  1564. * skb. The reason for doing this is that the first fragment cannot be
  1565. * unmapped until we have reached the end of packet descriptor for a buffer
  1566. * chain.
  1567. */
  1568. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1569. struct sk_buff *skb)
  1570. {
  1571. /* if the page was released unmap it, else just sync our portion */
  1572. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1573. dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
  1574. ixgbe_rx_pg_size(rx_ring),
  1575. DMA_FROM_DEVICE,
  1576. IXGBE_RX_DMA_ATTR);
  1577. } else if (ring_uses_build_skb(rx_ring)) {
  1578. unsigned long offset = (unsigned long)(skb->data) & ~PAGE_MASK;
  1579. dma_sync_single_range_for_cpu(rx_ring->dev,
  1580. IXGBE_CB(skb)->dma,
  1581. offset,
  1582. skb_headlen(skb),
  1583. DMA_FROM_DEVICE);
  1584. } else {
  1585. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1586. dma_sync_single_range_for_cpu(rx_ring->dev,
  1587. IXGBE_CB(skb)->dma,
  1588. frag->page_offset,
  1589. skb_frag_size(frag),
  1590. DMA_FROM_DEVICE);
  1591. }
  1592. }
  1593. /**
  1594. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1595. * @rx_ring: rx descriptor ring packet is being transacted on
  1596. * @rx_desc: pointer to the EOP Rx descriptor
  1597. * @skb: pointer to current skb being fixed
  1598. *
  1599. * Check if the skb is valid in the XDP case it will be an error pointer.
  1600. * Return true in this case to abort processing and advance to next
  1601. * descriptor.
  1602. *
  1603. * Check for corrupted packet headers caused by senders on the local L2
  1604. * embedded NIC switch not setting up their Tx Descriptors right. These
  1605. * should be very rare.
  1606. *
  1607. * Also address the case where we are pulling data in on pages only
  1608. * and as such no data is present in the skb header.
  1609. *
  1610. * In addition if skb is not at least 60 bytes we need to pad it so that
  1611. * it is large enough to qualify as a valid Ethernet frame.
  1612. *
  1613. * Returns true if an error was encountered and skb was freed.
  1614. **/
  1615. static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1616. union ixgbe_adv_rx_desc *rx_desc,
  1617. struct sk_buff *skb)
  1618. {
  1619. struct net_device *netdev = rx_ring->netdev;
  1620. /* XDP packets use error pointer so abort at this point */
  1621. if (IS_ERR(skb))
  1622. return true;
  1623. /* Verify netdev is present, and that packet does not have any
  1624. * errors that would be unacceptable to the netdev.
  1625. */
  1626. if (!netdev ||
  1627. (unlikely(ixgbe_test_staterr(rx_desc,
  1628. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1629. !(netdev->features & NETIF_F_RXALL)))) {
  1630. dev_kfree_skb_any(skb);
  1631. return true;
  1632. }
  1633. /* place header in linear portion of buffer */
  1634. if (!skb_headlen(skb))
  1635. ixgbe_pull_tail(rx_ring, skb);
  1636. #ifdef IXGBE_FCOE
  1637. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1638. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1639. return false;
  1640. #endif
  1641. /* if eth_skb_pad returns an error the skb was freed */
  1642. if (eth_skb_pad(skb))
  1643. return true;
  1644. return false;
  1645. }
  1646. /**
  1647. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1648. * @rx_ring: rx descriptor ring to store buffers on
  1649. * @old_buff: donor buffer to have page reused
  1650. *
  1651. * Synchronizes page for reuse by the adapter
  1652. **/
  1653. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1654. struct ixgbe_rx_buffer *old_buff)
  1655. {
  1656. struct ixgbe_rx_buffer *new_buff;
  1657. u16 nta = rx_ring->next_to_alloc;
  1658. new_buff = &rx_ring->rx_buffer_info[nta];
  1659. /* update, and store next to alloc */
  1660. nta++;
  1661. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1662. /* Transfer page from old buffer to new buffer.
  1663. * Move each member individually to avoid possible store
  1664. * forwarding stalls and unnecessary copy of skb.
  1665. */
  1666. new_buff->dma = old_buff->dma;
  1667. new_buff->page = old_buff->page;
  1668. new_buff->page_offset = old_buff->page_offset;
  1669. new_buff->pagecnt_bias = old_buff->pagecnt_bias;
  1670. }
  1671. static inline bool ixgbe_page_is_reserved(struct page *page)
  1672. {
  1673. return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
  1674. }
  1675. static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
  1676. {
  1677. unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
  1678. struct page *page = rx_buffer->page;
  1679. /* avoid re-using remote pages */
  1680. if (unlikely(ixgbe_page_is_reserved(page)))
  1681. return false;
  1682. #if (PAGE_SIZE < 8192)
  1683. /* if we are only owner of page we can reuse it */
  1684. if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
  1685. return false;
  1686. #else
  1687. /* The last offset is a bit aggressive in that we assume the
  1688. * worst case of FCoE being enabled and using a 3K buffer.
  1689. * However this should have minimal impact as the 1K extra is
  1690. * still less than one buffer in size.
  1691. */
  1692. #define IXGBE_LAST_OFFSET \
  1693. (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
  1694. if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
  1695. return false;
  1696. #endif
  1697. /* If we have drained the page fragment pool we need to update
  1698. * the pagecnt_bias and page count so that we fully restock the
  1699. * number of references the driver holds.
  1700. */
  1701. if (unlikely(pagecnt_bias == 1)) {
  1702. page_ref_add(page, USHRT_MAX - 1);
  1703. rx_buffer->pagecnt_bias = USHRT_MAX;
  1704. }
  1705. return true;
  1706. }
  1707. /**
  1708. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1709. * @rx_ring: rx descriptor ring to transact packets on
  1710. * @rx_buffer: buffer containing page to add
  1711. * @skb: sk_buff to place the data into
  1712. * @size: size of data in rx_buffer
  1713. *
  1714. * This function will add the data contained in rx_buffer->page to the skb.
  1715. * This is done either through a direct copy if the data in the buffer is
  1716. * less than the skb header size, otherwise it will just attach the page as
  1717. * a frag to the skb.
  1718. *
  1719. * The function will then update the page offset if necessary and return
  1720. * true if the buffer can be reused by the adapter.
  1721. **/
  1722. static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1723. struct ixgbe_rx_buffer *rx_buffer,
  1724. struct sk_buff *skb,
  1725. unsigned int size)
  1726. {
  1727. #if (PAGE_SIZE < 8192)
  1728. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1729. #else
  1730. unsigned int truesize = ring_uses_build_skb(rx_ring) ?
  1731. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
  1732. SKB_DATA_ALIGN(size);
  1733. #endif
  1734. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
  1735. rx_buffer->page_offset, size, truesize);
  1736. #if (PAGE_SIZE < 8192)
  1737. rx_buffer->page_offset ^= truesize;
  1738. #else
  1739. rx_buffer->page_offset += truesize;
  1740. #endif
  1741. }
  1742. static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
  1743. union ixgbe_adv_rx_desc *rx_desc,
  1744. struct sk_buff **skb,
  1745. const unsigned int size)
  1746. {
  1747. struct ixgbe_rx_buffer *rx_buffer;
  1748. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1749. prefetchw(rx_buffer->page);
  1750. *skb = rx_buffer->skb;
  1751. /* Delay unmapping of the first packet. It carries the header
  1752. * information, HW may still access the header after the writeback.
  1753. * Only unmap it when EOP is reached
  1754. */
  1755. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
  1756. if (!*skb)
  1757. goto skip_sync;
  1758. } else {
  1759. if (*skb)
  1760. ixgbe_dma_sync_frag(rx_ring, *skb);
  1761. }
  1762. /* we are reusing so sync this buffer for CPU use */
  1763. dma_sync_single_range_for_cpu(rx_ring->dev,
  1764. rx_buffer->dma,
  1765. rx_buffer->page_offset,
  1766. size,
  1767. DMA_FROM_DEVICE);
  1768. skip_sync:
  1769. rx_buffer->pagecnt_bias--;
  1770. return rx_buffer;
  1771. }
  1772. static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
  1773. struct ixgbe_rx_buffer *rx_buffer,
  1774. struct sk_buff *skb)
  1775. {
  1776. if (ixgbe_can_reuse_rx_page(rx_buffer)) {
  1777. /* hand second half of page back to the ring */
  1778. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1779. } else {
  1780. if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1781. /* the page has been released from the ring */
  1782. IXGBE_CB(skb)->page_released = true;
  1783. } else {
  1784. /* we are not reusing the buffer so unmap it */
  1785. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  1786. ixgbe_rx_pg_size(rx_ring),
  1787. DMA_FROM_DEVICE,
  1788. IXGBE_RX_DMA_ATTR);
  1789. }
  1790. __page_frag_cache_drain(rx_buffer->page,
  1791. rx_buffer->pagecnt_bias);
  1792. }
  1793. /* clear contents of rx_buffer */
  1794. rx_buffer->page = NULL;
  1795. rx_buffer->skb = NULL;
  1796. }
  1797. static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
  1798. struct ixgbe_rx_buffer *rx_buffer,
  1799. struct xdp_buff *xdp,
  1800. union ixgbe_adv_rx_desc *rx_desc)
  1801. {
  1802. unsigned int size = xdp->data_end - xdp->data;
  1803. #if (PAGE_SIZE < 8192)
  1804. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1805. #else
  1806. unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
  1807. xdp->data_hard_start);
  1808. #endif
  1809. struct sk_buff *skb;
  1810. /* prefetch first cache line of first page */
  1811. prefetch(xdp->data);
  1812. #if L1_CACHE_BYTES < 128
  1813. prefetch(xdp->data + L1_CACHE_BYTES);
  1814. #endif
  1815. /* Note, we get here by enabling legacy-rx via:
  1816. *
  1817. * ethtool --set-priv-flags <dev> legacy-rx on
  1818. *
  1819. * In this mode, we currently get 0 extra XDP headroom as
  1820. * opposed to having legacy-rx off, where we process XDP
  1821. * packets going to stack via ixgbe_build_skb(). The latter
  1822. * provides us currently with 192 bytes of headroom.
  1823. *
  1824. * For ixgbe_construct_skb() mode it means that the
  1825. * xdp->data_meta will always point to xdp->data, since
  1826. * the helper cannot expand the head. Should this ever
  1827. * change in future for legacy-rx mode on, then lets also
  1828. * add xdp->data_meta handling here.
  1829. */
  1830. /* allocate a skb to store the frags */
  1831. skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
  1832. if (unlikely(!skb))
  1833. return NULL;
  1834. if (size > IXGBE_RX_HDR_SIZE) {
  1835. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1836. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1837. skb_add_rx_frag(skb, 0, rx_buffer->page,
  1838. xdp->data - page_address(rx_buffer->page),
  1839. size, truesize);
  1840. #if (PAGE_SIZE < 8192)
  1841. rx_buffer->page_offset ^= truesize;
  1842. #else
  1843. rx_buffer->page_offset += truesize;
  1844. #endif
  1845. } else {
  1846. memcpy(__skb_put(skb, size),
  1847. xdp->data, ALIGN(size, sizeof(long)));
  1848. rx_buffer->pagecnt_bias++;
  1849. }
  1850. return skb;
  1851. }
  1852. static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
  1853. struct ixgbe_rx_buffer *rx_buffer,
  1854. struct xdp_buff *xdp,
  1855. union ixgbe_adv_rx_desc *rx_desc)
  1856. {
  1857. unsigned int metasize = xdp->data - xdp->data_meta;
  1858. #if (PAGE_SIZE < 8192)
  1859. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1860. #else
  1861. unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
  1862. SKB_DATA_ALIGN(xdp->data_end -
  1863. xdp->data_hard_start);
  1864. #endif
  1865. struct sk_buff *skb;
  1866. /* Prefetch first cache line of first page. If xdp->data_meta
  1867. * is unused, this points extactly as xdp->data, otherwise we
  1868. * likely have a consumer accessing first few bytes of meta
  1869. * data, and then actual data.
  1870. */
  1871. prefetch(xdp->data_meta);
  1872. #if L1_CACHE_BYTES < 128
  1873. prefetch(xdp->data_meta + L1_CACHE_BYTES);
  1874. #endif
  1875. /* build an skb to around the page buffer */
  1876. skb = build_skb(xdp->data_hard_start, truesize);
  1877. if (unlikely(!skb))
  1878. return NULL;
  1879. /* update pointers within the skb to store the data */
  1880. skb_reserve(skb, xdp->data - xdp->data_hard_start);
  1881. __skb_put(skb, xdp->data_end - xdp->data);
  1882. if (metasize)
  1883. skb_metadata_set(skb, metasize);
  1884. /* record DMA address if this is the start of a chain of buffers */
  1885. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1886. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1887. /* update buffer offset */
  1888. #if (PAGE_SIZE < 8192)
  1889. rx_buffer->page_offset ^= truesize;
  1890. #else
  1891. rx_buffer->page_offset += truesize;
  1892. #endif
  1893. return skb;
  1894. }
  1895. #define IXGBE_XDP_PASS 0
  1896. #define IXGBE_XDP_CONSUMED BIT(0)
  1897. #define IXGBE_XDP_TX BIT(1)
  1898. #define IXGBE_XDP_REDIR BIT(2)
  1899. static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
  1900. struct xdp_frame *xdpf);
  1901. static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
  1902. struct ixgbe_ring *rx_ring,
  1903. struct xdp_buff *xdp)
  1904. {
  1905. int err, result = IXGBE_XDP_PASS;
  1906. struct bpf_prog *xdp_prog;
  1907. struct xdp_frame *xdpf;
  1908. u32 act;
  1909. rcu_read_lock();
  1910. xdp_prog = READ_ONCE(rx_ring->xdp_prog);
  1911. if (!xdp_prog)
  1912. goto xdp_out;
  1913. prefetchw(xdp->data_hard_start); /* xdp_frame write */
  1914. act = bpf_prog_run_xdp(xdp_prog, xdp);
  1915. switch (act) {
  1916. case XDP_PASS:
  1917. break;
  1918. case XDP_TX:
  1919. xdpf = convert_to_xdp_frame(xdp);
  1920. if (unlikely(!xdpf)) {
  1921. result = IXGBE_XDP_CONSUMED;
  1922. break;
  1923. }
  1924. result = ixgbe_xmit_xdp_ring(adapter, xdpf);
  1925. break;
  1926. case XDP_REDIRECT:
  1927. err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
  1928. if (!err)
  1929. result = IXGBE_XDP_REDIR;
  1930. else
  1931. result = IXGBE_XDP_CONSUMED;
  1932. break;
  1933. default:
  1934. bpf_warn_invalid_xdp_action(act);
  1935. /* fallthrough */
  1936. case XDP_ABORTED:
  1937. trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
  1938. /* fallthrough -- handle aborts by dropping packet */
  1939. case XDP_DROP:
  1940. result = IXGBE_XDP_CONSUMED;
  1941. break;
  1942. }
  1943. xdp_out:
  1944. rcu_read_unlock();
  1945. return ERR_PTR(-result);
  1946. }
  1947. static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
  1948. struct ixgbe_rx_buffer *rx_buffer,
  1949. unsigned int size)
  1950. {
  1951. #if (PAGE_SIZE < 8192)
  1952. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1953. rx_buffer->page_offset ^= truesize;
  1954. #else
  1955. unsigned int truesize = ring_uses_build_skb(rx_ring) ?
  1956. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
  1957. SKB_DATA_ALIGN(size);
  1958. rx_buffer->page_offset += truesize;
  1959. #endif
  1960. }
  1961. /**
  1962. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  1963. * @q_vector: structure containing interrupt and ring information
  1964. * @rx_ring: rx descriptor ring to transact packets on
  1965. * @budget: Total limit on number of packets to process
  1966. *
  1967. * This function provides a "bounce buffer" approach to Rx interrupt
  1968. * processing. The advantage to this is that on systems that have
  1969. * expensive overhead for IOMMU access this provides a means of avoiding
  1970. * it by maintaining the mapping of the page to the syste.
  1971. *
  1972. * Returns amount of work completed
  1973. **/
  1974. static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1975. struct ixgbe_ring *rx_ring,
  1976. const int budget)
  1977. {
  1978. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1979. struct ixgbe_adapter *adapter = q_vector->adapter;
  1980. #ifdef IXGBE_FCOE
  1981. int ddp_bytes;
  1982. unsigned int mss = 0;
  1983. #endif /* IXGBE_FCOE */
  1984. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  1985. unsigned int xdp_xmit = 0;
  1986. struct xdp_buff xdp;
  1987. xdp.rxq = &rx_ring->xdp_rxq;
  1988. while (likely(total_rx_packets < budget)) {
  1989. union ixgbe_adv_rx_desc *rx_desc;
  1990. struct ixgbe_rx_buffer *rx_buffer;
  1991. struct sk_buff *skb;
  1992. unsigned int size;
  1993. /* return some buffers to hardware, one at a time is too slow */
  1994. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1995. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1996. cleaned_count = 0;
  1997. }
  1998. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  1999. size = le16_to_cpu(rx_desc->wb.upper.length);
  2000. if (!size)
  2001. break;
  2002. /* This memory barrier is needed to keep us from reading
  2003. * any other fields out of the rx_desc until we know the
  2004. * descriptor has been written back
  2005. */
  2006. dma_rmb();
  2007. rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
  2008. /* retrieve a buffer from the ring */
  2009. if (!skb) {
  2010. xdp.data = page_address(rx_buffer->page) +
  2011. rx_buffer->page_offset;
  2012. xdp.data_meta = xdp.data;
  2013. xdp.data_hard_start = xdp.data -
  2014. ixgbe_rx_offset(rx_ring);
  2015. xdp.data_end = xdp.data + size;
  2016. skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
  2017. }
  2018. if (IS_ERR(skb)) {
  2019. unsigned int xdp_res = -PTR_ERR(skb);
  2020. if (xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR)) {
  2021. xdp_xmit |= xdp_res;
  2022. ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
  2023. } else {
  2024. rx_buffer->pagecnt_bias++;
  2025. }
  2026. total_rx_packets++;
  2027. total_rx_bytes += size;
  2028. } else if (skb) {
  2029. ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
  2030. } else if (ring_uses_build_skb(rx_ring)) {
  2031. skb = ixgbe_build_skb(rx_ring, rx_buffer,
  2032. &xdp, rx_desc);
  2033. } else {
  2034. skb = ixgbe_construct_skb(rx_ring, rx_buffer,
  2035. &xdp, rx_desc);
  2036. }
  2037. /* exit if we failed to retrieve a buffer */
  2038. if (!skb) {
  2039. rx_ring->rx_stats.alloc_rx_buff_failed++;
  2040. rx_buffer->pagecnt_bias++;
  2041. break;
  2042. }
  2043. ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
  2044. cleaned_count++;
  2045. /* place incomplete frames back on ring for completion */
  2046. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  2047. continue;
  2048. /* verify the packet layout is correct */
  2049. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  2050. continue;
  2051. /* probably a little skewed due to removing CRC */
  2052. total_rx_bytes += skb->len;
  2053. /* populate checksum, timestamp, VLAN, and protocol */
  2054. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  2055. #ifdef IXGBE_FCOE
  2056. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  2057. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  2058. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  2059. /* include DDPed FCoE data */
  2060. if (ddp_bytes > 0) {
  2061. if (!mss) {
  2062. mss = rx_ring->netdev->mtu -
  2063. sizeof(struct fcoe_hdr) -
  2064. sizeof(struct fc_frame_header) -
  2065. sizeof(struct fcoe_crc_eof);
  2066. if (mss > 512)
  2067. mss &= ~511;
  2068. }
  2069. total_rx_bytes += ddp_bytes;
  2070. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  2071. mss);
  2072. }
  2073. if (!ddp_bytes) {
  2074. dev_kfree_skb_any(skb);
  2075. continue;
  2076. }
  2077. }
  2078. #endif /* IXGBE_FCOE */
  2079. ixgbe_rx_skb(q_vector, skb);
  2080. /* update budget accounting */
  2081. total_rx_packets++;
  2082. }
  2083. if (xdp_xmit & IXGBE_XDP_REDIR)
  2084. xdp_do_flush_map();
  2085. if (xdp_xmit & IXGBE_XDP_TX) {
  2086. struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
  2087. /* Force memory writes to complete before letting h/w
  2088. * know there are new descriptors to fetch.
  2089. */
  2090. wmb();
  2091. writel(ring->next_to_use, ring->tail);
  2092. }
  2093. u64_stats_update_begin(&rx_ring->syncp);
  2094. rx_ring->stats.packets += total_rx_packets;
  2095. rx_ring->stats.bytes += total_rx_bytes;
  2096. u64_stats_update_end(&rx_ring->syncp);
  2097. q_vector->rx.total_packets += total_rx_packets;
  2098. q_vector->rx.total_bytes += total_rx_bytes;
  2099. return total_rx_packets;
  2100. }
  2101. /**
  2102. * ixgbe_configure_msix - Configure MSI-X hardware
  2103. * @adapter: board private structure
  2104. *
  2105. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  2106. * interrupts.
  2107. **/
  2108. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  2109. {
  2110. struct ixgbe_q_vector *q_vector;
  2111. int v_idx;
  2112. u32 mask;
  2113. /* Populate MSIX to EITR Select */
  2114. if (adapter->num_vfs > 32) {
  2115. u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
  2116. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  2117. }
  2118. /*
  2119. * Populate the IVAR table and set the ITR values to the
  2120. * corresponding register.
  2121. */
  2122. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  2123. struct ixgbe_ring *ring;
  2124. q_vector = adapter->q_vector[v_idx];
  2125. ixgbe_for_each_ring(ring, q_vector->rx)
  2126. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  2127. ixgbe_for_each_ring(ring, q_vector->tx)
  2128. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  2129. ixgbe_write_eitr(q_vector);
  2130. }
  2131. switch (adapter->hw.mac.type) {
  2132. case ixgbe_mac_82598EB:
  2133. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  2134. v_idx);
  2135. break;
  2136. case ixgbe_mac_82599EB:
  2137. case ixgbe_mac_X540:
  2138. case ixgbe_mac_X550:
  2139. case ixgbe_mac_X550EM_x:
  2140. case ixgbe_mac_x550em_a:
  2141. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  2142. break;
  2143. default:
  2144. break;
  2145. }
  2146. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  2147. /* set up to autoclear timer, and the vectors */
  2148. mask = IXGBE_EIMS_ENABLE_MASK;
  2149. mask &= ~(IXGBE_EIMS_OTHER |
  2150. IXGBE_EIMS_MAILBOX |
  2151. IXGBE_EIMS_LSC);
  2152. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  2153. }
  2154. /**
  2155. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  2156. * @q_vector: structure containing interrupt and ring information
  2157. * @ring_container: structure containing ring performance data
  2158. *
  2159. * Stores a new ITR value based on packets and byte
  2160. * counts during the last interrupt. The advantage of per interrupt
  2161. * computation is faster updates and more accurate ITR for the current
  2162. * traffic pattern. Constants in this function were computed
  2163. * based on theoretical maximum wire speed and thresholds were set based
  2164. * on testing data as well as attempting to minimize response time
  2165. * while increasing bulk throughput.
  2166. **/
  2167. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  2168. struct ixgbe_ring_container *ring_container)
  2169. {
  2170. unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
  2171. IXGBE_ITR_ADAPTIVE_LATENCY;
  2172. unsigned int avg_wire_size, packets, bytes;
  2173. unsigned long next_update = jiffies;
  2174. /* If we don't have any rings just leave ourselves set for maximum
  2175. * possible latency so we take ourselves out of the equation.
  2176. */
  2177. if (!ring_container->ring)
  2178. return;
  2179. /* If we didn't update within up to 1 - 2 jiffies we can assume
  2180. * that either packets are coming in so slow there hasn't been
  2181. * any work, or that there is so much work that NAPI is dealing
  2182. * with interrupt moderation and we don't need to do anything.
  2183. */
  2184. if (time_after(next_update, ring_container->next_update))
  2185. goto clear_counts;
  2186. packets = ring_container->total_packets;
  2187. /* We have no packets to actually measure against. This means
  2188. * either one of the other queues on this vector is active or
  2189. * we are a Tx queue doing TSO with too high of an interrupt rate.
  2190. *
  2191. * When this occurs just tick up our delay by the minimum value
  2192. * and hope that this extra delay will prevent us from being called
  2193. * without any work on our queue.
  2194. */
  2195. if (!packets) {
  2196. itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
  2197. if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
  2198. itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
  2199. itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
  2200. goto clear_counts;
  2201. }
  2202. bytes = ring_container->total_bytes;
  2203. /* If packets are less than 4 or bytes are less than 9000 assume
  2204. * insufficient data to use bulk rate limiting approach. We are
  2205. * likely latency driven.
  2206. */
  2207. if (packets < 4 && bytes < 9000) {
  2208. itr = IXGBE_ITR_ADAPTIVE_LATENCY;
  2209. goto adjust_by_size;
  2210. }
  2211. /* Between 4 and 48 we can assume that our current interrupt delay
  2212. * is only slightly too low. As such we should increase it by a small
  2213. * fixed amount.
  2214. */
  2215. if (packets < 48) {
  2216. itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
  2217. if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
  2218. itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
  2219. goto clear_counts;
  2220. }
  2221. /* Between 48 and 96 is our "goldilocks" zone where we are working
  2222. * out "just right". Just report that our current ITR is good for us.
  2223. */
  2224. if (packets < 96) {
  2225. itr = q_vector->itr >> 2;
  2226. goto clear_counts;
  2227. }
  2228. /* If packet count is 96 or greater we are likely looking at a slight
  2229. * overrun of the delay we want. Try halving our delay to see if that
  2230. * will cut the number of packets in half per interrupt.
  2231. */
  2232. if (packets < 256) {
  2233. itr = q_vector->itr >> 3;
  2234. if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
  2235. itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
  2236. goto clear_counts;
  2237. }
  2238. /* The paths below assume we are dealing with a bulk ITR since number
  2239. * of packets is 256 or greater. We are just going to have to compute
  2240. * a value and try to bring the count under control, though for smaller
  2241. * packet sizes there isn't much we can do as NAPI polling will likely
  2242. * be kicking in sooner rather than later.
  2243. */
  2244. itr = IXGBE_ITR_ADAPTIVE_BULK;
  2245. adjust_by_size:
  2246. /* If packet counts are 256 or greater we can assume we have a gross
  2247. * overestimation of what the rate should be. Instead of trying to fine
  2248. * tune it just use the formula below to try and dial in an exact value
  2249. * give the current packet size of the frame.
  2250. */
  2251. avg_wire_size = bytes / packets;
  2252. /* The following is a crude approximation of:
  2253. * wmem_default / (size + overhead) = desired_pkts_per_int
  2254. * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
  2255. * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
  2256. *
  2257. * Assuming wmem_default is 212992 and overhead is 640 bytes per
  2258. * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
  2259. * formula down to
  2260. *
  2261. * (170 * (size + 24)) / (size + 640) = ITR
  2262. *
  2263. * We first do some math on the packet size and then finally bitshift
  2264. * by 8 after rounding up. We also have to account for PCIe link speed
  2265. * difference as ITR scales based on this.
  2266. */
  2267. if (avg_wire_size <= 60) {
  2268. /* Start at 50k ints/sec */
  2269. avg_wire_size = 5120;
  2270. } else if (avg_wire_size <= 316) {
  2271. /* 50K ints/sec to 16K ints/sec */
  2272. avg_wire_size *= 40;
  2273. avg_wire_size += 2720;
  2274. } else if (avg_wire_size <= 1084) {
  2275. /* 16K ints/sec to 9.2K ints/sec */
  2276. avg_wire_size *= 15;
  2277. avg_wire_size += 11452;
  2278. } else if (avg_wire_size <= 1980) {
  2279. /* 9.2K ints/sec to 8K ints/sec */
  2280. avg_wire_size *= 5;
  2281. avg_wire_size += 22420;
  2282. } else {
  2283. /* plateau at a limit of 8K ints/sec */
  2284. avg_wire_size = 32256;
  2285. }
  2286. /* If we are in low latency mode half our delay which doubles the rate
  2287. * to somewhere between 100K to 16K ints/sec
  2288. */
  2289. if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
  2290. avg_wire_size >>= 1;
  2291. /* Resultant value is 256 times larger than it needs to be. This
  2292. * gives us room to adjust the value as needed to either increase
  2293. * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
  2294. *
  2295. * Use addition as we have already recorded the new latency flag
  2296. * for the ITR value.
  2297. */
  2298. switch (q_vector->adapter->link_speed) {
  2299. case IXGBE_LINK_SPEED_10GB_FULL:
  2300. case IXGBE_LINK_SPEED_100_FULL:
  2301. default:
  2302. itr += DIV_ROUND_UP(avg_wire_size,
  2303. IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
  2304. IXGBE_ITR_ADAPTIVE_MIN_INC;
  2305. break;
  2306. case IXGBE_LINK_SPEED_2_5GB_FULL:
  2307. case IXGBE_LINK_SPEED_1GB_FULL:
  2308. case IXGBE_LINK_SPEED_10_FULL:
  2309. itr += DIV_ROUND_UP(avg_wire_size,
  2310. IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
  2311. IXGBE_ITR_ADAPTIVE_MIN_INC;
  2312. break;
  2313. }
  2314. clear_counts:
  2315. /* write back value */
  2316. ring_container->itr = itr;
  2317. /* next update should occur within next jiffy */
  2318. ring_container->next_update = next_update + 1;
  2319. ring_container->total_bytes = 0;
  2320. ring_container->total_packets = 0;
  2321. }
  2322. /**
  2323. * ixgbe_write_eitr - write EITR register in hardware specific way
  2324. * @q_vector: structure containing interrupt and ring information
  2325. *
  2326. * This function is made to be called by ethtool and by the driver
  2327. * when it needs to update EITR registers at runtime. Hardware
  2328. * specific quirks/differences are taken care of here.
  2329. */
  2330. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  2331. {
  2332. struct ixgbe_adapter *adapter = q_vector->adapter;
  2333. struct ixgbe_hw *hw = &adapter->hw;
  2334. int v_idx = q_vector->v_idx;
  2335. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  2336. switch (adapter->hw.mac.type) {
  2337. case ixgbe_mac_82598EB:
  2338. /* must write high and low 16 bits to reset counter */
  2339. itr_reg |= (itr_reg << 16);
  2340. break;
  2341. case ixgbe_mac_82599EB:
  2342. case ixgbe_mac_X540:
  2343. case ixgbe_mac_X550:
  2344. case ixgbe_mac_X550EM_x:
  2345. case ixgbe_mac_x550em_a:
  2346. /*
  2347. * set the WDIS bit to not clear the timer bits and cause an
  2348. * immediate assertion of the interrupt
  2349. */
  2350. itr_reg |= IXGBE_EITR_CNT_WDIS;
  2351. break;
  2352. default:
  2353. break;
  2354. }
  2355. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  2356. }
  2357. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  2358. {
  2359. u32 new_itr;
  2360. ixgbe_update_itr(q_vector, &q_vector->tx);
  2361. ixgbe_update_itr(q_vector, &q_vector->rx);
  2362. /* use the smallest value of new ITR delay calculations */
  2363. new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
  2364. /* Clear latency flag if set, shift into correct position */
  2365. new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
  2366. new_itr <<= 2;
  2367. if (new_itr != q_vector->itr) {
  2368. /* save the algorithm value here */
  2369. q_vector->itr = new_itr;
  2370. ixgbe_write_eitr(q_vector);
  2371. }
  2372. }
  2373. /**
  2374. * ixgbe_check_overtemp_subtask - check for over temperature
  2375. * @adapter: pointer to adapter
  2376. **/
  2377. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  2378. {
  2379. struct ixgbe_hw *hw = &adapter->hw;
  2380. u32 eicr = adapter->interrupt_event;
  2381. s32 rc;
  2382. if (test_bit(__IXGBE_DOWN, &adapter->state))
  2383. return;
  2384. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  2385. return;
  2386. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2387. switch (hw->device_id) {
  2388. case IXGBE_DEV_ID_82599_T3_LOM:
  2389. /*
  2390. * Since the warning interrupt is for both ports
  2391. * we don't have to check if:
  2392. * - This interrupt wasn't for our port.
  2393. * - We may have missed the interrupt so always have to
  2394. * check if we got a LSC
  2395. */
  2396. if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
  2397. !(eicr & IXGBE_EICR_LSC))
  2398. return;
  2399. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  2400. u32 speed;
  2401. bool link_up = false;
  2402. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2403. if (link_up)
  2404. return;
  2405. }
  2406. /* Check if this is not due to overtemp */
  2407. if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
  2408. return;
  2409. break;
  2410. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2411. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2412. rc = hw->phy.ops.check_overtemp(hw);
  2413. if (rc != IXGBE_ERR_OVERTEMP)
  2414. return;
  2415. break;
  2416. default:
  2417. if (adapter->hw.mac.type >= ixgbe_mac_X540)
  2418. return;
  2419. if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
  2420. return;
  2421. break;
  2422. }
  2423. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2424. adapter->interrupt_event = 0;
  2425. }
  2426. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  2427. {
  2428. struct ixgbe_hw *hw = &adapter->hw;
  2429. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  2430. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2431. e_crit(probe, "Fan has stopped, replace the adapter\n");
  2432. /* write to clear the interrupt */
  2433. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2434. }
  2435. }
  2436. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2437. {
  2438. struct ixgbe_hw *hw = &adapter->hw;
  2439. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  2440. return;
  2441. switch (adapter->hw.mac.type) {
  2442. case ixgbe_mac_82599EB:
  2443. /*
  2444. * Need to check link state so complete overtemp check
  2445. * on service task
  2446. */
  2447. if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
  2448. (eicr & IXGBE_EICR_LSC)) &&
  2449. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  2450. adapter->interrupt_event = eicr;
  2451. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2452. ixgbe_service_event_schedule(adapter);
  2453. return;
  2454. }
  2455. return;
  2456. case ixgbe_mac_x550em_a:
  2457. if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
  2458. adapter->interrupt_event = eicr;
  2459. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2460. ixgbe_service_event_schedule(adapter);
  2461. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  2462. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2463. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
  2464. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2465. }
  2466. return;
  2467. case ixgbe_mac_X550:
  2468. case ixgbe_mac_X540:
  2469. if (!(eicr & IXGBE_EICR_TS))
  2470. return;
  2471. break;
  2472. default:
  2473. return;
  2474. }
  2475. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2476. }
  2477. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2478. {
  2479. switch (hw->mac.type) {
  2480. case ixgbe_mac_82598EB:
  2481. if (hw->phy.type == ixgbe_phy_nl)
  2482. return true;
  2483. return false;
  2484. case ixgbe_mac_82599EB:
  2485. case ixgbe_mac_X550EM_x:
  2486. case ixgbe_mac_x550em_a:
  2487. switch (hw->mac.ops.get_media_type(hw)) {
  2488. case ixgbe_media_type_fiber:
  2489. case ixgbe_media_type_fiber_qsfp:
  2490. return true;
  2491. default:
  2492. return false;
  2493. }
  2494. default:
  2495. return false;
  2496. }
  2497. }
  2498. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2499. {
  2500. struct ixgbe_hw *hw = &adapter->hw;
  2501. u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
  2502. if (!ixgbe_is_sfp(hw))
  2503. return;
  2504. /* Later MAC's use different SDP */
  2505. if (hw->mac.type >= ixgbe_mac_X540)
  2506. eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
  2507. if (eicr & eicr_mask) {
  2508. /* Clear the interrupt */
  2509. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
  2510. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2511. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  2512. adapter->sfp_poll_time = 0;
  2513. ixgbe_service_event_schedule(adapter);
  2514. }
  2515. }
  2516. if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
  2517. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2518. /* Clear the interrupt */
  2519. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2520. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2521. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  2522. ixgbe_service_event_schedule(adapter);
  2523. }
  2524. }
  2525. }
  2526. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  2527. {
  2528. struct ixgbe_hw *hw = &adapter->hw;
  2529. adapter->lsc_int++;
  2530. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2531. adapter->link_check_timeout = jiffies;
  2532. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2533. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2534. IXGBE_WRITE_FLUSH(hw);
  2535. ixgbe_service_event_schedule(adapter);
  2536. }
  2537. }
  2538. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2539. u64 qmask)
  2540. {
  2541. u32 mask;
  2542. struct ixgbe_hw *hw = &adapter->hw;
  2543. switch (hw->mac.type) {
  2544. case ixgbe_mac_82598EB:
  2545. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2546. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2547. break;
  2548. case ixgbe_mac_82599EB:
  2549. case ixgbe_mac_X540:
  2550. case ixgbe_mac_X550:
  2551. case ixgbe_mac_X550EM_x:
  2552. case ixgbe_mac_x550em_a:
  2553. mask = (qmask & 0xFFFFFFFF);
  2554. if (mask)
  2555. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2556. mask = (qmask >> 32);
  2557. if (mask)
  2558. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2559. break;
  2560. default:
  2561. break;
  2562. }
  2563. /* skip the flush */
  2564. }
  2565. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  2566. u64 qmask)
  2567. {
  2568. u32 mask;
  2569. struct ixgbe_hw *hw = &adapter->hw;
  2570. switch (hw->mac.type) {
  2571. case ixgbe_mac_82598EB:
  2572. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2573. IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
  2574. break;
  2575. case ixgbe_mac_82599EB:
  2576. case ixgbe_mac_X540:
  2577. case ixgbe_mac_X550:
  2578. case ixgbe_mac_X550EM_x:
  2579. case ixgbe_mac_x550em_a:
  2580. mask = (qmask & 0xFFFFFFFF);
  2581. if (mask)
  2582. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
  2583. mask = (qmask >> 32);
  2584. if (mask)
  2585. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
  2586. break;
  2587. default:
  2588. break;
  2589. }
  2590. /* skip the flush */
  2591. }
  2592. /**
  2593. * ixgbe_irq_enable - Enable default interrupt generation settings
  2594. * @adapter: board private structure
  2595. * @queues: enable irqs for queues
  2596. * @flush: flush register write
  2597. **/
  2598. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2599. bool flush)
  2600. {
  2601. struct ixgbe_hw *hw = &adapter->hw;
  2602. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2603. /* don't reenable LSC while waiting for link */
  2604. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2605. mask &= ~IXGBE_EIMS_LSC;
  2606. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2607. switch (adapter->hw.mac.type) {
  2608. case ixgbe_mac_82599EB:
  2609. mask |= IXGBE_EIMS_GPI_SDP0(hw);
  2610. break;
  2611. case ixgbe_mac_X540:
  2612. case ixgbe_mac_X550:
  2613. case ixgbe_mac_X550EM_x:
  2614. case ixgbe_mac_x550em_a:
  2615. mask |= IXGBE_EIMS_TS;
  2616. break;
  2617. default:
  2618. break;
  2619. }
  2620. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2621. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2622. switch (adapter->hw.mac.type) {
  2623. case ixgbe_mac_82599EB:
  2624. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2625. mask |= IXGBE_EIMS_GPI_SDP2(hw);
  2626. /* fall through */
  2627. case ixgbe_mac_X540:
  2628. case ixgbe_mac_X550:
  2629. case ixgbe_mac_X550EM_x:
  2630. case ixgbe_mac_x550em_a:
  2631. if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
  2632. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
  2633. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
  2634. mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
  2635. if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
  2636. mask |= IXGBE_EICR_GPI_SDP0_X540;
  2637. mask |= IXGBE_EIMS_ECC;
  2638. mask |= IXGBE_EIMS_MAILBOX;
  2639. break;
  2640. default:
  2641. break;
  2642. }
  2643. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2644. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2645. mask |= IXGBE_EIMS_FLOW_DIR;
  2646. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2647. if (queues)
  2648. ixgbe_irq_enable_queues(adapter, ~0);
  2649. if (flush)
  2650. IXGBE_WRITE_FLUSH(&adapter->hw);
  2651. }
  2652. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2653. {
  2654. struct ixgbe_adapter *adapter = data;
  2655. struct ixgbe_hw *hw = &adapter->hw;
  2656. u32 eicr;
  2657. /*
  2658. * Workaround for Silicon errata. Use clear-by-write instead
  2659. * of clear-by-read. Reading with EICS will return the
  2660. * interrupt causes without clearing, which later be done
  2661. * with the write to EICR.
  2662. */
  2663. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2664. /* The lower 16bits of the EICR register are for the queue interrupts
  2665. * which should be masked here in order to not accidentally clear them if
  2666. * the bits are high when ixgbe_msix_other is called. There is a race
  2667. * condition otherwise which results in possible performance loss
  2668. * especially if the ixgbe_msix_other interrupt is triggering
  2669. * consistently (as it would when PPS is turned on for the X540 device)
  2670. */
  2671. eicr &= 0xFFFF0000;
  2672. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2673. if (eicr & IXGBE_EICR_LSC)
  2674. ixgbe_check_lsc(adapter);
  2675. if (eicr & IXGBE_EICR_MAILBOX)
  2676. ixgbe_msg_task(adapter);
  2677. switch (hw->mac.type) {
  2678. case ixgbe_mac_82599EB:
  2679. case ixgbe_mac_X540:
  2680. case ixgbe_mac_X550:
  2681. case ixgbe_mac_X550EM_x:
  2682. case ixgbe_mac_x550em_a:
  2683. if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
  2684. (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
  2685. adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
  2686. ixgbe_service_event_schedule(adapter);
  2687. IXGBE_WRITE_REG(hw, IXGBE_EICR,
  2688. IXGBE_EICR_GPI_SDP0_X540);
  2689. }
  2690. if (eicr & IXGBE_EICR_ECC) {
  2691. e_info(link, "Received ECC Err, initiating reset\n");
  2692. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2693. ixgbe_service_event_schedule(adapter);
  2694. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2695. }
  2696. /* Handle Flow Director Full threshold interrupt */
  2697. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2698. int reinit_count = 0;
  2699. int i;
  2700. for (i = 0; i < adapter->num_tx_queues; i++) {
  2701. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2702. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2703. &ring->state))
  2704. reinit_count++;
  2705. }
  2706. if (reinit_count) {
  2707. /* no more flow director interrupts until after init */
  2708. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2709. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2710. ixgbe_service_event_schedule(adapter);
  2711. }
  2712. }
  2713. ixgbe_check_sfp_event(adapter, eicr);
  2714. ixgbe_check_overtemp_event(adapter, eicr);
  2715. break;
  2716. default:
  2717. break;
  2718. }
  2719. ixgbe_check_fan_failure(adapter, eicr);
  2720. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2721. ixgbe_ptp_check_pps_event(adapter);
  2722. /* re-enable the original interrupt state, no lsc, no queues */
  2723. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2724. ixgbe_irq_enable(adapter, false, false);
  2725. return IRQ_HANDLED;
  2726. }
  2727. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2728. {
  2729. struct ixgbe_q_vector *q_vector = data;
  2730. /* EIAM disabled interrupts (on this vector) for us */
  2731. if (q_vector->rx.ring || q_vector->tx.ring)
  2732. napi_schedule_irqoff(&q_vector->napi);
  2733. return IRQ_HANDLED;
  2734. }
  2735. /**
  2736. * ixgbe_poll - NAPI Rx polling callback
  2737. * @napi: structure for representing this polling device
  2738. * @budget: how many packets driver is allowed to clean
  2739. *
  2740. * This function is used for legacy and MSI, NAPI mode
  2741. **/
  2742. int ixgbe_poll(struct napi_struct *napi, int budget)
  2743. {
  2744. struct ixgbe_q_vector *q_vector =
  2745. container_of(napi, struct ixgbe_q_vector, napi);
  2746. struct ixgbe_adapter *adapter = q_vector->adapter;
  2747. struct ixgbe_ring *ring;
  2748. int per_ring_budget, work_done = 0;
  2749. bool clean_complete = true;
  2750. #ifdef CONFIG_IXGBE_DCA
  2751. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2752. ixgbe_update_dca(q_vector);
  2753. #endif
  2754. ixgbe_for_each_ring(ring, q_vector->tx) {
  2755. if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
  2756. clean_complete = false;
  2757. }
  2758. /* Exit if we are called by netpoll */
  2759. if (budget <= 0)
  2760. return budget;
  2761. /* attempt to distribute budget to each queue fairly, but don't allow
  2762. * the budget to go below 1 because we'll exit polling */
  2763. if (q_vector->rx.count > 1)
  2764. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2765. else
  2766. per_ring_budget = budget;
  2767. ixgbe_for_each_ring(ring, q_vector->rx) {
  2768. int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
  2769. per_ring_budget);
  2770. work_done += cleaned;
  2771. if (cleaned >= per_ring_budget)
  2772. clean_complete = false;
  2773. }
  2774. /* If all work not completed, return budget and keep polling */
  2775. if (!clean_complete)
  2776. return budget;
  2777. /* all work done, exit the polling mode */
  2778. napi_complete_done(napi, work_done);
  2779. if (adapter->rx_itr_setting & 1)
  2780. ixgbe_set_itr(q_vector);
  2781. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2782. ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
  2783. return min(work_done, budget - 1);
  2784. }
  2785. /**
  2786. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2787. * @adapter: board private structure
  2788. *
  2789. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2790. * interrupts from the kernel.
  2791. **/
  2792. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2793. {
  2794. struct net_device *netdev = adapter->netdev;
  2795. unsigned int ri = 0, ti = 0;
  2796. int vector, err;
  2797. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2798. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2799. struct msix_entry *entry = &adapter->msix_entries[vector];
  2800. if (q_vector->tx.ring && q_vector->rx.ring) {
  2801. snprintf(q_vector->name, sizeof(q_vector->name),
  2802. "%s-TxRx-%u", netdev->name, ri++);
  2803. ti++;
  2804. } else if (q_vector->rx.ring) {
  2805. snprintf(q_vector->name, sizeof(q_vector->name),
  2806. "%s-rx-%u", netdev->name, ri++);
  2807. } else if (q_vector->tx.ring) {
  2808. snprintf(q_vector->name, sizeof(q_vector->name),
  2809. "%s-tx-%u", netdev->name, ti++);
  2810. } else {
  2811. /* skip this unused q_vector */
  2812. continue;
  2813. }
  2814. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2815. q_vector->name, q_vector);
  2816. if (err) {
  2817. e_err(probe, "request_irq failed for MSIX interrupt "
  2818. "Error: %d\n", err);
  2819. goto free_queue_irqs;
  2820. }
  2821. /* If Flow Director is enabled, set interrupt affinity */
  2822. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2823. /* assign the mask for this irq */
  2824. irq_set_affinity_hint(entry->vector,
  2825. &q_vector->affinity_mask);
  2826. }
  2827. }
  2828. err = request_irq(adapter->msix_entries[vector].vector,
  2829. ixgbe_msix_other, 0, netdev->name, adapter);
  2830. if (err) {
  2831. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2832. goto free_queue_irqs;
  2833. }
  2834. return 0;
  2835. free_queue_irqs:
  2836. while (vector) {
  2837. vector--;
  2838. irq_set_affinity_hint(adapter->msix_entries[vector].vector,
  2839. NULL);
  2840. free_irq(adapter->msix_entries[vector].vector,
  2841. adapter->q_vector[vector]);
  2842. }
  2843. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2844. pci_disable_msix(adapter->pdev);
  2845. kfree(adapter->msix_entries);
  2846. adapter->msix_entries = NULL;
  2847. return err;
  2848. }
  2849. /**
  2850. * ixgbe_intr - legacy mode Interrupt Handler
  2851. * @irq: interrupt number
  2852. * @data: pointer to a network interface device structure
  2853. **/
  2854. static irqreturn_t ixgbe_intr(int irq, void *data)
  2855. {
  2856. struct ixgbe_adapter *adapter = data;
  2857. struct ixgbe_hw *hw = &adapter->hw;
  2858. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2859. u32 eicr;
  2860. /*
  2861. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2862. * before the read of EICR.
  2863. */
  2864. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2865. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2866. * therefore no explicit interrupt disable is necessary */
  2867. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2868. if (!eicr) {
  2869. /*
  2870. * shared interrupt alert!
  2871. * make sure interrupts are enabled because the read will
  2872. * have disabled interrupts due to EIAM
  2873. * finish the workaround of silicon errata on 82598. Unmask
  2874. * the interrupt that we masked before the EICR read.
  2875. */
  2876. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2877. ixgbe_irq_enable(adapter, true, true);
  2878. return IRQ_NONE; /* Not our interrupt */
  2879. }
  2880. if (eicr & IXGBE_EICR_LSC)
  2881. ixgbe_check_lsc(adapter);
  2882. switch (hw->mac.type) {
  2883. case ixgbe_mac_82599EB:
  2884. ixgbe_check_sfp_event(adapter, eicr);
  2885. /* Fall through */
  2886. case ixgbe_mac_X540:
  2887. case ixgbe_mac_X550:
  2888. case ixgbe_mac_X550EM_x:
  2889. case ixgbe_mac_x550em_a:
  2890. if (eicr & IXGBE_EICR_ECC) {
  2891. e_info(link, "Received ECC Err, initiating reset\n");
  2892. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2893. ixgbe_service_event_schedule(adapter);
  2894. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2895. }
  2896. ixgbe_check_overtemp_event(adapter, eicr);
  2897. break;
  2898. default:
  2899. break;
  2900. }
  2901. ixgbe_check_fan_failure(adapter, eicr);
  2902. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2903. ixgbe_ptp_check_pps_event(adapter);
  2904. /* would disable interrupts here but EIAM disabled it */
  2905. napi_schedule_irqoff(&q_vector->napi);
  2906. /*
  2907. * re-enable link(maybe) and non-queue interrupts, no flush.
  2908. * ixgbe_poll will re-enable the queue interrupts
  2909. */
  2910. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2911. ixgbe_irq_enable(adapter, false, false);
  2912. return IRQ_HANDLED;
  2913. }
  2914. /**
  2915. * ixgbe_request_irq - initialize interrupts
  2916. * @adapter: board private structure
  2917. *
  2918. * Attempts to configure interrupts using the best available
  2919. * capabilities of the hardware and kernel.
  2920. **/
  2921. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2922. {
  2923. struct net_device *netdev = adapter->netdev;
  2924. int err;
  2925. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2926. err = ixgbe_request_msix_irqs(adapter);
  2927. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2928. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2929. netdev->name, adapter);
  2930. else
  2931. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2932. netdev->name, adapter);
  2933. if (err)
  2934. e_err(probe, "request_irq failed, Error %d\n", err);
  2935. return err;
  2936. }
  2937. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2938. {
  2939. int vector;
  2940. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2941. free_irq(adapter->pdev->irq, adapter);
  2942. return;
  2943. }
  2944. if (!adapter->msix_entries)
  2945. return;
  2946. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2947. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2948. struct msix_entry *entry = &adapter->msix_entries[vector];
  2949. /* free only the irqs that were actually requested */
  2950. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2951. continue;
  2952. /* clear the affinity_mask in the IRQ descriptor */
  2953. irq_set_affinity_hint(entry->vector, NULL);
  2954. free_irq(entry->vector, q_vector);
  2955. }
  2956. free_irq(adapter->msix_entries[vector].vector, adapter);
  2957. }
  2958. /**
  2959. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2960. * @adapter: board private structure
  2961. **/
  2962. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2963. {
  2964. switch (adapter->hw.mac.type) {
  2965. case ixgbe_mac_82598EB:
  2966. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2967. break;
  2968. case ixgbe_mac_82599EB:
  2969. case ixgbe_mac_X540:
  2970. case ixgbe_mac_X550:
  2971. case ixgbe_mac_X550EM_x:
  2972. case ixgbe_mac_x550em_a:
  2973. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2974. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2975. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2976. break;
  2977. default:
  2978. break;
  2979. }
  2980. IXGBE_WRITE_FLUSH(&adapter->hw);
  2981. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2982. int vector;
  2983. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  2984. synchronize_irq(adapter->msix_entries[vector].vector);
  2985. synchronize_irq(adapter->msix_entries[vector++].vector);
  2986. } else {
  2987. synchronize_irq(adapter->pdev->irq);
  2988. }
  2989. }
  2990. /**
  2991. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2992. * @adapter: board private structure
  2993. *
  2994. **/
  2995. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2996. {
  2997. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2998. ixgbe_write_eitr(q_vector);
  2999. ixgbe_set_ivar(adapter, 0, 0, 0);
  3000. ixgbe_set_ivar(adapter, 1, 0, 0);
  3001. e_info(hw, "Legacy interrupt IVAR setup done\n");
  3002. }
  3003. /**
  3004. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  3005. * @adapter: board private structure
  3006. * @ring: structure containing ring specific data
  3007. *
  3008. * Configure the Tx descriptor ring after a reset.
  3009. **/
  3010. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  3011. struct ixgbe_ring *ring)
  3012. {
  3013. struct ixgbe_hw *hw = &adapter->hw;
  3014. u64 tdba = ring->dma;
  3015. int wait_loop = 10;
  3016. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  3017. u8 reg_idx = ring->reg_idx;
  3018. /* disable queue to avoid issues while updating state */
  3019. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  3020. IXGBE_WRITE_FLUSH(hw);
  3021. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  3022. (tdba & DMA_BIT_MASK(32)));
  3023. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  3024. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  3025. ring->count * sizeof(union ixgbe_adv_tx_desc));
  3026. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  3027. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  3028. ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
  3029. /*
  3030. * set WTHRESH to encourage burst writeback, it should not be set
  3031. * higher than 1 when:
  3032. * - ITR is 0 as it could cause false TX hangs
  3033. * - ITR is set to > 100k int/sec and BQL is enabled
  3034. *
  3035. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  3036. * to or less than the number of on chip descriptors, which is
  3037. * currently 40.
  3038. */
  3039. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  3040. txdctl |= 1u << 16; /* WTHRESH = 1 */
  3041. else
  3042. txdctl |= 8u << 16; /* WTHRESH = 8 */
  3043. /*
  3044. * Setting PTHRESH to 32 both improves performance
  3045. * and avoids a TX hang with DFP enabled
  3046. */
  3047. txdctl |= (1u << 8) | /* HTHRESH = 1 */
  3048. 32; /* PTHRESH = 32 */
  3049. /* reinitialize flowdirector state */
  3050. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  3051. ring->atr_sample_rate = adapter->atr_sample_rate;
  3052. ring->atr_count = 0;
  3053. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  3054. } else {
  3055. ring->atr_sample_rate = 0;
  3056. }
  3057. /* initialize XPS */
  3058. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  3059. struct ixgbe_q_vector *q_vector = ring->q_vector;
  3060. if (q_vector)
  3061. netif_set_xps_queue(ring->netdev,
  3062. &q_vector->affinity_mask,
  3063. ring->queue_index);
  3064. }
  3065. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  3066. /* reinitialize tx_buffer_info */
  3067. memset(ring->tx_buffer_info, 0,
  3068. sizeof(struct ixgbe_tx_buffer) * ring->count);
  3069. /* enable queue */
  3070. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  3071. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3072. if (hw->mac.type == ixgbe_mac_82598EB &&
  3073. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3074. return;
  3075. /* poll to verify queue is enabled */
  3076. do {
  3077. usleep_range(1000, 2000);
  3078. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  3079. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  3080. if (!wait_loop)
  3081. hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
  3082. }
  3083. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  3084. {
  3085. struct ixgbe_hw *hw = &adapter->hw;
  3086. u32 rttdcs, mtqc;
  3087. u8 tcs = adapter->hw_tcs;
  3088. if (hw->mac.type == ixgbe_mac_82598EB)
  3089. return;
  3090. /* disable the arbiter while setting MTQC */
  3091. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  3092. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  3093. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  3094. /* set transmit pool layout */
  3095. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3096. mtqc = IXGBE_MTQC_VT_ENA;
  3097. if (tcs > 4)
  3098. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  3099. else if (tcs > 1)
  3100. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3101. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3102. IXGBE_82599_VMDQ_4Q_MASK)
  3103. mtqc |= IXGBE_MTQC_32VF;
  3104. else
  3105. mtqc |= IXGBE_MTQC_64VF;
  3106. } else {
  3107. if (tcs > 4)
  3108. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  3109. else if (tcs > 1)
  3110. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3111. else
  3112. mtqc = IXGBE_MTQC_64Q_1PB;
  3113. }
  3114. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  3115. /* Enable Security TX Buffer IFG for multiple pb */
  3116. if (tcs) {
  3117. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  3118. sectx |= IXGBE_SECTX_DCB;
  3119. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  3120. }
  3121. /* re-enable the arbiter */
  3122. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  3123. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  3124. }
  3125. /**
  3126. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  3127. * @adapter: board private structure
  3128. *
  3129. * Configure the Tx unit of the MAC after a reset.
  3130. **/
  3131. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  3132. {
  3133. struct ixgbe_hw *hw = &adapter->hw;
  3134. u32 dmatxctl;
  3135. u32 i;
  3136. ixgbe_setup_mtqc(adapter);
  3137. if (hw->mac.type != ixgbe_mac_82598EB) {
  3138. /* DMATXCTL.EN must be before Tx queues are enabled */
  3139. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  3140. dmatxctl |= IXGBE_DMATXCTL_TE;
  3141. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  3142. }
  3143. /* Setup the HW Tx Head and Tail descriptor pointers */
  3144. for (i = 0; i < adapter->num_tx_queues; i++)
  3145. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  3146. for (i = 0; i < adapter->num_xdp_queues; i++)
  3147. ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
  3148. }
  3149. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  3150. struct ixgbe_ring *ring)
  3151. {
  3152. struct ixgbe_hw *hw = &adapter->hw;
  3153. u8 reg_idx = ring->reg_idx;
  3154. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  3155. srrctl |= IXGBE_SRRCTL_DROP_EN;
  3156. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3157. }
  3158. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  3159. struct ixgbe_ring *ring)
  3160. {
  3161. struct ixgbe_hw *hw = &adapter->hw;
  3162. u8 reg_idx = ring->reg_idx;
  3163. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  3164. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  3165. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3166. }
  3167. #ifdef CONFIG_IXGBE_DCB
  3168. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  3169. #else
  3170. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  3171. #endif
  3172. {
  3173. int i;
  3174. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  3175. if (adapter->ixgbe_ieee_pfc)
  3176. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  3177. /*
  3178. * We should set the drop enable bit if:
  3179. * SR-IOV is enabled
  3180. * or
  3181. * Number of Rx queues > 1 and flow control is disabled
  3182. *
  3183. * This allows us to avoid head of line blocking for security
  3184. * and performance reasons.
  3185. */
  3186. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  3187. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  3188. for (i = 0; i < adapter->num_rx_queues; i++)
  3189. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  3190. } else {
  3191. for (i = 0; i < adapter->num_rx_queues; i++)
  3192. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  3193. }
  3194. }
  3195. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  3196. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  3197. struct ixgbe_ring *rx_ring)
  3198. {
  3199. struct ixgbe_hw *hw = &adapter->hw;
  3200. u32 srrctl;
  3201. u8 reg_idx = rx_ring->reg_idx;
  3202. if (hw->mac.type == ixgbe_mac_82598EB) {
  3203. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  3204. /*
  3205. * if VMDq is not active we must program one srrctl register
  3206. * per RSS queue since we have enabled RDRXCTL.MVMEN
  3207. */
  3208. reg_idx &= mask;
  3209. }
  3210. /* configure header buffer length, needed for RSC */
  3211. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  3212. /* configure the packet buffer length */
  3213. if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
  3214. srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3215. else
  3216. srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3217. /* configure descriptor type */
  3218. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  3219. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3220. }
  3221. /**
  3222. * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
  3223. * @adapter: device handle
  3224. *
  3225. * - 82598/82599/X540: 128
  3226. * - X550(non-SRIOV mode): 512
  3227. * - X550(SRIOV mode): 64
  3228. */
  3229. u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
  3230. {
  3231. if (adapter->hw.mac.type < ixgbe_mac_X550)
  3232. return 128;
  3233. else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3234. return 64;
  3235. else
  3236. return 512;
  3237. }
  3238. /**
  3239. * ixgbe_store_key - Write the RSS key to HW
  3240. * @adapter: device handle
  3241. *
  3242. * Write the RSS key stored in adapter.rss_key to HW.
  3243. */
  3244. void ixgbe_store_key(struct ixgbe_adapter *adapter)
  3245. {
  3246. struct ixgbe_hw *hw = &adapter->hw;
  3247. int i;
  3248. for (i = 0; i < 10; i++)
  3249. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
  3250. }
  3251. /**
  3252. * ixgbe_init_rss_key - Initialize adapter RSS key
  3253. * @adapter: device handle
  3254. *
  3255. * Allocates and initializes the RSS key if it is not allocated.
  3256. **/
  3257. static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
  3258. {
  3259. u32 *rss_key;
  3260. if (!adapter->rss_key) {
  3261. rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
  3262. if (unlikely(!rss_key))
  3263. return -ENOMEM;
  3264. netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
  3265. adapter->rss_key = rss_key;
  3266. }
  3267. return 0;
  3268. }
  3269. /**
  3270. * ixgbe_store_reta - Write the RETA table to HW
  3271. * @adapter: device handle
  3272. *
  3273. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3274. */
  3275. void ixgbe_store_reta(struct ixgbe_adapter *adapter)
  3276. {
  3277. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3278. struct ixgbe_hw *hw = &adapter->hw;
  3279. u32 reta = 0;
  3280. u32 indices_multi;
  3281. u8 *indir_tbl = adapter->rss_indir_tbl;
  3282. /* Fill out the redirection table as follows:
  3283. * - 82598: 8 bit wide entries containing pair of 4 bit RSS
  3284. * indices.
  3285. * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
  3286. * - X550: 8 bit wide entries containing 6 bit RSS index
  3287. */
  3288. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  3289. indices_multi = 0x11;
  3290. else
  3291. indices_multi = 0x1;
  3292. /* Write redirection table to HW */
  3293. for (i = 0; i < reta_entries; i++) {
  3294. reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
  3295. if ((i & 3) == 3) {
  3296. if (i < 128)
  3297. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  3298. else
  3299. IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
  3300. reta);
  3301. reta = 0;
  3302. }
  3303. }
  3304. }
  3305. /**
  3306. * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
  3307. * @adapter: device handle
  3308. *
  3309. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3310. */
  3311. static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
  3312. {
  3313. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3314. struct ixgbe_hw *hw = &adapter->hw;
  3315. u32 vfreta = 0;
  3316. /* Write redirection table to HW */
  3317. for (i = 0; i < reta_entries; i++) {
  3318. u16 pool = adapter->num_rx_pools;
  3319. vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
  3320. if ((i & 3) != 3)
  3321. continue;
  3322. while (pool--)
  3323. IXGBE_WRITE_REG(hw,
  3324. IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
  3325. vfreta);
  3326. vfreta = 0;
  3327. }
  3328. }
  3329. static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
  3330. {
  3331. u32 i, j;
  3332. u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3333. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3334. /* Program table for at least 4 queues w/ SR-IOV so that VFs can
  3335. * make full use of any rings they may have. We will use the
  3336. * PSRTYPE register to control how many rings we use within the PF.
  3337. */
  3338. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
  3339. rss_i = 4;
  3340. /* Fill out hash function seeds */
  3341. ixgbe_store_key(adapter);
  3342. /* Fill out redirection table */
  3343. memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
  3344. for (i = 0, j = 0; i < reta_entries; i++, j++) {
  3345. if (j == rss_i)
  3346. j = 0;
  3347. adapter->rss_indir_tbl[i] = j;
  3348. }
  3349. ixgbe_store_reta(adapter);
  3350. }
  3351. static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
  3352. {
  3353. struct ixgbe_hw *hw = &adapter->hw;
  3354. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3355. int i, j;
  3356. /* Fill out hash function seeds */
  3357. for (i = 0; i < 10; i++) {
  3358. u16 pool = adapter->num_rx_pools;
  3359. while (pool--)
  3360. IXGBE_WRITE_REG(hw,
  3361. IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
  3362. *(adapter->rss_key + i));
  3363. }
  3364. /* Fill out the redirection table */
  3365. for (i = 0, j = 0; i < 64; i++, j++) {
  3366. if (j == rss_i)
  3367. j = 0;
  3368. adapter->rss_indir_tbl[i] = j;
  3369. }
  3370. ixgbe_store_vfreta(adapter);
  3371. }
  3372. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  3373. {
  3374. struct ixgbe_hw *hw = &adapter->hw;
  3375. u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
  3376. u32 rxcsum;
  3377. /* Disable indicating checksum in descriptor, enables RSS hash */
  3378. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  3379. rxcsum |= IXGBE_RXCSUM_PCSD;
  3380. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  3381. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3382. if (adapter->ring_feature[RING_F_RSS].mask)
  3383. mrqc = IXGBE_MRQC_RSSEN;
  3384. } else {
  3385. u8 tcs = adapter->hw_tcs;
  3386. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3387. if (tcs > 4)
  3388. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  3389. else if (tcs > 1)
  3390. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  3391. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3392. IXGBE_82599_VMDQ_4Q_MASK)
  3393. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  3394. else
  3395. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  3396. /* Enable L3/L4 for Tx Switched packets */
  3397. mrqc |= IXGBE_MRQC_L3L4TXSWEN;
  3398. } else {
  3399. if (tcs > 4)
  3400. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  3401. else if (tcs > 1)
  3402. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  3403. else
  3404. mrqc = IXGBE_MRQC_RSSEN;
  3405. }
  3406. }
  3407. /* Perform hash on these packet types */
  3408. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  3409. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  3410. IXGBE_MRQC_RSS_FIELD_IPV6 |
  3411. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  3412. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  3413. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  3414. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  3415. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  3416. if ((hw->mac.type >= ixgbe_mac_X550) &&
  3417. (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  3418. u16 pool = adapter->num_rx_pools;
  3419. /* Enable VF RSS mode */
  3420. mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
  3421. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3422. /* Setup RSS through the VF registers */
  3423. ixgbe_setup_vfreta(adapter);
  3424. vfmrqc = IXGBE_MRQC_RSSEN;
  3425. vfmrqc |= rss_field;
  3426. while (pool--)
  3427. IXGBE_WRITE_REG(hw,
  3428. IXGBE_PFVFMRQC(VMDQ_P(pool)),
  3429. vfmrqc);
  3430. } else {
  3431. ixgbe_setup_reta(adapter);
  3432. mrqc |= rss_field;
  3433. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3434. }
  3435. }
  3436. /**
  3437. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  3438. * @adapter: address of board private structure
  3439. * @ring: structure containing ring specific data
  3440. **/
  3441. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  3442. struct ixgbe_ring *ring)
  3443. {
  3444. struct ixgbe_hw *hw = &adapter->hw;
  3445. u32 rscctrl;
  3446. u8 reg_idx = ring->reg_idx;
  3447. if (!ring_is_rsc_enabled(ring))
  3448. return;
  3449. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  3450. rscctrl |= IXGBE_RSCCTL_RSCEN;
  3451. /*
  3452. * we must limit the number of descriptors so that the
  3453. * total size of max desc * buf_len is not greater
  3454. * than 65536
  3455. */
  3456. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  3457. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  3458. }
  3459. #define IXGBE_MAX_RX_DESC_POLL 10
  3460. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  3461. struct ixgbe_ring *ring)
  3462. {
  3463. struct ixgbe_hw *hw = &adapter->hw;
  3464. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3465. u32 rxdctl;
  3466. u8 reg_idx = ring->reg_idx;
  3467. if (ixgbe_removed(hw->hw_addr))
  3468. return;
  3469. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3470. if (hw->mac.type == ixgbe_mac_82598EB &&
  3471. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3472. return;
  3473. do {
  3474. usleep_range(1000, 2000);
  3475. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3476. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  3477. if (!wait_loop) {
  3478. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  3479. "the polling period\n", reg_idx);
  3480. }
  3481. }
  3482. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  3483. struct ixgbe_ring *ring)
  3484. {
  3485. struct ixgbe_hw *hw = &adapter->hw;
  3486. union ixgbe_adv_rx_desc *rx_desc;
  3487. u64 rdba = ring->dma;
  3488. u32 rxdctl;
  3489. u8 reg_idx = ring->reg_idx;
  3490. /* disable queue to avoid use of these values while updating state */
  3491. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3492. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  3493. /* write value back with RXDCTL.ENABLE bit cleared */
  3494. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3495. IXGBE_WRITE_FLUSH(hw);
  3496. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  3497. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  3498. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  3499. ring->count * sizeof(union ixgbe_adv_rx_desc));
  3500. /* Force flushing of IXGBE_RDLEN to prevent MDD */
  3501. IXGBE_WRITE_FLUSH(hw);
  3502. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  3503. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  3504. ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
  3505. ixgbe_configure_srrctl(adapter, ring);
  3506. ixgbe_configure_rscctl(adapter, ring);
  3507. if (hw->mac.type == ixgbe_mac_82598EB) {
  3508. /*
  3509. * enable cache line friendly hardware writes:
  3510. * PTHRESH=32 descriptors (half the internal cache),
  3511. * this also removes ugly rx_no_buffer_count increment
  3512. * HTHRESH=4 descriptors (to minimize latency on fetch)
  3513. * WTHRESH=8 burst writeback up to two cache lines
  3514. */
  3515. rxdctl &= ~0x3FFFFF;
  3516. rxdctl |= 0x080420;
  3517. #if (PAGE_SIZE < 8192)
  3518. /* RXDCTL.RLPML does not work on 82599 */
  3519. } else if (hw->mac.type != ixgbe_mac_82599EB) {
  3520. rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
  3521. IXGBE_RXDCTL_RLPML_EN);
  3522. /* Limit the maximum frame size so we don't overrun the skb.
  3523. * This can happen in SRIOV mode when the MTU of the VF is
  3524. * higher than the MTU of the PF.
  3525. */
  3526. if (ring_uses_build_skb(ring) &&
  3527. !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
  3528. rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
  3529. IXGBE_RXDCTL_RLPML_EN;
  3530. #endif
  3531. }
  3532. /* initialize rx_buffer_info */
  3533. memset(ring->rx_buffer_info, 0,
  3534. sizeof(struct ixgbe_rx_buffer) * ring->count);
  3535. /* initialize Rx descriptor 0 */
  3536. rx_desc = IXGBE_RX_DESC(ring, 0);
  3537. rx_desc->wb.upper.length = 0;
  3538. /* enable receive descriptor ring */
  3539. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3540. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3541. ixgbe_rx_desc_queue_enable(adapter, ring);
  3542. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  3543. }
  3544. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  3545. {
  3546. struct ixgbe_hw *hw = &adapter->hw;
  3547. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3548. u16 pool = adapter->num_rx_pools;
  3549. /* PSRTYPE must be initialized in non 82598 adapters */
  3550. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3551. IXGBE_PSRTYPE_UDPHDR |
  3552. IXGBE_PSRTYPE_IPV4HDR |
  3553. IXGBE_PSRTYPE_L2HDR |
  3554. IXGBE_PSRTYPE_IPV6HDR;
  3555. if (hw->mac.type == ixgbe_mac_82598EB)
  3556. return;
  3557. if (rss_i > 3)
  3558. psrtype |= 2u << 29;
  3559. else if (rss_i > 1)
  3560. psrtype |= 1u << 29;
  3561. while (pool--)
  3562. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3563. }
  3564. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  3565. {
  3566. struct ixgbe_hw *hw = &adapter->hw;
  3567. u16 pool = adapter->num_rx_pools;
  3568. u32 reg_offset, vf_shift, vmolr;
  3569. u32 gcr_ext, vmdctl;
  3570. int i;
  3571. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  3572. return;
  3573. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  3574. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  3575. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  3576. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  3577. vmdctl |= IXGBE_VT_CTL_REPLEN;
  3578. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  3579. /* accept untagged packets until a vlan tag is
  3580. * specifically set for the VMDQ queue/pool
  3581. */
  3582. vmolr = IXGBE_VMOLR_AUPE;
  3583. while (pool--)
  3584. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr);
  3585. vf_shift = VMDQ_P(0) % 32;
  3586. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  3587. /* Enable only the PF's pool for Tx/Rx */
  3588. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
  3589. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  3590. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
  3591. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  3592. if (adapter->bridge_mode == BRIDGE_MODE_VEB)
  3593. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  3594. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  3595. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  3596. /* clear VLAN promisc flag so VFTA will be updated if necessary */
  3597. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3598. /*
  3599. * Set up VF register offsets for selected VT Mode,
  3600. * i.e. 32 or 64 VFs for SR-IOV
  3601. */
  3602. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3603. case IXGBE_82599_VMDQ_8Q_MASK:
  3604. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  3605. break;
  3606. case IXGBE_82599_VMDQ_4Q_MASK:
  3607. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  3608. break;
  3609. default:
  3610. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  3611. break;
  3612. }
  3613. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3614. for (i = 0; i < adapter->num_vfs; i++) {
  3615. /* configure spoof checking */
  3616. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
  3617. adapter->vfinfo[i].spoofchk_enabled);
  3618. /* Enable/Disable RSS query feature */
  3619. ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
  3620. adapter->vfinfo[i].rss_query_enabled);
  3621. }
  3622. }
  3623. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  3624. {
  3625. struct ixgbe_hw *hw = &adapter->hw;
  3626. struct net_device *netdev = adapter->netdev;
  3627. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3628. struct ixgbe_ring *rx_ring;
  3629. int i;
  3630. u32 mhadd, hlreg0;
  3631. #ifdef IXGBE_FCOE
  3632. /* adjust max frame to be able to do baby jumbo for FCoE */
  3633. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  3634. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  3635. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3636. #endif /* IXGBE_FCOE */
  3637. /* adjust max frame to be at least the size of a standard frame */
  3638. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  3639. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  3640. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  3641. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  3642. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  3643. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  3644. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  3645. }
  3646. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3647. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  3648. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  3649. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3650. /*
  3651. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3652. * the Base and Length of the Rx Descriptor Ring
  3653. */
  3654. for (i = 0; i < adapter->num_rx_queues; i++) {
  3655. rx_ring = adapter->rx_ring[i];
  3656. clear_ring_rsc_enabled(rx_ring);
  3657. clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3658. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3659. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3660. set_ring_rsc_enabled(rx_ring);
  3661. if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
  3662. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3663. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3664. if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
  3665. continue;
  3666. set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3667. #if (PAGE_SIZE < 8192)
  3668. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3669. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3670. if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
  3671. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  3672. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3673. #endif
  3674. }
  3675. }
  3676. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  3677. {
  3678. struct ixgbe_hw *hw = &adapter->hw;
  3679. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  3680. switch (hw->mac.type) {
  3681. case ixgbe_mac_82598EB:
  3682. /*
  3683. * For VMDq support of different descriptor types or
  3684. * buffer sizes through the use of multiple SRRCTL
  3685. * registers, RDRXCTL.MVMEN must be set to 1
  3686. *
  3687. * also, the manual doesn't mention it clearly but DCA hints
  3688. * will only use queue 0's tags unless this bit is set. Side
  3689. * effects of setting this bit are only that SRRCTL must be
  3690. * fully programmed [0..15]
  3691. */
  3692. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  3693. break;
  3694. case ixgbe_mac_X550:
  3695. case ixgbe_mac_X550EM_x:
  3696. case ixgbe_mac_x550em_a:
  3697. if (adapter->num_vfs)
  3698. rdrxctl |= IXGBE_RDRXCTL_PSP;
  3699. /* fall through */
  3700. case ixgbe_mac_82599EB:
  3701. case ixgbe_mac_X540:
  3702. /* Disable RSC for ACK packets */
  3703. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  3704. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  3705. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  3706. /* hardware requires some bits to be set by default */
  3707. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  3708. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  3709. break;
  3710. default:
  3711. /* We should do nothing since we don't know this hardware */
  3712. return;
  3713. }
  3714. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  3715. }
  3716. /**
  3717. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  3718. * @adapter: board private structure
  3719. *
  3720. * Configure the Rx unit of the MAC after a reset.
  3721. **/
  3722. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  3723. {
  3724. struct ixgbe_hw *hw = &adapter->hw;
  3725. int i;
  3726. u32 rxctrl, rfctl;
  3727. /* disable receives while setting up the descriptors */
  3728. hw->mac.ops.disable_rx(hw);
  3729. ixgbe_setup_psrtype(adapter);
  3730. ixgbe_setup_rdrxctl(adapter);
  3731. /* RSC Setup */
  3732. rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  3733. rfctl &= ~IXGBE_RFCTL_RSC_DIS;
  3734. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  3735. rfctl |= IXGBE_RFCTL_RSC_DIS;
  3736. /* disable NFS filtering */
  3737. rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
  3738. IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
  3739. /* Program registers for the distribution of queues */
  3740. ixgbe_setup_mrqc(adapter);
  3741. /* set_rx_buffer_len must be called before ring initialization */
  3742. ixgbe_set_rx_buffer_len(adapter);
  3743. /*
  3744. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3745. * the Base and Length of the Rx Descriptor Ring
  3746. */
  3747. for (i = 0; i < adapter->num_rx_queues; i++)
  3748. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  3749. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3750. /* disable drop enable for 82598 parts */
  3751. if (hw->mac.type == ixgbe_mac_82598EB)
  3752. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  3753. /* enable all receives */
  3754. rxctrl |= IXGBE_RXCTRL_RXEN;
  3755. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  3756. }
  3757. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  3758. __be16 proto, u16 vid)
  3759. {
  3760. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3761. struct ixgbe_hw *hw = &adapter->hw;
  3762. /* add VID to filter table */
  3763. if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3764. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
  3765. set_bit(vid, adapter->active_vlans);
  3766. return 0;
  3767. }
  3768. static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
  3769. {
  3770. u32 vlvf;
  3771. int idx;
  3772. /* short cut the special case */
  3773. if (vlan == 0)
  3774. return 0;
  3775. /* Search for the vlan id in the VLVF entries */
  3776. for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
  3777. vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
  3778. if ((vlvf & VLAN_VID_MASK) == vlan)
  3779. break;
  3780. }
  3781. return idx;
  3782. }
  3783. void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
  3784. {
  3785. struct ixgbe_hw *hw = &adapter->hw;
  3786. u32 bits, word;
  3787. int idx;
  3788. idx = ixgbe_find_vlvf_entry(hw, vid);
  3789. if (!idx)
  3790. return;
  3791. /* See if any other pools are set for this VLAN filter
  3792. * entry other than the PF.
  3793. */
  3794. word = idx * 2 + (VMDQ_P(0) / 32);
  3795. bits = ~BIT(VMDQ_P(0) % 32);
  3796. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3797. /* Disable the filter so this falls into the default pool. */
  3798. if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
  3799. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3800. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
  3801. IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
  3802. }
  3803. }
  3804. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  3805. __be16 proto, u16 vid)
  3806. {
  3807. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3808. struct ixgbe_hw *hw = &adapter->hw;
  3809. /* remove VID from filter table */
  3810. if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3811. hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
  3812. clear_bit(vid, adapter->active_vlans);
  3813. return 0;
  3814. }
  3815. /**
  3816. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3817. * @adapter: driver data
  3818. */
  3819. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3820. {
  3821. struct ixgbe_hw *hw = &adapter->hw;
  3822. u32 vlnctrl;
  3823. int i, j;
  3824. switch (hw->mac.type) {
  3825. case ixgbe_mac_82598EB:
  3826. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3827. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3828. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3829. break;
  3830. case ixgbe_mac_82599EB:
  3831. case ixgbe_mac_X540:
  3832. case ixgbe_mac_X550:
  3833. case ixgbe_mac_X550EM_x:
  3834. case ixgbe_mac_x550em_a:
  3835. for (i = 0; i < adapter->num_rx_queues; i++) {
  3836. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3837. if (!netif_is_ixgbe(ring->netdev))
  3838. continue;
  3839. j = ring->reg_idx;
  3840. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3841. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3842. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3843. }
  3844. break;
  3845. default:
  3846. break;
  3847. }
  3848. }
  3849. /**
  3850. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3851. * @adapter: driver data
  3852. */
  3853. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3854. {
  3855. struct ixgbe_hw *hw = &adapter->hw;
  3856. u32 vlnctrl;
  3857. int i, j;
  3858. switch (hw->mac.type) {
  3859. case ixgbe_mac_82598EB:
  3860. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3861. vlnctrl |= IXGBE_VLNCTRL_VME;
  3862. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3863. break;
  3864. case ixgbe_mac_82599EB:
  3865. case ixgbe_mac_X540:
  3866. case ixgbe_mac_X550:
  3867. case ixgbe_mac_X550EM_x:
  3868. case ixgbe_mac_x550em_a:
  3869. for (i = 0; i < adapter->num_rx_queues; i++) {
  3870. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3871. if (!netif_is_ixgbe(ring->netdev))
  3872. continue;
  3873. j = ring->reg_idx;
  3874. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3875. vlnctrl |= IXGBE_RXDCTL_VME;
  3876. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3877. }
  3878. break;
  3879. default:
  3880. break;
  3881. }
  3882. }
  3883. static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
  3884. {
  3885. struct ixgbe_hw *hw = &adapter->hw;
  3886. u32 vlnctrl, i;
  3887. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3888. if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
  3889. /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
  3890. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3891. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3892. } else {
  3893. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  3894. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3895. return;
  3896. }
  3897. /* Nothing to do for 82598 */
  3898. if (hw->mac.type == ixgbe_mac_82598EB)
  3899. return;
  3900. /* We are already in VLAN promisc, nothing to do */
  3901. if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
  3902. return;
  3903. /* Set flag so we don't redo unnecessary work */
  3904. adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
  3905. /* Add PF to all active pools */
  3906. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3907. u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
  3908. u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
  3909. vlvfb |= BIT(VMDQ_P(0) % 32);
  3910. IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
  3911. }
  3912. /* Set all bits in the VLAN filter table array */
  3913. for (i = hw->mac.vft_size; i--;)
  3914. IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
  3915. }
  3916. #define VFTA_BLOCK_SIZE 8
  3917. static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
  3918. {
  3919. struct ixgbe_hw *hw = &adapter->hw;
  3920. u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
  3921. u32 vid_start = vfta_offset * 32;
  3922. u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
  3923. u32 i, vid, word, bits;
  3924. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3925. u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
  3926. /* pull VLAN ID from VLVF */
  3927. vid = vlvf & VLAN_VID_MASK;
  3928. /* only concern outselves with a certain range */
  3929. if (vid < vid_start || vid >= vid_end)
  3930. continue;
  3931. if (vlvf) {
  3932. /* record VLAN ID in VFTA */
  3933. vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
  3934. /* if PF is part of this then continue */
  3935. if (test_bit(vid, adapter->active_vlans))
  3936. continue;
  3937. }
  3938. /* remove PF from the pool */
  3939. word = i * 2 + VMDQ_P(0) / 32;
  3940. bits = ~BIT(VMDQ_P(0) % 32);
  3941. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3942. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
  3943. }
  3944. /* extract values from active_vlans and write back to VFTA */
  3945. for (i = VFTA_BLOCK_SIZE; i--;) {
  3946. vid = (vfta_offset + i) * 32;
  3947. word = vid / BITS_PER_LONG;
  3948. bits = vid % BITS_PER_LONG;
  3949. vfta[i] |= adapter->active_vlans[word] >> bits;
  3950. IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
  3951. }
  3952. }
  3953. static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
  3954. {
  3955. struct ixgbe_hw *hw = &adapter->hw;
  3956. u32 vlnctrl, i;
  3957. /* Set VLAN filtering to enabled */
  3958. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3959. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3960. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3961. if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
  3962. hw->mac.type == ixgbe_mac_82598EB)
  3963. return;
  3964. /* We are not in VLAN promisc, nothing to do */
  3965. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3966. return;
  3967. /* Set flag so we don't redo unnecessary work */
  3968. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3969. for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
  3970. ixgbe_scrub_vfta(adapter, i);
  3971. }
  3972. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  3973. {
  3974. u16 vid = 1;
  3975. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  3976. for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
  3977. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  3978. }
  3979. /**
  3980. * ixgbe_write_mc_addr_list - write multicast addresses to MTA
  3981. * @netdev: network interface device structure
  3982. *
  3983. * Writes multicast address list to the MTA hash table.
  3984. * Returns: -ENOMEM on failure
  3985. * 0 on no addresses written
  3986. * X on writing X addresses to MTA
  3987. **/
  3988. static int ixgbe_write_mc_addr_list(struct net_device *netdev)
  3989. {
  3990. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3991. struct ixgbe_hw *hw = &adapter->hw;
  3992. if (!netif_running(netdev))
  3993. return 0;
  3994. if (hw->mac.ops.update_mc_addr_list)
  3995. hw->mac.ops.update_mc_addr_list(hw, netdev);
  3996. else
  3997. return -ENOMEM;
  3998. #ifdef CONFIG_PCI_IOV
  3999. ixgbe_restore_vf_multicasts(adapter);
  4000. #endif
  4001. return netdev_mc_count(netdev);
  4002. }
  4003. #ifdef CONFIG_PCI_IOV
  4004. void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
  4005. {
  4006. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4007. struct ixgbe_hw *hw = &adapter->hw;
  4008. int i;
  4009. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4010. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  4011. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4012. hw->mac.ops.set_rar(hw, i,
  4013. mac_table->addr,
  4014. mac_table->pool,
  4015. IXGBE_RAH_AV);
  4016. else
  4017. hw->mac.ops.clear_rar(hw, i);
  4018. }
  4019. }
  4020. #endif
  4021. static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
  4022. {
  4023. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4024. struct ixgbe_hw *hw = &adapter->hw;
  4025. int i;
  4026. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4027. if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
  4028. continue;
  4029. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  4030. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4031. hw->mac.ops.set_rar(hw, i,
  4032. mac_table->addr,
  4033. mac_table->pool,
  4034. IXGBE_RAH_AV);
  4035. else
  4036. hw->mac.ops.clear_rar(hw, i);
  4037. }
  4038. }
  4039. static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
  4040. {
  4041. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4042. struct ixgbe_hw *hw = &adapter->hw;
  4043. int i;
  4044. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4045. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  4046. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  4047. }
  4048. ixgbe_sync_mac_table(adapter);
  4049. }
  4050. static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
  4051. {
  4052. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4053. struct ixgbe_hw *hw = &adapter->hw;
  4054. int i, count = 0;
  4055. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4056. /* do not count default RAR as available */
  4057. if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
  4058. continue;
  4059. /* only count unused and addresses that belong to us */
  4060. if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
  4061. if (mac_table->pool != pool)
  4062. continue;
  4063. }
  4064. count++;
  4065. }
  4066. return count;
  4067. }
  4068. /* this function destroys the first RAR entry */
  4069. static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
  4070. {
  4071. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4072. struct ixgbe_hw *hw = &adapter->hw;
  4073. memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
  4074. mac_table->pool = VMDQ_P(0);
  4075. mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
  4076. hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
  4077. IXGBE_RAH_AV);
  4078. }
  4079. int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
  4080. const u8 *addr, u16 pool)
  4081. {
  4082. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4083. struct ixgbe_hw *hw = &adapter->hw;
  4084. int i;
  4085. if (is_zero_ether_addr(addr))
  4086. return -EINVAL;
  4087. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4088. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4089. continue;
  4090. ether_addr_copy(mac_table->addr, addr);
  4091. mac_table->pool = pool;
  4092. mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
  4093. IXGBE_MAC_STATE_IN_USE;
  4094. ixgbe_sync_mac_table(adapter);
  4095. return i;
  4096. }
  4097. return -ENOMEM;
  4098. }
  4099. int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
  4100. const u8 *addr, u16 pool)
  4101. {
  4102. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4103. struct ixgbe_hw *hw = &adapter->hw;
  4104. int i;
  4105. if (is_zero_ether_addr(addr))
  4106. return -EINVAL;
  4107. /* search table for addr, if found clear IN_USE flag and sync */
  4108. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4109. /* we can only delete an entry if it is in use */
  4110. if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
  4111. continue;
  4112. /* we only care about entries that belong to the given pool */
  4113. if (mac_table->pool != pool)
  4114. continue;
  4115. /* we only care about a specific MAC address */
  4116. if (!ether_addr_equal(addr, mac_table->addr))
  4117. continue;
  4118. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  4119. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  4120. ixgbe_sync_mac_table(adapter);
  4121. return 0;
  4122. }
  4123. return -ENOMEM;
  4124. }
  4125. static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
  4126. {
  4127. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4128. int ret;
  4129. ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
  4130. return min_t(int, ret, 0);
  4131. }
  4132. static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
  4133. {
  4134. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4135. ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
  4136. return 0;
  4137. }
  4138. /**
  4139. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  4140. * @netdev: network interface device structure
  4141. *
  4142. * The set_rx_method entry point is called whenever the unicast/multicast
  4143. * address list or the network interface flags are updated. This routine is
  4144. * responsible for configuring the hardware for proper unicast, multicast and
  4145. * promiscuous mode.
  4146. **/
  4147. void ixgbe_set_rx_mode(struct net_device *netdev)
  4148. {
  4149. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4150. struct ixgbe_hw *hw = &adapter->hw;
  4151. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  4152. netdev_features_t features = netdev->features;
  4153. int count;
  4154. /* Check for Promiscuous and All Multicast modes */
  4155. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4156. /* set all bits that we expect to always be set */
  4157. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  4158. fctrl |= IXGBE_FCTRL_BAM;
  4159. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  4160. fctrl |= IXGBE_FCTRL_PMCF;
  4161. /* clear the bits we are changing the status of */
  4162. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  4163. if (netdev->flags & IFF_PROMISC) {
  4164. hw->addr_ctrl.user_set_promisc = true;
  4165. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  4166. vmolr |= IXGBE_VMOLR_MPE;
  4167. features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4168. } else {
  4169. if (netdev->flags & IFF_ALLMULTI) {
  4170. fctrl |= IXGBE_FCTRL_MPE;
  4171. vmolr |= IXGBE_VMOLR_MPE;
  4172. }
  4173. hw->addr_ctrl.user_set_promisc = false;
  4174. }
  4175. /*
  4176. * Write addresses to available RAR registers, if there is not
  4177. * sufficient space to store all the addresses then enable
  4178. * unicast promiscuous mode
  4179. */
  4180. if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
  4181. fctrl |= IXGBE_FCTRL_UPE;
  4182. vmolr |= IXGBE_VMOLR_ROPE;
  4183. }
  4184. /* Write addresses to the MTA, if the attempt fails
  4185. * then we should just turn on promiscuous mode so
  4186. * that we can at least receive multicast traffic
  4187. */
  4188. count = ixgbe_write_mc_addr_list(netdev);
  4189. if (count < 0) {
  4190. fctrl |= IXGBE_FCTRL_MPE;
  4191. vmolr |= IXGBE_VMOLR_MPE;
  4192. } else if (count) {
  4193. vmolr |= IXGBE_VMOLR_ROMPE;
  4194. }
  4195. if (hw->mac.type != ixgbe_mac_82598EB) {
  4196. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  4197. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  4198. IXGBE_VMOLR_ROPE);
  4199. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  4200. }
  4201. /* This is useful for sniffing bad packets. */
  4202. if (features & NETIF_F_RXALL) {
  4203. /* UPE and MPE will be handled by normal PROMISC logic
  4204. * in e1000e_set_rx_mode */
  4205. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  4206. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  4207. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  4208. fctrl &= ~(IXGBE_FCTRL_DPF);
  4209. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  4210. }
  4211. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4212. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  4213. ixgbe_vlan_strip_enable(adapter);
  4214. else
  4215. ixgbe_vlan_strip_disable(adapter);
  4216. if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
  4217. ixgbe_vlan_promisc_disable(adapter);
  4218. else
  4219. ixgbe_vlan_promisc_enable(adapter);
  4220. }
  4221. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  4222. {
  4223. int q_idx;
  4224. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4225. napi_enable(&adapter->q_vector[q_idx]->napi);
  4226. }
  4227. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  4228. {
  4229. int q_idx;
  4230. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4231. napi_disable(&adapter->q_vector[q_idx]->napi);
  4232. }
  4233. static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
  4234. {
  4235. struct ixgbe_hw *hw = &adapter->hw;
  4236. u32 vxlanctrl;
  4237. if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
  4238. IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
  4239. return;
  4240. vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
  4241. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
  4242. if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
  4243. adapter->vxlan_port = 0;
  4244. if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
  4245. adapter->geneve_port = 0;
  4246. }
  4247. #ifdef CONFIG_IXGBE_DCB
  4248. /**
  4249. * ixgbe_configure_dcb - Configure DCB hardware
  4250. * @adapter: ixgbe adapter struct
  4251. *
  4252. * This is called by the driver on open to configure the DCB hardware.
  4253. * This is also called by the gennetlink interface when reconfiguring
  4254. * the DCB state.
  4255. */
  4256. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  4257. {
  4258. struct ixgbe_hw *hw = &adapter->hw;
  4259. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4260. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  4261. if (hw->mac.type == ixgbe_mac_82598EB)
  4262. netif_set_gso_max_size(adapter->netdev, 65536);
  4263. return;
  4264. }
  4265. if (hw->mac.type == ixgbe_mac_82598EB)
  4266. netif_set_gso_max_size(adapter->netdev, 32768);
  4267. #ifdef IXGBE_FCOE
  4268. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  4269. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  4270. #endif
  4271. /* reconfigure the hardware */
  4272. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  4273. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4274. DCB_TX_CONFIG);
  4275. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4276. DCB_RX_CONFIG);
  4277. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  4278. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  4279. ixgbe_dcb_hw_ets(&adapter->hw,
  4280. adapter->ixgbe_ieee_ets,
  4281. max_frame);
  4282. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  4283. adapter->ixgbe_ieee_pfc->pfc_en,
  4284. adapter->ixgbe_ieee_ets->prio_tc);
  4285. }
  4286. /* Enable RSS Hash per TC */
  4287. if (hw->mac.type != ixgbe_mac_82598EB) {
  4288. u32 msb = 0;
  4289. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  4290. while (rss_i) {
  4291. msb++;
  4292. rss_i >>= 1;
  4293. }
  4294. /* write msb to all 8 TCs in one write */
  4295. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  4296. }
  4297. }
  4298. #endif
  4299. /* Additional bittime to account for IXGBE framing */
  4300. #define IXGBE_ETH_FRAMING 20
  4301. /**
  4302. * ixgbe_hpbthresh - calculate high water mark for flow control
  4303. *
  4304. * @adapter: board private structure to calculate for
  4305. * @pb: packet buffer to calculate
  4306. */
  4307. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  4308. {
  4309. struct ixgbe_hw *hw = &adapter->hw;
  4310. struct net_device *dev = adapter->netdev;
  4311. int link, tc, kb, marker;
  4312. u32 dv_id, rx_pba;
  4313. /* Calculate max LAN frame size */
  4314. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  4315. #ifdef IXGBE_FCOE
  4316. /* FCoE traffic class uses FCOE jumbo frames */
  4317. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4318. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4319. (pb == ixgbe_fcoe_get_tc(adapter)))
  4320. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4321. #endif
  4322. /* Calculate delay value for device */
  4323. switch (hw->mac.type) {
  4324. case ixgbe_mac_X540:
  4325. case ixgbe_mac_X550:
  4326. case ixgbe_mac_X550EM_x:
  4327. case ixgbe_mac_x550em_a:
  4328. dv_id = IXGBE_DV_X540(link, tc);
  4329. break;
  4330. default:
  4331. dv_id = IXGBE_DV(link, tc);
  4332. break;
  4333. }
  4334. /* Loopback switch introduces additional latency */
  4335. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4336. dv_id += IXGBE_B2BT(tc);
  4337. /* Delay value is calculated in bit times convert to KB */
  4338. kb = IXGBE_BT2KB(dv_id);
  4339. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  4340. marker = rx_pba - kb;
  4341. /* It is possible that the packet buffer is not large enough
  4342. * to provide required headroom. In this case throw an error
  4343. * to user and a do the best we can.
  4344. */
  4345. if (marker < 0) {
  4346. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  4347. "headroom to support flow control."
  4348. "Decrease MTU or number of traffic classes\n", pb);
  4349. marker = tc + 1;
  4350. }
  4351. return marker;
  4352. }
  4353. /**
  4354. * ixgbe_lpbthresh - calculate low water mark for for flow control
  4355. *
  4356. * @adapter: board private structure to calculate for
  4357. * @pb: packet buffer to calculate
  4358. */
  4359. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
  4360. {
  4361. struct ixgbe_hw *hw = &adapter->hw;
  4362. struct net_device *dev = adapter->netdev;
  4363. int tc;
  4364. u32 dv_id;
  4365. /* Calculate max LAN frame size */
  4366. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4367. #ifdef IXGBE_FCOE
  4368. /* FCoE traffic class uses FCOE jumbo frames */
  4369. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4370. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4371. (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
  4372. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4373. #endif
  4374. /* Calculate delay value for device */
  4375. switch (hw->mac.type) {
  4376. case ixgbe_mac_X540:
  4377. case ixgbe_mac_X550:
  4378. case ixgbe_mac_X550EM_x:
  4379. case ixgbe_mac_x550em_a:
  4380. dv_id = IXGBE_LOW_DV_X540(tc);
  4381. break;
  4382. default:
  4383. dv_id = IXGBE_LOW_DV(tc);
  4384. break;
  4385. }
  4386. /* Delay value is calculated in bit times convert to KB */
  4387. return IXGBE_BT2KB(dv_id);
  4388. }
  4389. /*
  4390. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  4391. */
  4392. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  4393. {
  4394. struct ixgbe_hw *hw = &adapter->hw;
  4395. int num_tc = adapter->hw_tcs;
  4396. int i;
  4397. if (!num_tc)
  4398. num_tc = 1;
  4399. for (i = 0; i < num_tc; i++) {
  4400. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  4401. hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
  4402. /* Low water marks must not be larger than high water marks */
  4403. if (hw->fc.low_water[i] > hw->fc.high_water[i])
  4404. hw->fc.low_water[i] = 0;
  4405. }
  4406. for (; i < MAX_TRAFFIC_CLASS; i++)
  4407. hw->fc.high_water[i] = 0;
  4408. }
  4409. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  4410. {
  4411. struct ixgbe_hw *hw = &adapter->hw;
  4412. int hdrm;
  4413. u8 tc = adapter->hw_tcs;
  4414. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  4415. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  4416. hdrm = 32 << adapter->fdir_pballoc;
  4417. else
  4418. hdrm = 0;
  4419. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  4420. ixgbe_pbthresh_setup(adapter);
  4421. }
  4422. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  4423. {
  4424. struct ixgbe_hw *hw = &adapter->hw;
  4425. struct hlist_node *node2;
  4426. struct ixgbe_fdir_filter *filter;
  4427. spin_lock(&adapter->fdir_perfect_lock);
  4428. if (!hlist_empty(&adapter->fdir_filter_list))
  4429. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  4430. hlist_for_each_entry_safe(filter, node2,
  4431. &adapter->fdir_filter_list, fdir_node) {
  4432. ixgbe_fdir_write_perfect_filter_82599(hw,
  4433. &filter->filter,
  4434. filter->sw_idx,
  4435. (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
  4436. IXGBE_FDIR_DROP_QUEUE :
  4437. adapter->rx_ring[filter->action]->reg_idx);
  4438. }
  4439. spin_unlock(&adapter->fdir_perfect_lock);
  4440. }
  4441. /**
  4442. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  4443. * @rx_ring: ring to free buffers from
  4444. **/
  4445. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  4446. {
  4447. u16 i = rx_ring->next_to_clean;
  4448. struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
  4449. /* Free all the Rx ring sk_buffs */
  4450. while (i != rx_ring->next_to_alloc) {
  4451. if (rx_buffer->skb) {
  4452. struct sk_buff *skb = rx_buffer->skb;
  4453. if (IXGBE_CB(skb)->page_released)
  4454. dma_unmap_page_attrs(rx_ring->dev,
  4455. IXGBE_CB(skb)->dma,
  4456. ixgbe_rx_pg_size(rx_ring),
  4457. DMA_FROM_DEVICE,
  4458. IXGBE_RX_DMA_ATTR);
  4459. dev_kfree_skb(skb);
  4460. }
  4461. /* Invalidate cache lines that may have been written to by
  4462. * device so that we avoid corrupting memory.
  4463. */
  4464. dma_sync_single_range_for_cpu(rx_ring->dev,
  4465. rx_buffer->dma,
  4466. rx_buffer->page_offset,
  4467. ixgbe_rx_bufsz(rx_ring),
  4468. DMA_FROM_DEVICE);
  4469. /* free resources associated with mapping */
  4470. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  4471. ixgbe_rx_pg_size(rx_ring),
  4472. DMA_FROM_DEVICE,
  4473. IXGBE_RX_DMA_ATTR);
  4474. __page_frag_cache_drain(rx_buffer->page,
  4475. rx_buffer->pagecnt_bias);
  4476. i++;
  4477. rx_buffer++;
  4478. if (i == rx_ring->count) {
  4479. i = 0;
  4480. rx_buffer = rx_ring->rx_buffer_info;
  4481. }
  4482. }
  4483. rx_ring->next_to_alloc = 0;
  4484. rx_ring->next_to_clean = 0;
  4485. rx_ring->next_to_use = 0;
  4486. }
  4487. static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
  4488. struct ixgbe_fwd_adapter *accel)
  4489. {
  4490. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  4491. int num_tc = netdev_get_num_tc(adapter->netdev);
  4492. struct net_device *vdev = accel->netdev;
  4493. int i, baseq, err;
  4494. baseq = accel->pool * adapter->num_rx_queues_per_pool;
  4495. netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
  4496. accel->pool, adapter->num_rx_pools,
  4497. baseq, baseq + adapter->num_rx_queues_per_pool);
  4498. accel->rx_base_queue = baseq;
  4499. accel->tx_base_queue = baseq;
  4500. /* record configuration for macvlan interface in vdev */
  4501. for (i = 0; i < num_tc; i++)
  4502. netdev_bind_sb_channel_queue(adapter->netdev, vdev,
  4503. i, rss_i, baseq + (rss_i * i));
  4504. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4505. adapter->rx_ring[baseq + i]->netdev = vdev;
  4506. /* Guarantee all rings are updated before we update the
  4507. * MAC address filter.
  4508. */
  4509. wmb();
  4510. /* ixgbe_add_mac_filter will return an index if it succeeds, so we
  4511. * need to only treat it as an error value if it is negative.
  4512. */
  4513. err = ixgbe_add_mac_filter(adapter, vdev->dev_addr,
  4514. VMDQ_P(accel->pool));
  4515. if (err >= 0)
  4516. return 0;
  4517. /* if we cannot add the MAC rule then disable the offload */
  4518. macvlan_release_l2fw_offload(vdev);
  4519. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4520. adapter->rx_ring[baseq + i]->netdev = NULL;
  4521. netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n");
  4522. /* unbind the queues and drop the subordinate channel config */
  4523. netdev_unbind_sb_channel(adapter->netdev, vdev);
  4524. netdev_set_sb_channel(vdev, 0);
  4525. clear_bit(accel->pool, adapter->fwd_bitmask);
  4526. kfree(accel);
  4527. return err;
  4528. }
  4529. static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
  4530. {
  4531. struct ixgbe_adapter *adapter = data;
  4532. struct ixgbe_fwd_adapter *accel;
  4533. if (!netif_is_macvlan(vdev))
  4534. return 0;
  4535. accel = macvlan_accel_priv(vdev);
  4536. if (!accel)
  4537. return 0;
  4538. ixgbe_fwd_ring_up(adapter, accel);
  4539. return 0;
  4540. }
  4541. static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
  4542. {
  4543. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4544. ixgbe_macvlan_up, adapter);
  4545. }
  4546. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  4547. {
  4548. struct ixgbe_hw *hw = &adapter->hw;
  4549. ixgbe_configure_pb(adapter);
  4550. #ifdef CONFIG_IXGBE_DCB
  4551. ixgbe_configure_dcb(adapter);
  4552. #endif
  4553. /*
  4554. * We must restore virtualization before VLANs or else
  4555. * the VLVF registers will not be populated
  4556. */
  4557. ixgbe_configure_virtualization(adapter);
  4558. ixgbe_set_rx_mode(adapter->netdev);
  4559. ixgbe_restore_vlan(adapter);
  4560. ixgbe_ipsec_restore(adapter);
  4561. switch (hw->mac.type) {
  4562. case ixgbe_mac_82599EB:
  4563. case ixgbe_mac_X540:
  4564. hw->mac.ops.disable_rx_buff(hw);
  4565. break;
  4566. default:
  4567. break;
  4568. }
  4569. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4570. ixgbe_init_fdir_signature_82599(&adapter->hw,
  4571. adapter->fdir_pballoc);
  4572. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  4573. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  4574. adapter->fdir_pballoc);
  4575. ixgbe_fdir_filter_restore(adapter);
  4576. }
  4577. switch (hw->mac.type) {
  4578. case ixgbe_mac_82599EB:
  4579. case ixgbe_mac_X540:
  4580. hw->mac.ops.enable_rx_buff(hw);
  4581. break;
  4582. default:
  4583. break;
  4584. }
  4585. #ifdef CONFIG_IXGBE_DCA
  4586. /* configure DCA */
  4587. if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
  4588. ixgbe_setup_dca(adapter);
  4589. #endif /* CONFIG_IXGBE_DCA */
  4590. #ifdef IXGBE_FCOE
  4591. /* configure FCoE L2 filters, redirection table, and Rx control */
  4592. ixgbe_configure_fcoe(adapter);
  4593. #endif /* IXGBE_FCOE */
  4594. ixgbe_configure_tx(adapter);
  4595. ixgbe_configure_rx(adapter);
  4596. ixgbe_configure_dfwd(adapter);
  4597. }
  4598. /**
  4599. * ixgbe_sfp_link_config - set up SFP+ link
  4600. * @adapter: pointer to private adapter struct
  4601. **/
  4602. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  4603. {
  4604. /*
  4605. * We are assuming the worst case scenario here, and that
  4606. * is that an SFP was inserted/removed after the reset
  4607. * but before SFP detection was enabled. As such the best
  4608. * solution is to just start searching as soon as we start
  4609. */
  4610. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  4611. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4612. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4613. adapter->sfp_poll_time = 0;
  4614. }
  4615. /**
  4616. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  4617. * @hw: pointer to private hardware struct
  4618. *
  4619. * Returns 0 on success, negative on failure
  4620. **/
  4621. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  4622. {
  4623. u32 speed;
  4624. bool autoneg, link_up = false;
  4625. int ret = IXGBE_ERR_LINK_SETUP;
  4626. if (hw->mac.ops.check_link)
  4627. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  4628. if (ret)
  4629. return ret;
  4630. speed = hw->phy.autoneg_advertised;
  4631. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  4632. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  4633. &autoneg);
  4634. if (ret)
  4635. return ret;
  4636. if (hw->mac.ops.setup_link)
  4637. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  4638. return ret;
  4639. }
  4640. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  4641. {
  4642. struct ixgbe_hw *hw = &adapter->hw;
  4643. u32 gpie = 0;
  4644. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4645. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  4646. IXGBE_GPIE_OCD;
  4647. gpie |= IXGBE_GPIE_EIAME;
  4648. /*
  4649. * use EIAM to auto-mask when MSI-X interrupt is asserted
  4650. * this saves a register write for every interrupt
  4651. */
  4652. switch (hw->mac.type) {
  4653. case ixgbe_mac_82598EB:
  4654. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4655. break;
  4656. case ixgbe_mac_82599EB:
  4657. case ixgbe_mac_X540:
  4658. case ixgbe_mac_X550:
  4659. case ixgbe_mac_X550EM_x:
  4660. case ixgbe_mac_x550em_a:
  4661. default:
  4662. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  4663. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  4664. break;
  4665. }
  4666. } else {
  4667. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  4668. * specifically only auto mask tx and rx interrupts */
  4669. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4670. }
  4671. /* XXX: to interrupt immediately for EICS writes, enable this */
  4672. /* gpie |= IXGBE_GPIE_EIMEN; */
  4673. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  4674. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  4675. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  4676. case IXGBE_82599_VMDQ_8Q_MASK:
  4677. gpie |= IXGBE_GPIE_VTMODE_16;
  4678. break;
  4679. case IXGBE_82599_VMDQ_4Q_MASK:
  4680. gpie |= IXGBE_GPIE_VTMODE_32;
  4681. break;
  4682. default:
  4683. gpie |= IXGBE_GPIE_VTMODE_64;
  4684. break;
  4685. }
  4686. }
  4687. /* Enable Thermal over heat sensor interrupt */
  4688. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  4689. switch (adapter->hw.mac.type) {
  4690. case ixgbe_mac_82599EB:
  4691. gpie |= IXGBE_SDP0_GPIEN_8259X;
  4692. break;
  4693. default:
  4694. break;
  4695. }
  4696. }
  4697. /* Enable fan failure interrupt */
  4698. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  4699. gpie |= IXGBE_SDP1_GPIEN(hw);
  4700. switch (hw->mac.type) {
  4701. case ixgbe_mac_82599EB:
  4702. gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
  4703. break;
  4704. case ixgbe_mac_X550EM_x:
  4705. case ixgbe_mac_x550em_a:
  4706. gpie |= IXGBE_SDP0_GPIEN_X540;
  4707. break;
  4708. default:
  4709. break;
  4710. }
  4711. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  4712. }
  4713. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  4714. {
  4715. struct ixgbe_hw *hw = &adapter->hw;
  4716. int err;
  4717. u32 ctrl_ext;
  4718. ixgbe_get_hw_control(adapter);
  4719. ixgbe_setup_gpie(adapter);
  4720. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4721. ixgbe_configure_msix(adapter);
  4722. else
  4723. ixgbe_configure_msi_and_legacy(adapter);
  4724. /* enable the optics for 82599 SFP+ fiber */
  4725. if (hw->mac.ops.enable_tx_laser)
  4726. hw->mac.ops.enable_tx_laser(hw);
  4727. if (hw->phy.ops.set_phy_power)
  4728. hw->phy.ops.set_phy_power(hw, true);
  4729. smp_mb__before_atomic();
  4730. clear_bit(__IXGBE_DOWN, &adapter->state);
  4731. ixgbe_napi_enable_all(adapter);
  4732. if (ixgbe_is_sfp(hw)) {
  4733. ixgbe_sfp_link_config(adapter);
  4734. } else {
  4735. err = ixgbe_non_sfp_link_config(hw);
  4736. if (err)
  4737. e_err(probe, "link_config FAILED %d\n", err);
  4738. }
  4739. /* clear any pending interrupts, may auto mask */
  4740. IXGBE_READ_REG(hw, IXGBE_EICR);
  4741. ixgbe_irq_enable(adapter, true, true);
  4742. /*
  4743. * If this adapter has a fan, check to see if we had a failure
  4744. * before we enabled the interrupt.
  4745. */
  4746. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4747. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4748. if (esdp & IXGBE_ESDP_SDP1)
  4749. e_crit(drv, "Fan has stopped, replace the adapter\n");
  4750. }
  4751. /* bring the link up in the watchdog, this could race with our first
  4752. * link up interrupt but shouldn't be a problem */
  4753. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4754. adapter->link_check_timeout = jiffies;
  4755. mod_timer(&adapter->service_timer, jiffies);
  4756. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  4757. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  4758. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  4759. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  4760. }
  4761. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  4762. {
  4763. WARN_ON(in_interrupt());
  4764. /* put off any impending NetWatchDogTimeout */
  4765. netif_trans_update(adapter->netdev);
  4766. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  4767. usleep_range(1000, 2000);
  4768. if (adapter->hw.phy.type == ixgbe_phy_fw)
  4769. ixgbe_watchdog_link_is_down(adapter);
  4770. ixgbe_down(adapter);
  4771. /*
  4772. * If SR-IOV enabled then wait a bit before bringing the adapter
  4773. * back up to give the VFs time to respond to the reset. The
  4774. * two second wait is based upon the watchdog timer cycle in
  4775. * the VF driver.
  4776. */
  4777. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4778. msleep(2000);
  4779. ixgbe_up(adapter);
  4780. clear_bit(__IXGBE_RESETTING, &adapter->state);
  4781. }
  4782. void ixgbe_up(struct ixgbe_adapter *adapter)
  4783. {
  4784. /* hardware has been reset, we need to reload some things */
  4785. ixgbe_configure(adapter);
  4786. ixgbe_up_complete(adapter);
  4787. }
  4788. static unsigned long ixgbe_get_completion_timeout(struct ixgbe_adapter *adapter)
  4789. {
  4790. u16 devctl2;
  4791. pcie_capability_read_word(adapter->pdev, PCI_EXP_DEVCTL2, &devctl2);
  4792. switch (devctl2 & IXGBE_PCIDEVCTRL2_TIMEO_MASK) {
  4793. case IXGBE_PCIDEVCTRL2_17_34s:
  4794. case IXGBE_PCIDEVCTRL2_4_8s:
  4795. /* For now we cap the upper limit on delay to 2 seconds
  4796. * as we end up going up to 34 seconds of delay in worst
  4797. * case timeout value.
  4798. */
  4799. case IXGBE_PCIDEVCTRL2_1_2s:
  4800. return 2000000ul; /* 2.0 s */
  4801. case IXGBE_PCIDEVCTRL2_260_520ms:
  4802. return 520000ul; /* 520 ms */
  4803. case IXGBE_PCIDEVCTRL2_65_130ms:
  4804. return 130000ul; /* 130 ms */
  4805. case IXGBE_PCIDEVCTRL2_16_32ms:
  4806. return 32000ul; /* 32 ms */
  4807. case IXGBE_PCIDEVCTRL2_1_2ms:
  4808. return 2000ul; /* 2 ms */
  4809. case IXGBE_PCIDEVCTRL2_50_100us:
  4810. return 100ul; /* 100 us */
  4811. case IXGBE_PCIDEVCTRL2_16_32ms_def:
  4812. return 32000ul; /* 32 ms */
  4813. default:
  4814. break;
  4815. }
  4816. /* We shouldn't need to hit this path, but just in case default as
  4817. * though completion timeout is not supported and support 32ms.
  4818. */
  4819. return 32000ul;
  4820. }
  4821. void ixgbe_disable_rx(struct ixgbe_adapter *adapter)
  4822. {
  4823. unsigned long wait_delay, delay_interval;
  4824. struct ixgbe_hw *hw = &adapter->hw;
  4825. int i, wait_loop;
  4826. u32 rxdctl;
  4827. /* disable receives */
  4828. hw->mac.ops.disable_rx(hw);
  4829. if (ixgbe_removed(hw->hw_addr))
  4830. return;
  4831. /* disable all enabled Rx queues */
  4832. for (i = 0; i < adapter->num_rx_queues; i++) {
  4833. struct ixgbe_ring *ring = adapter->rx_ring[i];
  4834. u8 reg_idx = ring->reg_idx;
  4835. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  4836. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  4837. rxdctl |= IXGBE_RXDCTL_SWFLSH;
  4838. /* write value back with RXDCTL.ENABLE bit cleared */
  4839. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  4840. }
  4841. /* RXDCTL.EN may not change on 82598 if link is down, so skip it */
  4842. if (hw->mac.type == ixgbe_mac_82598EB &&
  4843. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  4844. return;
  4845. /* Determine our minimum delay interval. We will increase this value
  4846. * with each subsequent test. This way if the device returns quickly
  4847. * we should spend as little time as possible waiting, however as
  4848. * the time increases we will wait for larger periods of time.
  4849. *
  4850. * The trick here is that we increase the interval using the
  4851. * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
  4852. * of that wait is that it totals up to 100x whatever interval we
  4853. * choose. Since our minimum wait is 100us we can just divide the
  4854. * total timeout by 100 to get our minimum delay interval.
  4855. */
  4856. delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
  4857. wait_loop = IXGBE_MAX_RX_DESC_POLL;
  4858. wait_delay = delay_interval;
  4859. while (wait_loop--) {
  4860. usleep_range(wait_delay, wait_delay + 10);
  4861. wait_delay += delay_interval * 2;
  4862. rxdctl = 0;
  4863. /* OR together the reading of all the active RXDCTL registers,
  4864. * and then test the result. We need the disable to complete
  4865. * before we start freeing the memory and invalidating the
  4866. * DMA mappings.
  4867. */
  4868. for (i = 0; i < adapter->num_rx_queues; i++) {
  4869. struct ixgbe_ring *ring = adapter->rx_ring[i];
  4870. u8 reg_idx = ring->reg_idx;
  4871. rxdctl |= IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  4872. }
  4873. if (!(rxdctl & IXGBE_RXDCTL_ENABLE))
  4874. return;
  4875. }
  4876. e_err(drv,
  4877. "RXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
  4878. }
  4879. void ixgbe_disable_tx(struct ixgbe_adapter *adapter)
  4880. {
  4881. unsigned long wait_delay, delay_interval;
  4882. struct ixgbe_hw *hw = &adapter->hw;
  4883. int i, wait_loop;
  4884. u32 txdctl;
  4885. if (ixgbe_removed(hw->hw_addr))
  4886. return;
  4887. /* disable all enabled Tx queues */
  4888. for (i = 0; i < adapter->num_tx_queues; i++) {
  4889. struct ixgbe_ring *ring = adapter->tx_ring[i];
  4890. u8 reg_idx = ring->reg_idx;
  4891. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4892. }
  4893. /* disable all enabled XDP Tx queues */
  4894. for (i = 0; i < adapter->num_xdp_queues; i++) {
  4895. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  4896. u8 reg_idx = ring->reg_idx;
  4897. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4898. }
  4899. /* If the link is not up there shouldn't be much in the way of
  4900. * pending transactions. Those that are left will be flushed out
  4901. * when the reset logic goes through the flush sequence to clean out
  4902. * the pending Tx transactions.
  4903. */
  4904. if (!(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  4905. goto dma_engine_disable;
  4906. /* Determine our minimum delay interval. We will increase this value
  4907. * with each subsequent test. This way if the device returns quickly
  4908. * we should spend as little time as possible waiting, however as
  4909. * the time increases we will wait for larger periods of time.
  4910. *
  4911. * The trick here is that we increase the interval using the
  4912. * following pattern: 1x 3x 5x 7x 9x 11x 13x 15x 17x 19x. The result
  4913. * of that wait is that it totals up to 100x whatever interval we
  4914. * choose. Since our minimum wait is 100us we can just divide the
  4915. * total timeout by 100 to get our minimum delay interval.
  4916. */
  4917. delay_interval = ixgbe_get_completion_timeout(adapter) / 100;
  4918. wait_loop = IXGBE_MAX_RX_DESC_POLL;
  4919. wait_delay = delay_interval;
  4920. while (wait_loop--) {
  4921. usleep_range(wait_delay, wait_delay + 10);
  4922. wait_delay += delay_interval * 2;
  4923. txdctl = 0;
  4924. /* OR together the reading of all the active TXDCTL registers,
  4925. * and then test the result. We need the disable to complete
  4926. * before we start freeing the memory and invalidating the
  4927. * DMA mappings.
  4928. */
  4929. for (i = 0; i < adapter->num_tx_queues; i++) {
  4930. struct ixgbe_ring *ring = adapter->tx_ring[i];
  4931. u8 reg_idx = ring->reg_idx;
  4932. txdctl |= IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  4933. }
  4934. for (i = 0; i < adapter->num_xdp_queues; i++) {
  4935. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  4936. u8 reg_idx = ring->reg_idx;
  4937. txdctl |= IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  4938. }
  4939. if (!(txdctl & IXGBE_TXDCTL_ENABLE))
  4940. goto dma_engine_disable;
  4941. }
  4942. e_err(drv,
  4943. "TXDCTL.ENABLE for one or more queues not cleared within the polling period\n");
  4944. dma_engine_disable:
  4945. /* Disable the Tx DMA engine on 82599 and later MAC */
  4946. switch (hw->mac.type) {
  4947. case ixgbe_mac_82599EB:
  4948. case ixgbe_mac_X540:
  4949. case ixgbe_mac_X550:
  4950. case ixgbe_mac_X550EM_x:
  4951. case ixgbe_mac_x550em_a:
  4952. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  4953. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  4954. ~IXGBE_DMATXCTL_TE));
  4955. /* fall through */
  4956. default:
  4957. break;
  4958. }
  4959. }
  4960. void ixgbe_reset(struct ixgbe_adapter *adapter)
  4961. {
  4962. struct ixgbe_hw *hw = &adapter->hw;
  4963. struct net_device *netdev = adapter->netdev;
  4964. int err;
  4965. if (ixgbe_removed(hw->hw_addr))
  4966. return;
  4967. /* lock SFP init bit to prevent race conditions with the watchdog */
  4968. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4969. usleep_range(1000, 2000);
  4970. /* clear all SFP and link config related flags while holding SFP_INIT */
  4971. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  4972. IXGBE_FLAG2_SFP_NEEDS_RESET);
  4973. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  4974. err = hw->mac.ops.init_hw(hw);
  4975. switch (err) {
  4976. case 0:
  4977. case IXGBE_ERR_SFP_NOT_PRESENT:
  4978. case IXGBE_ERR_SFP_NOT_SUPPORTED:
  4979. break;
  4980. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  4981. e_dev_err("master disable timed out\n");
  4982. break;
  4983. case IXGBE_ERR_EEPROM_VERSION:
  4984. /* We are running on a pre-production device, log a warning */
  4985. e_dev_warn("This device is a pre-production adapter/LOM. "
  4986. "Please be aware there may be issues associated with "
  4987. "your hardware. If you are experiencing problems "
  4988. "please contact your Intel or hardware "
  4989. "representative who provided you with this "
  4990. "hardware.\n");
  4991. break;
  4992. default:
  4993. e_dev_err("Hardware Error: %d\n", err);
  4994. }
  4995. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4996. /* flush entries out of MAC table */
  4997. ixgbe_flush_sw_mac_table(adapter);
  4998. __dev_uc_unsync(netdev, NULL);
  4999. /* do not flush user set addresses */
  5000. ixgbe_mac_set_default_filter(adapter);
  5001. /* update SAN MAC vmdq pool selection */
  5002. if (hw->mac.san_mac_rar_index)
  5003. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  5004. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  5005. ixgbe_ptp_reset(adapter);
  5006. if (hw->phy.ops.set_phy_power) {
  5007. if (!netif_running(adapter->netdev) && !adapter->wol)
  5008. hw->phy.ops.set_phy_power(hw, false);
  5009. else
  5010. hw->phy.ops.set_phy_power(hw, true);
  5011. }
  5012. }
  5013. /**
  5014. * ixgbe_clean_tx_ring - Free Tx Buffers
  5015. * @tx_ring: ring to be cleaned
  5016. **/
  5017. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  5018. {
  5019. u16 i = tx_ring->next_to_clean;
  5020. struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
  5021. while (i != tx_ring->next_to_use) {
  5022. union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
  5023. /* Free all the Tx ring sk_buffs */
  5024. if (ring_is_xdp(tx_ring))
  5025. xdp_return_frame(tx_buffer->xdpf);
  5026. else
  5027. dev_kfree_skb_any(tx_buffer->skb);
  5028. /* unmap skb header data */
  5029. dma_unmap_single(tx_ring->dev,
  5030. dma_unmap_addr(tx_buffer, dma),
  5031. dma_unmap_len(tx_buffer, len),
  5032. DMA_TO_DEVICE);
  5033. /* check for eop_desc to determine the end of the packet */
  5034. eop_desc = tx_buffer->next_to_watch;
  5035. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  5036. /* unmap remaining buffers */
  5037. while (tx_desc != eop_desc) {
  5038. tx_buffer++;
  5039. tx_desc++;
  5040. i++;
  5041. if (unlikely(i == tx_ring->count)) {
  5042. i = 0;
  5043. tx_buffer = tx_ring->tx_buffer_info;
  5044. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  5045. }
  5046. /* unmap any remaining paged data */
  5047. if (dma_unmap_len(tx_buffer, len))
  5048. dma_unmap_page(tx_ring->dev,
  5049. dma_unmap_addr(tx_buffer, dma),
  5050. dma_unmap_len(tx_buffer, len),
  5051. DMA_TO_DEVICE);
  5052. }
  5053. /* move us one more past the eop_desc for start of next pkt */
  5054. tx_buffer++;
  5055. i++;
  5056. if (unlikely(i == tx_ring->count)) {
  5057. i = 0;
  5058. tx_buffer = tx_ring->tx_buffer_info;
  5059. }
  5060. }
  5061. /* reset BQL for queue */
  5062. if (!ring_is_xdp(tx_ring))
  5063. netdev_tx_reset_queue(txring_txq(tx_ring));
  5064. /* reset next_to_use and next_to_clean */
  5065. tx_ring->next_to_use = 0;
  5066. tx_ring->next_to_clean = 0;
  5067. }
  5068. /**
  5069. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  5070. * @adapter: board private structure
  5071. **/
  5072. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  5073. {
  5074. int i;
  5075. for (i = 0; i < adapter->num_rx_queues; i++)
  5076. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  5077. }
  5078. /**
  5079. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  5080. * @adapter: board private structure
  5081. **/
  5082. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  5083. {
  5084. int i;
  5085. for (i = 0; i < adapter->num_tx_queues; i++)
  5086. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  5087. for (i = 0; i < adapter->num_xdp_queues; i++)
  5088. ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
  5089. }
  5090. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  5091. {
  5092. struct hlist_node *node2;
  5093. struct ixgbe_fdir_filter *filter;
  5094. spin_lock(&adapter->fdir_perfect_lock);
  5095. hlist_for_each_entry_safe(filter, node2,
  5096. &adapter->fdir_filter_list, fdir_node) {
  5097. hlist_del(&filter->fdir_node);
  5098. kfree(filter);
  5099. }
  5100. adapter->fdir_filter_count = 0;
  5101. spin_unlock(&adapter->fdir_perfect_lock);
  5102. }
  5103. void ixgbe_down(struct ixgbe_adapter *adapter)
  5104. {
  5105. struct net_device *netdev = adapter->netdev;
  5106. struct ixgbe_hw *hw = &adapter->hw;
  5107. int i;
  5108. /* signal that we are down to the interrupt handler */
  5109. if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
  5110. return; /* do nothing if already down */
  5111. /* Shut off incoming Tx traffic */
  5112. netif_tx_stop_all_queues(netdev);
  5113. /* call carrier off first to avoid false dev_watchdog timeouts */
  5114. netif_carrier_off(netdev);
  5115. netif_tx_disable(netdev);
  5116. /* Disable Rx */
  5117. ixgbe_disable_rx(adapter);
  5118. /* synchronize_sched() needed for pending XDP buffers to drain */
  5119. if (adapter->xdp_ring[0])
  5120. synchronize_sched();
  5121. ixgbe_irq_disable(adapter);
  5122. ixgbe_napi_disable_all(adapter);
  5123. clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  5124. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  5125. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  5126. del_timer_sync(&adapter->service_timer);
  5127. if (adapter->num_vfs) {
  5128. /* Clear EITR Select mapping */
  5129. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  5130. /* Mark all the VFs as inactive */
  5131. for (i = 0 ; i < adapter->num_vfs; i++)
  5132. adapter->vfinfo[i].clear_to_send = false;
  5133. /* ping all the active vfs to let them know we are going down */
  5134. ixgbe_ping_all_vfs(adapter);
  5135. /* Disable all VFTE/VFRE TX/RX */
  5136. ixgbe_disable_tx_rx(adapter);
  5137. }
  5138. /* disable transmits in the hardware now that interrupts are off */
  5139. ixgbe_disable_tx(adapter);
  5140. if (!pci_channel_offline(adapter->pdev))
  5141. ixgbe_reset(adapter);
  5142. /* power down the optics for 82599 SFP+ fiber */
  5143. if (hw->mac.ops.disable_tx_laser)
  5144. hw->mac.ops.disable_tx_laser(hw);
  5145. ixgbe_clean_all_tx_rings(adapter);
  5146. ixgbe_clean_all_rx_rings(adapter);
  5147. }
  5148. /**
  5149. * ixgbe_eee_capable - helper function to determine EEE support on X550
  5150. * @adapter: board private structure
  5151. */
  5152. static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
  5153. {
  5154. struct ixgbe_hw *hw = &adapter->hw;
  5155. switch (hw->device_id) {
  5156. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5157. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5158. if (!hw->phy.eee_speeds_supported)
  5159. break;
  5160. adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
  5161. if (!hw->phy.eee_speeds_advertised)
  5162. break;
  5163. adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
  5164. break;
  5165. default:
  5166. adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
  5167. adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
  5168. break;
  5169. }
  5170. }
  5171. /**
  5172. * ixgbe_tx_timeout - Respond to a Tx Hang
  5173. * @netdev: network interface device structure
  5174. **/
  5175. static void ixgbe_tx_timeout(struct net_device *netdev)
  5176. {
  5177. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5178. /* Do the reset outside of interrupt context */
  5179. ixgbe_tx_timeout_reset(adapter);
  5180. }
  5181. #ifdef CONFIG_IXGBE_DCB
  5182. static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
  5183. {
  5184. struct ixgbe_hw *hw = &adapter->hw;
  5185. struct tc_configuration *tc;
  5186. int j;
  5187. switch (hw->mac.type) {
  5188. case ixgbe_mac_82598EB:
  5189. case ixgbe_mac_82599EB:
  5190. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  5191. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  5192. break;
  5193. case ixgbe_mac_X540:
  5194. case ixgbe_mac_X550:
  5195. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  5196. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  5197. break;
  5198. case ixgbe_mac_X550EM_x:
  5199. case ixgbe_mac_x550em_a:
  5200. default:
  5201. adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
  5202. adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
  5203. break;
  5204. }
  5205. /* Configure DCB traffic classes */
  5206. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  5207. tc = &adapter->dcb_cfg.tc_config[j];
  5208. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  5209. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  5210. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  5211. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  5212. tc->dcb_pfc = pfc_disabled;
  5213. }
  5214. /* Initialize default user to priority mapping, UPx->TC0 */
  5215. tc = &adapter->dcb_cfg.tc_config[0];
  5216. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  5217. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  5218. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  5219. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  5220. adapter->dcb_cfg.pfc_mode_enable = false;
  5221. adapter->dcb_set_bitmap = 0x00;
  5222. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  5223. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  5224. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  5225. sizeof(adapter->temp_dcb_cfg));
  5226. }
  5227. #endif
  5228. /**
  5229. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  5230. * @adapter: board private structure to initialize
  5231. * @ii: pointer to ixgbe_info for device
  5232. *
  5233. * ixgbe_sw_init initializes the Adapter private data structure.
  5234. * Fields are initialized based on PCI device information and
  5235. * OS network device settings (MTU size).
  5236. **/
  5237. static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
  5238. const struct ixgbe_info *ii)
  5239. {
  5240. struct ixgbe_hw *hw = &adapter->hw;
  5241. struct pci_dev *pdev = adapter->pdev;
  5242. unsigned int rss, fdir;
  5243. u32 fwsm;
  5244. int i;
  5245. /* PCI config space info */
  5246. hw->vendor_id = pdev->vendor;
  5247. hw->device_id = pdev->device;
  5248. hw->revision_id = pdev->revision;
  5249. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  5250. hw->subsystem_device_id = pdev->subsystem_device;
  5251. /* get_invariants needs the device IDs */
  5252. ii->get_invariants(hw);
  5253. /* Set common capability flags and settings */
  5254. rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
  5255. adapter->ring_feature[RING_F_RSS].limit = rss;
  5256. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  5257. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  5258. adapter->atr_sample_rate = 20;
  5259. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  5260. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  5261. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  5262. adapter->ring_feature[RING_F_VMDQ].limit = 1;
  5263. #ifdef CONFIG_IXGBE_DCA
  5264. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  5265. #endif
  5266. #ifdef CONFIG_IXGBE_DCB
  5267. adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
  5268. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  5269. #endif
  5270. #ifdef IXGBE_FCOE
  5271. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  5272. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5273. #ifdef CONFIG_IXGBE_DCB
  5274. /* Default traffic class to use for FCoE */
  5275. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  5276. #endif /* CONFIG_IXGBE_DCB */
  5277. #endif /* IXGBE_FCOE */
  5278. /* initialize static ixgbe jump table entries */
  5279. adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
  5280. GFP_KERNEL);
  5281. if (!adapter->jump_tables[0])
  5282. return -ENOMEM;
  5283. adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
  5284. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
  5285. adapter->jump_tables[i] = NULL;
  5286. adapter->mac_table = kcalloc(hw->mac.num_rar_entries,
  5287. sizeof(struct ixgbe_mac_addr),
  5288. GFP_KERNEL);
  5289. if (!adapter->mac_table)
  5290. return -ENOMEM;
  5291. if (ixgbe_init_rss_key(adapter))
  5292. return -ENOMEM;
  5293. /* Set MAC specific capability flags and exceptions */
  5294. switch (hw->mac.type) {
  5295. case ixgbe_mac_82598EB:
  5296. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  5297. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  5298. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  5299. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  5300. adapter->ring_feature[RING_F_FDIR].limit = 0;
  5301. adapter->atr_sample_rate = 0;
  5302. adapter->fdir_pballoc = 0;
  5303. #ifdef IXGBE_FCOE
  5304. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5305. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5306. #ifdef CONFIG_IXGBE_DCB
  5307. adapter->fcoe.up = 0;
  5308. #endif /* IXGBE_DCB */
  5309. #endif /* IXGBE_FCOE */
  5310. break;
  5311. case ixgbe_mac_82599EB:
  5312. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  5313. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5314. break;
  5315. case ixgbe_mac_X540:
  5316. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  5317. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  5318. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5319. break;
  5320. case ixgbe_mac_x550em_a:
  5321. adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
  5322. switch (hw->device_id) {
  5323. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5324. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5325. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5326. break;
  5327. default:
  5328. break;
  5329. }
  5330. /* fall through */
  5331. case ixgbe_mac_X550EM_x:
  5332. #ifdef CONFIG_IXGBE_DCB
  5333. adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
  5334. #endif
  5335. #ifdef IXGBE_FCOE
  5336. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5337. #ifdef CONFIG_IXGBE_DCB
  5338. adapter->fcoe.up = 0;
  5339. #endif /* IXGBE_DCB */
  5340. #endif /* IXGBE_FCOE */
  5341. /* Fall Through */
  5342. case ixgbe_mac_X550:
  5343. if (hw->mac.type == ixgbe_mac_X550)
  5344. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5345. #ifdef CONFIG_IXGBE_DCA
  5346. adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
  5347. #endif
  5348. adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
  5349. break;
  5350. default:
  5351. break;
  5352. }
  5353. #ifdef IXGBE_FCOE
  5354. /* FCoE support exists, always init the FCoE lock */
  5355. spin_lock_init(&adapter->fcoe.lock);
  5356. #endif
  5357. /* n-tuple support exists, always init our spinlock */
  5358. spin_lock_init(&adapter->fdir_perfect_lock);
  5359. #ifdef CONFIG_IXGBE_DCB
  5360. ixgbe_init_dcb(adapter);
  5361. #endif
  5362. ixgbe_init_ipsec_offload(adapter);
  5363. /* default flow control settings */
  5364. hw->fc.requested_mode = ixgbe_fc_full;
  5365. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  5366. ixgbe_pbthresh_setup(adapter);
  5367. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  5368. hw->fc.send_xon = true;
  5369. hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
  5370. #ifdef CONFIG_PCI_IOV
  5371. if (max_vfs > 0)
  5372. e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
  5373. /* assign number of SR-IOV VFs */
  5374. if (hw->mac.type != ixgbe_mac_82598EB) {
  5375. if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
  5376. max_vfs = 0;
  5377. e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
  5378. }
  5379. }
  5380. #endif /* CONFIG_PCI_IOV */
  5381. /* enable itr by default in dynamic mode */
  5382. adapter->rx_itr_setting = 1;
  5383. adapter->tx_itr_setting = 1;
  5384. /* set default ring sizes */
  5385. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  5386. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  5387. /* set default work limits */
  5388. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  5389. /* initialize eeprom parameters */
  5390. if (ixgbe_init_eeprom_params_generic(hw)) {
  5391. e_dev_err("EEPROM initialization failed\n");
  5392. return -EIO;
  5393. }
  5394. /* PF holds first pool slot */
  5395. set_bit(0, adapter->fwd_bitmask);
  5396. set_bit(__IXGBE_DOWN, &adapter->state);
  5397. return 0;
  5398. }
  5399. /**
  5400. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  5401. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  5402. *
  5403. * Return 0 on success, negative on failure
  5404. **/
  5405. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  5406. {
  5407. struct device *dev = tx_ring->dev;
  5408. int orig_node = dev_to_node(dev);
  5409. int ring_node = -1;
  5410. int size;
  5411. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  5412. if (tx_ring->q_vector)
  5413. ring_node = tx_ring->q_vector->numa_node;
  5414. tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
  5415. if (!tx_ring->tx_buffer_info)
  5416. tx_ring->tx_buffer_info = vmalloc(size);
  5417. if (!tx_ring->tx_buffer_info)
  5418. goto err;
  5419. /* round up to nearest 4K */
  5420. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  5421. tx_ring->size = ALIGN(tx_ring->size, 4096);
  5422. set_dev_node(dev, ring_node);
  5423. tx_ring->desc = dma_alloc_coherent(dev,
  5424. tx_ring->size,
  5425. &tx_ring->dma,
  5426. GFP_KERNEL);
  5427. set_dev_node(dev, orig_node);
  5428. if (!tx_ring->desc)
  5429. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  5430. &tx_ring->dma, GFP_KERNEL);
  5431. if (!tx_ring->desc)
  5432. goto err;
  5433. tx_ring->next_to_use = 0;
  5434. tx_ring->next_to_clean = 0;
  5435. return 0;
  5436. err:
  5437. vfree(tx_ring->tx_buffer_info);
  5438. tx_ring->tx_buffer_info = NULL;
  5439. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  5440. return -ENOMEM;
  5441. }
  5442. /**
  5443. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  5444. * @adapter: board private structure
  5445. *
  5446. * If this function returns with an error, then it's possible one or
  5447. * more of the rings is populated (while the rest are not). It is the
  5448. * callers duty to clean those orphaned rings.
  5449. *
  5450. * Return 0 on success, negative on failure
  5451. **/
  5452. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  5453. {
  5454. int i, j = 0, err = 0;
  5455. for (i = 0; i < adapter->num_tx_queues; i++) {
  5456. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  5457. if (!err)
  5458. continue;
  5459. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  5460. goto err_setup_tx;
  5461. }
  5462. for (j = 0; j < adapter->num_xdp_queues; j++) {
  5463. err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
  5464. if (!err)
  5465. continue;
  5466. e_err(probe, "Allocation for Tx Queue %u failed\n", j);
  5467. goto err_setup_tx;
  5468. }
  5469. return 0;
  5470. err_setup_tx:
  5471. /* rewind the index freeing the rings as we go */
  5472. while (j--)
  5473. ixgbe_free_tx_resources(adapter->xdp_ring[j]);
  5474. while (i--)
  5475. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5476. return err;
  5477. }
  5478. /**
  5479. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  5480. * @adapter: pointer to ixgbe_adapter
  5481. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  5482. *
  5483. * Returns 0 on success, negative on failure
  5484. **/
  5485. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  5486. struct ixgbe_ring *rx_ring)
  5487. {
  5488. struct device *dev = rx_ring->dev;
  5489. int orig_node = dev_to_node(dev);
  5490. int ring_node = -1;
  5491. int size, err;
  5492. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  5493. if (rx_ring->q_vector)
  5494. ring_node = rx_ring->q_vector->numa_node;
  5495. rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
  5496. if (!rx_ring->rx_buffer_info)
  5497. rx_ring->rx_buffer_info = vmalloc(size);
  5498. if (!rx_ring->rx_buffer_info)
  5499. goto err;
  5500. /* Round up to nearest 4K */
  5501. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  5502. rx_ring->size = ALIGN(rx_ring->size, 4096);
  5503. set_dev_node(dev, ring_node);
  5504. rx_ring->desc = dma_alloc_coherent(dev,
  5505. rx_ring->size,
  5506. &rx_ring->dma,
  5507. GFP_KERNEL);
  5508. set_dev_node(dev, orig_node);
  5509. if (!rx_ring->desc)
  5510. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  5511. &rx_ring->dma, GFP_KERNEL);
  5512. if (!rx_ring->desc)
  5513. goto err;
  5514. rx_ring->next_to_clean = 0;
  5515. rx_ring->next_to_use = 0;
  5516. /* XDP RX-queue info */
  5517. if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
  5518. rx_ring->queue_index) < 0)
  5519. goto err;
  5520. err = xdp_rxq_info_reg_mem_model(&rx_ring->xdp_rxq,
  5521. MEM_TYPE_PAGE_SHARED, NULL);
  5522. if (err) {
  5523. xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
  5524. goto err;
  5525. }
  5526. rx_ring->xdp_prog = adapter->xdp_prog;
  5527. return 0;
  5528. err:
  5529. vfree(rx_ring->rx_buffer_info);
  5530. rx_ring->rx_buffer_info = NULL;
  5531. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  5532. return -ENOMEM;
  5533. }
  5534. /**
  5535. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  5536. * @adapter: board private structure
  5537. *
  5538. * If this function returns with an error, then it's possible one or
  5539. * more of the rings is populated (while the rest are not). It is the
  5540. * callers duty to clean those orphaned rings.
  5541. *
  5542. * Return 0 on success, negative on failure
  5543. **/
  5544. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  5545. {
  5546. int i, err = 0;
  5547. for (i = 0; i < adapter->num_rx_queues; i++) {
  5548. err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
  5549. if (!err)
  5550. continue;
  5551. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  5552. goto err_setup_rx;
  5553. }
  5554. #ifdef IXGBE_FCOE
  5555. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  5556. if (!err)
  5557. #endif
  5558. return 0;
  5559. err_setup_rx:
  5560. /* rewind the index freeing the rings as we go */
  5561. while (i--)
  5562. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5563. return err;
  5564. }
  5565. /**
  5566. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  5567. * @tx_ring: Tx descriptor ring for a specific queue
  5568. *
  5569. * Free all transmit software resources
  5570. **/
  5571. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  5572. {
  5573. ixgbe_clean_tx_ring(tx_ring);
  5574. vfree(tx_ring->tx_buffer_info);
  5575. tx_ring->tx_buffer_info = NULL;
  5576. /* if not set, then don't free */
  5577. if (!tx_ring->desc)
  5578. return;
  5579. dma_free_coherent(tx_ring->dev, tx_ring->size,
  5580. tx_ring->desc, tx_ring->dma);
  5581. tx_ring->desc = NULL;
  5582. }
  5583. /**
  5584. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  5585. * @adapter: board private structure
  5586. *
  5587. * Free all transmit software resources
  5588. **/
  5589. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  5590. {
  5591. int i;
  5592. for (i = 0; i < adapter->num_tx_queues; i++)
  5593. if (adapter->tx_ring[i]->desc)
  5594. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5595. for (i = 0; i < adapter->num_xdp_queues; i++)
  5596. if (adapter->xdp_ring[i]->desc)
  5597. ixgbe_free_tx_resources(adapter->xdp_ring[i]);
  5598. }
  5599. /**
  5600. * ixgbe_free_rx_resources - Free Rx Resources
  5601. * @rx_ring: ring to clean the resources from
  5602. *
  5603. * Free all receive software resources
  5604. **/
  5605. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  5606. {
  5607. ixgbe_clean_rx_ring(rx_ring);
  5608. rx_ring->xdp_prog = NULL;
  5609. xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
  5610. vfree(rx_ring->rx_buffer_info);
  5611. rx_ring->rx_buffer_info = NULL;
  5612. /* if not set, then don't free */
  5613. if (!rx_ring->desc)
  5614. return;
  5615. dma_free_coherent(rx_ring->dev, rx_ring->size,
  5616. rx_ring->desc, rx_ring->dma);
  5617. rx_ring->desc = NULL;
  5618. }
  5619. /**
  5620. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  5621. * @adapter: board private structure
  5622. *
  5623. * Free all receive software resources
  5624. **/
  5625. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  5626. {
  5627. int i;
  5628. #ifdef IXGBE_FCOE
  5629. ixgbe_free_fcoe_ddp_resources(adapter);
  5630. #endif
  5631. for (i = 0; i < adapter->num_rx_queues; i++)
  5632. if (adapter->rx_ring[i]->desc)
  5633. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5634. }
  5635. /**
  5636. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  5637. * @netdev: network interface device structure
  5638. * @new_mtu: new value for maximum frame size
  5639. *
  5640. * Returns 0 on success, negative on failure
  5641. **/
  5642. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  5643. {
  5644. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5645. if (adapter->xdp_prog) {
  5646. int new_frame_size = new_mtu + ETH_HLEN + ETH_FCS_LEN +
  5647. VLAN_HLEN;
  5648. int i;
  5649. for (i = 0; i < adapter->num_rx_queues; i++) {
  5650. struct ixgbe_ring *ring = adapter->rx_ring[i];
  5651. if (new_frame_size > ixgbe_rx_bufsz(ring)) {
  5652. e_warn(probe, "Requested MTU size is not supported with XDP\n");
  5653. return -EINVAL;
  5654. }
  5655. }
  5656. }
  5657. /*
  5658. * For 82599EB we cannot allow legacy VFs to enable their receive
  5659. * paths when MTU greater than 1500 is configured. So display a
  5660. * warning that legacy VFs will be disabled.
  5661. */
  5662. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  5663. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  5664. (new_mtu > ETH_DATA_LEN))
  5665. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  5666. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  5667. /* must set new MTU before calling down or up */
  5668. netdev->mtu = new_mtu;
  5669. if (netif_running(netdev))
  5670. ixgbe_reinit_locked(adapter);
  5671. return 0;
  5672. }
  5673. /**
  5674. * ixgbe_open - Called when a network interface is made active
  5675. * @netdev: network interface device structure
  5676. *
  5677. * Returns 0 on success, negative value on failure
  5678. *
  5679. * The open entry point is called when a network interface is made
  5680. * active by the system (IFF_UP). At this point all resources needed
  5681. * for transmit and receive operations are allocated, the interrupt
  5682. * handler is registered with the OS, the watchdog timer is started,
  5683. * and the stack is notified that the interface is ready.
  5684. **/
  5685. int ixgbe_open(struct net_device *netdev)
  5686. {
  5687. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5688. struct ixgbe_hw *hw = &adapter->hw;
  5689. int err, queues;
  5690. /* disallow open during test */
  5691. if (test_bit(__IXGBE_TESTING, &adapter->state))
  5692. return -EBUSY;
  5693. netif_carrier_off(netdev);
  5694. /* allocate transmit descriptors */
  5695. err = ixgbe_setup_all_tx_resources(adapter);
  5696. if (err)
  5697. goto err_setup_tx;
  5698. /* allocate receive descriptors */
  5699. err = ixgbe_setup_all_rx_resources(adapter);
  5700. if (err)
  5701. goto err_setup_rx;
  5702. ixgbe_configure(adapter);
  5703. err = ixgbe_request_irq(adapter);
  5704. if (err)
  5705. goto err_req_irq;
  5706. /* Notify the stack of the actual queue counts. */
  5707. queues = adapter->num_tx_queues;
  5708. err = netif_set_real_num_tx_queues(netdev, queues);
  5709. if (err)
  5710. goto err_set_queues;
  5711. queues = adapter->num_rx_queues;
  5712. err = netif_set_real_num_rx_queues(netdev, queues);
  5713. if (err)
  5714. goto err_set_queues;
  5715. ixgbe_ptp_init(adapter);
  5716. ixgbe_up_complete(adapter);
  5717. ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
  5718. udp_tunnel_get_rx_info(netdev);
  5719. return 0;
  5720. err_set_queues:
  5721. ixgbe_free_irq(adapter);
  5722. err_req_irq:
  5723. ixgbe_free_all_rx_resources(adapter);
  5724. if (hw->phy.ops.set_phy_power && !adapter->wol)
  5725. hw->phy.ops.set_phy_power(&adapter->hw, false);
  5726. err_setup_rx:
  5727. ixgbe_free_all_tx_resources(adapter);
  5728. err_setup_tx:
  5729. ixgbe_reset(adapter);
  5730. return err;
  5731. }
  5732. static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
  5733. {
  5734. ixgbe_ptp_suspend(adapter);
  5735. if (adapter->hw.phy.ops.enter_lplu) {
  5736. adapter->hw.phy.reset_disable = true;
  5737. ixgbe_down(adapter);
  5738. adapter->hw.phy.ops.enter_lplu(&adapter->hw);
  5739. adapter->hw.phy.reset_disable = false;
  5740. } else {
  5741. ixgbe_down(adapter);
  5742. }
  5743. ixgbe_free_irq(adapter);
  5744. ixgbe_free_all_tx_resources(adapter);
  5745. ixgbe_free_all_rx_resources(adapter);
  5746. }
  5747. /**
  5748. * ixgbe_close - Disables a network interface
  5749. * @netdev: network interface device structure
  5750. *
  5751. * Returns 0, this is not allowed to fail
  5752. *
  5753. * The close entry point is called when an interface is de-activated
  5754. * by the OS. The hardware is still under the drivers control, but
  5755. * needs to be disabled. A global MAC reset is issued to stop the
  5756. * hardware, and all transmit and receive resources are freed.
  5757. **/
  5758. int ixgbe_close(struct net_device *netdev)
  5759. {
  5760. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5761. ixgbe_ptp_stop(adapter);
  5762. if (netif_device_present(netdev))
  5763. ixgbe_close_suspend(adapter);
  5764. ixgbe_fdir_filter_exit(adapter);
  5765. ixgbe_release_hw_control(adapter);
  5766. return 0;
  5767. }
  5768. #ifdef CONFIG_PM
  5769. static int ixgbe_resume(struct pci_dev *pdev)
  5770. {
  5771. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5772. struct net_device *netdev = adapter->netdev;
  5773. u32 err;
  5774. adapter->hw.hw_addr = adapter->io_addr;
  5775. pci_set_power_state(pdev, PCI_D0);
  5776. pci_restore_state(pdev);
  5777. /*
  5778. * pci_restore_state clears dev->state_saved so call
  5779. * pci_save_state to restore it.
  5780. */
  5781. pci_save_state(pdev);
  5782. err = pci_enable_device_mem(pdev);
  5783. if (err) {
  5784. e_dev_err("Cannot enable PCI device from suspend\n");
  5785. return err;
  5786. }
  5787. smp_mb__before_atomic();
  5788. clear_bit(__IXGBE_DISABLED, &adapter->state);
  5789. pci_set_master(pdev);
  5790. pci_wake_from_d3(pdev, false);
  5791. ixgbe_reset(adapter);
  5792. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5793. rtnl_lock();
  5794. err = ixgbe_init_interrupt_scheme(adapter);
  5795. if (!err && netif_running(netdev))
  5796. err = ixgbe_open(netdev);
  5797. if (!err)
  5798. netif_device_attach(netdev);
  5799. rtnl_unlock();
  5800. return err;
  5801. }
  5802. #endif /* CONFIG_PM */
  5803. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5804. {
  5805. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5806. struct net_device *netdev = adapter->netdev;
  5807. struct ixgbe_hw *hw = &adapter->hw;
  5808. u32 ctrl;
  5809. u32 wufc = adapter->wol;
  5810. #ifdef CONFIG_PM
  5811. int retval = 0;
  5812. #endif
  5813. rtnl_lock();
  5814. netif_device_detach(netdev);
  5815. if (netif_running(netdev))
  5816. ixgbe_close_suspend(adapter);
  5817. ixgbe_clear_interrupt_scheme(adapter);
  5818. rtnl_unlock();
  5819. #ifdef CONFIG_PM
  5820. retval = pci_save_state(pdev);
  5821. if (retval)
  5822. return retval;
  5823. #endif
  5824. if (hw->mac.ops.stop_link_on_d3)
  5825. hw->mac.ops.stop_link_on_d3(hw);
  5826. if (wufc) {
  5827. u32 fctrl;
  5828. ixgbe_set_rx_mode(netdev);
  5829. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  5830. if (hw->mac.ops.enable_tx_laser)
  5831. hw->mac.ops.enable_tx_laser(hw);
  5832. /* enable the reception of multicast packets */
  5833. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5834. fctrl |= IXGBE_FCTRL_MPE;
  5835. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  5836. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  5837. ctrl |= IXGBE_CTRL_GIO_DIS;
  5838. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  5839. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  5840. } else {
  5841. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  5842. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  5843. }
  5844. switch (hw->mac.type) {
  5845. case ixgbe_mac_82598EB:
  5846. pci_wake_from_d3(pdev, false);
  5847. break;
  5848. case ixgbe_mac_82599EB:
  5849. case ixgbe_mac_X540:
  5850. case ixgbe_mac_X550:
  5851. case ixgbe_mac_X550EM_x:
  5852. case ixgbe_mac_x550em_a:
  5853. pci_wake_from_d3(pdev, !!wufc);
  5854. break;
  5855. default:
  5856. break;
  5857. }
  5858. *enable_wake = !!wufc;
  5859. if (hw->phy.ops.set_phy_power && !*enable_wake)
  5860. hw->phy.ops.set_phy_power(hw, false);
  5861. ixgbe_release_hw_control(adapter);
  5862. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  5863. pci_disable_device(pdev);
  5864. return 0;
  5865. }
  5866. #ifdef CONFIG_PM
  5867. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  5868. {
  5869. int retval;
  5870. bool wake;
  5871. retval = __ixgbe_shutdown(pdev, &wake);
  5872. if (retval)
  5873. return retval;
  5874. if (wake) {
  5875. pci_prepare_to_sleep(pdev);
  5876. } else {
  5877. pci_wake_from_d3(pdev, false);
  5878. pci_set_power_state(pdev, PCI_D3hot);
  5879. }
  5880. return 0;
  5881. }
  5882. #endif /* CONFIG_PM */
  5883. static void ixgbe_shutdown(struct pci_dev *pdev)
  5884. {
  5885. bool wake;
  5886. __ixgbe_shutdown(pdev, &wake);
  5887. if (system_state == SYSTEM_POWER_OFF) {
  5888. pci_wake_from_d3(pdev, wake);
  5889. pci_set_power_state(pdev, PCI_D3hot);
  5890. }
  5891. }
  5892. /**
  5893. * ixgbe_update_stats - Update the board statistics counters.
  5894. * @adapter: board private structure
  5895. **/
  5896. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  5897. {
  5898. struct net_device *netdev = adapter->netdev;
  5899. struct ixgbe_hw *hw = &adapter->hw;
  5900. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  5901. u64 total_mpc = 0;
  5902. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  5903. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  5904. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  5905. u64 alloc_rx_page = 0;
  5906. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  5907. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5908. test_bit(__IXGBE_RESETTING, &adapter->state))
  5909. return;
  5910. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  5911. u64 rsc_count = 0;
  5912. u64 rsc_flush = 0;
  5913. for (i = 0; i < adapter->num_rx_queues; i++) {
  5914. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  5915. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  5916. }
  5917. adapter->rsc_total_count = rsc_count;
  5918. adapter->rsc_total_flush = rsc_flush;
  5919. }
  5920. for (i = 0; i < adapter->num_rx_queues; i++) {
  5921. struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
  5922. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  5923. alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
  5924. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  5925. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  5926. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  5927. bytes += rx_ring->stats.bytes;
  5928. packets += rx_ring->stats.packets;
  5929. }
  5930. adapter->non_eop_descs = non_eop_descs;
  5931. adapter->alloc_rx_page = alloc_rx_page;
  5932. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  5933. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  5934. adapter->hw_csum_rx_error = hw_csum_rx_error;
  5935. netdev->stats.rx_bytes = bytes;
  5936. netdev->stats.rx_packets = packets;
  5937. bytes = 0;
  5938. packets = 0;
  5939. /* gather some stats to the adapter struct that are per queue */
  5940. for (i = 0; i < adapter->num_tx_queues; i++) {
  5941. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  5942. restart_queue += tx_ring->tx_stats.restart_queue;
  5943. tx_busy += tx_ring->tx_stats.tx_busy;
  5944. bytes += tx_ring->stats.bytes;
  5945. packets += tx_ring->stats.packets;
  5946. }
  5947. for (i = 0; i < adapter->num_xdp_queues; i++) {
  5948. struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
  5949. restart_queue += xdp_ring->tx_stats.restart_queue;
  5950. tx_busy += xdp_ring->tx_stats.tx_busy;
  5951. bytes += xdp_ring->stats.bytes;
  5952. packets += xdp_ring->stats.packets;
  5953. }
  5954. adapter->restart_queue = restart_queue;
  5955. adapter->tx_busy = tx_busy;
  5956. netdev->stats.tx_bytes = bytes;
  5957. netdev->stats.tx_packets = packets;
  5958. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  5959. /* 8 register reads */
  5960. for (i = 0; i < 8; i++) {
  5961. /* for packet buffers not used, the register should read 0 */
  5962. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  5963. missed_rx += mpc;
  5964. hwstats->mpc[i] += mpc;
  5965. total_mpc += hwstats->mpc[i];
  5966. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  5967. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  5968. switch (hw->mac.type) {
  5969. case ixgbe_mac_82598EB:
  5970. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  5971. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  5972. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  5973. hwstats->pxonrxc[i] +=
  5974. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  5975. break;
  5976. case ixgbe_mac_82599EB:
  5977. case ixgbe_mac_X540:
  5978. case ixgbe_mac_X550:
  5979. case ixgbe_mac_X550EM_x:
  5980. case ixgbe_mac_x550em_a:
  5981. hwstats->pxonrxc[i] +=
  5982. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  5983. break;
  5984. default:
  5985. break;
  5986. }
  5987. }
  5988. /*16 register reads */
  5989. for (i = 0; i < 16; i++) {
  5990. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  5991. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  5992. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  5993. (hw->mac.type == ixgbe_mac_X540) ||
  5994. (hw->mac.type == ixgbe_mac_X550) ||
  5995. (hw->mac.type == ixgbe_mac_X550EM_x) ||
  5996. (hw->mac.type == ixgbe_mac_x550em_a)) {
  5997. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  5998. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  5999. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  6000. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  6001. }
  6002. }
  6003. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  6004. /* work around hardware counting issue */
  6005. hwstats->gprc -= missed_rx;
  6006. ixgbe_update_xoff_received(adapter);
  6007. /* 82598 hardware only has a 32 bit counter in the high register */
  6008. switch (hw->mac.type) {
  6009. case ixgbe_mac_82598EB:
  6010. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  6011. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  6012. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  6013. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  6014. break;
  6015. case ixgbe_mac_X540:
  6016. case ixgbe_mac_X550:
  6017. case ixgbe_mac_X550EM_x:
  6018. case ixgbe_mac_x550em_a:
  6019. /* OS2BMC stats are X540 and later */
  6020. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  6021. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  6022. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  6023. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  6024. /* fall through */
  6025. case ixgbe_mac_82599EB:
  6026. for (i = 0; i < 16; i++)
  6027. adapter->hw_rx_no_dma_resources +=
  6028. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  6029. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  6030. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  6031. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  6032. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  6033. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  6034. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  6035. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  6036. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  6037. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  6038. #ifdef IXGBE_FCOE
  6039. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  6040. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  6041. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  6042. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  6043. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  6044. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  6045. /* Add up per cpu counters for total ddp aloc fail */
  6046. if (adapter->fcoe.ddp_pool) {
  6047. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  6048. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  6049. unsigned int cpu;
  6050. u64 noddp = 0, noddp_ext_buff = 0;
  6051. for_each_possible_cpu(cpu) {
  6052. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  6053. noddp += ddp_pool->noddp;
  6054. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  6055. }
  6056. hwstats->fcoe_noddp = noddp;
  6057. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  6058. }
  6059. #endif /* IXGBE_FCOE */
  6060. break;
  6061. default:
  6062. break;
  6063. }
  6064. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  6065. hwstats->bprc += bprc;
  6066. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  6067. if (hw->mac.type == ixgbe_mac_82598EB)
  6068. hwstats->mprc -= bprc;
  6069. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  6070. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  6071. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  6072. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  6073. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  6074. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  6075. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  6076. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  6077. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  6078. hwstats->lxontxc += lxon;
  6079. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  6080. hwstats->lxofftxc += lxoff;
  6081. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  6082. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  6083. /*
  6084. * 82598 errata - tx of flow control packets is included in tx counters
  6085. */
  6086. xon_off_tot = lxon + lxoff;
  6087. hwstats->gptc -= xon_off_tot;
  6088. hwstats->mptc -= xon_off_tot;
  6089. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  6090. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  6091. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  6092. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  6093. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  6094. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  6095. hwstats->ptc64 -= xon_off_tot;
  6096. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  6097. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  6098. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  6099. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  6100. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  6101. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  6102. /* Fill out the OS statistics structure */
  6103. netdev->stats.multicast = hwstats->mprc;
  6104. /* Rx Errors */
  6105. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  6106. netdev->stats.rx_dropped = 0;
  6107. netdev->stats.rx_length_errors = hwstats->rlec;
  6108. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  6109. netdev->stats.rx_missed_errors = total_mpc;
  6110. }
  6111. /**
  6112. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  6113. * @adapter: pointer to the device adapter structure
  6114. **/
  6115. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  6116. {
  6117. struct ixgbe_hw *hw = &adapter->hw;
  6118. int i;
  6119. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  6120. return;
  6121. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  6122. /* if interface is down do nothing */
  6123. if (test_bit(__IXGBE_DOWN, &adapter->state))
  6124. return;
  6125. /* do nothing if we are not using signature filters */
  6126. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  6127. return;
  6128. adapter->fdir_overflow++;
  6129. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  6130. for (i = 0; i < adapter->num_tx_queues; i++)
  6131. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  6132. &(adapter->tx_ring[i]->state));
  6133. for (i = 0; i < adapter->num_xdp_queues; i++)
  6134. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  6135. &adapter->xdp_ring[i]->state);
  6136. /* re-enable flow director interrupts */
  6137. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  6138. } else {
  6139. e_err(probe, "failed to finish FDIR re-initialization, "
  6140. "ignored adding FDIR ATR filters\n");
  6141. }
  6142. }
  6143. /**
  6144. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  6145. * @adapter: pointer to the device adapter structure
  6146. *
  6147. * This function serves two purposes. First it strobes the interrupt lines
  6148. * in order to make certain interrupts are occurring. Secondly it sets the
  6149. * bits needed to check for TX hangs. As a result we should immediately
  6150. * determine if a hang has occurred.
  6151. */
  6152. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  6153. {
  6154. struct ixgbe_hw *hw = &adapter->hw;
  6155. u64 eics = 0;
  6156. int i;
  6157. /* If we're down, removing or resetting, just bail */
  6158. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6159. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6160. test_bit(__IXGBE_RESETTING, &adapter->state))
  6161. return;
  6162. /* Force detection of hung controller */
  6163. if (netif_carrier_ok(adapter->netdev)) {
  6164. for (i = 0; i < adapter->num_tx_queues; i++)
  6165. set_check_for_tx_hang(adapter->tx_ring[i]);
  6166. for (i = 0; i < adapter->num_xdp_queues; i++)
  6167. set_check_for_tx_hang(adapter->xdp_ring[i]);
  6168. }
  6169. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  6170. /*
  6171. * for legacy and MSI interrupts don't set any bits
  6172. * that are enabled for EIAM, because this operation
  6173. * would set *both* EIMS and EICS for any bit in EIAM
  6174. */
  6175. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  6176. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  6177. } else {
  6178. /* get one bit for every active tx/rx interrupt vector */
  6179. for (i = 0; i < adapter->num_q_vectors; i++) {
  6180. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  6181. if (qv->rx.ring || qv->tx.ring)
  6182. eics |= BIT_ULL(i);
  6183. }
  6184. }
  6185. /* Cause software interrupt to ensure rings are cleaned */
  6186. ixgbe_irq_rearm_queues(adapter, eics);
  6187. }
  6188. /**
  6189. * ixgbe_watchdog_update_link - update the link status
  6190. * @adapter: pointer to the device adapter structure
  6191. **/
  6192. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  6193. {
  6194. struct ixgbe_hw *hw = &adapter->hw;
  6195. u32 link_speed = adapter->link_speed;
  6196. bool link_up = adapter->link_up;
  6197. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  6198. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  6199. return;
  6200. if (hw->mac.ops.check_link) {
  6201. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  6202. } else {
  6203. /* always assume link is up, if no check link function */
  6204. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  6205. link_up = true;
  6206. }
  6207. if (adapter->ixgbe_ieee_pfc)
  6208. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  6209. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  6210. hw->mac.ops.fc_enable(hw);
  6211. ixgbe_set_rx_drop_en(adapter);
  6212. }
  6213. if (link_up ||
  6214. time_after(jiffies, (adapter->link_check_timeout +
  6215. IXGBE_TRY_LINK_TIMEOUT))) {
  6216. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  6217. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  6218. IXGBE_WRITE_FLUSH(hw);
  6219. }
  6220. adapter->link_up = link_up;
  6221. adapter->link_speed = link_speed;
  6222. }
  6223. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  6224. {
  6225. #ifdef CONFIG_IXGBE_DCB
  6226. struct net_device *netdev = adapter->netdev;
  6227. struct dcb_app app = {
  6228. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  6229. .protocol = 0,
  6230. };
  6231. u8 up = 0;
  6232. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  6233. up = dcb_ieee_getapp_mask(netdev, &app);
  6234. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  6235. #endif
  6236. }
  6237. /**
  6238. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  6239. * print link up message
  6240. * @adapter: pointer to the device adapter structure
  6241. **/
  6242. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  6243. {
  6244. struct net_device *netdev = adapter->netdev;
  6245. struct ixgbe_hw *hw = &adapter->hw;
  6246. u32 link_speed = adapter->link_speed;
  6247. const char *speed_str;
  6248. bool flow_rx, flow_tx;
  6249. /* only continue if link was previously down */
  6250. if (netif_carrier_ok(netdev))
  6251. return;
  6252. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  6253. switch (hw->mac.type) {
  6254. case ixgbe_mac_82598EB: {
  6255. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  6256. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  6257. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  6258. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  6259. }
  6260. break;
  6261. case ixgbe_mac_X540:
  6262. case ixgbe_mac_X550:
  6263. case ixgbe_mac_X550EM_x:
  6264. case ixgbe_mac_x550em_a:
  6265. case ixgbe_mac_82599EB: {
  6266. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  6267. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  6268. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  6269. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  6270. }
  6271. break;
  6272. default:
  6273. flow_tx = false;
  6274. flow_rx = false;
  6275. break;
  6276. }
  6277. adapter->last_rx_ptp_check = jiffies;
  6278. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6279. ixgbe_ptp_start_cyclecounter(adapter);
  6280. switch (link_speed) {
  6281. case IXGBE_LINK_SPEED_10GB_FULL:
  6282. speed_str = "10 Gbps";
  6283. break;
  6284. case IXGBE_LINK_SPEED_5GB_FULL:
  6285. speed_str = "5 Gbps";
  6286. break;
  6287. case IXGBE_LINK_SPEED_2_5GB_FULL:
  6288. speed_str = "2.5 Gbps";
  6289. break;
  6290. case IXGBE_LINK_SPEED_1GB_FULL:
  6291. speed_str = "1 Gbps";
  6292. break;
  6293. case IXGBE_LINK_SPEED_100_FULL:
  6294. speed_str = "100 Mbps";
  6295. break;
  6296. case IXGBE_LINK_SPEED_10_FULL:
  6297. speed_str = "10 Mbps";
  6298. break;
  6299. default:
  6300. speed_str = "unknown speed";
  6301. break;
  6302. }
  6303. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
  6304. ((flow_rx && flow_tx) ? "RX/TX" :
  6305. (flow_rx ? "RX" :
  6306. (flow_tx ? "TX" : "None"))));
  6307. netif_carrier_on(netdev);
  6308. ixgbe_check_vf_rate_limit(adapter);
  6309. /* enable transmits */
  6310. netif_tx_wake_all_queues(adapter->netdev);
  6311. /* update the default user priority for VFs */
  6312. ixgbe_update_default_up(adapter);
  6313. /* ping all the active vfs to let them know link has changed */
  6314. ixgbe_ping_all_vfs(adapter);
  6315. }
  6316. /**
  6317. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  6318. * print link down message
  6319. * @adapter: pointer to the adapter structure
  6320. **/
  6321. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  6322. {
  6323. struct net_device *netdev = adapter->netdev;
  6324. struct ixgbe_hw *hw = &adapter->hw;
  6325. adapter->link_up = false;
  6326. adapter->link_speed = 0;
  6327. /* only continue if link was up previously */
  6328. if (!netif_carrier_ok(netdev))
  6329. return;
  6330. /* poll for SFP+ cable when link is down */
  6331. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  6332. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  6333. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6334. ixgbe_ptp_start_cyclecounter(adapter);
  6335. e_info(drv, "NIC Link is Down\n");
  6336. netif_carrier_off(netdev);
  6337. /* ping all the active vfs to let them know link has changed */
  6338. ixgbe_ping_all_vfs(adapter);
  6339. }
  6340. static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
  6341. {
  6342. int i;
  6343. for (i = 0; i < adapter->num_tx_queues; i++) {
  6344. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  6345. if (tx_ring->next_to_use != tx_ring->next_to_clean)
  6346. return true;
  6347. }
  6348. for (i = 0; i < adapter->num_xdp_queues; i++) {
  6349. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  6350. if (ring->next_to_use != ring->next_to_clean)
  6351. return true;
  6352. }
  6353. return false;
  6354. }
  6355. static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
  6356. {
  6357. struct ixgbe_hw *hw = &adapter->hw;
  6358. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  6359. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  6360. int i, j;
  6361. if (!adapter->num_vfs)
  6362. return false;
  6363. /* resetting the PF is only needed for MAC before X550 */
  6364. if (hw->mac.type >= ixgbe_mac_X550)
  6365. return false;
  6366. for (i = 0; i < adapter->num_vfs; i++) {
  6367. for (j = 0; j < q_per_pool; j++) {
  6368. u32 h, t;
  6369. h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
  6370. t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
  6371. if (h != t)
  6372. return true;
  6373. }
  6374. }
  6375. return false;
  6376. }
  6377. /**
  6378. * ixgbe_watchdog_flush_tx - flush queues on link down
  6379. * @adapter: pointer to the device adapter structure
  6380. **/
  6381. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  6382. {
  6383. if (!netif_carrier_ok(adapter->netdev)) {
  6384. if (ixgbe_ring_tx_pending(adapter) ||
  6385. ixgbe_vf_tx_pending(adapter)) {
  6386. /* We've lost link, so the controller stops DMA,
  6387. * but we've got queued Tx work that's never going
  6388. * to get done, so reset controller to flush Tx.
  6389. * (Do the reset outside of interrupt context).
  6390. */
  6391. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  6392. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  6393. }
  6394. }
  6395. }
  6396. #ifdef CONFIG_PCI_IOV
  6397. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  6398. {
  6399. struct ixgbe_hw *hw = &adapter->hw;
  6400. struct pci_dev *pdev = adapter->pdev;
  6401. unsigned int vf;
  6402. u32 gpc;
  6403. if (!(netif_carrier_ok(adapter->netdev)))
  6404. return;
  6405. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  6406. if (gpc) /* If incrementing then no need for the check below */
  6407. return;
  6408. /* Check to see if a bad DMA write target from an errant or
  6409. * malicious VF has caused a PCIe error. If so then we can
  6410. * issue a VFLR to the offending VF(s) and then resume without
  6411. * requesting a full slot reset.
  6412. */
  6413. if (!pdev)
  6414. return;
  6415. /* check status reg for all VFs owned by this PF */
  6416. for (vf = 0; vf < adapter->num_vfs; ++vf) {
  6417. struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
  6418. u16 status_reg;
  6419. if (!vfdev)
  6420. continue;
  6421. pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
  6422. if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
  6423. status_reg & PCI_STATUS_REC_MASTER_ABORT)
  6424. pcie_flr(vfdev);
  6425. }
  6426. }
  6427. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  6428. {
  6429. u32 ssvpc;
  6430. /* Do not perform spoof check for 82598 or if not in IOV mode */
  6431. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  6432. adapter->num_vfs == 0)
  6433. return;
  6434. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  6435. /*
  6436. * ssvpc register is cleared on read, if zero then no
  6437. * spoofed packets in the last interval.
  6438. */
  6439. if (!ssvpc)
  6440. return;
  6441. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  6442. }
  6443. #else
  6444. static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
  6445. {
  6446. }
  6447. static void
  6448. ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
  6449. {
  6450. }
  6451. #endif /* CONFIG_PCI_IOV */
  6452. /**
  6453. * ixgbe_watchdog_subtask - check and bring link up
  6454. * @adapter: pointer to the device adapter structure
  6455. **/
  6456. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  6457. {
  6458. /* if interface is down, removing or resetting, do nothing */
  6459. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6460. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6461. test_bit(__IXGBE_RESETTING, &adapter->state))
  6462. return;
  6463. ixgbe_watchdog_update_link(adapter);
  6464. if (adapter->link_up)
  6465. ixgbe_watchdog_link_is_up(adapter);
  6466. else
  6467. ixgbe_watchdog_link_is_down(adapter);
  6468. ixgbe_check_for_bad_vf(adapter);
  6469. ixgbe_spoof_check(adapter);
  6470. ixgbe_update_stats(adapter);
  6471. ixgbe_watchdog_flush_tx(adapter);
  6472. }
  6473. /**
  6474. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  6475. * @adapter: the ixgbe adapter structure
  6476. **/
  6477. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  6478. {
  6479. struct ixgbe_hw *hw = &adapter->hw;
  6480. s32 err;
  6481. /* not searching for SFP so there is nothing to do here */
  6482. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  6483. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6484. return;
  6485. if (adapter->sfp_poll_time &&
  6486. time_after(adapter->sfp_poll_time, jiffies))
  6487. return; /* If not yet time to poll for SFP */
  6488. /* someone else is in init, wait until next service event */
  6489. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6490. return;
  6491. adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
  6492. err = hw->phy.ops.identify_sfp(hw);
  6493. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6494. goto sfp_out;
  6495. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  6496. /* If no cable is present, then we need to reset
  6497. * the next time we find a good cable. */
  6498. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  6499. }
  6500. /* exit on error */
  6501. if (err)
  6502. goto sfp_out;
  6503. /* exit if reset not needed */
  6504. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6505. goto sfp_out;
  6506. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  6507. /*
  6508. * A module may be identified correctly, but the EEPROM may not have
  6509. * support for that module. setup_sfp() will fail in that case, so
  6510. * we should not allow that module to load.
  6511. */
  6512. if (hw->mac.type == ixgbe_mac_82598EB)
  6513. err = hw->phy.ops.reset(hw);
  6514. else
  6515. err = hw->mac.ops.setup_sfp(hw);
  6516. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6517. goto sfp_out;
  6518. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  6519. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  6520. sfp_out:
  6521. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6522. if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
  6523. (adapter->netdev->reg_state == NETREG_REGISTERED)) {
  6524. e_dev_err("failed to initialize because an unsupported "
  6525. "SFP+ module type was detected.\n");
  6526. e_dev_err("Reload the driver after installing a "
  6527. "supported module.\n");
  6528. unregister_netdev(adapter->netdev);
  6529. }
  6530. }
  6531. /**
  6532. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  6533. * @adapter: the ixgbe adapter structure
  6534. **/
  6535. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  6536. {
  6537. struct ixgbe_hw *hw = &adapter->hw;
  6538. u32 cap_speed;
  6539. u32 speed;
  6540. bool autoneg = false;
  6541. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  6542. return;
  6543. /* someone else is in init, wait until next service event */
  6544. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6545. return;
  6546. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  6547. hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
  6548. /* advertise highest capable link speed */
  6549. if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
  6550. speed = IXGBE_LINK_SPEED_10GB_FULL;
  6551. else
  6552. speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
  6553. IXGBE_LINK_SPEED_1GB_FULL);
  6554. if (hw->mac.ops.setup_link)
  6555. hw->mac.ops.setup_link(hw, speed, true);
  6556. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  6557. adapter->link_check_timeout = jiffies;
  6558. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6559. }
  6560. /**
  6561. * ixgbe_service_timer - Timer Call-back
  6562. * @t: pointer to timer_list structure
  6563. **/
  6564. static void ixgbe_service_timer(struct timer_list *t)
  6565. {
  6566. struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
  6567. unsigned long next_event_offset;
  6568. /* poll faster when waiting for link */
  6569. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  6570. next_event_offset = HZ / 10;
  6571. else
  6572. next_event_offset = HZ * 2;
  6573. /* Reset the timer */
  6574. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  6575. ixgbe_service_event_schedule(adapter);
  6576. }
  6577. static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
  6578. {
  6579. struct ixgbe_hw *hw = &adapter->hw;
  6580. u32 status;
  6581. if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
  6582. return;
  6583. adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
  6584. if (!hw->phy.ops.handle_lasi)
  6585. return;
  6586. status = hw->phy.ops.handle_lasi(&adapter->hw);
  6587. if (status != IXGBE_ERR_OVERTEMP)
  6588. return;
  6589. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  6590. }
  6591. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  6592. {
  6593. if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
  6594. return;
  6595. rtnl_lock();
  6596. /* If we're already down, removing or resetting, just bail */
  6597. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6598. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6599. test_bit(__IXGBE_RESETTING, &adapter->state)) {
  6600. rtnl_unlock();
  6601. return;
  6602. }
  6603. ixgbe_dump(adapter);
  6604. netdev_err(adapter->netdev, "Reset adapter\n");
  6605. adapter->tx_timeout_count++;
  6606. ixgbe_reinit_locked(adapter);
  6607. rtnl_unlock();
  6608. }
  6609. /**
  6610. * ixgbe_service_task - manages and runs subtasks
  6611. * @work: pointer to work_struct containing our data
  6612. **/
  6613. static void ixgbe_service_task(struct work_struct *work)
  6614. {
  6615. struct ixgbe_adapter *adapter = container_of(work,
  6616. struct ixgbe_adapter,
  6617. service_task);
  6618. if (ixgbe_removed(adapter->hw.hw_addr)) {
  6619. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  6620. rtnl_lock();
  6621. ixgbe_down(adapter);
  6622. rtnl_unlock();
  6623. }
  6624. ixgbe_service_event_complete(adapter);
  6625. return;
  6626. }
  6627. if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
  6628. rtnl_lock();
  6629. adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  6630. udp_tunnel_get_rx_info(adapter->netdev);
  6631. rtnl_unlock();
  6632. }
  6633. ixgbe_reset_subtask(adapter);
  6634. ixgbe_phy_interrupt_subtask(adapter);
  6635. ixgbe_sfp_detection_subtask(adapter);
  6636. ixgbe_sfp_link_config_subtask(adapter);
  6637. ixgbe_check_overtemp_subtask(adapter);
  6638. ixgbe_watchdog_subtask(adapter);
  6639. ixgbe_fdir_reinit_subtask(adapter);
  6640. ixgbe_check_hang_subtask(adapter);
  6641. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
  6642. ixgbe_ptp_overflow_check(adapter);
  6643. if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER)
  6644. ixgbe_ptp_rx_hang(adapter);
  6645. ixgbe_ptp_tx_hang(adapter);
  6646. }
  6647. ixgbe_service_event_complete(adapter);
  6648. }
  6649. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  6650. struct ixgbe_tx_buffer *first,
  6651. u8 *hdr_len,
  6652. struct ixgbe_ipsec_tx_data *itd)
  6653. {
  6654. u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
  6655. struct sk_buff *skb = first->skb;
  6656. union {
  6657. struct iphdr *v4;
  6658. struct ipv6hdr *v6;
  6659. unsigned char *hdr;
  6660. } ip;
  6661. union {
  6662. struct tcphdr *tcp;
  6663. unsigned char *hdr;
  6664. } l4;
  6665. u32 paylen, l4_offset;
  6666. u32 fceof_saidx = 0;
  6667. int err;
  6668. if (skb->ip_summed != CHECKSUM_PARTIAL)
  6669. return 0;
  6670. if (!skb_is_gso(skb))
  6671. return 0;
  6672. err = skb_cow_head(skb, 0);
  6673. if (err < 0)
  6674. return err;
  6675. if (eth_p_mpls(first->protocol))
  6676. ip.hdr = skb_inner_network_header(skb);
  6677. else
  6678. ip.hdr = skb_network_header(skb);
  6679. l4.hdr = skb_checksum_start(skb);
  6680. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  6681. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6682. /* initialize outer IP header fields */
  6683. if (ip.v4->version == 4) {
  6684. unsigned char *csum_start = skb_checksum_start(skb);
  6685. unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
  6686. int len = csum_start - trans_start;
  6687. /* IP header will have to cancel out any data that
  6688. * is not a part of the outer IP header, so set to
  6689. * a reverse csum if needed, else init check to 0.
  6690. */
  6691. ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
  6692. csum_fold(csum_partial(trans_start,
  6693. len, 0)) : 0;
  6694. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  6695. ip.v4->tot_len = 0;
  6696. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6697. IXGBE_TX_FLAGS_CSUM |
  6698. IXGBE_TX_FLAGS_IPV4;
  6699. } else {
  6700. ip.v6->payload_len = 0;
  6701. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6702. IXGBE_TX_FLAGS_CSUM;
  6703. }
  6704. /* determine offset of inner transport header */
  6705. l4_offset = l4.hdr - skb->data;
  6706. /* compute length of segmentation header */
  6707. *hdr_len = (l4.tcp->doff * 4) + l4_offset;
  6708. /* remove payload length from inner checksum */
  6709. paylen = skb->len - l4_offset;
  6710. csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen));
  6711. /* update gso size and bytecount with header size */
  6712. first->gso_segs = skb_shinfo(skb)->gso_segs;
  6713. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  6714. /* mss_l4len_id: use 0 as index for TSO */
  6715. mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
  6716. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  6717. fceof_saidx |= itd->sa_idx;
  6718. type_tucmd |= itd->flags | itd->trailer_len;
  6719. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  6720. vlan_macip_lens = l4.hdr - ip.hdr;
  6721. vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6722. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6723. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
  6724. mss_l4len_idx);
  6725. return 1;
  6726. }
  6727. static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
  6728. {
  6729. unsigned int offset = 0;
  6730. ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
  6731. return offset == skb_checksum_start_offset(skb);
  6732. }
  6733. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  6734. struct ixgbe_tx_buffer *first,
  6735. struct ixgbe_ipsec_tx_data *itd)
  6736. {
  6737. struct sk_buff *skb = first->skb;
  6738. u32 vlan_macip_lens = 0;
  6739. u32 fceof_saidx = 0;
  6740. u32 type_tucmd = 0;
  6741. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  6742. csum_failed:
  6743. if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
  6744. IXGBE_TX_FLAGS_CC)))
  6745. return;
  6746. goto no_csum;
  6747. }
  6748. switch (skb->csum_offset) {
  6749. case offsetof(struct tcphdr, check):
  6750. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6751. /* fall through */
  6752. case offsetof(struct udphdr, check):
  6753. break;
  6754. case offsetof(struct sctphdr, checksum):
  6755. /* validate that this is actually an SCTP request */
  6756. if (((first->protocol == htons(ETH_P_IP)) &&
  6757. (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
  6758. ((first->protocol == htons(ETH_P_IPV6)) &&
  6759. ixgbe_ipv6_csum_is_sctp(skb))) {
  6760. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  6761. break;
  6762. }
  6763. /* fall through */
  6764. default:
  6765. skb_checksum_help(skb);
  6766. goto csum_failed;
  6767. }
  6768. /* update TX checksum flag */
  6769. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  6770. vlan_macip_lens = skb_checksum_start_offset(skb) -
  6771. skb_network_offset(skb);
  6772. no_csum:
  6773. /* vlan_macip_lens: MACLEN, VLAN tag */
  6774. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6775. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6776. fceof_saidx |= itd->sa_idx;
  6777. type_tucmd |= itd->flags | itd->trailer_len;
  6778. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
  6779. }
  6780. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  6781. ((_flag <= _result) ? \
  6782. ((u32)(_input & _flag) * (_result / _flag)) : \
  6783. ((u32)(_input & _flag) / (_flag / _result)))
  6784. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  6785. {
  6786. /* set type for advanced descriptor with frame checksum insertion */
  6787. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  6788. IXGBE_ADVTXD_DCMD_DEXT |
  6789. IXGBE_ADVTXD_DCMD_IFCS;
  6790. /* set HW vlan bit if vlan is present */
  6791. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  6792. IXGBE_ADVTXD_DCMD_VLE);
  6793. /* set segmentation enable bits for TSO/FSO */
  6794. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  6795. IXGBE_ADVTXD_DCMD_TSE);
  6796. /* set timestamp bit if present */
  6797. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  6798. IXGBE_ADVTXD_MAC_TSTAMP);
  6799. /* insert frame checksum */
  6800. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  6801. return cmd_type;
  6802. }
  6803. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  6804. u32 tx_flags, unsigned int paylen)
  6805. {
  6806. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  6807. /* enable L4 checksum for TSO and TX checksum offload */
  6808. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6809. IXGBE_TX_FLAGS_CSUM,
  6810. IXGBE_ADVTXD_POPTS_TXSM);
  6811. /* enable IPv4 checksum for TSO */
  6812. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6813. IXGBE_TX_FLAGS_IPV4,
  6814. IXGBE_ADVTXD_POPTS_IXSM);
  6815. /* enable IPsec */
  6816. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6817. IXGBE_TX_FLAGS_IPSEC,
  6818. IXGBE_ADVTXD_POPTS_IPSEC);
  6819. /*
  6820. * Check Context must be set if Tx switch is enabled, which it
  6821. * always is for case where virtual functions are running
  6822. */
  6823. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6824. IXGBE_TX_FLAGS_CC,
  6825. IXGBE_ADVTXD_CC);
  6826. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  6827. }
  6828. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6829. {
  6830. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6831. /* Herbert's original patch had:
  6832. * smp_mb__after_netif_stop_queue();
  6833. * but since that doesn't exist yet, just open code it.
  6834. */
  6835. smp_mb();
  6836. /* We need to check again in a case another CPU has just
  6837. * made room available.
  6838. */
  6839. if (likely(ixgbe_desc_unused(tx_ring) < size))
  6840. return -EBUSY;
  6841. /* A reprieve! - use start_queue because it doesn't call schedule */
  6842. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6843. ++tx_ring->tx_stats.restart_queue;
  6844. return 0;
  6845. }
  6846. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6847. {
  6848. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  6849. return 0;
  6850. return __ixgbe_maybe_stop_tx(tx_ring, size);
  6851. }
  6852. #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
  6853. IXGBE_TXD_CMD_RS)
  6854. static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  6855. struct ixgbe_tx_buffer *first,
  6856. const u8 hdr_len)
  6857. {
  6858. struct sk_buff *skb = first->skb;
  6859. struct ixgbe_tx_buffer *tx_buffer;
  6860. union ixgbe_adv_tx_desc *tx_desc;
  6861. struct skb_frag_struct *frag;
  6862. dma_addr_t dma;
  6863. unsigned int data_len, size;
  6864. u32 tx_flags = first->tx_flags;
  6865. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  6866. u16 i = tx_ring->next_to_use;
  6867. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  6868. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  6869. size = skb_headlen(skb);
  6870. data_len = skb->data_len;
  6871. #ifdef IXGBE_FCOE
  6872. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  6873. if (data_len < sizeof(struct fcoe_crc_eof)) {
  6874. size -= sizeof(struct fcoe_crc_eof) - data_len;
  6875. data_len = 0;
  6876. } else {
  6877. data_len -= sizeof(struct fcoe_crc_eof);
  6878. }
  6879. }
  6880. #endif
  6881. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  6882. tx_buffer = first;
  6883. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  6884. if (dma_mapping_error(tx_ring->dev, dma))
  6885. goto dma_error;
  6886. /* record length, and DMA address */
  6887. dma_unmap_len_set(tx_buffer, len, size);
  6888. dma_unmap_addr_set(tx_buffer, dma, dma);
  6889. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6890. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  6891. tx_desc->read.cmd_type_len =
  6892. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  6893. i++;
  6894. tx_desc++;
  6895. if (i == tx_ring->count) {
  6896. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6897. i = 0;
  6898. }
  6899. tx_desc->read.olinfo_status = 0;
  6900. dma += IXGBE_MAX_DATA_PER_TXD;
  6901. size -= IXGBE_MAX_DATA_PER_TXD;
  6902. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6903. }
  6904. if (likely(!data_len))
  6905. break;
  6906. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  6907. i++;
  6908. tx_desc++;
  6909. if (i == tx_ring->count) {
  6910. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6911. i = 0;
  6912. }
  6913. tx_desc->read.olinfo_status = 0;
  6914. #ifdef IXGBE_FCOE
  6915. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  6916. #else
  6917. size = skb_frag_size(frag);
  6918. #endif
  6919. data_len -= size;
  6920. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  6921. DMA_TO_DEVICE);
  6922. tx_buffer = &tx_ring->tx_buffer_info[i];
  6923. }
  6924. /* write last descriptor with RS and EOP bits */
  6925. cmd_type |= size | IXGBE_TXD_CMD;
  6926. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  6927. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  6928. /* set the timestamp */
  6929. first->time_stamp = jiffies;
  6930. /*
  6931. * Force memory writes to complete before letting h/w know there
  6932. * are new descriptors to fetch. (Only applicable for weak-ordered
  6933. * memory model archs, such as IA-64).
  6934. *
  6935. * We also need this memory barrier to make certain all of the
  6936. * status bits have been updated before next_to_watch is written.
  6937. */
  6938. wmb();
  6939. /* set next_to_watch value indicating a packet is present */
  6940. first->next_to_watch = tx_desc;
  6941. i++;
  6942. if (i == tx_ring->count)
  6943. i = 0;
  6944. tx_ring->next_to_use = i;
  6945. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  6946. if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
  6947. writel(i, tx_ring->tail);
  6948. /* we need this if more than one processor can write to our tail
  6949. * at a time, it synchronizes IO on IA64/Altix systems
  6950. */
  6951. mmiowb();
  6952. }
  6953. return 0;
  6954. dma_error:
  6955. dev_err(tx_ring->dev, "TX DMA map failed\n");
  6956. /* clear dma mappings for failed tx_buffer_info map */
  6957. for (;;) {
  6958. tx_buffer = &tx_ring->tx_buffer_info[i];
  6959. if (dma_unmap_len(tx_buffer, len))
  6960. dma_unmap_page(tx_ring->dev,
  6961. dma_unmap_addr(tx_buffer, dma),
  6962. dma_unmap_len(tx_buffer, len),
  6963. DMA_TO_DEVICE);
  6964. dma_unmap_len_set(tx_buffer, len, 0);
  6965. if (tx_buffer == first)
  6966. break;
  6967. if (i == 0)
  6968. i += tx_ring->count;
  6969. i--;
  6970. }
  6971. dev_kfree_skb_any(first->skb);
  6972. first->skb = NULL;
  6973. tx_ring->next_to_use = i;
  6974. return -1;
  6975. }
  6976. static void ixgbe_atr(struct ixgbe_ring *ring,
  6977. struct ixgbe_tx_buffer *first)
  6978. {
  6979. struct ixgbe_q_vector *q_vector = ring->q_vector;
  6980. union ixgbe_atr_hash_dword input = { .dword = 0 };
  6981. union ixgbe_atr_hash_dword common = { .dword = 0 };
  6982. union {
  6983. unsigned char *network;
  6984. struct iphdr *ipv4;
  6985. struct ipv6hdr *ipv6;
  6986. } hdr;
  6987. struct tcphdr *th;
  6988. unsigned int hlen;
  6989. struct sk_buff *skb;
  6990. __be16 vlan_id;
  6991. int l4_proto;
  6992. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  6993. if (!q_vector)
  6994. return;
  6995. /* do nothing if sampling is disabled */
  6996. if (!ring->atr_sample_rate)
  6997. return;
  6998. ring->atr_count++;
  6999. /* currently only IPv4/IPv6 with TCP is supported */
  7000. if ((first->protocol != htons(ETH_P_IP)) &&
  7001. (first->protocol != htons(ETH_P_IPV6)))
  7002. return;
  7003. /* snag network header to get L4 type and address */
  7004. skb = first->skb;
  7005. hdr.network = skb_network_header(skb);
  7006. if (unlikely(hdr.network <= skb->data))
  7007. return;
  7008. if (skb->encapsulation &&
  7009. first->protocol == htons(ETH_P_IP) &&
  7010. hdr.ipv4->protocol == IPPROTO_UDP) {
  7011. struct ixgbe_adapter *adapter = q_vector->adapter;
  7012. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  7013. VXLAN_HEADROOM))
  7014. return;
  7015. /* verify the port is recognized as VXLAN */
  7016. if (adapter->vxlan_port &&
  7017. udp_hdr(skb)->dest == adapter->vxlan_port)
  7018. hdr.network = skb_inner_network_header(skb);
  7019. if (adapter->geneve_port &&
  7020. udp_hdr(skb)->dest == adapter->geneve_port)
  7021. hdr.network = skb_inner_network_header(skb);
  7022. }
  7023. /* Make sure we have at least [minimum IPv4 header + TCP]
  7024. * or [IPv6 header] bytes
  7025. */
  7026. if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
  7027. return;
  7028. /* Currently only IPv4/IPv6 with TCP is supported */
  7029. switch (hdr.ipv4->version) {
  7030. case IPVERSION:
  7031. /* access ihl as u8 to avoid unaligned access on ia64 */
  7032. hlen = (hdr.network[0] & 0x0F) << 2;
  7033. l4_proto = hdr.ipv4->protocol;
  7034. break;
  7035. case 6:
  7036. hlen = hdr.network - skb->data;
  7037. l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
  7038. hlen -= hdr.network - skb->data;
  7039. break;
  7040. default:
  7041. return;
  7042. }
  7043. if (l4_proto != IPPROTO_TCP)
  7044. return;
  7045. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  7046. hlen + sizeof(struct tcphdr)))
  7047. return;
  7048. th = (struct tcphdr *)(hdr.network + hlen);
  7049. /* skip this packet since the socket is closing */
  7050. if (th->fin)
  7051. return;
  7052. /* sample on all syn packets or once every atr sample count */
  7053. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  7054. return;
  7055. /* reset sample count */
  7056. ring->atr_count = 0;
  7057. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  7058. /*
  7059. * src and dst are inverted, think how the receiver sees them
  7060. *
  7061. * The input is broken into two sections, a non-compressed section
  7062. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  7063. * is XORed together and stored in the compressed dword.
  7064. */
  7065. input.formatted.vlan_id = vlan_id;
  7066. /*
  7067. * since src port and flex bytes occupy the same word XOR them together
  7068. * and write the value to source port portion of compressed dword
  7069. */
  7070. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  7071. common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
  7072. else
  7073. common.port.src ^= th->dest ^ first->protocol;
  7074. common.port.dst ^= th->source;
  7075. switch (hdr.ipv4->version) {
  7076. case IPVERSION:
  7077. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  7078. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  7079. break;
  7080. case 6:
  7081. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  7082. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  7083. hdr.ipv6->saddr.s6_addr32[1] ^
  7084. hdr.ipv6->saddr.s6_addr32[2] ^
  7085. hdr.ipv6->saddr.s6_addr32[3] ^
  7086. hdr.ipv6->daddr.s6_addr32[0] ^
  7087. hdr.ipv6->daddr.s6_addr32[1] ^
  7088. hdr.ipv6->daddr.s6_addr32[2] ^
  7089. hdr.ipv6->daddr.s6_addr32[3];
  7090. break;
  7091. default:
  7092. break;
  7093. }
  7094. if (hdr.network != skb_network_header(skb))
  7095. input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
  7096. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  7097. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  7098. input, common, ring->queue_index);
  7099. }
  7100. #ifdef IXGBE_FCOE
  7101. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
  7102. struct net_device *sb_dev,
  7103. select_queue_fallback_t fallback)
  7104. {
  7105. struct ixgbe_adapter *adapter;
  7106. struct ixgbe_ring_feature *f;
  7107. int txq;
  7108. if (sb_dev) {
  7109. u8 tc = netdev_get_prio_tc_map(dev, skb->priority);
  7110. struct net_device *vdev = sb_dev;
  7111. txq = vdev->tc_to_txq[tc].offset;
  7112. txq += reciprocal_scale(skb_get_hash(skb),
  7113. vdev->tc_to_txq[tc].count);
  7114. return txq;
  7115. }
  7116. /*
  7117. * only execute the code below if protocol is FCoE
  7118. * or FIP and we have FCoE enabled on the adapter
  7119. */
  7120. switch (vlan_get_protocol(skb)) {
  7121. case htons(ETH_P_FCOE):
  7122. case htons(ETH_P_FIP):
  7123. adapter = netdev_priv(dev);
  7124. if (!sb_dev && (adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  7125. break;
  7126. /* fall through */
  7127. default:
  7128. return fallback(dev, skb, sb_dev);
  7129. }
  7130. f = &adapter->ring_feature[RING_F_FCOE];
  7131. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  7132. smp_processor_id();
  7133. while (txq >= f->indices)
  7134. txq -= f->indices;
  7135. return txq + f->offset;
  7136. }
  7137. #endif
  7138. static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
  7139. struct xdp_frame *xdpf)
  7140. {
  7141. struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
  7142. struct ixgbe_tx_buffer *tx_buffer;
  7143. union ixgbe_adv_tx_desc *tx_desc;
  7144. u32 len, cmd_type;
  7145. dma_addr_t dma;
  7146. u16 i;
  7147. len = xdpf->len;
  7148. if (unlikely(!ixgbe_desc_unused(ring)))
  7149. return IXGBE_XDP_CONSUMED;
  7150. dma = dma_map_single(ring->dev, xdpf->data, len, DMA_TO_DEVICE);
  7151. if (dma_mapping_error(ring->dev, dma))
  7152. return IXGBE_XDP_CONSUMED;
  7153. /* record the location of the first descriptor for this packet */
  7154. tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
  7155. tx_buffer->bytecount = len;
  7156. tx_buffer->gso_segs = 1;
  7157. tx_buffer->protocol = 0;
  7158. i = ring->next_to_use;
  7159. tx_desc = IXGBE_TX_DESC(ring, i);
  7160. dma_unmap_len_set(tx_buffer, len, len);
  7161. dma_unmap_addr_set(tx_buffer, dma, dma);
  7162. tx_buffer->xdpf = xdpf;
  7163. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  7164. /* put descriptor type bits */
  7165. cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  7166. IXGBE_ADVTXD_DCMD_DEXT |
  7167. IXGBE_ADVTXD_DCMD_IFCS;
  7168. cmd_type |= len | IXGBE_TXD_CMD;
  7169. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  7170. tx_desc->read.olinfo_status =
  7171. cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
  7172. /* Avoid any potential race with xdp_xmit and cleanup */
  7173. smp_wmb();
  7174. /* set next_to_watch value indicating a packet is present */
  7175. i++;
  7176. if (i == ring->count)
  7177. i = 0;
  7178. tx_buffer->next_to_watch = tx_desc;
  7179. ring->next_to_use = i;
  7180. return IXGBE_XDP_TX;
  7181. }
  7182. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  7183. struct ixgbe_adapter *adapter,
  7184. struct ixgbe_ring *tx_ring)
  7185. {
  7186. struct ixgbe_tx_buffer *first;
  7187. int tso;
  7188. u32 tx_flags = 0;
  7189. unsigned short f;
  7190. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  7191. struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
  7192. __be16 protocol = skb->protocol;
  7193. u8 hdr_len = 0;
  7194. /*
  7195. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  7196. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  7197. * + 2 desc gap to keep tail from touching head,
  7198. * + 1 desc for context descriptor,
  7199. * otherwise try next time
  7200. */
  7201. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  7202. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  7203. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  7204. tx_ring->tx_stats.tx_busy++;
  7205. return NETDEV_TX_BUSY;
  7206. }
  7207. /* record the location of the first descriptor for this packet */
  7208. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  7209. first->skb = skb;
  7210. first->bytecount = skb->len;
  7211. first->gso_segs = 1;
  7212. /* if we have a HW VLAN tag being added default to the HW one */
  7213. if (skb_vlan_tag_present(skb)) {
  7214. tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  7215. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  7216. /* else if it is a SW VLAN check the next protocol and store the tag */
  7217. } else if (protocol == htons(ETH_P_8021Q)) {
  7218. struct vlan_hdr *vhdr, _vhdr;
  7219. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  7220. if (!vhdr)
  7221. goto out_drop;
  7222. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  7223. IXGBE_TX_FLAGS_VLAN_SHIFT;
  7224. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  7225. }
  7226. protocol = vlan_get_protocol(skb);
  7227. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  7228. adapter->ptp_clock) {
  7229. if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
  7230. &adapter->state)) {
  7231. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  7232. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  7233. /* schedule check for Tx timestamp */
  7234. adapter->ptp_tx_skb = skb_get(skb);
  7235. adapter->ptp_tx_start = jiffies;
  7236. schedule_work(&adapter->ptp_tx_work);
  7237. } else {
  7238. adapter->tx_hwtstamp_skipped++;
  7239. }
  7240. }
  7241. skb_tx_timestamp(skb);
  7242. #ifdef CONFIG_PCI_IOV
  7243. /*
  7244. * Use the l2switch_enable flag - would be false if the DMA
  7245. * Tx switch had been disabled.
  7246. */
  7247. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  7248. tx_flags |= IXGBE_TX_FLAGS_CC;
  7249. #endif
  7250. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  7251. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  7252. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  7253. (skb->priority != TC_PRIO_CONTROL))) {
  7254. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  7255. tx_flags |= (skb->priority & 0x7) <<
  7256. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  7257. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  7258. struct vlan_ethhdr *vhdr;
  7259. if (skb_cow_head(skb, 0))
  7260. goto out_drop;
  7261. vhdr = (struct vlan_ethhdr *)skb->data;
  7262. vhdr->h_vlan_TCI = htons(tx_flags >>
  7263. IXGBE_TX_FLAGS_VLAN_SHIFT);
  7264. } else {
  7265. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  7266. }
  7267. }
  7268. /* record initial flags and protocol */
  7269. first->tx_flags = tx_flags;
  7270. first->protocol = protocol;
  7271. #ifdef IXGBE_FCOE
  7272. /* setup tx offload for FCoE */
  7273. if ((protocol == htons(ETH_P_FCOE)) &&
  7274. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  7275. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  7276. if (tso < 0)
  7277. goto out_drop;
  7278. goto xmit_fcoe;
  7279. }
  7280. #endif /* IXGBE_FCOE */
  7281. #ifdef CONFIG_XFRM_OFFLOAD
  7282. if (skb->sp && !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
  7283. goto out_drop;
  7284. #endif
  7285. tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx);
  7286. if (tso < 0)
  7287. goto out_drop;
  7288. else if (!tso)
  7289. ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
  7290. /* add the ATR filter if ATR is on */
  7291. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  7292. ixgbe_atr(tx_ring, first);
  7293. #ifdef IXGBE_FCOE
  7294. xmit_fcoe:
  7295. #endif /* IXGBE_FCOE */
  7296. if (ixgbe_tx_map(tx_ring, first, hdr_len))
  7297. goto cleanup_tx_timestamp;
  7298. return NETDEV_TX_OK;
  7299. out_drop:
  7300. dev_kfree_skb_any(first->skb);
  7301. first->skb = NULL;
  7302. cleanup_tx_timestamp:
  7303. if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
  7304. dev_kfree_skb_any(adapter->ptp_tx_skb);
  7305. adapter->ptp_tx_skb = NULL;
  7306. cancel_work_sync(&adapter->ptp_tx_work);
  7307. clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
  7308. }
  7309. return NETDEV_TX_OK;
  7310. }
  7311. static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
  7312. struct net_device *netdev,
  7313. struct ixgbe_ring *ring)
  7314. {
  7315. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7316. struct ixgbe_ring *tx_ring;
  7317. /*
  7318. * The minimum packet size for olinfo paylen is 17 so pad the skb
  7319. * in order to meet this minimum size requirement.
  7320. */
  7321. if (skb_put_padto(skb, 17))
  7322. return NETDEV_TX_OK;
  7323. tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
  7324. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  7325. }
  7326. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  7327. struct net_device *netdev)
  7328. {
  7329. return __ixgbe_xmit_frame(skb, netdev, NULL);
  7330. }
  7331. /**
  7332. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  7333. * @netdev: network interface device structure
  7334. * @p: pointer to an address structure
  7335. *
  7336. * Returns 0 on success, negative on failure
  7337. **/
  7338. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  7339. {
  7340. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7341. struct ixgbe_hw *hw = &adapter->hw;
  7342. struct sockaddr *addr = p;
  7343. if (!is_valid_ether_addr(addr->sa_data))
  7344. return -EADDRNOTAVAIL;
  7345. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  7346. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  7347. ixgbe_mac_set_default_filter(adapter);
  7348. return 0;
  7349. }
  7350. static int
  7351. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  7352. {
  7353. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7354. struct ixgbe_hw *hw = &adapter->hw;
  7355. u16 value;
  7356. int rc;
  7357. if (prtad != hw->phy.mdio.prtad)
  7358. return -EINVAL;
  7359. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  7360. if (!rc)
  7361. rc = value;
  7362. return rc;
  7363. }
  7364. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  7365. u16 addr, u16 value)
  7366. {
  7367. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7368. struct ixgbe_hw *hw = &adapter->hw;
  7369. if (prtad != hw->phy.mdio.prtad)
  7370. return -EINVAL;
  7371. return hw->phy.ops.write_reg(hw, addr, devad, value);
  7372. }
  7373. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  7374. {
  7375. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7376. switch (cmd) {
  7377. case SIOCSHWTSTAMP:
  7378. return ixgbe_ptp_set_ts_config(adapter, req);
  7379. case SIOCGHWTSTAMP:
  7380. return ixgbe_ptp_get_ts_config(adapter, req);
  7381. case SIOCGMIIPHY:
  7382. if (!adapter->hw.phy.ops.read_reg)
  7383. return -EOPNOTSUPP;
  7384. /* fall through */
  7385. default:
  7386. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  7387. }
  7388. }
  7389. /**
  7390. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  7391. * netdev->dev_addrs
  7392. * @dev: network interface device structure
  7393. *
  7394. * Returns non-zero on failure
  7395. **/
  7396. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  7397. {
  7398. int err = 0;
  7399. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7400. struct ixgbe_hw *hw = &adapter->hw;
  7401. if (is_valid_ether_addr(hw->mac.san_addr)) {
  7402. rtnl_lock();
  7403. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  7404. rtnl_unlock();
  7405. /* update SAN MAC vmdq pool selection */
  7406. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  7407. }
  7408. return err;
  7409. }
  7410. /**
  7411. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  7412. * netdev->dev_addrs
  7413. * @dev: network interface device structure
  7414. *
  7415. * Returns non-zero on failure
  7416. **/
  7417. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  7418. {
  7419. int err = 0;
  7420. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7421. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  7422. if (is_valid_ether_addr(mac->san_addr)) {
  7423. rtnl_lock();
  7424. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  7425. rtnl_unlock();
  7426. }
  7427. return err;
  7428. }
  7429. #ifdef CONFIG_NET_POLL_CONTROLLER
  7430. /*
  7431. * Polling 'interrupt' - used by things like netconsole to send skbs
  7432. * without having to re-enable interrupts. It's not called while
  7433. * the interrupt routine is executing.
  7434. */
  7435. static void ixgbe_netpoll(struct net_device *netdev)
  7436. {
  7437. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7438. int i;
  7439. /* if interface is down do nothing */
  7440. if (test_bit(__IXGBE_DOWN, &adapter->state))
  7441. return;
  7442. /* loop through and schedule all active queues */
  7443. for (i = 0; i < adapter->num_q_vectors; i++)
  7444. ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
  7445. }
  7446. #endif
  7447. static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
  7448. struct ixgbe_ring *ring)
  7449. {
  7450. u64 bytes, packets;
  7451. unsigned int start;
  7452. if (ring) {
  7453. do {
  7454. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7455. packets = ring->stats.packets;
  7456. bytes = ring->stats.bytes;
  7457. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7458. stats->tx_packets += packets;
  7459. stats->tx_bytes += bytes;
  7460. }
  7461. }
  7462. static void ixgbe_get_stats64(struct net_device *netdev,
  7463. struct rtnl_link_stats64 *stats)
  7464. {
  7465. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7466. int i;
  7467. rcu_read_lock();
  7468. for (i = 0; i < adapter->num_rx_queues; i++) {
  7469. struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
  7470. u64 bytes, packets;
  7471. unsigned int start;
  7472. if (ring) {
  7473. do {
  7474. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7475. packets = ring->stats.packets;
  7476. bytes = ring->stats.bytes;
  7477. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7478. stats->rx_packets += packets;
  7479. stats->rx_bytes += bytes;
  7480. }
  7481. }
  7482. for (i = 0; i < adapter->num_tx_queues; i++) {
  7483. struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
  7484. ixgbe_get_ring_stats64(stats, ring);
  7485. }
  7486. for (i = 0; i < adapter->num_xdp_queues; i++) {
  7487. struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
  7488. ixgbe_get_ring_stats64(stats, ring);
  7489. }
  7490. rcu_read_unlock();
  7491. /* following stats updated by ixgbe_watchdog_task() */
  7492. stats->multicast = netdev->stats.multicast;
  7493. stats->rx_errors = netdev->stats.rx_errors;
  7494. stats->rx_length_errors = netdev->stats.rx_length_errors;
  7495. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  7496. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  7497. }
  7498. #ifdef CONFIG_IXGBE_DCB
  7499. /**
  7500. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  7501. * @adapter: pointer to ixgbe_adapter
  7502. * @tc: number of traffic classes currently enabled
  7503. *
  7504. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  7505. * 802.1Q priority maps to a packet buffer that exists.
  7506. */
  7507. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  7508. {
  7509. struct ixgbe_hw *hw = &adapter->hw;
  7510. u32 reg, rsave;
  7511. int i;
  7512. /* 82598 have a static priority to TC mapping that can not
  7513. * be changed so no validation is needed.
  7514. */
  7515. if (hw->mac.type == ixgbe_mac_82598EB)
  7516. return;
  7517. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  7518. rsave = reg;
  7519. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  7520. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  7521. /* If up2tc is out of bounds default to zero */
  7522. if (up2tc > tc)
  7523. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  7524. }
  7525. if (reg != rsave)
  7526. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  7527. return;
  7528. }
  7529. /**
  7530. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  7531. * @adapter: Pointer to adapter struct
  7532. *
  7533. * Populate the netdev user priority to tc map
  7534. */
  7535. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  7536. {
  7537. struct net_device *dev = adapter->netdev;
  7538. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  7539. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  7540. u8 prio;
  7541. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  7542. u8 tc = 0;
  7543. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  7544. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  7545. else if (ets)
  7546. tc = ets->prio_tc[prio];
  7547. netdev_set_prio_tc_map(dev, prio, tc);
  7548. }
  7549. }
  7550. #endif /* CONFIG_IXGBE_DCB */
  7551. static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
  7552. {
  7553. struct ixgbe_adapter *adapter = data;
  7554. struct ixgbe_fwd_adapter *accel;
  7555. int pool;
  7556. /* we only care about macvlans... */
  7557. if (!netif_is_macvlan(vdev))
  7558. return 0;
  7559. /* that have hardware offload enabled... */
  7560. accel = macvlan_accel_priv(vdev);
  7561. if (!accel)
  7562. return 0;
  7563. /* If we can relocate to a different bit do so */
  7564. pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
  7565. if (pool < adapter->num_rx_pools) {
  7566. set_bit(pool, adapter->fwd_bitmask);
  7567. accel->pool = pool;
  7568. return 0;
  7569. }
  7570. /* if we cannot find a free pool then disable the offload */
  7571. netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n");
  7572. macvlan_release_l2fw_offload(vdev);
  7573. /* unbind the queues and drop the subordinate channel config */
  7574. netdev_unbind_sb_channel(adapter->netdev, vdev);
  7575. netdev_set_sb_channel(vdev, 0);
  7576. kfree(accel);
  7577. return 0;
  7578. }
  7579. static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
  7580. {
  7581. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7582. /* flush any stale bits out of the fwd bitmask */
  7583. bitmap_clear(adapter->fwd_bitmask, 1, 63);
  7584. /* walk through upper devices reassigning pools */
  7585. netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
  7586. adapter);
  7587. }
  7588. /**
  7589. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  7590. *
  7591. * @dev: net device to configure
  7592. * @tc: number of traffic classes to enable
  7593. */
  7594. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  7595. {
  7596. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7597. struct ixgbe_hw *hw = &adapter->hw;
  7598. /* Hardware supports up to 8 traffic classes */
  7599. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
  7600. return -EINVAL;
  7601. if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
  7602. return -EINVAL;
  7603. /* Hardware has to reinitialize queues and interrupts to
  7604. * match packet buffer alignment. Unfortunately, the
  7605. * hardware is not flexible enough to do this dynamically.
  7606. */
  7607. if (netif_running(dev))
  7608. ixgbe_close(dev);
  7609. else
  7610. ixgbe_reset(adapter);
  7611. ixgbe_clear_interrupt_scheme(adapter);
  7612. #ifdef CONFIG_IXGBE_DCB
  7613. if (tc) {
  7614. if (adapter->xdp_prog) {
  7615. e_warn(probe, "DCB is not supported with XDP\n");
  7616. ixgbe_init_interrupt_scheme(adapter);
  7617. if (netif_running(dev))
  7618. ixgbe_open(dev);
  7619. return -EINVAL;
  7620. }
  7621. netdev_set_num_tc(dev, tc);
  7622. ixgbe_set_prio_tc_map(adapter);
  7623. adapter->hw_tcs = tc;
  7624. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  7625. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  7626. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  7627. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  7628. }
  7629. } else {
  7630. netdev_reset_tc(dev);
  7631. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  7632. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  7633. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  7634. adapter->hw_tcs = tc;
  7635. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  7636. adapter->dcb_cfg.pfc_mode_enable = false;
  7637. }
  7638. ixgbe_validate_rtr(adapter, tc);
  7639. #endif /* CONFIG_IXGBE_DCB */
  7640. ixgbe_init_interrupt_scheme(adapter);
  7641. ixgbe_defrag_macvlan_pools(dev);
  7642. if (netif_running(dev))
  7643. return ixgbe_open(dev);
  7644. return 0;
  7645. }
  7646. static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
  7647. struct tc_cls_u32_offload *cls)
  7648. {
  7649. u32 hdl = cls->knode.handle;
  7650. u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
  7651. u32 loc = cls->knode.handle & 0xfffff;
  7652. int err = 0, i, j;
  7653. struct ixgbe_jump_table *jump = NULL;
  7654. if (loc > IXGBE_MAX_HW_ENTRIES)
  7655. return -EINVAL;
  7656. if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
  7657. return -EINVAL;
  7658. /* Clear this filter in the link data it is associated with */
  7659. if (uhtid != 0x800) {
  7660. jump = adapter->jump_tables[uhtid];
  7661. if (!jump)
  7662. return -EINVAL;
  7663. if (!test_bit(loc - 1, jump->child_loc_map))
  7664. return -EINVAL;
  7665. clear_bit(loc - 1, jump->child_loc_map);
  7666. }
  7667. /* Check if the filter being deleted is a link */
  7668. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7669. jump = adapter->jump_tables[i];
  7670. if (jump && jump->link_hdl == hdl) {
  7671. /* Delete filters in the hardware in the child hash
  7672. * table associated with this link
  7673. */
  7674. for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
  7675. if (!test_bit(j, jump->child_loc_map))
  7676. continue;
  7677. spin_lock(&adapter->fdir_perfect_lock);
  7678. err = ixgbe_update_ethtool_fdir_entry(adapter,
  7679. NULL,
  7680. j + 1);
  7681. spin_unlock(&adapter->fdir_perfect_lock);
  7682. clear_bit(j, jump->child_loc_map);
  7683. }
  7684. /* Remove resources for this link */
  7685. kfree(jump->input);
  7686. kfree(jump->mask);
  7687. kfree(jump);
  7688. adapter->jump_tables[i] = NULL;
  7689. return err;
  7690. }
  7691. }
  7692. spin_lock(&adapter->fdir_perfect_lock);
  7693. err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
  7694. spin_unlock(&adapter->fdir_perfect_lock);
  7695. return err;
  7696. }
  7697. static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
  7698. struct tc_cls_u32_offload *cls)
  7699. {
  7700. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7701. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7702. return -EINVAL;
  7703. /* This ixgbe devices do not support hash tables at the moment
  7704. * so abort when given hash tables.
  7705. */
  7706. if (cls->hnode.divisor > 0)
  7707. return -EINVAL;
  7708. set_bit(uhtid - 1, &adapter->tables);
  7709. return 0;
  7710. }
  7711. static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
  7712. struct tc_cls_u32_offload *cls)
  7713. {
  7714. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7715. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7716. return -EINVAL;
  7717. clear_bit(uhtid - 1, &adapter->tables);
  7718. return 0;
  7719. }
  7720. #ifdef CONFIG_NET_CLS_ACT
  7721. struct upper_walk_data {
  7722. struct ixgbe_adapter *adapter;
  7723. u64 action;
  7724. int ifindex;
  7725. u8 queue;
  7726. };
  7727. static int get_macvlan_queue(struct net_device *upper, void *_data)
  7728. {
  7729. if (netif_is_macvlan(upper)) {
  7730. struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
  7731. struct upper_walk_data *data = _data;
  7732. struct ixgbe_adapter *adapter = data->adapter;
  7733. int ifindex = data->ifindex;
  7734. if (vadapter && upper->ifindex == ifindex) {
  7735. data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
  7736. data->action = data->queue;
  7737. return 1;
  7738. }
  7739. }
  7740. return 0;
  7741. }
  7742. static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
  7743. u8 *queue, u64 *action)
  7744. {
  7745. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  7746. unsigned int num_vfs = adapter->num_vfs, vf;
  7747. struct upper_walk_data data;
  7748. struct net_device *upper;
  7749. /* redirect to a SRIOV VF */
  7750. for (vf = 0; vf < num_vfs; ++vf) {
  7751. upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
  7752. if (upper->ifindex == ifindex) {
  7753. *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
  7754. *action = vf + 1;
  7755. *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  7756. return 0;
  7757. }
  7758. }
  7759. /* redirect to a offloaded macvlan netdev */
  7760. data.adapter = adapter;
  7761. data.ifindex = ifindex;
  7762. data.action = 0;
  7763. data.queue = 0;
  7764. if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
  7765. get_macvlan_queue, &data)) {
  7766. *action = data.action;
  7767. *queue = data.queue;
  7768. return 0;
  7769. }
  7770. return -EINVAL;
  7771. }
  7772. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7773. struct tcf_exts *exts, u64 *action, u8 *queue)
  7774. {
  7775. const struct tc_action *a;
  7776. int i;
  7777. if (!tcf_exts_has_actions(exts))
  7778. return -EINVAL;
  7779. tcf_exts_for_each_action(i, a, exts) {
  7780. /* Drop action */
  7781. if (is_tcf_gact_shot(a)) {
  7782. *action = IXGBE_FDIR_DROP_QUEUE;
  7783. *queue = IXGBE_FDIR_DROP_QUEUE;
  7784. return 0;
  7785. }
  7786. /* Redirect to a VF or a offloaded macvlan */
  7787. if (is_tcf_mirred_egress_redirect(a)) {
  7788. struct net_device *dev = tcf_mirred_dev(a);
  7789. if (!dev)
  7790. return -EINVAL;
  7791. return handle_redirect_action(adapter, dev->ifindex,
  7792. queue, action);
  7793. }
  7794. return -EINVAL;
  7795. }
  7796. return -EINVAL;
  7797. }
  7798. #else
  7799. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7800. struct tcf_exts *exts, u64 *action, u8 *queue)
  7801. {
  7802. return -EINVAL;
  7803. }
  7804. #endif /* CONFIG_NET_CLS_ACT */
  7805. static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
  7806. union ixgbe_atr_input *mask,
  7807. struct tc_cls_u32_offload *cls,
  7808. struct ixgbe_mat_field *field_ptr,
  7809. struct ixgbe_nexthdr *nexthdr)
  7810. {
  7811. int i, j, off;
  7812. __be32 val, m;
  7813. bool found_entry = false, found_jump_field = false;
  7814. for (i = 0; i < cls->knode.sel->nkeys; i++) {
  7815. off = cls->knode.sel->keys[i].off;
  7816. val = cls->knode.sel->keys[i].val;
  7817. m = cls->knode.sel->keys[i].mask;
  7818. for (j = 0; field_ptr[j].val; j++) {
  7819. if (field_ptr[j].off == off) {
  7820. field_ptr[j].val(input, mask, (__force u32)val,
  7821. (__force u32)m);
  7822. input->filter.formatted.flow_type |=
  7823. field_ptr[j].type;
  7824. found_entry = true;
  7825. break;
  7826. }
  7827. }
  7828. if (nexthdr) {
  7829. if (nexthdr->off == cls->knode.sel->keys[i].off &&
  7830. nexthdr->val ==
  7831. (__force u32)cls->knode.sel->keys[i].val &&
  7832. nexthdr->mask ==
  7833. (__force u32)cls->knode.sel->keys[i].mask)
  7834. found_jump_field = true;
  7835. else
  7836. continue;
  7837. }
  7838. }
  7839. if (nexthdr && !found_jump_field)
  7840. return -EINVAL;
  7841. if (!found_entry)
  7842. return 0;
  7843. mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
  7844. IXGBE_ATR_L4TYPE_MASK;
  7845. if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
  7846. mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
  7847. return 0;
  7848. }
  7849. static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  7850. struct tc_cls_u32_offload *cls)
  7851. {
  7852. __be16 protocol = cls->common.protocol;
  7853. u32 loc = cls->knode.handle & 0xfffff;
  7854. struct ixgbe_hw *hw = &adapter->hw;
  7855. struct ixgbe_mat_field *field_ptr;
  7856. struct ixgbe_fdir_filter *input = NULL;
  7857. union ixgbe_atr_input *mask = NULL;
  7858. struct ixgbe_jump_table *jump = NULL;
  7859. int i, err = -EINVAL;
  7860. u8 queue;
  7861. u32 uhtid, link_uhtid;
  7862. uhtid = TC_U32_USERHTID(cls->knode.handle);
  7863. link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
  7864. /* At the moment cls_u32 jumps to network layer and skips past
  7865. * L2 headers. The canonical method to match L2 frames is to use
  7866. * negative values. However this is error prone at best but really
  7867. * just broken because there is no way to "know" what sort of hdr
  7868. * is in front of the network layer. Fix cls_u32 to support L2
  7869. * headers when needed.
  7870. */
  7871. if (protocol != htons(ETH_P_IP))
  7872. return err;
  7873. if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
  7874. e_err(drv, "Location out of range\n");
  7875. return err;
  7876. }
  7877. /* cls u32 is a graph starting at root node 0x800. The driver tracks
  7878. * links and also the fields used to advance the parser across each
  7879. * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
  7880. * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
  7881. * To add support for new nodes update ixgbe_model.h parse structures
  7882. * this function _should_ be generic try not to hardcode values here.
  7883. */
  7884. if (uhtid == 0x800) {
  7885. field_ptr = (adapter->jump_tables[0])->mat;
  7886. } else {
  7887. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7888. return err;
  7889. if (!adapter->jump_tables[uhtid])
  7890. return err;
  7891. field_ptr = (adapter->jump_tables[uhtid])->mat;
  7892. }
  7893. if (!field_ptr)
  7894. return err;
  7895. /* At this point we know the field_ptr is valid and need to either
  7896. * build cls_u32 link or attach filter. Because adding a link to
  7897. * a handle that does not exist is invalid and the same for adding
  7898. * rules to handles that don't exist.
  7899. */
  7900. if (link_uhtid) {
  7901. struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
  7902. if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
  7903. return err;
  7904. if (!test_bit(link_uhtid - 1, &adapter->tables))
  7905. return err;
  7906. /* Multiple filters as links to the same hash table are not
  7907. * supported. To add a new filter with the same next header
  7908. * but different match/jump conditions, create a new hash table
  7909. * and link to it.
  7910. */
  7911. if (adapter->jump_tables[link_uhtid] &&
  7912. (adapter->jump_tables[link_uhtid])->link_hdl) {
  7913. e_err(drv, "Link filter exists for link: %x\n",
  7914. link_uhtid);
  7915. return err;
  7916. }
  7917. for (i = 0; nexthdr[i].jump; i++) {
  7918. if (nexthdr[i].o != cls->knode.sel->offoff ||
  7919. nexthdr[i].s != cls->knode.sel->offshift ||
  7920. nexthdr[i].m !=
  7921. (__force u32)cls->knode.sel->offmask)
  7922. return err;
  7923. jump = kzalloc(sizeof(*jump), GFP_KERNEL);
  7924. if (!jump)
  7925. return -ENOMEM;
  7926. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7927. if (!input) {
  7928. err = -ENOMEM;
  7929. goto free_jump;
  7930. }
  7931. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7932. if (!mask) {
  7933. err = -ENOMEM;
  7934. goto free_input;
  7935. }
  7936. jump->input = input;
  7937. jump->mask = mask;
  7938. jump->link_hdl = cls->knode.handle;
  7939. err = ixgbe_clsu32_build_input(input, mask, cls,
  7940. field_ptr, &nexthdr[i]);
  7941. if (!err) {
  7942. jump->mat = nexthdr[i].jump;
  7943. adapter->jump_tables[link_uhtid] = jump;
  7944. break;
  7945. }
  7946. }
  7947. return 0;
  7948. }
  7949. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7950. if (!input)
  7951. return -ENOMEM;
  7952. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7953. if (!mask) {
  7954. err = -ENOMEM;
  7955. goto free_input;
  7956. }
  7957. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
  7958. if ((adapter->jump_tables[uhtid])->input)
  7959. memcpy(input, (adapter->jump_tables[uhtid])->input,
  7960. sizeof(*input));
  7961. if ((adapter->jump_tables[uhtid])->mask)
  7962. memcpy(mask, (adapter->jump_tables[uhtid])->mask,
  7963. sizeof(*mask));
  7964. /* Lookup in all child hash tables if this location is already
  7965. * filled with a filter
  7966. */
  7967. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7968. struct ixgbe_jump_table *link = adapter->jump_tables[i];
  7969. if (link && (test_bit(loc - 1, link->child_loc_map))) {
  7970. e_err(drv, "Filter exists in location: %x\n",
  7971. loc);
  7972. err = -EINVAL;
  7973. goto err_out;
  7974. }
  7975. }
  7976. }
  7977. err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
  7978. if (err)
  7979. goto err_out;
  7980. err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
  7981. &queue);
  7982. if (err < 0)
  7983. goto err_out;
  7984. input->sw_idx = loc;
  7985. spin_lock(&adapter->fdir_perfect_lock);
  7986. if (hlist_empty(&adapter->fdir_filter_list)) {
  7987. memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
  7988. err = ixgbe_fdir_set_input_mask_82599(hw, mask);
  7989. if (err)
  7990. goto err_out_w_lock;
  7991. } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
  7992. err = -EINVAL;
  7993. goto err_out_w_lock;
  7994. }
  7995. ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
  7996. err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
  7997. input->sw_idx, queue);
  7998. if (!err)
  7999. ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
  8000. spin_unlock(&adapter->fdir_perfect_lock);
  8001. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
  8002. set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
  8003. kfree(mask);
  8004. return err;
  8005. err_out_w_lock:
  8006. spin_unlock(&adapter->fdir_perfect_lock);
  8007. err_out:
  8008. kfree(mask);
  8009. free_input:
  8010. kfree(input);
  8011. free_jump:
  8012. kfree(jump);
  8013. return err;
  8014. }
  8015. static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
  8016. struct tc_cls_u32_offload *cls_u32)
  8017. {
  8018. switch (cls_u32->command) {
  8019. case TC_CLSU32_NEW_KNODE:
  8020. case TC_CLSU32_REPLACE_KNODE:
  8021. return ixgbe_configure_clsu32(adapter, cls_u32);
  8022. case TC_CLSU32_DELETE_KNODE:
  8023. return ixgbe_delete_clsu32(adapter, cls_u32);
  8024. case TC_CLSU32_NEW_HNODE:
  8025. case TC_CLSU32_REPLACE_HNODE:
  8026. return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
  8027. case TC_CLSU32_DELETE_HNODE:
  8028. return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
  8029. default:
  8030. return -EOPNOTSUPP;
  8031. }
  8032. }
  8033. static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  8034. void *cb_priv)
  8035. {
  8036. struct ixgbe_adapter *adapter = cb_priv;
  8037. if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
  8038. return -EOPNOTSUPP;
  8039. switch (type) {
  8040. case TC_SETUP_CLSU32:
  8041. return ixgbe_setup_tc_cls_u32(adapter, type_data);
  8042. default:
  8043. return -EOPNOTSUPP;
  8044. }
  8045. }
  8046. static int ixgbe_setup_tc_block(struct net_device *dev,
  8047. struct tc_block_offload *f)
  8048. {
  8049. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8050. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  8051. return -EOPNOTSUPP;
  8052. switch (f->command) {
  8053. case TC_BLOCK_BIND:
  8054. return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
  8055. adapter, adapter, f->extack);
  8056. case TC_BLOCK_UNBIND:
  8057. tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
  8058. adapter);
  8059. return 0;
  8060. default:
  8061. return -EOPNOTSUPP;
  8062. }
  8063. }
  8064. static int ixgbe_setup_tc_mqprio(struct net_device *dev,
  8065. struct tc_mqprio_qopt *mqprio)
  8066. {
  8067. mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  8068. return ixgbe_setup_tc(dev, mqprio->num_tc);
  8069. }
  8070. static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
  8071. void *type_data)
  8072. {
  8073. switch (type) {
  8074. case TC_SETUP_BLOCK:
  8075. return ixgbe_setup_tc_block(dev, type_data);
  8076. case TC_SETUP_QDISC_MQPRIO:
  8077. return ixgbe_setup_tc_mqprio(dev, type_data);
  8078. default:
  8079. return -EOPNOTSUPP;
  8080. }
  8081. }
  8082. #ifdef CONFIG_PCI_IOV
  8083. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  8084. {
  8085. struct net_device *netdev = adapter->netdev;
  8086. rtnl_lock();
  8087. ixgbe_setup_tc(netdev, adapter->hw_tcs);
  8088. rtnl_unlock();
  8089. }
  8090. #endif
  8091. void ixgbe_do_reset(struct net_device *netdev)
  8092. {
  8093. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  8094. if (netif_running(netdev))
  8095. ixgbe_reinit_locked(adapter);
  8096. else
  8097. ixgbe_reset(adapter);
  8098. }
  8099. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  8100. netdev_features_t features)
  8101. {
  8102. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  8103. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  8104. if (!(features & NETIF_F_RXCSUM))
  8105. features &= ~NETIF_F_LRO;
  8106. /* Turn off LRO if not RSC capable */
  8107. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  8108. features &= ~NETIF_F_LRO;
  8109. if (adapter->xdp_prog && (features & NETIF_F_LRO)) {
  8110. e_dev_err("LRO is not supported with XDP\n");
  8111. features &= ~NETIF_F_LRO;
  8112. }
  8113. return features;
  8114. }
  8115. static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter)
  8116. {
  8117. int rss = min_t(int, ixgbe_max_rss_indices(adapter),
  8118. num_online_cpus());
  8119. /* go back to full RSS if we're not running SR-IOV */
  8120. if (!adapter->ring_feature[RING_F_VMDQ].offset)
  8121. adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED |
  8122. IXGBE_FLAG_SRIOV_ENABLED);
  8123. adapter->ring_feature[RING_F_RSS].limit = rss;
  8124. adapter->ring_feature[RING_F_VMDQ].limit = 1;
  8125. ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs);
  8126. }
  8127. static int ixgbe_set_features(struct net_device *netdev,
  8128. netdev_features_t features)
  8129. {
  8130. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  8131. netdev_features_t changed = netdev->features ^ features;
  8132. bool need_reset = false;
  8133. /* Make sure RSC matches LRO, reset if change */
  8134. if (!(features & NETIF_F_LRO)) {
  8135. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  8136. need_reset = true;
  8137. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  8138. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  8139. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  8140. if (adapter->rx_itr_setting == 1 ||
  8141. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  8142. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  8143. need_reset = true;
  8144. } else if ((changed ^ features) & NETIF_F_LRO) {
  8145. e_info(probe, "rx-usecs set too low, "
  8146. "disabling RSC\n");
  8147. }
  8148. }
  8149. /*
  8150. * Check if Flow Director n-tuple support or hw_tc support was
  8151. * enabled or disabled. If the state changed, we need to reset.
  8152. */
  8153. if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
  8154. /* turn off ATR, enable perfect filters and reset */
  8155. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  8156. need_reset = true;
  8157. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  8158. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  8159. } else {
  8160. /* turn off perfect filters, enable ATR and reset */
  8161. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  8162. need_reset = true;
  8163. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  8164. /* We cannot enable ATR if SR-IOV is enabled */
  8165. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
  8166. /* We cannot enable ATR if we have 2 or more tcs */
  8167. (adapter->hw_tcs > 1) ||
  8168. /* We cannot enable ATR if RSS is disabled */
  8169. (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
  8170. /* A sample rate of 0 indicates ATR disabled */
  8171. (!adapter->atr_sample_rate))
  8172. ; /* do nothing not supported */
  8173. else /* otherwise supported and set the flag */
  8174. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  8175. }
  8176. if (changed & NETIF_F_RXALL)
  8177. need_reset = true;
  8178. netdev->features = features;
  8179. if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
  8180. if (features & NETIF_F_RXCSUM) {
  8181. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  8182. } else {
  8183. u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  8184. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  8185. }
  8186. }
  8187. if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
  8188. if (features & NETIF_F_RXCSUM) {
  8189. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  8190. } else {
  8191. u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  8192. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  8193. }
  8194. }
  8195. if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
  8196. ixgbe_reset_l2fw_offload(adapter);
  8197. else if (need_reset)
  8198. ixgbe_do_reset(netdev);
  8199. else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
  8200. NETIF_F_HW_VLAN_CTAG_FILTER))
  8201. ixgbe_set_rx_mode(netdev);
  8202. return 0;
  8203. }
  8204. /**
  8205. * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
  8206. * @dev: The port's netdev
  8207. * @ti: Tunnel endpoint information
  8208. **/
  8209. static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
  8210. struct udp_tunnel_info *ti)
  8211. {
  8212. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8213. struct ixgbe_hw *hw = &adapter->hw;
  8214. __be16 port = ti->port;
  8215. u32 port_shift = 0;
  8216. u32 reg;
  8217. if (ti->sa_family != AF_INET)
  8218. return;
  8219. switch (ti->type) {
  8220. case UDP_TUNNEL_TYPE_VXLAN:
  8221. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  8222. return;
  8223. if (adapter->vxlan_port == port)
  8224. return;
  8225. if (adapter->vxlan_port) {
  8226. netdev_info(dev,
  8227. "VXLAN port %d set, not adding port %d\n",
  8228. ntohs(adapter->vxlan_port),
  8229. ntohs(port));
  8230. return;
  8231. }
  8232. adapter->vxlan_port = port;
  8233. break;
  8234. case UDP_TUNNEL_TYPE_GENEVE:
  8235. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  8236. return;
  8237. if (adapter->geneve_port == port)
  8238. return;
  8239. if (adapter->geneve_port) {
  8240. netdev_info(dev,
  8241. "GENEVE port %d set, not adding port %d\n",
  8242. ntohs(adapter->geneve_port),
  8243. ntohs(port));
  8244. return;
  8245. }
  8246. port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
  8247. adapter->geneve_port = port;
  8248. break;
  8249. default:
  8250. return;
  8251. }
  8252. reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
  8253. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
  8254. }
  8255. /**
  8256. * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
  8257. * @dev: The port's netdev
  8258. * @ti: Tunnel endpoint information
  8259. **/
  8260. static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
  8261. struct udp_tunnel_info *ti)
  8262. {
  8263. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8264. u32 port_mask;
  8265. if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
  8266. ti->type != UDP_TUNNEL_TYPE_GENEVE)
  8267. return;
  8268. if (ti->sa_family != AF_INET)
  8269. return;
  8270. switch (ti->type) {
  8271. case UDP_TUNNEL_TYPE_VXLAN:
  8272. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  8273. return;
  8274. if (adapter->vxlan_port != ti->port) {
  8275. netdev_info(dev, "VXLAN port %d not found\n",
  8276. ntohs(ti->port));
  8277. return;
  8278. }
  8279. port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  8280. break;
  8281. case UDP_TUNNEL_TYPE_GENEVE:
  8282. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  8283. return;
  8284. if (adapter->geneve_port != ti->port) {
  8285. netdev_info(dev, "GENEVE port %d not found\n",
  8286. ntohs(ti->port));
  8287. return;
  8288. }
  8289. port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  8290. break;
  8291. default:
  8292. return;
  8293. }
  8294. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  8295. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  8296. }
  8297. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  8298. struct net_device *dev,
  8299. const unsigned char *addr, u16 vid,
  8300. u16 flags)
  8301. {
  8302. /* guarantee we can provide a unique filter for the unicast address */
  8303. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  8304. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8305. u16 pool = VMDQ_P(0);
  8306. if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
  8307. return -ENOMEM;
  8308. }
  8309. return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
  8310. }
  8311. /**
  8312. * ixgbe_configure_bridge_mode - set various bridge modes
  8313. * @adapter: the private structure
  8314. * @mode: requested bridge mode
  8315. *
  8316. * Configure some settings require for various bridge modes.
  8317. **/
  8318. static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
  8319. __u16 mode)
  8320. {
  8321. struct ixgbe_hw *hw = &adapter->hw;
  8322. unsigned int p, num_pools;
  8323. u32 vmdctl;
  8324. switch (mode) {
  8325. case BRIDGE_MODE_VEPA:
  8326. /* disable Tx loopback, rely on switch hairpin mode */
  8327. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
  8328. /* must enable Rx switching replication to allow multicast
  8329. * packet reception on all VFs, and to enable source address
  8330. * pruning.
  8331. */
  8332. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  8333. vmdctl |= IXGBE_VT_CTL_REPLEN;
  8334. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  8335. /* enable Rx source address pruning. Note, this requires
  8336. * replication to be enabled or else it does nothing.
  8337. */
  8338. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  8339. for (p = 0; p < num_pools; p++) {
  8340. if (hw->mac.ops.set_source_address_pruning)
  8341. hw->mac.ops.set_source_address_pruning(hw,
  8342. true,
  8343. p);
  8344. }
  8345. break;
  8346. case BRIDGE_MODE_VEB:
  8347. /* enable Tx loopback for internal VF/PF communication */
  8348. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
  8349. IXGBE_PFDTXGSWC_VT_LBEN);
  8350. /* disable Rx switching replication unless we have SR-IOV
  8351. * virtual functions
  8352. */
  8353. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  8354. if (!adapter->num_vfs)
  8355. vmdctl &= ~IXGBE_VT_CTL_REPLEN;
  8356. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  8357. /* disable Rx source address pruning, since we don't expect to
  8358. * be receiving external loopback of our transmitted frames.
  8359. */
  8360. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  8361. for (p = 0; p < num_pools; p++) {
  8362. if (hw->mac.ops.set_source_address_pruning)
  8363. hw->mac.ops.set_source_address_pruning(hw,
  8364. false,
  8365. p);
  8366. }
  8367. break;
  8368. default:
  8369. return -EINVAL;
  8370. }
  8371. adapter->bridge_mode = mode;
  8372. e_info(drv, "enabling bridge mode: %s\n",
  8373. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  8374. return 0;
  8375. }
  8376. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  8377. struct nlmsghdr *nlh, u16 flags)
  8378. {
  8379. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8380. struct nlattr *attr, *br_spec;
  8381. int rem;
  8382. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  8383. return -EOPNOTSUPP;
  8384. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  8385. if (!br_spec)
  8386. return -EINVAL;
  8387. nla_for_each_nested(attr, br_spec, rem) {
  8388. int status;
  8389. __u16 mode;
  8390. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  8391. continue;
  8392. if (nla_len(attr) < sizeof(mode))
  8393. return -EINVAL;
  8394. mode = nla_get_u16(attr);
  8395. status = ixgbe_configure_bridge_mode(adapter, mode);
  8396. if (status)
  8397. return status;
  8398. break;
  8399. }
  8400. return 0;
  8401. }
  8402. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  8403. struct net_device *dev,
  8404. u32 filter_mask, int nlflags)
  8405. {
  8406. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8407. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  8408. return 0;
  8409. return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
  8410. adapter->bridge_mode, 0, 0, nlflags,
  8411. filter_mask, NULL);
  8412. }
  8413. static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
  8414. {
  8415. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  8416. struct ixgbe_fwd_adapter *accel;
  8417. int tcs = adapter->hw_tcs ? : 1;
  8418. int pool, err;
  8419. if (adapter->xdp_prog) {
  8420. e_warn(probe, "L2FW offload is not supported with XDP\n");
  8421. return ERR_PTR(-EINVAL);
  8422. }
  8423. /* The hardware supported by ixgbe only filters on the destination MAC
  8424. * address. In order to avoid issues we only support offloading modes
  8425. * where the hardware can actually provide the functionality.
  8426. */
  8427. if (!macvlan_supports_dest_filter(vdev))
  8428. return ERR_PTR(-EMEDIUMTYPE);
  8429. /* We need to lock down the macvlan to be a single queue device so that
  8430. * we can reuse the tc_to_txq field in the macvlan netdev to represent
  8431. * the queue mapping to our netdev.
  8432. */
  8433. if (netif_is_multiqueue(vdev))
  8434. return ERR_PTR(-ERANGE);
  8435. pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
  8436. if (pool == adapter->num_rx_pools) {
  8437. u16 used_pools = adapter->num_vfs + adapter->num_rx_pools;
  8438. u16 reserved_pools;
  8439. if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  8440. adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
  8441. adapter->num_rx_pools > IXGBE_MAX_MACVLANS)
  8442. return ERR_PTR(-EBUSY);
  8443. /* Hardware has a limited number of available pools. Each VF,
  8444. * and the PF require a pool. Check to ensure we don't
  8445. * attempt to use more then the available number of pools.
  8446. */
  8447. if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
  8448. return ERR_PTR(-EBUSY);
  8449. /* Enable VMDq flag so device will be set in VM mode */
  8450. adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED |
  8451. IXGBE_FLAG_SRIOV_ENABLED;
  8452. /* Try to reserve as many queues per pool as possible,
  8453. * we start with the configurations that support 4 queues
  8454. * per pools, followed by 2, and then by just 1 per pool.
  8455. */
  8456. if (used_pools < 32 && adapter->num_rx_pools < 16)
  8457. reserved_pools = min_t(u16,
  8458. 32 - used_pools,
  8459. 16 - adapter->num_rx_pools);
  8460. else if (adapter->num_rx_pools < 32)
  8461. reserved_pools = min_t(u16,
  8462. 64 - used_pools,
  8463. 32 - adapter->num_rx_pools);
  8464. else
  8465. reserved_pools = 64 - used_pools;
  8466. if (!reserved_pools)
  8467. return ERR_PTR(-EBUSY);
  8468. adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools;
  8469. /* Force reinit of ring allocation with VMDQ enabled */
  8470. err = ixgbe_setup_tc(pdev, adapter->hw_tcs);
  8471. if (err)
  8472. return ERR_PTR(err);
  8473. if (pool >= adapter->num_rx_pools)
  8474. return ERR_PTR(-ENOMEM);
  8475. }
  8476. accel = kzalloc(sizeof(*accel), GFP_KERNEL);
  8477. if (!accel)
  8478. return ERR_PTR(-ENOMEM);
  8479. set_bit(pool, adapter->fwd_bitmask);
  8480. netdev_set_sb_channel(vdev, pool);
  8481. accel->pool = pool;
  8482. accel->netdev = vdev;
  8483. if (!netif_running(pdev))
  8484. return accel;
  8485. err = ixgbe_fwd_ring_up(adapter, accel);
  8486. if (err)
  8487. return ERR_PTR(err);
  8488. return accel;
  8489. }
  8490. static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
  8491. {
  8492. struct ixgbe_fwd_adapter *accel = priv;
  8493. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  8494. unsigned int rxbase = accel->rx_base_queue;
  8495. unsigned int i;
  8496. /* delete unicast filter associated with offloaded interface */
  8497. ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr,
  8498. VMDQ_P(accel->pool));
  8499. /* Allow remaining Rx packets to get flushed out of the
  8500. * Rx FIFO before we drop the netdev for the ring.
  8501. */
  8502. usleep_range(10000, 20000);
  8503. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  8504. struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i];
  8505. struct ixgbe_q_vector *qv = ring->q_vector;
  8506. /* Make sure we aren't processing any packets and clear
  8507. * netdev to shut down the ring.
  8508. */
  8509. if (netif_running(adapter->netdev))
  8510. napi_synchronize(&qv->napi);
  8511. ring->netdev = NULL;
  8512. }
  8513. /* unbind the queues and drop the subordinate channel config */
  8514. netdev_unbind_sb_channel(pdev, accel->netdev);
  8515. netdev_set_sb_channel(accel->netdev, 0);
  8516. clear_bit(accel->pool, adapter->fwd_bitmask);
  8517. kfree(accel);
  8518. }
  8519. #define IXGBE_MAX_MAC_HDR_LEN 127
  8520. #define IXGBE_MAX_NETWORK_HDR_LEN 511
  8521. static netdev_features_t
  8522. ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
  8523. netdev_features_t features)
  8524. {
  8525. unsigned int network_hdr_len, mac_hdr_len;
  8526. /* Make certain the headers can be described by a context descriptor */
  8527. mac_hdr_len = skb_network_header(skb) - skb->data;
  8528. if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
  8529. return features & ~(NETIF_F_HW_CSUM |
  8530. NETIF_F_SCTP_CRC |
  8531. NETIF_F_HW_VLAN_CTAG_TX |
  8532. NETIF_F_TSO |
  8533. NETIF_F_TSO6);
  8534. network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
  8535. if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
  8536. return features & ~(NETIF_F_HW_CSUM |
  8537. NETIF_F_SCTP_CRC |
  8538. NETIF_F_TSO |
  8539. NETIF_F_TSO6);
  8540. /* We can only support IPV4 TSO in tunnels if we can mangle the
  8541. * inner IP ID field, so strip TSO if MANGLEID is not supported.
  8542. * IPsec offoad sets skb->encapsulation but still can handle
  8543. * the TSO, so it's the exception.
  8544. */
  8545. if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) {
  8546. #ifdef CONFIG_XFRM_OFFLOAD
  8547. if (!skb->sp)
  8548. #endif
  8549. features &= ~NETIF_F_TSO;
  8550. }
  8551. return features;
  8552. }
  8553. static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
  8554. {
  8555. int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  8556. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8557. struct bpf_prog *old_prog;
  8558. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  8559. return -EINVAL;
  8560. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  8561. return -EINVAL;
  8562. /* verify ixgbe ring attributes are sufficient for XDP */
  8563. for (i = 0; i < adapter->num_rx_queues; i++) {
  8564. struct ixgbe_ring *ring = adapter->rx_ring[i];
  8565. if (ring_is_rsc_enabled(ring))
  8566. return -EINVAL;
  8567. if (frame_size > ixgbe_rx_bufsz(ring))
  8568. return -EINVAL;
  8569. }
  8570. if (nr_cpu_ids > MAX_XDP_QUEUES)
  8571. return -ENOMEM;
  8572. old_prog = xchg(&adapter->xdp_prog, prog);
  8573. /* If transitioning XDP modes reconfigure rings */
  8574. if (!!prog != !!old_prog) {
  8575. int err = ixgbe_setup_tc(dev, adapter->hw_tcs);
  8576. if (err) {
  8577. rcu_assign_pointer(adapter->xdp_prog, old_prog);
  8578. return -EINVAL;
  8579. }
  8580. } else {
  8581. for (i = 0; i < adapter->num_rx_queues; i++)
  8582. (void)xchg(&adapter->rx_ring[i]->xdp_prog,
  8583. adapter->xdp_prog);
  8584. }
  8585. if (old_prog)
  8586. bpf_prog_put(old_prog);
  8587. return 0;
  8588. }
  8589. static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
  8590. {
  8591. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8592. switch (xdp->command) {
  8593. case XDP_SETUP_PROG:
  8594. return ixgbe_xdp_setup(dev, xdp->prog);
  8595. case XDP_QUERY_PROG:
  8596. xdp->prog_id = adapter->xdp_prog ?
  8597. adapter->xdp_prog->aux->id : 0;
  8598. return 0;
  8599. default:
  8600. return -EINVAL;
  8601. }
  8602. }
  8603. static void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring)
  8604. {
  8605. /* Force memory writes to complete before letting h/w know there
  8606. * are new descriptors to fetch.
  8607. */
  8608. wmb();
  8609. writel(ring->next_to_use, ring->tail);
  8610. }
  8611. static int ixgbe_xdp_xmit(struct net_device *dev, int n,
  8612. struct xdp_frame **frames, u32 flags)
  8613. {
  8614. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8615. struct ixgbe_ring *ring;
  8616. int drops = 0;
  8617. int i;
  8618. if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
  8619. return -ENETDOWN;
  8620. if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
  8621. return -EINVAL;
  8622. /* During program transitions its possible adapter->xdp_prog is assigned
  8623. * but ring has not been configured yet. In this case simply abort xmit.
  8624. */
  8625. ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
  8626. if (unlikely(!ring))
  8627. return -ENXIO;
  8628. for (i = 0; i < n; i++) {
  8629. struct xdp_frame *xdpf = frames[i];
  8630. int err;
  8631. err = ixgbe_xmit_xdp_ring(adapter, xdpf);
  8632. if (err != IXGBE_XDP_TX) {
  8633. xdp_return_frame_rx_napi(xdpf);
  8634. drops++;
  8635. }
  8636. }
  8637. if (unlikely(flags & XDP_XMIT_FLUSH))
  8638. ixgbe_xdp_ring_update_tail(ring);
  8639. return n - drops;
  8640. }
  8641. static const struct net_device_ops ixgbe_netdev_ops = {
  8642. .ndo_open = ixgbe_open,
  8643. .ndo_stop = ixgbe_close,
  8644. .ndo_start_xmit = ixgbe_xmit_frame,
  8645. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  8646. .ndo_validate_addr = eth_validate_addr,
  8647. .ndo_set_mac_address = ixgbe_set_mac,
  8648. .ndo_change_mtu = ixgbe_change_mtu,
  8649. .ndo_tx_timeout = ixgbe_tx_timeout,
  8650. .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
  8651. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  8652. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  8653. .ndo_do_ioctl = ixgbe_ioctl,
  8654. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  8655. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  8656. .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
  8657. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  8658. .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
  8659. .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
  8660. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  8661. .ndo_get_stats64 = ixgbe_get_stats64,
  8662. .ndo_setup_tc = __ixgbe_setup_tc,
  8663. #ifdef CONFIG_NET_POLL_CONTROLLER
  8664. .ndo_poll_controller = ixgbe_netpoll,
  8665. #endif
  8666. #ifdef IXGBE_FCOE
  8667. .ndo_select_queue = ixgbe_select_queue,
  8668. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  8669. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  8670. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  8671. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  8672. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  8673. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  8674. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  8675. #endif /* IXGBE_FCOE */
  8676. .ndo_set_features = ixgbe_set_features,
  8677. .ndo_fix_features = ixgbe_fix_features,
  8678. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  8679. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  8680. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  8681. .ndo_dfwd_add_station = ixgbe_fwd_add,
  8682. .ndo_dfwd_del_station = ixgbe_fwd_del,
  8683. .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
  8684. .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
  8685. .ndo_features_check = ixgbe_features_check,
  8686. .ndo_bpf = ixgbe_xdp,
  8687. .ndo_xdp_xmit = ixgbe_xdp_xmit,
  8688. };
  8689. /**
  8690. * ixgbe_enumerate_functions - Get the number of ports this device has
  8691. * @adapter: adapter structure
  8692. *
  8693. * This function enumerates the phsyical functions co-located on a single slot,
  8694. * in order to determine how many ports a device has. This is most useful in
  8695. * determining the required GT/s of PCIe bandwidth necessary for optimal
  8696. * performance.
  8697. **/
  8698. static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
  8699. {
  8700. struct pci_dev *entry, *pdev = adapter->pdev;
  8701. int physfns = 0;
  8702. /* Some cards can not use the generic count PCIe functions method,
  8703. * because they are behind a parent switch, so we hardcode these with
  8704. * the correct number of functions.
  8705. */
  8706. if (ixgbe_pcie_from_parent(&adapter->hw))
  8707. physfns = 4;
  8708. list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
  8709. /* don't count virtual functions */
  8710. if (entry->is_virtfn)
  8711. continue;
  8712. /* When the devices on the bus don't all match our device ID,
  8713. * we can't reliably determine the correct number of
  8714. * functions. This can occur if a function has been direct
  8715. * attached to a virtual machine using VT-d, for example. In
  8716. * this case, simply return -1 to indicate this.
  8717. */
  8718. if ((entry->vendor != pdev->vendor) ||
  8719. (entry->device != pdev->device))
  8720. return -1;
  8721. physfns++;
  8722. }
  8723. return physfns;
  8724. }
  8725. /**
  8726. * ixgbe_wol_supported - Check whether device supports WoL
  8727. * @adapter: the adapter private structure
  8728. * @device_id: the device ID
  8729. * @subdevice_id: the subsystem device ID
  8730. *
  8731. * This function is used by probe and ethtool to determine
  8732. * which devices have WoL support
  8733. *
  8734. **/
  8735. bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  8736. u16 subdevice_id)
  8737. {
  8738. struct ixgbe_hw *hw = &adapter->hw;
  8739. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  8740. /* WOL not supported on 82598 */
  8741. if (hw->mac.type == ixgbe_mac_82598EB)
  8742. return false;
  8743. /* check eeprom to see if WOL is enabled for X540 and newer */
  8744. if (hw->mac.type >= ixgbe_mac_X540) {
  8745. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  8746. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  8747. (hw->bus.func == 0)))
  8748. return true;
  8749. }
  8750. /* WOL is determined based on device IDs for 82599 MACs */
  8751. switch (device_id) {
  8752. case IXGBE_DEV_ID_82599_SFP:
  8753. /* Only these subdevices could supports WOL */
  8754. switch (subdevice_id) {
  8755. case IXGBE_SUBDEV_ID_82599_560FLR:
  8756. case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
  8757. case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
  8758. case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
  8759. /* only support first port */
  8760. if (hw->bus.func != 0)
  8761. break;
  8762. /* fall through */
  8763. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  8764. case IXGBE_SUBDEV_ID_82599_SFP:
  8765. case IXGBE_SUBDEV_ID_82599_RNDC:
  8766. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  8767. case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
  8768. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
  8769. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
  8770. return true;
  8771. }
  8772. break;
  8773. case IXGBE_DEV_ID_82599EN_SFP:
  8774. /* Only these subdevices support WOL */
  8775. switch (subdevice_id) {
  8776. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  8777. return true;
  8778. }
  8779. break;
  8780. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  8781. /* All except this subdevice support WOL */
  8782. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  8783. return true;
  8784. break;
  8785. case IXGBE_DEV_ID_82599_KX4:
  8786. return true;
  8787. default:
  8788. break;
  8789. }
  8790. return false;
  8791. }
  8792. /**
  8793. * ixgbe_set_fw_version - Set FW version
  8794. * @adapter: the adapter private structure
  8795. *
  8796. * This function is used by probe and ethtool to determine the FW version to
  8797. * format to display. The FW version is taken from the EEPROM/NVM.
  8798. */
  8799. static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
  8800. {
  8801. struct ixgbe_hw *hw = &adapter->hw;
  8802. struct ixgbe_nvm_version nvm_ver;
  8803. ixgbe_get_oem_prod_version(hw, &nvm_ver);
  8804. if (nvm_ver.oem_valid) {
  8805. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  8806. "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
  8807. nvm_ver.oem_release);
  8808. return;
  8809. }
  8810. ixgbe_get_etk_id(hw, &nvm_ver);
  8811. ixgbe_get_orom_version(hw, &nvm_ver);
  8812. if (nvm_ver.or_valid) {
  8813. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  8814. "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
  8815. nvm_ver.or_build, nvm_ver.or_patch);
  8816. return;
  8817. }
  8818. /* Set ETrack ID format */
  8819. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  8820. "0x%08x", nvm_ver.etk_id);
  8821. }
  8822. /**
  8823. * ixgbe_probe - Device Initialization Routine
  8824. * @pdev: PCI device information struct
  8825. * @ent: entry in ixgbe_pci_tbl
  8826. *
  8827. * Returns 0 on success, negative on failure
  8828. *
  8829. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  8830. * The OS initialization, configuring of the adapter private structure,
  8831. * and a hardware reset occur.
  8832. **/
  8833. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  8834. {
  8835. struct net_device *netdev;
  8836. struct ixgbe_adapter *adapter = NULL;
  8837. struct ixgbe_hw *hw;
  8838. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  8839. int i, err, pci_using_dac, expected_gts;
  8840. unsigned int indices = MAX_TX_QUEUES;
  8841. u8 part_str[IXGBE_PBANUM_LENGTH];
  8842. bool disable_dev = false;
  8843. #ifdef IXGBE_FCOE
  8844. u16 device_caps;
  8845. #endif
  8846. u32 eec;
  8847. /* Catch broken hardware that put the wrong VF device ID in
  8848. * the PCIe SR-IOV capability.
  8849. */
  8850. if (pdev->is_virtfn) {
  8851. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  8852. pci_name(pdev), pdev->vendor, pdev->device);
  8853. return -EINVAL;
  8854. }
  8855. err = pci_enable_device_mem(pdev);
  8856. if (err)
  8857. return err;
  8858. if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
  8859. pci_using_dac = 1;
  8860. } else {
  8861. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8862. if (err) {
  8863. dev_err(&pdev->dev,
  8864. "No usable DMA configuration, aborting\n");
  8865. goto err_dma;
  8866. }
  8867. pci_using_dac = 0;
  8868. }
  8869. err = pci_request_mem_regions(pdev, ixgbe_driver_name);
  8870. if (err) {
  8871. dev_err(&pdev->dev,
  8872. "pci_request_selected_regions failed 0x%x\n", err);
  8873. goto err_pci_reg;
  8874. }
  8875. pci_enable_pcie_error_reporting(pdev);
  8876. pci_set_master(pdev);
  8877. pci_save_state(pdev);
  8878. if (ii->mac == ixgbe_mac_82598EB) {
  8879. #ifdef CONFIG_IXGBE_DCB
  8880. /* 8 TC w/ 4 queues per TC */
  8881. indices = 4 * MAX_TRAFFIC_CLASS;
  8882. #else
  8883. indices = IXGBE_MAX_RSS_INDICES;
  8884. #endif
  8885. }
  8886. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  8887. if (!netdev) {
  8888. err = -ENOMEM;
  8889. goto err_alloc_etherdev;
  8890. }
  8891. SET_NETDEV_DEV(netdev, &pdev->dev);
  8892. adapter = netdev_priv(netdev);
  8893. adapter->netdev = netdev;
  8894. adapter->pdev = pdev;
  8895. hw = &adapter->hw;
  8896. hw->back = adapter;
  8897. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  8898. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  8899. pci_resource_len(pdev, 0));
  8900. adapter->io_addr = hw->hw_addr;
  8901. if (!hw->hw_addr) {
  8902. err = -EIO;
  8903. goto err_ioremap;
  8904. }
  8905. netdev->netdev_ops = &ixgbe_netdev_ops;
  8906. ixgbe_set_ethtool_ops(netdev);
  8907. netdev->watchdog_timeo = 5 * HZ;
  8908. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  8909. /* Setup hw api */
  8910. hw->mac.ops = *ii->mac_ops;
  8911. hw->mac.type = ii->mac;
  8912. hw->mvals = ii->mvals;
  8913. if (ii->link_ops)
  8914. hw->link.ops = *ii->link_ops;
  8915. /* EEPROM */
  8916. hw->eeprom.ops = *ii->eeprom_ops;
  8917. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  8918. if (ixgbe_removed(hw->hw_addr)) {
  8919. err = -EIO;
  8920. goto err_ioremap;
  8921. }
  8922. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  8923. if (!(eec & BIT(8)))
  8924. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  8925. /* PHY */
  8926. hw->phy.ops = *ii->phy_ops;
  8927. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  8928. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  8929. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  8930. hw->phy.mdio.mmds = 0;
  8931. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8932. hw->phy.mdio.dev = netdev;
  8933. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  8934. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  8935. /* setup the private structure */
  8936. err = ixgbe_sw_init(adapter, ii);
  8937. if (err)
  8938. goto err_sw_init;
  8939. /* Make sure the SWFW semaphore is in a valid state */
  8940. if (hw->mac.ops.init_swfw_sync)
  8941. hw->mac.ops.init_swfw_sync(hw);
  8942. /* Make it possible the adapter to be woken up via WOL */
  8943. switch (adapter->hw.mac.type) {
  8944. case ixgbe_mac_82599EB:
  8945. case ixgbe_mac_X540:
  8946. case ixgbe_mac_X550:
  8947. case ixgbe_mac_X550EM_x:
  8948. case ixgbe_mac_x550em_a:
  8949. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  8950. break;
  8951. default:
  8952. break;
  8953. }
  8954. /*
  8955. * If there is a fan on this device and it has failed log the
  8956. * failure.
  8957. */
  8958. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  8959. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  8960. if (esdp & IXGBE_ESDP_SDP1)
  8961. e_crit(probe, "Fan has stopped, replace the adapter\n");
  8962. }
  8963. if (allow_unsupported_sfp)
  8964. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  8965. /* reset_hw fills in the perm_addr as well */
  8966. hw->phy.reset_if_overtemp = true;
  8967. err = hw->mac.ops.reset_hw(hw);
  8968. hw->phy.reset_if_overtemp = false;
  8969. ixgbe_set_eee_capable(adapter);
  8970. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  8971. err = 0;
  8972. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  8973. e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
  8974. e_dev_err("Reload the driver after installing a supported module.\n");
  8975. goto err_sw_init;
  8976. } else if (err) {
  8977. e_dev_err("HW Init failed: %d\n", err);
  8978. goto err_sw_init;
  8979. }
  8980. #ifdef CONFIG_PCI_IOV
  8981. /* SR-IOV not supported on the 82598 */
  8982. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  8983. goto skip_sriov;
  8984. /* Mailbox */
  8985. ixgbe_init_mbx_params_pf(hw);
  8986. hw->mbx.ops = ii->mbx_ops;
  8987. pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
  8988. ixgbe_enable_sriov(adapter, max_vfs);
  8989. skip_sriov:
  8990. #endif
  8991. netdev->features = NETIF_F_SG |
  8992. NETIF_F_TSO |
  8993. NETIF_F_TSO6 |
  8994. NETIF_F_RXHASH |
  8995. NETIF_F_RXCSUM |
  8996. NETIF_F_HW_CSUM;
  8997. #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
  8998. NETIF_F_GSO_GRE_CSUM | \
  8999. NETIF_F_GSO_IPXIP4 | \
  9000. NETIF_F_GSO_IPXIP6 | \
  9001. NETIF_F_GSO_UDP_TUNNEL | \
  9002. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  9003. netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
  9004. netdev->features |= NETIF_F_GSO_PARTIAL |
  9005. IXGBE_GSO_PARTIAL_FEATURES;
  9006. if (hw->mac.type >= ixgbe_mac_82599EB)
  9007. netdev->features |= NETIF_F_SCTP_CRC;
  9008. #ifdef CONFIG_XFRM_OFFLOAD
  9009. #define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
  9010. NETIF_F_HW_ESP_TX_CSUM | \
  9011. NETIF_F_GSO_ESP)
  9012. if (adapter->ipsec)
  9013. netdev->features |= IXGBE_ESP_FEATURES;
  9014. #endif
  9015. /* copy netdev features into list of user selectable features */
  9016. netdev->hw_features |= netdev->features |
  9017. NETIF_F_HW_VLAN_CTAG_FILTER |
  9018. NETIF_F_HW_VLAN_CTAG_RX |
  9019. NETIF_F_HW_VLAN_CTAG_TX |
  9020. NETIF_F_RXALL |
  9021. NETIF_F_HW_L2FW_DOFFLOAD;
  9022. if (hw->mac.type >= ixgbe_mac_82599EB)
  9023. netdev->hw_features |= NETIF_F_NTUPLE |
  9024. NETIF_F_HW_TC;
  9025. if (pci_using_dac)
  9026. netdev->features |= NETIF_F_HIGHDMA;
  9027. netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
  9028. netdev->hw_enc_features |= netdev->vlan_features;
  9029. netdev->mpls_features |= NETIF_F_SG |
  9030. NETIF_F_TSO |
  9031. NETIF_F_TSO6 |
  9032. NETIF_F_HW_CSUM;
  9033. netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
  9034. /* set this bit last since it cannot be part of vlan_features */
  9035. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
  9036. NETIF_F_HW_VLAN_CTAG_RX |
  9037. NETIF_F_HW_VLAN_CTAG_TX;
  9038. netdev->priv_flags |= IFF_UNICAST_FLT;
  9039. netdev->priv_flags |= IFF_SUPP_NOFCS;
  9040. /* MTU range: 68 - 9710 */
  9041. netdev->min_mtu = ETH_MIN_MTU;
  9042. netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
  9043. #ifdef CONFIG_IXGBE_DCB
  9044. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  9045. netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
  9046. #endif
  9047. #ifdef IXGBE_FCOE
  9048. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  9049. unsigned int fcoe_l;
  9050. if (hw->mac.ops.get_device_caps) {
  9051. hw->mac.ops.get_device_caps(hw, &device_caps);
  9052. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  9053. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  9054. }
  9055. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  9056. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  9057. netdev->features |= NETIF_F_FSO |
  9058. NETIF_F_FCOE_CRC;
  9059. netdev->vlan_features |= NETIF_F_FSO |
  9060. NETIF_F_FCOE_CRC |
  9061. NETIF_F_FCOE_MTU;
  9062. }
  9063. #endif /* IXGBE_FCOE */
  9064. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  9065. netdev->hw_features |= NETIF_F_LRO;
  9066. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  9067. netdev->features |= NETIF_F_LRO;
  9068. /* make sure the EEPROM is good */
  9069. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  9070. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  9071. err = -EIO;
  9072. goto err_sw_init;
  9073. }
  9074. eth_platform_get_mac_address(&adapter->pdev->dev,
  9075. adapter->hw.mac.perm_addr);
  9076. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  9077. if (!is_valid_ether_addr(netdev->dev_addr)) {
  9078. e_dev_err("invalid MAC address\n");
  9079. err = -EIO;
  9080. goto err_sw_init;
  9081. }
  9082. /* Set hw->mac.addr to permanent MAC address */
  9083. ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
  9084. ixgbe_mac_set_default_filter(adapter);
  9085. timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
  9086. if (ixgbe_removed(hw->hw_addr)) {
  9087. err = -EIO;
  9088. goto err_sw_init;
  9089. }
  9090. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  9091. set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
  9092. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  9093. err = ixgbe_init_interrupt_scheme(adapter);
  9094. if (err)
  9095. goto err_sw_init;
  9096. for (i = 0; i < adapter->num_rx_queues; i++)
  9097. u64_stats_init(&adapter->rx_ring[i]->syncp);
  9098. for (i = 0; i < adapter->num_tx_queues; i++)
  9099. u64_stats_init(&adapter->tx_ring[i]->syncp);
  9100. for (i = 0; i < adapter->num_xdp_queues; i++)
  9101. u64_stats_init(&adapter->xdp_ring[i]->syncp);
  9102. /* WOL not supported for all devices */
  9103. adapter->wol = 0;
  9104. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  9105. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  9106. pdev->subsystem_device);
  9107. if (hw->wol_enabled)
  9108. adapter->wol = IXGBE_WUFC_MAG;
  9109. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  9110. /* save off EEPROM version number */
  9111. ixgbe_set_fw_version(adapter);
  9112. /* pick up the PCI bus settings for reporting later */
  9113. if (ixgbe_pcie_from_parent(hw))
  9114. ixgbe_get_parent_bus_info(adapter);
  9115. else
  9116. hw->mac.ops.get_bus_info(hw);
  9117. /* calculate the expected PCIe bandwidth required for optimal
  9118. * performance. Note that some older parts will never have enough
  9119. * bandwidth due to being older generation PCIe parts. We clamp these
  9120. * parts to ensure no warning is displayed if it can't be fixed.
  9121. */
  9122. switch (hw->mac.type) {
  9123. case ixgbe_mac_82598EB:
  9124. expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
  9125. break;
  9126. default:
  9127. expected_gts = ixgbe_enumerate_functions(adapter) * 10;
  9128. break;
  9129. }
  9130. /* don't check link if we failed to enumerate functions */
  9131. if (expected_gts > 0)
  9132. ixgbe_check_minimum_link(adapter, expected_gts);
  9133. err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
  9134. if (err)
  9135. strlcpy(part_str, "Unknown", sizeof(part_str));
  9136. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  9137. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  9138. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  9139. part_str);
  9140. else
  9141. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  9142. hw->mac.type, hw->phy.type, part_str);
  9143. e_dev_info("%pM\n", netdev->dev_addr);
  9144. /* reset the hardware with the new settings */
  9145. err = hw->mac.ops.start_hw(hw);
  9146. if (err == IXGBE_ERR_EEPROM_VERSION) {
  9147. /* We are running on a pre-production device, log a warning */
  9148. e_dev_warn("This device is a pre-production adapter/LOM. "
  9149. "Please be aware there may be issues associated "
  9150. "with your hardware. If you are experiencing "
  9151. "problems please contact your Intel or hardware "
  9152. "representative who provided you with this "
  9153. "hardware.\n");
  9154. }
  9155. strcpy(netdev->name, "eth%d");
  9156. pci_set_drvdata(pdev, adapter);
  9157. err = register_netdev(netdev);
  9158. if (err)
  9159. goto err_register;
  9160. /* power down the optics for 82599 SFP+ fiber */
  9161. if (hw->mac.ops.disable_tx_laser)
  9162. hw->mac.ops.disable_tx_laser(hw);
  9163. /* carrier off reporting is important to ethtool even BEFORE open */
  9164. netif_carrier_off(netdev);
  9165. #ifdef CONFIG_IXGBE_DCA
  9166. if (dca_add_requester(&pdev->dev) == 0) {
  9167. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  9168. ixgbe_setup_dca(adapter);
  9169. }
  9170. #endif
  9171. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  9172. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  9173. for (i = 0; i < adapter->num_vfs; i++)
  9174. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  9175. }
  9176. /* firmware requires driver version to be 0xFFFFFFFF
  9177. * since os does not support feature
  9178. */
  9179. if (hw->mac.ops.set_fw_drv_ver)
  9180. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
  9181. sizeof(ixgbe_driver_version) - 1,
  9182. ixgbe_driver_version);
  9183. /* add san mac addr to netdev */
  9184. ixgbe_add_sanmac_netdev(netdev);
  9185. e_dev_info("%s\n", ixgbe_default_device_descr);
  9186. #ifdef CONFIG_IXGBE_HWMON
  9187. if (ixgbe_sysfs_init(adapter))
  9188. e_err(probe, "failed to allocate sysfs resources\n");
  9189. #endif /* CONFIG_IXGBE_HWMON */
  9190. ixgbe_dbg_adapter_init(adapter);
  9191. /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
  9192. if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
  9193. hw->mac.ops.setup_link(hw,
  9194. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  9195. true);
  9196. return 0;
  9197. err_register:
  9198. ixgbe_release_hw_control(adapter);
  9199. ixgbe_clear_interrupt_scheme(adapter);
  9200. err_sw_init:
  9201. ixgbe_disable_sriov(adapter);
  9202. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  9203. iounmap(adapter->io_addr);
  9204. kfree(adapter->jump_tables[0]);
  9205. kfree(adapter->mac_table);
  9206. kfree(adapter->rss_key);
  9207. err_ioremap:
  9208. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  9209. free_netdev(netdev);
  9210. err_alloc_etherdev:
  9211. pci_release_mem_regions(pdev);
  9212. err_pci_reg:
  9213. err_dma:
  9214. if (!adapter || disable_dev)
  9215. pci_disable_device(pdev);
  9216. return err;
  9217. }
  9218. /**
  9219. * ixgbe_remove - Device Removal Routine
  9220. * @pdev: PCI device information struct
  9221. *
  9222. * ixgbe_remove is called by the PCI subsystem to alert the driver
  9223. * that it should release a PCI device. The could be caused by a
  9224. * Hot-Plug event, or because the driver is going to be removed from
  9225. * memory.
  9226. **/
  9227. static void ixgbe_remove(struct pci_dev *pdev)
  9228. {
  9229. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9230. struct net_device *netdev;
  9231. bool disable_dev;
  9232. int i;
  9233. /* if !adapter then we already cleaned up in probe */
  9234. if (!adapter)
  9235. return;
  9236. netdev = adapter->netdev;
  9237. ixgbe_dbg_adapter_exit(adapter);
  9238. set_bit(__IXGBE_REMOVING, &adapter->state);
  9239. cancel_work_sync(&adapter->service_task);
  9240. #ifdef CONFIG_IXGBE_DCA
  9241. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  9242. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  9243. dca_remove_requester(&pdev->dev);
  9244. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  9245. IXGBE_DCA_CTRL_DCA_DISABLE);
  9246. }
  9247. #endif
  9248. #ifdef CONFIG_IXGBE_HWMON
  9249. ixgbe_sysfs_exit(adapter);
  9250. #endif /* CONFIG_IXGBE_HWMON */
  9251. /* remove the added san mac */
  9252. ixgbe_del_sanmac_netdev(netdev);
  9253. #ifdef CONFIG_PCI_IOV
  9254. ixgbe_disable_sriov(adapter);
  9255. #endif
  9256. if (netdev->reg_state == NETREG_REGISTERED)
  9257. unregister_netdev(netdev);
  9258. ixgbe_stop_ipsec_offload(adapter);
  9259. ixgbe_clear_interrupt_scheme(adapter);
  9260. ixgbe_release_hw_control(adapter);
  9261. #ifdef CONFIG_DCB
  9262. kfree(adapter->ixgbe_ieee_pfc);
  9263. kfree(adapter->ixgbe_ieee_ets);
  9264. #endif
  9265. iounmap(adapter->io_addr);
  9266. pci_release_mem_regions(pdev);
  9267. e_dev_info("complete\n");
  9268. for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
  9269. if (adapter->jump_tables[i]) {
  9270. kfree(adapter->jump_tables[i]->input);
  9271. kfree(adapter->jump_tables[i]->mask);
  9272. }
  9273. kfree(adapter->jump_tables[i]);
  9274. }
  9275. kfree(adapter->mac_table);
  9276. kfree(adapter->rss_key);
  9277. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  9278. free_netdev(netdev);
  9279. pci_disable_pcie_error_reporting(pdev);
  9280. if (disable_dev)
  9281. pci_disable_device(pdev);
  9282. }
  9283. /**
  9284. * ixgbe_io_error_detected - called when PCI error is detected
  9285. * @pdev: Pointer to PCI device
  9286. * @state: The current pci connection state
  9287. *
  9288. * This function is called after a PCI bus error affecting
  9289. * this device has been detected.
  9290. */
  9291. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  9292. pci_channel_state_t state)
  9293. {
  9294. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9295. struct net_device *netdev = adapter->netdev;
  9296. #ifdef CONFIG_PCI_IOV
  9297. struct ixgbe_hw *hw = &adapter->hw;
  9298. struct pci_dev *bdev, *vfdev;
  9299. u32 dw0, dw1, dw2, dw3;
  9300. int vf, pos;
  9301. u16 req_id, pf_func;
  9302. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  9303. adapter->num_vfs == 0)
  9304. goto skip_bad_vf_detection;
  9305. bdev = pdev->bus->self;
  9306. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  9307. bdev = bdev->bus->self;
  9308. if (!bdev)
  9309. goto skip_bad_vf_detection;
  9310. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  9311. if (!pos)
  9312. goto skip_bad_vf_detection;
  9313. dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
  9314. dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
  9315. dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
  9316. dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
  9317. if (ixgbe_removed(hw->hw_addr))
  9318. goto skip_bad_vf_detection;
  9319. req_id = dw1 >> 16;
  9320. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  9321. if (!(req_id & 0x0080))
  9322. goto skip_bad_vf_detection;
  9323. pf_func = req_id & 0x01;
  9324. if ((pf_func & 1) == (pdev->devfn & 1)) {
  9325. unsigned int device_id;
  9326. vf = (req_id & 0x7F) >> 1;
  9327. e_dev_err("VF %d has caused a PCIe error\n", vf);
  9328. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  9329. "%8.8x\tdw3: %8.8x\n",
  9330. dw0, dw1, dw2, dw3);
  9331. switch (adapter->hw.mac.type) {
  9332. case ixgbe_mac_82599EB:
  9333. device_id = IXGBE_82599_VF_DEVICE_ID;
  9334. break;
  9335. case ixgbe_mac_X540:
  9336. device_id = IXGBE_X540_VF_DEVICE_ID;
  9337. break;
  9338. case ixgbe_mac_X550:
  9339. device_id = IXGBE_DEV_ID_X550_VF;
  9340. break;
  9341. case ixgbe_mac_X550EM_x:
  9342. device_id = IXGBE_DEV_ID_X550EM_X_VF;
  9343. break;
  9344. case ixgbe_mac_x550em_a:
  9345. device_id = IXGBE_DEV_ID_X550EM_A_VF;
  9346. break;
  9347. default:
  9348. device_id = 0;
  9349. break;
  9350. }
  9351. /* Find the pci device of the offending VF */
  9352. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  9353. while (vfdev) {
  9354. if (vfdev->devfn == (req_id & 0xFF))
  9355. break;
  9356. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  9357. device_id, vfdev);
  9358. }
  9359. /*
  9360. * There's a slim chance the VF could have been hot plugged,
  9361. * so if it is no longer present we don't need to issue the
  9362. * VFLR. Just clean up the AER in that case.
  9363. */
  9364. if (vfdev) {
  9365. pcie_flr(vfdev);
  9366. /* Free device reference count */
  9367. pci_dev_put(vfdev);
  9368. }
  9369. pci_cleanup_aer_uncorrect_error_status(pdev);
  9370. }
  9371. /*
  9372. * Even though the error may have occurred on the other port
  9373. * we still need to increment the vf error reference count for
  9374. * both ports because the I/O resume function will be called
  9375. * for both of them.
  9376. */
  9377. adapter->vferr_refcount++;
  9378. return PCI_ERS_RESULT_RECOVERED;
  9379. skip_bad_vf_detection:
  9380. #endif /* CONFIG_PCI_IOV */
  9381. if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  9382. return PCI_ERS_RESULT_DISCONNECT;
  9383. if (!netif_device_present(netdev))
  9384. return PCI_ERS_RESULT_DISCONNECT;
  9385. rtnl_lock();
  9386. netif_device_detach(netdev);
  9387. if (netif_running(netdev))
  9388. ixgbe_close_suspend(adapter);
  9389. if (state == pci_channel_io_perm_failure) {
  9390. rtnl_unlock();
  9391. return PCI_ERS_RESULT_DISCONNECT;
  9392. }
  9393. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  9394. pci_disable_device(pdev);
  9395. rtnl_unlock();
  9396. /* Request a slot reset. */
  9397. return PCI_ERS_RESULT_NEED_RESET;
  9398. }
  9399. /**
  9400. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  9401. * @pdev: Pointer to PCI device
  9402. *
  9403. * Restart the card from scratch, as if from a cold-boot.
  9404. */
  9405. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  9406. {
  9407. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9408. pci_ers_result_t result;
  9409. int err;
  9410. if (pci_enable_device_mem(pdev)) {
  9411. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  9412. result = PCI_ERS_RESULT_DISCONNECT;
  9413. } else {
  9414. smp_mb__before_atomic();
  9415. clear_bit(__IXGBE_DISABLED, &adapter->state);
  9416. adapter->hw.hw_addr = adapter->io_addr;
  9417. pci_set_master(pdev);
  9418. pci_restore_state(pdev);
  9419. pci_save_state(pdev);
  9420. pci_wake_from_d3(pdev, false);
  9421. ixgbe_reset(adapter);
  9422. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  9423. result = PCI_ERS_RESULT_RECOVERED;
  9424. }
  9425. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  9426. if (err) {
  9427. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  9428. "failed 0x%0x\n", err);
  9429. /* non-fatal, continue */
  9430. }
  9431. return result;
  9432. }
  9433. /**
  9434. * ixgbe_io_resume - called when traffic can start flowing again.
  9435. * @pdev: Pointer to PCI device
  9436. *
  9437. * This callback is called when the error recovery driver tells us that
  9438. * its OK to resume normal operation.
  9439. */
  9440. static void ixgbe_io_resume(struct pci_dev *pdev)
  9441. {
  9442. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9443. struct net_device *netdev = adapter->netdev;
  9444. #ifdef CONFIG_PCI_IOV
  9445. if (adapter->vferr_refcount) {
  9446. e_info(drv, "Resuming after VF err\n");
  9447. adapter->vferr_refcount--;
  9448. return;
  9449. }
  9450. #endif
  9451. rtnl_lock();
  9452. if (netif_running(netdev))
  9453. ixgbe_open(netdev);
  9454. netif_device_attach(netdev);
  9455. rtnl_unlock();
  9456. }
  9457. static const struct pci_error_handlers ixgbe_err_handler = {
  9458. .error_detected = ixgbe_io_error_detected,
  9459. .slot_reset = ixgbe_io_slot_reset,
  9460. .resume = ixgbe_io_resume,
  9461. };
  9462. static struct pci_driver ixgbe_driver = {
  9463. .name = ixgbe_driver_name,
  9464. .id_table = ixgbe_pci_tbl,
  9465. .probe = ixgbe_probe,
  9466. .remove = ixgbe_remove,
  9467. #ifdef CONFIG_PM
  9468. .suspend = ixgbe_suspend,
  9469. .resume = ixgbe_resume,
  9470. #endif
  9471. .shutdown = ixgbe_shutdown,
  9472. .sriov_configure = ixgbe_pci_sriov_configure,
  9473. .err_handler = &ixgbe_err_handler
  9474. };
  9475. /**
  9476. * ixgbe_init_module - Driver Registration Routine
  9477. *
  9478. * ixgbe_init_module is the first routine called when the driver is
  9479. * loaded. All it does is register with the PCI subsystem.
  9480. **/
  9481. static int __init ixgbe_init_module(void)
  9482. {
  9483. int ret;
  9484. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  9485. pr_info("%s\n", ixgbe_copyright);
  9486. ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
  9487. if (!ixgbe_wq) {
  9488. pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
  9489. return -ENOMEM;
  9490. }
  9491. ixgbe_dbg_init();
  9492. ret = pci_register_driver(&ixgbe_driver);
  9493. if (ret) {
  9494. destroy_workqueue(ixgbe_wq);
  9495. ixgbe_dbg_exit();
  9496. return ret;
  9497. }
  9498. #ifdef CONFIG_IXGBE_DCA
  9499. dca_register_notify(&dca_notifier);
  9500. #endif
  9501. return 0;
  9502. }
  9503. module_init(ixgbe_init_module);
  9504. /**
  9505. * ixgbe_exit_module - Driver Exit Cleanup Routine
  9506. *
  9507. * ixgbe_exit_module is called just before the driver is removed
  9508. * from memory.
  9509. **/
  9510. static void __exit ixgbe_exit_module(void)
  9511. {
  9512. #ifdef CONFIG_IXGBE_DCA
  9513. dca_unregister_notify(&dca_notifier);
  9514. #endif
  9515. pci_unregister_driver(&ixgbe_driver);
  9516. ixgbe_dbg_exit();
  9517. if (ixgbe_wq) {
  9518. destroy_workqueue(ixgbe_wq);
  9519. ixgbe_wq = NULL;
  9520. }
  9521. }
  9522. #ifdef CONFIG_IXGBE_DCA
  9523. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  9524. void *p)
  9525. {
  9526. int ret_val;
  9527. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  9528. __ixgbe_notify_dca);
  9529. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  9530. }
  9531. #endif /* CONFIG_IXGBE_DCA */
  9532. module_exit(ixgbe_exit_module);
  9533. /* ixgbe_main.c */