ixgbe_main.c 306 KB

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