ixgbe_main.c 254 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2015 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/types.h>
  22. #include <linux/module.h>
  23. #include <linux/pci.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/string.h>
  27. #include <linux/in.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/ip.h>
  30. #include <linux/tcp.h>
  31. #include <linux/sctp.h>
  32. #include <linux/pkt_sched.h>
  33. #include <linux/ipv6.h>
  34. #include <linux/slab.h>
  35. #include <net/checksum.h>
  36. #include <net/ip6_checksum.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/if.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/if_macvlan.h>
  42. #include <linux/if_bridge.h>
  43. #include <linux/prefetch.h>
  44. #include <scsi/fc/fc_fcoe.h>
  45. #include <net/vxlan.h>
  46. #ifdef CONFIG_OF
  47. #include <linux/of_net.h>
  48. #endif
  49. #ifdef CONFIG_SPARC
  50. #include <asm/idprom.h>
  51. #include <asm/prom.h>
  52. #endif
  53. #include "ixgbe.h"
  54. #include "ixgbe_common.h"
  55. #include "ixgbe_dcb_82599.h"
  56. #include "ixgbe_sriov.h"
  57. #ifdef CONFIG_IXGBE_VXLAN
  58. #include <net/vxlan.h>
  59. #endif
  60. char ixgbe_driver_name[] = "ixgbe";
  61. static const char ixgbe_driver_string[] =
  62. "Intel(R) 10 Gigabit PCI Express Network Driver";
  63. #ifdef IXGBE_FCOE
  64. char ixgbe_default_device_descr[] =
  65. "Intel(R) 10 Gigabit Network Connection";
  66. #else
  67. static char ixgbe_default_device_descr[] =
  68. "Intel(R) 10 Gigabit Network Connection";
  69. #endif
  70. #define DRV_VERSION "4.0.1-k"
  71. const char ixgbe_driver_version[] = DRV_VERSION;
  72. static const char ixgbe_copyright[] =
  73. "Copyright (c) 1999-2015 Intel Corporation.";
  74. 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";
  75. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  76. [board_82598] = &ixgbe_82598_info,
  77. [board_82599] = &ixgbe_82599_info,
  78. [board_X540] = &ixgbe_X540_info,
  79. [board_X550] = &ixgbe_X550_info,
  80. [board_X550EM_x] = &ixgbe_X550EM_x_info,
  81. };
  82. /* ixgbe_pci_tbl - PCI Device ID Table
  83. *
  84. * Wildcard entries (PCI_ANY_ID) should come last
  85. * Last entry must be all 0s
  86. *
  87. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  88. * Class, Class Mask, private data (not used) }
  89. */
  90. static const struct pci_device_id ixgbe_pci_tbl[] = {
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  103. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  104. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  105. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  106. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  107. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  108. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  109. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  110. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  111. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  112. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  113. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  114. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  115. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  116. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  117. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
  118. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  119. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  120. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  121. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
  122. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
  123. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
  124. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
  125. /* required last entry */
  126. {0, }
  127. };
  128. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  129. #ifdef CONFIG_IXGBE_DCA
  130. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  131. void *p);
  132. static struct notifier_block dca_notifier = {
  133. .notifier_call = ixgbe_notify_dca,
  134. .next = NULL,
  135. .priority = 0
  136. };
  137. #endif
  138. #ifdef CONFIG_PCI_IOV
  139. static unsigned int max_vfs;
  140. module_param(max_vfs, uint, 0);
  141. MODULE_PARM_DESC(max_vfs,
  142. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
  143. #endif /* CONFIG_PCI_IOV */
  144. static unsigned int allow_unsupported_sfp;
  145. module_param(allow_unsupported_sfp, uint, 0);
  146. MODULE_PARM_DESC(allow_unsupported_sfp,
  147. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  148. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  149. static int debug = -1;
  150. module_param(debug, int, 0);
  151. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  152. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  153. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  154. MODULE_LICENSE("GPL");
  155. MODULE_VERSION(DRV_VERSION);
  156. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
  157. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  158. u32 reg, u16 *value)
  159. {
  160. struct pci_dev *parent_dev;
  161. struct pci_bus *parent_bus;
  162. parent_bus = adapter->pdev->bus->parent;
  163. if (!parent_bus)
  164. return -1;
  165. parent_dev = parent_bus->self;
  166. if (!parent_dev)
  167. return -1;
  168. if (!pci_is_pcie(parent_dev))
  169. return -1;
  170. pcie_capability_read_word(parent_dev, reg, value);
  171. if (*value == IXGBE_FAILED_READ_CFG_WORD &&
  172. ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
  173. return -1;
  174. return 0;
  175. }
  176. static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  177. {
  178. struct ixgbe_hw *hw = &adapter->hw;
  179. u16 link_status = 0;
  180. int err;
  181. hw->bus.type = ixgbe_bus_type_pci_express;
  182. /* Get the negotiated link width and speed from PCI config space of the
  183. * parent, as this device is behind a switch
  184. */
  185. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  186. /* assume caller will handle error case */
  187. if (err)
  188. return err;
  189. hw->bus.width = ixgbe_convert_bus_width(link_status);
  190. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  191. return 0;
  192. }
  193. /**
  194. * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
  195. * @hw: hw specific details
  196. *
  197. * This function is used by probe to determine whether a device's PCI-Express
  198. * bandwidth details should be gathered from the parent bus instead of from the
  199. * device. Used to ensure that various locations all have the correct device ID
  200. * checks.
  201. */
  202. static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
  203. {
  204. switch (hw->device_id) {
  205. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  206. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  207. return true;
  208. default:
  209. return false;
  210. }
  211. }
  212. static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
  213. int expected_gts)
  214. {
  215. struct ixgbe_hw *hw = &adapter->hw;
  216. int max_gts = 0;
  217. enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
  218. enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
  219. struct pci_dev *pdev;
  220. /* Some devices are not connected over PCIe and thus do not negotiate
  221. * speed. These devices do not have valid bus info, and thus any report
  222. * we generate may not be correct.
  223. */
  224. if (hw->bus.type == ixgbe_bus_type_internal)
  225. return;
  226. /* determine whether to use the parent device */
  227. if (ixgbe_pcie_from_parent(&adapter->hw))
  228. pdev = adapter->pdev->bus->parent->self;
  229. else
  230. pdev = adapter->pdev;
  231. if (pcie_get_minimum_link(pdev, &speed, &width) ||
  232. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
  233. e_dev_warn("Unable to determine PCI Express bandwidth.\n");
  234. return;
  235. }
  236. switch (speed) {
  237. case PCIE_SPEED_2_5GT:
  238. /* 8b/10b encoding reduces max throughput by 20% */
  239. max_gts = 2 * width;
  240. break;
  241. case PCIE_SPEED_5_0GT:
  242. /* 8b/10b encoding reduces max throughput by 20% */
  243. max_gts = 4 * width;
  244. break;
  245. case PCIE_SPEED_8_0GT:
  246. /* 128b/130b encoding reduces throughput by less than 2% */
  247. max_gts = 8 * width;
  248. break;
  249. default:
  250. e_dev_warn("Unable to determine PCI Express bandwidth.\n");
  251. return;
  252. }
  253. e_dev_info("PCI Express bandwidth of %dGT/s available\n",
  254. max_gts);
  255. e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
  256. (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
  257. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
  258. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
  259. "Unknown"),
  260. width,
  261. (speed == PCIE_SPEED_2_5GT ? "20%" :
  262. speed == PCIE_SPEED_5_0GT ? "20%" :
  263. speed == PCIE_SPEED_8_0GT ? "<2%" :
  264. "Unknown"));
  265. if (max_gts < expected_gts) {
  266. e_dev_warn("This is not sufficient for optimal performance of this card.\n");
  267. e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
  268. expected_gts);
  269. e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
  270. }
  271. }
  272. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  273. {
  274. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  275. !test_bit(__IXGBE_REMOVING, &adapter->state) &&
  276. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  277. schedule_work(&adapter->service_task);
  278. }
  279. static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
  280. {
  281. struct ixgbe_adapter *adapter = hw->back;
  282. if (!hw->hw_addr)
  283. return;
  284. hw->hw_addr = NULL;
  285. e_dev_err("Adapter removed\n");
  286. if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  287. ixgbe_service_event_schedule(adapter);
  288. }
  289. static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
  290. {
  291. u32 value;
  292. /* The following check not only optimizes a bit by not
  293. * performing a read on the status register when the
  294. * register just read was a status register read that
  295. * returned IXGBE_FAILED_READ_REG. It also blocks any
  296. * potential recursion.
  297. */
  298. if (reg == IXGBE_STATUS) {
  299. ixgbe_remove_adapter(hw);
  300. return;
  301. }
  302. value = ixgbe_read_reg(hw, IXGBE_STATUS);
  303. if (value == IXGBE_FAILED_READ_REG)
  304. ixgbe_remove_adapter(hw);
  305. }
  306. /**
  307. * ixgbe_read_reg - Read from device register
  308. * @hw: hw specific details
  309. * @reg: offset of register to read
  310. *
  311. * Returns : value read or IXGBE_FAILED_READ_REG if removed
  312. *
  313. * This function is used to read device registers. It checks for device
  314. * removal by confirming any read that returns all ones by checking the
  315. * status register value for all ones. This function avoids reading from
  316. * the hardware if a removal was previously detected in which case it
  317. * returns IXGBE_FAILED_READ_REG (all ones).
  318. */
  319. u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
  320. {
  321. u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
  322. u32 value;
  323. if (ixgbe_removed(reg_addr))
  324. return IXGBE_FAILED_READ_REG;
  325. value = readl(reg_addr + reg);
  326. if (unlikely(value == IXGBE_FAILED_READ_REG))
  327. ixgbe_check_remove(hw, reg);
  328. return value;
  329. }
  330. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
  331. {
  332. u16 value;
  333. pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
  334. if (value == IXGBE_FAILED_READ_CFG_WORD) {
  335. ixgbe_remove_adapter(hw);
  336. return true;
  337. }
  338. return false;
  339. }
  340. u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
  341. {
  342. struct ixgbe_adapter *adapter = hw->back;
  343. u16 value;
  344. if (ixgbe_removed(hw->hw_addr))
  345. return IXGBE_FAILED_READ_CFG_WORD;
  346. pci_read_config_word(adapter->pdev, reg, &value);
  347. if (value == IXGBE_FAILED_READ_CFG_WORD &&
  348. ixgbe_check_cfg_remove(hw, adapter->pdev))
  349. return IXGBE_FAILED_READ_CFG_WORD;
  350. return value;
  351. }
  352. #ifdef CONFIG_PCI_IOV
  353. static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
  354. {
  355. struct ixgbe_adapter *adapter = hw->back;
  356. u32 value;
  357. if (ixgbe_removed(hw->hw_addr))
  358. return IXGBE_FAILED_READ_CFG_DWORD;
  359. pci_read_config_dword(adapter->pdev, reg, &value);
  360. if (value == IXGBE_FAILED_READ_CFG_DWORD &&
  361. ixgbe_check_cfg_remove(hw, adapter->pdev))
  362. return IXGBE_FAILED_READ_CFG_DWORD;
  363. return value;
  364. }
  365. #endif /* CONFIG_PCI_IOV */
  366. void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
  367. {
  368. struct ixgbe_adapter *adapter = hw->back;
  369. if (ixgbe_removed(hw->hw_addr))
  370. return;
  371. pci_write_config_word(adapter->pdev, reg, value);
  372. }
  373. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  374. {
  375. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  376. /* flush memory to make sure state is correct before next watchdog */
  377. smp_mb__before_atomic();
  378. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  379. }
  380. struct ixgbe_reg_info {
  381. u32 ofs;
  382. char *name;
  383. };
  384. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  385. /* General Registers */
  386. {IXGBE_CTRL, "CTRL"},
  387. {IXGBE_STATUS, "STATUS"},
  388. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  389. /* Interrupt Registers */
  390. {IXGBE_EICR, "EICR"},
  391. /* RX Registers */
  392. {IXGBE_SRRCTL(0), "SRRCTL"},
  393. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  394. {IXGBE_RDLEN(0), "RDLEN"},
  395. {IXGBE_RDH(0), "RDH"},
  396. {IXGBE_RDT(0), "RDT"},
  397. {IXGBE_RXDCTL(0), "RXDCTL"},
  398. {IXGBE_RDBAL(0), "RDBAL"},
  399. {IXGBE_RDBAH(0), "RDBAH"},
  400. /* TX Registers */
  401. {IXGBE_TDBAL(0), "TDBAL"},
  402. {IXGBE_TDBAH(0), "TDBAH"},
  403. {IXGBE_TDLEN(0), "TDLEN"},
  404. {IXGBE_TDH(0), "TDH"},
  405. {IXGBE_TDT(0), "TDT"},
  406. {IXGBE_TXDCTL(0), "TXDCTL"},
  407. /* List Terminator */
  408. { .name = NULL }
  409. };
  410. /*
  411. * ixgbe_regdump - register printout routine
  412. */
  413. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  414. {
  415. int i = 0, j = 0;
  416. char rname[16];
  417. u32 regs[64];
  418. switch (reginfo->ofs) {
  419. case IXGBE_SRRCTL(0):
  420. for (i = 0; i < 64; i++)
  421. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  422. break;
  423. case IXGBE_DCA_RXCTRL(0):
  424. for (i = 0; i < 64; i++)
  425. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  426. break;
  427. case IXGBE_RDLEN(0):
  428. for (i = 0; i < 64; i++)
  429. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  430. break;
  431. case IXGBE_RDH(0):
  432. for (i = 0; i < 64; i++)
  433. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  434. break;
  435. case IXGBE_RDT(0):
  436. for (i = 0; i < 64; i++)
  437. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  438. break;
  439. case IXGBE_RXDCTL(0):
  440. for (i = 0; i < 64; i++)
  441. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  442. break;
  443. case IXGBE_RDBAL(0):
  444. for (i = 0; i < 64; i++)
  445. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  446. break;
  447. case IXGBE_RDBAH(0):
  448. for (i = 0; i < 64; i++)
  449. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  450. break;
  451. case IXGBE_TDBAL(0):
  452. for (i = 0; i < 64; i++)
  453. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  454. break;
  455. case IXGBE_TDBAH(0):
  456. for (i = 0; i < 64; i++)
  457. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  458. break;
  459. case IXGBE_TDLEN(0):
  460. for (i = 0; i < 64; i++)
  461. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  462. break;
  463. case IXGBE_TDH(0):
  464. for (i = 0; i < 64; i++)
  465. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  466. break;
  467. case IXGBE_TDT(0):
  468. for (i = 0; i < 64; i++)
  469. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  470. break;
  471. case IXGBE_TXDCTL(0):
  472. for (i = 0; i < 64; i++)
  473. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  474. break;
  475. default:
  476. pr_info("%-15s %08x\n", reginfo->name,
  477. IXGBE_READ_REG(hw, reginfo->ofs));
  478. return;
  479. }
  480. for (i = 0; i < 8; i++) {
  481. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
  482. pr_err("%-15s", rname);
  483. for (j = 0; j < 8; j++)
  484. pr_cont(" %08x", regs[i*8+j]);
  485. pr_cont("\n");
  486. }
  487. }
  488. /*
  489. * ixgbe_dump - Print registers, tx-rings and rx-rings
  490. */
  491. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  492. {
  493. struct net_device *netdev = adapter->netdev;
  494. struct ixgbe_hw *hw = &adapter->hw;
  495. struct ixgbe_reg_info *reginfo;
  496. int n = 0;
  497. struct ixgbe_ring *tx_ring;
  498. struct ixgbe_tx_buffer *tx_buffer;
  499. union ixgbe_adv_tx_desc *tx_desc;
  500. struct my_u0 { u64 a; u64 b; } *u0;
  501. struct ixgbe_ring *rx_ring;
  502. union ixgbe_adv_rx_desc *rx_desc;
  503. struct ixgbe_rx_buffer *rx_buffer_info;
  504. u32 staterr;
  505. int i = 0;
  506. if (!netif_msg_hw(adapter))
  507. return;
  508. /* Print netdevice Info */
  509. if (netdev) {
  510. dev_info(&adapter->pdev->dev, "Net device Info\n");
  511. pr_info("Device Name state "
  512. "trans_start last_rx\n");
  513. pr_info("%-15s %016lX %016lX %016lX\n",
  514. netdev->name,
  515. netdev->state,
  516. netdev->trans_start,
  517. netdev->last_rx);
  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. tx_ring = adapter->tx_ring[n];
  535. tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  536. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  537. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  538. (u64)dma_unmap_addr(tx_buffer, dma),
  539. dma_unmap_len(tx_buffer, len),
  540. tx_buffer->next_to_watch,
  541. (u64)tx_buffer->time_stamp);
  542. }
  543. /* Print TX Rings */
  544. if (!netif_msg_tx_done(adapter))
  545. goto rx_ring_summary;
  546. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  547. /* Transmit Descriptor Formats
  548. *
  549. * 82598 Advanced Transmit Descriptor
  550. * +--------------------------------------------------------------+
  551. * 0 | Buffer Address [63:0] |
  552. * +--------------------------------------------------------------+
  553. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  554. * +--------------------------------------------------------------+
  555. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  556. *
  557. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  558. * +--------------------------------------------------------------+
  559. * 0 | RSV [63:0] |
  560. * +--------------------------------------------------------------+
  561. * 8 | RSV | STA | NXTSEQ |
  562. * +--------------------------------------------------------------+
  563. * 63 36 35 32 31 0
  564. *
  565. * 82599+ Advanced Transmit Descriptor
  566. * +--------------------------------------------------------------+
  567. * 0 | Buffer Address [63:0] |
  568. * +--------------------------------------------------------------+
  569. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  570. * +--------------------------------------------------------------+
  571. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  572. *
  573. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  574. * +--------------------------------------------------------------+
  575. * 0 | RSV [63:0] |
  576. * +--------------------------------------------------------------+
  577. * 8 | RSV | STA | RSV |
  578. * +--------------------------------------------------------------+
  579. * 63 36 35 32 31 0
  580. */
  581. for (n = 0; n < adapter->num_tx_queues; n++) {
  582. tx_ring = adapter->tx_ring[n];
  583. pr_info("------------------------------------\n");
  584. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  585. pr_info("------------------------------------\n");
  586. pr_info("%s%s %s %s %s %s\n",
  587. "T [desc] [address 63:0 ] ",
  588. "[PlPOIdStDDt Ln] [bi->dma ] ",
  589. "leng", "ntw", "timestamp", "bi->skb");
  590. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  591. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  592. tx_buffer = &tx_ring->tx_buffer_info[i];
  593. u0 = (struct my_u0 *)tx_desc;
  594. if (dma_unmap_len(tx_buffer, len) > 0) {
  595. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
  596. i,
  597. le64_to_cpu(u0->a),
  598. le64_to_cpu(u0->b),
  599. (u64)dma_unmap_addr(tx_buffer, dma),
  600. dma_unmap_len(tx_buffer, len),
  601. tx_buffer->next_to_watch,
  602. (u64)tx_buffer->time_stamp,
  603. tx_buffer->skb);
  604. if (i == tx_ring->next_to_use &&
  605. i == tx_ring->next_to_clean)
  606. pr_cont(" NTC/U\n");
  607. else if (i == tx_ring->next_to_use)
  608. pr_cont(" NTU\n");
  609. else if (i == tx_ring->next_to_clean)
  610. pr_cont(" NTC\n");
  611. else
  612. pr_cont("\n");
  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",
  686. "R [desc] [ PktBuf A0] ",
  687. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  688. "<-- Adv Rx Read format\n");
  689. pr_info("%s%s%s",
  690. "RWB[desc] [PcsmIpSHl PtRs] ",
  691. "[vl er S cks ln] ---------------- [bi->skb ] ",
  692. "<-- Adv Rx Write-Back format\n");
  693. for (i = 0; i < rx_ring->count; i++) {
  694. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  695. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  696. u0 = (struct my_u0 *)rx_desc;
  697. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  698. if (staterr & IXGBE_RXD_STAT_DD) {
  699. /* Descriptor Done */
  700. pr_info("RWB[0x%03X] %016llX "
  701. "%016llX ---------------- %p", i,
  702. le64_to_cpu(u0->a),
  703. le64_to_cpu(u0->b),
  704. rx_buffer_info->skb);
  705. } else {
  706. pr_info("R [0x%03X] %016llX "
  707. "%016llX %016llX %p", i,
  708. le64_to_cpu(u0->a),
  709. le64_to_cpu(u0->b),
  710. (u64)rx_buffer_info->dma,
  711. rx_buffer_info->skb);
  712. if (netif_msg_pktdata(adapter) &&
  713. rx_buffer_info->dma) {
  714. print_hex_dump(KERN_INFO, "",
  715. DUMP_PREFIX_ADDRESS, 16, 1,
  716. page_address(rx_buffer_info->page) +
  717. rx_buffer_info->page_offset,
  718. ixgbe_rx_bufsz(rx_ring), true);
  719. }
  720. }
  721. if (i == rx_ring->next_to_use)
  722. pr_cont(" NTU\n");
  723. else if (i == rx_ring->next_to_clean)
  724. pr_cont(" NTC\n");
  725. else
  726. pr_cont("\n");
  727. }
  728. }
  729. }
  730. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  731. {
  732. u32 ctrl_ext;
  733. /* Let firmware take over control of h/w */
  734. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  735. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  736. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  737. }
  738. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  739. {
  740. u32 ctrl_ext;
  741. /* Let firmware know the driver has taken over */
  742. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  743. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  744. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  745. }
  746. /**
  747. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  748. * @adapter: pointer to adapter struct
  749. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  750. * @queue: queue to map the corresponding interrupt to
  751. * @msix_vector: the vector to map to the corresponding queue
  752. *
  753. */
  754. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  755. u8 queue, u8 msix_vector)
  756. {
  757. u32 ivar, index;
  758. struct ixgbe_hw *hw = &adapter->hw;
  759. switch (hw->mac.type) {
  760. case ixgbe_mac_82598EB:
  761. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  762. if (direction == -1)
  763. direction = 0;
  764. index = (((direction * 64) + queue) >> 2) & 0x1F;
  765. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  766. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  767. ivar |= (msix_vector << (8 * (queue & 0x3)));
  768. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  769. break;
  770. case ixgbe_mac_82599EB:
  771. case ixgbe_mac_X540:
  772. case ixgbe_mac_X550:
  773. case ixgbe_mac_X550EM_x:
  774. if (direction == -1) {
  775. /* other causes */
  776. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  777. index = ((queue & 1) * 8);
  778. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  779. ivar &= ~(0xFF << index);
  780. ivar |= (msix_vector << index);
  781. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  782. break;
  783. } else {
  784. /* tx or rx causes */
  785. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  786. index = ((16 * (queue & 1)) + (8 * direction));
  787. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  788. ivar &= ~(0xFF << index);
  789. ivar |= (msix_vector << index);
  790. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  791. break;
  792. }
  793. default:
  794. break;
  795. }
  796. }
  797. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  798. u64 qmask)
  799. {
  800. u32 mask;
  801. switch (adapter->hw.mac.type) {
  802. case ixgbe_mac_82598EB:
  803. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  804. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  805. break;
  806. case ixgbe_mac_82599EB:
  807. case ixgbe_mac_X540:
  808. case ixgbe_mac_X550:
  809. case ixgbe_mac_X550EM_x:
  810. mask = (qmask & 0xFFFFFFFF);
  811. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  812. mask = (qmask >> 32);
  813. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  814. break;
  815. default:
  816. break;
  817. }
  818. }
  819. void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
  820. struct ixgbe_tx_buffer *tx_buffer)
  821. {
  822. if (tx_buffer->skb) {
  823. dev_kfree_skb_any(tx_buffer->skb);
  824. if (dma_unmap_len(tx_buffer, len))
  825. dma_unmap_single(ring->dev,
  826. dma_unmap_addr(tx_buffer, dma),
  827. dma_unmap_len(tx_buffer, len),
  828. DMA_TO_DEVICE);
  829. } else if (dma_unmap_len(tx_buffer, len)) {
  830. dma_unmap_page(ring->dev,
  831. dma_unmap_addr(tx_buffer, dma),
  832. dma_unmap_len(tx_buffer, len),
  833. DMA_TO_DEVICE);
  834. }
  835. tx_buffer->next_to_watch = NULL;
  836. tx_buffer->skb = NULL;
  837. dma_unmap_len_set(tx_buffer, len, 0);
  838. /* tx_buffer must be completely set up in the transmit path */
  839. }
  840. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  841. {
  842. struct ixgbe_hw *hw = &adapter->hw;
  843. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  844. int i;
  845. u32 data;
  846. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  847. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  848. return;
  849. switch (hw->mac.type) {
  850. case ixgbe_mac_82598EB:
  851. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  852. break;
  853. default:
  854. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  855. }
  856. hwstats->lxoffrxc += data;
  857. /* refill credits (no tx hang) if we received xoff */
  858. if (!data)
  859. return;
  860. for (i = 0; i < adapter->num_tx_queues; i++)
  861. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  862. &adapter->tx_ring[i]->state);
  863. }
  864. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  865. {
  866. struct ixgbe_hw *hw = &adapter->hw;
  867. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  868. u32 xoff[8] = {0};
  869. u8 tc;
  870. int i;
  871. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  872. if (adapter->ixgbe_ieee_pfc)
  873. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  874. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  875. ixgbe_update_xoff_rx_lfc(adapter);
  876. return;
  877. }
  878. /* update stats for each tc, only valid with PFC enabled */
  879. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  880. u32 pxoffrxc;
  881. switch (hw->mac.type) {
  882. case ixgbe_mac_82598EB:
  883. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  884. break;
  885. default:
  886. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  887. }
  888. hwstats->pxoffrxc[i] += pxoffrxc;
  889. /* Get the TC for given UP */
  890. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  891. xoff[tc] += pxoffrxc;
  892. }
  893. /* disarm tx queues that have received xoff frames */
  894. for (i = 0; i < adapter->num_tx_queues; i++) {
  895. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  896. tc = tx_ring->dcb_tc;
  897. if (xoff[tc])
  898. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  899. }
  900. }
  901. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  902. {
  903. return ring->stats.packets;
  904. }
  905. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  906. {
  907. struct ixgbe_adapter *adapter;
  908. struct ixgbe_hw *hw;
  909. u32 head, tail;
  910. if (ring->l2_accel_priv)
  911. adapter = ring->l2_accel_priv->real_adapter;
  912. else
  913. adapter = netdev_priv(ring->netdev);
  914. hw = &adapter->hw;
  915. head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
  916. tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
  917. if (head != tail)
  918. return (head < tail) ?
  919. tail - head : (tail + ring->count - head);
  920. return 0;
  921. }
  922. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  923. {
  924. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  925. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  926. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  927. clear_check_for_tx_hang(tx_ring);
  928. /*
  929. * Check for a hung queue, but be thorough. This verifies
  930. * that a transmit has been completed since the previous
  931. * check AND there is at least one packet pending. The
  932. * ARMED bit is set to indicate a potential hang. The
  933. * bit is cleared if a pause frame is received to remove
  934. * false hang detection due to PFC or 802.3x frames. By
  935. * requiring this to fail twice we avoid races with
  936. * pfc clearing the ARMED bit and conditions where we
  937. * run the check_tx_hang logic with a transmit completion
  938. * pending but without time to complete it yet.
  939. */
  940. if (tx_done_old == tx_done && tx_pending)
  941. /* make sure it is true for two checks in a row */
  942. return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  943. &tx_ring->state);
  944. /* update completed stats and continue */
  945. tx_ring->tx_stats.tx_done_old = tx_done;
  946. /* reset the countdown */
  947. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  948. return false;
  949. }
  950. /**
  951. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  952. * @adapter: driver private struct
  953. **/
  954. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  955. {
  956. /* Do the reset outside of interrupt context */
  957. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  958. adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
  959. e_warn(drv, "initiating reset due to tx timeout\n");
  960. ixgbe_service_event_schedule(adapter);
  961. }
  962. }
  963. /**
  964. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  965. * @q_vector: structure containing interrupt and ring information
  966. * @tx_ring: tx ring to clean
  967. **/
  968. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  969. struct ixgbe_ring *tx_ring)
  970. {
  971. struct ixgbe_adapter *adapter = q_vector->adapter;
  972. struct ixgbe_tx_buffer *tx_buffer;
  973. union ixgbe_adv_tx_desc *tx_desc;
  974. unsigned int total_bytes = 0, total_packets = 0;
  975. unsigned int budget = q_vector->tx.work_limit;
  976. unsigned int i = tx_ring->next_to_clean;
  977. if (test_bit(__IXGBE_DOWN, &adapter->state))
  978. return true;
  979. tx_buffer = &tx_ring->tx_buffer_info[i];
  980. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  981. i -= tx_ring->count;
  982. do {
  983. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  984. /* if next_to_watch is not set then there is no work pending */
  985. if (!eop_desc)
  986. break;
  987. /* prevent any other reads prior to eop_desc */
  988. read_barrier_depends();
  989. /* if DD is not set pending work has not been completed */
  990. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  991. break;
  992. /* clear next_to_watch to prevent false hangs */
  993. tx_buffer->next_to_watch = NULL;
  994. /* update the statistics for this packet */
  995. total_bytes += tx_buffer->bytecount;
  996. total_packets += tx_buffer->gso_segs;
  997. /* free the skb */
  998. dev_consume_skb_any(tx_buffer->skb);
  999. /* unmap skb header data */
  1000. dma_unmap_single(tx_ring->dev,
  1001. dma_unmap_addr(tx_buffer, dma),
  1002. dma_unmap_len(tx_buffer, len),
  1003. DMA_TO_DEVICE);
  1004. /* clear tx_buffer data */
  1005. tx_buffer->skb = NULL;
  1006. dma_unmap_len_set(tx_buffer, len, 0);
  1007. /* unmap remaining buffers */
  1008. while (tx_desc != eop_desc) {
  1009. tx_buffer++;
  1010. tx_desc++;
  1011. i++;
  1012. if (unlikely(!i)) {
  1013. i -= tx_ring->count;
  1014. tx_buffer = tx_ring->tx_buffer_info;
  1015. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1016. }
  1017. /* unmap any remaining paged data */
  1018. if (dma_unmap_len(tx_buffer, len)) {
  1019. dma_unmap_page(tx_ring->dev,
  1020. dma_unmap_addr(tx_buffer, dma),
  1021. dma_unmap_len(tx_buffer, len),
  1022. DMA_TO_DEVICE);
  1023. dma_unmap_len_set(tx_buffer, len, 0);
  1024. }
  1025. }
  1026. /* move us one more past the eop_desc for start of next pkt */
  1027. tx_buffer++;
  1028. tx_desc++;
  1029. i++;
  1030. if (unlikely(!i)) {
  1031. i -= tx_ring->count;
  1032. tx_buffer = tx_ring->tx_buffer_info;
  1033. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1034. }
  1035. /* issue prefetch for next Tx descriptor */
  1036. prefetch(tx_desc);
  1037. /* update budget accounting */
  1038. budget--;
  1039. } while (likely(budget));
  1040. i += tx_ring->count;
  1041. tx_ring->next_to_clean = i;
  1042. u64_stats_update_begin(&tx_ring->syncp);
  1043. tx_ring->stats.bytes += total_bytes;
  1044. tx_ring->stats.packets += total_packets;
  1045. u64_stats_update_end(&tx_ring->syncp);
  1046. q_vector->tx.total_bytes += total_bytes;
  1047. q_vector->tx.total_packets += total_packets;
  1048. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  1049. /* schedule immediate reset if we believe we hung */
  1050. struct ixgbe_hw *hw = &adapter->hw;
  1051. e_err(drv, "Detected Tx Unit Hang\n"
  1052. " Tx Queue <%d>\n"
  1053. " TDH, TDT <%x>, <%x>\n"
  1054. " next_to_use <%x>\n"
  1055. " next_to_clean <%x>\n"
  1056. "tx_buffer_info[next_to_clean]\n"
  1057. " time_stamp <%lx>\n"
  1058. " jiffies <%lx>\n",
  1059. tx_ring->queue_index,
  1060. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  1061. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  1062. tx_ring->next_to_use, i,
  1063. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  1064. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  1065. e_info(probe,
  1066. "tx hang %d detected on queue %d, resetting adapter\n",
  1067. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  1068. /* schedule immediate reset if we believe we hung */
  1069. ixgbe_tx_timeout_reset(adapter);
  1070. /* the adapter is about to reset, no point in enabling stuff */
  1071. return true;
  1072. }
  1073. netdev_tx_completed_queue(txring_txq(tx_ring),
  1074. total_packets, total_bytes);
  1075. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  1076. if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
  1077. (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
  1078. /* Make sure that anybody stopping the queue after this
  1079. * sees the new next_to_clean.
  1080. */
  1081. smp_mb();
  1082. if (__netif_subqueue_stopped(tx_ring->netdev,
  1083. tx_ring->queue_index)
  1084. && !test_bit(__IXGBE_DOWN, &adapter->state)) {
  1085. netif_wake_subqueue(tx_ring->netdev,
  1086. tx_ring->queue_index);
  1087. ++tx_ring->tx_stats.restart_queue;
  1088. }
  1089. }
  1090. return !!budget;
  1091. }
  1092. #ifdef CONFIG_IXGBE_DCA
  1093. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  1094. struct ixgbe_ring *tx_ring,
  1095. int cpu)
  1096. {
  1097. struct ixgbe_hw *hw = &adapter->hw;
  1098. u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
  1099. u16 reg_offset;
  1100. switch (hw->mac.type) {
  1101. case ixgbe_mac_82598EB:
  1102. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  1103. break;
  1104. case ixgbe_mac_82599EB:
  1105. case ixgbe_mac_X540:
  1106. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  1107. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  1108. break;
  1109. default:
  1110. /* for unknown hardware do not write register */
  1111. return;
  1112. }
  1113. /*
  1114. * We can enable relaxed ordering for reads, but not writes when
  1115. * DCA is enabled. This is due to a known issue in some chipsets
  1116. * which will cause the DCA tag to be cleared.
  1117. */
  1118. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  1119. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  1120. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  1121. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  1122. }
  1123. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  1124. struct ixgbe_ring *rx_ring,
  1125. int cpu)
  1126. {
  1127. struct ixgbe_hw *hw = &adapter->hw;
  1128. u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  1129. u8 reg_idx = rx_ring->reg_idx;
  1130. switch (hw->mac.type) {
  1131. case ixgbe_mac_82599EB:
  1132. case ixgbe_mac_X540:
  1133. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  1134. break;
  1135. default:
  1136. break;
  1137. }
  1138. /*
  1139. * We can enable relaxed ordering for reads, but not writes when
  1140. * DCA is enabled. This is due to a known issue in some chipsets
  1141. * which will cause the DCA tag to be cleared.
  1142. */
  1143. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  1144. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  1145. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  1146. }
  1147. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  1148. {
  1149. struct ixgbe_adapter *adapter = q_vector->adapter;
  1150. struct ixgbe_ring *ring;
  1151. int cpu = get_cpu();
  1152. if (q_vector->cpu == cpu)
  1153. goto out_no_update;
  1154. ixgbe_for_each_ring(ring, q_vector->tx)
  1155. ixgbe_update_tx_dca(adapter, ring, cpu);
  1156. ixgbe_for_each_ring(ring, q_vector->rx)
  1157. ixgbe_update_rx_dca(adapter, ring, cpu);
  1158. q_vector->cpu = cpu;
  1159. out_no_update:
  1160. put_cpu();
  1161. }
  1162. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  1163. {
  1164. int i;
  1165. if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
  1166. return;
  1167. /* always use CB2 mode, difference is masked in the CB driver */
  1168. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
  1169. for (i = 0; i < adapter->num_q_vectors; i++) {
  1170. adapter->q_vector[i]->cpu = -1;
  1171. ixgbe_update_dca(adapter->q_vector[i]);
  1172. }
  1173. }
  1174. static int __ixgbe_notify_dca(struct device *dev, void *data)
  1175. {
  1176. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  1177. unsigned long event = *(unsigned long *)data;
  1178. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  1179. return 0;
  1180. switch (event) {
  1181. case DCA_PROVIDER_ADD:
  1182. /* if we're already enabled, don't do it again */
  1183. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1184. break;
  1185. if (dca_add_requester(dev) == 0) {
  1186. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  1187. ixgbe_setup_dca(adapter);
  1188. break;
  1189. }
  1190. /* Fall Through since DCA is disabled. */
  1191. case DCA_PROVIDER_REMOVE:
  1192. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  1193. dca_remove_requester(dev);
  1194. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  1195. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  1196. }
  1197. break;
  1198. }
  1199. return 0;
  1200. }
  1201. #endif /* CONFIG_IXGBE_DCA */
  1202. #define IXGBE_RSS_L4_TYPES_MASK \
  1203. ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
  1204. (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
  1205. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
  1206. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
  1207. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1208. union ixgbe_adv_rx_desc *rx_desc,
  1209. struct sk_buff *skb)
  1210. {
  1211. u16 rss_type;
  1212. if (!(ring->netdev->features & NETIF_F_RXHASH))
  1213. return;
  1214. rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
  1215. IXGBE_RXDADV_RSSTYPE_MASK;
  1216. if (!rss_type)
  1217. return;
  1218. skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
  1219. (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
  1220. PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
  1221. }
  1222. #ifdef IXGBE_FCOE
  1223. /**
  1224. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1225. * @ring: structure containing ring specific data
  1226. * @rx_desc: advanced rx descriptor
  1227. *
  1228. * Returns : true if it is FCoE pkt
  1229. */
  1230. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1231. union ixgbe_adv_rx_desc *rx_desc)
  1232. {
  1233. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1234. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1235. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1236. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1237. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1238. }
  1239. #endif /* IXGBE_FCOE */
  1240. /**
  1241. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1242. * @ring: structure containing ring specific data
  1243. * @rx_desc: current Rx descriptor being processed
  1244. * @skb: skb currently being received and modified
  1245. **/
  1246. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1247. union ixgbe_adv_rx_desc *rx_desc,
  1248. struct sk_buff *skb)
  1249. {
  1250. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1251. __le16 hdr_info = rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
  1252. bool encap_pkt = false;
  1253. skb_checksum_none_assert(skb);
  1254. /* Rx csum disabled */
  1255. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1256. return;
  1257. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) &&
  1258. (hdr_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_TUNNEL >> 16))) {
  1259. encap_pkt = true;
  1260. skb->encapsulation = 1;
  1261. }
  1262. /* if IP and error */
  1263. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1264. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1265. ring->rx_stats.csum_err++;
  1266. return;
  1267. }
  1268. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1269. return;
  1270. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1271. /*
  1272. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1273. * checksum errors.
  1274. */
  1275. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1276. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1277. return;
  1278. ring->rx_stats.csum_err++;
  1279. return;
  1280. }
  1281. /* It must be a TCP or UDP packet with a valid checksum */
  1282. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1283. if (encap_pkt) {
  1284. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
  1285. return;
  1286. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
  1287. ring->rx_stats.csum_err++;
  1288. return;
  1289. }
  1290. /* If we checked the outer header let the stack know */
  1291. skb->csum_level = 1;
  1292. }
  1293. }
  1294. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1295. struct ixgbe_rx_buffer *bi)
  1296. {
  1297. struct page *page = bi->page;
  1298. dma_addr_t dma;
  1299. /* since we are recycling buffers we should seldom need to alloc */
  1300. if (likely(page))
  1301. return true;
  1302. /* alloc new page for storage */
  1303. page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
  1304. if (unlikely(!page)) {
  1305. rx_ring->rx_stats.alloc_rx_page_failed++;
  1306. return false;
  1307. }
  1308. /* map page for use */
  1309. dma = dma_map_page(rx_ring->dev, page, 0,
  1310. ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
  1311. /*
  1312. * if mapping failed free memory back to system since
  1313. * there isn't much point in holding memory we can't use
  1314. */
  1315. if (dma_mapping_error(rx_ring->dev, dma)) {
  1316. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1317. rx_ring->rx_stats.alloc_rx_page_failed++;
  1318. return false;
  1319. }
  1320. bi->dma = dma;
  1321. bi->page = page;
  1322. bi->page_offset = 0;
  1323. return true;
  1324. }
  1325. /**
  1326. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1327. * @rx_ring: ring to place buffers on
  1328. * @cleaned_count: number of buffers to replace
  1329. **/
  1330. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1331. {
  1332. union ixgbe_adv_rx_desc *rx_desc;
  1333. struct ixgbe_rx_buffer *bi;
  1334. u16 i = rx_ring->next_to_use;
  1335. /* nothing to do */
  1336. if (!cleaned_count)
  1337. return;
  1338. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1339. bi = &rx_ring->rx_buffer_info[i];
  1340. i -= rx_ring->count;
  1341. do {
  1342. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1343. break;
  1344. /*
  1345. * Refresh the desc even if buffer_addrs didn't change
  1346. * because each write-back erases this info.
  1347. */
  1348. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1349. rx_desc++;
  1350. bi++;
  1351. i++;
  1352. if (unlikely(!i)) {
  1353. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1354. bi = rx_ring->rx_buffer_info;
  1355. i -= rx_ring->count;
  1356. }
  1357. /* clear the status bits for the next_to_use descriptor */
  1358. rx_desc->wb.upper.status_error = 0;
  1359. cleaned_count--;
  1360. } while (cleaned_count);
  1361. i += rx_ring->count;
  1362. if (rx_ring->next_to_use != i) {
  1363. rx_ring->next_to_use = i;
  1364. /* update next to alloc since we have filled the ring */
  1365. rx_ring->next_to_alloc = i;
  1366. /* Force memory writes to complete before letting h/w
  1367. * know there are new descriptors to fetch. (Only
  1368. * applicable for weak-ordered memory model archs,
  1369. * such as IA-64).
  1370. */
  1371. wmb();
  1372. writel(i, rx_ring->tail);
  1373. }
  1374. }
  1375. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1376. struct sk_buff *skb)
  1377. {
  1378. u16 hdr_len = skb_headlen(skb);
  1379. /* set gso_size to avoid messing up TCP MSS */
  1380. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1381. IXGBE_CB(skb)->append_cnt);
  1382. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1383. }
  1384. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1385. struct sk_buff *skb)
  1386. {
  1387. /* if append_cnt is 0 then frame is not RSC */
  1388. if (!IXGBE_CB(skb)->append_cnt)
  1389. return;
  1390. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1391. rx_ring->rx_stats.rsc_flush++;
  1392. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1393. /* gso_size is computed using append_cnt so always clear it last */
  1394. IXGBE_CB(skb)->append_cnt = 0;
  1395. }
  1396. /**
  1397. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1398. * @rx_ring: rx descriptor ring packet is being transacted on
  1399. * @rx_desc: pointer to the EOP Rx descriptor
  1400. * @skb: pointer to current skb being populated
  1401. *
  1402. * This function checks the ring, descriptor, and packet information in
  1403. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1404. * other fields within the skb.
  1405. **/
  1406. static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1407. union ixgbe_adv_rx_desc *rx_desc,
  1408. struct sk_buff *skb)
  1409. {
  1410. struct net_device *dev = rx_ring->netdev;
  1411. ixgbe_update_rsc_stats(rx_ring, skb);
  1412. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1413. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1414. if (unlikely(ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_TS)))
  1415. ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector->adapter, skb);
  1416. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1417. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1418. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1419. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1420. }
  1421. skb_record_rx_queue(skb, rx_ring->queue_index);
  1422. skb->protocol = eth_type_trans(skb, dev);
  1423. }
  1424. static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1425. struct sk_buff *skb)
  1426. {
  1427. if (ixgbe_qv_busy_polling(q_vector))
  1428. netif_receive_skb(skb);
  1429. else
  1430. napi_gro_receive(&q_vector->napi, skb);
  1431. }
  1432. /**
  1433. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1434. * @rx_ring: Rx ring being processed
  1435. * @rx_desc: Rx descriptor for current buffer
  1436. * @skb: Current socket buffer containing buffer in progress
  1437. *
  1438. * This function updates next to clean. If the buffer is an EOP buffer
  1439. * this function exits returning false, otherwise it will place the
  1440. * sk_buff in the next buffer to be chained and return true indicating
  1441. * that this is in fact a non-EOP buffer.
  1442. **/
  1443. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1444. union ixgbe_adv_rx_desc *rx_desc,
  1445. struct sk_buff *skb)
  1446. {
  1447. u32 ntc = rx_ring->next_to_clean + 1;
  1448. /* fetch, update, and store next to clean */
  1449. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1450. rx_ring->next_to_clean = ntc;
  1451. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1452. /* update RSC append count if present */
  1453. if (ring_is_rsc_enabled(rx_ring)) {
  1454. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1455. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1456. if (unlikely(rsc_enabled)) {
  1457. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1458. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1459. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1460. /* update ntc based on RSC value */
  1461. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1462. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1463. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1464. }
  1465. }
  1466. /* if we are the last buffer then there is nothing else to do */
  1467. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1468. return false;
  1469. /* place skb in next buffer to be received */
  1470. rx_ring->rx_buffer_info[ntc].skb = skb;
  1471. rx_ring->rx_stats.non_eop_descs++;
  1472. return true;
  1473. }
  1474. /**
  1475. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1476. * @rx_ring: rx descriptor ring packet is being transacted on
  1477. * @skb: pointer to current skb being adjusted
  1478. *
  1479. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1480. * main difference between this version and the original function is that
  1481. * this function can make several assumptions about the state of things
  1482. * that allow for significant optimizations versus the standard function.
  1483. * As a result we can do things like drop a frag and maintain an accurate
  1484. * truesize for the skb.
  1485. */
  1486. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1487. struct sk_buff *skb)
  1488. {
  1489. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1490. unsigned char *va;
  1491. unsigned int pull_len;
  1492. /*
  1493. * it is valid to use page_address instead of kmap since we are
  1494. * working with pages allocated out of the lomem pool per
  1495. * alloc_page(GFP_ATOMIC)
  1496. */
  1497. va = skb_frag_address(frag);
  1498. /*
  1499. * we need the header to contain the greater of either ETH_HLEN or
  1500. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1501. */
  1502. pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
  1503. /* align pull length to size of long to optimize memcpy performance */
  1504. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1505. /* update all of the pointers */
  1506. skb_frag_size_sub(frag, pull_len);
  1507. frag->page_offset += pull_len;
  1508. skb->data_len -= pull_len;
  1509. skb->tail += pull_len;
  1510. }
  1511. /**
  1512. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1513. * @rx_ring: rx descriptor ring packet is being transacted on
  1514. * @skb: pointer to current skb being updated
  1515. *
  1516. * This function provides a basic DMA sync up for the first fragment of an
  1517. * skb. The reason for doing this is that the first fragment cannot be
  1518. * unmapped until we have reached the end of packet descriptor for a buffer
  1519. * chain.
  1520. */
  1521. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1522. struct sk_buff *skb)
  1523. {
  1524. /* if the page was released unmap it, else just sync our portion */
  1525. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1526. dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
  1527. ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
  1528. IXGBE_CB(skb)->page_released = false;
  1529. } else {
  1530. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1531. dma_sync_single_range_for_cpu(rx_ring->dev,
  1532. IXGBE_CB(skb)->dma,
  1533. frag->page_offset,
  1534. ixgbe_rx_bufsz(rx_ring),
  1535. DMA_FROM_DEVICE);
  1536. }
  1537. IXGBE_CB(skb)->dma = 0;
  1538. }
  1539. /**
  1540. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1541. * @rx_ring: rx descriptor ring packet is being transacted on
  1542. * @rx_desc: pointer to the EOP Rx descriptor
  1543. * @skb: pointer to current skb being fixed
  1544. *
  1545. * Check for corrupted packet headers caused by senders on the local L2
  1546. * embedded NIC switch not setting up their Tx Descriptors right. These
  1547. * should be very rare.
  1548. *
  1549. * Also address the case where we are pulling data in on pages only
  1550. * and as such no data is present in the skb header.
  1551. *
  1552. * In addition if skb is not at least 60 bytes we need to pad it so that
  1553. * it is large enough to qualify as a valid Ethernet frame.
  1554. *
  1555. * Returns true if an error was encountered and skb was freed.
  1556. **/
  1557. static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1558. union ixgbe_adv_rx_desc *rx_desc,
  1559. struct sk_buff *skb)
  1560. {
  1561. struct net_device *netdev = rx_ring->netdev;
  1562. /* verify that the packet does not have any known errors */
  1563. if (unlikely(ixgbe_test_staterr(rx_desc,
  1564. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1565. !(netdev->features & NETIF_F_RXALL))) {
  1566. dev_kfree_skb_any(skb);
  1567. return true;
  1568. }
  1569. /* place header in linear portion of buffer */
  1570. if (skb_is_nonlinear(skb))
  1571. ixgbe_pull_tail(rx_ring, skb);
  1572. #ifdef IXGBE_FCOE
  1573. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1574. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1575. return false;
  1576. #endif
  1577. /* if eth_skb_pad returns an error the skb was freed */
  1578. if (eth_skb_pad(skb))
  1579. return true;
  1580. return false;
  1581. }
  1582. /**
  1583. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1584. * @rx_ring: rx descriptor ring to store buffers on
  1585. * @old_buff: donor buffer to have page reused
  1586. *
  1587. * Synchronizes page for reuse by the adapter
  1588. **/
  1589. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1590. struct ixgbe_rx_buffer *old_buff)
  1591. {
  1592. struct ixgbe_rx_buffer *new_buff;
  1593. u16 nta = rx_ring->next_to_alloc;
  1594. new_buff = &rx_ring->rx_buffer_info[nta];
  1595. /* update, and store next to alloc */
  1596. nta++;
  1597. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1598. /* transfer page from old buffer to new buffer */
  1599. *new_buff = *old_buff;
  1600. /* sync the buffer for use by the device */
  1601. dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
  1602. new_buff->page_offset,
  1603. ixgbe_rx_bufsz(rx_ring),
  1604. DMA_FROM_DEVICE);
  1605. }
  1606. static inline bool ixgbe_page_is_reserved(struct page *page)
  1607. {
  1608. return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
  1609. }
  1610. /**
  1611. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1612. * @rx_ring: rx descriptor ring to transact packets on
  1613. * @rx_buffer: buffer containing page to add
  1614. * @rx_desc: descriptor containing length of buffer written by hardware
  1615. * @skb: sk_buff to place the data into
  1616. *
  1617. * This function will add the data contained in rx_buffer->page to the skb.
  1618. * This is done either through a direct copy if the data in the buffer is
  1619. * less than the skb header size, otherwise it will just attach the page as
  1620. * a frag to the skb.
  1621. *
  1622. * The function will then update the page offset if necessary and return
  1623. * true if the buffer can be reused by the adapter.
  1624. **/
  1625. static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1626. struct ixgbe_rx_buffer *rx_buffer,
  1627. union ixgbe_adv_rx_desc *rx_desc,
  1628. struct sk_buff *skb)
  1629. {
  1630. struct page *page = rx_buffer->page;
  1631. unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
  1632. #if (PAGE_SIZE < 8192)
  1633. unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
  1634. #else
  1635. unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
  1636. unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
  1637. ixgbe_rx_bufsz(rx_ring);
  1638. #endif
  1639. if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
  1640. unsigned char *va = page_address(page) + rx_buffer->page_offset;
  1641. memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
  1642. /* page is not reserved, we can reuse buffer as-is */
  1643. if (likely(!ixgbe_page_is_reserved(page)))
  1644. return true;
  1645. /* this page cannot be reused so discard it */
  1646. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1647. return false;
  1648. }
  1649. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
  1650. rx_buffer->page_offset, size, truesize);
  1651. /* avoid re-using remote pages */
  1652. if (unlikely(ixgbe_page_is_reserved(page)))
  1653. return false;
  1654. #if (PAGE_SIZE < 8192)
  1655. /* if we are only owner of page we can reuse it */
  1656. if (unlikely(page_count(page) != 1))
  1657. return false;
  1658. /* flip page offset to other buffer */
  1659. rx_buffer->page_offset ^= truesize;
  1660. #else
  1661. /* move offset up to the next cache line */
  1662. rx_buffer->page_offset += truesize;
  1663. if (rx_buffer->page_offset > last_offset)
  1664. return false;
  1665. #endif
  1666. /* Even if we own the page, we are not allowed to use atomic_set()
  1667. * This would break get_page_unless_zero() users.
  1668. */
  1669. atomic_inc(&page->_count);
  1670. return true;
  1671. }
  1672. static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
  1673. union ixgbe_adv_rx_desc *rx_desc)
  1674. {
  1675. struct ixgbe_rx_buffer *rx_buffer;
  1676. struct sk_buff *skb;
  1677. struct page *page;
  1678. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1679. page = rx_buffer->page;
  1680. prefetchw(page);
  1681. skb = rx_buffer->skb;
  1682. if (likely(!skb)) {
  1683. void *page_addr = page_address(page) +
  1684. rx_buffer->page_offset;
  1685. /* prefetch first cache line of first page */
  1686. prefetch(page_addr);
  1687. #if L1_CACHE_BYTES < 128
  1688. prefetch(page_addr + L1_CACHE_BYTES);
  1689. #endif
  1690. /* allocate a skb to store the frags */
  1691. skb = napi_alloc_skb(&rx_ring->q_vector->napi,
  1692. IXGBE_RX_HDR_SIZE);
  1693. if (unlikely(!skb)) {
  1694. rx_ring->rx_stats.alloc_rx_buff_failed++;
  1695. return NULL;
  1696. }
  1697. /*
  1698. * we will be copying header into skb->data in
  1699. * pskb_may_pull so it is in our interest to prefetch
  1700. * it now to avoid a possible cache miss
  1701. */
  1702. prefetchw(skb->data);
  1703. /*
  1704. * Delay unmapping of the first packet. It carries the
  1705. * header information, HW may still access the header
  1706. * after the writeback. Only unmap it when EOP is
  1707. * reached
  1708. */
  1709. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1710. goto dma_sync;
  1711. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1712. } else {
  1713. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1714. ixgbe_dma_sync_frag(rx_ring, skb);
  1715. dma_sync:
  1716. /* we are reusing so sync this buffer for CPU use */
  1717. dma_sync_single_range_for_cpu(rx_ring->dev,
  1718. rx_buffer->dma,
  1719. rx_buffer->page_offset,
  1720. ixgbe_rx_bufsz(rx_ring),
  1721. DMA_FROM_DEVICE);
  1722. rx_buffer->skb = NULL;
  1723. }
  1724. /* pull page into skb */
  1725. if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
  1726. /* hand second half of page back to the ring */
  1727. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1728. } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1729. /* the page has been released from the ring */
  1730. IXGBE_CB(skb)->page_released = true;
  1731. } else {
  1732. /* we are not reusing the buffer so unmap it */
  1733. dma_unmap_page(rx_ring->dev, rx_buffer->dma,
  1734. ixgbe_rx_pg_size(rx_ring),
  1735. DMA_FROM_DEVICE);
  1736. }
  1737. /* clear contents of buffer_info */
  1738. rx_buffer->page = NULL;
  1739. return skb;
  1740. }
  1741. /**
  1742. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  1743. * @q_vector: structure containing interrupt and ring information
  1744. * @rx_ring: rx descriptor ring to transact packets on
  1745. * @budget: Total limit on number of packets to process
  1746. *
  1747. * This function provides a "bounce buffer" approach to Rx interrupt
  1748. * processing. The advantage to this is that on systems that have
  1749. * expensive overhead for IOMMU access this provides a means of avoiding
  1750. * it by maintaining the mapping of the page to the syste.
  1751. *
  1752. * Returns amount of work completed
  1753. **/
  1754. static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1755. struct ixgbe_ring *rx_ring,
  1756. const int budget)
  1757. {
  1758. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1759. #ifdef IXGBE_FCOE
  1760. struct ixgbe_adapter *adapter = q_vector->adapter;
  1761. int ddp_bytes;
  1762. unsigned int mss = 0;
  1763. #endif /* IXGBE_FCOE */
  1764. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  1765. while (likely(total_rx_packets < budget)) {
  1766. union ixgbe_adv_rx_desc *rx_desc;
  1767. struct sk_buff *skb;
  1768. /* return some buffers to hardware, one at a time is too slow */
  1769. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1770. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1771. cleaned_count = 0;
  1772. }
  1773. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  1774. if (!rx_desc->wb.upper.status_error)
  1775. break;
  1776. /* This memory barrier is needed to keep us from reading
  1777. * any other fields out of the rx_desc until we know the
  1778. * descriptor has been written back
  1779. */
  1780. dma_rmb();
  1781. /* retrieve a buffer from the ring */
  1782. skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
  1783. /* exit if we failed to retrieve a buffer */
  1784. if (!skb)
  1785. break;
  1786. cleaned_count++;
  1787. /* place incomplete frames back on ring for completion */
  1788. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  1789. continue;
  1790. /* verify the packet layout is correct */
  1791. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  1792. continue;
  1793. /* probably a little skewed due to removing CRC */
  1794. total_rx_bytes += skb->len;
  1795. /* populate checksum, timestamp, VLAN, and protocol */
  1796. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  1797. #ifdef IXGBE_FCOE
  1798. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  1799. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  1800. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  1801. /* include DDPed FCoE data */
  1802. if (ddp_bytes > 0) {
  1803. if (!mss) {
  1804. mss = rx_ring->netdev->mtu -
  1805. sizeof(struct fcoe_hdr) -
  1806. sizeof(struct fc_frame_header) -
  1807. sizeof(struct fcoe_crc_eof);
  1808. if (mss > 512)
  1809. mss &= ~511;
  1810. }
  1811. total_rx_bytes += ddp_bytes;
  1812. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  1813. mss);
  1814. }
  1815. if (!ddp_bytes) {
  1816. dev_kfree_skb_any(skb);
  1817. continue;
  1818. }
  1819. }
  1820. #endif /* IXGBE_FCOE */
  1821. skb_mark_napi_id(skb, &q_vector->napi);
  1822. ixgbe_rx_skb(q_vector, skb);
  1823. /* update budget accounting */
  1824. total_rx_packets++;
  1825. }
  1826. u64_stats_update_begin(&rx_ring->syncp);
  1827. rx_ring->stats.packets += total_rx_packets;
  1828. rx_ring->stats.bytes += total_rx_bytes;
  1829. u64_stats_update_end(&rx_ring->syncp);
  1830. q_vector->rx.total_packets += total_rx_packets;
  1831. q_vector->rx.total_bytes += total_rx_bytes;
  1832. return total_rx_packets;
  1833. }
  1834. #ifdef CONFIG_NET_RX_BUSY_POLL
  1835. /* must be called with local_bh_disable()d */
  1836. static int ixgbe_low_latency_recv(struct napi_struct *napi)
  1837. {
  1838. struct ixgbe_q_vector *q_vector =
  1839. container_of(napi, struct ixgbe_q_vector, napi);
  1840. struct ixgbe_adapter *adapter = q_vector->adapter;
  1841. struct ixgbe_ring *ring;
  1842. int found = 0;
  1843. if (test_bit(__IXGBE_DOWN, &adapter->state))
  1844. return LL_FLUSH_FAILED;
  1845. if (!ixgbe_qv_lock_poll(q_vector))
  1846. return LL_FLUSH_BUSY;
  1847. ixgbe_for_each_ring(ring, q_vector->rx) {
  1848. found = ixgbe_clean_rx_irq(q_vector, ring, 4);
  1849. #ifdef BP_EXTENDED_STATS
  1850. if (found)
  1851. ring->stats.cleaned += found;
  1852. else
  1853. ring->stats.misses++;
  1854. #endif
  1855. if (found)
  1856. break;
  1857. }
  1858. ixgbe_qv_unlock_poll(q_vector);
  1859. return found;
  1860. }
  1861. #endif /* CONFIG_NET_RX_BUSY_POLL */
  1862. /**
  1863. * ixgbe_configure_msix - Configure MSI-X hardware
  1864. * @adapter: board private structure
  1865. *
  1866. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  1867. * interrupts.
  1868. **/
  1869. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  1870. {
  1871. struct ixgbe_q_vector *q_vector;
  1872. int v_idx;
  1873. u32 mask;
  1874. /* Populate MSIX to EITR Select */
  1875. if (adapter->num_vfs > 32) {
  1876. u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
  1877. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  1878. }
  1879. /*
  1880. * Populate the IVAR table and set the ITR values to the
  1881. * corresponding register.
  1882. */
  1883. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  1884. struct ixgbe_ring *ring;
  1885. q_vector = adapter->q_vector[v_idx];
  1886. ixgbe_for_each_ring(ring, q_vector->rx)
  1887. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  1888. ixgbe_for_each_ring(ring, q_vector->tx)
  1889. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  1890. ixgbe_write_eitr(q_vector);
  1891. }
  1892. switch (adapter->hw.mac.type) {
  1893. case ixgbe_mac_82598EB:
  1894. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  1895. v_idx);
  1896. break;
  1897. case ixgbe_mac_82599EB:
  1898. case ixgbe_mac_X540:
  1899. case ixgbe_mac_X550:
  1900. case ixgbe_mac_X550EM_x:
  1901. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  1902. break;
  1903. default:
  1904. break;
  1905. }
  1906. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  1907. /* set up to autoclear timer, and the vectors */
  1908. mask = IXGBE_EIMS_ENABLE_MASK;
  1909. mask &= ~(IXGBE_EIMS_OTHER |
  1910. IXGBE_EIMS_MAILBOX |
  1911. IXGBE_EIMS_LSC);
  1912. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  1913. }
  1914. enum latency_range {
  1915. lowest_latency = 0,
  1916. low_latency = 1,
  1917. bulk_latency = 2,
  1918. latency_invalid = 255
  1919. };
  1920. /**
  1921. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  1922. * @q_vector: structure containing interrupt and ring information
  1923. * @ring_container: structure containing ring performance data
  1924. *
  1925. * Stores a new ITR value based on packets and byte
  1926. * counts during the last interrupt. The advantage of per interrupt
  1927. * computation is faster updates and more accurate ITR for the current
  1928. * traffic pattern. Constants in this function were computed
  1929. * based on theoretical maximum wire speed and thresholds were set based
  1930. * on testing data as well as attempting to minimize response time
  1931. * while increasing bulk throughput.
  1932. * this functionality is controlled by the InterruptThrottleRate module
  1933. * parameter (see ixgbe_param.c)
  1934. **/
  1935. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  1936. struct ixgbe_ring_container *ring_container)
  1937. {
  1938. int bytes = ring_container->total_bytes;
  1939. int packets = ring_container->total_packets;
  1940. u32 timepassed_us;
  1941. u64 bytes_perint;
  1942. u8 itr_setting = ring_container->itr;
  1943. if (packets == 0)
  1944. return;
  1945. /* simple throttlerate management
  1946. * 0-10MB/s lowest (100000 ints/s)
  1947. * 10-20MB/s low (20000 ints/s)
  1948. * 20-1249MB/s bulk (8000 ints/s)
  1949. */
  1950. /* what was last interrupt timeslice? */
  1951. timepassed_us = q_vector->itr >> 2;
  1952. if (timepassed_us == 0)
  1953. return;
  1954. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  1955. switch (itr_setting) {
  1956. case lowest_latency:
  1957. if (bytes_perint > 10)
  1958. itr_setting = low_latency;
  1959. break;
  1960. case low_latency:
  1961. if (bytes_perint > 20)
  1962. itr_setting = bulk_latency;
  1963. else if (bytes_perint <= 10)
  1964. itr_setting = lowest_latency;
  1965. break;
  1966. case bulk_latency:
  1967. if (bytes_perint <= 20)
  1968. itr_setting = low_latency;
  1969. break;
  1970. }
  1971. /* clear work counters since we have the values we need */
  1972. ring_container->total_bytes = 0;
  1973. ring_container->total_packets = 0;
  1974. /* write updated itr to ring container */
  1975. ring_container->itr = itr_setting;
  1976. }
  1977. /**
  1978. * ixgbe_write_eitr - write EITR register in hardware specific way
  1979. * @q_vector: structure containing interrupt and ring information
  1980. *
  1981. * This function is made to be called by ethtool and by the driver
  1982. * when it needs to update EITR registers at runtime. Hardware
  1983. * specific quirks/differences are taken care of here.
  1984. */
  1985. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  1986. {
  1987. struct ixgbe_adapter *adapter = q_vector->adapter;
  1988. struct ixgbe_hw *hw = &adapter->hw;
  1989. int v_idx = q_vector->v_idx;
  1990. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  1991. switch (adapter->hw.mac.type) {
  1992. case ixgbe_mac_82598EB:
  1993. /* must write high and low 16 bits to reset counter */
  1994. itr_reg |= (itr_reg << 16);
  1995. break;
  1996. case ixgbe_mac_82599EB:
  1997. case ixgbe_mac_X540:
  1998. case ixgbe_mac_X550:
  1999. case ixgbe_mac_X550EM_x:
  2000. /*
  2001. * set the WDIS bit to not clear the timer bits and cause an
  2002. * immediate assertion of the interrupt
  2003. */
  2004. itr_reg |= IXGBE_EITR_CNT_WDIS;
  2005. break;
  2006. default:
  2007. break;
  2008. }
  2009. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  2010. }
  2011. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  2012. {
  2013. u32 new_itr = q_vector->itr;
  2014. u8 current_itr;
  2015. ixgbe_update_itr(q_vector, &q_vector->tx);
  2016. ixgbe_update_itr(q_vector, &q_vector->rx);
  2017. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  2018. switch (current_itr) {
  2019. /* counts and packets in update_itr are dependent on these numbers */
  2020. case lowest_latency:
  2021. new_itr = IXGBE_100K_ITR;
  2022. break;
  2023. case low_latency:
  2024. new_itr = IXGBE_20K_ITR;
  2025. break;
  2026. case bulk_latency:
  2027. new_itr = IXGBE_8K_ITR;
  2028. break;
  2029. default:
  2030. break;
  2031. }
  2032. if (new_itr != q_vector->itr) {
  2033. /* do an exponential smoothing */
  2034. new_itr = (10 * new_itr * q_vector->itr) /
  2035. ((9 * new_itr) + q_vector->itr);
  2036. /* save the algorithm value here */
  2037. q_vector->itr = new_itr;
  2038. ixgbe_write_eitr(q_vector);
  2039. }
  2040. }
  2041. /**
  2042. * ixgbe_check_overtemp_subtask - check for over temperature
  2043. * @adapter: pointer to adapter
  2044. **/
  2045. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  2046. {
  2047. struct ixgbe_hw *hw = &adapter->hw;
  2048. u32 eicr = adapter->interrupt_event;
  2049. if (test_bit(__IXGBE_DOWN, &adapter->state))
  2050. return;
  2051. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  2052. !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  2053. return;
  2054. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2055. switch (hw->device_id) {
  2056. case IXGBE_DEV_ID_82599_T3_LOM:
  2057. /*
  2058. * Since the warning interrupt is for both ports
  2059. * we don't have to check if:
  2060. * - This interrupt wasn't for our port.
  2061. * - We may have missed the interrupt so always have to
  2062. * check if we got a LSC
  2063. */
  2064. if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
  2065. !(eicr & IXGBE_EICR_LSC))
  2066. return;
  2067. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  2068. u32 speed;
  2069. bool link_up = false;
  2070. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2071. if (link_up)
  2072. return;
  2073. }
  2074. /* Check if this is not due to overtemp */
  2075. if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
  2076. return;
  2077. break;
  2078. default:
  2079. if (adapter->hw.mac.type >= ixgbe_mac_X540)
  2080. return;
  2081. if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
  2082. return;
  2083. break;
  2084. }
  2085. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2086. adapter->interrupt_event = 0;
  2087. }
  2088. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  2089. {
  2090. struct ixgbe_hw *hw = &adapter->hw;
  2091. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  2092. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2093. e_crit(probe, "Fan has stopped, replace the adapter\n");
  2094. /* write to clear the interrupt */
  2095. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2096. }
  2097. }
  2098. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2099. {
  2100. struct ixgbe_hw *hw = &adapter->hw;
  2101. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  2102. return;
  2103. switch (adapter->hw.mac.type) {
  2104. case ixgbe_mac_82599EB:
  2105. /*
  2106. * Need to check link state so complete overtemp check
  2107. * on service task
  2108. */
  2109. if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
  2110. (eicr & IXGBE_EICR_LSC)) &&
  2111. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  2112. adapter->interrupt_event = eicr;
  2113. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2114. ixgbe_service_event_schedule(adapter);
  2115. return;
  2116. }
  2117. return;
  2118. case ixgbe_mac_X540:
  2119. if (!(eicr & IXGBE_EICR_TS))
  2120. return;
  2121. break;
  2122. default:
  2123. return;
  2124. }
  2125. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2126. }
  2127. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2128. {
  2129. switch (hw->mac.type) {
  2130. case ixgbe_mac_82598EB:
  2131. if (hw->phy.type == ixgbe_phy_nl)
  2132. return true;
  2133. return false;
  2134. case ixgbe_mac_82599EB:
  2135. case ixgbe_mac_X550EM_x:
  2136. switch (hw->mac.ops.get_media_type(hw)) {
  2137. case ixgbe_media_type_fiber:
  2138. case ixgbe_media_type_fiber_qsfp:
  2139. return true;
  2140. default:
  2141. return false;
  2142. }
  2143. default:
  2144. return false;
  2145. }
  2146. }
  2147. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2148. {
  2149. struct ixgbe_hw *hw = &adapter->hw;
  2150. if (eicr & IXGBE_EICR_GPI_SDP2(hw)) {
  2151. /* Clear the interrupt */
  2152. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2(hw));
  2153. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2154. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  2155. ixgbe_service_event_schedule(adapter);
  2156. }
  2157. }
  2158. if (eicr & IXGBE_EICR_GPI_SDP1(hw)) {
  2159. /* Clear the interrupt */
  2160. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2161. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2162. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  2163. ixgbe_service_event_schedule(adapter);
  2164. }
  2165. }
  2166. }
  2167. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  2168. {
  2169. struct ixgbe_hw *hw = &adapter->hw;
  2170. adapter->lsc_int++;
  2171. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2172. adapter->link_check_timeout = jiffies;
  2173. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2174. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2175. IXGBE_WRITE_FLUSH(hw);
  2176. ixgbe_service_event_schedule(adapter);
  2177. }
  2178. }
  2179. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2180. u64 qmask)
  2181. {
  2182. u32 mask;
  2183. struct ixgbe_hw *hw = &adapter->hw;
  2184. switch (hw->mac.type) {
  2185. case ixgbe_mac_82598EB:
  2186. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2187. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2188. break;
  2189. case ixgbe_mac_82599EB:
  2190. case ixgbe_mac_X540:
  2191. case ixgbe_mac_X550:
  2192. case ixgbe_mac_X550EM_x:
  2193. mask = (qmask & 0xFFFFFFFF);
  2194. if (mask)
  2195. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2196. mask = (qmask >> 32);
  2197. if (mask)
  2198. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2199. break;
  2200. default:
  2201. break;
  2202. }
  2203. /* skip the flush */
  2204. }
  2205. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  2206. u64 qmask)
  2207. {
  2208. u32 mask;
  2209. struct ixgbe_hw *hw = &adapter->hw;
  2210. switch (hw->mac.type) {
  2211. case ixgbe_mac_82598EB:
  2212. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2213. IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
  2214. break;
  2215. case ixgbe_mac_82599EB:
  2216. case ixgbe_mac_X540:
  2217. case ixgbe_mac_X550:
  2218. case ixgbe_mac_X550EM_x:
  2219. mask = (qmask & 0xFFFFFFFF);
  2220. if (mask)
  2221. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
  2222. mask = (qmask >> 32);
  2223. if (mask)
  2224. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
  2225. break;
  2226. default:
  2227. break;
  2228. }
  2229. /* skip the flush */
  2230. }
  2231. /**
  2232. * ixgbe_irq_enable - Enable default interrupt generation settings
  2233. * @adapter: board private structure
  2234. **/
  2235. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2236. bool flush)
  2237. {
  2238. struct ixgbe_hw *hw = &adapter->hw;
  2239. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2240. /* don't reenable LSC while waiting for link */
  2241. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2242. mask &= ~IXGBE_EIMS_LSC;
  2243. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2244. switch (adapter->hw.mac.type) {
  2245. case ixgbe_mac_82599EB:
  2246. mask |= IXGBE_EIMS_GPI_SDP0(hw);
  2247. break;
  2248. case ixgbe_mac_X540:
  2249. case ixgbe_mac_X550:
  2250. case ixgbe_mac_X550EM_x:
  2251. mask |= IXGBE_EIMS_TS;
  2252. break;
  2253. default:
  2254. break;
  2255. }
  2256. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2257. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2258. switch (adapter->hw.mac.type) {
  2259. case ixgbe_mac_82599EB:
  2260. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2261. mask |= IXGBE_EIMS_GPI_SDP2(hw);
  2262. /* fall through */
  2263. case ixgbe_mac_X540:
  2264. case ixgbe_mac_X550:
  2265. case ixgbe_mac_X550EM_x:
  2266. if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
  2267. mask |= IXGBE_EICR_GPI_SDP0_X540;
  2268. mask |= IXGBE_EIMS_ECC;
  2269. mask |= IXGBE_EIMS_MAILBOX;
  2270. break;
  2271. default:
  2272. break;
  2273. }
  2274. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2275. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2276. mask |= IXGBE_EIMS_FLOW_DIR;
  2277. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2278. if (queues)
  2279. ixgbe_irq_enable_queues(adapter, ~0);
  2280. if (flush)
  2281. IXGBE_WRITE_FLUSH(&adapter->hw);
  2282. }
  2283. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2284. {
  2285. struct ixgbe_adapter *adapter = data;
  2286. struct ixgbe_hw *hw = &adapter->hw;
  2287. u32 eicr;
  2288. /*
  2289. * Workaround for Silicon errata. Use clear-by-write instead
  2290. * of clear-by-read. Reading with EICS will return the
  2291. * interrupt causes without clearing, which later be done
  2292. * with the write to EICR.
  2293. */
  2294. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2295. /* The lower 16bits of the EICR register are for the queue interrupts
  2296. * which should be masked here in order to not accidentally clear them if
  2297. * the bits are high when ixgbe_msix_other is called. There is a race
  2298. * condition otherwise which results in possible performance loss
  2299. * especially if the ixgbe_msix_other interrupt is triggering
  2300. * consistently (as it would when PPS is turned on for the X540 device)
  2301. */
  2302. eicr &= 0xFFFF0000;
  2303. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2304. if (eicr & IXGBE_EICR_LSC)
  2305. ixgbe_check_lsc(adapter);
  2306. if (eicr & IXGBE_EICR_MAILBOX)
  2307. ixgbe_msg_task(adapter);
  2308. switch (hw->mac.type) {
  2309. case ixgbe_mac_82599EB:
  2310. case ixgbe_mac_X540:
  2311. case ixgbe_mac_X550:
  2312. case ixgbe_mac_X550EM_x:
  2313. if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
  2314. (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
  2315. adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
  2316. ixgbe_service_event_schedule(adapter);
  2317. IXGBE_WRITE_REG(hw, IXGBE_EICR,
  2318. IXGBE_EICR_GPI_SDP0_X540);
  2319. }
  2320. if (eicr & IXGBE_EICR_ECC) {
  2321. e_info(link, "Received ECC Err, initiating reset\n");
  2322. adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
  2323. ixgbe_service_event_schedule(adapter);
  2324. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2325. }
  2326. /* Handle Flow Director Full threshold interrupt */
  2327. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2328. int reinit_count = 0;
  2329. int i;
  2330. for (i = 0; i < adapter->num_tx_queues; i++) {
  2331. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2332. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2333. &ring->state))
  2334. reinit_count++;
  2335. }
  2336. if (reinit_count) {
  2337. /* no more flow director interrupts until after init */
  2338. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2339. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2340. ixgbe_service_event_schedule(adapter);
  2341. }
  2342. }
  2343. ixgbe_check_sfp_event(adapter, eicr);
  2344. ixgbe_check_overtemp_event(adapter, eicr);
  2345. break;
  2346. default:
  2347. break;
  2348. }
  2349. ixgbe_check_fan_failure(adapter, eicr);
  2350. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2351. ixgbe_ptp_check_pps_event(adapter, eicr);
  2352. /* re-enable the original interrupt state, no lsc, no queues */
  2353. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2354. ixgbe_irq_enable(adapter, false, false);
  2355. return IRQ_HANDLED;
  2356. }
  2357. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2358. {
  2359. struct ixgbe_q_vector *q_vector = data;
  2360. /* EIAM disabled interrupts (on this vector) for us */
  2361. if (q_vector->rx.ring || q_vector->tx.ring)
  2362. napi_schedule(&q_vector->napi);
  2363. return IRQ_HANDLED;
  2364. }
  2365. /**
  2366. * ixgbe_poll - NAPI Rx polling callback
  2367. * @napi: structure for representing this polling device
  2368. * @budget: how many packets driver is allowed to clean
  2369. *
  2370. * This function is used for legacy and MSI, NAPI mode
  2371. **/
  2372. int ixgbe_poll(struct napi_struct *napi, int budget)
  2373. {
  2374. struct ixgbe_q_vector *q_vector =
  2375. container_of(napi, struct ixgbe_q_vector, napi);
  2376. struct ixgbe_adapter *adapter = q_vector->adapter;
  2377. struct ixgbe_ring *ring;
  2378. int per_ring_budget;
  2379. bool clean_complete = true;
  2380. #ifdef CONFIG_IXGBE_DCA
  2381. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2382. ixgbe_update_dca(q_vector);
  2383. #endif
  2384. ixgbe_for_each_ring(ring, q_vector->tx)
  2385. clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
  2386. if (!ixgbe_qv_lock_napi(q_vector))
  2387. return budget;
  2388. /* attempt to distribute budget to each queue fairly, but don't allow
  2389. * the budget to go below 1 because we'll exit polling */
  2390. if (q_vector->rx.count > 1)
  2391. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2392. else
  2393. per_ring_budget = budget;
  2394. ixgbe_for_each_ring(ring, q_vector->rx)
  2395. clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring,
  2396. per_ring_budget) < per_ring_budget);
  2397. ixgbe_qv_unlock_napi(q_vector);
  2398. /* If all work not completed, return budget and keep polling */
  2399. if (!clean_complete)
  2400. return budget;
  2401. /* all work done, exit the polling mode */
  2402. napi_complete(napi);
  2403. if (adapter->rx_itr_setting & 1)
  2404. ixgbe_set_itr(q_vector);
  2405. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2406. ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
  2407. return 0;
  2408. }
  2409. /**
  2410. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2411. * @adapter: board private structure
  2412. *
  2413. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2414. * interrupts from the kernel.
  2415. **/
  2416. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2417. {
  2418. struct net_device *netdev = adapter->netdev;
  2419. int vector, err;
  2420. int ri = 0, ti = 0;
  2421. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2422. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2423. struct msix_entry *entry = &adapter->msix_entries[vector];
  2424. if (q_vector->tx.ring && q_vector->rx.ring) {
  2425. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2426. "%s-%s-%d", netdev->name, "TxRx", ri++);
  2427. ti++;
  2428. } else if (q_vector->rx.ring) {
  2429. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2430. "%s-%s-%d", netdev->name, "rx", ri++);
  2431. } else if (q_vector->tx.ring) {
  2432. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2433. "%s-%s-%d", netdev->name, "tx", ti++);
  2434. } else {
  2435. /* skip this unused q_vector */
  2436. continue;
  2437. }
  2438. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2439. q_vector->name, q_vector);
  2440. if (err) {
  2441. e_err(probe, "request_irq failed for MSIX interrupt "
  2442. "Error: %d\n", err);
  2443. goto free_queue_irqs;
  2444. }
  2445. /* If Flow Director is enabled, set interrupt affinity */
  2446. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2447. /* assign the mask for this irq */
  2448. irq_set_affinity_hint(entry->vector,
  2449. &q_vector->affinity_mask);
  2450. }
  2451. }
  2452. err = request_irq(adapter->msix_entries[vector].vector,
  2453. ixgbe_msix_other, 0, netdev->name, adapter);
  2454. if (err) {
  2455. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2456. goto free_queue_irqs;
  2457. }
  2458. return 0;
  2459. free_queue_irqs:
  2460. while (vector) {
  2461. vector--;
  2462. irq_set_affinity_hint(adapter->msix_entries[vector].vector,
  2463. NULL);
  2464. free_irq(adapter->msix_entries[vector].vector,
  2465. adapter->q_vector[vector]);
  2466. }
  2467. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2468. pci_disable_msix(adapter->pdev);
  2469. kfree(adapter->msix_entries);
  2470. adapter->msix_entries = NULL;
  2471. return err;
  2472. }
  2473. /**
  2474. * ixgbe_intr - legacy mode Interrupt Handler
  2475. * @irq: interrupt number
  2476. * @data: pointer to a network interface device structure
  2477. **/
  2478. static irqreturn_t ixgbe_intr(int irq, void *data)
  2479. {
  2480. struct ixgbe_adapter *adapter = data;
  2481. struct ixgbe_hw *hw = &adapter->hw;
  2482. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2483. u32 eicr;
  2484. /*
  2485. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2486. * before the read of EICR.
  2487. */
  2488. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2489. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2490. * therefore no explicit interrupt disable is necessary */
  2491. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2492. if (!eicr) {
  2493. /*
  2494. * shared interrupt alert!
  2495. * make sure interrupts are enabled because the read will
  2496. * have disabled interrupts due to EIAM
  2497. * finish the workaround of silicon errata on 82598. Unmask
  2498. * the interrupt that we masked before the EICR read.
  2499. */
  2500. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2501. ixgbe_irq_enable(adapter, true, true);
  2502. return IRQ_NONE; /* Not our interrupt */
  2503. }
  2504. if (eicr & IXGBE_EICR_LSC)
  2505. ixgbe_check_lsc(adapter);
  2506. switch (hw->mac.type) {
  2507. case ixgbe_mac_82599EB:
  2508. ixgbe_check_sfp_event(adapter, eicr);
  2509. /* Fall through */
  2510. case ixgbe_mac_X540:
  2511. case ixgbe_mac_X550:
  2512. case ixgbe_mac_X550EM_x:
  2513. if (eicr & IXGBE_EICR_ECC) {
  2514. e_info(link, "Received ECC Err, initiating reset\n");
  2515. adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
  2516. ixgbe_service_event_schedule(adapter);
  2517. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2518. }
  2519. ixgbe_check_overtemp_event(adapter, eicr);
  2520. break;
  2521. default:
  2522. break;
  2523. }
  2524. ixgbe_check_fan_failure(adapter, eicr);
  2525. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2526. ixgbe_ptp_check_pps_event(adapter, eicr);
  2527. /* would disable interrupts here but EIAM disabled it */
  2528. napi_schedule(&q_vector->napi);
  2529. /*
  2530. * re-enable link(maybe) and non-queue interrupts, no flush.
  2531. * ixgbe_poll will re-enable the queue interrupts
  2532. */
  2533. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2534. ixgbe_irq_enable(adapter, false, false);
  2535. return IRQ_HANDLED;
  2536. }
  2537. /**
  2538. * ixgbe_request_irq - initialize interrupts
  2539. * @adapter: board private structure
  2540. *
  2541. * Attempts to configure interrupts using the best available
  2542. * capabilities of the hardware and kernel.
  2543. **/
  2544. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2545. {
  2546. struct net_device *netdev = adapter->netdev;
  2547. int err;
  2548. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2549. err = ixgbe_request_msix_irqs(adapter);
  2550. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2551. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2552. netdev->name, adapter);
  2553. else
  2554. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2555. netdev->name, adapter);
  2556. if (err)
  2557. e_err(probe, "request_irq failed, Error %d\n", err);
  2558. return err;
  2559. }
  2560. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2561. {
  2562. int vector;
  2563. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2564. free_irq(adapter->pdev->irq, adapter);
  2565. return;
  2566. }
  2567. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2568. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2569. struct msix_entry *entry = &adapter->msix_entries[vector];
  2570. /* free only the irqs that were actually requested */
  2571. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2572. continue;
  2573. /* clear the affinity_mask in the IRQ descriptor */
  2574. irq_set_affinity_hint(entry->vector, NULL);
  2575. free_irq(entry->vector, q_vector);
  2576. }
  2577. free_irq(adapter->msix_entries[vector++].vector, adapter);
  2578. }
  2579. /**
  2580. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2581. * @adapter: board private structure
  2582. **/
  2583. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2584. {
  2585. switch (adapter->hw.mac.type) {
  2586. case ixgbe_mac_82598EB:
  2587. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2588. break;
  2589. case ixgbe_mac_82599EB:
  2590. case ixgbe_mac_X540:
  2591. case ixgbe_mac_X550:
  2592. case ixgbe_mac_X550EM_x:
  2593. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2594. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2595. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2596. break;
  2597. default:
  2598. break;
  2599. }
  2600. IXGBE_WRITE_FLUSH(&adapter->hw);
  2601. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2602. int vector;
  2603. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  2604. synchronize_irq(adapter->msix_entries[vector].vector);
  2605. synchronize_irq(adapter->msix_entries[vector++].vector);
  2606. } else {
  2607. synchronize_irq(adapter->pdev->irq);
  2608. }
  2609. }
  2610. /**
  2611. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2612. *
  2613. **/
  2614. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2615. {
  2616. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2617. ixgbe_write_eitr(q_vector);
  2618. ixgbe_set_ivar(adapter, 0, 0, 0);
  2619. ixgbe_set_ivar(adapter, 1, 0, 0);
  2620. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2621. }
  2622. /**
  2623. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  2624. * @adapter: board private structure
  2625. * @ring: structure containing ring specific data
  2626. *
  2627. * Configure the Tx descriptor ring after a reset.
  2628. **/
  2629. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  2630. struct ixgbe_ring *ring)
  2631. {
  2632. struct ixgbe_hw *hw = &adapter->hw;
  2633. u64 tdba = ring->dma;
  2634. int wait_loop = 10;
  2635. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  2636. u8 reg_idx = ring->reg_idx;
  2637. /* disable queue to avoid issues while updating state */
  2638. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  2639. IXGBE_WRITE_FLUSH(hw);
  2640. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  2641. (tdba & DMA_BIT_MASK(32)));
  2642. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  2643. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  2644. ring->count * sizeof(union ixgbe_adv_tx_desc));
  2645. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  2646. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  2647. ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
  2648. /*
  2649. * set WTHRESH to encourage burst writeback, it should not be set
  2650. * higher than 1 when:
  2651. * - ITR is 0 as it could cause false TX hangs
  2652. * - ITR is set to > 100k int/sec and BQL is enabled
  2653. *
  2654. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  2655. * to or less than the number of on chip descriptors, which is
  2656. * currently 40.
  2657. */
  2658. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  2659. txdctl |= (1 << 16); /* WTHRESH = 1 */
  2660. else
  2661. txdctl |= (8 << 16); /* WTHRESH = 8 */
  2662. /*
  2663. * Setting PTHRESH to 32 both improves performance
  2664. * and avoids a TX hang with DFP enabled
  2665. */
  2666. txdctl |= (1 << 8) | /* HTHRESH = 1 */
  2667. 32; /* PTHRESH = 32 */
  2668. /* reinitialize flowdirector state */
  2669. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2670. ring->atr_sample_rate = adapter->atr_sample_rate;
  2671. ring->atr_count = 0;
  2672. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  2673. } else {
  2674. ring->atr_sample_rate = 0;
  2675. }
  2676. /* initialize XPS */
  2677. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  2678. struct ixgbe_q_vector *q_vector = ring->q_vector;
  2679. if (q_vector)
  2680. netif_set_xps_queue(ring->netdev,
  2681. &q_vector->affinity_mask,
  2682. ring->queue_index);
  2683. }
  2684. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  2685. /* enable queue */
  2686. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  2687. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2688. if (hw->mac.type == ixgbe_mac_82598EB &&
  2689. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2690. return;
  2691. /* poll to verify queue is enabled */
  2692. do {
  2693. usleep_range(1000, 2000);
  2694. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  2695. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  2696. if (!wait_loop)
  2697. e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
  2698. }
  2699. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  2700. {
  2701. struct ixgbe_hw *hw = &adapter->hw;
  2702. u32 rttdcs, mtqc;
  2703. u8 tcs = netdev_get_num_tc(adapter->netdev);
  2704. if (hw->mac.type == ixgbe_mac_82598EB)
  2705. return;
  2706. /* disable the arbiter while setting MTQC */
  2707. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  2708. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  2709. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2710. /* set transmit pool layout */
  2711. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2712. mtqc = IXGBE_MTQC_VT_ENA;
  2713. if (tcs > 4)
  2714. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2715. else if (tcs > 1)
  2716. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2717. else if (adapter->ring_feature[RING_F_RSS].indices == 4)
  2718. mtqc |= IXGBE_MTQC_32VF;
  2719. else
  2720. mtqc |= IXGBE_MTQC_64VF;
  2721. } else {
  2722. if (tcs > 4)
  2723. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2724. else if (tcs > 1)
  2725. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2726. else
  2727. mtqc = IXGBE_MTQC_64Q_1PB;
  2728. }
  2729. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  2730. /* Enable Security TX Buffer IFG for multiple pb */
  2731. if (tcs) {
  2732. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  2733. sectx |= IXGBE_SECTX_DCB;
  2734. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  2735. }
  2736. /* re-enable the arbiter */
  2737. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  2738. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2739. }
  2740. /**
  2741. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  2742. * @adapter: board private structure
  2743. *
  2744. * Configure the Tx unit of the MAC after a reset.
  2745. **/
  2746. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  2747. {
  2748. struct ixgbe_hw *hw = &adapter->hw;
  2749. u32 dmatxctl;
  2750. u32 i;
  2751. ixgbe_setup_mtqc(adapter);
  2752. if (hw->mac.type != ixgbe_mac_82598EB) {
  2753. /* DMATXCTL.EN must be before Tx queues are enabled */
  2754. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2755. dmatxctl |= IXGBE_DMATXCTL_TE;
  2756. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2757. }
  2758. /* Setup the HW Tx Head and Tail descriptor pointers */
  2759. for (i = 0; i < adapter->num_tx_queues; i++)
  2760. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2761. }
  2762. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  2763. struct ixgbe_ring *ring)
  2764. {
  2765. struct ixgbe_hw *hw = &adapter->hw;
  2766. u8 reg_idx = ring->reg_idx;
  2767. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2768. srrctl |= IXGBE_SRRCTL_DROP_EN;
  2769. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2770. }
  2771. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  2772. struct ixgbe_ring *ring)
  2773. {
  2774. struct ixgbe_hw *hw = &adapter->hw;
  2775. u8 reg_idx = ring->reg_idx;
  2776. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2777. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  2778. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2779. }
  2780. #ifdef CONFIG_IXGBE_DCB
  2781. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2782. #else
  2783. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2784. #endif
  2785. {
  2786. int i;
  2787. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  2788. if (adapter->ixgbe_ieee_pfc)
  2789. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  2790. /*
  2791. * We should set the drop enable bit if:
  2792. * SR-IOV is enabled
  2793. * or
  2794. * Number of Rx queues > 1 and flow control is disabled
  2795. *
  2796. * This allows us to avoid head of line blocking for security
  2797. * and performance reasons.
  2798. */
  2799. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  2800. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  2801. for (i = 0; i < adapter->num_rx_queues; i++)
  2802. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  2803. } else {
  2804. for (i = 0; i < adapter->num_rx_queues; i++)
  2805. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  2806. }
  2807. }
  2808. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  2809. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  2810. struct ixgbe_ring *rx_ring)
  2811. {
  2812. struct ixgbe_hw *hw = &adapter->hw;
  2813. u32 srrctl;
  2814. u8 reg_idx = rx_ring->reg_idx;
  2815. if (hw->mac.type == ixgbe_mac_82598EB) {
  2816. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  2817. /*
  2818. * if VMDq is not active we must program one srrctl register
  2819. * per RSS queue since we have enabled RDRXCTL.MVMEN
  2820. */
  2821. reg_idx &= mask;
  2822. }
  2823. /* configure header buffer length, needed for RSC */
  2824. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2825. /* configure the packet buffer length */
  2826. srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2827. /* configure descriptor type */
  2828. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2829. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2830. }
  2831. /**
  2832. * Return a number of entries in the RSS indirection table
  2833. *
  2834. * @adapter: device handle
  2835. *
  2836. * - 82598/82599/X540: 128
  2837. * - X550(non-SRIOV mode): 512
  2838. * - X550(SRIOV mode): 64
  2839. */
  2840. u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
  2841. {
  2842. if (adapter->hw.mac.type < ixgbe_mac_X550)
  2843. return 128;
  2844. else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  2845. return 64;
  2846. else
  2847. return 512;
  2848. }
  2849. /**
  2850. * Write the RETA table to HW
  2851. *
  2852. * @adapter: device handle
  2853. *
  2854. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  2855. */
  2856. void ixgbe_store_reta(struct ixgbe_adapter *adapter)
  2857. {
  2858. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  2859. struct ixgbe_hw *hw = &adapter->hw;
  2860. u32 reta = 0;
  2861. u32 indices_multi;
  2862. u8 *indir_tbl = adapter->rss_indir_tbl;
  2863. /* Fill out the redirection table as follows:
  2864. * - 82598: 8 bit wide entries containing pair of 4 bit RSS
  2865. * indices.
  2866. * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
  2867. * - X550: 8 bit wide entries containing 6 bit RSS index
  2868. */
  2869. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  2870. indices_multi = 0x11;
  2871. else
  2872. indices_multi = 0x1;
  2873. /* Write redirection table to HW */
  2874. for (i = 0; i < reta_entries; i++) {
  2875. reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
  2876. if ((i & 3) == 3) {
  2877. if (i < 128)
  2878. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  2879. else
  2880. IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
  2881. reta);
  2882. reta = 0;
  2883. }
  2884. }
  2885. }
  2886. /**
  2887. * Write the RETA table to HW (for x550 devices in SRIOV mode)
  2888. *
  2889. * @adapter: device handle
  2890. *
  2891. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  2892. */
  2893. static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
  2894. {
  2895. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  2896. struct ixgbe_hw *hw = &adapter->hw;
  2897. u32 vfreta = 0;
  2898. unsigned int pf_pool = adapter->num_vfs;
  2899. /* Write redirection table to HW */
  2900. for (i = 0; i < reta_entries; i++) {
  2901. vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
  2902. if ((i & 3) == 3) {
  2903. IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
  2904. vfreta);
  2905. vfreta = 0;
  2906. }
  2907. }
  2908. }
  2909. static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
  2910. {
  2911. struct ixgbe_hw *hw = &adapter->hw;
  2912. u32 i, j;
  2913. u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  2914. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  2915. /* Program table for at least 2 queues w/ SR-IOV so that VFs can
  2916. * make full use of any rings they may have. We will use the
  2917. * PSRTYPE register to control how many rings we use within the PF.
  2918. */
  2919. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
  2920. rss_i = 2;
  2921. /* Fill out hash function seeds */
  2922. for (i = 0; i < 10; i++)
  2923. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
  2924. /* Fill out redirection table */
  2925. memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
  2926. for (i = 0, j = 0; i < reta_entries; i++, j++) {
  2927. if (j == rss_i)
  2928. j = 0;
  2929. adapter->rss_indir_tbl[i] = j;
  2930. }
  2931. ixgbe_store_reta(adapter);
  2932. }
  2933. static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
  2934. {
  2935. struct ixgbe_hw *hw = &adapter->hw;
  2936. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  2937. unsigned int pf_pool = adapter->num_vfs;
  2938. int i, j;
  2939. /* Fill out hash function seeds */
  2940. for (i = 0; i < 10; i++)
  2941. IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
  2942. adapter->rss_key[i]);
  2943. /* Fill out the redirection table */
  2944. for (i = 0, j = 0; i < 64; i++, j++) {
  2945. if (j == rss_i)
  2946. j = 0;
  2947. adapter->rss_indir_tbl[i] = j;
  2948. }
  2949. ixgbe_store_vfreta(adapter);
  2950. }
  2951. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  2952. {
  2953. struct ixgbe_hw *hw = &adapter->hw;
  2954. u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
  2955. u32 rxcsum;
  2956. /* Disable indicating checksum in descriptor, enables RSS hash */
  2957. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  2958. rxcsum |= IXGBE_RXCSUM_PCSD;
  2959. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  2960. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2961. if (adapter->ring_feature[RING_F_RSS].mask)
  2962. mrqc = IXGBE_MRQC_RSSEN;
  2963. } else {
  2964. u8 tcs = netdev_get_num_tc(adapter->netdev);
  2965. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2966. if (tcs > 4)
  2967. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  2968. else if (tcs > 1)
  2969. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  2970. else if (adapter->ring_feature[RING_F_RSS].indices == 4)
  2971. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  2972. else
  2973. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  2974. } else {
  2975. if (tcs > 4)
  2976. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  2977. else if (tcs > 1)
  2978. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  2979. else
  2980. mrqc = IXGBE_MRQC_RSSEN;
  2981. }
  2982. }
  2983. /* Perform hash on these packet types */
  2984. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  2985. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  2986. IXGBE_MRQC_RSS_FIELD_IPV6 |
  2987. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  2988. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  2989. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  2990. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  2991. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  2992. netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
  2993. if ((hw->mac.type >= ixgbe_mac_X550) &&
  2994. (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  2995. unsigned int pf_pool = adapter->num_vfs;
  2996. /* Enable VF RSS mode */
  2997. mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
  2998. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  2999. /* Setup RSS through the VF registers */
  3000. ixgbe_setup_vfreta(adapter);
  3001. vfmrqc = IXGBE_MRQC_RSSEN;
  3002. vfmrqc |= rss_field;
  3003. IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
  3004. } else {
  3005. ixgbe_setup_reta(adapter);
  3006. mrqc |= rss_field;
  3007. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3008. }
  3009. }
  3010. /**
  3011. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  3012. * @adapter: address of board private structure
  3013. * @index: index of ring to set
  3014. **/
  3015. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  3016. struct ixgbe_ring *ring)
  3017. {
  3018. struct ixgbe_hw *hw = &adapter->hw;
  3019. u32 rscctrl;
  3020. u8 reg_idx = ring->reg_idx;
  3021. if (!ring_is_rsc_enabled(ring))
  3022. return;
  3023. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  3024. rscctrl |= IXGBE_RSCCTL_RSCEN;
  3025. /*
  3026. * we must limit the number of descriptors so that the
  3027. * total size of max desc * buf_len is not greater
  3028. * than 65536
  3029. */
  3030. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  3031. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  3032. }
  3033. #define IXGBE_MAX_RX_DESC_POLL 10
  3034. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  3035. struct ixgbe_ring *ring)
  3036. {
  3037. struct ixgbe_hw *hw = &adapter->hw;
  3038. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3039. u32 rxdctl;
  3040. u8 reg_idx = ring->reg_idx;
  3041. if (ixgbe_removed(hw->hw_addr))
  3042. return;
  3043. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3044. if (hw->mac.type == ixgbe_mac_82598EB &&
  3045. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3046. return;
  3047. do {
  3048. usleep_range(1000, 2000);
  3049. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3050. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  3051. if (!wait_loop) {
  3052. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  3053. "the polling period\n", reg_idx);
  3054. }
  3055. }
  3056. void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
  3057. struct ixgbe_ring *ring)
  3058. {
  3059. struct ixgbe_hw *hw = &adapter->hw;
  3060. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3061. u32 rxdctl;
  3062. u8 reg_idx = ring->reg_idx;
  3063. if (ixgbe_removed(hw->hw_addr))
  3064. return;
  3065. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3066. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  3067. /* write value back with RXDCTL.ENABLE bit cleared */
  3068. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3069. if (hw->mac.type == ixgbe_mac_82598EB &&
  3070. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3071. return;
  3072. /* the hardware may take up to 100us to really disable the rx queue */
  3073. do {
  3074. udelay(10);
  3075. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3076. } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
  3077. if (!wait_loop) {
  3078. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
  3079. "the polling period\n", reg_idx);
  3080. }
  3081. }
  3082. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  3083. struct ixgbe_ring *ring)
  3084. {
  3085. struct ixgbe_hw *hw = &adapter->hw;
  3086. u64 rdba = ring->dma;
  3087. u32 rxdctl;
  3088. u8 reg_idx = ring->reg_idx;
  3089. /* disable queue to avoid issues while updating state */
  3090. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3091. ixgbe_disable_rx_queue(adapter, ring);
  3092. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  3093. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  3094. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  3095. ring->count * sizeof(union ixgbe_adv_rx_desc));
  3096. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  3097. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  3098. ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
  3099. ixgbe_configure_srrctl(adapter, ring);
  3100. ixgbe_configure_rscctl(adapter, ring);
  3101. if (hw->mac.type == ixgbe_mac_82598EB) {
  3102. /*
  3103. * enable cache line friendly hardware writes:
  3104. * PTHRESH=32 descriptors (half the internal cache),
  3105. * this also removes ugly rx_no_buffer_count increment
  3106. * HTHRESH=4 descriptors (to minimize latency on fetch)
  3107. * WTHRESH=8 burst writeback up to two cache lines
  3108. */
  3109. rxdctl &= ~0x3FFFFF;
  3110. rxdctl |= 0x080420;
  3111. }
  3112. /* enable receive descriptor ring */
  3113. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3114. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3115. ixgbe_rx_desc_queue_enable(adapter, ring);
  3116. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  3117. }
  3118. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  3119. {
  3120. struct ixgbe_hw *hw = &adapter->hw;
  3121. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3122. u16 pool;
  3123. /* PSRTYPE must be initialized in non 82598 adapters */
  3124. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3125. IXGBE_PSRTYPE_UDPHDR |
  3126. IXGBE_PSRTYPE_IPV4HDR |
  3127. IXGBE_PSRTYPE_L2HDR |
  3128. IXGBE_PSRTYPE_IPV6HDR;
  3129. if (hw->mac.type == ixgbe_mac_82598EB)
  3130. return;
  3131. if (rss_i > 3)
  3132. psrtype |= 2 << 29;
  3133. else if (rss_i > 1)
  3134. psrtype |= 1 << 29;
  3135. for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
  3136. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3137. }
  3138. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  3139. {
  3140. struct ixgbe_hw *hw = &adapter->hw;
  3141. u32 reg_offset, vf_shift;
  3142. u32 gcr_ext, vmdctl;
  3143. int i;
  3144. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  3145. return;
  3146. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  3147. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  3148. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  3149. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  3150. vmdctl |= IXGBE_VT_CTL_REPLEN;
  3151. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  3152. vf_shift = VMDQ_P(0) % 32;
  3153. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  3154. /* Enable only the PF's pool for Tx/Rx */
  3155. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
  3156. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  3157. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
  3158. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  3159. if (adapter->bridge_mode == BRIDGE_MODE_VEB)
  3160. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  3161. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  3162. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  3163. /*
  3164. * Set up VF register offsets for selected VT Mode,
  3165. * i.e. 32 or 64 VFs for SR-IOV
  3166. */
  3167. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3168. case IXGBE_82599_VMDQ_8Q_MASK:
  3169. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  3170. break;
  3171. case IXGBE_82599_VMDQ_4Q_MASK:
  3172. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  3173. break;
  3174. default:
  3175. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  3176. break;
  3177. }
  3178. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3179. /* Enable MAC Anti-Spoofing */
  3180. hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
  3181. adapter->num_vfs);
  3182. /* Ensure LLDP is set for Ethertype Antispoofing if we will be
  3183. * calling set_ethertype_anti_spoofing for each VF in loop below
  3184. */
  3185. if (hw->mac.ops.set_ethertype_anti_spoofing)
  3186. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_LLDP),
  3187. (IXGBE_ETQF_FILTER_EN | /* enable filter */
  3188. IXGBE_ETQF_TX_ANTISPOOF | /* tx antispoof */
  3189. IXGBE_ETH_P_LLDP)); /* LLDP eth type */
  3190. /* For VFs that have spoof checking turned off */
  3191. for (i = 0; i < adapter->num_vfs; i++) {
  3192. if (!adapter->vfinfo[i].spoofchk_enabled)
  3193. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
  3194. /* enable ethertype anti spoofing if hw supports it */
  3195. if (hw->mac.ops.set_ethertype_anti_spoofing)
  3196. hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
  3197. /* Enable/Disable RSS query feature */
  3198. ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
  3199. adapter->vfinfo[i].rss_query_enabled);
  3200. }
  3201. }
  3202. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  3203. {
  3204. struct ixgbe_hw *hw = &adapter->hw;
  3205. struct net_device *netdev = adapter->netdev;
  3206. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3207. struct ixgbe_ring *rx_ring;
  3208. int i;
  3209. u32 mhadd, hlreg0;
  3210. #ifdef IXGBE_FCOE
  3211. /* adjust max frame to be able to do baby jumbo for FCoE */
  3212. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  3213. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  3214. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3215. #endif /* IXGBE_FCOE */
  3216. /* adjust max frame to be at least the size of a standard frame */
  3217. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  3218. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  3219. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  3220. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  3221. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  3222. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  3223. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  3224. }
  3225. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3226. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  3227. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  3228. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3229. /*
  3230. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3231. * the Base and Length of the Rx Descriptor Ring
  3232. */
  3233. for (i = 0; i < adapter->num_rx_queues; i++) {
  3234. rx_ring = adapter->rx_ring[i];
  3235. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3236. set_ring_rsc_enabled(rx_ring);
  3237. else
  3238. clear_ring_rsc_enabled(rx_ring);
  3239. }
  3240. }
  3241. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  3242. {
  3243. struct ixgbe_hw *hw = &adapter->hw;
  3244. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  3245. switch (hw->mac.type) {
  3246. case ixgbe_mac_X550:
  3247. case ixgbe_mac_X550EM_x:
  3248. case ixgbe_mac_82598EB:
  3249. /*
  3250. * For VMDq support of different descriptor types or
  3251. * buffer sizes through the use of multiple SRRCTL
  3252. * registers, RDRXCTL.MVMEN must be set to 1
  3253. *
  3254. * also, the manual doesn't mention it clearly but DCA hints
  3255. * will only use queue 0's tags unless this bit is set. Side
  3256. * effects of setting this bit are only that SRRCTL must be
  3257. * fully programmed [0..15]
  3258. */
  3259. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  3260. break;
  3261. case ixgbe_mac_82599EB:
  3262. case ixgbe_mac_X540:
  3263. /* Disable RSC for ACK packets */
  3264. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  3265. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  3266. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  3267. /* hardware requires some bits to be set by default */
  3268. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  3269. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  3270. break;
  3271. default:
  3272. /* We should do nothing since we don't know this hardware */
  3273. return;
  3274. }
  3275. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  3276. }
  3277. /**
  3278. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  3279. * @adapter: board private structure
  3280. *
  3281. * Configure the Rx unit of the MAC after a reset.
  3282. **/
  3283. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  3284. {
  3285. struct ixgbe_hw *hw = &adapter->hw;
  3286. int i;
  3287. u32 rxctrl, rfctl;
  3288. /* disable receives while setting up the descriptors */
  3289. hw->mac.ops.disable_rx(hw);
  3290. ixgbe_setup_psrtype(adapter);
  3291. ixgbe_setup_rdrxctl(adapter);
  3292. /* RSC Setup */
  3293. rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  3294. rfctl &= ~IXGBE_RFCTL_RSC_DIS;
  3295. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  3296. rfctl |= IXGBE_RFCTL_RSC_DIS;
  3297. IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
  3298. /* Program registers for the distribution of queues */
  3299. ixgbe_setup_mrqc(adapter);
  3300. /* set_rx_buffer_len must be called before ring initialization */
  3301. ixgbe_set_rx_buffer_len(adapter);
  3302. /*
  3303. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3304. * the Base and Length of the Rx Descriptor Ring
  3305. */
  3306. for (i = 0; i < adapter->num_rx_queues; i++)
  3307. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  3308. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3309. /* disable drop enable for 82598 parts */
  3310. if (hw->mac.type == ixgbe_mac_82598EB)
  3311. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  3312. /* enable all receives */
  3313. rxctrl |= IXGBE_RXCTRL_RXEN;
  3314. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  3315. }
  3316. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  3317. __be16 proto, u16 vid)
  3318. {
  3319. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3320. struct ixgbe_hw *hw = &adapter->hw;
  3321. /* add VID to filter table */
  3322. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
  3323. set_bit(vid, adapter->active_vlans);
  3324. return 0;
  3325. }
  3326. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  3327. __be16 proto, u16 vid)
  3328. {
  3329. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3330. struct ixgbe_hw *hw = &adapter->hw;
  3331. /* remove VID from filter table */
  3332. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
  3333. clear_bit(vid, adapter->active_vlans);
  3334. return 0;
  3335. }
  3336. /**
  3337. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3338. * @adapter: driver data
  3339. */
  3340. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3341. {
  3342. struct ixgbe_hw *hw = &adapter->hw;
  3343. u32 vlnctrl;
  3344. int i, j;
  3345. switch (hw->mac.type) {
  3346. case ixgbe_mac_82598EB:
  3347. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3348. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3349. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3350. break;
  3351. case ixgbe_mac_82599EB:
  3352. case ixgbe_mac_X540:
  3353. case ixgbe_mac_X550:
  3354. case ixgbe_mac_X550EM_x:
  3355. for (i = 0; i < adapter->num_rx_queues; i++) {
  3356. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3357. if (ring->l2_accel_priv)
  3358. continue;
  3359. j = ring->reg_idx;
  3360. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3361. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3362. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3363. }
  3364. break;
  3365. default:
  3366. break;
  3367. }
  3368. }
  3369. /**
  3370. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3371. * @adapter: driver data
  3372. */
  3373. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3374. {
  3375. struct ixgbe_hw *hw = &adapter->hw;
  3376. u32 vlnctrl;
  3377. int i, j;
  3378. switch (hw->mac.type) {
  3379. case ixgbe_mac_82598EB:
  3380. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3381. vlnctrl |= IXGBE_VLNCTRL_VME;
  3382. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3383. break;
  3384. case ixgbe_mac_82599EB:
  3385. case ixgbe_mac_X540:
  3386. case ixgbe_mac_X550:
  3387. case ixgbe_mac_X550EM_x:
  3388. for (i = 0; i < adapter->num_rx_queues; i++) {
  3389. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3390. if (ring->l2_accel_priv)
  3391. continue;
  3392. j = ring->reg_idx;
  3393. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3394. vlnctrl |= IXGBE_RXDCTL_VME;
  3395. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3396. }
  3397. break;
  3398. default:
  3399. break;
  3400. }
  3401. }
  3402. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  3403. {
  3404. u16 vid;
  3405. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  3406. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  3407. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  3408. }
  3409. /**
  3410. * ixgbe_write_mc_addr_list - write multicast addresses to MTA
  3411. * @netdev: network interface device structure
  3412. *
  3413. * Writes multicast address list to the MTA hash table.
  3414. * Returns: -ENOMEM on failure
  3415. * 0 on no addresses written
  3416. * X on writing X addresses to MTA
  3417. **/
  3418. static int ixgbe_write_mc_addr_list(struct net_device *netdev)
  3419. {
  3420. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3421. struct ixgbe_hw *hw = &adapter->hw;
  3422. if (!netif_running(netdev))
  3423. return 0;
  3424. if (hw->mac.ops.update_mc_addr_list)
  3425. hw->mac.ops.update_mc_addr_list(hw, netdev);
  3426. else
  3427. return -ENOMEM;
  3428. #ifdef CONFIG_PCI_IOV
  3429. ixgbe_restore_vf_multicasts(adapter);
  3430. #endif
  3431. return netdev_mc_count(netdev);
  3432. }
  3433. #ifdef CONFIG_PCI_IOV
  3434. void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
  3435. {
  3436. struct ixgbe_hw *hw = &adapter->hw;
  3437. int i;
  3438. for (i = 0; i < hw->mac.num_rar_entries; i++) {
  3439. if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
  3440. hw->mac.ops.set_rar(hw, i, adapter->mac_table[i].addr,
  3441. adapter->mac_table[i].queue,
  3442. IXGBE_RAH_AV);
  3443. else
  3444. hw->mac.ops.clear_rar(hw, i);
  3445. adapter->mac_table[i].state &= ~(IXGBE_MAC_STATE_MODIFIED);
  3446. }
  3447. }
  3448. #endif
  3449. static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
  3450. {
  3451. struct ixgbe_hw *hw = &adapter->hw;
  3452. int i;
  3453. for (i = 0; i < hw->mac.num_rar_entries; i++) {
  3454. if (adapter->mac_table[i].state & IXGBE_MAC_STATE_MODIFIED) {
  3455. if (adapter->mac_table[i].state &
  3456. IXGBE_MAC_STATE_IN_USE)
  3457. hw->mac.ops.set_rar(hw, i,
  3458. adapter->mac_table[i].addr,
  3459. adapter->mac_table[i].queue,
  3460. IXGBE_RAH_AV);
  3461. else
  3462. hw->mac.ops.clear_rar(hw, i);
  3463. adapter->mac_table[i].state &=
  3464. ~(IXGBE_MAC_STATE_MODIFIED);
  3465. }
  3466. }
  3467. }
  3468. static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
  3469. {
  3470. int i;
  3471. struct ixgbe_hw *hw = &adapter->hw;
  3472. for (i = 0; i < hw->mac.num_rar_entries; i++) {
  3473. adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
  3474. adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
  3475. eth_zero_addr(adapter->mac_table[i].addr);
  3476. adapter->mac_table[i].queue = 0;
  3477. }
  3478. ixgbe_sync_mac_table(adapter);
  3479. }
  3480. static int ixgbe_available_rars(struct ixgbe_adapter *adapter)
  3481. {
  3482. struct ixgbe_hw *hw = &adapter->hw;
  3483. int i, count = 0;
  3484. for (i = 0; i < hw->mac.num_rar_entries; i++) {
  3485. if (adapter->mac_table[i].state == 0)
  3486. count++;
  3487. }
  3488. return count;
  3489. }
  3490. /* this function destroys the first RAR entry */
  3491. static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter,
  3492. u8 *addr)
  3493. {
  3494. struct ixgbe_hw *hw = &adapter->hw;
  3495. memcpy(&adapter->mac_table[0].addr, addr, ETH_ALEN);
  3496. adapter->mac_table[0].queue = VMDQ_P(0);
  3497. adapter->mac_table[0].state = (IXGBE_MAC_STATE_DEFAULT |
  3498. IXGBE_MAC_STATE_IN_USE);
  3499. hw->mac.ops.set_rar(hw, 0, adapter->mac_table[0].addr,
  3500. adapter->mac_table[0].queue,
  3501. IXGBE_RAH_AV);
  3502. }
  3503. int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
  3504. {
  3505. struct ixgbe_hw *hw = &adapter->hw;
  3506. int i;
  3507. if (is_zero_ether_addr(addr))
  3508. return -EINVAL;
  3509. for (i = 0; i < hw->mac.num_rar_entries; i++) {
  3510. if (adapter->mac_table[i].state & IXGBE_MAC_STATE_IN_USE)
  3511. continue;
  3512. adapter->mac_table[i].state |= (IXGBE_MAC_STATE_MODIFIED |
  3513. IXGBE_MAC_STATE_IN_USE);
  3514. ether_addr_copy(adapter->mac_table[i].addr, addr);
  3515. adapter->mac_table[i].queue = queue;
  3516. ixgbe_sync_mac_table(adapter);
  3517. return i;
  3518. }
  3519. return -ENOMEM;
  3520. }
  3521. int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, u8 *addr, u16 queue)
  3522. {
  3523. /* search table for addr, if found, set to 0 and sync */
  3524. int i;
  3525. struct ixgbe_hw *hw = &adapter->hw;
  3526. if (is_zero_ether_addr(addr))
  3527. return -EINVAL;
  3528. for (i = 0; i < hw->mac.num_rar_entries; i++) {
  3529. if (ether_addr_equal(addr, adapter->mac_table[i].addr) &&
  3530. adapter->mac_table[i].queue == queue) {
  3531. adapter->mac_table[i].state |= IXGBE_MAC_STATE_MODIFIED;
  3532. adapter->mac_table[i].state &= ~IXGBE_MAC_STATE_IN_USE;
  3533. eth_zero_addr(adapter->mac_table[i].addr);
  3534. adapter->mac_table[i].queue = 0;
  3535. ixgbe_sync_mac_table(adapter);
  3536. return 0;
  3537. }
  3538. }
  3539. return -ENOMEM;
  3540. }
  3541. /**
  3542. * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
  3543. * @netdev: network interface device structure
  3544. *
  3545. * Writes unicast address list to the RAR table.
  3546. * Returns: -ENOMEM on failure/insufficient address space
  3547. * 0 on no addresses written
  3548. * X on writing X addresses to the RAR table
  3549. **/
  3550. static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
  3551. {
  3552. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3553. int count = 0;
  3554. /* return ENOMEM indicating insufficient memory for addresses */
  3555. if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter))
  3556. return -ENOMEM;
  3557. if (!netdev_uc_empty(netdev)) {
  3558. struct netdev_hw_addr *ha;
  3559. netdev_for_each_uc_addr(ha, netdev) {
  3560. ixgbe_del_mac_filter(adapter, ha->addr, vfn);
  3561. ixgbe_add_mac_filter(adapter, ha->addr, vfn);
  3562. count++;
  3563. }
  3564. }
  3565. return count;
  3566. }
  3567. /**
  3568. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  3569. * @netdev: network interface device structure
  3570. *
  3571. * The set_rx_method entry point is called whenever the unicast/multicast
  3572. * address list or the network interface flags are updated. This routine is
  3573. * responsible for configuring the hardware for proper unicast, multicast and
  3574. * promiscuous mode.
  3575. **/
  3576. void ixgbe_set_rx_mode(struct net_device *netdev)
  3577. {
  3578. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3579. struct ixgbe_hw *hw = &adapter->hw;
  3580. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  3581. u32 vlnctrl;
  3582. int count;
  3583. /* Check for Promiscuous and All Multicast modes */
  3584. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  3585. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3586. /* set all bits that we expect to always be set */
  3587. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  3588. fctrl |= IXGBE_FCTRL_BAM;
  3589. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  3590. fctrl |= IXGBE_FCTRL_PMCF;
  3591. /* clear the bits we are changing the status of */
  3592. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3593. vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
  3594. if (netdev->flags & IFF_PROMISC) {
  3595. hw->addr_ctrl.user_set_promisc = true;
  3596. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3597. vmolr |= IXGBE_VMOLR_MPE;
  3598. /* Only disable hardware filter vlans in promiscuous mode
  3599. * if SR-IOV and VMDQ are disabled - otherwise ensure
  3600. * that hardware VLAN filters remain enabled.
  3601. */
  3602. if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
  3603. IXGBE_FLAG_SRIOV_ENABLED))
  3604. vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
  3605. } else {
  3606. if (netdev->flags & IFF_ALLMULTI) {
  3607. fctrl |= IXGBE_FCTRL_MPE;
  3608. vmolr |= IXGBE_VMOLR_MPE;
  3609. }
  3610. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3611. hw->addr_ctrl.user_set_promisc = false;
  3612. }
  3613. /*
  3614. * Write addresses to available RAR registers, if there is not
  3615. * sufficient space to store all the addresses then enable
  3616. * unicast promiscuous mode
  3617. */
  3618. count = ixgbe_write_uc_addr_list(netdev, VMDQ_P(0));
  3619. if (count < 0) {
  3620. fctrl |= IXGBE_FCTRL_UPE;
  3621. vmolr |= IXGBE_VMOLR_ROPE;
  3622. }
  3623. /* Write addresses to the MTA, if the attempt fails
  3624. * then we should just turn on promiscuous mode so
  3625. * that we can at least receive multicast traffic
  3626. */
  3627. count = ixgbe_write_mc_addr_list(netdev);
  3628. if (count < 0) {
  3629. fctrl |= IXGBE_FCTRL_MPE;
  3630. vmolr |= IXGBE_VMOLR_MPE;
  3631. } else if (count) {
  3632. vmolr |= IXGBE_VMOLR_ROMPE;
  3633. }
  3634. if (hw->mac.type != ixgbe_mac_82598EB) {
  3635. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  3636. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  3637. IXGBE_VMOLR_ROPE);
  3638. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  3639. }
  3640. /* This is useful for sniffing bad packets. */
  3641. if (adapter->netdev->features & NETIF_F_RXALL) {
  3642. /* UPE and MPE will be handled by normal PROMISC logic
  3643. * in e1000e_set_rx_mode */
  3644. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  3645. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  3646. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  3647. fctrl &= ~(IXGBE_FCTRL_DPF);
  3648. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  3649. }
  3650. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3651. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  3652. if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  3653. ixgbe_vlan_strip_enable(adapter);
  3654. else
  3655. ixgbe_vlan_strip_disable(adapter);
  3656. }
  3657. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  3658. {
  3659. int q_idx;
  3660. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
  3661. ixgbe_qv_init_lock(adapter->q_vector[q_idx]);
  3662. napi_enable(&adapter->q_vector[q_idx]->napi);
  3663. }
  3664. }
  3665. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  3666. {
  3667. int q_idx;
  3668. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) {
  3669. napi_disable(&adapter->q_vector[q_idx]->napi);
  3670. while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) {
  3671. pr_info("QV %d locked\n", q_idx);
  3672. usleep_range(1000, 20000);
  3673. }
  3674. }
  3675. }
  3676. static void ixgbe_clear_vxlan_port(struct ixgbe_adapter *adapter)
  3677. {
  3678. switch (adapter->hw.mac.type) {
  3679. case ixgbe_mac_X550:
  3680. case ixgbe_mac_X550EM_x:
  3681. IXGBE_WRITE_REG(&adapter->hw, IXGBE_VXLANCTRL, 0);
  3682. #ifdef CONFIG_IXGBE_VXLAN
  3683. adapter->vxlan_port = 0;
  3684. #endif
  3685. break;
  3686. default:
  3687. break;
  3688. }
  3689. }
  3690. #ifdef CONFIG_IXGBE_DCB
  3691. /**
  3692. * ixgbe_configure_dcb - Configure DCB hardware
  3693. * @adapter: ixgbe adapter struct
  3694. *
  3695. * This is called by the driver on open to configure the DCB hardware.
  3696. * This is also called by the gennetlink interface when reconfiguring
  3697. * the DCB state.
  3698. */
  3699. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  3700. {
  3701. struct ixgbe_hw *hw = &adapter->hw;
  3702. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3703. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  3704. if (hw->mac.type == ixgbe_mac_82598EB)
  3705. netif_set_gso_max_size(adapter->netdev, 65536);
  3706. return;
  3707. }
  3708. if (hw->mac.type == ixgbe_mac_82598EB)
  3709. netif_set_gso_max_size(adapter->netdev, 32768);
  3710. #ifdef IXGBE_FCOE
  3711. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  3712. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  3713. #endif
  3714. /* reconfigure the hardware */
  3715. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  3716. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  3717. DCB_TX_CONFIG);
  3718. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  3719. DCB_RX_CONFIG);
  3720. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  3721. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  3722. ixgbe_dcb_hw_ets(&adapter->hw,
  3723. adapter->ixgbe_ieee_ets,
  3724. max_frame);
  3725. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  3726. adapter->ixgbe_ieee_pfc->pfc_en,
  3727. adapter->ixgbe_ieee_ets->prio_tc);
  3728. }
  3729. /* Enable RSS Hash per TC */
  3730. if (hw->mac.type != ixgbe_mac_82598EB) {
  3731. u32 msb = 0;
  3732. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  3733. while (rss_i) {
  3734. msb++;
  3735. rss_i >>= 1;
  3736. }
  3737. /* write msb to all 8 TCs in one write */
  3738. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  3739. }
  3740. }
  3741. #endif
  3742. /* Additional bittime to account for IXGBE framing */
  3743. #define IXGBE_ETH_FRAMING 20
  3744. /**
  3745. * ixgbe_hpbthresh - calculate high water mark for flow control
  3746. *
  3747. * @adapter: board private structure to calculate for
  3748. * @pb: packet buffer to calculate
  3749. */
  3750. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  3751. {
  3752. struct ixgbe_hw *hw = &adapter->hw;
  3753. struct net_device *dev = adapter->netdev;
  3754. int link, tc, kb, marker;
  3755. u32 dv_id, rx_pba;
  3756. /* Calculate max LAN frame size */
  3757. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  3758. #ifdef IXGBE_FCOE
  3759. /* FCoE traffic class uses FCOE jumbo frames */
  3760. if ((dev->features & NETIF_F_FCOE_MTU) &&
  3761. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  3762. (pb == ixgbe_fcoe_get_tc(adapter)))
  3763. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3764. #endif
  3765. /* Calculate delay value for device */
  3766. switch (hw->mac.type) {
  3767. case ixgbe_mac_X540:
  3768. case ixgbe_mac_X550:
  3769. case ixgbe_mac_X550EM_x:
  3770. dv_id = IXGBE_DV_X540(link, tc);
  3771. break;
  3772. default:
  3773. dv_id = IXGBE_DV(link, tc);
  3774. break;
  3775. }
  3776. /* Loopback switch introduces additional latency */
  3777. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3778. dv_id += IXGBE_B2BT(tc);
  3779. /* Delay value is calculated in bit times convert to KB */
  3780. kb = IXGBE_BT2KB(dv_id);
  3781. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  3782. marker = rx_pba - kb;
  3783. /* It is possible that the packet buffer is not large enough
  3784. * to provide required headroom. In this case throw an error
  3785. * to user and a do the best we can.
  3786. */
  3787. if (marker < 0) {
  3788. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  3789. "headroom to support flow control."
  3790. "Decrease MTU or number of traffic classes\n", pb);
  3791. marker = tc + 1;
  3792. }
  3793. return marker;
  3794. }
  3795. /**
  3796. * ixgbe_lpbthresh - calculate low water mark for for flow control
  3797. *
  3798. * @adapter: board private structure to calculate for
  3799. * @pb: packet buffer to calculate
  3800. */
  3801. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
  3802. {
  3803. struct ixgbe_hw *hw = &adapter->hw;
  3804. struct net_device *dev = adapter->netdev;
  3805. int tc;
  3806. u32 dv_id;
  3807. /* Calculate max LAN frame size */
  3808. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3809. #ifdef IXGBE_FCOE
  3810. /* FCoE traffic class uses FCOE jumbo frames */
  3811. if ((dev->features & NETIF_F_FCOE_MTU) &&
  3812. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  3813. (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
  3814. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3815. #endif
  3816. /* Calculate delay value for device */
  3817. switch (hw->mac.type) {
  3818. case ixgbe_mac_X540:
  3819. case ixgbe_mac_X550:
  3820. case ixgbe_mac_X550EM_x:
  3821. dv_id = IXGBE_LOW_DV_X540(tc);
  3822. break;
  3823. default:
  3824. dv_id = IXGBE_LOW_DV(tc);
  3825. break;
  3826. }
  3827. /* Delay value is calculated in bit times convert to KB */
  3828. return IXGBE_BT2KB(dv_id);
  3829. }
  3830. /*
  3831. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  3832. */
  3833. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  3834. {
  3835. struct ixgbe_hw *hw = &adapter->hw;
  3836. int num_tc = netdev_get_num_tc(adapter->netdev);
  3837. int i;
  3838. if (!num_tc)
  3839. num_tc = 1;
  3840. for (i = 0; i < num_tc; i++) {
  3841. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  3842. hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
  3843. /* Low water marks must not be larger than high water marks */
  3844. if (hw->fc.low_water[i] > hw->fc.high_water[i])
  3845. hw->fc.low_water[i] = 0;
  3846. }
  3847. for (; i < MAX_TRAFFIC_CLASS; i++)
  3848. hw->fc.high_water[i] = 0;
  3849. }
  3850. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  3851. {
  3852. struct ixgbe_hw *hw = &adapter->hw;
  3853. int hdrm;
  3854. u8 tc = netdev_get_num_tc(adapter->netdev);
  3855. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  3856. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  3857. hdrm = 32 << adapter->fdir_pballoc;
  3858. else
  3859. hdrm = 0;
  3860. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  3861. ixgbe_pbthresh_setup(adapter);
  3862. }
  3863. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  3864. {
  3865. struct ixgbe_hw *hw = &adapter->hw;
  3866. struct hlist_node *node2;
  3867. struct ixgbe_fdir_filter *filter;
  3868. spin_lock(&adapter->fdir_perfect_lock);
  3869. if (!hlist_empty(&adapter->fdir_filter_list))
  3870. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  3871. hlist_for_each_entry_safe(filter, node2,
  3872. &adapter->fdir_filter_list, fdir_node) {
  3873. ixgbe_fdir_write_perfect_filter_82599(hw,
  3874. &filter->filter,
  3875. filter->sw_idx,
  3876. (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
  3877. IXGBE_FDIR_DROP_QUEUE :
  3878. adapter->rx_ring[filter->action]->reg_idx);
  3879. }
  3880. spin_unlock(&adapter->fdir_perfect_lock);
  3881. }
  3882. static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
  3883. struct ixgbe_adapter *adapter)
  3884. {
  3885. struct ixgbe_hw *hw = &adapter->hw;
  3886. u32 vmolr;
  3887. /* No unicast promiscuous support for VMDQ devices. */
  3888. vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
  3889. vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
  3890. /* clear the affected bit */
  3891. vmolr &= ~IXGBE_VMOLR_MPE;
  3892. if (dev->flags & IFF_ALLMULTI) {
  3893. vmolr |= IXGBE_VMOLR_MPE;
  3894. } else {
  3895. vmolr |= IXGBE_VMOLR_ROMPE;
  3896. hw->mac.ops.update_mc_addr_list(hw, dev);
  3897. }
  3898. ixgbe_write_uc_addr_list(adapter->netdev, pool);
  3899. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
  3900. }
  3901. static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
  3902. {
  3903. struct ixgbe_adapter *adapter = vadapter->real_adapter;
  3904. int rss_i = adapter->num_rx_queues_per_pool;
  3905. struct ixgbe_hw *hw = &adapter->hw;
  3906. u16 pool = vadapter->pool;
  3907. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3908. IXGBE_PSRTYPE_UDPHDR |
  3909. IXGBE_PSRTYPE_IPV4HDR |
  3910. IXGBE_PSRTYPE_L2HDR |
  3911. IXGBE_PSRTYPE_IPV6HDR;
  3912. if (hw->mac.type == ixgbe_mac_82598EB)
  3913. return;
  3914. if (rss_i > 3)
  3915. psrtype |= 2 << 29;
  3916. else if (rss_i > 1)
  3917. psrtype |= 1 << 29;
  3918. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3919. }
  3920. /**
  3921. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  3922. * @rx_ring: ring to free buffers from
  3923. **/
  3924. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  3925. {
  3926. struct device *dev = rx_ring->dev;
  3927. unsigned long size;
  3928. u16 i;
  3929. /* ring already cleared, nothing to do */
  3930. if (!rx_ring->rx_buffer_info)
  3931. return;
  3932. /* Free all the Rx ring sk_buffs */
  3933. for (i = 0; i < rx_ring->count; i++) {
  3934. struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
  3935. if (rx_buffer->skb) {
  3936. struct sk_buff *skb = rx_buffer->skb;
  3937. if (IXGBE_CB(skb)->page_released)
  3938. dma_unmap_page(dev,
  3939. IXGBE_CB(skb)->dma,
  3940. ixgbe_rx_bufsz(rx_ring),
  3941. DMA_FROM_DEVICE);
  3942. dev_kfree_skb(skb);
  3943. rx_buffer->skb = NULL;
  3944. }
  3945. if (!rx_buffer->page)
  3946. continue;
  3947. dma_unmap_page(dev, rx_buffer->dma,
  3948. ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
  3949. __free_pages(rx_buffer->page, ixgbe_rx_pg_order(rx_ring));
  3950. rx_buffer->page = NULL;
  3951. }
  3952. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  3953. memset(rx_ring->rx_buffer_info, 0, size);
  3954. /* Zero out the descriptor ring */
  3955. memset(rx_ring->desc, 0, rx_ring->size);
  3956. rx_ring->next_to_alloc = 0;
  3957. rx_ring->next_to_clean = 0;
  3958. rx_ring->next_to_use = 0;
  3959. }
  3960. static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
  3961. struct ixgbe_ring *rx_ring)
  3962. {
  3963. struct ixgbe_adapter *adapter = vadapter->real_adapter;
  3964. int index = rx_ring->queue_index + vadapter->rx_base_queue;
  3965. /* shutdown specific queue receive and wait for dma to settle */
  3966. ixgbe_disable_rx_queue(adapter, rx_ring);
  3967. usleep_range(10000, 20000);
  3968. ixgbe_irq_disable_queues(adapter, ((u64)1 << index));
  3969. ixgbe_clean_rx_ring(rx_ring);
  3970. rx_ring->l2_accel_priv = NULL;
  3971. }
  3972. static int ixgbe_fwd_ring_down(struct net_device *vdev,
  3973. struct ixgbe_fwd_adapter *accel)
  3974. {
  3975. struct ixgbe_adapter *adapter = accel->real_adapter;
  3976. unsigned int rxbase = accel->rx_base_queue;
  3977. unsigned int txbase = accel->tx_base_queue;
  3978. int i;
  3979. netif_tx_stop_all_queues(vdev);
  3980. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  3981. ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
  3982. adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
  3983. }
  3984. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  3985. adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
  3986. adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
  3987. }
  3988. return 0;
  3989. }
  3990. static int ixgbe_fwd_ring_up(struct net_device *vdev,
  3991. struct ixgbe_fwd_adapter *accel)
  3992. {
  3993. struct ixgbe_adapter *adapter = accel->real_adapter;
  3994. unsigned int rxbase, txbase, queues;
  3995. int i, baseq, err = 0;
  3996. if (!test_bit(accel->pool, &adapter->fwd_bitmask))
  3997. return 0;
  3998. baseq = accel->pool * adapter->num_rx_queues_per_pool;
  3999. netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
  4000. accel->pool, adapter->num_rx_pools,
  4001. baseq, baseq + adapter->num_rx_queues_per_pool,
  4002. adapter->fwd_bitmask);
  4003. accel->netdev = vdev;
  4004. accel->rx_base_queue = rxbase = baseq;
  4005. accel->tx_base_queue = txbase = baseq;
  4006. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4007. ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
  4008. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4009. adapter->rx_ring[rxbase + i]->netdev = vdev;
  4010. adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
  4011. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
  4012. }
  4013. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4014. adapter->tx_ring[txbase + i]->netdev = vdev;
  4015. adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
  4016. }
  4017. queues = min_t(unsigned int,
  4018. adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
  4019. err = netif_set_real_num_tx_queues(vdev, queues);
  4020. if (err)
  4021. goto fwd_queue_err;
  4022. err = netif_set_real_num_rx_queues(vdev, queues);
  4023. if (err)
  4024. goto fwd_queue_err;
  4025. if (is_valid_ether_addr(vdev->dev_addr))
  4026. ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
  4027. ixgbe_fwd_psrtype(accel);
  4028. ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
  4029. return err;
  4030. fwd_queue_err:
  4031. ixgbe_fwd_ring_down(vdev, accel);
  4032. return err;
  4033. }
  4034. static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
  4035. {
  4036. struct net_device *upper;
  4037. struct list_head *iter;
  4038. int err;
  4039. netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
  4040. if (netif_is_macvlan(upper)) {
  4041. struct macvlan_dev *dfwd = netdev_priv(upper);
  4042. struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
  4043. if (dfwd->fwd_priv) {
  4044. err = ixgbe_fwd_ring_up(upper, vadapter);
  4045. if (err)
  4046. continue;
  4047. }
  4048. }
  4049. }
  4050. }
  4051. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  4052. {
  4053. struct ixgbe_hw *hw = &adapter->hw;
  4054. ixgbe_configure_pb(adapter);
  4055. #ifdef CONFIG_IXGBE_DCB
  4056. ixgbe_configure_dcb(adapter);
  4057. #endif
  4058. /*
  4059. * We must restore virtualization before VLANs or else
  4060. * the VLVF registers will not be populated
  4061. */
  4062. ixgbe_configure_virtualization(adapter);
  4063. ixgbe_set_rx_mode(adapter->netdev);
  4064. ixgbe_restore_vlan(adapter);
  4065. switch (hw->mac.type) {
  4066. case ixgbe_mac_82599EB:
  4067. case ixgbe_mac_X540:
  4068. hw->mac.ops.disable_rx_buff(hw);
  4069. break;
  4070. default:
  4071. break;
  4072. }
  4073. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4074. ixgbe_init_fdir_signature_82599(&adapter->hw,
  4075. adapter->fdir_pballoc);
  4076. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  4077. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  4078. adapter->fdir_pballoc);
  4079. ixgbe_fdir_filter_restore(adapter);
  4080. }
  4081. switch (hw->mac.type) {
  4082. case ixgbe_mac_82599EB:
  4083. case ixgbe_mac_X540:
  4084. hw->mac.ops.enable_rx_buff(hw);
  4085. break;
  4086. default:
  4087. break;
  4088. }
  4089. #ifdef IXGBE_FCOE
  4090. /* configure FCoE L2 filters, redirection table, and Rx control */
  4091. ixgbe_configure_fcoe(adapter);
  4092. #endif /* IXGBE_FCOE */
  4093. ixgbe_configure_tx(adapter);
  4094. ixgbe_configure_rx(adapter);
  4095. ixgbe_configure_dfwd(adapter);
  4096. }
  4097. /**
  4098. * ixgbe_sfp_link_config - set up SFP+ link
  4099. * @adapter: pointer to private adapter struct
  4100. **/
  4101. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  4102. {
  4103. /*
  4104. * We are assuming the worst case scenario here, and that
  4105. * is that an SFP was inserted/removed after the reset
  4106. * but before SFP detection was enabled. As such the best
  4107. * solution is to just start searching as soon as we start
  4108. */
  4109. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  4110. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4111. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4112. }
  4113. /**
  4114. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  4115. * @hw: pointer to private hardware struct
  4116. *
  4117. * Returns 0 on success, negative on failure
  4118. **/
  4119. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  4120. {
  4121. u32 speed;
  4122. bool autoneg, link_up = false;
  4123. int ret = IXGBE_ERR_LINK_SETUP;
  4124. if (hw->mac.ops.check_link)
  4125. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  4126. if (ret)
  4127. return ret;
  4128. speed = hw->phy.autoneg_advertised;
  4129. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  4130. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  4131. &autoneg);
  4132. if (ret)
  4133. return ret;
  4134. if (hw->mac.ops.setup_link)
  4135. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  4136. return ret;
  4137. }
  4138. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  4139. {
  4140. struct ixgbe_hw *hw = &adapter->hw;
  4141. u32 gpie = 0;
  4142. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4143. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  4144. IXGBE_GPIE_OCD;
  4145. gpie |= IXGBE_GPIE_EIAME;
  4146. /*
  4147. * use EIAM to auto-mask when MSI-X interrupt is asserted
  4148. * this saves a register write for every interrupt
  4149. */
  4150. switch (hw->mac.type) {
  4151. case ixgbe_mac_82598EB:
  4152. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4153. break;
  4154. case ixgbe_mac_82599EB:
  4155. case ixgbe_mac_X540:
  4156. case ixgbe_mac_X550:
  4157. case ixgbe_mac_X550EM_x:
  4158. default:
  4159. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  4160. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  4161. break;
  4162. }
  4163. } else {
  4164. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  4165. * specifically only auto mask tx and rx interrupts */
  4166. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4167. }
  4168. /* XXX: to interrupt immediately for EICS writes, enable this */
  4169. /* gpie |= IXGBE_GPIE_EIMEN; */
  4170. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  4171. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  4172. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  4173. case IXGBE_82599_VMDQ_8Q_MASK:
  4174. gpie |= IXGBE_GPIE_VTMODE_16;
  4175. break;
  4176. case IXGBE_82599_VMDQ_4Q_MASK:
  4177. gpie |= IXGBE_GPIE_VTMODE_32;
  4178. break;
  4179. default:
  4180. gpie |= IXGBE_GPIE_VTMODE_64;
  4181. break;
  4182. }
  4183. }
  4184. /* Enable Thermal over heat sensor interrupt */
  4185. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  4186. switch (adapter->hw.mac.type) {
  4187. case ixgbe_mac_82599EB:
  4188. gpie |= IXGBE_SDP0_GPIEN_8259X;
  4189. break;
  4190. case ixgbe_mac_X540:
  4191. gpie |= IXGBE_EIMS_TS;
  4192. break;
  4193. default:
  4194. break;
  4195. }
  4196. }
  4197. /* Enable fan failure interrupt */
  4198. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  4199. gpie |= IXGBE_SDP1_GPIEN(hw);
  4200. if (hw->mac.type == ixgbe_mac_82599EB) {
  4201. gpie |= IXGBE_SDP1_GPIEN_8259X;
  4202. gpie |= IXGBE_SDP2_GPIEN_8259X;
  4203. }
  4204. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  4205. }
  4206. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  4207. {
  4208. struct ixgbe_hw *hw = &adapter->hw;
  4209. int err;
  4210. u32 ctrl_ext;
  4211. ixgbe_get_hw_control(adapter);
  4212. ixgbe_setup_gpie(adapter);
  4213. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4214. ixgbe_configure_msix(adapter);
  4215. else
  4216. ixgbe_configure_msi_and_legacy(adapter);
  4217. /* enable the optics for 82599 SFP+ fiber */
  4218. if (hw->mac.ops.enable_tx_laser)
  4219. hw->mac.ops.enable_tx_laser(hw);
  4220. if (hw->phy.ops.set_phy_power)
  4221. hw->phy.ops.set_phy_power(hw, true);
  4222. smp_mb__before_atomic();
  4223. clear_bit(__IXGBE_DOWN, &adapter->state);
  4224. ixgbe_napi_enable_all(adapter);
  4225. if (ixgbe_is_sfp(hw)) {
  4226. ixgbe_sfp_link_config(adapter);
  4227. } else {
  4228. err = ixgbe_non_sfp_link_config(hw);
  4229. if (err)
  4230. e_err(probe, "link_config FAILED %d\n", err);
  4231. }
  4232. /* clear any pending interrupts, may auto mask */
  4233. IXGBE_READ_REG(hw, IXGBE_EICR);
  4234. ixgbe_irq_enable(adapter, true, true);
  4235. /*
  4236. * If this adapter has a fan, check to see if we had a failure
  4237. * before we enabled the interrupt.
  4238. */
  4239. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4240. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4241. if (esdp & IXGBE_ESDP_SDP1)
  4242. e_crit(drv, "Fan has stopped, replace the adapter\n");
  4243. }
  4244. /* bring the link up in the watchdog, this could race with our first
  4245. * link up interrupt but shouldn't be a problem */
  4246. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4247. adapter->link_check_timeout = jiffies;
  4248. mod_timer(&adapter->service_timer, jiffies);
  4249. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  4250. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  4251. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  4252. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  4253. }
  4254. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  4255. {
  4256. WARN_ON(in_interrupt());
  4257. /* put off any impending NetWatchDogTimeout */
  4258. adapter->netdev->trans_start = jiffies;
  4259. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  4260. usleep_range(1000, 2000);
  4261. ixgbe_down(adapter);
  4262. /*
  4263. * If SR-IOV enabled then wait a bit before bringing the adapter
  4264. * back up to give the VFs time to respond to the reset. The
  4265. * two second wait is based upon the watchdog timer cycle in
  4266. * the VF driver.
  4267. */
  4268. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4269. msleep(2000);
  4270. ixgbe_up(adapter);
  4271. clear_bit(__IXGBE_RESETTING, &adapter->state);
  4272. }
  4273. void ixgbe_up(struct ixgbe_adapter *adapter)
  4274. {
  4275. /* hardware has been reset, we need to reload some things */
  4276. ixgbe_configure(adapter);
  4277. ixgbe_up_complete(adapter);
  4278. }
  4279. void ixgbe_reset(struct ixgbe_adapter *adapter)
  4280. {
  4281. struct ixgbe_hw *hw = &adapter->hw;
  4282. struct net_device *netdev = adapter->netdev;
  4283. int err;
  4284. u8 old_addr[ETH_ALEN];
  4285. if (ixgbe_removed(hw->hw_addr))
  4286. return;
  4287. /* lock SFP init bit to prevent race conditions with the watchdog */
  4288. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4289. usleep_range(1000, 2000);
  4290. /* clear all SFP and link config related flags while holding SFP_INIT */
  4291. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  4292. IXGBE_FLAG2_SFP_NEEDS_RESET);
  4293. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  4294. err = hw->mac.ops.init_hw(hw);
  4295. switch (err) {
  4296. case 0:
  4297. case IXGBE_ERR_SFP_NOT_PRESENT:
  4298. case IXGBE_ERR_SFP_NOT_SUPPORTED:
  4299. break;
  4300. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  4301. e_dev_err("master disable timed out\n");
  4302. break;
  4303. case IXGBE_ERR_EEPROM_VERSION:
  4304. /* We are running on a pre-production device, log a warning */
  4305. e_dev_warn("This device is a pre-production adapter/LOM. "
  4306. "Please be aware there may be issues associated with "
  4307. "your hardware. If you are experiencing problems "
  4308. "please contact your Intel or hardware "
  4309. "representative who provided you with this "
  4310. "hardware.\n");
  4311. break;
  4312. default:
  4313. e_dev_err("Hardware Error: %d\n", err);
  4314. }
  4315. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4316. /* do not flush user set addresses */
  4317. memcpy(old_addr, &adapter->mac_table[0].addr, netdev->addr_len);
  4318. ixgbe_flush_sw_mac_table(adapter);
  4319. ixgbe_mac_set_default_filter(adapter, old_addr);
  4320. /* update SAN MAC vmdq pool selection */
  4321. if (hw->mac.san_mac_rar_index)
  4322. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  4323. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  4324. ixgbe_ptp_reset(adapter);
  4325. if (hw->phy.ops.set_phy_power) {
  4326. if (!netif_running(adapter->netdev) && !adapter->wol)
  4327. hw->phy.ops.set_phy_power(hw, false);
  4328. else
  4329. hw->phy.ops.set_phy_power(hw, true);
  4330. }
  4331. }
  4332. /**
  4333. * ixgbe_clean_tx_ring - Free Tx Buffers
  4334. * @tx_ring: ring to be cleaned
  4335. **/
  4336. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  4337. {
  4338. struct ixgbe_tx_buffer *tx_buffer_info;
  4339. unsigned long size;
  4340. u16 i;
  4341. /* ring already cleared, nothing to do */
  4342. if (!tx_ring->tx_buffer_info)
  4343. return;
  4344. /* Free all the Tx ring sk_buffs */
  4345. for (i = 0; i < tx_ring->count; i++) {
  4346. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4347. ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  4348. }
  4349. netdev_tx_reset_queue(txring_txq(tx_ring));
  4350. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  4351. memset(tx_ring->tx_buffer_info, 0, size);
  4352. /* Zero out the descriptor ring */
  4353. memset(tx_ring->desc, 0, tx_ring->size);
  4354. tx_ring->next_to_use = 0;
  4355. tx_ring->next_to_clean = 0;
  4356. }
  4357. /**
  4358. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  4359. * @adapter: board private structure
  4360. **/
  4361. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  4362. {
  4363. int i;
  4364. for (i = 0; i < adapter->num_rx_queues; i++)
  4365. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  4366. }
  4367. /**
  4368. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  4369. * @adapter: board private structure
  4370. **/
  4371. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  4372. {
  4373. int i;
  4374. for (i = 0; i < adapter->num_tx_queues; i++)
  4375. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  4376. }
  4377. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  4378. {
  4379. struct hlist_node *node2;
  4380. struct ixgbe_fdir_filter *filter;
  4381. spin_lock(&adapter->fdir_perfect_lock);
  4382. hlist_for_each_entry_safe(filter, node2,
  4383. &adapter->fdir_filter_list, fdir_node) {
  4384. hlist_del(&filter->fdir_node);
  4385. kfree(filter);
  4386. }
  4387. adapter->fdir_filter_count = 0;
  4388. spin_unlock(&adapter->fdir_perfect_lock);
  4389. }
  4390. void ixgbe_down(struct ixgbe_adapter *adapter)
  4391. {
  4392. struct net_device *netdev = adapter->netdev;
  4393. struct ixgbe_hw *hw = &adapter->hw;
  4394. struct net_device *upper;
  4395. struct list_head *iter;
  4396. int i;
  4397. /* signal that we are down to the interrupt handler */
  4398. if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
  4399. return; /* do nothing if already down */
  4400. /* disable receives */
  4401. hw->mac.ops.disable_rx(hw);
  4402. /* disable all enabled rx queues */
  4403. for (i = 0; i < adapter->num_rx_queues; i++)
  4404. /* this call also flushes the previous write */
  4405. ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
  4406. usleep_range(10000, 20000);
  4407. netif_tx_stop_all_queues(netdev);
  4408. /* call carrier off first to avoid false dev_watchdog timeouts */
  4409. netif_carrier_off(netdev);
  4410. netif_tx_disable(netdev);
  4411. /* disable any upper devices */
  4412. netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
  4413. if (netif_is_macvlan(upper)) {
  4414. struct macvlan_dev *vlan = netdev_priv(upper);
  4415. if (vlan->fwd_priv) {
  4416. netif_tx_stop_all_queues(upper);
  4417. netif_carrier_off(upper);
  4418. netif_tx_disable(upper);
  4419. }
  4420. }
  4421. }
  4422. ixgbe_irq_disable(adapter);
  4423. ixgbe_napi_disable_all(adapter);
  4424. adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
  4425. IXGBE_FLAG2_RESET_REQUESTED);
  4426. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4427. del_timer_sync(&adapter->service_timer);
  4428. if (adapter->num_vfs) {
  4429. /* Clear EITR Select mapping */
  4430. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  4431. /* Mark all the VFs as inactive */
  4432. for (i = 0 ; i < adapter->num_vfs; i++)
  4433. adapter->vfinfo[i].clear_to_send = false;
  4434. /* ping all the active vfs to let them know we are going down */
  4435. ixgbe_ping_all_vfs(adapter);
  4436. /* Disable all VFTE/VFRE TX/RX */
  4437. ixgbe_disable_tx_rx(adapter);
  4438. }
  4439. /* disable transmits in the hardware now that interrupts are off */
  4440. for (i = 0; i < adapter->num_tx_queues; i++) {
  4441. u8 reg_idx = adapter->tx_ring[i]->reg_idx;
  4442. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4443. }
  4444. /* Disable the Tx DMA engine on 82599 and later MAC */
  4445. switch (hw->mac.type) {
  4446. case ixgbe_mac_82599EB:
  4447. case ixgbe_mac_X540:
  4448. case ixgbe_mac_X550:
  4449. case ixgbe_mac_X550EM_x:
  4450. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  4451. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  4452. ~IXGBE_DMATXCTL_TE));
  4453. break;
  4454. default:
  4455. break;
  4456. }
  4457. if (!pci_channel_offline(adapter->pdev))
  4458. ixgbe_reset(adapter);
  4459. /* power down the optics for 82599 SFP+ fiber */
  4460. if (hw->mac.ops.disable_tx_laser)
  4461. hw->mac.ops.disable_tx_laser(hw);
  4462. ixgbe_clean_all_tx_rings(adapter);
  4463. ixgbe_clean_all_rx_rings(adapter);
  4464. #ifdef CONFIG_IXGBE_DCA
  4465. /* since we reset the hardware DCA settings were cleared */
  4466. ixgbe_setup_dca(adapter);
  4467. #endif
  4468. }
  4469. /**
  4470. * ixgbe_tx_timeout - Respond to a Tx Hang
  4471. * @netdev: network interface device structure
  4472. **/
  4473. static void ixgbe_tx_timeout(struct net_device *netdev)
  4474. {
  4475. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4476. /* Do the reset outside of interrupt context */
  4477. ixgbe_tx_timeout_reset(adapter);
  4478. }
  4479. /**
  4480. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  4481. * @adapter: board private structure to initialize
  4482. *
  4483. * ixgbe_sw_init initializes the Adapter private data structure.
  4484. * Fields are initialized based on PCI device information and
  4485. * OS network device settings (MTU size).
  4486. **/
  4487. static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
  4488. {
  4489. struct ixgbe_hw *hw = &adapter->hw;
  4490. struct pci_dev *pdev = adapter->pdev;
  4491. unsigned int rss, fdir;
  4492. u32 fwsm;
  4493. #ifdef CONFIG_IXGBE_DCB
  4494. int j;
  4495. struct tc_configuration *tc;
  4496. #endif
  4497. /* PCI config space info */
  4498. hw->vendor_id = pdev->vendor;
  4499. hw->device_id = pdev->device;
  4500. hw->revision_id = pdev->revision;
  4501. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  4502. hw->subsystem_device_id = pdev->subsystem_device;
  4503. /* Set common capability flags and settings */
  4504. rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
  4505. adapter->ring_feature[RING_F_RSS].limit = rss;
  4506. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  4507. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  4508. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  4509. adapter->atr_sample_rate = 20;
  4510. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  4511. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  4512. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  4513. #ifdef CONFIG_IXGBE_DCA
  4514. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  4515. #endif
  4516. #ifdef IXGBE_FCOE
  4517. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  4518. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  4519. #ifdef CONFIG_IXGBE_DCB
  4520. /* Default traffic class to use for FCoE */
  4521. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  4522. #endif /* CONFIG_IXGBE_DCB */
  4523. #endif /* IXGBE_FCOE */
  4524. adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
  4525. hw->mac.num_rar_entries,
  4526. GFP_ATOMIC);
  4527. /* Set MAC specific capability flags and exceptions */
  4528. switch (hw->mac.type) {
  4529. case ixgbe_mac_82598EB:
  4530. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  4531. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  4532. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  4533. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  4534. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  4535. adapter->ring_feature[RING_F_FDIR].limit = 0;
  4536. adapter->atr_sample_rate = 0;
  4537. adapter->fdir_pballoc = 0;
  4538. #ifdef IXGBE_FCOE
  4539. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  4540. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  4541. #ifdef CONFIG_IXGBE_DCB
  4542. adapter->fcoe.up = 0;
  4543. #endif /* IXGBE_DCB */
  4544. #endif /* IXGBE_FCOE */
  4545. break;
  4546. case ixgbe_mac_82599EB:
  4547. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  4548. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  4549. break;
  4550. case ixgbe_mac_X540:
  4551. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  4552. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  4553. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  4554. break;
  4555. case ixgbe_mac_X550EM_x:
  4556. case ixgbe_mac_X550:
  4557. #ifdef CONFIG_IXGBE_DCA
  4558. adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
  4559. #endif
  4560. #ifdef CONFIG_IXGBE_VXLAN
  4561. adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
  4562. #endif
  4563. break;
  4564. default:
  4565. break;
  4566. }
  4567. #ifdef IXGBE_FCOE
  4568. /* FCoE support exists, always init the FCoE lock */
  4569. spin_lock_init(&adapter->fcoe.lock);
  4570. #endif
  4571. /* n-tuple support exists, always init our spinlock */
  4572. spin_lock_init(&adapter->fdir_perfect_lock);
  4573. #ifdef CONFIG_IXGBE_DCB
  4574. switch (hw->mac.type) {
  4575. case ixgbe_mac_X540:
  4576. case ixgbe_mac_X550:
  4577. case ixgbe_mac_X550EM_x:
  4578. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  4579. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  4580. break;
  4581. default:
  4582. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  4583. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  4584. break;
  4585. }
  4586. /* Configure DCB traffic classes */
  4587. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  4588. tc = &adapter->dcb_cfg.tc_config[j];
  4589. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  4590. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  4591. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  4592. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  4593. tc->dcb_pfc = pfc_disabled;
  4594. }
  4595. /* Initialize default user to priority mapping, UPx->TC0 */
  4596. tc = &adapter->dcb_cfg.tc_config[0];
  4597. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  4598. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  4599. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  4600. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  4601. adapter->dcb_cfg.pfc_mode_enable = false;
  4602. adapter->dcb_set_bitmap = 0x00;
  4603. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  4604. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  4605. sizeof(adapter->temp_dcb_cfg));
  4606. #endif
  4607. /* default flow control settings */
  4608. hw->fc.requested_mode = ixgbe_fc_full;
  4609. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  4610. ixgbe_pbthresh_setup(adapter);
  4611. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  4612. hw->fc.send_xon = true;
  4613. hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
  4614. #ifdef CONFIG_PCI_IOV
  4615. if (max_vfs > 0)
  4616. e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
  4617. /* assign number of SR-IOV VFs */
  4618. if (hw->mac.type != ixgbe_mac_82598EB) {
  4619. if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
  4620. adapter->num_vfs = 0;
  4621. e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
  4622. } else {
  4623. adapter->num_vfs = max_vfs;
  4624. }
  4625. }
  4626. #endif /* CONFIG_PCI_IOV */
  4627. /* enable itr by default in dynamic mode */
  4628. adapter->rx_itr_setting = 1;
  4629. adapter->tx_itr_setting = 1;
  4630. /* set default ring sizes */
  4631. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  4632. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  4633. /* set default work limits */
  4634. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  4635. /* initialize eeprom parameters */
  4636. if (ixgbe_init_eeprom_params_generic(hw)) {
  4637. e_dev_err("EEPROM initialization failed\n");
  4638. return -EIO;
  4639. }
  4640. /* PF holds first pool slot */
  4641. set_bit(0, &adapter->fwd_bitmask);
  4642. set_bit(__IXGBE_DOWN, &adapter->state);
  4643. return 0;
  4644. }
  4645. /**
  4646. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  4647. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  4648. *
  4649. * Return 0 on success, negative on failure
  4650. **/
  4651. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  4652. {
  4653. struct device *dev = tx_ring->dev;
  4654. int orig_node = dev_to_node(dev);
  4655. int ring_node = -1;
  4656. int size;
  4657. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  4658. if (tx_ring->q_vector)
  4659. ring_node = tx_ring->q_vector->numa_node;
  4660. tx_ring->tx_buffer_info = vzalloc_node(size, ring_node);
  4661. if (!tx_ring->tx_buffer_info)
  4662. tx_ring->tx_buffer_info = vzalloc(size);
  4663. if (!tx_ring->tx_buffer_info)
  4664. goto err;
  4665. u64_stats_init(&tx_ring->syncp);
  4666. /* round up to nearest 4K */
  4667. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  4668. tx_ring->size = ALIGN(tx_ring->size, 4096);
  4669. set_dev_node(dev, ring_node);
  4670. tx_ring->desc = dma_alloc_coherent(dev,
  4671. tx_ring->size,
  4672. &tx_ring->dma,
  4673. GFP_KERNEL);
  4674. set_dev_node(dev, orig_node);
  4675. if (!tx_ring->desc)
  4676. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  4677. &tx_ring->dma, GFP_KERNEL);
  4678. if (!tx_ring->desc)
  4679. goto err;
  4680. tx_ring->next_to_use = 0;
  4681. tx_ring->next_to_clean = 0;
  4682. return 0;
  4683. err:
  4684. vfree(tx_ring->tx_buffer_info);
  4685. tx_ring->tx_buffer_info = NULL;
  4686. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  4687. return -ENOMEM;
  4688. }
  4689. /**
  4690. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  4691. * @adapter: board private structure
  4692. *
  4693. * If this function returns with an error, then it's possible one or
  4694. * more of the rings is populated (while the rest are not). It is the
  4695. * callers duty to clean those orphaned rings.
  4696. *
  4697. * Return 0 on success, negative on failure
  4698. **/
  4699. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  4700. {
  4701. int i, err = 0;
  4702. for (i = 0; i < adapter->num_tx_queues; i++) {
  4703. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  4704. if (!err)
  4705. continue;
  4706. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  4707. goto err_setup_tx;
  4708. }
  4709. return 0;
  4710. err_setup_tx:
  4711. /* rewind the index freeing the rings as we go */
  4712. while (i--)
  4713. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  4714. return err;
  4715. }
  4716. /**
  4717. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  4718. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  4719. *
  4720. * Returns 0 on success, negative on failure
  4721. **/
  4722. int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
  4723. {
  4724. struct device *dev = rx_ring->dev;
  4725. int orig_node = dev_to_node(dev);
  4726. int ring_node = -1;
  4727. int size;
  4728. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  4729. if (rx_ring->q_vector)
  4730. ring_node = rx_ring->q_vector->numa_node;
  4731. rx_ring->rx_buffer_info = vzalloc_node(size, ring_node);
  4732. if (!rx_ring->rx_buffer_info)
  4733. rx_ring->rx_buffer_info = vzalloc(size);
  4734. if (!rx_ring->rx_buffer_info)
  4735. goto err;
  4736. u64_stats_init(&rx_ring->syncp);
  4737. /* Round up to nearest 4K */
  4738. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  4739. rx_ring->size = ALIGN(rx_ring->size, 4096);
  4740. set_dev_node(dev, ring_node);
  4741. rx_ring->desc = dma_alloc_coherent(dev,
  4742. rx_ring->size,
  4743. &rx_ring->dma,
  4744. GFP_KERNEL);
  4745. set_dev_node(dev, orig_node);
  4746. if (!rx_ring->desc)
  4747. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  4748. &rx_ring->dma, GFP_KERNEL);
  4749. if (!rx_ring->desc)
  4750. goto err;
  4751. rx_ring->next_to_clean = 0;
  4752. rx_ring->next_to_use = 0;
  4753. return 0;
  4754. err:
  4755. vfree(rx_ring->rx_buffer_info);
  4756. rx_ring->rx_buffer_info = NULL;
  4757. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  4758. return -ENOMEM;
  4759. }
  4760. /**
  4761. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  4762. * @adapter: board private structure
  4763. *
  4764. * If this function returns with an error, then it's possible one or
  4765. * more of the rings is populated (while the rest are not). It is the
  4766. * callers duty to clean those orphaned rings.
  4767. *
  4768. * Return 0 on success, negative on failure
  4769. **/
  4770. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  4771. {
  4772. int i, err = 0;
  4773. for (i = 0; i < adapter->num_rx_queues; i++) {
  4774. err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
  4775. if (!err)
  4776. continue;
  4777. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  4778. goto err_setup_rx;
  4779. }
  4780. #ifdef IXGBE_FCOE
  4781. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  4782. if (!err)
  4783. #endif
  4784. return 0;
  4785. err_setup_rx:
  4786. /* rewind the index freeing the rings as we go */
  4787. while (i--)
  4788. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  4789. return err;
  4790. }
  4791. /**
  4792. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  4793. * @tx_ring: Tx descriptor ring for a specific queue
  4794. *
  4795. * Free all transmit software resources
  4796. **/
  4797. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  4798. {
  4799. ixgbe_clean_tx_ring(tx_ring);
  4800. vfree(tx_ring->tx_buffer_info);
  4801. tx_ring->tx_buffer_info = NULL;
  4802. /* if not set, then don't free */
  4803. if (!tx_ring->desc)
  4804. return;
  4805. dma_free_coherent(tx_ring->dev, tx_ring->size,
  4806. tx_ring->desc, tx_ring->dma);
  4807. tx_ring->desc = NULL;
  4808. }
  4809. /**
  4810. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  4811. * @adapter: board private structure
  4812. *
  4813. * Free all transmit software resources
  4814. **/
  4815. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  4816. {
  4817. int i;
  4818. for (i = 0; i < adapter->num_tx_queues; i++)
  4819. if (adapter->tx_ring[i]->desc)
  4820. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  4821. }
  4822. /**
  4823. * ixgbe_free_rx_resources - Free Rx Resources
  4824. * @rx_ring: ring to clean the resources from
  4825. *
  4826. * Free all receive software resources
  4827. **/
  4828. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  4829. {
  4830. ixgbe_clean_rx_ring(rx_ring);
  4831. vfree(rx_ring->rx_buffer_info);
  4832. rx_ring->rx_buffer_info = NULL;
  4833. /* if not set, then don't free */
  4834. if (!rx_ring->desc)
  4835. return;
  4836. dma_free_coherent(rx_ring->dev, rx_ring->size,
  4837. rx_ring->desc, rx_ring->dma);
  4838. rx_ring->desc = NULL;
  4839. }
  4840. /**
  4841. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  4842. * @adapter: board private structure
  4843. *
  4844. * Free all receive software resources
  4845. **/
  4846. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  4847. {
  4848. int i;
  4849. #ifdef IXGBE_FCOE
  4850. ixgbe_free_fcoe_ddp_resources(adapter);
  4851. #endif
  4852. for (i = 0; i < adapter->num_rx_queues; i++)
  4853. if (adapter->rx_ring[i]->desc)
  4854. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  4855. }
  4856. /**
  4857. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  4858. * @netdev: network interface device structure
  4859. * @new_mtu: new value for maximum frame size
  4860. *
  4861. * Returns 0 on success, negative on failure
  4862. **/
  4863. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  4864. {
  4865. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4866. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  4867. /* MTU < 68 is an error and causes problems on some kernels */
  4868. if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
  4869. return -EINVAL;
  4870. /*
  4871. * For 82599EB we cannot allow legacy VFs to enable their receive
  4872. * paths when MTU greater than 1500 is configured. So display a
  4873. * warning that legacy VFs will be disabled.
  4874. */
  4875. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  4876. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  4877. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  4878. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  4879. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  4880. /* must set new MTU before calling down or up */
  4881. netdev->mtu = new_mtu;
  4882. if (netif_running(netdev))
  4883. ixgbe_reinit_locked(adapter);
  4884. return 0;
  4885. }
  4886. /**
  4887. * ixgbe_open - Called when a network interface is made active
  4888. * @netdev: network interface device structure
  4889. *
  4890. * Returns 0 on success, negative value on failure
  4891. *
  4892. * The open entry point is called when a network interface is made
  4893. * active by the system (IFF_UP). At this point all resources needed
  4894. * for transmit and receive operations are allocated, the interrupt
  4895. * handler is registered with the OS, the watchdog timer is started,
  4896. * and the stack is notified that the interface is ready.
  4897. **/
  4898. static int ixgbe_open(struct net_device *netdev)
  4899. {
  4900. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4901. struct ixgbe_hw *hw = &adapter->hw;
  4902. int err, queues;
  4903. /* disallow open during test */
  4904. if (test_bit(__IXGBE_TESTING, &adapter->state))
  4905. return -EBUSY;
  4906. netif_carrier_off(netdev);
  4907. /* allocate transmit descriptors */
  4908. err = ixgbe_setup_all_tx_resources(adapter);
  4909. if (err)
  4910. goto err_setup_tx;
  4911. /* allocate receive descriptors */
  4912. err = ixgbe_setup_all_rx_resources(adapter);
  4913. if (err)
  4914. goto err_setup_rx;
  4915. ixgbe_configure(adapter);
  4916. err = ixgbe_request_irq(adapter);
  4917. if (err)
  4918. goto err_req_irq;
  4919. /* Notify the stack of the actual queue counts. */
  4920. if (adapter->num_rx_pools > 1)
  4921. queues = adapter->num_rx_queues_per_pool;
  4922. else
  4923. queues = adapter->num_tx_queues;
  4924. err = netif_set_real_num_tx_queues(netdev, queues);
  4925. if (err)
  4926. goto err_set_queues;
  4927. if (adapter->num_rx_pools > 1 &&
  4928. adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
  4929. queues = IXGBE_MAX_L2A_QUEUES;
  4930. else
  4931. queues = adapter->num_rx_queues;
  4932. err = netif_set_real_num_rx_queues(netdev, queues);
  4933. if (err)
  4934. goto err_set_queues;
  4935. ixgbe_ptp_init(adapter);
  4936. ixgbe_up_complete(adapter);
  4937. ixgbe_clear_vxlan_port(adapter);
  4938. #ifdef CONFIG_IXGBE_VXLAN
  4939. vxlan_get_rx_port(netdev);
  4940. #endif
  4941. return 0;
  4942. err_set_queues:
  4943. ixgbe_free_irq(adapter);
  4944. err_req_irq:
  4945. ixgbe_free_all_rx_resources(adapter);
  4946. if (hw->phy.ops.set_phy_power && !adapter->wol)
  4947. hw->phy.ops.set_phy_power(&adapter->hw, false);
  4948. err_setup_rx:
  4949. ixgbe_free_all_tx_resources(adapter);
  4950. err_setup_tx:
  4951. ixgbe_reset(adapter);
  4952. return err;
  4953. }
  4954. static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
  4955. {
  4956. ixgbe_ptp_suspend(adapter);
  4957. if (adapter->hw.phy.ops.enter_lplu) {
  4958. adapter->hw.phy.reset_disable = true;
  4959. ixgbe_down(adapter);
  4960. adapter->hw.phy.ops.enter_lplu(&adapter->hw);
  4961. adapter->hw.phy.reset_disable = false;
  4962. } else {
  4963. ixgbe_down(adapter);
  4964. }
  4965. ixgbe_free_irq(adapter);
  4966. ixgbe_free_all_tx_resources(adapter);
  4967. ixgbe_free_all_rx_resources(adapter);
  4968. }
  4969. /**
  4970. * ixgbe_close - Disables a network interface
  4971. * @netdev: network interface device structure
  4972. *
  4973. * Returns 0, this is not allowed to fail
  4974. *
  4975. * The close entry point is called when an interface is de-activated
  4976. * by the OS. The hardware is still under the drivers control, but
  4977. * needs to be disabled. A global MAC reset is issued to stop the
  4978. * hardware, and all transmit and receive resources are freed.
  4979. **/
  4980. static int ixgbe_close(struct net_device *netdev)
  4981. {
  4982. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4983. ixgbe_ptp_stop(adapter);
  4984. ixgbe_close_suspend(adapter);
  4985. ixgbe_fdir_filter_exit(adapter);
  4986. ixgbe_release_hw_control(adapter);
  4987. return 0;
  4988. }
  4989. #ifdef CONFIG_PM
  4990. static int ixgbe_resume(struct pci_dev *pdev)
  4991. {
  4992. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  4993. struct net_device *netdev = adapter->netdev;
  4994. u32 err;
  4995. adapter->hw.hw_addr = adapter->io_addr;
  4996. pci_set_power_state(pdev, PCI_D0);
  4997. pci_restore_state(pdev);
  4998. /*
  4999. * pci_restore_state clears dev->state_saved so call
  5000. * pci_save_state to restore it.
  5001. */
  5002. pci_save_state(pdev);
  5003. err = pci_enable_device_mem(pdev);
  5004. if (err) {
  5005. e_dev_err("Cannot enable PCI device from suspend\n");
  5006. return err;
  5007. }
  5008. smp_mb__before_atomic();
  5009. clear_bit(__IXGBE_DISABLED, &adapter->state);
  5010. pci_set_master(pdev);
  5011. pci_wake_from_d3(pdev, false);
  5012. ixgbe_reset(adapter);
  5013. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5014. rtnl_lock();
  5015. err = ixgbe_init_interrupt_scheme(adapter);
  5016. if (!err && netif_running(netdev))
  5017. err = ixgbe_open(netdev);
  5018. rtnl_unlock();
  5019. if (err)
  5020. return err;
  5021. netif_device_attach(netdev);
  5022. return 0;
  5023. }
  5024. #endif /* CONFIG_PM */
  5025. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5026. {
  5027. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5028. struct net_device *netdev = adapter->netdev;
  5029. struct ixgbe_hw *hw = &adapter->hw;
  5030. u32 ctrl, fctrl;
  5031. u32 wufc = adapter->wol;
  5032. #ifdef CONFIG_PM
  5033. int retval = 0;
  5034. #endif
  5035. netif_device_detach(netdev);
  5036. rtnl_lock();
  5037. if (netif_running(netdev))
  5038. ixgbe_close_suspend(adapter);
  5039. rtnl_unlock();
  5040. ixgbe_clear_interrupt_scheme(adapter);
  5041. #ifdef CONFIG_PM
  5042. retval = pci_save_state(pdev);
  5043. if (retval)
  5044. return retval;
  5045. #endif
  5046. if (hw->mac.ops.stop_link_on_d3)
  5047. hw->mac.ops.stop_link_on_d3(hw);
  5048. if (wufc) {
  5049. ixgbe_set_rx_mode(netdev);
  5050. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  5051. if (hw->mac.ops.enable_tx_laser)
  5052. hw->mac.ops.enable_tx_laser(hw);
  5053. /* turn on all-multi mode if wake on multicast is enabled */
  5054. if (wufc & IXGBE_WUFC_MC) {
  5055. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5056. fctrl |= IXGBE_FCTRL_MPE;
  5057. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  5058. }
  5059. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  5060. ctrl |= IXGBE_CTRL_GIO_DIS;
  5061. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  5062. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  5063. } else {
  5064. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  5065. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  5066. }
  5067. switch (hw->mac.type) {
  5068. case ixgbe_mac_82598EB:
  5069. pci_wake_from_d3(pdev, false);
  5070. break;
  5071. case ixgbe_mac_82599EB:
  5072. case ixgbe_mac_X540:
  5073. case ixgbe_mac_X550:
  5074. case ixgbe_mac_X550EM_x:
  5075. pci_wake_from_d3(pdev, !!wufc);
  5076. break;
  5077. default:
  5078. break;
  5079. }
  5080. *enable_wake = !!wufc;
  5081. if (hw->phy.ops.set_phy_power && !*enable_wake)
  5082. hw->phy.ops.set_phy_power(hw, false);
  5083. ixgbe_release_hw_control(adapter);
  5084. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  5085. pci_disable_device(pdev);
  5086. return 0;
  5087. }
  5088. #ifdef CONFIG_PM
  5089. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  5090. {
  5091. int retval;
  5092. bool wake;
  5093. retval = __ixgbe_shutdown(pdev, &wake);
  5094. if (retval)
  5095. return retval;
  5096. if (wake) {
  5097. pci_prepare_to_sleep(pdev);
  5098. } else {
  5099. pci_wake_from_d3(pdev, false);
  5100. pci_set_power_state(pdev, PCI_D3hot);
  5101. }
  5102. return 0;
  5103. }
  5104. #endif /* CONFIG_PM */
  5105. static void ixgbe_shutdown(struct pci_dev *pdev)
  5106. {
  5107. bool wake;
  5108. __ixgbe_shutdown(pdev, &wake);
  5109. if (system_state == SYSTEM_POWER_OFF) {
  5110. pci_wake_from_d3(pdev, wake);
  5111. pci_set_power_state(pdev, PCI_D3hot);
  5112. }
  5113. }
  5114. /**
  5115. * ixgbe_update_stats - Update the board statistics counters.
  5116. * @adapter: board private structure
  5117. **/
  5118. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  5119. {
  5120. struct net_device *netdev = adapter->netdev;
  5121. struct ixgbe_hw *hw = &adapter->hw;
  5122. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  5123. u64 total_mpc = 0;
  5124. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  5125. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  5126. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  5127. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  5128. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5129. test_bit(__IXGBE_RESETTING, &adapter->state))
  5130. return;
  5131. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  5132. u64 rsc_count = 0;
  5133. u64 rsc_flush = 0;
  5134. for (i = 0; i < adapter->num_rx_queues; i++) {
  5135. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  5136. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  5137. }
  5138. adapter->rsc_total_count = rsc_count;
  5139. adapter->rsc_total_flush = rsc_flush;
  5140. }
  5141. for (i = 0; i < adapter->num_rx_queues; i++) {
  5142. struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
  5143. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  5144. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  5145. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  5146. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  5147. bytes += rx_ring->stats.bytes;
  5148. packets += rx_ring->stats.packets;
  5149. }
  5150. adapter->non_eop_descs = non_eop_descs;
  5151. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  5152. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  5153. adapter->hw_csum_rx_error = hw_csum_rx_error;
  5154. netdev->stats.rx_bytes = bytes;
  5155. netdev->stats.rx_packets = packets;
  5156. bytes = 0;
  5157. packets = 0;
  5158. /* gather some stats to the adapter struct that are per queue */
  5159. for (i = 0; i < adapter->num_tx_queues; i++) {
  5160. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  5161. restart_queue += tx_ring->tx_stats.restart_queue;
  5162. tx_busy += tx_ring->tx_stats.tx_busy;
  5163. bytes += tx_ring->stats.bytes;
  5164. packets += tx_ring->stats.packets;
  5165. }
  5166. adapter->restart_queue = restart_queue;
  5167. adapter->tx_busy = tx_busy;
  5168. netdev->stats.tx_bytes = bytes;
  5169. netdev->stats.tx_packets = packets;
  5170. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  5171. /* 8 register reads */
  5172. for (i = 0; i < 8; i++) {
  5173. /* for packet buffers not used, the register should read 0 */
  5174. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  5175. missed_rx += mpc;
  5176. hwstats->mpc[i] += mpc;
  5177. total_mpc += hwstats->mpc[i];
  5178. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  5179. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  5180. switch (hw->mac.type) {
  5181. case ixgbe_mac_82598EB:
  5182. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  5183. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  5184. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  5185. hwstats->pxonrxc[i] +=
  5186. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  5187. break;
  5188. case ixgbe_mac_82599EB:
  5189. case ixgbe_mac_X540:
  5190. case ixgbe_mac_X550:
  5191. case ixgbe_mac_X550EM_x:
  5192. hwstats->pxonrxc[i] +=
  5193. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  5194. break;
  5195. default:
  5196. break;
  5197. }
  5198. }
  5199. /*16 register reads */
  5200. for (i = 0; i < 16; i++) {
  5201. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  5202. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  5203. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  5204. (hw->mac.type == ixgbe_mac_X540) ||
  5205. (hw->mac.type == ixgbe_mac_X550) ||
  5206. (hw->mac.type == ixgbe_mac_X550EM_x)) {
  5207. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  5208. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  5209. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  5210. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  5211. }
  5212. }
  5213. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  5214. /* work around hardware counting issue */
  5215. hwstats->gprc -= missed_rx;
  5216. ixgbe_update_xoff_received(adapter);
  5217. /* 82598 hardware only has a 32 bit counter in the high register */
  5218. switch (hw->mac.type) {
  5219. case ixgbe_mac_82598EB:
  5220. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  5221. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  5222. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  5223. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  5224. break;
  5225. case ixgbe_mac_X540:
  5226. case ixgbe_mac_X550:
  5227. case ixgbe_mac_X550EM_x:
  5228. /* OS2BMC stats are X540 and later */
  5229. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  5230. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  5231. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  5232. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  5233. case ixgbe_mac_82599EB:
  5234. for (i = 0; i < 16; i++)
  5235. adapter->hw_rx_no_dma_resources +=
  5236. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  5237. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  5238. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  5239. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  5240. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  5241. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  5242. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  5243. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  5244. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  5245. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  5246. #ifdef IXGBE_FCOE
  5247. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  5248. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  5249. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  5250. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  5251. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  5252. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  5253. /* Add up per cpu counters for total ddp aloc fail */
  5254. if (adapter->fcoe.ddp_pool) {
  5255. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  5256. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  5257. unsigned int cpu;
  5258. u64 noddp = 0, noddp_ext_buff = 0;
  5259. for_each_possible_cpu(cpu) {
  5260. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  5261. noddp += ddp_pool->noddp;
  5262. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  5263. }
  5264. hwstats->fcoe_noddp = noddp;
  5265. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  5266. }
  5267. #endif /* IXGBE_FCOE */
  5268. break;
  5269. default:
  5270. break;
  5271. }
  5272. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  5273. hwstats->bprc += bprc;
  5274. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  5275. if (hw->mac.type == ixgbe_mac_82598EB)
  5276. hwstats->mprc -= bprc;
  5277. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  5278. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  5279. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  5280. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  5281. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  5282. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  5283. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  5284. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  5285. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  5286. hwstats->lxontxc += lxon;
  5287. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  5288. hwstats->lxofftxc += lxoff;
  5289. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  5290. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  5291. /*
  5292. * 82598 errata - tx of flow control packets is included in tx counters
  5293. */
  5294. xon_off_tot = lxon + lxoff;
  5295. hwstats->gptc -= xon_off_tot;
  5296. hwstats->mptc -= xon_off_tot;
  5297. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  5298. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  5299. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  5300. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  5301. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  5302. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  5303. hwstats->ptc64 -= xon_off_tot;
  5304. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  5305. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  5306. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  5307. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  5308. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  5309. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  5310. /* Fill out the OS statistics structure */
  5311. netdev->stats.multicast = hwstats->mprc;
  5312. /* Rx Errors */
  5313. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  5314. netdev->stats.rx_dropped = 0;
  5315. netdev->stats.rx_length_errors = hwstats->rlec;
  5316. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  5317. netdev->stats.rx_missed_errors = total_mpc;
  5318. }
  5319. /**
  5320. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  5321. * @adapter: pointer to the device adapter structure
  5322. **/
  5323. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  5324. {
  5325. struct ixgbe_hw *hw = &adapter->hw;
  5326. int i;
  5327. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  5328. return;
  5329. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  5330. /* if interface is down do nothing */
  5331. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5332. return;
  5333. /* do nothing if we are not using signature filters */
  5334. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  5335. return;
  5336. adapter->fdir_overflow++;
  5337. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  5338. for (i = 0; i < adapter->num_tx_queues; i++)
  5339. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  5340. &(adapter->tx_ring[i]->state));
  5341. /* re-enable flow director interrupts */
  5342. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  5343. } else {
  5344. e_err(probe, "failed to finish FDIR re-initialization, "
  5345. "ignored adding FDIR ATR filters\n");
  5346. }
  5347. }
  5348. /**
  5349. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  5350. * @adapter: pointer to the device adapter structure
  5351. *
  5352. * This function serves two purposes. First it strobes the interrupt lines
  5353. * in order to make certain interrupts are occurring. Secondly it sets the
  5354. * bits needed to check for TX hangs. As a result we should immediately
  5355. * determine if a hang has occurred.
  5356. */
  5357. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  5358. {
  5359. struct ixgbe_hw *hw = &adapter->hw;
  5360. u64 eics = 0;
  5361. int i;
  5362. /* If we're down, removing or resetting, just bail */
  5363. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5364. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  5365. test_bit(__IXGBE_RESETTING, &adapter->state))
  5366. return;
  5367. /* Force detection of hung controller */
  5368. if (netif_carrier_ok(adapter->netdev)) {
  5369. for (i = 0; i < adapter->num_tx_queues; i++)
  5370. set_check_for_tx_hang(adapter->tx_ring[i]);
  5371. }
  5372. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  5373. /*
  5374. * for legacy and MSI interrupts don't set any bits
  5375. * that are enabled for EIAM, because this operation
  5376. * would set *both* EIMS and EICS for any bit in EIAM
  5377. */
  5378. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  5379. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  5380. } else {
  5381. /* get one bit for every active tx/rx interrupt vector */
  5382. for (i = 0; i < adapter->num_q_vectors; i++) {
  5383. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  5384. if (qv->rx.ring || qv->tx.ring)
  5385. eics |= ((u64)1 << i);
  5386. }
  5387. }
  5388. /* Cause software interrupt to ensure rings are cleaned */
  5389. ixgbe_irq_rearm_queues(adapter, eics);
  5390. }
  5391. /**
  5392. * ixgbe_watchdog_update_link - update the link status
  5393. * @adapter: pointer to the device adapter structure
  5394. * @link_speed: pointer to a u32 to store the link_speed
  5395. **/
  5396. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  5397. {
  5398. struct ixgbe_hw *hw = &adapter->hw;
  5399. u32 link_speed = adapter->link_speed;
  5400. bool link_up = adapter->link_up;
  5401. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  5402. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  5403. return;
  5404. if (hw->mac.ops.check_link) {
  5405. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  5406. } else {
  5407. /* always assume link is up, if no check link function */
  5408. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  5409. link_up = true;
  5410. }
  5411. if (adapter->ixgbe_ieee_pfc)
  5412. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  5413. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  5414. hw->mac.ops.fc_enable(hw);
  5415. ixgbe_set_rx_drop_en(adapter);
  5416. }
  5417. if (link_up ||
  5418. time_after(jiffies, (adapter->link_check_timeout +
  5419. IXGBE_TRY_LINK_TIMEOUT))) {
  5420. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  5421. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  5422. IXGBE_WRITE_FLUSH(hw);
  5423. }
  5424. adapter->link_up = link_up;
  5425. adapter->link_speed = link_speed;
  5426. }
  5427. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  5428. {
  5429. #ifdef CONFIG_IXGBE_DCB
  5430. struct net_device *netdev = adapter->netdev;
  5431. struct dcb_app app = {
  5432. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  5433. .protocol = 0,
  5434. };
  5435. u8 up = 0;
  5436. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  5437. up = dcb_ieee_getapp_mask(netdev, &app);
  5438. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  5439. #endif
  5440. }
  5441. /**
  5442. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  5443. * print link up message
  5444. * @adapter: pointer to the device adapter structure
  5445. **/
  5446. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  5447. {
  5448. struct net_device *netdev = adapter->netdev;
  5449. struct ixgbe_hw *hw = &adapter->hw;
  5450. struct net_device *upper;
  5451. struct list_head *iter;
  5452. u32 link_speed = adapter->link_speed;
  5453. const char *speed_str;
  5454. bool flow_rx, flow_tx;
  5455. /* only continue if link was previously down */
  5456. if (netif_carrier_ok(netdev))
  5457. return;
  5458. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  5459. switch (hw->mac.type) {
  5460. case ixgbe_mac_82598EB: {
  5461. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5462. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  5463. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  5464. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  5465. }
  5466. break;
  5467. case ixgbe_mac_X540:
  5468. case ixgbe_mac_X550:
  5469. case ixgbe_mac_X550EM_x:
  5470. case ixgbe_mac_82599EB: {
  5471. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  5472. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  5473. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  5474. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  5475. }
  5476. break;
  5477. default:
  5478. flow_tx = false;
  5479. flow_rx = false;
  5480. break;
  5481. }
  5482. adapter->last_rx_ptp_check = jiffies;
  5483. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  5484. ixgbe_ptp_start_cyclecounter(adapter);
  5485. switch (link_speed) {
  5486. case IXGBE_LINK_SPEED_10GB_FULL:
  5487. speed_str = "10 Gbps";
  5488. break;
  5489. case IXGBE_LINK_SPEED_2_5GB_FULL:
  5490. speed_str = "2.5 Gbps";
  5491. break;
  5492. case IXGBE_LINK_SPEED_1GB_FULL:
  5493. speed_str = "1 Gbps";
  5494. break;
  5495. case IXGBE_LINK_SPEED_100_FULL:
  5496. speed_str = "100 Mbps";
  5497. break;
  5498. default:
  5499. speed_str = "unknown speed";
  5500. break;
  5501. }
  5502. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
  5503. ((flow_rx && flow_tx) ? "RX/TX" :
  5504. (flow_rx ? "RX" :
  5505. (flow_tx ? "TX" : "None"))));
  5506. netif_carrier_on(netdev);
  5507. ixgbe_check_vf_rate_limit(adapter);
  5508. /* enable transmits */
  5509. netif_tx_wake_all_queues(adapter->netdev);
  5510. /* enable any upper devices */
  5511. rtnl_lock();
  5512. netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) {
  5513. if (netif_is_macvlan(upper)) {
  5514. struct macvlan_dev *vlan = netdev_priv(upper);
  5515. if (vlan->fwd_priv)
  5516. netif_tx_wake_all_queues(upper);
  5517. }
  5518. }
  5519. rtnl_unlock();
  5520. /* update the default user priority for VFs */
  5521. ixgbe_update_default_up(adapter);
  5522. /* ping all the active vfs to let them know link has changed */
  5523. ixgbe_ping_all_vfs(adapter);
  5524. }
  5525. /**
  5526. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  5527. * print link down message
  5528. * @adapter: pointer to the adapter structure
  5529. **/
  5530. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  5531. {
  5532. struct net_device *netdev = adapter->netdev;
  5533. struct ixgbe_hw *hw = &adapter->hw;
  5534. adapter->link_up = false;
  5535. adapter->link_speed = 0;
  5536. /* only continue if link was up previously */
  5537. if (!netif_carrier_ok(netdev))
  5538. return;
  5539. /* poll for SFP+ cable when link is down */
  5540. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  5541. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  5542. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  5543. ixgbe_ptp_start_cyclecounter(adapter);
  5544. e_info(drv, "NIC Link is Down\n");
  5545. netif_carrier_off(netdev);
  5546. /* ping all the active vfs to let them know link has changed */
  5547. ixgbe_ping_all_vfs(adapter);
  5548. }
  5549. static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
  5550. {
  5551. int i;
  5552. for (i = 0; i < adapter->num_tx_queues; i++) {
  5553. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  5554. if (tx_ring->next_to_use != tx_ring->next_to_clean)
  5555. return true;
  5556. }
  5557. return false;
  5558. }
  5559. static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
  5560. {
  5561. struct ixgbe_hw *hw = &adapter->hw;
  5562. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  5563. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  5564. int i, j;
  5565. if (!adapter->num_vfs)
  5566. return false;
  5567. /* resetting the PF is only needed for MAC before X550 */
  5568. if (hw->mac.type >= ixgbe_mac_X550)
  5569. return false;
  5570. for (i = 0; i < adapter->num_vfs; i++) {
  5571. for (j = 0; j < q_per_pool; j++) {
  5572. u32 h, t;
  5573. h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
  5574. t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
  5575. if (h != t)
  5576. return true;
  5577. }
  5578. }
  5579. return false;
  5580. }
  5581. /**
  5582. * ixgbe_watchdog_flush_tx - flush queues on link down
  5583. * @adapter: pointer to the device adapter structure
  5584. **/
  5585. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  5586. {
  5587. if (!netif_carrier_ok(adapter->netdev)) {
  5588. if (ixgbe_ring_tx_pending(adapter) ||
  5589. ixgbe_vf_tx_pending(adapter)) {
  5590. /* We've lost link, so the controller stops DMA,
  5591. * but we've got queued Tx work that's never going
  5592. * to get done, so reset controller to flush Tx.
  5593. * (Do the reset outside of interrupt context).
  5594. */
  5595. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  5596. adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
  5597. }
  5598. }
  5599. }
  5600. #ifdef CONFIG_PCI_IOV
  5601. static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
  5602. struct pci_dev *vfdev)
  5603. {
  5604. if (!pci_wait_for_pending_transaction(vfdev))
  5605. e_dev_warn("Issuing VFLR with pending transactions\n");
  5606. e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
  5607. pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
  5608. msleep(100);
  5609. }
  5610. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  5611. {
  5612. struct ixgbe_hw *hw = &adapter->hw;
  5613. struct pci_dev *pdev = adapter->pdev;
  5614. struct pci_dev *vfdev;
  5615. u32 gpc;
  5616. int pos;
  5617. unsigned short vf_id;
  5618. if (!(netif_carrier_ok(adapter->netdev)))
  5619. return;
  5620. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  5621. if (gpc) /* If incrementing then no need for the check below */
  5622. return;
  5623. /* Check to see if a bad DMA write target from an errant or
  5624. * malicious VF has caused a PCIe error. If so then we can
  5625. * issue a VFLR to the offending VF(s) and then resume without
  5626. * requesting a full slot reset.
  5627. */
  5628. if (!pdev)
  5629. return;
  5630. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
  5631. if (!pos)
  5632. return;
  5633. /* get the device ID for the VF */
  5634. pci_read_config_word(pdev, pos + PCI_SRIOV_VF_DID, &vf_id);
  5635. /* check status reg for all VFs owned by this PF */
  5636. vfdev = pci_get_device(pdev->vendor, vf_id, NULL);
  5637. while (vfdev) {
  5638. if (vfdev->is_virtfn && (vfdev->physfn == pdev)) {
  5639. u16 status_reg;
  5640. pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
  5641. if (status_reg & PCI_STATUS_REC_MASTER_ABORT)
  5642. /* issue VFLR */
  5643. ixgbe_issue_vf_flr(adapter, vfdev);
  5644. }
  5645. vfdev = pci_get_device(pdev->vendor, vf_id, vfdev);
  5646. }
  5647. }
  5648. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  5649. {
  5650. u32 ssvpc;
  5651. /* Do not perform spoof check for 82598 or if not in IOV mode */
  5652. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  5653. adapter->num_vfs == 0)
  5654. return;
  5655. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  5656. /*
  5657. * ssvpc register is cleared on read, if zero then no
  5658. * spoofed packets in the last interval.
  5659. */
  5660. if (!ssvpc)
  5661. return;
  5662. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  5663. }
  5664. #else
  5665. static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
  5666. {
  5667. }
  5668. static void
  5669. ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
  5670. {
  5671. }
  5672. #endif /* CONFIG_PCI_IOV */
  5673. /**
  5674. * ixgbe_watchdog_subtask - check and bring link up
  5675. * @adapter: pointer to the device adapter structure
  5676. **/
  5677. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  5678. {
  5679. /* if interface is down, removing or resetting, do nothing */
  5680. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5681. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  5682. test_bit(__IXGBE_RESETTING, &adapter->state))
  5683. return;
  5684. ixgbe_watchdog_update_link(adapter);
  5685. if (adapter->link_up)
  5686. ixgbe_watchdog_link_is_up(adapter);
  5687. else
  5688. ixgbe_watchdog_link_is_down(adapter);
  5689. ixgbe_check_for_bad_vf(adapter);
  5690. ixgbe_spoof_check(adapter);
  5691. ixgbe_update_stats(adapter);
  5692. ixgbe_watchdog_flush_tx(adapter);
  5693. }
  5694. /**
  5695. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  5696. * @adapter: the ixgbe adapter structure
  5697. **/
  5698. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  5699. {
  5700. struct ixgbe_hw *hw = &adapter->hw;
  5701. s32 err;
  5702. /* not searching for SFP so there is nothing to do here */
  5703. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  5704. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  5705. return;
  5706. /* someone else is in init, wait until next service event */
  5707. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  5708. return;
  5709. err = hw->phy.ops.identify_sfp(hw);
  5710. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  5711. goto sfp_out;
  5712. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  5713. /* If no cable is present, then we need to reset
  5714. * the next time we find a good cable. */
  5715. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  5716. }
  5717. /* exit on error */
  5718. if (err)
  5719. goto sfp_out;
  5720. /* exit if reset not needed */
  5721. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  5722. goto sfp_out;
  5723. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  5724. /*
  5725. * A module may be identified correctly, but the EEPROM may not have
  5726. * support for that module. setup_sfp() will fail in that case, so
  5727. * we should not allow that module to load.
  5728. */
  5729. if (hw->mac.type == ixgbe_mac_82598EB)
  5730. err = hw->phy.ops.reset(hw);
  5731. else
  5732. err = hw->mac.ops.setup_sfp(hw);
  5733. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  5734. goto sfp_out;
  5735. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  5736. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  5737. sfp_out:
  5738. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  5739. if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
  5740. (adapter->netdev->reg_state == NETREG_REGISTERED)) {
  5741. e_dev_err("failed to initialize because an unsupported "
  5742. "SFP+ module type was detected.\n");
  5743. e_dev_err("Reload the driver after installing a "
  5744. "supported module.\n");
  5745. unregister_netdev(adapter->netdev);
  5746. }
  5747. }
  5748. /**
  5749. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  5750. * @adapter: the ixgbe adapter structure
  5751. **/
  5752. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  5753. {
  5754. struct ixgbe_hw *hw = &adapter->hw;
  5755. u32 speed;
  5756. bool autoneg = false;
  5757. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  5758. return;
  5759. /* someone else is in init, wait until next service event */
  5760. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  5761. return;
  5762. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  5763. speed = hw->phy.autoneg_advertised;
  5764. if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
  5765. hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
  5766. /* setup the highest link when no autoneg */
  5767. if (!autoneg) {
  5768. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  5769. speed = IXGBE_LINK_SPEED_10GB_FULL;
  5770. }
  5771. }
  5772. if (hw->mac.ops.setup_link)
  5773. hw->mac.ops.setup_link(hw, speed, true);
  5774. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  5775. adapter->link_check_timeout = jiffies;
  5776. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  5777. }
  5778. /**
  5779. * ixgbe_service_timer - Timer Call-back
  5780. * @data: pointer to adapter cast into an unsigned long
  5781. **/
  5782. static void ixgbe_service_timer(unsigned long data)
  5783. {
  5784. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  5785. unsigned long next_event_offset;
  5786. /* poll faster when waiting for link */
  5787. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  5788. next_event_offset = HZ / 10;
  5789. else
  5790. next_event_offset = HZ * 2;
  5791. /* Reset the timer */
  5792. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  5793. ixgbe_service_event_schedule(adapter);
  5794. }
  5795. static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
  5796. {
  5797. struct ixgbe_hw *hw = &adapter->hw;
  5798. u32 status;
  5799. if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
  5800. return;
  5801. adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
  5802. if (!hw->phy.ops.handle_lasi)
  5803. return;
  5804. status = hw->phy.ops.handle_lasi(&adapter->hw);
  5805. if (status != IXGBE_ERR_OVERTEMP)
  5806. return;
  5807. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  5808. }
  5809. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  5810. {
  5811. if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
  5812. return;
  5813. adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
  5814. /* If we're already down, removing or resetting, just bail */
  5815. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5816. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  5817. test_bit(__IXGBE_RESETTING, &adapter->state))
  5818. return;
  5819. ixgbe_dump(adapter);
  5820. netdev_err(adapter->netdev, "Reset adapter\n");
  5821. adapter->tx_timeout_count++;
  5822. rtnl_lock();
  5823. ixgbe_reinit_locked(adapter);
  5824. rtnl_unlock();
  5825. }
  5826. /**
  5827. * ixgbe_service_task - manages and runs subtasks
  5828. * @work: pointer to work_struct containing our data
  5829. **/
  5830. static void ixgbe_service_task(struct work_struct *work)
  5831. {
  5832. struct ixgbe_adapter *adapter = container_of(work,
  5833. struct ixgbe_adapter,
  5834. service_task);
  5835. if (ixgbe_removed(adapter->hw.hw_addr)) {
  5836. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  5837. rtnl_lock();
  5838. ixgbe_down(adapter);
  5839. rtnl_unlock();
  5840. }
  5841. ixgbe_service_event_complete(adapter);
  5842. return;
  5843. }
  5844. #ifdef CONFIG_IXGBE_VXLAN
  5845. if (adapter->flags2 & IXGBE_FLAG2_VXLAN_REREG_NEEDED) {
  5846. adapter->flags2 &= ~IXGBE_FLAG2_VXLAN_REREG_NEEDED;
  5847. vxlan_get_rx_port(adapter->netdev);
  5848. }
  5849. #endif /* CONFIG_IXGBE_VXLAN */
  5850. ixgbe_reset_subtask(adapter);
  5851. ixgbe_phy_interrupt_subtask(adapter);
  5852. ixgbe_sfp_detection_subtask(adapter);
  5853. ixgbe_sfp_link_config_subtask(adapter);
  5854. ixgbe_check_overtemp_subtask(adapter);
  5855. ixgbe_watchdog_subtask(adapter);
  5856. ixgbe_fdir_reinit_subtask(adapter);
  5857. ixgbe_check_hang_subtask(adapter);
  5858. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
  5859. ixgbe_ptp_overflow_check(adapter);
  5860. ixgbe_ptp_rx_hang(adapter);
  5861. }
  5862. ixgbe_service_event_complete(adapter);
  5863. }
  5864. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  5865. struct ixgbe_tx_buffer *first,
  5866. u8 *hdr_len)
  5867. {
  5868. struct sk_buff *skb = first->skb;
  5869. u32 vlan_macip_lens, type_tucmd;
  5870. u32 mss_l4len_idx, l4len;
  5871. int err;
  5872. if (skb->ip_summed != CHECKSUM_PARTIAL)
  5873. return 0;
  5874. if (!skb_is_gso(skb))
  5875. return 0;
  5876. err = skb_cow_head(skb, 0);
  5877. if (err < 0)
  5878. return err;
  5879. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  5880. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5881. if (first->protocol == htons(ETH_P_IP)) {
  5882. struct iphdr *iph = ip_hdr(skb);
  5883. iph->tot_len = 0;
  5884. iph->check = 0;
  5885. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  5886. iph->daddr, 0,
  5887. IPPROTO_TCP,
  5888. 0);
  5889. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  5890. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  5891. IXGBE_TX_FLAGS_CSUM |
  5892. IXGBE_TX_FLAGS_IPV4;
  5893. } else if (skb_is_gso_v6(skb)) {
  5894. ipv6_hdr(skb)->payload_len = 0;
  5895. tcp_hdr(skb)->check =
  5896. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  5897. &ipv6_hdr(skb)->daddr,
  5898. 0, IPPROTO_TCP, 0);
  5899. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  5900. IXGBE_TX_FLAGS_CSUM;
  5901. }
  5902. /* compute header lengths */
  5903. l4len = tcp_hdrlen(skb);
  5904. *hdr_len = skb_transport_offset(skb) + l4len;
  5905. /* update gso size and bytecount with header size */
  5906. first->gso_segs = skb_shinfo(skb)->gso_segs;
  5907. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  5908. /* mss_l4len_id: use 0 as index for TSO */
  5909. mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
  5910. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  5911. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  5912. vlan_macip_lens = skb_network_header_len(skb);
  5913. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  5914. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  5915. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
  5916. mss_l4len_idx);
  5917. return 1;
  5918. }
  5919. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  5920. struct ixgbe_tx_buffer *first)
  5921. {
  5922. struct sk_buff *skb = first->skb;
  5923. u32 vlan_macip_lens = 0;
  5924. u32 mss_l4len_idx = 0;
  5925. u32 type_tucmd = 0;
  5926. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  5927. if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
  5928. !(first->tx_flags & IXGBE_TX_FLAGS_CC))
  5929. return;
  5930. vlan_macip_lens = skb_network_offset(skb) <<
  5931. IXGBE_ADVTXD_MACLEN_SHIFT;
  5932. } else {
  5933. u8 l4_hdr = 0;
  5934. union {
  5935. struct iphdr *ipv4;
  5936. struct ipv6hdr *ipv6;
  5937. u8 *raw;
  5938. } network_hdr;
  5939. union {
  5940. struct tcphdr *tcphdr;
  5941. u8 *raw;
  5942. } transport_hdr;
  5943. if (skb->encapsulation) {
  5944. network_hdr.raw = skb_inner_network_header(skb);
  5945. transport_hdr.raw = skb_inner_transport_header(skb);
  5946. vlan_macip_lens = skb_inner_network_offset(skb) <<
  5947. IXGBE_ADVTXD_MACLEN_SHIFT;
  5948. } else {
  5949. network_hdr.raw = skb_network_header(skb);
  5950. transport_hdr.raw = skb_transport_header(skb);
  5951. vlan_macip_lens = skb_network_offset(skb) <<
  5952. IXGBE_ADVTXD_MACLEN_SHIFT;
  5953. }
  5954. /* use first 4 bits to determine IP version */
  5955. switch (network_hdr.ipv4->version) {
  5956. case IPVERSION:
  5957. vlan_macip_lens |= transport_hdr.raw - network_hdr.raw;
  5958. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  5959. l4_hdr = network_hdr.ipv4->protocol;
  5960. break;
  5961. case 6:
  5962. vlan_macip_lens |= transport_hdr.raw - network_hdr.raw;
  5963. l4_hdr = network_hdr.ipv6->nexthdr;
  5964. break;
  5965. default:
  5966. if (unlikely(net_ratelimit())) {
  5967. dev_warn(tx_ring->dev,
  5968. "partial checksum but version=%d\n",
  5969. network_hdr.ipv4->version);
  5970. }
  5971. }
  5972. switch (l4_hdr) {
  5973. case IPPROTO_TCP:
  5974. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5975. mss_l4len_idx = (transport_hdr.tcphdr->doff * 4) <<
  5976. IXGBE_ADVTXD_L4LEN_SHIFT;
  5977. break;
  5978. case IPPROTO_SCTP:
  5979. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  5980. mss_l4len_idx = sizeof(struct sctphdr) <<
  5981. IXGBE_ADVTXD_L4LEN_SHIFT;
  5982. break;
  5983. case IPPROTO_UDP:
  5984. mss_l4len_idx = sizeof(struct udphdr) <<
  5985. IXGBE_ADVTXD_L4LEN_SHIFT;
  5986. break;
  5987. default:
  5988. if (unlikely(net_ratelimit())) {
  5989. dev_warn(tx_ring->dev,
  5990. "partial checksum but l4 proto=%x!\n",
  5991. l4_hdr);
  5992. }
  5993. break;
  5994. }
  5995. /* update TX checksum flag */
  5996. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  5997. }
  5998. /* vlan_macip_lens: MACLEN, VLAN tag */
  5999. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6000. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
  6001. type_tucmd, mss_l4len_idx);
  6002. }
  6003. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  6004. ((_flag <= _result) ? \
  6005. ((u32)(_input & _flag) * (_result / _flag)) : \
  6006. ((u32)(_input & _flag) / (_flag / _result)))
  6007. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  6008. {
  6009. /* set type for advanced descriptor with frame checksum insertion */
  6010. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  6011. IXGBE_ADVTXD_DCMD_DEXT |
  6012. IXGBE_ADVTXD_DCMD_IFCS;
  6013. /* set HW vlan bit if vlan is present */
  6014. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  6015. IXGBE_ADVTXD_DCMD_VLE);
  6016. /* set segmentation enable bits for TSO/FSO */
  6017. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  6018. IXGBE_ADVTXD_DCMD_TSE);
  6019. /* set timestamp bit if present */
  6020. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  6021. IXGBE_ADVTXD_MAC_TSTAMP);
  6022. /* insert frame checksum */
  6023. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  6024. return cmd_type;
  6025. }
  6026. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  6027. u32 tx_flags, unsigned int paylen)
  6028. {
  6029. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  6030. /* enable L4 checksum for TSO and TX checksum offload */
  6031. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6032. IXGBE_TX_FLAGS_CSUM,
  6033. IXGBE_ADVTXD_POPTS_TXSM);
  6034. /* enble IPv4 checksum for TSO */
  6035. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6036. IXGBE_TX_FLAGS_IPV4,
  6037. IXGBE_ADVTXD_POPTS_IXSM);
  6038. /*
  6039. * Check Context must be set if Tx switch is enabled, which it
  6040. * always is for case where virtual functions are running
  6041. */
  6042. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6043. IXGBE_TX_FLAGS_CC,
  6044. IXGBE_ADVTXD_CC);
  6045. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  6046. }
  6047. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6048. {
  6049. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6050. /* Herbert's original patch had:
  6051. * smp_mb__after_netif_stop_queue();
  6052. * but since that doesn't exist yet, just open code it.
  6053. */
  6054. smp_mb();
  6055. /* We need to check again in a case another CPU has just
  6056. * made room available.
  6057. */
  6058. if (likely(ixgbe_desc_unused(tx_ring) < size))
  6059. return -EBUSY;
  6060. /* A reprieve! - use start_queue because it doesn't call schedule */
  6061. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6062. ++tx_ring->tx_stats.restart_queue;
  6063. return 0;
  6064. }
  6065. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6066. {
  6067. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  6068. return 0;
  6069. return __ixgbe_maybe_stop_tx(tx_ring, size);
  6070. }
  6071. #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
  6072. IXGBE_TXD_CMD_RS)
  6073. static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  6074. struct ixgbe_tx_buffer *first,
  6075. const u8 hdr_len)
  6076. {
  6077. struct sk_buff *skb = first->skb;
  6078. struct ixgbe_tx_buffer *tx_buffer;
  6079. union ixgbe_adv_tx_desc *tx_desc;
  6080. struct skb_frag_struct *frag;
  6081. dma_addr_t dma;
  6082. unsigned int data_len, size;
  6083. u32 tx_flags = first->tx_flags;
  6084. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  6085. u16 i = tx_ring->next_to_use;
  6086. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  6087. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  6088. size = skb_headlen(skb);
  6089. data_len = skb->data_len;
  6090. #ifdef IXGBE_FCOE
  6091. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  6092. if (data_len < sizeof(struct fcoe_crc_eof)) {
  6093. size -= sizeof(struct fcoe_crc_eof) - data_len;
  6094. data_len = 0;
  6095. } else {
  6096. data_len -= sizeof(struct fcoe_crc_eof);
  6097. }
  6098. }
  6099. #endif
  6100. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  6101. tx_buffer = first;
  6102. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  6103. if (dma_mapping_error(tx_ring->dev, dma))
  6104. goto dma_error;
  6105. /* record length, and DMA address */
  6106. dma_unmap_len_set(tx_buffer, len, size);
  6107. dma_unmap_addr_set(tx_buffer, dma, dma);
  6108. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6109. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  6110. tx_desc->read.cmd_type_len =
  6111. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  6112. i++;
  6113. tx_desc++;
  6114. if (i == tx_ring->count) {
  6115. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6116. i = 0;
  6117. }
  6118. tx_desc->read.olinfo_status = 0;
  6119. dma += IXGBE_MAX_DATA_PER_TXD;
  6120. size -= IXGBE_MAX_DATA_PER_TXD;
  6121. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6122. }
  6123. if (likely(!data_len))
  6124. break;
  6125. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  6126. i++;
  6127. tx_desc++;
  6128. if (i == tx_ring->count) {
  6129. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6130. i = 0;
  6131. }
  6132. tx_desc->read.olinfo_status = 0;
  6133. #ifdef IXGBE_FCOE
  6134. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  6135. #else
  6136. size = skb_frag_size(frag);
  6137. #endif
  6138. data_len -= size;
  6139. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  6140. DMA_TO_DEVICE);
  6141. tx_buffer = &tx_ring->tx_buffer_info[i];
  6142. }
  6143. /* write last descriptor with RS and EOP bits */
  6144. cmd_type |= size | IXGBE_TXD_CMD;
  6145. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  6146. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  6147. /* set the timestamp */
  6148. first->time_stamp = jiffies;
  6149. /*
  6150. * Force memory writes to complete before letting h/w know there
  6151. * are new descriptors to fetch. (Only applicable for weak-ordered
  6152. * memory model archs, such as IA-64).
  6153. *
  6154. * We also need this memory barrier to make certain all of the
  6155. * status bits have been updated before next_to_watch is written.
  6156. */
  6157. wmb();
  6158. /* set next_to_watch value indicating a packet is present */
  6159. first->next_to_watch = tx_desc;
  6160. i++;
  6161. if (i == tx_ring->count)
  6162. i = 0;
  6163. tx_ring->next_to_use = i;
  6164. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  6165. if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
  6166. writel(i, tx_ring->tail);
  6167. /* we need this if more than one processor can write to our tail
  6168. * at a time, it synchronizes IO on IA64/Altix systems
  6169. */
  6170. mmiowb();
  6171. }
  6172. return;
  6173. dma_error:
  6174. dev_err(tx_ring->dev, "TX DMA map failed\n");
  6175. /* clear dma mappings for failed tx_buffer_info map */
  6176. for (;;) {
  6177. tx_buffer = &tx_ring->tx_buffer_info[i];
  6178. ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
  6179. if (tx_buffer == first)
  6180. break;
  6181. if (i == 0)
  6182. i = tx_ring->count;
  6183. i--;
  6184. }
  6185. tx_ring->next_to_use = i;
  6186. }
  6187. static void ixgbe_atr(struct ixgbe_ring *ring,
  6188. struct ixgbe_tx_buffer *first)
  6189. {
  6190. struct ixgbe_q_vector *q_vector = ring->q_vector;
  6191. union ixgbe_atr_hash_dword input = { .dword = 0 };
  6192. union ixgbe_atr_hash_dword common = { .dword = 0 };
  6193. union {
  6194. unsigned char *network;
  6195. struct iphdr *ipv4;
  6196. struct ipv6hdr *ipv6;
  6197. } hdr;
  6198. struct tcphdr *th;
  6199. struct sk_buff *skb;
  6200. #ifdef CONFIG_IXGBE_VXLAN
  6201. u8 encap = false;
  6202. #endif /* CONFIG_IXGBE_VXLAN */
  6203. __be16 vlan_id;
  6204. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  6205. if (!q_vector)
  6206. return;
  6207. /* do nothing if sampling is disabled */
  6208. if (!ring->atr_sample_rate)
  6209. return;
  6210. ring->atr_count++;
  6211. /* snag network header to get L4 type and address */
  6212. skb = first->skb;
  6213. hdr.network = skb_network_header(skb);
  6214. if (skb->encapsulation) {
  6215. #ifdef CONFIG_IXGBE_VXLAN
  6216. struct ixgbe_adapter *adapter = q_vector->adapter;
  6217. if (!adapter->vxlan_port)
  6218. return;
  6219. if (first->protocol != htons(ETH_P_IP) ||
  6220. hdr.ipv4->version != IPVERSION ||
  6221. hdr.ipv4->protocol != IPPROTO_UDP) {
  6222. return;
  6223. }
  6224. if (ntohs(udp_hdr(skb)->dest) != adapter->vxlan_port)
  6225. return;
  6226. encap = true;
  6227. hdr.network = skb_inner_network_header(skb);
  6228. th = inner_tcp_hdr(skb);
  6229. #else
  6230. return;
  6231. #endif /* CONFIG_IXGBE_VXLAN */
  6232. } else {
  6233. /* Currently only IPv4/IPv6 with TCP is supported */
  6234. if ((first->protocol != htons(ETH_P_IPV6) ||
  6235. hdr.ipv6->nexthdr != IPPROTO_TCP) &&
  6236. (first->protocol != htons(ETH_P_IP) ||
  6237. hdr.ipv4->protocol != IPPROTO_TCP))
  6238. return;
  6239. th = tcp_hdr(skb);
  6240. }
  6241. /* skip this packet since it is invalid or the socket is closing */
  6242. if (!th || th->fin)
  6243. return;
  6244. /* sample on all syn packets or once every atr sample count */
  6245. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  6246. return;
  6247. /* reset sample count */
  6248. ring->atr_count = 0;
  6249. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  6250. /*
  6251. * src and dst are inverted, think how the receiver sees them
  6252. *
  6253. * The input is broken into two sections, a non-compressed section
  6254. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  6255. * is XORed together and stored in the compressed dword.
  6256. */
  6257. input.formatted.vlan_id = vlan_id;
  6258. /*
  6259. * since src port and flex bytes occupy the same word XOR them together
  6260. * and write the value to source port portion of compressed dword
  6261. */
  6262. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  6263. common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
  6264. else
  6265. common.port.src ^= th->dest ^ first->protocol;
  6266. common.port.dst ^= th->source;
  6267. if (first->protocol == htons(ETH_P_IP)) {
  6268. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  6269. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  6270. } else {
  6271. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  6272. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  6273. hdr.ipv6->saddr.s6_addr32[1] ^
  6274. hdr.ipv6->saddr.s6_addr32[2] ^
  6275. hdr.ipv6->saddr.s6_addr32[3] ^
  6276. hdr.ipv6->daddr.s6_addr32[0] ^
  6277. hdr.ipv6->daddr.s6_addr32[1] ^
  6278. hdr.ipv6->daddr.s6_addr32[2] ^
  6279. hdr.ipv6->daddr.s6_addr32[3];
  6280. }
  6281. #ifdef CONFIG_IXGBE_VXLAN
  6282. if (encap)
  6283. input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
  6284. #endif /* CONFIG_IXGBE_VXLAN */
  6285. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  6286. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  6287. input, common, ring->queue_index);
  6288. }
  6289. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
  6290. void *accel_priv, select_queue_fallback_t fallback)
  6291. {
  6292. struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
  6293. #ifdef IXGBE_FCOE
  6294. struct ixgbe_adapter *adapter;
  6295. struct ixgbe_ring_feature *f;
  6296. int txq;
  6297. #endif
  6298. if (fwd_adapter)
  6299. return skb->queue_mapping + fwd_adapter->tx_base_queue;
  6300. #ifdef IXGBE_FCOE
  6301. /*
  6302. * only execute the code below if protocol is FCoE
  6303. * or FIP and we have FCoE enabled on the adapter
  6304. */
  6305. switch (vlan_get_protocol(skb)) {
  6306. case htons(ETH_P_FCOE):
  6307. case htons(ETH_P_FIP):
  6308. adapter = netdev_priv(dev);
  6309. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  6310. break;
  6311. default:
  6312. return fallback(dev, skb);
  6313. }
  6314. f = &adapter->ring_feature[RING_F_FCOE];
  6315. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  6316. smp_processor_id();
  6317. while (txq >= f->indices)
  6318. txq -= f->indices;
  6319. return txq + f->offset;
  6320. #else
  6321. return fallback(dev, skb);
  6322. #endif
  6323. }
  6324. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  6325. struct ixgbe_adapter *adapter,
  6326. struct ixgbe_ring *tx_ring)
  6327. {
  6328. struct ixgbe_tx_buffer *first;
  6329. int tso;
  6330. u32 tx_flags = 0;
  6331. unsigned short f;
  6332. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  6333. __be16 protocol = skb->protocol;
  6334. u8 hdr_len = 0;
  6335. /*
  6336. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  6337. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  6338. * + 2 desc gap to keep tail from touching head,
  6339. * + 1 desc for context descriptor,
  6340. * otherwise try next time
  6341. */
  6342. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  6343. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  6344. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  6345. tx_ring->tx_stats.tx_busy++;
  6346. return NETDEV_TX_BUSY;
  6347. }
  6348. /* record the location of the first descriptor for this packet */
  6349. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  6350. first->skb = skb;
  6351. first->bytecount = skb->len;
  6352. first->gso_segs = 1;
  6353. /* if we have a HW VLAN tag being added default to the HW one */
  6354. if (skb_vlan_tag_present(skb)) {
  6355. tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  6356. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  6357. /* else if it is a SW VLAN check the next protocol and store the tag */
  6358. } else if (protocol == htons(ETH_P_8021Q)) {
  6359. struct vlan_hdr *vhdr, _vhdr;
  6360. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  6361. if (!vhdr)
  6362. goto out_drop;
  6363. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  6364. IXGBE_TX_FLAGS_VLAN_SHIFT;
  6365. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  6366. }
  6367. protocol = vlan_get_protocol(skb);
  6368. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  6369. adapter->ptp_clock &&
  6370. !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
  6371. &adapter->state)) {
  6372. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  6373. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  6374. /* schedule check for Tx timestamp */
  6375. adapter->ptp_tx_skb = skb_get(skb);
  6376. adapter->ptp_tx_start = jiffies;
  6377. schedule_work(&adapter->ptp_tx_work);
  6378. }
  6379. skb_tx_timestamp(skb);
  6380. #ifdef CONFIG_PCI_IOV
  6381. /*
  6382. * Use the l2switch_enable flag - would be false if the DMA
  6383. * Tx switch had been disabled.
  6384. */
  6385. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6386. tx_flags |= IXGBE_TX_FLAGS_CC;
  6387. #endif
  6388. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  6389. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  6390. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  6391. (skb->priority != TC_PRIO_CONTROL))) {
  6392. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  6393. tx_flags |= (skb->priority & 0x7) <<
  6394. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  6395. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  6396. struct vlan_ethhdr *vhdr;
  6397. if (skb_cow_head(skb, 0))
  6398. goto out_drop;
  6399. vhdr = (struct vlan_ethhdr *)skb->data;
  6400. vhdr->h_vlan_TCI = htons(tx_flags >>
  6401. IXGBE_TX_FLAGS_VLAN_SHIFT);
  6402. } else {
  6403. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  6404. }
  6405. }
  6406. /* record initial flags and protocol */
  6407. first->tx_flags = tx_flags;
  6408. first->protocol = protocol;
  6409. #ifdef IXGBE_FCOE
  6410. /* setup tx offload for FCoE */
  6411. if ((protocol == htons(ETH_P_FCOE)) &&
  6412. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  6413. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  6414. if (tso < 0)
  6415. goto out_drop;
  6416. goto xmit_fcoe;
  6417. }
  6418. #endif /* IXGBE_FCOE */
  6419. tso = ixgbe_tso(tx_ring, first, &hdr_len);
  6420. if (tso < 0)
  6421. goto out_drop;
  6422. else if (!tso)
  6423. ixgbe_tx_csum(tx_ring, first);
  6424. /* add the ATR filter if ATR is on */
  6425. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  6426. ixgbe_atr(tx_ring, first);
  6427. #ifdef IXGBE_FCOE
  6428. xmit_fcoe:
  6429. #endif /* IXGBE_FCOE */
  6430. ixgbe_tx_map(tx_ring, first, hdr_len);
  6431. return NETDEV_TX_OK;
  6432. out_drop:
  6433. dev_kfree_skb_any(first->skb);
  6434. first->skb = NULL;
  6435. return NETDEV_TX_OK;
  6436. }
  6437. static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
  6438. struct net_device *netdev,
  6439. struct ixgbe_ring *ring)
  6440. {
  6441. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6442. struct ixgbe_ring *tx_ring;
  6443. /*
  6444. * The minimum packet size for olinfo paylen is 17 so pad the skb
  6445. * in order to meet this minimum size requirement.
  6446. */
  6447. if (skb_put_padto(skb, 17))
  6448. return NETDEV_TX_OK;
  6449. tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
  6450. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  6451. }
  6452. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  6453. struct net_device *netdev)
  6454. {
  6455. return __ixgbe_xmit_frame(skb, netdev, NULL);
  6456. }
  6457. /**
  6458. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  6459. * @netdev: network interface device structure
  6460. * @p: pointer to an address structure
  6461. *
  6462. * Returns 0 on success, negative on failure
  6463. **/
  6464. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  6465. {
  6466. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6467. struct ixgbe_hw *hw = &adapter->hw;
  6468. struct sockaddr *addr = p;
  6469. int ret;
  6470. if (!is_valid_ether_addr(addr->sa_data))
  6471. return -EADDRNOTAVAIL;
  6472. ixgbe_del_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
  6473. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  6474. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  6475. ret = ixgbe_add_mac_filter(adapter, hw->mac.addr, VMDQ_P(0));
  6476. return ret > 0 ? 0 : ret;
  6477. }
  6478. static int
  6479. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  6480. {
  6481. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6482. struct ixgbe_hw *hw = &adapter->hw;
  6483. u16 value;
  6484. int rc;
  6485. if (prtad != hw->phy.mdio.prtad)
  6486. return -EINVAL;
  6487. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  6488. if (!rc)
  6489. rc = value;
  6490. return rc;
  6491. }
  6492. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  6493. u16 addr, u16 value)
  6494. {
  6495. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6496. struct ixgbe_hw *hw = &adapter->hw;
  6497. if (prtad != hw->phy.mdio.prtad)
  6498. return -EINVAL;
  6499. return hw->phy.ops.write_reg(hw, addr, devad, value);
  6500. }
  6501. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  6502. {
  6503. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6504. switch (cmd) {
  6505. case SIOCSHWTSTAMP:
  6506. return ixgbe_ptp_set_ts_config(adapter, req);
  6507. case SIOCGHWTSTAMP:
  6508. return ixgbe_ptp_get_ts_config(adapter, req);
  6509. default:
  6510. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  6511. }
  6512. }
  6513. /**
  6514. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  6515. * netdev->dev_addrs
  6516. * @netdev: network interface device structure
  6517. *
  6518. * Returns non-zero on failure
  6519. **/
  6520. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  6521. {
  6522. int err = 0;
  6523. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6524. struct ixgbe_hw *hw = &adapter->hw;
  6525. if (is_valid_ether_addr(hw->mac.san_addr)) {
  6526. rtnl_lock();
  6527. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  6528. rtnl_unlock();
  6529. /* update SAN MAC vmdq pool selection */
  6530. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  6531. }
  6532. return err;
  6533. }
  6534. /**
  6535. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  6536. * netdev->dev_addrs
  6537. * @netdev: network interface device structure
  6538. *
  6539. * Returns non-zero on failure
  6540. **/
  6541. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  6542. {
  6543. int err = 0;
  6544. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6545. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  6546. if (is_valid_ether_addr(mac->san_addr)) {
  6547. rtnl_lock();
  6548. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  6549. rtnl_unlock();
  6550. }
  6551. return err;
  6552. }
  6553. #ifdef CONFIG_NET_POLL_CONTROLLER
  6554. /*
  6555. * Polling 'interrupt' - used by things like netconsole to send skbs
  6556. * without having to re-enable interrupts. It's not called while
  6557. * the interrupt routine is executing.
  6558. */
  6559. static void ixgbe_netpoll(struct net_device *netdev)
  6560. {
  6561. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6562. int i;
  6563. /* if interface is down do nothing */
  6564. if (test_bit(__IXGBE_DOWN, &adapter->state))
  6565. return;
  6566. /* loop through and schedule all active queues */
  6567. for (i = 0; i < adapter->num_q_vectors; i++)
  6568. ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
  6569. }
  6570. #endif
  6571. static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
  6572. struct rtnl_link_stats64 *stats)
  6573. {
  6574. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6575. int i;
  6576. rcu_read_lock();
  6577. for (i = 0; i < adapter->num_rx_queues; i++) {
  6578. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
  6579. u64 bytes, packets;
  6580. unsigned int start;
  6581. if (ring) {
  6582. do {
  6583. start = u64_stats_fetch_begin_irq(&ring->syncp);
  6584. packets = ring->stats.packets;
  6585. bytes = ring->stats.bytes;
  6586. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  6587. stats->rx_packets += packets;
  6588. stats->rx_bytes += bytes;
  6589. }
  6590. }
  6591. for (i = 0; i < adapter->num_tx_queues; i++) {
  6592. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
  6593. u64 bytes, packets;
  6594. unsigned int start;
  6595. if (ring) {
  6596. do {
  6597. start = u64_stats_fetch_begin_irq(&ring->syncp);
  6598. packets = ring->stats.packets;
  6599. bytes = ring->stats.bytes;
  6600. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  6601. stats->tx_packets += packets;
  6602. stats->tx_bytes += bytes;
  6603. }
  6604. }
  6605. rcu_read_unlock();
  6606. /* following stats updated by ixgbe_watchdog_task() */
  6607. stats->multicast = netdev->stats.multicast;
  6608. stats->rx_errors = netdev->stats.rx_errors;
  6609. stats->rx_length_errors = netdev->stats.rx_length_errors;
  6610. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  6611. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  6612. return stats;
  6613. }
  6614. #ifdef CONFIG_IXGBE_DCB
  6615. /**
  6616. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  6617. * @adapter: pointer to ixgbe_adapter
  6618. * @tc: number of traffic classes currently enabled
  6619. *
  6620. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  6621. * 802.1Q priority maps to a packet buffer that exists.
  6622. */
  6623. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  6624. {
  6625. struct ixgbe_hw *hw = &adapter->hw;
  6626. u32 reg, rsave;
  6627. int i;
  6628. /* 82598 have a static priority to TC mapping that can not
  6629. * be changed so no validation is needed.
  6630. */
  6631. if (hw->mac.type == ixgbe_mac_82598EB)
  6632. return;
  6633. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  6634. rsave = reg;
  6635. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  6636. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  6637. /* If up2tc is out of bounds default to zero */
  6638. if (up2tc > tc)
  6639. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  6640. }
  6641. if (reg != rsave)
  6642. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  6643. return;
  6644. }
  6645. /**
  6646. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  6647. * @adapter: Pointer to adapter struct
  6648. *
  6649. * Populate the netdev user priority to tc map
  6650. */
  6651. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  6652. {
  6653. struct net_device *dev = adapter->netdev;
  6654. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  6655. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  6656. u8 prio;
  6657. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  6658. u8 tc = 0;
  6659. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  6660. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  6661. else if (ets)
  6662. tc = ets->prio_tc[prio];
  6663. netdev_set_prio_tc_map(dev, prio, tc);
  6664. }
  6665. }
  6666. #endif /* CONFIG_IXGBE_DCB */
  6667. /**
  6668. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  6669. *
  6670. * @netdev: net device to configure
  6671. * @tc: number of traffic classes to enable
  6672. */
  6673. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  6674. {
  6675. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6676. struct ixgbe_hw *hw = &adapter->hw;
  6677. bool pools;
  6678. /* Hardware supports up to 8 traffic classes */
  6679. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
  6680. return -EINVAL;
  6681. if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
  6682. return -EINVAL;
  6683. pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
  6684. if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
  6685. return -EBUSY;
  6686. /* Hardware has to reinitialize queues and interrupts to
  6687. * match packet buffer alignment. Unfortunately, the
  6688. * hardware is not flexible enough to do this dynamically.
  6689. */
  6690. if (netif_running(dev))
  6691. ixgbe_close(dev);
  6692. ixgbe_clear_interrupt_scheme(adapter);
  6693. #ifdef CONFIG_IXGBE_DCB
  6694. if (tc) {
  6695. netdev_set_num_tc(dev, tc);
  6696. ixgbe_set_prio_tc_map(adapter);
  6697. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  6698. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  6699. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  6700. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  6701. }
  6702. } else {
  6703. netdev_reset_tc(dev);
  6704. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  6705. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  6706. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  6707. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  6708. adapter->dcb_cfg.pfc_mode_enable = false;
  6709. }
  6710. ixgbe_validate_rtr(adapter, tc);
  6711. #endif /* CONFIG_IXGBE_DCB */
  6712. ixgbe_init_interrupt_scheme(adapter);
  6713. if (netif_running(dev))
  6714. return ixgbe_open(dev);
  6715. return 0;
  6716. }
  6717. #ifdef CONFIG_PCI_IOV
  6718. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  6719. {
  6720. struct net_device *netdev = adapter->netdev;
  6721. rtnl_lock();
  6722. ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
  6723. rtnl_unlock();
  6724. }
  6725. #endif
  6726. void ixgbe_do_reset(struct net_device *netdev)
  6727. {
  6728. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6729. if (netif_running(netdev))
  6730. ixgbe_reinit_locked(adapter);
  6731. else
  6732. ixgbe_reset(adapter);
  6733. }
  6734. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  6735. netdev_features_t features)
  6736. {
  6737. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6738. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  6739. if (!(features & NETIF_F_RXCSUM))
  6740. features &= ~NETIF_F_LRO;
  6741. /* Turn off LRO if not RSC capable */
  6742. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  6743. features &= ~NETIF_F_LRO;
  6744. return features;
  6745. }
  6746. static int ixgbe_set_features(struct net_device *netdev,
  6747. netdev_features_t features)
  6748. {
  6749. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6750. netdev_features_t changed = netdev->features ^ features;
  6751. bool need_reset = false;
  6752. /* Make sure RSC matches LRO, reset if change */
  6753. if (!(features & NETIF_F_LRO)) {
  6754. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  6755. need_reset = true;
  6756. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  6757. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  6758. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  6759. if (adapter->rx_itr_setting == 1 ||
  6760. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  6761. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  6762. need_reset = true;
  6763. } else if ((changed ^ features) & NETIF_F_LRO) {
  6764. e_info(probe, "rx-usecs set too low, "
  6765. "disabling RSC\n");
  6766. }
  6767. }
  6768. /*
  6769. * Check if Flow Director n-tuple support was enabled or disabled. If
  6770. * the state changed, we need to reset.
  6771. */
  6772. switch (features & NETIF_F_NTUPLE) {
  6773. case NETIF_F_NTUPLE:
  6774. /* turn off ATR, enable perfect filters and reset */
  6775. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  6776. need_reset = true;
  6777. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  6778. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  6779. break;
  6780. default:
  6781. /* turn off perfect filters, enable ATR and reset */
  6782. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  6783. need_reset = true;
  6784. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  6785. /* We cannot enable ATR if SR-IOV is enabled */
  6786. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6787. break;
  6788. /* We cannot enable ATR if we have 2 or more traffic classes */
  6789. if (netdev_get_num_tc(netdev) > 1)
  6790. break;
  6791. /* We cannot enable ATR if RSS is disabled */
  6792. if (adapter->ring_feature[RING_F_RSS].limit <= 1)
  6793. break;
  6794. /* A sample rate of 0 indicates ATR disabled */
  6795. if (!adapter->atr_sample_rate)
  6796. break;
  6797. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  6798. break;
  6799. }
  6800. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  6801. ixgbe_vlan_strip_enable(adapter);
  6802. else
  6803. ixgbe_vlan_strip_disable(adapter);
  6804. if (changed & NETIF_F_RXALL)
  6805. need_reset = true;
  6806. netdev->features = features;
  6807. #ifdef CONFIG_IXGBE_VXLAN
  6808. if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
  6809. if (features & NETIF_F_RXCSUM)
  6810. adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED;
  6811. else
  6812. ixgbe_clear_vxlan_port(adapter);
  6813. }
  6814. #endif /* CONFIG_IXGBE_VXLAN */
  6815. if (need_reset)
  6816. ixgbe_do_reset(netdev);
  6817. return 0;
  6818. }
  6819. #ifdef CONFIG_IXGBE_VXLAN
  6820. /**
  6821. * ixgbe_add_vxlan_port - Get notifications about VXLAN ports that come up
  6822. * @dev: The port's netdev
  6823. * @sa_family: Socket Family that VXLAN is notifiying us about
  6824. * @port: New UDP port number that VXLAN started listening to
  6825. **/
  6826. static void ixgbe_add_vxlan_port(struct net_device *dev, sa_family_t sa_family,
  6827. __be16 port)
  6828. {
  6829. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6830. struct ixgbe_hw *hw = &adapter->hw;
  6831. u16 new_port = ntohs(port);
  6832. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  6833. return;
  6834. if (sa_family == AF_INET6)
  6835. return;
  6836. if (adapter->vxlan_port == new_port)
  6837. return;
  6838. if (adapter->vxlan_port) {
  6839. netdev_info(dev,
  6840. "Hit Max num of VXLAN ports, not adding port %d\n",
  6841. new_port);
  6842. return;
  6843. }
  6844. adapter->vxlan_port = new_port;
  6845. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, new_port);
  6846. }
  6847. /**
  6848. * ixgbe_del_vxlan_port - Get notifications about VXLAN ports that go away
  6849. * @dev: The port's netdev
  6850. * @sa_family: Socket Family that VXLAN is notifying us about
  6851. * @port: UDP port number that VXLAN stopped listening to
  6852. **/
  6853. static void ixgbe_del_vxlan_port(struct net_device *dev, sa_family_t sa_family,
  6854. __be16 port)
  6855. {
  6856. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6857. u16 new_port = ntohs(port);
  6858. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  6859. return;
  6860. if (sa_family == AF_INET6)
  6861. return;
  6862. if (adapter->vxlan_port != new_port) {
  6863. netdev_info(dev, "Port %d was not found, not deleting\n",
  6864. new_port);
  6865. return;
  6866. }
  6867. ixgbe_clear_vxlan_port(adapter);
  6868. adapter->flags2 |= IXGBE_FLAG2_VXLAN_REREG_NEEDED;
  6869. }
  6870. #endif /* CONFIG_IXGBE_VXLAN */
  6871. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  6872. struct net_device *dev,
  6873. const unsigned char *addr, u16 vid,
  6874. u16 flags)
  6875. {
  6876. /* guarantee we can provide a unique filter for the unicast address */
  6877. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  6878. if (IXGBE_MAX_PF_MACVLANS <= netdev_uc_count(dev))
  6879. return -ENOMEM;
  6880. }
  6881. return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
  6882. }
  6883. /**
  6884. * ixgbe_configure_bridge_mode - set various bridge modes
  6885. * @adapter - the private structure
  6886. * @mode - requested bridge mode
  6887. *
  6888. * Configure some settings require for various bridge modes.
  6889. **/
  6890. static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
  6891. __u16 mode)
  6892. {
  6893. struct ixgbe_hw *hw = &adapter->hw;
  6894. unsigned int p, num_pools;
  6895. u32 vmdctl;
  6896. switch (mode) {
  6897. case BRIDGE_MODE_VEPA:
  6898. /* disable Tx loopback, rely on switch hairpin mode */
  6899. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
  6900. /* must enable Rx switching replication to allow multicast
  6901. * packet reception on all VFs, and to enable source address
  6902. * pruning.
  6903. */
  6904. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  6905. vmdctl |= IXGBE_VT_CTL_REPLEN;
  6906. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  6907. /* enable Rx source address pruning. Note, this requires
  6908. * replication to be enabled or else it does nothing.
  6909. */
  6910. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  6911. for (p = 0; p < num_pools; p++) {
  6912. if (hw->mac.ops.set_source_address_pruning)
  6913. hw->mac.ops.set_source_address_pruning(hw,
  6914. true,
  6915. p);
  6916. }
  6917. break;
  6918. case BRIDGE_MODE_VEB:
  6919. /* enable Tx loopback for internal VF/PF communication */
  6920. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
  6921. IXGBE_PFDTXGSWC_VT_LBEN);
  6922. /* disable Rx switching replication unless we have SR-IOV
  6923. * virtual functions
  6924. */
  6925. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  6926. if (!adapter->num_vfs)
  6927. vmdctl &= ~IXGBE_VT_CTL_REPLEN;
  6928. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  6929. /* disable Rx source address pruning, since we don't expect to
  6930. * be receiving external loopback of our transmitted frames.
  6931. */
  6932. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  6933. for (p = 0; p < num_pools; p++) {
  6934. if (hw->mac.ops.set_source_address_pruning)
  6935. hw->mac.ops.set_source_address_pruning(hw,
  6936. false,
  6937. p);
  6938. }
  6939. break;
  6940. default:
  6941. return -EINVAL;
  6942. }
  6943. adapter->bridge_mode = mode;
  6944. e_info(drv, "enabling bridge mode: %s\n",
  6945. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  6946. return 0;
  6947. }
  6948. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  6949. struct nlmsghdr *nlh, u16 flags)
  6950. {
  6951. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6952. struct nlattr *attr, *br_spec;
  6953. int rem;
  6954. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  6955. return -EOPNOTSUPP;
  6956. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  6957. if (!br_spec)
  6958. return -EINVAL;
  6959. nla_for_each_nested(attr, br_spec, rem) {
  6960. int status;
  6961. __u16 mode;
  6962. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  6963. continue;
  6964. if (nla_len(attr) < sizeof(mode))
  6965. return -EINVAL;
  6966. mode = nla_get_u16(attr);
  6967. status = ixgbe_configure_bridge_mode(adapter, mode);
  6968. if (status)
  6969. return status;
  6970. break;
  6971. }
  6972. return 0;
  6973. }
  6974. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  6975. struct net_device *dev,
  6976. u32 filter_mask, int nlflags)
  6977. {
  6978. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6979. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  6980. return 0;
  6981. return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
  6982. adapter->bridge_mode, 0, 0, nlflags,
  6983. filter_mask, NULL);
  6984. }
  6985. static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
  6986. {
  6987. struct ixgbe_fwd_adapter *fwd_adapter = NULL;
  6988. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  6989. int used_pools = adapter->num_vfs + adapter->num_rx_pools;
  6990. unsigned int limit;
  6991. int pool, err;
  6992. /* Hardware has a limited number of available pools. Each VF, and the
  6993. * PF require a pool. Check to ensure we don't attempt to use more
  6994. * then the available number of pools.
  6995. */
  6996. if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
  6997. return ERR_PTR(-EINVAL);
  6998. #ifdef CONFIG_RPS
  6999. if (vdev->num_rx_queues != vdev->num_tx_queues) {
  7000. netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
  7001. vdev->name);
  7002. return ERR_PTR(-EINVAL);
  7003. }
  7004. #endif
  7005. /* Check for hardware restriction on number of rx/tx queues */
  7006. if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
  7007. vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
  7008. netdev_info(pdev,
  7009. "%s: Supports RX/TX Queue counts 1,2, and 4\n",
  7010. pdev->name);
  7011. return ERR_PTR(-EINVAL);
  7012. }
  7013. if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  7014. adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
  7015. (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
  7016. return ERR_PTR(-EBUSY);
  7017. fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
  7018. if (!fwd_adapter)
  7019. return ERR_PTR(-ENOMEM);
  7020. pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
  7021. adapter->num_rx_pools++;
  7022. set_bit(pool, &adapter->fwd_bitmask);
  7023. limit = find_last_bit(&adapter->fwd_bitmask, 32);
  7024. /* Enable VMDq flag so device will be set in VM mode */
  7025. adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
  7026. adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
  7027. adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
  7028. /* Force reinit of ring allocation with VMDQ enabled */
  7029. err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
  7030. if (err)
  7031. goto fwd_add_err;
  7032. fwd_adapter->pool = pool;
  7033. fwd_adapter->real_adapter = adapter;
  7034. err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
  7035. if (err)
  7036. goto fwd_add_err;
  7037. netif_tx_start_all_queues(vdev);
  7038. return fwd_adapter;
  7039. fwd_add_err:
  7040. /* unwind counter and free adapter struct */
  7041. netdev_info(pdev,
  7042. "%s: dfwd hardware acceleration failed\n", vdev->name);
  7043. clear_bit(pool, &adapter->fwd_bitmask);
  7044. adapter->num_rx_pools--;
  7045. kfree(fwd_adapter);
  7046. return ERR_PTR(err);
  7047. }
  7048. static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
  7049. {
  7050. struct ixgbe_fwd_adapter *fwd_adapter = priv;
  7051. struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
  7052. unsigned int limit;
  7053. clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
  7054. adapter->num_rx_pools--;
  7055. limit = find_last_bit(&adapter->fwd_bitmask, 32);
  7056. adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
  7057. ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
  7058. ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
  7059. netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
  7060. fwd_adapter->pool, adapter->num_rx_pools,
  7061. fwd_adapter->rx_base_queue,
  7062. fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
  7063. adapter->fwd_bitmask);
  7064. kfree(fwd_adapter);
  7065. }
  7066. #define IXGBE_MAX_TUNNEL_HDR_LEN 80
  7067. static netdev_features_t
  7068. ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
  7069. netdev_features_t features)
  7070. {
  7071. if (!skb->encapsulation)
  7072. return features;
  7073. if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) >
  7074. IXGBE_MAX_TUNNEL_HDR_LEN))
  7075. return features & ~NETIF_F_ALL_CSUM;
  7076. return features;
  7077. }
  7078. static const struct net_device_ops ixgbe_netdev_ops = {
  7079. .ndo_open = ixgbe_open,
  7080. .ndo_stop = ixgbe_close,
  7081. .ndo_start_xmit = ixgbe_xmit_frame,
  7082. .ndo_select_queue = ixgbe_select_queue,
  7083. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  7084. .ndo_validate_addr = eth_validate_addr,
  7085. .ndo_set_mac_address = ixgbe_set_mac,
  7086. .ndo_change_mtu = ixgbe_change_mtu,
  7087. .ndo_tx_timeout = ixgbe_tx_timeout,
  7088. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  7089. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  7090. .ndo_do_ioctl = ixgbe_ioctl,
  7091. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  7092. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  7093. .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
  7094. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  7095. .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
  7096. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  7097. .ndo_get_stats64 = ixgbe_get_stats64,
  7098. #ifdef CONFIG_IXGBE_DCB
  7099. .ndo_setup_tc = ixgbe_setup_tc,
  7100. #endif
  7101. #ifdef CONFIG_NET_POLL_CONTROLLER
  7102. .ndo_poll_controller = ixgbe_netpoll,
  7103. #endif
  7104. #ifdef CONFIG_NET_RX_BUSY_POLL
  7105. .ndo_busy_poll = ixgbe_low_latency_recv,
  7106. #endif
  7107. #ifdef IXGBE_FCOE
  7108. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  7109. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  7110. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  7111. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  7112. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  7113. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  7114. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  7115. #endif /* IXGBE_FCOE */
  7116. .ndo_set_features = ixgbe_set_features,
  7117. .ndo_fix_features = ixgbe_fix_features,
  7118. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  7119. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  7120. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  7121. .ndo_dfwd_add_station = ixgbe_fwd_add,
  7122. .ndo_dfwd_del_station = ixgbe_fwd_del,
  7123. #ifdef CONFIG_IXGBE_VXLAN
  7124. .ndo_add_vxlan_port = ixgbe_add_vxlan_port,
  7125. .ndo_del_vxlan_port = ixgbe_del_vxlan_port,
  7126. #endif /* CONFIG_IXGBE_VXLAN */
  7127. .ndo_features_check = ixgbe_features_check,
  7128. };
  7129. /**
  7130. * ixgbe_enumerate_functions - Get the number of ports this device has
  7131. * @adapter: adapter structure
  7132. *
  7133. * This function enumerates the phsyical functions co-located on a single slot,
  7134. * in order to determine how many ports a device has. This is most useful in
  7135. * determining the required GT/s of PCIe bandwidth necessary for optimal
  7136. * performance.
  7137. **/
  7138. static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
  7139. {
  7140. struct pci_dev *entry, *pdev = adapter->pdev;
  7141. int physfns = 0;
  7142. /* Some cards can not use the generic count PCIe functions method,
  7143. * because they are behind a parent switch, so we hardcode these with
  7144. * the correct number of functions.
  7145. */
  7146. if (ixgbe_pcie_from_parent(&adapter->hw))
  7147. physfns = 4;
  7148. list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
  7149. /* don't count virtual functions */
  7150. if (entry->is_virtfn)
  7151. continue;
  7152. /* When the devices on the bus don't all match our device ID,
  7153. * we can't reliably determine the correct number of
  7154. * functions. This can occur if a function has been direct
  7155. * attached to a virtual machine using VT-d, for example. In
  7156. * this case, simply return -1 to indicate this.
  7157. */
  7158. if ((entry->vendor != pdev->vendor) ||
  7159. (entry->device != pdev->device))
  7160. return -1;
  7161. physfns++;
  7162. }
  7163. return physfns;
  7164. }
  7165. /**
  7166. * ixgbe_wol_supported - Check whether device supports WoL
  7167. * @hw: hw specific details
  7168. * @device_id: the device ID
  7169. * @subdev_id: the subsystem device ID
  7170. *
  7171. * This function is used by probe and ethtool to determine
  7172. * which devices have WoL support
  7173. *
  7174. **/
  7175. int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  7176. u16 subdevice_id)
  7177. {
  7178. struct ixgbe_hw *hw = &adapter->hw;
  7179. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  7180. int is_wol_supported = 0;
  7181. switch (device_id) {
  7182. case IXGBE_DEV_ID_82599_SFP:
  7183. /* Only these subdevices could supports WOL */
  7184. switch (subdevice_id) {
  7185. case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
  7186. case IXGBE_SUBDEV_ID_82599_560FLR:
  7187. /* only support first port */
  7188. if (hw->bus.func != 0)
  7189. break;
  7190. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  7191. case IXGBE_SUBDEV_ID_82599_SFP:
  7192. case IXGBE_SUBDEV_ID_82599_RNDC:
  7193. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  7194. case IXGBE_SUBDEV_ID_82599_LOM_SFP:
  7195. is_wol_supported = 1;
  7196. break;
  7197. }
  7198. break;
  7199. case IXGBE_DEV_ID_82599EN_SFP:
  7200. /* Only this subdevice supports WOL */
  7201. switch (subdevice_id) {
  7202. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  7203. is_wol_supported = 1;
  7204. break;
  7205. }
  7206. break;
  7207. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  7208. /* All except this subdevice support WOL */
  7209. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  7210. is_wol_supported = 1;
  7211. break;
  7212. case IXGBE_DEV_ID_82599_KX4:
  7213. is_wol_supported = 1;
  7214. break;
  7215. case IXGBE_DEV_ID_X540T:
  7216. case IXGBE_DEV_ID_X540T1:
  7217. case IXGBE_DEV_ID_X550T:
  7218. case IXGBE_DEV_ID_X550EM_X_KX4:
  7219. case IXGBE_DEV_ID_X550EM_X_KR:
  7220. case IXGBE_DEV_ID_X550EM_X_10G_T:
  7221. /* check eeprom to see if enabled wol */
  7222. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  7223. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  7224. (hw->bus.func == 0))) {
  7225. is_wol_supported = 1;
  7226. }
  7227. break;
  7228. }
  7229. return is_wol_supported;
  7230. }
  7231. /**
  7232. * ixgbe_get_platform_mac_addr - Look up MAC address in Open Firmware / IDPROM
  7233. * @adapter: Pointer to adapter struct
  7234. */
  7235. static void ixgbe_get_platform_mac_addr(struct ixgbe_adapter *adapter)
  7236. {
  7237. #ifdef CONFIG_OF
  7238. struct device_node *dp = pci_device_to_OF_node(adapter->pdev);
  7239. struct ixgbe_hw *hw = &adapter->hw;
  7240. const unsigned char *addr;
  7241. addr = of_get_mac_address(dp);
  7242. if (addr) {
  7243. ether_addr_copy(hw->mac.perm_addr, addr);
  7244. return;
  7245. }
  7246. #endif /* CONFIG_OF */
  7247. #ifdef CONFIG_SPARC
  7248. ether_addr_copy(hw->mac.perm_addr, idprom->id_ethaddr);
  7249. #endif /* CONFIG_SPARC */
  7250. }
  7251. /**
  7252. * ixgbe_probe - Device Initialization Routine
  7253. * @pdev: PCI device information struct
  7254. * @ent: entry in ixgbe_pci_tbl
  7255. *
  7256. * Returns 0 on success, negative on failure
  7257. *
  7258. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  7259. * The OS initialization, configuring of the adapter private structure,
  7260. * and a hardware reset occur.
  7261. **/
  7262. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  7263. {
  7264. struct net_device *netdev;
  7265. struct ixgbe_adapter *adapter = NULL;
  7266. struct ixgbe_hw *hw;
  7267. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  7268. int i, err, pci_using_dac, expected_gts;
  7269. unsigned int indices = MAX_TX_QUEUES;
  7270. u8 part_str[IXGBE_PBANUM_LENGTH];
  7271. bool disable_dev = false;
  7272. #ifdef IXGBE_FCOE
  7273. u16 device_caps;
  7274. #endif
  7275. u32 eec;
  7276. /* Catch broken hardware that put the wrong VF device ID in
  7277. * the PCIe SR-IOV capability.
  7278. */
  7279. if (pdev->is_virtfn) {
  7280. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  7281. pci_name(pdev), pdev->vendor, pdev->device);
  7282. return -EINVAL;
  7283. }
  7284. err = pci_enable_device_mem(pdev);
  7285. if (err)
  7286. return err;
  7287. if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
  7288. pci_using_dac = 1;
  7289. } else {
  7290. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  7291. if (err) {
  7292. dev_err(&pdev->dev,
  7293. "No usable DMA configuration, aborting\n");
  7294. goto err_dma;
  7295. }
  7296. pci_using_dac = 0;
  7297. }
  7298. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  7299. IORESOURCE_MEM), ixgbe_driver_name);
  7300. if (err) {
  7301. dev_err(&pdev->dev,
  7302. "pci_request_selected_regions failed 0x%x\n", err);
  7303. goto err_pci_reg;
  7304. }
  7305. pci_enable_pcie_error_reporting(pdev);
  7306. pci_set_master(pdev);
  7307. pci_save_state(pdev);
  7308. if (ii->mac == ixgbe_mac_82598EB) {
  7309. #ifdef CONFIG_IXGBE_DCB
  7310. /* 8 TC w/ 4 queues per TC */
  7311. indices = 4 * MAX_TRAFFIC_CLASS;
  7312. #else
  7313. indices = IXGBE_MAX_RSS_INDICES;
  7314. #endif
  7315. }
  7316. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  7317. if (!netdev) {
  7318. err = -ENOMEM;
  7319. goto err_alloc_etherdev;
  7320. }
  7321. SET_NETDEV_DEV(netdev, &pdev->dev);
  7322. adapter = netdev_priv(netdev);
  7323. adapter->netdev = netdev;
  7324. adapter->pdev = pdev;
  7325. hw = &adapter->hw;
  7326. hw->back = adapter;
  7327. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  7328. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  7329. pci_resource_len(pdev, 0));
  7330. adapter->io_addr = hw->hw_addr;
  7331. if (!hw->hw_addr) {
  7332. err = -EIO;
  7333. goto err_ioremap;
  7334. }
  7335. netdev->netdev_ops = &ixgbe_netdev_ops;
  7336. ixgbe_set_ethtool_ops(netdev);
  7337. netdev->watchdog_timeo = 5 * HZ;
  7338. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  7339. /* Setup hw api */
  7340. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  7341. hw->mac.type = ii->mac;
  7342. hw->mvals = ii->mvals;
  7343. /* EEPROM */
  7344. memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
  7345. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  7346. if (ixgbe_removed(hw->hw_addr)) {
  7347. err = -EIO;
  7348. goto err_ioremap;
  7349. }
  7350. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  7351. if (!(eec & (1 << 8)))
  7352. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  7353. /* PHY */
  7354. memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
  7355. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  7356. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  7357. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  7358. hw->phy.mdio.mmds = 0;
  7359. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  7360. hw->phy.mdio.dev = netdev;
  7361. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  7362. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  7363. ii->get_invariants(hw);
  7364. /* setup the private structure */
  7365. err = ixgbe_sw_init(adapter);
  7366. if (err)
  7367. goto err_sw_init;
  7368. /* Make it possible the adapter to be woken up via WOL */
  7369. switch (adapter->hw.mac.type) {
  7370. case ixgbe_mac_82599EB:
  7371. case ixgbe_mac_X540:
  7372. case ixgbe_mac_X550:
  7373. case ixgbe_mac_X550EM_x:
  7374. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  7375. break;
  7376. default:
  7377. break;
  7378. }
  7379. /*
  7380. * If there is a fan on this device and it has failed log the
  7381. * failure.
  7382. */
  7383. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  7384. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  7385. if (esdp & IXGBE_ESDP_SDP1)
  7386. e_crit(probe, "Fan has stopped, replace the adapter\n");
  7387. }
  7388. if (allow_unsupported_sfp)
  7389. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  7390. /* reset_hw fills in the perm_addr as well */
  7391. hw->phy.reset_if_overtemp = true;
  7392. err = hw->mac.ops.reset_hw(hw);
  7393. hw->phy.reset_if_overtemp = false;
  7394. if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
  7395. hw->mac.type == ixgbe_mac_82598EB) {
  7396. err = 0;
  7397. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  7398. e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
  7399. e_dev_err("Reload the driver after installing a supported module.\n");
  7400. goto err_sw_init;
  7401. } else if (err) {
  7402. e_dev_err("HW Init failed: %d\n", err);
  7403. goto err_sw_init;
  7404. }
  7405. #ifdef CONFIG_PCI_IOV
  7406. /* SR-IOV not supported on the 82598 */
  7407. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  7408. goto skip_sriov;
  7409. /* Mailbox */
  7410. ixgbe_init_mbx_params_pf(hw);
  7411. memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
  7412. pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
  7413. ixgbe_enable_sriov(adapter);
  7414. skip_sriov:
  7415. #endif
  7416. netdev->features = NETIF_F_SG |
  7417. NETIF_F_IP_CSUM |
  7418. NETIF_F_IPV6_CSUM |
  7419. NETIF_F_HW_VLAN_CTAG_TX |
  7420. NETIF_F_HW_VLAN_CTAG_RX |
  7421. NETIF_F_TSO |
  7422. NETIF_F_TSO6 |
  7423. NETIF_F_RXHASH |
  7424. NETIF_F_RXCSUM;
  7425. netdev->hw_features = netdev->features | NETIF_F_HW_L2FW_DOFFLOAD;
  7426. switch (adapter->hw.mac.type) {
  7427. case ixgbe_mac_82599EB:
  7428. case ixgbe_mac_X540:
  7429. case ixgbe_mac_X550:
  7430. case ixgbe_mac_X550EM_x:
  7431. netdev->features |= NETIF_F_SCTP_CSUM;
  7432. netdev->hw_features |= NETIF_F_SCTP_CSUM |
  7433. NETIF_F_NTUPLE;
  7434. break;
  7435. default:
  7436. break;
  7437. }
  7438. netdev->hw_features |= NETIF_F_RXALL;
  7439. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  7440. netdev->vlan_features |= NETIF_F_TSO;
  7441. netdev->vlan_features |= NETIF_F_TSO6;
  7442. netdev->vlan_features |= NETIF_F_IP_CSUM;
  7443. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  7444. netdev->vlan_features |= NETIF_F_SG;
  7445. netdev->hw_enc_features |= NETIF_F_SG | NETIF_F_IP_CSUM |
  7446. NETIF_F_IPV6_CSUM;
  7447. netdev->priv_flags |= IFF_UNICAST_FLT;
  7448. netdev->priv_flags |= IFF_SUPP_NOFCS;
  7449. #ifdef CONFIG_IXGBE_VXLAN
  7450. switch (adapter->hw.mac.type) {
  7451. case ixgbe_mac_X550:
  7452. case ixgbe_mac_X550EM_x:
  7453. netdev->hw_enc_features |= NETIF_F_RXCSUM |
  7454. NETIF_F_IP_CSUM |
  7455. NETIF_F_IPV6_CSUM;
  7456. break;
  7457. default:
  7458. break;
  7459. }
  7460. #endif /* CONFIG_IXGBE_VXLAN */
  7461. #ifdef CONFIG_IXGBE_DCB
  7462. netdev->dcbnl_ops = &dcbnl_ops;
  7463. #endif
  7464. #ifdef IXGBE_FCOE
  7465. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  7466. unsigned int fcoe_l;
  7467. if (hw->mac.ops.get_device_caps) {
  7468. hw->mac.ops.get_device_caps(hw, &device_caps);
  7469. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  7470. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  7471. }
  7472. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  7473. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  7474. netdev->features |= NETIF_F_FSO |
  7475. NETIF_F_FCOE_CRC;
  7476. netdev->vlan_features |= NETIF_F_FSO |
  7477. NETIF_F_FCOE_CRC |
  7478. NETIF_F_FCOE_MTU;
  7479. }
  7480. #endif /* IXGBE_FCOE */
  7481. if (pci_using_dac) {
  7482. netdev->features |= NETIF_F_HIGHDMA;
  7483. netdev->vlan_features |= NETIF_F_HIGHDMA;
  7484. }
  7485. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  7486. netdev->hw_features |= NETIF_F_LRO;
  7487. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  7488. netdev->features |= NETIF_F_LRO;
  7489. /* make sure the EEPROM is good */
  7490. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  7491. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  7492. err = -EIO;
  7493. goto err_sw_init;
  7494. }
  7495. ixgbe_get_platform_mac_addr(adapter);
  7496. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  7497. if (!is_valid_ether_addr(netdev->dev_addr)) {
  7498. e_dev_err("invalid MAC address\n");
  7499. err = -EIO;
  7500. goto err_sw_init;
  7501. }
  7502. ixgbe_mac_set_default_filter(adapter, hw->mac.perm_addr);
  7503. setup_timer(&adapter->service_timer, &ixgbe_service_timer,
  7504. (unsigned long) adapter);
  7505. if (ixgbe_removed(hw->hw_addr)) {
  7506. err = -EIO;
  7507. goto err_sw_init;
  7508. }
  7509. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  7510. set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
  7511. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  7512. err = ixgbe_init_interrupt_scheme(adapter);
  7513. if (err)
  7514. goto err_sw_init;
  7515. /* WOL not supported for all devices */
  7516. adapter->wol = 0;
  7517. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  7518. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  7519. pdev->subsystem_device);
  7520. if (hw->wol_enabled)
  7521. adapter->wol = IXGBE_WUFC_MAG;
  7522. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  7523. /* save off EEPROM version number */
  7524. hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
  7525. hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
  7526. /* pick up the PCI bus settings for reporting later */
  7527. if (ixgbe_pcie_from_parent(hw))
  7528. ixgbe_get_parent_bus_info(adapter);
  7529. else
  7530. hw->mac.ops.get_bus_info(hw);
  7531. /* calculate the expected PCIe bandwidth required for optimal
  7532. * performance. Note that some older parts will never have enough
  7533. * bandwidth due to being older generation PCIe parts. We clamp these
  7534. * parts to ensure no warning is displayed if it can't be fixed.
  7535. */
  7536. switch (hw->mac.type) {
  7537. case ixgbe_mac_82598EB:
  7538. expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
  7539. break;
  7540. default:
  7541. expected_gts = ixgbe_enumerate_functions(adapter) * 10;
  7542. break;
  7543. }
  7544. /* don't check link if we failed to enumerate functions */
  7545. if (expected_gts > 0)
  7546. ixgbe_check_minimum_link(adapter, expected_gts);
  7547. err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
  7548. if (err)
  7549. strlcpy(part_str, "Unknown", sizeof(part_str));
  7550. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  7551. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  7552. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  7553. part_str);
  7554. else
  7555. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  7556. hw->mac.type, hw->phy.type, part_str);
  7557. e_dev_info("%pM\n", netdev->dev_addr);
  7558. /* reset the hardware with the new settings */
  7559. err = hw->mac.ops.start_hw(hw);
  7560. if (err == IXGBE_ERR_EEPROM_VERSION) {
  7561. /* We are running on a pre-production device, log a warning */
  7562. e_dev_warn("This device is a pre-production adapter/LOM. "
  7563. "Please be aware there may be issues associated "
  7564. "with your hardware. If you are experiencing "
  7565. "problems please contact your Intel or hardware "
  7566. "representative who provided you with this "
  7567. "hardware.\n");
  7568. }
  7569. strcpy(netdev->name, "eth%d");
  7570. err = register_netdev(netdev);
  7571. if (err)
  7572. goto err_register;
  7573. pci_set_drvdata(pdev, adapter);
  7574. /* power down the optics for 82599 SFP+ fiber */
  7575. if (hw->mac.ops.disable_tx_laser)
  7576. hw->mac.ops.disable_tx_laser(hw);
  7577. /* carrier off reporting is important to ethtool even BEFORE open */
  7578. netif_carrier_off(netdev);
  7579. #ifdef CONFIG_IXGBE_DCA
  7580. if (dca_add_requester(&pdev->dev) == 0) {
  7581. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  7582. ixgbe_setup_dca(adapter);
  7583. }
  7584. #endif
  7585. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  7586. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  7587. for (i = 0; i < adapter->num_vfs; i++)
  7588. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  7589. }
  7590. /* firmware requires driver version to be 0xFFFFFFFF
  7591. * since os does not support feature
  7592. */
  7593. if (hw->mac.ops.set_fw_drv_ver)
  7594. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
  7595. 0xFF);
  7596. /* add san mac addr to netdev */
  7597. ixgbe_add_sanmac_netdev(netdev);
  7598. e_dev_info("%s\n", ixgbe_default_device_descr);
  7599. #ifdef CONFIG_IXGBE_HWMON
  7600. if (ixgbe_sysfs_init(adapter))
  7601. e_err(probe, "failed to allocate sysfs resources\n");
  7602. #endif /* CONFIG_IXGBE_HWMON */
  7603. ixgbe_dbg_adapter_init(adapter);
  7604. /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
  7605. if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
  7606. hw->mac.ops.setup_link(hw,
  7607. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  7608. true);
  7609. return 0;
  7610. err_register:
  7611. ixgbe_release_hw_control(adapter);
  7612. ixgbe_clear_interrupt_scheme(adapter);
  7613. err_sw_init:
  7614. ixgbe_disable_sriov(adapter);
  7615. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  7616. iounmap(adapter->io_addr);
  7617. kfree(adapter->mac_table);
  7618. err_ioremap:
  7619. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  7620. free_netdev(netdev);
  7621. err_alloc_etherdev:
  7622. pci_release_selected_regions(pdev,
  7623. pci_select_bars(pdev, IORESOURCE_MEM));
  7624. err_pci_reg:
  7625. err_dma:
  7626. if (!adapter || disable_dev)
  7627. pci_disable_device(pdev);
  7628. return err;
  7629. }
  7630. /**
  7631. * ixgbe_remove - Device Removal Routine
  7632. * @pdev: PCI device information struct
  7633. *
  7634. * ixgbe_remove is called by the PCI subsystem to alert the driver
  7635. * that it should release a PCI device. The could be caused by a
  7636. * Hot-Plug event, or because the driver is going to be removed from
  7637. * memory.
  7638. **/
  7639. static void ixgbe_remove(struct pci_dev *pdev)
  7640. {
  7641. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  7642. struct net_device *netdev;
  7643. bool disable_dev;
  7644. /* if !adapter then we already cleaned up in probe */
  7645. if (!adapter)
  7646. return;
  7647. netdev = adapter->netdev;
  7648. ixgbe_dbg_adapter_exit(adapter);
  7649. set_bit(__IXGBE_REMOVING, &adapter->state);
  7650. cancel_work_sync(&adapter->service_task);
  7651. #ifdef CONFIG_IXGBE_DCA
  7652. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  7653. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  7654. dca_remove_requester(&pdev->dev);
  7655. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  7656. }
  7657. #endif
  7658. #ifdef CONFIG_IXGBE_HWMON
  7659. ixgbe_sysfs_exit(adapter);
  7660. #endif /* CONFIG_IXGBE_HWMON */
  7661. /* remove the added san mac */
  7662. ixgbe_del_sanmac_netdev(netdev);
  7663. if (netdev->reg_state == NETREG_REGISTERED)
  7664. unregister_netdev(netdev);
  7665. #ifdef CONFIG_PCI_IOV
  7666. ixgbe_disable_sriov(adapter);
  7667. #endif
  7668. ixgbe_clear_interrupt_scheme(adapter);
  7669. ixgbe_release_hw_control(adapter);
  7670. #ifdef CONFIG_DCB
  7671. kfree(adapter->ixgbe_ieee_pfc);
  7672. kfree(adapter->ixgbe_ieee_ets);
  7673. #endif
  7674. iounmap(adapter->io_addr);
  7675. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  7676. IORESOURCE_MEM));
  7677. e_dev_info("complete\n");
  7678. kfree(adapter->mac_table);
  7679. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  7680. free_netdev(netdev);
  7681. pci_disable_pcie_error_reporting(pdev);
  7682. if (disable_dev)
  7683. pci_disable_device(pdev);
  7684. }
  7685. /**
  7686. * ixgbe_io_error_detected - called when PCI error is detected
  7687. * @pdev: Pointer to PCI device
  7688. * @state: The current pci connection state
  7689. *
  7690. * This function is called after a PCI bus error affecting
  7691. * this device has been detected.
  7692. */
  7693. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  7694. pci_channel_state_t state)
  7695. {
  7696. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  7697. struct net_device *netdev = adapter->netdev;
  7698. #ifdef CONFIG_PCI_IOV
  7699. struct ixgbe_hw *hw = &adapter->hw;
  7700. struct pci_dev *bdev, *vfdev;
  7701. u32 dw0, dw1, dw2, dw3;
  7702. int vf, pos;
  7703. u16 req_id, pf_func;
  7704. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  7705. adapter->num_vfs == 0)
  7706. goto skip_bad_vf_detection;
  7707. bdev = pdev->bus->self;
  7708. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  7709. bdev = bdev->bus->self;
  7710. if (!bdev)
  7711. goto skip_bad_vf_detection;
  7712. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  7713. if (!pos)
  7714. goto skip_bad_vf_detection;
  7715. dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
  7716. dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
  7717. dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
  7718. dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
  7719. if (ixgbe_removed(hw->hw_addr))
  7720. goto skip_bad_vf_detection;
  7721. req_id = dw1 >> 16;
  7722. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  7723. if (!(req_id & 0x0080))
  7724. goto skip_bad_vf_detection;
  7725. pf_func = req_id & 0x01;
  7726. if ((pf_func & 1) == (pdev->devfn & 1)) {
  7727. unsigned int device_id;
  7728. vf = (req_id & 0x7F) >> 1;
  7729. e_dev_err("VF %d has caused a PCIe error\n", vf);
  7730. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  7731. "%8.8x\tdw3: %8.8x\n",
  7732. dw0, dw1, dw2, dw3);
  7733. switch (adapter->hw.mac.type) {
  7734. case ixgbe_mac_82599EB:
  7735. device_id = IXGBE_82599_VF_DEVICE_ID;
  7736. break;
  7737. case ixgbe_mac_X540:
  7738. device_id = IXGBE_X540_VF_DEVICE_ID;
  7739. break;
  7740. case ixgbe_mac_X550:
  7741. device_id = IXGBE_DEV_ID_X550_VF;
  7742. break;
  7743. case ixgbe_mac_X550EM_x:
  7744. device_id = IXGBE_DEV_ID_X550EM_X_VF;
  7745. break;
  7746. default:
  7747. device_id = 0;
  7748. break;
  7749. }
  7750. /* Find the pci device of the offending VF */
  7751. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  7752. while (vfdev) {
  7753. if (vfdev->devfn == (req_id & 0xFF))
  7754. break;
  7755. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  7756. device_id, vfdev);
  7757. }
  7758. /*
  7759. * There's a slim chance the VF could have been hot plugged,
  7760. * so if it is no longer present we don't need to issue the
  7761. * VFLR. Just clean up the AER in that case.
  7762. */
  7763. if (vfdev) {
  7764. ixgbe_issue_vf_flr(adapter, vfdev);
  7765. /* Free device reference count */
  7766. pci_dev_put(vfdev);
  7767. }
  7768. pci_cleanup_aer_uncorrect_error_status(pdev);
  7769. }
  7770. /*
  7771. * Even though the error may have occurred on the other port
  7772. * we still need to increment the vf error reference count for
  7773. * both ports because the I/O resume function will be called
  7774. * for both of them.
  7775. */
  7776. adapter->vferr_refcount++;
  7777. return PCI_ERS_RESULT_RECOVERED;
  7778. skip_bad_vf_detection:
  7779. #endif /* CONFIG_PCI_IOV */
  7780. if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  7781. return PCI_ERS_RESULT_DISCONNECT;
  7782. rtnl_lock();
  7783. netif_device_detach(netdev);
  7784. if (state == pci_channel_io_perm_failure) {
  7785. rtnl_unlock();
  7786. return PCI_ERS_RESULT_DISCONNECT;
  7787. }
  7788. if (netif_running(netdev))
  7789. ixgbe_down(adapter);
  7790. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  7791. pci_disable_device(pdev);
  7792. rtnl_unlock();
  7793. /* Request a slot reset. */
  7794. return PCI_ERS_RESULT_NEED_RESET;
  7795. }
  7796. /**
  7797. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  7798. * @pdev: Pointer to PCI device
  7799. *
  7800. * Restart the card from scratch, as if from a cold-boot.
  7801. */
  7802. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  7803. {
  7804. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  7805. pci_ers_result_t result;
  7806. int err;
  7807. if (pci_enable_device_mem(pdev)) {
  7808. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  7809. result = PCI_ERS_RESULT_DISCONNECT;
  7810. } else {
  7811. smp_mb__before_atomic();
  7812. clear_bit(__IXGBE_DISABLED, &adapter->state);
  7813. adapter->hw.hw_addr = adapter->io_addr;
  7814. pci_set_master(pdev);
  7815. pci_restore_state(pdev);
  7816. pci_save_state(pdev);
  7817. pci_wake_from_d3(pdev, false);
  7818. ixgbe_reset(adapter);
  7819. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  7820. result = PCI_ERS_RESULT_RECOVERED;
  7821. }
  7822. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  7823. if (err) {
  7824. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  7825. "failed 0x%0x\n", err);
  7826. /* non-fatal, continue */
  7827. }
  7828. return result;
  7829. }
  7830. /**
  7831. * ixgbe_io_resume - called when traffic can start flowing again.
  7832. * @pdev: Pointer to PCI device
  7833. *
  7834. * This callback is called when the error recovery driver tells us that
  7835. * its OK to resume normal operation.
  7836. */
  7837. static void ixgbe_io_resume(struct pci_dev *pdev)
  7838. {
  7839. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  7840. struct net_device *netdev = adapter->netdev;
  7841. #ifdef CONFIG_PCI_IOV
  7842. if (adapter->vferr_refcount) {
  7843. e_info(drv, "Resuming after VF err\n");
  7844. adapter->vferr_refcount--;
  7845. return;
  7846. }
  7847. #endif
  7848. if (netif_running(netdev))
  7849. ixgbe_up(adapter);
  7850. netif_device_attach(netdev);
  7851. }
  7852. static const struct pci_error_handlers ixgbe_err_handler = {
  7853. .error_detected = ixgbe_io_error_detected,
  7854. .slot_reset = ixgbe_io_slot_reset,
  7855. .resume = ixgbe_io_resume,
  7856. };
  7857. static struct pci_driver ixgbe_driver = {
  7858. .name = ixgbe_driver_name,
  7859. .id_table = ixgbe_pci_tbl,
  7860. .probe = ixgbe_probe,
  7861. .remove = ixgbe_remove,
  7862. #ifdef CONFIG_PM
  7863. .suspend = ixgbe_suspend,
  7864. .resume = ixgbe_resume,
  7865. #endif
  7866. .shutdown = ixgbe_shutdown,
  7867. .sriov_configure = ixgbe_pci_sriov_configure,
  7868. .err_handler = &ixgbe_err_handler
  7869. };
  7870. /**
  7871. * ixgbe_init_module - Driver Registration Routine
  7872. *
  7873. * ixgbe_init_module is the first routine called when the driver is
  7874. * loaded. All it does is register with the PCI subsystem.
  7875. **/
  7876. static int __init ixgbe_init_module(void)
  7877. {
  7878. int ret;
  7879. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  7880. pr_info("%s\n", ixgbe_copyright);
  7881. ixgbe_dbg_init();
  7882. ret = pci_register_driver(&ixgbe_driver);
  7883. if (ret) {
  7884. ixgbe_dbg_exit();
  7885. return ret;
  7886. }
  7887. #ifdef CONFIG_IXGBE_DCA
  7888. dca_register_notify(&dca_notifier);
  7889. #endif
  7890. return 0;
  7891. }
  7892. module_init(ixgbe_init_module);
  7893. /**
  7894. * ixgbe_exit_module - Driver Exit Cleanup Routine
  7895. *
  7896. * ixgbe_exit_module is called just before the driver is removed
  7897. * from memory.
  7898. **/
  7899. static void __exit ixgbe_exit_module(void)
  7900. {
  7901. #ifdef CONFIG_IXGBE_DCA
  7902. dca_unregister_notify(&dca_notifier);
  7903. #endif
  7904. pci_unregister_driver(&ixgbe_driver);
  7905. ixgbe_dbg_exit();
  7906. }
  7907. #ifdef CONFIG_IXGBE_DCA
  7908. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  7909. void *p)
  7910. {
  7911. int ret_val;
  7912. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  7913. __ixgbe_notify_dca);
  7914. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  7915. }
  7916. #endif /* CONFIG_IXGBE_DCA */
  7917. module_exit(ixgbe_exit_module);
  7918. /* ixgbe_main.c */