ixgbe_main.c 217 KB

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