ixgbe_main.c 224 KB

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