ixgbe_main.c 220 KB

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