ixgbe_main.c 190 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2010 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/ip.h>
  28. #include <linux/tcp.h>
  29. #include <linux/pkt_sched.h>
  30. #include <linux/ipv6.h>
  31. #include <linux/slab.h>
  32. #include <net/checksum.h>
  33. #include <net/ip6_checksum.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if_vlan.h>
  36. #include <scsi/fc/fc_fcoe.h>
  37. #include "ixgbe.h"
  38. #include "ixgbe_common.h"
  39. #include "ixgbe_dcb_82599.h"
  40. #include "ixgbe_sriov.h"
  41. char ixgbe_driver_name[] = "ixgbe";
  42. static const char ixgbe_driver_string[] =
  43. "Intel(R) 10 Gigabit PCI Express Network Driver";
  44. #define DRV_VERSION "2.0.62-k2"
  45. const char ixgbe_driver_version[] = DRV_VERSION;
  46. static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation.";
  47. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  48. [board_82598] = &ixgbe_82598_info,
  49. [board_82599] = &ixgbe_82599_info,
  50. };
  51. /* ixgbe_pci_tbl - PCI Device ID Table
  52. *
  53. * Wildcard entries (PCI_ANY_ID) should come last
  54. * Last entry must be all 0s
  55. *
  56. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  57. * Class, Class Mask, private data (not used) }
  58. */
  59. static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
  60. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
  61. board_82598 },
  62. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
  63. board_82598 },
  64. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
  65. board_82598 },
  66. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
  67. board_82598 },
  68. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
  69. board_82598 },
  70. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
  71. board_82598 },
  72. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
  73. board_82598 },
  74. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
  75. board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
  77. board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
  79. board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
  81. board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
  83. board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
  85. board_82599 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
  87. board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
  89. board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
  91. board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
  93. board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
  95. board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
  97. board_82599 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
  99. board_82599 },
  100. /* required last entry */
  101. {0, }
  102. };
  103. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  104. #ifdef CONFIG_IXGBE_DCA
  105. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  106. void *p);
  107. static struct notifier_block dca_notifier = {
  108. .notifier_call = ixgbe_notify_dca,
  109. .next = NULL,
  110. .priority = 0
  111. };
  112. #endif
  113. #ifdef CONFIG_PCI_IOV
  114. static unsigned int max_vfs;
  115. module_param(max_vfs, uint, 0);
  116. MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
  117. "per physical function");
  118. #endif /* CONFIG_PCI_IOV */
  119. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  120. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  121. MODULE_LICENSE("GPL");
  122. MODULE_VERSION(DRV_VERSION);
  123. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  124. static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
  125. {
  126. struct ixgbe_hw *hw = &adapter->hw;
  127. u32 gcr;
  128. u32 gpie;
  129. u32 vmdctl;
  130. #ifdef CONFIG_PCI_IOV
  131. /* disable iov and allow time for transactions to clear */
  132. pci_disable_sriov(adapter->pdev);
  133. #endif
  134. /* turn off device IOV mode */
  135. gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  136. gcr &= ~(IXGBE_GCR_EXT_SRIOV);
  137. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
  138. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  139. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  140. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  141. /* set default pool back to 0 */
  142. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  143. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  144. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  145. /* take a breather then clean up driver data */
  146. msleep(100);
  147. if (adapter->vfinfo)
  148. kfree(adapter->vfinfo);
  149. adapter->vfinfo = NULL;
  150. adapter->num_vfs = 0;
  151. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  152. }
  153. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  154. {
  155. u32 ctrl_ext;
  156. /* Let firmware take over control of h/w */
  157. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  158. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  159. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  160. }
  161. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  162. {
  163. u32 ctrl_ext;
  164. /* Let firmware know the driver has taken over */
  165. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  166. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  167. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  168. }
  169. /*
  170. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  171. * @adapter: pointer to adapter struct
  172. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  173. * @queue: queue to map the corresponding interrupt to
  174. * @msix_vector: the vector to map to the corresponding queue
  175. *
  176. */
  177. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  178. u8 queue, u8 msix_vector)
  179. {
  180. u32 ivar, index;
  181. struct ixgbe_hw *hw = &adapter->hw;
  182. switch (hw->mac.type) {
  183. case ixgbe_mac_82598EB:
  184. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  185. if (direction == -1)
  186. direction = 0;
  187. index = (((direction * 64) + queue) >> 2) & 0x1F;
  188. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  189. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  190. ivar |= (msix_vector << (8 * (queue & 0x3)));
  191. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  192. break;
  193. case ixgbe_mac_82599EB:
  194. if (direction == -1) {
  195. /* other causes */
  196. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  197. index = ((queue & 1) * 8);
  198. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  199. ivar &= ~(0xFF << index);
  200. ivar |= (msix_vector << index);
  201. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  202. break;
  203. } else {
  204. /* tx or rx causes */
  205. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  206. index = ((16 * (queue & 1)) + (8 * direction));
  207. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  208. ivar &= ~(0xFF << index);
  209. ivar |= (msix_vector << index);
  210. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  211. break;
  212. }
  213. default:
  214. break;
  215. }
  216. }
  217. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  218. u64 qmask)
  219. {
  220. u32 mask;
  221. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  222. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  223. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  224. } else {
  225. mask = (qmask & 0xFFFFFFFF);
  226. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  227. mask = (qmask >> 32);
  228. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  229. }
  230. }
  231. static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
  232. struct ixgbe_tx_buffer
  233. *tx_buffer_info)
  234. {
  235. if (tx_buffer_info->dma) {
  236. if (tx_buffer_info->mapped_as_page)
  237. pci_unmap_page(adapter->pdev,
  238. tx_buffer_info->dma,
  239. tx_buffer_info->length,
  240. PCI_DMA_TODEVICE);
  241. else
  242. pci_unmap_single(adapter->pdev,
  243. tx_buffer_info->dma,
  244. tx_buffer_info->length,
  245. PCI_DMA_TODEVICE);
  246. tx_buffer_info->dma = 0;
  247. }
  248. if (tx_buffer_info->skb) {
  249. dev_kfree_skb_any(tx_buffer_info->skb);
  250. tx_buffer_info->skb = NULL;
  251. }
  252. tx_buffer_info->time_stamp = 0;
  253. /* tx_buffer_info must be completely set up in the transmit path */
  254. }
  255. /**
  256. * ixgbe_tx_is_paused - check if the tx ring is paused
  257. * @adapter: the ixgbe adapter
  258. * @tx_ring: the corresponding tx_ring
  259. *
  260. * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
  261. * corresponding TC of this tx_ring when checking TFCS.
  262. *
  263. * Returns : true if paused
  264. */
  265. static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter,
  266. struct ixgbe_ring *tx_ring)
  267. {
  268. u32 txoff = IXGBE_TFCS_TXOFF;
  269. #ifdef CONFIG_IXGBE_DCB
  270. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  271. int tc;
  272. int reg_idx = tx_ring->reg_idx;
  273. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  274. switch (adapter->hw.mac.type) {
  275. case ixgbe_mac_82598EB:
  276. tc = reg_idx >> 2;
  277. txoff = IXGBE_TFCS_TXOFF0;
  278. break;
  279. case ixgbe_mac_82599EB:
  280. tc = 0;
  281. txoff = IXGBE_TFCS_TXOFF;
  282. if (dcb_i == 8) {
  283. /* TC0, TC1 */
  284. tc = reg_idx >> 5;
  285. if (tc == 2) /* TC2, TC3 */
  286. tc += (reg_idx - 64) >> 4;
  287. else if (tc == 3) /* TC4, TC5, TC6, TC7 */
  288. tc += 1 + ((reg_idx - 96) >> 3);
  289. } else if (dcb_i == 4) {
  290. /* TC0, TC1 */
  291. tc = reg_idx >> 6;
  292. if (tc == 1) {
  293. tc += (reg_idx - 64) >> 5;
  294. if (tc == 2) /* TC2, TC3 */
  295. tc += (reg_idx - 96) >> 4;
  296. }
  297. }
  298. break;
  299. default:
  300. tc = 0;
  301. }
  302. txoff <<= tc;
  303. }
  304. #endif
  305. return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff;
  306. }
  307. static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
  308. struct ixgbe_ring *tx_ring,
  309. unsigned int eop)
  310. {
  311. struct ixgbe_hw *hw = &adapter->hw;
  312. /* Detect a transmit hang in hardware, this serializes the
  313. * check with the clearing of time_stamp and movement of eop */
  314. adapter->detect_tx_hung = false;
  315. if (tx_ring->tx_buffer_info[eop].time_stamp &&
  316. time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
  317. !ixgbe_tx_is_paused(adapter, tx_ring)) {
  318. /* detected Tx unit hang */
  319. union ixgbe_adv_tx_desc *tx_desc;
  320. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  321. DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
  322. " Tx Queue <%d>\n"
  323. " TDH, TDT <%x>, <%x>\n"
  324. " next_to_use <%x>\n"
  325. " next_to_clean <%x>\n"
  326. "tx_buffer_info[next_to_clean]\n"
  327. " time_stamp <%lx>\n"
  328. " jiffies <%lx>\n",
  329. tx_ring->queue_index,
  330. IXGBE_READ_REG(hw, tx_ring->head),
  331. IXGBE_READ_REG(hw, tx_ring->tail),
  332. tx_ring->next_to_use, eop,
  333. tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
  334. return true;
  335. }
  336. return false;
  337. }
  338. #define IXGBE_MAX_TXD_PWR 14
  339. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  340. /* Tx Descriptors needed, worst case */
  341. #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
  342. (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
  343. #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
  344. MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
  345. static void ixgbe_tx_timeout(struct net_device *netdev);
  346. /**
  347. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  348. * @q_vector: structure containing interrupt and ring information
  349. * @tx_ring: tx ring to clean
  350. **/
  351. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  352. struct ixgbe_ring *tx_ring)
  353. {
  354. struct ixgbe_adapter *adapter = q_vector->adapter;
  355. struct net_device *netdev = adapter->netdev;
  356. union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
  357. struct ixgbe_tx_buffer *tx_buffer_info;
  358. unsigned int i, eop, count = 0;
  359. unsigned int total_bytes = 0, total_packets = 0;
  360. i = tx_ring->next_to_clean;
  361. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  362. eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  363. while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
  364. (count < tx_ring->work_limit)) {
  365. bool cleaned = false;
  366. for ( ; !cleaned; count++) {
  367. struct sk_buff *skb;
  368. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  369. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  370. cleaned = (i == eop);
  371. skb = tx_buffer_info->skb;
  372. if (cleaned && skb) {
  373. unsigned int segs, bytecount;
  374. unsigned int hlen = skb_headlen(skb);
  375. /* gso_segs is currently only valid for tcp */
  376. segs = skb_shinfo(skb)->gso_segs ?: 1;
  377. #ifdef IXGBE_FCOE
  378. /* adjust for FCoE Sequence Offload */
  379. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  380. && (skb->protocol == htons(ETH_P_FCOE)) &&
  381. skb_is_gso(skb)) {
  382. hlen = skb_transport_offset(skb) +
  383. sizeof(struct fc_frame_header) +
  384. sizeof(struct fcoe_crc_eof);
  385. segs = DIV_ROUND_UP(skb->len - hlen,
  386. skb_shinfo(skb)->gso_size);
  387. }
  388. #endif /* IXGBE_FCOE */
  389. /* multiply data chunks by size of headers */
  390. bytecount = ((segs - 1) * hlen) + skb->len;
  391. total_packets += segs;
  392. total_bytes += bytecount;
  393. }
  394. ixgbe_unmap_and_free_tx_resource(adapter,
  395. tx_buffer_info);
  396. tx_desc->wb.status = 0;
  397. i++;
  398. if (i == tx_ring->count)
  399. i = 0;
  400. }
  401. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  402. eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  403. }
  404. tx_ring->next_to_clean = i;
  405. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  406. if (unlikely(count && netif_carrier_ok(netdev) &&
  407. (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
  408. /* Make sure that anybody stopping the queue after this
  409. * sees the new next_to_clean.
  410. */
  411. smp_mb();
  412. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  413. !test_bit(__IXGBE_DOWN, &adapter->state)) {
  414. netif_wake_subqueue(netdev, tx_ring->queue_index);
  415. ++tx_ring->restart_queue;
  416. }
  417. }
  418. if (adapter->detect_tx_hung) {
  419. if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
  420. /* schedule immediate reset if we believe we hung */
  421. DPRINTK(PROBE, INFO,
  422. "tx hang %d detected, resetting adapter\n",
  423. adapter->tx_timeout_count + 1);
  424. ixgbe_tx_timeout(adapter->netdev);
  425. }
  426. }
  427. /* re-arm the interrupt */
  428. if (count >= tx_ring->work_limit)
  429. ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
  430. tx_ring->total_bytes += total_bytes;
  431. tx_ring->total_packets += total_packets;
  432. tx_ring->stats.packets += total_packets;
  433. tx_ring->stats.bytes += total_bytes;
  434. return (count < tx_ring->work_limit);
  435. }
  436. #ifdef CONFIG_IXGBE_DCA
  437. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  438. struct ixgbe_ring *rx_ring)
  439. {
  440. u32 rxctrl;
  441. int cpu = get_cpu();
  442. int q = rx_ring->reg_idx;
  443. if (rx_ring->cpu != cpu) {
  444. rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
  445. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  446. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
  447. rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  448. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  449. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
  450. rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  451. IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
  452. }
  453. rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  454. rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
  455. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
  456. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
  457. IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
  458. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
  459. rx_ring->cpu = cpu;
  460. }
  461. put_cpu();
  462. }
  463. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  464. struct ixgbe_ring *tx_ring)
  465. {
  466. u32 txctrl;
  467. int cpu = get_cpu();
  468. int q = tx_ring->reg_idx;
  469. struct ixgbe_hw *hw = &adapter->hw;
  470. if (tx_ring->cpu != cpu) {
  471. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  472. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
  473. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
  474. txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  475. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  476. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
  477. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  478. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
  479. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
  480. txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  481. IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
  482. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  483. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
  484. }
  485. tx_ring->cpu = cpu;
  486. }
  487. put_cpu();
  488. }
  489. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  490. {
  491. int i;
  492. if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
  493. return;
  494. /* always use CB2 mode, difference is masked in the CB driver */
  495. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
  496. for (i = 0; i < adapter->num_tx_queues; i++) {
  497. adapter->tx_ring[i]->cpu = -1;
  498. ixgbe_update_tx_dca(adapter, adapter->tx_ring[i]);
  499. }
  500. for (i = 0; i < adapter->num_rx_queues; i++) {
  501. adapter->rx_ring[i]->cpu = -1;
  502. ixgbe_update_rx_dca(adapter, adapter->rx_ring[i]);
  503. }
  504. }
  505. static int __ixgbe_notify_dca(struct device *dev, void *data)
  506. {
  507. struct net_device *netdev = dev_get_drvdata(dev);
  508. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  509. unsigned long event = *(unsigned long *)data;
  510. switch (event) {
  511. case DCA_PROVIDER_ADD:
  512. /* if we're already enabled, don't do it again */
  513. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  514. break;
  515. if (dca_add_requester(dev) == 0) {
  516. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  517. ixgbe_setup_dca(adapter);
  518. break;
  519. }
  520. /* Fall Through since DCA is disabled. */
  521. case DCA_PROVIDER_REMOVE:
  522. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  523. dca_remove_requester(dev);
  524. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  525. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  526. }
  527. break;
  528. }
  529. return 0;
  530. }
  531. #endif /* CONFIG_IXGBE_DCA */
  532. /**
  533. * ixgbe_receive_skb - Send a completed packet up the stack
  534. * @adapter: board private structure
  535. * @skb: packet to send up
  536. * @status: hardware indication of status of receive
  537. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  538. * @rx_desc: rx descriptor
  539. **/
  540. static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
  541. struct sk_buff *skb, u8 status,
  542. struct ixgbe_ring *ring,
  543. union ixgbe_adv_rx_desc *rx_desc)
  544. {
  545. struct ixgbe_adapter *adapter = q_vector->adapter;
  546. struct napi_struct *napi = &q_vector->napi;
  547. bool is_vlan = (status & IXGBE_RXD_STAT_VP);
  548. u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
  549. skb_record_rx_queue(skb, ring->queue_index);
  550. if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
  551. if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
  552. vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
  553. else
  554. napi_gro_receive(napi, skb);
  555. } else {
  556. if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
  557. vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
  558. else
  559. netif_rx(skb);
  560. }
  561. }
  562. /**
  563. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  564. * @adapter: address of board private structure
  565. * @status_err: hardware indication of status of receive
  566. * @skb: skb currently being received and modified
  567. **/
  568. static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
  569. union ixgbe_adv_rx_desc *rx_desc,
  570. struct sk_buff *skb)
  571. {
  572. u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
  573. skb->ip_summed = CHECKSUM_NONE;
  574. /* Rx csum disabled */
  575. if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
  576. return;
  577. /* if IP and error */
  578. if ((status_err & IXGBE_RXD_STAT_IPCS) &&
  579. (status_err & IXGBE_RXDADV_ERR_IPE)) {
  580. adapter->hw_csum_rx_error++;
  581. return;
  582. }
  583. if (!(status_err & IXGBE_RXD_STAT_L4CS))
  584. return;
  585. if (status_err & IXGBE_RXDADV_ERR_TCPE) {
  586. u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  587. /*
  588. * 82599 errata, UDP frames with a 0 checksum can be marked as
  589. * checksum errors.
  590. */
  591. if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
  592. (adapter->hw.mac.type == ixgbe_mac_82599EB))
  593. return;
  594. adapter->hw_csum_rx_error++;
  595. return;
  596. }
  597. /* It must be a TCP or UDP packet with a valid checksum */
  598. skb->ip_summed = CHECKSUM_UNNECESSARY;
  599. }
  600. static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
  601. struct ixgbe_ring *rx_ring, u32 val)
  602. {
  603. /*
  604. * Force memory writes to complete before letting h/w
  605. * know there are new descriptors to fetch. (Only
  606. * applicable for weak-ordered memory model archs,
  607. * such as IA-64).
  608. */
  609. wmb();
  610. IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
  611. }
  612. /**
  613. * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
  614. * @adapter: address of board private structure
  615. **/
  616. static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
  617. struct ixgbe_ring *rx_ring,
  618. int cleaned_count)
  619. {
  620. struct pci_dev *pdev = adapter->pdev;
  621. union ixgbe_adv_rx_desc *rx_desc;
  622. struct ixgbe_rx_buffer *bi;
  623. unsigned int i;
  624. i = rx_ring->next_to_use;
  625. bi = &rx_ring->rx_buffer_info[i];
  626. while (cleaned_count--) {
  627. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  628. if (!bi->page_dma &&
  629. (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
  630. if (!bi->page) {
  631. bi->page = alloc_page(GFP_ATOMIC);
  632. if (!bi->page) {
  633. adapter->alloc_rx_page_failed++;
  634. goto no_buffers;
  635. }
  636. bi->page_offset = 0;
  637. } else {
  638. /* use a half page if we're re-using */
  639. bi->page_offset ^= (PAGE_SIZE / 2);
  640. }
  641. bi->page_dma = pci_map_page(pdev, bi->page,
  642. bi->page_offset,
  643. (PAGE_SIZE / 2),
  644. PCI_DMA_FROMDEVICE);
  645. }
  646. if (!bi->skb) {
  647. struct sk_buff *skb;
  648. /* netdev_alloc_skb reserves 32 bytes up front!! */
  649. uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES;
  650. skb = netdev_alloc_skb(adapter->netdev, bufsz);
  651. if (!skb) {
  652. adapter->alloc_rx_buff_failed++;
  653. goto no_buffers;
  654. }
  655. /* advance the data pointer to the next cache line */
  656. skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES)
  657. - skb->data));
  658. bi->skb = skb;
  659. bi->dma = pci_map_single(pdev, skb->data,
  660. rx_ring->rx_buf_len,
  661. PCI_DMA_FROMDEVICE);
  662. }
  663. /* Refresh the desc even if buffer_addrs didn't change because
  664. * each write-back erases this info. */
  665. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  666. rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
  667. rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
  668. } else {
  669. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
  670. }
  671. i++;
  672. if (i == rx_ring->count)
  673. i = 0;
  674. bi = &rx_ring->rx_buffer_info[i];
  675. }
  676. no_buffers:
  677. if (rx_ring->next_to_use != i) {
  678. rx_ring->next_to_use = i;
  679. if (i-- == 0)
  680. i = (rx_ring->count - 1);
  681. ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
  682. }
  683. }
  684. static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
  685. {
  686. return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
  687. }
  688. static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
  689. {
  690. return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  691. }
  692. static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
  693. {
  694. return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
  695. IXGBE_RXDADV_RSCCNT_MASK) >>
  696. IXGBE_RXDADV_RSCCNT_SHIFT;
  697. }
  698. /**
  699. * ixgbe_transform_rsc_queue - change rsc queue into a full packet
  700. * @skb: pointer to the last skb in the rsc queue
  701. * @count: pointer to number of packets coalesced in this context
  702. *
  703. * This function changes a queue full of hw rsc buffers into a completed
  704. * packet. It uses the ->prev pointers to find the first packet and then
  705. * turns it into the frag list owner.
  706. **/
  707. static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
  708. u64 *count)
  709. {
  710. unsigned int frag_list_size = 0;
  711. while (skb->prev) {
  712. struct sk_buff *prev = skb->prev;
  713. frag_list_size += skb->len;
  714. skb->prev = NULL;
  715. skb = prev;
  716. *count += 1;
  717. }
  718. skb_shinfo(skb)->frag_list = skb->next;
  719. skb->next = NULL;
  720. skb->len += frag_list_size;
  721. skb->data_len += frag_list_size;
  722. skb->truesize += frag_list_size;
  723. return skb;
  724. }
  725. struct ixgbe_rsc_cb {
  726. dma_addr_t dma;
  727. };
  728. #define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
  729. static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  730. struct ixgbe_ring *rx_ring,
  731. int *work_done, int work_to_do)
  732. {
  733. struct ixgbe_adapter *adapter = q_vector->adapter;
  734. struct net_device *netdev = adapter->netdev;
  735. struct pci_dev *pdev = adapter->pdev;
  736. union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
  737. struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
  738. struct sk_buff *skb;
  739. unsigned int i, rsc_count = 0;
  740. u32 len, staterr;
  741. u16 hdr_info;
  742. bool cleaned = false;
  743. int cleaned_count = 0;
  744. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  745. #ifdef IXGBE_FCOE
  746. int ddp_bytes = 0;
  747. #endif /* IXGBE_FCOE */
  748. i = rx_ring->next_to_clean;
  749. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  750. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  751. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  752. while (staterr & IXGBE_RXD_STAT_DD) {
  753. u32 upper_len = 0;
  754. if (*work_done >= work_to_do)
  755. break;
  756. (*work_done)++;
  757. rmb(); /* read descriptor and rx_buffer_info after status DD */
  758. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  759. hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
  760. len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
  761. IXGBE_RXDADV_HDRBUFLEN_SHIFT;
  762. if (len > IXGBE_RX_HDR_SIZE)
  763. len = IXGBE_RX_HDR_SIZE;
  764. upper_len = le16_to_cpu(rx_desc->wb.upper.length);
  765. } else {
  766. len = le16_to_cpu(rx_desc->wb.upper.length);
  767. }
  768. cleaned = true;
  769. skb = rx_buffer_info->skb;
  770. prefetch(skb->data);
  771. rx_buffer_info->skb = NULL;
  772. if (rx_buffer_info->dma) {
  773. if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  774. (!(staterr & IXGBE_RXD_STAT_EOP)) &&
  775. (!(skb->prev)))
  776. /*
  777. * When HWRSC is enabled, delay unmapping
  778. * of the first packet. It carries the
  779. * header information, HW may still
  780. * access the header after the writeback.
  781. * Only unmap it when EOP is reached
  782. */
  783. IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
  784. else
  785. pci_unmap_single(pdev, rx_buffer_info->dma,
  786. rx_ring->rx_buf_len,
  787. PCI_DMA_FROMDEVICE);
  788. rx_buffer_info->dma = 0;
  789. skb_put(skb, len);
  790. }
  791. if (upper_len) {
  792. pci_unmap_page(pdev, rx_buffer_info->page_dma,
  793. PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
  794. rx_buffer_info->page_dma = 0;
  795. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  796. rx_buffer_info->page,
  797. rx_buffer_info->page_offset,
  798. upper_len);
  799. if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
  800. (page_count(rx_buffer_info->page) != 1))
  801. rx_buffer_info->page = NULL;
  802. else
  803. get_page(rx_buffer_info->page);
  804. skb->len += upper_len;
  805. skb->data_len += upper_len;
  806. skb->truesize += upper_len;
  807. }
  808. i++;
  809. if (i == rx_ring->count)
  810. i = 0;
  811. next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
  812. prefetch(next_rxd);
  813. cleaned_count++;
  814. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  815. rsc_count = ixgbe_get_rsc_count(rx_desc);
  816. if (rsc_count) {
  817. u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
  818. IXGBE_RXDADV_NEXTP_SHIFT;
  819. next_buffer = &rx_ring->rx_buffer_info[nextp];
  820. } else {
  821. next_buffer = &rx_ring->rx_buffer_info[i];
  822. }
  823. if (staterr & IXGBE_RXD_STAT_EOP) {
  824. if (skb->prev)
  825. skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
  826. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  827. if (IXGBE_RSC_CB(skb)->dma) {
  828. pci_unmap_single(pdev, IXGBE_RSC_CB(skb)->dma,
  829. rx_ring->rx_buf_len,
  830. PCI_DMA_FROMDEVICE);
  831. IXGBE_RSC_CB(skb)->dma = 0;
  832. }
  833. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
  834. rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
  835. else
  836. rx_ring->rsc_count++;
  837. rx_ring->rsc_flush++;
  838. }
  839. rx_ring->stats.packets++;
  840. rx_ring->stats.bytes += skb->len;
  841. } else {
  842. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  843. rx_buffer_info->skb = next_buffer->skb;
  844. rx_buffer_info->dma = next_buffer->dma;
  845. next_buffer->skb = skb;
  846. next_buffer->dma = 0;
  847. } else {
  848. skb->next = next_buffer->skb;
  849. skb->next->prev = skb;
  850. }
  851. rx_ring->non_eop_descs++;
  852. goto next_desc;
  853. }
  854. if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
  855. dev_kfree_skb_irq(skb);
  856. goto next_desc;
  857. }
  858. ixgbe_rx_checksum(adapter, rx_desc, skb);
  859. /* probably a little skewed due to removing CRC */
  860. total_rx_bytes += skb->len;
  861. total_rx_packets++;
  862. skb->protocol = eth_type_trans(skb, adapter->netdev);
  863. #ifdef IXGBE_FCOE
  864. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  865. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  866. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  867. if (!ddp_bytes)
  868. goto next_desc;
  869. }
  870. #endif /* IXGBE_FCOE */
  871. ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
  872. next_desc:
  873. rx_desc->wb.upper.status_error = 0;
  874. /* return some buffers to hardware, one at a time is too slow */
  875. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  876. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  877. cleaned_count = 0;
  878. }
  879. /* use prefetched values */
  880. rx_desc = next_rxd;
  881. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  882. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  883. }
  884. rx_ring->next_to_clean = i;
  885. cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
  886. if (cleaned_count)
  887. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  888. #ifdef IXGBE_FCOE
  889. /* include DDPed FCoE data */
  890. if (ddp_bytes > 0) {
  891. unsigned int mss;
  892. mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
  893. sizeof(struct fc_frame_header) -
  894. sizeof(struct fcoe_crc_eof);
  895. if (mss > 512)
  896. mss &= ~511;
  897. total_rx_bytes += ddp_bytes;
  898. total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
  899. }
  900. #endif /* IXGBE_FCOE */
  901. rx_ring->total_packets += total_rx_packets;
  902. rx_ring->total_bytes += total_rx_bytes;
  903. netdev->stats.rx_bytes += total_rx_bytes;
  904. netdev->stats.rx_packets += total_rx_packets;
  905. return cleaned;
  906. }
  907. static int ixgbe_clean_rxonly(struct napi_struct *, int);
  908. /**
  909. * ixgbe_configure_msix - Configure MSI-X hardware
  910. * @adapter: board private structure
  911. *
  912. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  913. * interrupts.
  914. **/
  915. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  916. {
  917. struct ixgbe_q_vector *q_vector;
  918. int i, j, q_vectors, v_idx, r_idx;
  919. u32 mask;
  920. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  921. /*
  922. * Populate the IVAR table and set the ITR values to the
  923. * corresponding register.
  924. */
  925. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  926. q_vector = adapter->q_vector[v_idx];
  927. /* XXX for_each_set_bit(...) */
  928. r_idx = find_first_bit(q_vector->rxr_idx,
  929. adapter->num_rx_queues);
  930. for (i = 0; i < q_vector->rxr_count; i++) {
  931. j = adapter->rx_ring[r_idx]->reg_idx;
  932. ixgbe_set_ivar(adapter, 0, j, v_idx);
  933. r_idx = find_next_bit(q_vector->rxr_idx,
  934. adapter->num_rx_queues,
  935. r_idx + 1);
  936. }
  937. r_idx = find_first_bit(q_vector->txr_idx,
  938. adapter->num_tx_queues);
  939. for (i = 0; i < q_vector->txr_count; i++) {
  940. j = adapter->tx_ring[r_idx]->reg_idx;
  941. ixgbe_set_ivar(adapter, 1, j, v_idx);
  942. r_idx = find_next_bit(q_vector->txr_idx,
  943. adapter->num_tx_queues,
  944. r_idx + 1);
  945. }
  946. if (q_vector->txr_count && !q_vector->rxr_count)
  947. /* tx only */
  948. q_vector->eitr = adapter->tx_eitr_param;
  949. else if (q_vector->rxr_count)
  950. /* rx or mixed */
  951. q_vector->eitr = adapter->rx_eitr_param;
  952. ixgbe_write_eitr(q_vector);
  953. }
  954. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  955. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  956. v_idx);
  957. else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  958. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  959. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  960. /* set up to autoclear timer, and the vectors */
  961. mask = IXGBE_EIMS_ENABLE_MASK;
  962. if (adapter->num_vfs)
  963. mask &= ~(IXGBE_EIMS_OTHER |
  964. IXGBE_EIMS_MAILBOX |
  965. IXGBE_EIMS_LSC);
  966. else
  967. mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
  968. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  969. }
  970. enum latency_range {
  971. lowest_latency = 0,
  972. low_latency = 1,
  973. bulk_latency = 2,
  974. latency_invalid = 255
  975. };
  976. /**
  977. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  978. * @adapter: pointer to adapter
  979. * @eitr: eitr setting (ints per sec) to give last timeslice
  980. * @itr_setting: current throttle rate in ints/second
  981. * @packets: the number of packets during this measurement interval
  982. * @bytes: the number of bytes during this measurement interval
  983. *
  984. * Stores a new ITR value based on packets and byte
  985. * counts during the last interrupt. The advantage of per interrupt
  986. * computation is faster updates and more accurate ITR for the current
  987. * traffic pattern. Constants in this function were computed
  988. * based on theoretical maximum wire speed and thresholds were set based
  989. * on testing data as well as attempting to minimize response time
  990. * while increasing bulk throughput.
  991. * this functionality is controlled by the InterruptThrottleRate module
  992. * parameter (see ixgbe_param.c)
  993. **/
  994. static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
  995. u32 eitr, u8 itr_setting,
  996. int packets, int bytes)
  997. {
  998. unsigned int retval = itr_setting;
  999. u32 timepassed_us;
  1000. u64 bytes_perint;
  1001. if (packets == 0)
  1002. goto update_itr_done;
  1003. /* simple throttlerate management
  1004. * 0-20MB/s lowest (100000 ints/s)
  1005. * 20-100MB/s low (20000 ints/s)
  1006. * 100-1249MB/s bulk (8000 ints/s)
  1007. */
  1008. /* what was last interrupt timeslice? */
  1009. timepassed_us = 1000000/eitr;
  1010. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  1011. switch (itr_setting) {
  1012. case lowest_latency:
  1013. if (bytes_perint > adapter->eitr_low)
  1014. retval = low_latency;
  1015. break;
  1016. case low_latency:
  1017. if (bytes_perint > adapter->eitr_high)
  1018. retval = bulk_latency;
  1019. else if (bytes_perint <= adapter->eitr_low)
  1020. retval = lowest_latency;
  1021. break;
  1022. case bulk_latency:
  1023. if (bytes_perint <= adapter->eitr_high)
  1024. retval = low_latency;
  1025. break;
  1026. }
  1027. update_itr_done:
  1028. return retval;
  1029. }
  1030. /**
  1031. * ixgbe_write_eitr - write EITR register in hardware specific way
  1032. * @q_vector: structure containing interrupt and ring information
  1033. *
  1034. * This function is made to be called by ethtool and by the driver
  1035. * when it needs to update EITR registers at runtime. Hardware
  1036. * specific quirks/differences are taken care of here.
  1037. */
  1038. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  1039. {
  1040. struct ixgbe_adapter *adapter = q_vector->adapter;
  1041. struct ixgbe_hw *hw = &adapter->hw;
  1042. int v_idx = q_vector->v_idx;
  1043. u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
  1044. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1045. /* must write high and low 16 bits to reset counter */
  1046. itr_reg |= (itr_reg << 16);
  1047. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1048. /*
  1049. * set the WDIS bit to not clear the timer bits and cause an
  1050. * immediate assertion of the interrupt
  1051. */
  1052. itr_reg |= IXGBE_EITR_CNT_WDIS;
  1053. }
  1054. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  1055. }
  1056. static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
  1057. {
  1058. struct ixgbe_adapter *adapter = q_vector->adapter;
  1059. u32 new_itr;
  1060. u8 current_itr, ret_itr;
  1061. int i, r_idx;
  1062. struct ixgbe_ring *rx_ring, *tx_ring;
  1063. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1064. for (i = 0; i < q_vector->txr_count; i++) {
  1065. tx_ring = adapter->tx_ring[r_idx];
  1066. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1067. q_vector->tx_itr,
  1068. tx_ring->total_packets,
  1069. tx_ring->total_bytes);
  1070. /* if the result for this queue would decrease interrupt
  1071. * rate for this vector then use that result */
  1072. q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
  1073. q_vector->tx_itr - 1 : ret_itr);
  1074. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1075. r_idx + 1);
  1076. }
  1077. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1078. for (i = 0; i < q_vector->rxr_count; i++) {
  1079. rx_ring = adapter->rx_ring[r_idx];
  1080. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1081. q_vector->rx_itr,
  1082. rx_ring->total_packets,
  1083. rx_ring->total_bytes);
  1084. /* if the result for this queue would decrease interrupt
  1085. * rate for this vector then use that result */
  1086. q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
  1087. q_vector->rx_itr - 1 : ret_itr);
  1088. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1089. r_idx + 1);
  1090. }
  1091. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1092. switch (current_itr) {
  1093. /* counts and packets in update_itr are dependent on these numbers */
  1094. case lowest_latency:
  1095. new_itr = 100000;
  1096. break;
  1097. case low_latency:
  1098. new_itr = 20000; /* aka hwitr = ~200 */
  1099. break;
  1100. case bulk_latency:
  1101. default:
  1102. new_itr = 8000;
  1103. break;
  1104. }
  1105. if (new_itr != q_vector->eitr) {
  1106. /* do an exponential smoothing */
  1107. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1108. /* save the algorithm value here, not the smoothed one */
  1109. q_vector->eitr = new_itr;
  1110. ixgbe_write_eitr(q_vector);
  1111. }
  1112. return;
  1113. }
  1114. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  1115. {
  1116. struct ixgbe_hw *hw = &adapter->hw;
  1117. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  1118. (eicr & IXGBE_EICR_GPI_SDP1)) {
  1119. DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
  1120. /* write to clear the interrupt */
  1121. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1122. }
  1123. }
  1124. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  1125. {
  1126. struct ixgbe_hw *hw = &adapter->hw;
  1127. if (eicr & IXGBE_EICR_GPI_SDP1) {
  1128. /* Clear the interrupt */
  1129. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1130. schedule_work(&adapter->multispeed_fiber_task);
  1131. } else if (eicr & IXGBE_EICR_GPI_SDP2) {
  1132. /* Clear the interrupt */
  1133. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
  1134. schedule_work(&adapter->sfp_config_module_task);
  1135. } else {
  1136. /* Interrupt isn't for us... */
  1137. return;
  1138. }
  1139. }
  1140. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  1141. {
  1142. struct ixgbe_hw *hw = &adapter->hw;
  1143. adapter->lsc_int++;
  1144. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  1145. adapter->link_check_timeout = jiffies;
  1146. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  1147. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  1148. IXGBE_WRITE_FLUSH(hw);
  1149. schedule_work(&adapter->watchdog_task);
  1150. }
  1151. }
  1152. static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
  1153. {
  1154. struct net_device *netdev = data;
  1155. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1156. struct ixgbe_hw *hw = &adapter->hw;
  1157. u32 eicr;
  1158. /*
  1159. * Workaround for Silicon errata. Use clear-by-write instead
  1160. * of clear-by-read. Reading with EICS will return the
  1161. * interrupt causes without clearing, which later be done
  1162. * with the write to EICR.
  1163. */
  1164. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  1165. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  1166. if (eicr & IXGBE_EICR_LSC)
  1167. ixgbe_check_lsc(adapter);
  1168. if (eicr & IXGBE_EICR_MAILBOX)
  1169. ixgbe_msg_task(adapter);
  1170. if (hw->mac.type == ixgbe_mac_82598EB)
  1171. ixgbe_check_fan_failure(adapter, eicr);
  1172. if (hw->mac.type == ixgbe_mac_82599EB) {
  1173. ixgbe_check_sfp_event(adapter, eicr);
  1174. /* Handle Flow Director Full threshold interrupt */
  1175. if (eicr & IXGBE_EICR_FLOW_DIR) {
  1176. int i;
  1177. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
  1178. /* Disable transmits before FDIR Re-initialization */
  1179. netif_tx_stop_all_queues(netdev);
  1180. for (i = 0; i < adapter->num_tx_queues; i++) {
  1181. struct ixgbe_ring *tx_ring =
  1182. adapter->tx_ring[i];
  1183. if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
  1184. &tx_ring->reinit_state))
  1185. schedule_work(&adapter->fdir_reinit_task);
  1186. }
  1187. }
  1188. }
  1189. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1190. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
  1191. return IRQ_HANDLED;
  1192. }
  1193. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  1194. u64 qmask)
  1195. {
  1196. u32 mask;
  1197. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1198. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1199. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1200. } else {
  1201. mask = (qmask & 0xFFFFFFFF);
  1202. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
  1203. mask = (qmask >> 32);
  1204. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
  1205. }
  1206. /* skip the flush */
  1207. }
  1208. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  1209. u64 qmask)
  1210. {
  1211. u32 mask;
  1212. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1213. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1214. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
  1215. } else {
  1216. mask = (qmask & 0xFFFFFFFF);
  1217. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
  1218. mask = (qmask >> 32);
  1219. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
  1220. }
  1221. /* skip the flush */
  1222. }
  1223. static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
  1224. {
  1225. struct ixgbe_q_vector *q_vector = data;
  1226. struct ixgbe_adapter *adapter = q_vector->adapter;
  1227. struct ixgbe_ring *tx_ring;
  1228. int i, r_idx;
  1229. if (!q_vector->txr_count)
  1230. return IRQ_HANDLED;
  1231. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1232. for (i = 0; i < q_vector->txr_count; i++) {
  1233. tx_ring = adapter->tx_ring[r_idx];
  1234. tx_ring->total_bytes = 0;
  1235. tx_ring->total_packets = 0;
  1236. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1237. r_idx + 1);
  1238. }
  1239. /* EIAM disabled interrupts (on this vector) for us */
  1240. napi_schedule(&q_vector->napi);
  1241. return IRQ_HANDLED;
  1242. }
  1243. /**
  1244. * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
  1245. * @irq: unused
  1246. * @data: pointer to our q_vector struct for this interrupt vector
  1247. **/
  1248. static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
  1249. {
  1250. struct ixgbe_q_vector *q_vector = data;
  1251. struct ixgbe_adapter *adapter = q_vector->adapter;
  1252. struct ixgbe_ring *rx_ring;
  1253. int r_idx;
  1254. int i;
  1255. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1256. for (i = 0; i < q_vector->rxr_count; i++) {
  1257. rx_ring = adapter->rx_ring[r_idx];
  1258. rx_ring->total_bytes = 0;
  1259. rx_ring->total_packets = 0;
  1260. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1261. r_idx + 1);
  1262. }
  1263. if (!q_vector->rxr_count)
  1264. return IRQ_HANDLED;
  1265. /* disable interrupts on this vector only */
  1266. /* EIAM disabled interrupts (on this vector) for us */
  1267. napi_schedule(&q_vector->napi);
  1268. return IRQ_HANDLED;
  1269. }
  1270. static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
  1271. {
  1272. struct ixgbe_q_vector *q_vector = data;
  1273. struct ixgbe_adapter *adapter = q_vector->adapter;
  1274. struct ixgbe_ring *ring;
  1275. int r_idx;
  1276. int i;
  1277. if (!q_vector->txr_count && !q_vector->rxr_count)
  1278. return IRQ_HANDLED;
  1279. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1280. for (i = 0; i < q_vector->txr_count; i++) {
  1281. ring = adapter->tx_ring[r_idx];
  1282. ring->total_bytes = 0;
  1283. ring->total_packets = 0;
  1284. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1285. r_idx + 1);
  1286. }
  1287. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1288. for (i = 0; i < q_vector->rxr_count; i++) {
  1289. ring = adapter->rx_ring[r_idx];
  1290. ring->total_bytes = 0;
  1291. ring->total_packets = 0;
  1292. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1293. r_idx + 1);
  1294. }
  1295. /* EIAM disabled interrupts (on this vector) for us */
  1296. napi_schedule(&q_vector->napi);
  1297. return IRQ_HANDLED;
  1298. }
  1299. /**
  1300. * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
  1301. * @napi: napi struct with our devices info in it
  1302. * @budget: amount of work driver is allowed to do this pass, in packets
  1303. *
  1304. * This function is optimized for cleaning one queue only on a single
  1305. * q_vector!!!
  1306. **/
  1307. static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
  1308. {
  1309. struct ixgbe_q_vector *q_vector =
  1310. container_of(napi, struct ixgbe_q_vector, napi);
  1311. struct ixgbe_adapter *adapter = q_vector->adapter;
  1312. struct ixgbe_ring *rx_ring = NULL;
  1313. int work_done = 0;
  1314. long r_idx;
  1315. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1316. rx_ring = adapter->rx_ring[r_idx];
  1317. #ifdef CONFIG_IXGBE_DCA
  1318. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1319. ixgbe_update_rx_dca(adapter, rx_ring);
  1320. #endif
  1321. ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
  1322. /* If all Rx work done, exit the polling mode */
  1323. if (work_done < budget) {
  1324. napi_complete(napi);
  1325. if (adapter->rx_itr_setting & 1)
  1326. ixgbe_set_itr_msix(q_vector);
  1327. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1328. ixgbe_irq_enable_queues(adapter,
  1329. ((u64)1 << q_vector->v_idx));
  1330. }
  1331. return work_done;
  1332. }
  1333. /**
  1334. * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
  1335. * @napi: napi struct with our devices info in it
  1336. * @budget: amount of work driver is allowed to do this pass, in packets
  1337. *
  1338. * This function will clean more than one rx queue associated with a
  1339. * q_vector.
  1340. **/
  1341. static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
  1342. {
  1343. struct ixgbe_q_vector *q_vector =
  1344. container_of(napi, struct ixgbe_q_vector, napi);
  1345. struct ixgbe_adapter *adapter = q_vector->adapter;
  1346. struct ixgbe_ring *ring = NULL;
  1347. int work_done = 0, i;
  1348. long r_idx;
  1349. bool tx_clean_complete = true;
  1350. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1351. for (i = 0; i < q_vector->txr_count; i++) {
  1352. ring = adapter->tx_ring[r_idx];
  1353. #ifdef CONFIG_IXGBE_DCA
  1354. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1355. ixgbe_update_tx_dca(adapter, ring);
  1356. #endif
  1357. tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
  1358. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1359. r_idx + 1);
  1360. }
  1361. /* attempt to distribute budget to each queue fairly, but don't allow
  1362. * the budget to go below 1 because we'll exit polling */
  1363. budget /= (q_vector->rxr_count ?: 1);
  1364. budget = max(budget, 1);
  1365. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1366. for (i = 0; i < q_vector->rxr_count; i++) {
  1367. ring = adapter->rx_ring[r_idx];
  1368. #ifdef CONFIG_IXGBE_DCA
  1369. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1370. ixgbe_update_rx_dca(adapter, ring);
  1371. #endif
  1372. ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
  1373. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1374. r_idx + 1);
  1375. }
  1376. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1377. ring = adapter->rx_ring[r_idx];
  1378. /* If all Rx work done, exit the polling mode */
  1379. if (work_done < budget) {
  1380. napi_complete(napi);
  1381. if (adapter->rx_itr_setting & 1)
  1382. ixgbe_set_itr_msix(q_vector);
  1383. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1384. ixgbe_irq_enable_queues(adapter,
  1385. ((u64)1 << q_vector->v_idx));
  1386. return 0;
  1387. }
  1388. return work_done;
  1389. }
  1390. /**
  1391. * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
  1392. * @napi: napi struct with our devices info in it
  1393. * @budget: amount of work driver is allowed to do this pass, in packets
  1394. *
  1395. * This function is optimized for cleaning one queue only on a single
  1396. * q_vector!!!
  1397. **/
  1398. static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
  1399. {
  1400. struct ixgbe_q_vector *q_vector =
  1401. container_of(napi, struct ixgbe_q_vector, napi);
  1402. struct ixgbe_adapter *adapter = q_vector->adapter;
  1403. struct ixgbe_ring *tx_ring = NULL;
  1404. int work_done = 0;
  1405. long r_idx;
  1406. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1407. tx_ring = adapter->tx_ring[r_idx];
  1408. #ifdef CONFIG_IXGBE_DCA
  1409. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1410. ixgbe_update_tx_dca(adapter, tx_ring);
  1411. #endif
  1412. if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
  1413. work_done = budget;
  1414. /* If all Tx work done, exit the polling mode */
  1415. if (work_done < budget) {
  1416. napi_complete(napi);
  1417. if (adapter->tx_itr_setting & 1)
  1418. ixgbe_set_itr_msix(q_vector);
  1419. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1420. ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
  1421. }
  1422. return work_done;
  1423. }
  1424. static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
  1425. int r_idx)
  1426. {
  1427. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1428. set_bit(r_idx, q_vector->rxr_idx);
  1429. q_vector->rxr_count++;
  1430. }
  1431. static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
  1432. int t_idx)
  1433. {
  1434. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1435. set_bit(t_idx, q_vector->txr_idx);
  1436. q_vector->txr_count++;
  1437. }
  1438. /**
  1439. * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
  1440. * @adapter: board private structure to initialize
  1441. * @vectors: allotted vector count for descriptor rings
  1442. *
  1443. * This function maps descriptor rings to the queue-specific vectors
  1444. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  1445. * one vector per ring/queue, but on a constrained vector budget, we
  1446. * group the rings as "efficiently" as possible. You would add new
  1447. * mapping configurations in here.
  1448. **/
  1449. static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
  1450. int vectors)
  1451. {
  1452. int v_start = 0;
  1453. int rxr_idx = 0, txr_idx = 0;
  1454. int rxr_remaining = adapter->num_rx_queues;
  1455. int txr_remaining = adapter->num_tx_queues;
  1456. int i, j;
  1457. int rqpv, tqpv;
  1458. int err = 0;
  1459. /* No mapping required if MSI-X is disabled. */
  1460. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  1461. goto out;
  1462. /*
  1463. * The ideal configuration...
  1464. * We have enough vectors to map one per queue.
  1465. */
  1466. if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
  1467. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  1468. map_vector_to_rxq(adapter, v_start, rxr_idx);
  1469. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  1470. map_vector_to_txq(adapter, v_start, txr_idx);
  1471. goto out;
  1472. }
  1473. /*
  1474. * If we don't have enough vectors for a 1-to-1
  1475. * mapping, we'll have to group them so there are
  1476. * multiple queues per vector.
  1477. */
  1478. /* Re-adjusting *qpv takes care of the remainder. */
  1479. for (i = v_start; i < vectors; i++) {
  1480. rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
  1481. for (j = 0; j < rqpv; j++) {
  1482. map_vector_to_rxq(adapter, i, rxr_idx);
  1483. rxr_idx++;
  1484. rxr_remaining--;
  1485. }
  1486. }
  1487. for (i = v_start; i < vectors; i++) {
  1488. tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
  1489. for (j = 0; j < tqpv; j++) {
  1490. map_vector_to_txq(adapter, i, txr_idx);
  1491. txr_idx++;
  1492. txr_remaining--;
  1493. }
  1494. }
  1495. out:
  1496. return err;
  1497. }
  1498. /**
  1499. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  1500. * @adapter: board private structure
  1501. *
  1502. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  1503. * interrupts from the kernel.
  1504. **/
  1505. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  1506. {
  1507. struct net_device *netdev = adapter->netdev;
  1508. irqreturn_t (*handler)(int, void *);
  1509. int i, vector, q_vectors, err;
  1510. int ri=0, ti=0;
  1511. /* Decrement for Other and TCP Timer vectors */
  1512. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1513. /* Map the Tx/Rx rings to the vectors we were allotted. */
  1514. err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
  1515. if (err)
  1516. goto out;
  1517. #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
  1518. (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
  1519. &ixgbe_msix_clean_many)
  1520. for (vector = 0; vector < q_vectors; vector++) {
  1521. handler = SET_HANDLER(adapter->q_vector[vector]);
  1522. if(handler == &ixgbe_msix_clean_rx) {
  1523. sprintf(adapter->name[vector], "%s-%s-%d",
  1524. netdev->name, "rx", ri++);
  1525. }
  1526. else if(handler == &ixgbe_msix_clean_tx) {
  1527. sprintf(adapter->name[vector], "%s-%s-%d",
  1528. netdev->name, "tx", ti++);
  1529. }
  1530. else
  1531. sprintf(adapter->name[vector], "%s-%s-%d",
  1532. netdev->name, "TxRx", vector);
  1533. err = request_irq(adapter->msix_entries[vector].vector,
  1534. handler, 0, adapter->name[vector],
  1535. adapter->q_vector[vector]);
  1536. if (err) {
  1537. DPRINTK(PROBE, ERR,
  1538. "request_irq failed for MSIX interrupt "
  1539. "Error: %d\n", err);
  1540. goto free_queue_irqs;
  1541. }
  1542. }
  1543. sprintf(adapter->name[vector], "%s:lsc", netdev->name);
  1544. err = request_irq(adapter->msix_entries[vector].vector,
  1545. ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
  1546. if (err) {
  1547. DPRINTK(PROBE, ERR,
  1548. "request_irq for msix_lsc failed: %d\n", err);
  1549. goto free_queue_irqs;
  1550. }
  1551. return 0;
  1552. free_queue_irqs:
  1553. for (i = vector - 1; i >= 0; i--)
  1554. free_irq(adapter->msix_entries[--vector].vector,
  1555. adapter->q_vector[i]);
  1556. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  1557. pci_disable_msix(adapter->pdev);
  1558. kfree(adapter->msix_entries);
  1559. adapter->msix_entries = NULL;
  1560. out:
  1561. return err;
  1562. }
  1563. static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
  1564. {
  1565. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  1566. u8 current_itr;
  1567. u32 new_itr = q_vector->eitr;
  1568. struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
  1569. struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
  1570. q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
  1571. q_vector->tx_itr,
  1572. tx_ring->total_packets,
  1573. tx_ring->total_bytes);
  1574. q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
  1575. q_vector->rx_itr,
  1576. rx_ring->total_packets,
  1577. rx_ring->total_bytes);
  1578. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1579. switch (current_itr) {
  1580. /* counts and packets in update_itr are dependent on these numbers */
  1581. case lowest_latency:
  1582. new_itr = 100000;
  1583. break;
  1584. case low_latency:
  1585. new_itr = 20000; /* aka hwitr = ~200 */
  1586. break;
  1587. case bulk_latency:
  1588. new_itr = 8000;
  1589. break;
  1590. default:
  1591. break;
  1592. }
  1593. if (new_itr != q_vector->eitr) {
  1594. /* do an exponential smoothing */
  1595. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1596. /* save the algorithm value here, not the smoothed one */
  1597. q_vector->eitr = new_itr;
  1598. ixgbe_write_eitr(q_vector);
  1599. }
  1600. return;
  1601. }
  1602. /**
  1603. * ixgbe_irq_enable - Enable default interrupt generation settings
  1604. * @adapter: board private structure
  1605. **/
  1606. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
  1607. {
  1608. u32 mask;
  1609. mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  1610. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  1611. mask |= IXGBE_EIMS_GPI_SDP1;
  1612. if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1613. mask |= IXGBE_EIMS_ECC;
  1614. mask |= IXGBE_EIMS_GPI_SDP1;
  1615. mask |= IXGBE_EIMS_GPI_SDP2;
  1616. if (adapter->num_vfs)
  1617. mask |= IXGBE_EIMS_MAILBOX;
  1618. }
  1619. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  1620. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  1621. mask |= IXGBE_EIMS_FLOW_DIR;
  1622. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1623. ixgbe_irq_enable_queues(adapter, ~0);
  1624. IXGBE_WRITE_FLUSH(&adapter->hw);
  1625. if (adapter->num_vfs > 32) {
  1626. u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
  1627. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  1628. }
  1629. }
  1630. /**
  1631. * ixgbe_intr - legacy mode Interrupt Handler
  1632. * @irq: interrupt number
  1633. * @data: pointer to a network interface device structure
  1634. **/
  1635. static irqreturn_t ixgbe_intr(int irq, void *data)
  1636. {
  1637. struct net_device *netdev = data;
  1638. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1639. struct ixgbe_hw *hw = &adapter->hw;
  1640. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  1641. u32 eicr;
  1642. /*
  1643. * Workaround for silicon errata. Mask the interrupts
  1644. * before the read of EICR.
  1645. */
  1646. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  1647. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  1648. * therefore no explict interrupt disable is necessary */
  1649. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  1650. if (!eicr) {
  1651. /* shared interrupt alert!
  1652. * make sure interrupts are enabled because the read will
  1653. * have disabled interrupts due to EIAM */
  1654. ixgbe_irq_enable(adapter);
  1655. return IRQ_NONE; /* Not our interrupt */
  1656. }
  1657. if (eicr & IXGBE_EICR_LSC)
  1658. ixgbe_check_lsc(adapter);
  1659. if (hw->mac.type == ixgbe_mac_82599EB)
  1660. ixgbe_check_sfp_event(adapter, eicr);
  1661. ixgbe_check_fan_failure(adapter, eicr);
  1662. if (napi_schedule_prep(&(q_vector->napi))) {
  1663. adapter->tx_ring[0]->total_packets = 0;
  1664. adapter->tx_ring[0]->total_bytes = 0;
  1665. adapter->rx_ring[0]->total_packets = 0;
  1666. adapter->rx_ring[0]->total_bytes = 0;
  1667. /* would disable interrupts here but EIAM disabled it */
  1668. __napi_schedule(&(q_vector->napi));
  1669. }
  1670. return IRQ_HANDLED;
  1671. }
  1672. static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
  1673. {
  1674. int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1675. for (i = 0; i < q_vectors; i++) {
  1676. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  1677. bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
  1678. bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
  1679. q_vector->rxr_count = 0;
  1680. q_vector->txr_count = 0;
  1681. }
  1682. }
  1683. /**
  1684. * ixgbe_request_irq - initialize interrupts
  1685. * @adapter: board private structure
  1686. *
  1687. * Attempts to configure interrupts using the best available
  1688. * capabilities of the hardware and kernel.
  1689. **/
  1690. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  1691. {
  1692. struct net_device *netdev = adapter->netdev;
  1693. int err;
  1694. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  1695. err = ixgbe_request_msix_irqs(adapter);
  1696. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  1697. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  1698. netdev->name, netdev);
  1699. } else {
  1700. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  1701. netdev->name, netdev);
  1702. }
  1703. if (err)
  1704. DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
  1705. return err;
  1706. }
  1707. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  1708. {
  1709. struct net_device *netdev = adapter->netdev;
  1710. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  1711. int i, q_vectors;
  1712. q_vectors = adapter->num_msix_vectors;
  1713. i = q_vectors - 1;
  1714. free_irq(adapter->msix_entries[i].vector, netdev);
  1715. i--;
  1716. for (; i >= 0; i--) {
  1717. free_irq(adapter->msix_entries[i].vector,
  1718. adapter->q_vector[i]);
  1719. }
  1720. ixgbe_reset_q_vectors(adapter);
  1721. } else {
  1722. free_irq(adapter->pdev->irq, netdev);
  1723. }
  1724. }
  1725. /**
  1726. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  1727. * @adapter: board private structure
  1728. **/
  1729. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  1730. {
  1731. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1732. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  1733. } else {
  1734. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  1735. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  1736. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  1737. if (adapter->num_vfs > 32)
  1738. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  1739. }
  1740. IXGBE_WRITE_FLUSH(&adapter->hw);
  1741. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  1742. int i;
  1743. for (i = 0; i < adapter->num_msix_vectors; i++)
  1744. synchronize_irq(adapter->msix_entries[i].vector);
  1745. } else {
  1746. synchronize_irq(adapter->pdev->irq);
  1747. }
  1748. }
  1749. /**
  1750. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  1751. *
  1752. **/
  1753. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  1754. {
  1755. struct ixgbe_hw *hw = &adapter->hw;
  1756. IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
  1757. EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
  1758. ixgbe_set_ivar(adapter, 0, 0, 0);
  1759. ixgbe_set_ivar(adapter, 1, 0, 0);
  1760. map_vector_to_rxq(adapter, 0, 0);
  1761. map_vector_to_txq(adapter, 0, 0);
  1762. DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
  1763. }
  1764. /**
  1765. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  1766. * @adapter: board private structure
  1767. *
  1768. * Configure the Tx unit of the MAC after a reset.
  1769. **/
  1770. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  1771. {
  1772. u64 tdba;
  1773. struct ixgbe_hw *hw = &adapter->hw;
  1774. u32 i, j, tdlen, txctrl;
  1775. /* Setup the HW Tx Head and Tail descriptor pointers */
  1776. for (i = 0; i < adapter->num_tx_queues; i++) {
  1777. struct ixgbe_ring *ring = adapter->tx_ring[i];
  1778. j = ring->reg_idx;
  1779. tdba = ring->dma;
  1780. tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
  1781. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
  1782. (tdba & DMA_BIT_MASK(32)));
  1783. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
  1784. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
  1785. IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
  1786. IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
  1787. adapter->tx_ring[i]->head = IXGBE_TDH(j);
  1788. adapter->tx_ring[i]->tail = IXGBE_TDT(j);
  1789. /*
  1790. * Disable Tx Head Writeback RO bit, since this hoses
  1791. * bookkeeping if things aren't delivered in order.
  1792. */
  1793. switch (hw->mac.type) {
  1794. case ixgbe_mac_82598EB:
  1795. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
  1796. break;
  1797. case ixgbe_mac_82599EB:
  1798. default:
  1799. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j));
  1800. break;
  1801. }
  1802. txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
  1803. switch (hw->mac.type) {
  1804. case ixgbe_mac_82598EB:
  1805. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
  1806. break;
  1807. case ixgbe_mac_82599EB:
  1808. default:
  1809. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl);
  1810. break;
  1811. }
  1812. }
  1813. if (hw->mac.type == ixgbe_mac_82599EB) {
  1814. u32 rttdcs;
  1815. u32 mask;
  1816. /* disable the arbiter while setting MTQC */
  1817. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  1818. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  1819. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  1820. /* set transmit pool layout */
  1821. mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
  1822. switch (adapter->flags & mask) {
  1823. case (IXGBE_FLAG_SRIOV_ENABLED):
  1824. IXGBE_WRITE_REG(hw, IXGBE_MTQC,
  1825. (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
  1826. break;
  1827. case (IXGBE_FLAG_DCB_ENABLED):
  1828. /* We enable 8 traffic classes, DCB only */
  1829. IXGBE_WRITE_REG(hw, IXGBE_MTQC,
  1830. (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
  1831. break;
  1832. default:
  1833. IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
  1834. break;
  1835. }
  1836. /* re-eable the arbiter */
  1837. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  1838. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  1839. }
  1840. }
  1841. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  1842. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  1843. struct ixgbe_ring *rx_ring)
  1844. {
  1845. u32 srrctl;
  1846. int index;
  1847. struct ixgbe_ring_feature *feature = adapter->ring_feature;
  1848. index = rx_ring->reg_idx;
  1849. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1850. unsigned long mask;
  1851. mask = (unsigned long) feature[RING_F_RSS].mask;
  1852. index = index & mask;
  1853. }
  1854. srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
  1855. srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
  1856. srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
  1857. srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
  1858. IXGBE_SRRCTL_BSIZEHDR_MASK;
  1859. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1860. #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
  1861. srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  1862. #else
  1863. srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  1864. #endif
  1865. srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  1866. } else {
  1867. srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
  1868. IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  1869. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  1870. }
  1871. IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
  1872. }
  1873. static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  1874. {
  1875. u32 mrqc = 0;
  1876. int mask;
  1877. if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
  1878. return mrqc;
  1879. mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
  1880. #ifdef CONFIG_IXGBE_DCB
  1881. | IXGBE_FLAG_DCB_ENABLED
  1882. #endif
  1883. | IXGBE_FLAG_SRIOV_ENABLED
  1884. );
  1885. switch (mask) {
  1886. case (IXGBE_FLAG_RSS_ENABLED):
  1887. mrqc = IXGBE_MRQC_RSSEN;
  1888. break;
  1889. case (IXGBE_FLAG_SRIOV_ENABLED):
  1890. mrqc = IXGBE_MRQC_VMDQEN;
  1891. break;
  1892. #ifdef CONFIG_IXGBE_DCB
  1893. case (IXGBE_FLAG_DCB_ENABLED):
  1894. mrqc = IXGBE_MRQC_RT8TCEN;
  1895. break;
  1896. #endif /* CONFIG_IXGBE_DCB */
  1897. default:
  1898. break;
  1899. }
  1900. return mrqc;
  1901. }
  1902. /**
  1903. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  1904. * @adapter: address of board private structure
  1905. * @index: index of ring to set
  1906. **/
  1907. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index)
  1908. {
  1909. struct ixgbe_ring *rx_ring;
  1910. struct ixgbe_hw *hw = &adapter->hw;
  1911. int j;
  1912. u32 rscctrl;
  1913. int rx_buf_len;
  1914. rx_ring = adapter->rx_ring[index];
  1915. j = rx_ring->reg_idx;
  1916. rx_buf_len = rx_ring->rx_buf_len;
  1917. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
  1918. rscctrl |= IXGBE_RSCCTL_RSCEN;
  1919. /*
  1920. * we must limit the number of descriptors so that the
  1921. * total size of max desc * buf_len is not greater
  1922. * than 65535
  1923. */
  1924. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1925. #if (MAX_SKB_FRAGS > 16)
  1926. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  1927. #elif (MAX_SKB_FRAGS > 8)
  1928. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  1929. #elif (MAX_SKB_FRAGS > 4)
  1930. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  1931. #else
  1932. rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
  1933. #endif
  1934. } else {
  1935. if (rx_buf_len < IXGBE_RXBUFFER_4096)
  1936. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  1937. else if (rx_buf_len < IXGBE_RXBUFFER_8192)
  1938. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  1939. else
  1940. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  1941. }
  1942. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
  1943. }
  1944. /**
  1945. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  1946. * @adapter: board private structure
  1947. *
  1948. * Configure the Rx unit of the MAC after a reset.
  1949. **/
  1950. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  1951. {
  1952. u64 rdba;
  1953. struct ixgbe_hw *hw = &adapter->hw;
  1954. struct ixgbe_ring *rx_ring;
  1955. struct net_device *netdev = adapter->netdev;
  1956. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  1957. int i, j;
  1958. u32 rdlen, rxctrl, rxcsum;
  1959. static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
  1960. 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
  1961. 0x6A3E67EA, 0x14364D17, 0x3BED200D};
  1962. u32 fctrl, hlreg0;
  1963. u32 reta = 0, mrqc = 0;
  1964. u32 rdrxctl;
  1965. int rx_buf_len;
  1966. /* Decide whether to use packet split mode or not */
  1967. /* Do not use packet split if we're in SR-IOV Mode */
  1968. if (!adapter->num_vfs)
  1969. adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
  1970. /* Set the RX buffer length according to the mode */
  1971. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
  1972. rx_buf_len = IXGBE_RX_HDR_SIZE;
  1973. if (hw->mac.type == ixgbe_mac_82599EB) {
  1974. /* PSRTYPE must be initialized in 82599 */
  1975. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  1976. IXGBE_PSRTYPE_UDPHDR |
  1977. IXGBE_PSRTYPE_IPV4HDR |
  1978. IXGBE_PSRTYPE_IPV6HDR |
  1979. IXGBE_PSRTYPE_L2HDR;
  1980. IXGBE_WRITE_REG(hw,
  1981. IXGBE_PSRTYPE(adapter->num_vfs),
  1982. psrtype);
  1983. }
  1984. } else {
  1985. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  1986. (netdev->mtu <= ETH_DATA_LEN))
  1987. rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  1988. else
  1989. rx_buf_len = ALIGN(max_frame, 1024);
  1990. }
  1991. fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
  1992. fctrl |= IXGBE_FCTRL_BAM;
  1993. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  1994. fctrl |= IXGBE_FCTRL_PMCF;
  1995. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
  1996. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  1997. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1998. hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
  1999. else
  2000. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  2001. #ifdef IXGBE_FCOE
  2002. if (netdev->features & NETIF_F_FCOE_MTU)
  2003. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  2004. #endif
  2005. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  2006. rdlen = adapter->rx_ring[0]->count * sizeof(union ixgbe_adv_rx_desc);
  2007. /* disable receives while setting up the descriptors */
  2008. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2009. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  2010. /*
  2011. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2012. * the Base and Length of the Rx Descriptor Ring
  2013. */
  2014. for (i = 0; i < adapter->num_rx_queues; i++) {
  2015. rx_ring = adapter->rx_ring[i];
  2016. rdba = rx_ring->dma;
  2017. j = rx_ring->reg_idx;
  2018. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
  2019. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
  2020. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
  2021. IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
  2022. IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
  2023. rx_ring->head = IXGBE_RDH(j);
  2024. rx_ring->tail = IXGBE_RDT(j);
  2025. rx_ring->rx_buf_len = rx_buf_len;
  2026. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
  2027. rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
  2028. else
  2029. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  2030. #ifdef IXGBE_FCOE
  2031. if (netdev->features & NETIF_F_FCOE_MTU) {
  2032. struct ixgbe_ring_feature *f;
  2033. f = &adapter->ring_feature[RING_F_FCOE];
  2034. if ((i >= f->mask) && (i < f->mask + f->indices)) {
  2035. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  2036. if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
  2037. rx_ring->rx_buf_len =
  2038. IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2039. }
  2040. }
  2041. #endif /* IXGBE_FCOE */
  2042. ixgbe_configure_srrctl(adapter, rx_ring);
  2043. }
  2044. if (hw->mac.type == ixgbe_mac_82598EB) {
  2045. /*
  2046. * For VMDq support of different descriptor types or
  2047. * buffer sizes through the use of multiple SRRCTL
  2048. * registers, RDRXCTL.MVMEN must be set to 1
  2049. *
  2050. * also, the manual doesn't mention it clearly but DCA hints
  2051. * will only use queue 0's tags unless this bit is set. Side
  2052. * effects of setting this bit are only that SRRCTL must be
  2053. * fully programmed [0..15]
  2054. */
  2055. rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  2056. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  2057. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  2058. }
  2059. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2060. u32 vt_reg_bits;
  2061. u32 reg_offset, vf_shift;
  2062. u32 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2063. vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN
  2064. | IXGBE_VT_CTL_REPLEN;
  2065. vt_reg_bits |= (adapter->num_vfs <<
  2066. IXGBE_VT_CTL_POOL_SHIFT);
  2067. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
  2068. IXGBE_WRITE_REG(hw, IXGBE_MRQC, 0);
  2069. vf_shift = adapter->num_vfs % 32;
  2070. reg_offset = adapter->num_vfs / 32;
  2071. IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0);
  2072. IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0);
  2073. IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0);
  2074. IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0);
  2075. /* Enable only the PF's pool for Tx/Rx */
  2076. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
  2077. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
  2078. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  2079. ixgbe_set_vmolr(hw, adapter->num_vfs);
  2080. }
  2081. /* Program MRQC for the distribution of queues */
  2082. mrqc = ixgbe_setup_mrqc(adapter);
  2083. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  2084. /* Fill out redirection table */
  2085. for (i = 0, j = 0; i < 128; i++, j++) {
  2086. if (j == adapter->ring_feature[RING_F_RSS].indices)
  2087. j = 0;
  2088. /* reta = 4-byte sliding window of
  2089. * 0x00..(indices-1)(indices-1)00..etc. */
  2090. reta = (reta << 8) | (j * 0x11);
  2091. if ((i & 3) == 3)
  2092. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  2093. }
  2094. /* Fill out hash function seeds */
  2095. for (i = 0; i < 10; i++)
  2096. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
  2097. if (hw->mac.type == ixgbe_mac_82598EB)
  2098. mrqc |= IXGBE_MRQC_RSSEN;
  2099. /* Perform hash on these packet types */
  2100. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
  2101. | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
  2102. | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
  2103. | IXGBE_MRQC_RSS_FIELD_IPV6
  2104. | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
  2105. | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  2106. }
  2107. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  2108. if (adapter->num_vfs) {
  2109. u32 reg;
  2110. /* Map PF MAC address in RAR Entry 0 to first pool
  2111. * following VFs */
  2112. hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
  2113. /* Set up VF register offsets for selected VT Mode, i.e.
  2114. * 64 VFs for SR-IOV */
  2115. reg = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  2116. reg |= IXGBE_GCR_EXT_SRIOV;
  2117. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, reg);
  2118. }
  2119. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  2120. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
  2121. adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
  2122. /* Disable indicating checksum in descriptor, enables
  2123. * RSS hash */
  2124. rxcsum |= IXGBE_RXCSUM_PCSD;
  2125. }
  2126. if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
  2127. /* Enable IPv4 payload checksum for UDP fragments
  2128. * if PCSD is not set */
  2129. rxcsum |= IXGBE_RXCSUM_IPPCSE;
  2130. }
  2131. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  2132. if (hw->mac.type == ixgbe_mac_82599EB) {
  2133. rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  2134. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  2135. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  2136. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  2137. }
  2138. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  2139. /* Enable 82599 HW-RSC */
  2140. for (i = 0; i < adapter->num_rx_queues; i++)
  2141. ixgbe_configure_rscctl(adapter, i);
  2142. /* Disable RSC for ACK packets */
  2143. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  2144. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  2145. }
  2146. }
  2147. static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  2148. {
  2149. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2150. struct ixgbe_hw *hw = &adapter->hw;
  2151. int pool_ndx = adapter->num_vfs;
  2152. /* add VID to filter table */
  2153. hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
  2154. }
  2155. static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  2156. {
  2157. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2158. struct ixgbe_hw *hw = &adapter->hw;
  2159. int pool_ndx = adapter->num_vfs;
  2160. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2161. ixgbe_irq_disable(adapter);
  2162. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  2163. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2164. ixgbe_irq_enable(adapter);
  2165. /* remove VID from filter table */
  2166. hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
  2167. }
  2168. static void ixgbe_vlan_rx_register(struct net_device *netdev,
  2169. struct vlan_group *grp)
  2170. {
  2171. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2172. u32 ctrl;
  2173. int i, j;
  2174. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2175. ixgbe_irq_disable(adapter);
  2176. adapter->vlgrp = grp;
  2177. /*
  2178. * For a DCB driver, always enable VLAN tag stripping so we can
  2179. * still receive traffic from a DCB-enabled host even if we're
  2180. * not in DCB mode.
  2181. */
  2182. ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
  2183. /* Disable CFI check */
  2184. ctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2185. /* enable VLAN tag stripping */
  2186. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2187. ctrl |= IXGBE_VLNCTRL_VME;
  2188. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  2189. for (i = 0; i < adapter->num_rx_queues; i++) {
  2190. u32 ctrl;
  2191. j = adapter->rx_ring[i]->reg_idx;
  2192. ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
  2193. ctrl |= IXGBE_RXDCTL_VME;
  2194. IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
  2195. }
  2196. }
  2197. IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
  2198. ixgbe_vlan_rx_add_vid(netdev, 0);
  2199. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2200. ixgbe_irq_enable(adapter);
  2201. }
  2202. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  2203. {
  2204. ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  2205. if (adapter->vlgrp) {
  2206. u16 vid;
  2207. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  2208. if (!vlan_group_get_device(adapter->vlgrp, vid))
  2209. continue;
  2210. ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
  2211. }
  2212. }
  2213. }
  2214. static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
  2215. {
  2216. struct dev_mc_list *mc_ptr;
  2217. u8 *addr = *mc_addr_ptr;
  2218. *vmdq = 0;
  2219. mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
  2220. if (mc_ptr->next)
  2221. *mc_addr_ptr = mc_ptr->next->dmi_addr;
  2222. else
  2223. *mc_addr_ptr = NULL;
  2224. return addr;
  2225. }
  2226. /**
  2227. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  2228. * @netdev: network interface device structure
  2229. *
  2230. * The set_rx_method entry point is called whenever the unicast/multicast
  2231. * address list or the network interface flags are updated. This routine is
  2232. * responsible for configuring the hardware for proper unicast, multicast and
  2233. * promiscuous mode.
  2234. **/
  2235. void ixgbe_set_rx_mode(struct net_device *netdev)
  2236. {
  2237. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2238. struct ixgbe_hw *hw = &adapter->hw;
  2239. u32 fctrl, vlnctrl;
  2240. u8 *addr_list = NULL;
  2241. int addr_count = 0;
  2242. /* Check for Promiscuous and All Multicast modes */
  2243. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  2244. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2245. if (netdev->flags & IFF_PROMISC) {
  2246. hw->addr_ctrl.user_set_promisc = 1;
  2247. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2248. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  2249. } else {
  2250. if (netdev->flags & IFF_ALLMULTI) {
  2251. fctrl |= IXGBE_FCTRL_MPE;
  2252. fctrl &= ~IXGBE_FCTRL_UPE;
  2253. } else {
  2254. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2255. }
  2256. vlnctrl |= IXGBE_VLNCTRL_VFE;
  2257. hw->addr_ctrl.user_set_promisc = 0;
  2258. }
  2259. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  2260. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2261. /* reprogram secondary unicast list */
  2262. hw->mac.ops.update_uc_addr_list(hw, netdev);
  2263. /* reprogram multicast list */
  2264. addr_count = netdev_mc_count(netdev);
  2265. if (addr_count)
  2266. addr_list = netdev->mc_list->dmi_addr;
  2267. hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
  2268. ixgbe_addr_list_itr);
  2269. if (adapter->num_vfs)
  2270. ixgbe_restore_vf_multicasts(adapter);
  2271. }
  2272. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  2273. {
  2274. int q_idx;
  2275. struct ixgbe_q_vector *q_vector;
  2276. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2277. /* legacy and MSI only use one vector */
  2278. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2279. q_vectors = 1;
  2280. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2281. struct napi_struct *napi;
  2282. q_vector = adapter->q_vector[q_idx];
  2283. napi = &q_vector->napi;
  2284. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2285. if (!q_vector->rxr_count || !q_vector->txr_count) {
  2286. if (q_vector->txr_count == 1)
  2287. napi->poll = &ixgbe_clean_txonly;
  2288. else if (q_vector->rxr_count == 1)
  2289. napi->poll = &ixgbe_clean_rxonly;
  2290. }
  2291. }
  2292. napi_enable(napi);
  2293. }
  2294. }
  2295. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  2296. {
  2297. int q_idx;
  2298. struct ixgbe_q_vector *q_vector;
  2299. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2300. /* legacy and MSI only use one vector */
  2301. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2302. q_vectors = 1;
  2303. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2304. q_vector = adapter->q_vector[q_idx];
  2305. napi_disable(&q_vector->napi);
  2306. }
  2307. }
  2308. #ifdef CONFIG_IXGBE_DCB
  2309. /*
  2310. * ixgbe_configure_dcb - Configure DCB hardware
  2311. * @adapter: ixgbe adapter struct
  2312. *
  2313. * This is called by the driver on open to configure the DCB hardware.
  2314. * This is also called by the gennetlink interface when reconfiguring
  2315. * the DCB state.
  2316. */
  2317. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  2318. {
  2319. struct ixgbe_hw *hw = &adapter->hw;
  2320. u32 txdctl, vlnctrl;
  2321. int i, j;
  2322. ixgbe_dcb_check_config(&adapter->dcb_cfg);
  2323. ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
  2324. ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
  2325. /* reconfigure the hardware */
  2326. ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
  2327. for (i = 0; i < adapter->num_tx_queues; i++) {
  2328. j = adapter->tx_ring[i]->reg_idx;
  2329. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2330. /* PThresh workaround for Tx hang with DFP enabled. */
  2331. txdctl |= 32;
  2332. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2333. }
  2334. /* Enable VLAN tag insert/strip */
  2335. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2336. if (hw->mac.type == ixgbe_mac_82598EB) {
  2337. vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
  2338. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2339. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2340. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  2341. vlnctrl |= IXGBE_VLNCTRL_VFE;
  2342. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2343. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2344. for (i = 0; i < adapter->num_rx_queues; i++) {
  2345. j = adapter->rx_ring[i]->reg_idx;
  2346. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2347. vlnctrl |= IXGBE_RXDCTL_VME;
  2348. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  2349. }
  2350. }
  2351. hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
  2352. }
  2353. #endif
  2354. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  2355. {
  2356. struct net_device *netdev = adapter->netdev;
  2357. struct ixgbe_hw *hw = &adapter->hw;
  2358. int i;
  2359. ixgbe_set_rx_mode(netdev);
  2360. ixgbe_restore_vlan(adapter);
  2361. #ifdef CONFIG_IXGBE_DCB
  2362. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  2363. if (hw->mac.type == ixgbe_mac_82598EB)
  2364. netif_set_gso_max_size(netdev, 32768);
  2365. else
  2366. netif_set_gso_max_size(netdev, 65536);
  2367. ixgbe_configure_dcb(adapter);
  2368. } else {
  2369. netif_set_gso_max_size(netdev, 65536);
  2370. }
  2371. #else
  2372. netif_set_gso_max_size(netdev, 65536);
  2373. #endif
  2374. #ifdef IXGBE_FCOE
  2375. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  2376. ixgbe_configure_fcoe(adapter);
  2377. #endif /* IXGBE_FCOE */
  2378. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2379. for (i = 0; i < adapter->num_tx_queues; i++)
  2380. adapter->tx_ring[i]->atr_sample_rate =
  2381. adapter->atr_sample_rate;
  2382. ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
  2383. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  2384. ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
  2385. }
  2386. ixgbe_configure_tx(adapter);
  2387. ixgbe_configure_rx(adapter);
  2388. for (i = 0; i < adapter->num_rx_queues; i++)
  2389. ixgbe_alloc_rx_buffers(adapter, adapter->rx_ring[i],
  2390. (adapter->rx_ring[i]->count - 1));
  2391. }
  2392. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2393. {
  2394. switch (hw->phy.type) {
  2395. case ixgbe_phy_sfp_avago:
  2396. case ixgbe_phy_sfp_ftl:
  2397. case ixgbe_phy_sfp_intel:
  2398. case ixgbe_phy_sfp_unknown:
  2399. case ixgbe_phy_tw_tyco:
  2400. case ixgbe_phy_tw_unknown:
  2401. return true;
  2402. default:
  2403. return false;
  2404. }
  2405. }
  2406. /**
  2407. * ixgbe_sfp_link_config - set up SFP+ link
  2408. * @adapter: pointer to private adapter struct
  2409. **/
  2410. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  2411. {
  2412. struct ixgbe_hw *hw = &adapter->hw;
  2413. if (hw->phy.multispeed_fiber) {
  2414. /*
  2415. * In multispeed fiber setups, the device may not have
  2416. * had a physical connection when the driver loaded.
  2417. * If that's the case, the initial link configuration
  2418. * couldn't get the MAC into 10G or 1G mode, so we'll
  2419. * never have a link status change interrupt fire.
  2420. * We need to try and force an autonegotiation
  2421. * session, then bring up link.
  2422. */
  2423. hw->mac.ops.setup_sfp(hw);
  2424. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  2425. schedule_work(&adapter->multispeed_fiber_task);
  2426. } else {
  2427. /*
  2428. * Direct Attach Cu and non-multispeed fiber modules
  2429. * still need to be configured properly prior to
  2430. * attempting link.
  2431. */
  2432. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
  2433. schedule_work(&adapter->sfp_config_module_task);
  2434. }
  2435. }
  2436. /**
  2437. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  2438. * @hw: pointer to private hardware struct
  2439. *
  2440. * Returns 0 on success, negative on failure
  2441. **/
  2442. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  2443. {
  2444. u32 autoneg;
  2445. bool negotiation, link_up = false;
  2446. u32 ret = IXGBE_ERR_LINK_SETUP;
  2447. if (hw->mac.ops.check_link)
  2448. ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
  2449. if (ret)
  2450. goto link_cfg_out;
  2451. if (hw->mac.ops.get_link_capabilities)
  2452. ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  2453. if (ret)
  2454. goto link_cfg_out;
  2455. if (hw->mac.ops.setup_link)
  2456. ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
  2457. link_cfg_out:
  2458. return ret;
  2459. }
  2460. #define IXGBE_MAX_RX_DESC_POLL 10
  2461. static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  2462. int rxr)
  2463. {
  2464. int j = adapter->rx_ring[rxr]->reg_idx;
  2465. int k;
  2466. for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
  2467. if (IXGBE_READ_REG(&adapter->hw,
  2468. IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
  2469. break;
  2470. else
  2471. msleep(1);
  2472. }
  2473. if (k >= IXGBE_MAX_RX_DESC_POLL) {
  2474. DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
  2475. "not set within the polling period\n", rxr);
  2476. }
  2477. ixgbe_release_rx_desc(&adapter->hw, adapter->rx_ring[rxr],
  2478. (adapter->rx_ring[rxr]->count - 1));
  2479. }
  2480. static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
  2481. {
  2482. struct net_device *netdev = adapter->netdev;
  2483. struct ixgbe_hw *hw = &adapter->hw;
  2484. int i, j = 0;
  2485. int num_rx_rings = adapter->num_rx_queues;
  2486. int err;
  2487. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2488. u32 txdctl, rxdctl, mhadd;
  2489. u32 dmatxctl;
  2490. u32 gpie;
  2491. u32 ctrl_ext;
  2492. ixgbe_get_hw_control(adapter);
  2493. if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
  2494. (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
  2495. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2496. gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
  2497. IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
  2498. } else {
  2499. /* MSI only */
  2500. gpie = 0;
  2501. }
  2502. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2503. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  2504. gpie |= IXGBE_GPIE_VTMODE_64;
  2505. }
  2506. /* XXX: to interrupt immediately for EICS writes, enable this */
  2507. /* gpie |= IXGBE_GPIE_EIMEN; */
  2508. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2509. }
  2510. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2511. /*
  2512. * use EIAM to auto-mask when MSI-X interrupt is asserted
  2513. * this saves a register write for every interrupt
  2514. */
  2515. switch (hw->mac.type) {
  2516. case ixgbe_mac_82598EB:
  2517. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  2518. break;
  2519. default:
  2520. case ixgbe_mac_82599EB:
  2521. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  2522. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  2523. break;
  2524. }
  2525. } else {
  2526. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  2527. * specifically only auto mask tx and rx interrupts */
  2528. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  2529. }
  2530. /* Enable fan failure interrupt if media type is copper */
  2531. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  2532. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  2533. gpie |= IXGBE_SDP1_GPIEN;
  2534. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2535. }
  2536. if (hw->mac.type == ixgbe_mac_82599EB) {
  2537. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  2538. gpie |= IXGBE_SDP1_GPIEN;
  2539. gpie |= IXGBE_SDP2_GPIEN;
  2540. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2541. }
  2542. #ifdef IXGBE_FCOE
  2543. /* adjust max frame to be able to do baby jumbo for FCoE */
  2544. if ((netdev->features & NETIF_F_FCOE_MTU) &&
  2545. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  2546. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2547. #endif /* IXGBE_FCOE */
  2548. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  2549. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  2550. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  2551. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  2552. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  2553. }
  2554. for (i = 0; i < adapter->num_tx_queues; i++) {
  2555. j = adapter->tx_ring[i]->reg_idx;
  2556. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2557. /* enable WTHRESH=8 descriptors, to encourage burst writeback */
  2558. txdctl |= (8 << 16);
  2559. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2560. }
  2561. if (hw->mac.type == ixgbe_mac_82599EB) {
  2562. /* DMATXCTL.EN must be set after all Tx queue config is done */
  2563. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2564. dmatxctl |= IXGBE_DMATXCTL_TE;
  2565. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2566. }
  2567. for (i = 0; i < adapter->num_tx_queues; i++) {
  2568. j = adapter->tx_ring[i]->reg_idx;
  2569. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2570. txdctl |= IXGBE_TXDCTL_ENABLE;
  2571. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2572. if (hw->mac.type == ixgbe_mac_82599EB) {
  2573. int wait_loop = 10;
  2574. /* poll for Tx Enable ready */
  2575. do {
  2576. msleep(1);
  2577. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2578. } while (--wait_loop &&
  2579. !(txdctl & IXGBE_TXDCTL_ENABLE));
  2580. if (!wait_loop)
  2581. DPRINTK(DRV, ERR, "Could not enable "
  2582. "Tx Queue %d\n", j);
  2583. }
  2584. }
  2585. for (i = 0; i < num_rx_rings; i++) {
  2586. j = adapter->rx_ring[i]->reg_idx;
  2587. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2588. /* enable PTHRESH=32 descriptors (half the internal cache)
  2589. * and HTHRESH=0 descriptors (to minimize latency on fetch),
  2590. * this also removes a pesky rx_no_buffer_count increment */
  2591. rxdctl |= 0x0020;
  2592. rxdctl |= IXGBE_RXDCTL_ENABLE;
  2593. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
  2594. if (hw->mac.type == ixgbe_mac_82599EB)
  2595. ixgbe_rx_desc_queue_enable(adapter, i);
  2596. }
  2597. /* enable all receives */
  2598. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2599. if (hw->mac.type == ixgbe_mac_82598EB)
  2600. rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
  2601. else
  2602. rxdctl |= IXGBE_RXCTRL_RXEN;
  2603. hw->mac.ops.enable_rx_dma(hw, rxdctl);
  2604. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2605. ixgbe_configure_msix(adapter);
  2606. else
  2607. ixgbe_configure_msi_and_legacy(adapter);
  2608. /* enable the optics */
  2609. if (hw->phy.multispeed_fiber)
  2610. hw->mac.ops.enable_tx_laser(hw);
  2611. clear_bit(__IXGBE_DOWN, &adapter->state);
  2612. ixgbe_napi_enable_all(adapter);
  2613. /* clear any pending interrupts, may auto mask */
  2614. IXGBE_READ_REG(hw, IXGBE_EICR);
  2615. ixgbe_irq_enable(adapter);
  2616. /*
  2617. * If this adapter has a fan, check to see if we had a failure
  2618. * before we enabled the interrupt.
  2619. */
  2620. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  2621. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  2622. if (esdp & IXGBE_ESDP_SDP1)
  2623. DPRINTK(DRV, CRIT,
  2624. "Fan has stopped, replace the adapter\n");
  2625. }
  2626. /*
  2627. * For hot-pluggable SFP+ devices, a new SFP+ module may have
  2628. * arrived before interrupts were enabled but after probe. Such
  2629. * devices wouldn't have their type identified yet. We need to
  2630. * kick off the SFP+ module setup first, then try to bring up link.
  2631. * If we're not hot-pluggable SFP+, we just need to configure link
  2632. * and bring it up.
  2633. */
  2634. if (hw->phy.type == ixgbe_phy_unknown) {
  2635. err = hw->phy.ops.identify(hw);
  2636. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  2637. /*
  2638. * Take the device down and schedule the sfp tasklet
  2639. * which will unregister_netdev and log it.
  2640. */
  2641. ixgbe_down(adapter);
  2642. schedule_work(&adapter->sfp_config_module_task);
  2643. return err;
  2644. }
  2645. }
  2646. if (ixgbe_is_sfp(hw)) {
  2647. ixgbe_sfp_link_config(adapter);
  2648. } else {
  2649. err = ixgbe_non_sfp_link_config(hw);
  2650. if (err)
  2651. DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
  2652. }
  2653. for (i = 0; i < adapter->num_tx_queues; i++)
  2654. set_bit(__IXGBE_FDIR_INIT_DONE,
  2655. &(adapter->tx_ring[i]->reinit_state));
  2656. /* enable transmits */
  2657. netif_tx_start_all_queues(netdev);
  2658. /* bring the link up in the watchdog, this could race with our first
  2659. * link up interrupt but shouldn't be a problem */
  2660. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2661. adapter->link_check_timeout = jiffies;
  2662. mod_timer(&adapter->watchdog_timer, jiffies);
  2663. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  2664. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  2665. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  2666. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  2667. return 0;
  2668. }
  2669. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  2670. {
  2671. WARN_ON(in_interrupt());
  2672. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  2673. msleep(1);
  2674. ixgbe_down(adapter);
  2675. /*
  2676. * If SR-IOV enabled then wait a bit before bringing the adapter
  2677. * back up to give the VFs time to respond to the reset. The
  2678. * two second wait is based upon the watchdog timer cycle in
  2679. * the VF driver.
  2680. */
  2681. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  2682. msleep(2000);
  2683. ixgbe_up(adapter);
  2684. clear_bit(__IXGBE_RESETTING, &adapter->state);
  2685. }
  2686. int ixgbe_up(struct ixgbe_adapter *adapter)
  2687. {
  2688. /* hardware has been reset, we need to reload some things */
  2689. ixgbe_configure(adapter);
  2690. return ixgbe_up_complete(adapter);
  2691. }
  2692. void ixgbe_reset(struct ixgbe_adapter *adapter)
  2693. {
  2694. struct ixgbe_hw *hw = &adapter->hw;
  2695. int err;
  2696. err = hw->mac.ops.init_hw(hw);
  2697. switch (err) {
  2698. case 0:
  2699. case IXGBE_ERR_SFP_NOT_PRESENT:
  2700. break;
  2701. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  2702. dev_err(&adapter->pdev->dev, "master disable timed out\n");
  2703. break;
  2704. case IXGBE_ERR_EEPROM_VERSION:
  2705. /* We are running on a pre-production device, log a warning */
  2706. dev_warn(&adapter->pdev->dev, "This device is a pre-production "
  2707. "adapter/LOM. Please be aware there may be issues "
  2708. "associated with your hardware. If you are "
  2709. "experiencing problems please contact your Intel or "
  2710. "hardware representative who provided you with this "
  2711. "hardware.\n");
  2712. break;
  2713. default:
  2714. dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
  2715. }
  2716. /* reprogram the RAR[0] in case user changed it. */
  2717. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
  2718. IXGBE_RAH_AV);
  2719. }
  2720. /**
  2721. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  2722. * @adapter: board private structure
  2723. * @rx_ring: ring to free buffers from
  2724. **/
  2725. static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
  2726. struct ixgbe_ring *rx_ring)
  2727. {
  2728. struct pci_dev *pdev = adapter->pdev;
  2729. unsigned long size;
  2730. unsigned int i;
  2731. /* Free all the Rx ring sk_buffs */
  2732. for (i = 0; i < rx_ring->count; i++) {
  2733. struct ixgbe_rx_buffer *rx_buffer_info;
  2734. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  2735. if (rx_buffer_info->dma) {
  2736. pci_unmap_single(pdev, rx_buffer_info->dma,
  2737. rx_ring->rx_buf_len,
  2738. PCI_DMA_FROMDEVICE);
  2739. rx_buffer_info->dma = 0;
  2740. }
  2741. if (rx_buffer_info->skb) {
  2742. struct sk_buff *skb = rx_buffer_info->skb;
  2743. rx_buffer_info->skb = NULL;
  2744. do {
  2745. struct sk_buff *this = skb;
  2746. if (IXGBE_RSC_CB(this)->dma) {
  2747. pci_unmap_single(pdev, IXGBE_RSC_CB(this)->dma,
  2748. rx_ring->rx_buf_len,
  2749. PCI_DMA_FROMDEVICE);
  2750. IXGBE_RSC_CB(this)->dma = 0;
  2751. }
  2752. skb = skb->prev;
  2753. dev_kfree_skb(this);
  2754. } while (skb);
  2755. }
  2756. if (!rx_buffer_info->page)
  2757. continue;
  2758. if (rx_buffer_info->page_dma) {
  2759. pci_unmap_page(pdev, rx_buffer_info->page_dma,
  2760. PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
  2761. rx_buffer_info->page_dma = 0;
  2762. }
  2763. put_page(rx_buffer_info->page);
  2764. rx_buffer_info->page = NULL;
  2765. rx_buffer_info->page_offset = 0;
  2766. }
  2767. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  2768. memset(rx_ring->rx_buffer_info, 0, size);
  2769. /* Zero out the descriptor ring */
  2770. memset(rx_ring->desc, 0, rx_ring->size);
  2771. rx_ring->next_to_clean = 0;
  2772. rx_ring->next_to_use = 0;
  2773. if (rx_ring->head)
  2774. writel(0, adapter->hw.hw_addr + rx_ring->head);
  2775. if (rx_ring->tail)
  2776. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  2777. }
  2778. /**
  2779. * ixgbe_clean_tx_ring - Free Tx Buffers
  2780. * @adapter: board private structure
  2781. * @tx_ring: ring to be cleaned
  2782. **/
  2783. static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
  2784. struct ixgbe_ring *tx_ring)
  2785. {
  2786. struct ixgbe_tx_buffer *tx_buffer_info;
  2787. unsigned long size;
  2788. unsigned int i;
  2789. /* Free all the Tx ring sk_buffs */
  2790. for (i = 0; i < tx_ring->count; i++) {
  2791. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2792. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  2793. }
  2794. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  2795. memset(tx_ring->tx_buffer_info, 0, size);
  2796. /* Zero out the descriptor ring */
  2797. memset(tx_ring->desc, 0, tx_ring->size);
  2798. tx_ring->next_to_use = 0;
  2799. tx_ring->next_to_clean = 0;
  2800. if (tx_ring->head)
  2801. writel(0, adapter->hw.hw_addr + tx_ring->head);
  2802. if (tx_ring->tail)
  2803. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  2804. }
  2805. /**
  2806. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  2807. * @adapter: board private structure
  2808. **/
  2809. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  2810. {
  2811. int i;
  2812. for (i = 0; i < adapter->num_rx_queues; i++)
  2813. ixgbe_clean_rx_ring(adapter, adapter->rx_ring[i]);
  2814. }
  2815. /**
  2816. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  2817. * @adapter: board private structure
  2818. **/
  2819. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  2820. {
  2821. int i;
  2822. for (i = 0; i < adapter->num_tx_queues; i++)
  2823. ixgbe_clean_tx_ring(adapter, adapter->tx_ring[i]);
  2824. }
  2825. void ixgbe_down(struct ixgbe_adapter *adapter)
  2826. {
  2827. struct net_device *netdev = adapter->netdev;
  2828. struct ixgbe_hw *hw = &adapter->hw;
  2829. u32 rxctrl;
  2830. u32 txdctl;
  2831. int i, j;
  2832. /* signal that we are down to the interrupt handler */
  2833. set_bit(__IXGBE_DOWN, &adapter->state);
  2834. /* power down the optics */
  2835. if (hw->phy.multispeed_fiber)
  2836. hw->mac.ops.disable_tx_laser(hw);
  2837. /* disable receive for all VFs and wait one second */
  2838. if (adapter->num_vfs) {
  2839. /* ping all the active vfs to let them know we are going down */
  2840. ixgbe_ping_all_vfs(adapter);
  2841. /* Disable all VFTE/VFRE TX/RX */
  2842. ixgbe_disable_tx_rx(adapter);
  2843. /* Mark all the VFs as inactive */
  2844. for (i = 0 ; i < adapter->num_vfs; i++)
  2845. adapter->vfinfo[i].clear_to_send = 0;
  2846. }
  2847. /* disable receives */
  2848. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2849. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  2850. netif_tx_disable(netdev);
  2851. IXGBE_WRITE_FLUSH(hw);
  2852. msleep(10);
  2853. netif_tx_stop_all_queues(netdev);
  2854. ixgbe_irq_disable(adapter);
  2855. ixgbe_napi_disable_all(adapter);
  2856. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  2857. del_timer_sync(&adapter->sfp_timer);
  2858. del_timer_sync(&adapter->watchdog_timer);
  2859. cancel_work_sync(&adapter->watchdog_task);
  2860. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  2861. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  2862. cancel_work_sync(&adapter->fdir_reinit_task);
  2863. /* disable transmits in the hardware now that interrupts are off */
  2864. for (i = 0; i < adapter->num_tx_queues; i++) {
  2865. j = adapter->tx_ring[i]->reg_idx;
  2866. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2867. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
  2868. (txdctl & ~IXGBE_TXDCTL_ENABLE));
  2869. }
  2870. /* Disable the Tx DMA engine on 82599 */
  2871. if (hw->mac.type == ixgbe_mac_82599EB)
  2872. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  2873. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  2874. ~IXGBE_DMATXCTL_TE));
  2875. netif_carrier_off(netdev);
  2876. /* clear n-tuple filters that are cached */
  2877. ethtool_ntuple_flush(netdev);
  2878. if (!pci_channel_offline(adapter->pdev))
  2879. ixgbe_reset(adapter);
  2880. ixgbe_clean_all_tx_rings(adapter);
  2881. ixgbe_clean_all_rx_rings(adapter);
  2882. #ifdef CONFIG_IXGBE_DCA
  2883. /* since we reset the hardware DCA settings were cleared */
  2884. ixgbe_setup_dca(adapter);
  2885. #endif
  2886. }
  2887. /**
  2888. * ixgbe_poll - NAPI Rx polling callback
  2889. * @napi: structure for representing this polling device
  2890. * @budget: how many packets driver is allowed to clean
  2891. *
  2892. * This function is used for legacy and MSI, NAPI mode
  2893. **/
  2894. static int ixgbe_poll(struct napi_struct *napi, int budget)
  2895. {
  2896. struct ixgbe_q_vector *q_vector =
  2897. container_of(napi, struct ixgbe_q_vector, napi);
  2898. struct ixgbe_adapter *adapter = q_vector->adapter;
  2899. int tx_clean_complete, work_done = 0;
  2900. #ifdef CONFIG_IXGBE_DCA
  2901. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  2902. ixgbe_update_tx_dca(adapter, adapter->tx_ring[0]);
  2903. ixgbe_update_rx_dca(adapter, adapter->rx_ring[0]);
  2904. }
  2905. #endif
  2906. tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
  2907. ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
  2908. if (!tx_clean_complete)
  2909. work_done = budget;
  2910. /* If budget not fully consumed, exit the polling mode */
  2911. if (work_done < budget) {
  2912. napi_complete(napi);
  2913. if (adapter->rx_itr_setting & 1)
  2914. ixgbe_set_itr(adapter);
  2915. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2916. ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
  2917. }
  2918. return work_done;
  2919. }
  2920. /**
  2921. * ixgbe_tx_timeout - Respond to a Tx Hang
  2922. * @netdev: network interface device structure
  2923. **/
  2924. static void ixgbe_tx_timeout(struct net_device *netdev)
  2925. {
  2926. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2927. /* Do the reset outside of interrupt context */
  2928. schedule_work(&adapter->reset_task);
  2929. }
  2930. static void ixgbe_reset_task(struct work_struct *work)
  2931. {
  2932. struct ixgbe_adapter *adapter;
  2933. adapter = container_of(work, struct ixgbe_adapter, reset_task);
  2934. /* If we're already down or resetting, just bail */
  2935. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  2936. test_bit(__IXGBE_RESETTING, &adapter->state))
  2937. return;
  2938. adapter->tx_timeout_count++;
  2939. ixgbe_reinit_locked(adapter);
  2940. }
  2941. #ifdef CONFIG_IXGBE_DCB
  2942. static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
  2943. {
  2944. bool ret = false;
  2945. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
  2946. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
  2947. return ret;
  2948. f->mask = 0x7 << 3;
  2949. adapter->num_rx_queues = f->indices;
  2950. adapter->num_tx_queues = f->indices;
  2951. ret = true;
  2952. return ret;
  2953. }
  2954. #endif
  2955. /**
  2956. * ixgbe_set_rss_queues: Allocate queues for RSS
  2957. * @adapter: board private structure to initialize
  2958. *
  2959. * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
  2960. * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
  2961. *
  2962. **/
  2963. static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
  2964. {
  2965. bool ret = false;
  2966. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
  2967. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  2968. f->mask = 0xF;
  2969. adapter->num_rx_queues = f->indices;
  2970. adapter->num_tx_queues = f->indices;
  2971. ret = true;
  2972. } else {
  2973. ret = false;
  2974. }
  2975. return ret;
  2976. }
  2977. /**
  2978. * ixgbe_set_fdir_queues: Allocate queues for Flow Director
  2979. * @adapter: board private structure to initialize
  2980. *
  2981. * Flow Director is an advanced Rx filter, attempting to get Rx flows back
  2982. * to the original CPU that initiated the Tx session. This runs in addition
  2983. * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
  2984. * Rx load across CPUs using RSS.
  2985. *
  2986. **/
  2987. static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
  2988. {
  2989. bool ret = false;
  2990. struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
  2991. f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
  2992. f_fdir->mask = 0;
  2993. /* Flow Director must have RSS enabled */
  2994. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  2995. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  2996. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
  2997. adapter->num_tx_queues = f_fdir->indices;
  2998. adapter->num_rx_queues = f_fdir->indices;
  2999. ret = true;
  3000. } else {
  3001. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3002. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3003. }
  3004. return ret;
  3005. }
  3006. #ifdef IXGBE_FCOE
  3007. /**
  3008. * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
  3009. * @adapter: board private structure to initialize
  3010. *
  3011. * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
  3012. * The ring feature mask is not used as a mask for FCoE, as it can take any 8
  3013. * rx queues out of the max number of rx queues, instead, it is used as the
  3014. * index of the first rx queue used by FCoE.
  3015. *
  3016. **/
  3017. static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
  3018. {
  3019. bool ret = false;
  3020. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3021. f->indices = min((int)num_online_cpus(), f->indices);
  3022. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3023. adapter->num_rx_queues = 1;
  3024. adapter->num_tx_queues = 1;
  3025. #ifdef CONFIG_IXGBE_DCB
  3026. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3027. DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
  3028. ixgbe_set_dcb_queues(adapter);
  3029. }
  3030. #endif
  3031. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3032. DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
  3033. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3034. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3035. ixgbe_set_fdir_queues(adapter);
  3036. else
  3037. ixgbe_set_rss_queues(adapter);
  3038. }
  3039. /* adding FCoE rx rings to the end */
  3040. f->mask = adapter->num_rx_queues;
  3041. adapter->num_rx_queues += f->indices;
  3042. adapter->num_tx_queues += f->indices;
  3043. ret = true;
  3044. }
  3045. return ret;
  3046. }
  3047. #endif /* IXGBE_FCOE */
  3048. /**
  3049. * ixgbe_set_sriov_queues: Allocate queues for IOV use
  3050. * @adapter: board private structure to initialize
  3051. *
  3052. * IOV doesn't actually use anything, so just NAK the
  3053. * request for now and let the other queue routines
  3054. * figure out what to do.
  3055. */
  3056. static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
  3057. {
  3058. return false;
  3059. }
  3060. /*
  3061. * ixgbe_set_num_queues: Allocate queues for device, feature dependant
  3062. * @adapter: board private structure to initialize
  3063. *
  3064. * This is the top level queue allocation routine. The order here is very
  3065. * important, starting with the "most" number of features turned on at once,
  3066. * and ending with the smallest set of features. This way large combinations
  3067. * can be allocated if they're turned on, and smaller combinations are the
  3068. * fallthrough conditions.
  3069. *
  3070. **/
  3071. static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
  3072. {
  3073. /* Start with base case */
  3074. adapter->num_rx_queues = 1;
  3075. adapter->num_tx_queues = 1;
  3076. adapter->num_rx_pools = adapter->num_rx_queues;
  3077. adapter->num_rx_queues_per_pool = 1;
  3078. if (ixgbe_set_sriov_queues(adapter))
  3079. return;
  3080. #ifdef IXGBE_FCOE
  3081. if (ixgbe_set_fcoe_queues(adapter))
  3082. goto done;
  3083. #endif /* IXGBE_FCOE */
  3084. #ifdef CONFIG_IXGBE_DCB
  3085. if (ixgbe_set_dcb_queues(adapter))
  3086. goto done;
  3087. #endif
  3088. if (ixgbe_set_fdir_queues(adapter))
  3089. goto done;
  3090. if (ixgbe_set_rss_queues(adapter))
  3091. goto done;
  3092. /* fallback to base case */
  3093. adapter->num_rx_queues = 1;
  3094. adapter->num_tx_queues = 1;
  3095. done:
  3096. /* Notify the stack of the (possibly) reduced Tx Queue count. */
  3097. adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
  3098. }
  3099. static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
  3100. int vectors)
  3101. {
  3102. int err, vector_threshold;
  3103. /* We'll want at least 3 (vector_threshold):
  3104. * 1) TxQ[0] Cleanup
  3105. * 2) RxQ[0] Cleanup
  3106. * 3) Other (Link Status Change, etc.)
  3107. * 4) TCP Timer (optional)
  3108. */
  3109. vector_threshold = MIN_MSIX_COUNT;
  3110. /* The more we get, the more we will assign to Tx/Rx Cleanup
  3111. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  3112. * Right now, we simply care about how many we'll get; we'll
  3113. * set them up later while requesting irq's.
  3114. */
  3115. while (vectors >= vector_threshold) {
  3116. err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
  3117. vectors);
  3118. if (!err) /* Success in acquiring all requested vectors. */
  3119. break;
  3120. else if (err < 0)
  3121. vectors = 0; /* Nasty failure, quit now */
  3122. else /* err == number of vectors we should try again with */
  3123. vectors = err;
  3124. }
  3125. if (vectors < vector_threshold) {
  3126. /* Can't allocate enough MSI-X interrupts? Oh well.
  3127. * This just means we'll go with either a single MSI
  3128. * vector or fall back to legacy interrupts.
  3129. */
  3130. DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
  3131. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  3132. kfree(adapter->msix_entries);
  3133. adapter->msix_entries = NULL;
  3134. } else {
  3135. adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
  3136. /*
  3137. * Adjust for only the vectors we'll use, which is minimum
  3138. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  3139. * vectors we were allocated.
  3140. */
  3141. adapter->num_msix_vectors = min(vectors,
  3142. adapter->max_msix_q_vectors + NON_Q_VECTORS);
  3143. }
  3144. }
  3145. /**
  3146. * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
  3147. * @adapter: board private structure to initialize
  3148. *
  3149. * Cache the descriptor ring offsets for RSS to the assigned rings.
  3150. *
  3151. **/
  3152. static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
  3153. {
  3154. int i;
  3155. bool ret = false;
  3156. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3157. for (i = 0; i < adapter->num_rx_queues; i++)
  3158. adapter->rx_ring[i]->reg_idx = i;
  3159. for (i = 0; i < adapter->num_tx_queues; i++)
  3160. adapter->tx_ring[i]->reg_idx = i;
  3161. ret = true;
  3162. } else {
  3163. ret = false;
  3164. }
  3165. return ret;
  3166. }
  3167. #ifdef CONFIG_IXGBE_DCB
  3168. /**
  3169. * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
  3170. * @adapter: board private structure to initialize
  3171. *
  3172. * Cache the descriptor ring offsets for DCB to the assigned rings.
  3173. *
  3174. **/
  3175. static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
  3176. {
  3177. int i;
  3178. bool ret = false;
  3179. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  3180. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3181. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3182. /* the number of queues is assumed to be symmetric */
  3183. for (i = 0; i < dcb_i; i++) {
  3184. adapter->rx_ring[i]->reg_idx = i << 3;
  3185. adapter->tx_ring[i]->reg_idx = i << 2;
  3186. }
  3187. ret = true;
  3188. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  3189. if (dcb_i == 8) {
  3190. /*
  3191. * Tx TC0 starts at: descriptor queue 0
  3192. * Tx TC1 starts at: descriptor queue 32
  3193. * Tx TC2 starts at: descriptor queue 64
  3194. * Tx TC3 starts at: descriptor queue 80
  3195. * Tx TC4 starts at: descriptor queue 96
  3196. * Tx TC5 starts at: descriptor queue 104
  3197. * Tx TC6 starts at: descriptor queue 112
  3198. * Tx TC7 starts at: descriptor queue 120
  3199. *
  3200. * Rx TC0-TC7 are offset by 16 queues each
  3201. */
  3202. for (i = 0; i < 3; i++) {
  3203. adapter->tx_ring[i]->reg_idx = i << 5;
  3204. adapter->rx_ring[i]->reg_idx = i << 4;
  3205. }
  3206. for ( ; i < 5; i++) {
  3207. adapter->tx_ring[i]->reg_idx =
  3208. ((i + 2) << 4);
  3209. adapter->rx_ring[i]->reg_idx = i << 4;
  3210. }
  3211. for ( ; i < dcb_i; i++) {
  3212. adapter->tx_ring[i]->reg_idx =
  3213. ((i + 8) << 3);
  3214. adapter->rx_ring[i]->reg_idx = i << 4;
  3215. }
  3216. ret = true;
  3217. } else if (dcb_i == 4) {
  3218. /*
  3219. * Tx TC0 starts at: descriptor queue 0
  3220. * Tx TC1 starts at: descriptor queue 64
  3221. * Tx TC2 starts at: descriptor queue 96
  3222. * Tx TC3 starts at: descriptor queue 112
  3223. *
  3224. * Rx TC0-TC3 are offset by 32 queues each
  3225. */
  3226. adapter->tx_ring[0]->reg_idx = 0;
  3227. adapter->tx_ring[1]->reg_idx = 64;
  3228. adapter->tx_ring[2]->reg_idx = 96;
  3229. adapter->tx_ring[3]->reg_idx = 112;
  3230. for (i = 0 ; i < dcb_i; i++)
  3231. adapter->rx_ring[i]->reg_idx = i << 5;
  3232. ret = true;
  3233. } else {
  3234. ret = false;
  3235. }
  3236. } else {
  3237. ret = false;
  3238. }
  3239. } else {
  3240. ret = false;
  3241. }
  3242. return ret;
  3243. }
  3244. #endif
  3245. /**
  3246. * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
  3247. * @adapter: board private structure to initialize
  3248. *
  3249. * Cache the descriptor ring offsets for Flow Director to the assigned rings.
  3250. *
  3251. **/
  3252. static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
  3253. {
  3254. int i;
  3255. bool ret = false;
  3256. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  3257. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3258. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
  3259. for (i = 0; i < adapter->num_rx_queues; i++)
  3260. adapter->rx_ring[i]->reg_idx = i;
  3261. for (i = 0; i < adapter->num_tx_queues; i++)
  3262. adapter->tx_ring[i]->reg_idx = i;
  3263. ret = true;
  3264. }
  3265. return ret;
  3266. }
  3267. #ifdef IXGBE_FCOE
  3268. /**
  3269. * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
  3270. * @adapter: board private structure to initialize
  3271. *
  3272. * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
  3273. *
  3274. */
  3275. static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
  3276. {
  3277. int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
  3278. bool ret = false;
  3279. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3280. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3281. #ifdef CONFIG_IXGBE_DCB
  3282. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3283. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  3284. ixgbe_cache_ring_dcb(adapter);
  3285. /* find out queues in TC for FCoE */
  3286. fcoe_rx_i = adapter->rx_ring[fcoe->tc]->reg_idx + 1;
  3287. fcoe_tx_i = adapter->tx_ring[fcoe->tc]->reg_idx + 1;
  3288. /*
  3289. * In 82599, the number of Tx queues for each traffic
  3290. * class for both 8-TC and 4-TC modes are:
  3291. * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
  3292. * 8 TCs: 32 32 16 16 8 8 8 8
  3293. * 4 TCs: 64 64 32 32
  3294. * We have max 8 queues for FCoE, where 8 the is
  3295. * FCoE redirection table size. If TC for FCoE is
  3296. * less than or equal to TC3, we have enough queues
  3297. * to add max of 8 queues for FCoE, so we start FCoE
  3298. * tx descriptor from the next one, i.e., reg_idx + 1.
  3299. * If TC for FCoE is above TC3, implying 8 TC mode,
  3300. * and we need 8 for FCoE, we have to take all queues
  3301. * in that traffic class for FCoE.
  3302. */
  3303. if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
  3304. fcoe_tx_i--;
  3305. }
  3306. #endif /* CONFIG_IXGBE_DCB */
  3307. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3308. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3309. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3310. ixgbe_cache_ring_fdir(adapter);
  3311. else
  3312. ixgbe_cache_ring_rss(adapter);
  3313. fcoe_rx_i = f->mask;
  3314. fcoe_tx_i = f->mask;
  3315. }
  3316. for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
  3317. adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
  3318. adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
  3319. }
  3320. ret = true;
  3321. }
  3322. return ret;
  3323. }
  3324. #endif /* IXGBE_FCOE */
  3325. /**
  3326. * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
  3327. * @adapter: board private structure to initialize
  3328. *
  3329. * SR-IOV doesn't use any descriptor rings but changes the default if
  3330. * no other mapping is used.
  3331. *
  3332. */
  3333. static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
  3334. {
  3335. adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
  3336. adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
  3337. if (adapter->num_vfs)
  3338. return true;
  3339. else
  3340. return false;
  3341. }
  3342. /**
  3343. * ixgbe_cache_ring_register - Descriptor ring to register mapping
  3344. * @adapter: board private structure to initialize
  3345. *
  3346. * Once we know the feature-set enabled for the device, we'll cache
  3347. * the register offset the descriptor ring is assigned to.
  3348. *
  3349. * Note, the order the various feature calls is important. It must start with
  3350. * the "most" features enabled at the same time, then trickle down to the
  3351. * least amount of features turned on at once.
  3352. **/
  3353. static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
  3354. {
  3355. /* start with default case */
  3356. adapter->rx_ring[0]->reg_idx = 0;
  3357. adapter->tx_ring[0]->reg_idx = 0;
  3358. if (ixgbe_cache_ring_sriov(adapter))
  3359. return;
  3360. #ifdef IXGBE_FCOE
  3361. if (ixgbe_cache_ring_fcoe(adapter))
  3362. return;
  3363. #endif /* IXGBE_FCOE */
  3364. #ifdef CONFIG_IXGBE_DCB
  3365. if (ixgbe_cache_ring_dcb(adapter))
  3366. return;
  3367. #endif
  3368. if (ixgbe_cache_ring_fdir(adapter))
  3369. return;
  3370. if (ixgbe_cache_ring_rss(adapter))
  3371. return;
  3372. }
  3373. /**
  3374. * ixgbe_alloc_queues - Allocate memory for all rings
  3375. * @adapter: board private structure to initialize
  3376. *
  3377. * We allocate one ring per queue at run-time since we don't know the
  3378. * number of queues at compile-time. The polling_netdev array is
  3379. * intended for Multiqueue, but should work fine with a single queue.
  3380. **/
  3381. static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
  3382. {
  3383. int i;
  3384. int orig_node = adapter->node;
  3385. for (i = 0; i < adapter->num_tx_queues; i++) {
  3386. struct ixgbe_ring *ring = adapter->tx_ring[i];
  3387. if (orig_node == -1) {
  3388. int cur_node = next_online_node(adapter->node);
  3389. if (cur_node == MAX_NUMNODES)
  3390. cur_node = first_online_node;
  3391. adapter->node = cur_node;
  3392. }
  3393. ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL,
  3394. adapter->node);
  3395. if (!ring)
  3396. ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
  3397. if (!ring)
  3398. goto err_tx_ring_allocation;
  3399. ring->count = adapter->tx_ring_count;
  3400. ring->queue_index = i;
  3401. ring->numa_node = adapter->node;
  3402. adapter->tx_ring[i] = ring;
  3403. }
  3404. /* Restore the adapter's original node */
  3405. adapter->node = orig_node;
  3406. for (i = 0; i < adapter->num_rx_queues; i++) {
  3407. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3408. if (orig_node == -1) {
  3409. int cur_node = next_online_node(adapter->node);
  3410. if (cur_node == MAX_NUMNODES)
  3411. cur_node = first_online_node;
  3412. adapter->node = cur_node;
  3413. }
  3414. ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL,
  3415. adapter->node);
  3416. if (!ring)
  3417. ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
  3418. if (!ring)
  3419. goto err_rx_ring_allocation;
  3420. ring->count = adapter->rx_ring_count;
  3421. ring->queue_index = i;
  3422. ring->numa_node = adapter->node;
  3423. adapter->rx_ring[i] = ring;
  3424. }
  3425. /* Restore the adapter's original node */
  3426. adapter->node = orig_node;
  3427. ixgbe_cache_ring_register(adapter);
  3428. return 0;
  3429. err_rx_ring_allocation:
  3430. for (i = 0; i < adapter->num_tx_queues; i++)
  3431. kfree(adapter->tx_ring[i]);
  3432. err_tx_ring_allocation:
  3433. return -ENOMEM;
  3434. }
  3435. /**
  3436. * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
  3437. * @adapter: board private structure to initialize
  3438. *
  3439. * Attempt to configure the interrupts using the best available
  3440. * capabilities of the hardware and the kernel.
  3441. **/
  3442. static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
  3443. {
  3444. struct ixgbe_hw *hw = &adapter->hw;
  3445. int err = 0;
  3446. int vector, v_budget;
  3447. /*
  3448. * It's easy to be greedy for MSI-X vectors, but it really
  3449. * doesn't do us much good if we have a lot more vectors
  3450. * than CPU's. So let's be conservative and only ask for
  3451. * (roughly) the same number of vectors as there are CPU's.
  3452. */
  3453. v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
  3454. (int)num_online_cpus()) + NON_Q_VECTORS;
  3455. /*
  3456. * At the same time, hardware can only support a maximum of
  3457. * hw.mac->max_msix_vectors vectors. With features
  3458. * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
  3459. * descriptor queues supported by our device. Thus, we cap it off in
  3460. * those rare cases where the cpu count also exceeds our vector limit.
  3461. */
  3462. v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
  3463. /* A failure in MSI-X entry allocation isn't fatal, but it does
  3464. * mean we disable MSI-X capabilities of the adapter. */
  3465. adapter->msix_entries = kcalloc(v_budget,
  3466. sizeof(struct msix_entry), GFP_KERNEL);
  3467. if (adapter->msix_entries) {
  3468. for (vector = 0; vector < v_budget; vector++)
  3469. adapter->msix_entries[vector].entry = vector;
  3470. ixgbe_acquire_msix_vectors(adapter, v_budget);
  3471. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3472. goto out;
  3473. }
  3474. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  3475. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  3476. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3477. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3478. adapter->atr_sample_rate = 0;
  3479. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3480. ixgbe_disable_sriov(adapter);
  3481. ixgbe_set_num_queues(adapter);
  3482. err = pci_enable_msi(adapter->pdev);
  3483. if (!err) {
  3484. adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
  3485. } else {
  3486. DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
  3487. "falling back to legacy. Error: %d\n", err);
  3488. /* reset err */
  3489. err = 0;
  3490. }
  3491. out:
  3492. return err;
  3493. }
  3494. /**
  3495. * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
  3496. * @adapter: board private structure to initialize
  3497. *
  3498. * We allocate one q_vector per queue interrupt. If allocation fails we
  3499. * return -ENOMEM.
  3500. **/
  3501. static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
  3502. {
  3503. int q_idx, num_q_vectors;
  3504. struct ixgbe_q_vector *q_vector;
  3505. int napi_vectors;
  3506. int (*poll)(struct napi_struct *, int);
  3507. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3508. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  3509. napi_vectors = adapter->num_rx_queues;
  3510. poll = &ixgbe_clean_rxtx_many;
  3511. } else {
  3512. num_q_vectors = 1;
  3513. napi_vectors = 1;
  3514. poll = &ixgbe_poll;
  3515. }
  3516. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  3517. q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
  3518. GFP_KERNEL, adapter->node);
  3519. if (!q_vector)
  3520. q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
  3521. GFP_KERNEL);
  3522. if (!q_vector)
  3523. goto err_out;
  3524. q_vector->adapter = adapter;
  3525. if (q_vector->txr_count && !q_vector->rxr_count)
  3526. q_vector->eitr = adapter->tx_eitr_param;
  3527. else
  3528. q_vector->eitr = adapter->rx_eitr_param;
  3529. q_vector->v_idx = q_idx;
  3530. netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
  3531. adapter->q_vector[q_idx] = q_vector;
  3532. }
  3533. return 0;
  3534. err_out:
  3535. while (q_idx) {
  3536. q_idx--;
  3537. q_vector = adapter->q_vector[q_idx];
  3538. netif_napi_del(&q_vector->napi);
  3539. kfree(q_vector);
  3540. adapter->q_vector[q_idx] = NULL;
  3541. }
  3542. return -ENOMEM;
  3543. }
  3544. /**
  3545. * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
  3546. * @adapter: board private structure to initialize
  3547. *
  3548. * This function frees the memory allocated to the q_vectors. In addition if
  3549. * NAPI is enabled it will delete any references to the NAPI struct prior
  3550. * to freeing the q_vector.
  3551. **/
  3552. static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
  3553. {
  3554. int q_idx, num_q_vectors;
  3555. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3556. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  3557. else
  3558. num_q_vectors = 1;
  3559. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  3560. struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
  3561. adapter->q_vector[q_idx] = NULL;
  3562. netif_napi_del(&q_vector->napi);
  3563. kfree(q_vector);
  3564. }
  3565. }
  3566. static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
  3567. {
  3568. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3569. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  3570. pci_disable_msix(adapter->pdev);
  3571. kfree(adapter->msix_entries);
  3572. adapter->msix_entries = NULL;
  3573. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  3574. adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
  3575. pci_disable_msi(adapter->pdev);
  3576. }
  3577. return;
  3578. }
  3579. /**
  3580. * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
  3581. * @adapter: board private structure to initialize
  3582. *
  3583. * We determine which interrupt scheme to use based on...
  3584. * - Kernel support (MSI, MSI-X)
  3585. * - which can be user-defined (via MODULE_PARAM)
  3586. * - Hardware queue count (num_*_queues)
  3587. * - defined by miscellaneous hardware support/features (RSS, etc.)
  3588. **/
  3589. int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
  3590. {
  3591. int err;
  3592. /* Number of supported queues */
  3593. ixgbe_set_num_queues(adapter);
  3594. err = ixgbe_set_interrupt_capability(adapter);
  3595. if (err) {
  3596. DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
  3597. goto err_set_interrupt;
  3598. }
  3599. err = ixgbe_alloc_q_vectors(adapter);
  3600. if (err) {
  3601. DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
  3602. "vectors\n");
  3603. goto err_alloc_q_vectors;
  3604. }
  3605. err = ixgbe_alloc_queues(adapter);
  3606. if (err) {
  3607. DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
  3608. goto err_alloc_queues;
  3609. }
  3610. DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
  3611. "Tx Queue count = %u\n",
  3612. (adapter->num_rx_queues > 1) ? "Enabled" :
  3613. "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
  3614. set_bit(__IXGBE_DOWN, &adapter->state);
  3615. return 0;
  3616. err_alloc_queues:
  3617. ixgbe_free_q_vectors(adapter);
  3618. err_alloc_q_vectors:
  3619. ixgbe_reset_interrupt_capability(adapter);
  3620. err_set_interrupt:
  3621. return err;
  3622. }
  3623. /**
  3624. * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3625. * @adapter: board private structure to clear interrupt scheme on
  3626. *
  3627. * We go through and clear interrupt specific resources and reset the structure
  3628. * to pre-load conditions
  3629. **/
  3630. void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
  3631. {
  3632. int i;
  3633. for (i = 0; i < adapter->num_tx_queues; i++) {
  3634. kfree(adapter->tx_ring[i]);
  3635. adapter->tx_ring[i] = NULL;
  3636. }
  3637. for (i = 0; i < adapter->num_rx_queues; i++) {
  3638. kfree(adapter->rx_ring[i]);
  3639. adapter->rx_ring[i] = NULL;
  3640. }
  3641. ixgbe_free_q_vectors(adapter);
  3642. ixgbe_reset_interrupt_capability(adapter);
  3643. }
  3644. /**
  3645. * ixgbe_sfp_timer - worker thread to find a missing module
  3646. * @data: pointer to our adapter struct
  3647. **/
  3648. static void ixgbe_sfp_timer(unsigned long data)
  3649. {
  3650. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  3651. /*
  3652. * Do the sfp_timer outside of interrupt context due to the
  3653. * delays that sfp+ detection requires
  3654. */
  3655. schedule_work(&adapter->sfp_task);
  3656. }
  3657. /**
  3658. * ixgbe_sfp_task - worker thread to find a missing module
  3659. * @work: pointer to work_struct containing our data
  3660. **/
  3661. static void ixgbe_sfp_task(struct work_struct *work)
  3662. {
  3663. struct ixgbe_adapter *adapter = container_of(work,
  3664. struct ixgbe_adapter,
  3665. sfp_task);
  3666. struct ixgbe_hw *hw = &adapter->hw;
  3667. if ((hw->phy.type == ixgbe_phy_nl) &&
  3668. (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
  3669. s32 ret = hw->phy.ops.identify_sfp(hw);
  3670. if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
  3671. goto reschedule;
  3672. ret = hw->phy.ops.reset(hw);
  3673. if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  3674. dev_err(&adapter->pdev->dev, "failed to initialize "
  3675. "because an unsupported SFP+ module type "
  3676. "was detected.\n"
  3677. "Reload the driver after installing a "
  3678. "supported module.\n");
  3679. unregister_netdev(adapter->netdev);
  3680. } else {
  3681. DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
  3682. hw->phy.sfp_type);
  3683. }
  3684. /* don't need this routine any more */
  3685. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  3686. }
  3687. return;
  3688. reschedule:
  3689. if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
  3690. mod_timer(&adapter->sfp_timer,
  3691. round_jiffies(jiffies + (2 * HZ)));
  3692. }
  3693. /**
  3694. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  3695. * @adapter: board private structure to initialize
  3696. *
  3697. * ixgbe_sw_init initializes the Adapter private data structure.
  3698. * Fields are initialized based on PCI device information and
  3699. * OS network device settings (MTU size).
  3700. **/
  3701. static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
  3702. {
  3703. struct ixgbe_hw *hw = &adapter->hw;
  3704. struct pci_dev *pdev = adapter->pdev;
  3705. struct net_device *dev = adapter->netdev;
  3706. unsigned int rss;
  3707. #ifdef CONFIG_IXGBE_DCB
  3708. int j;
  3709. struct tc_configuration *tc;
  3710. #endif
  3711. /* PCI config space info */
  3712. hw->vendor_id = pdev->vendor;
  3713. hw->device_id = pdev->device;
  3714. hw->revision_id = pdev->revision;
  3715. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  3716. hw->subsystem_device_id = pdev->subsystem_device;
  3717. /* Set capability flags */
  3718. rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
  3719. adapter->ring_feature[RING_F_RSS].indices = rss;
  3720. adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
  3721. adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
  3722. if (hw->mac.type == ixgbe_mac_82598EB) {
  3723. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  3724. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  3725. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
  3726. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  3727. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
  3728. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  3729. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  3730. if (dev->features & NETIF_F_NTUPLE) {
  3731. /* Flow Director perfect filter enabled */
  3732. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3733. adapter->atr_sample_rate = 0;
  3734. spin_lock_init(&adapter->fdir_perfect_lock);
  3735. } else {
  3736. /* Flow Director hash filters enabled */
  3737. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3738. adapter->atr_sample_rate = 20;
  3739. }
  3740. adapter->ring_feature[RING_F_FDIR].indices =
  3741. IXGBE_MAX_FDIR_INDICES;
  3742. adapter->fdir_pballoc = 0;
  3743. #ifdef IXGBE_FCOE
  3744. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  3745. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  3746. adapter->ring_feature[RING_F_FCOE].indices = 0;
  3747. #ifdef CONFIG_IXGBE_DCB
  3748. /* Default traffic class to use for FCoE */
  3749. adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
  3750. #endif
  3751. #endif /* IXGBE_FCOE */
  3752. }
  3753. #ifdef CONFIG_IXGBE_DCB
  3754. /* Configure DCB traffic classes */
  3755. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  3756. tc = &adapter->dcb_cfg.tc_config[j];
  3757. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  3758. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  3759. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  3760. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  3761. tc->dcb_pfc = pfc_disabled;
  3762. }
  3763. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  3764. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  3765. adapter->dcb_cfg.rx_pba_cfg = pba_equal;
  3766. adapter->dcb_cfg.pfc_mode_enable = false;
  3767. adapter->dcb_cfg.round_robin_enable = false;
  3768. adapter->dcb_set_bitmap = 0x00;
  3769. ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
  3770. adapter->ring_feature[RING_F_DCB].indices);
  3771. #endif
  3772. /* default flow control settings */
  3773. hw->fc.requested_mode = ixgbe_fc_full;
  3774. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  3775. #ifdef CONFIG_DCB
  3776. adapter->last_lfc_mode = hw->fc.current_mode;
  3777. #endif
  3778. hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
  3779. hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
  3780. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  3781. hw->fc.send_xon = true;
  3782. hw->fc.disable_fc_autoneg = false;
  3783. /* enable itr by default in dynamic mode */
  3784. adapter->rx_itr_setting = 1;
  3785. adapter->rx_eitr_param = 20000;
  3786. adapter->tx_itr_setting = 1;
  3787. adapter->tx_eitr_param = 10000;
  3788. /* set defaults for eitr in MegaBytes */
  3789. adapter->eitr_low = 10;
  3790. adapter->eitr_high = 20;
  3791. /* set default ring sizes */
  3792. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  3793. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  3794. /* initialize eeprom parameters */
  3795. if (ixgbe_init_eeprom_params_generic(hw)) {
  3796. dev_err(&pdev->dev, "EEPROM initialization failed\n");
  3797. return -EIO;
  3798. }
  3799. /* enable rx csum by default */
  3800. adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
  3801. /* get assigned NUMA node */
  3802. adapter->node = dev_to_node(&pdev->dev);
  3803. set_bit(__IXGBE_DOWN, &adapter->state);
  3804. return 0;
  3805. }
  3806. /**
  3807. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  3808. * @adapter: board private structure
  3809. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  3810. *
  3811. * Return 0 on success, negative on failure
  3812. **/
  3813. int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
  3814. struct ixgbe_ring *tx_ring)
  3815. {
  3816. struct pci_dev *pdev = adapter->pdev;
  3817. int size;
  3818. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  3819. tx_ring->tx_buffer_info = vmalloc_node(size, tx_ring->numa_node);
  3820. if (!tx_ring->tx_buffer_info)
  3821. tx_ring->tx_buffer_info = vmalloc(size);
  3822. if (!tx_ring->tx_buffer_info)
  3823. goto err;
  3824. memset(tx_ring->tx_buffer_info, 0, size);
  3825. /* round up to nearest 4K */
  3826. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  3827. tx_ring->size = ALIGN(tx_ring->size, 4096);
  3828. tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
  3829. &tx_ring->dma);
  3830. if (!tx_ring->desc)
  3831. goto err;
  3832. tx_ring->next_to_use = 0;
  3833. tx_ring->next_to_clean = 0;
  3834. tx_ring->work_limit = tx_ring->count;
  3835. return 0;
  3836. err:
  3837. vfree(tx_ring->tx_buffer_info);
  3838. tx_ring->tx_buffer_info = NULL;
  3839. DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
  3840. "descriptor ring\n");
  3841. return -ENOMEM;
  3842. }
  3843. /**
  3844. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  3845. * @adapter: board private structure
  3846. *
  3847. * If this function returns with an error, then it's possible one or
  3848. * more of the rings is populated (while the rest are not). It is the
  3849. * callers duty to clean those orphaned rings.
  3850. *
  3851. * Return 0 on success, negative on failure
  3852. **/
  3853. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  3854. {
  3855. int i, err = 0;
  3856. for (i = 0; i < adapter->num_tx_queues; i++) {
  3857. err = ixgbe_setup_tx_resources(adapter, adapter->tx_ring[i]);
  3858. if (!err)
  3859. continue;
  3860. DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
  3861. break;
  3862. }
  3863. return err;
  3864. }
  3865. /**
  3866. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  3867. * @adapter: board private structure
  3868. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  3869. *
  3870. * Returns 0 on success, negative on failure
  3871. **/
  3872. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  3873. struct ixgbe_ring *rx_ring)
  3874. {
  3875. struct pci_dev *pdev = adapter->pdev;
  3876. int size;
  3877. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  3878. rx_ring->rx_buffer_info = vmalloc_node(size, adapter->node);
  3879. if (!rx_ring->rx_buffer_info)
  3880. rx_ring->rx_buffer_info = vmalloc(size);
  3881. if (!rx_ring->rx_buffer_info) {
  3882. DPRINTK(PROBE, ERR,
  3883. "vmalloc allocation failed for the rx desc ring\n");
  3884. goto alloc_failed;
  3885. }
  3886. memset(rx_ring->rx_buffer_info, 0, size);
  3887. /* Round up to nearest 4K */
  3888. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  3889. rx_ring->size = ALIGN(rx_ring->size, 4096);
  3890. rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
  3891. if (!rx_ring->desc) {
  3892. DPRINTK(PROBE, ERR,
  3893. "Memory allocation failed for the rx desc ring\n");
  3894. vfree(rx_ring->rx_buffer_info);
  3895. goto alloc_failed;
  3896. }
  3897. rx_ring->next_to_clean = 0;
  3898. rx_ring->next_to_use = 0;
  3899. return 0;
  3900. alloc_failed:
  3901. return -ENOMEM;
  3902. }
  3903. /**
  3904. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  3905. * @adapter: board private structure
  3906. *
  3907. * If this function returns with an error, then it's possible one or
  3908. * more of the rings is populated (while the rest are not). It is the
  3909. * callers duty to clean those orphaned rings.
  3910. *
  3911. * Return 0 on success, negative on failure
  3912. **/
  3913. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  3914. {
  3915. int i, err = 0;
  3916. for (i = 0; i < adapter->num_rx_queues; i++) {
  3917. err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
  3918. if (!err)
  3919. continue;
  3920. DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
  3921. break;
  3922. }
  3923. return err;
  3924. }
  3925. /**
  3926. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  3927. * @adapter: board private structure
  3928. * @tx_ring: Tx descriptor ring for a specific queue
  3929. *
  3930. * Free all transmit software resources
  3931. **/
  3932. void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
  3933. struct ixgbe_ring *tx_ring)
  3934. {
  3935. struct pci_dev *pdev = adapter->pdev;
  3936. ixgbe_clean_tx_ring(adapter, tx_ring);
  3937. vfree(tx_ring->tx_buffer_info);
  3938. tx_ring->tx_buffer_info = NULL;
  3939. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  3940. tx_ring->desc = NULL;
  3941. }
  3942. /**
  3943. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  3944. * @adapter: board private structure
  3945. *
  3946. * Free all transmit software resources
  3947. **/
  3948. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  3949. {
  3950. int i;
  3951. for (i = 0; i < adapter->num_tx_queues; i++)
  3952. if (adapter->tx_ring[i]->desc)
  3953. ixgbe_free_tx_resources(adapter, adapter->tx_ring[i]);
  3954. }
  3955. /**
  3956. * ixgbe_free_rx_resources - Free Rx Resources
  3957. * @adapter: board private structure
  3958. * @rx_ring: ring to clean the resources from
  3959. *
  3960. * Free all receive software resources
  3961. **/
  3962. void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
  3963. struct ixgbe_ring *rx_ring)
  3964. {
  3965. struct pci_dev *pdev = adapter->pdev;
  3966. ixgbe_clean_rx_ring(adapter, rx_ring);
  3967. vfree(rx_ring->rx_buffer_info);
  3968. rx_ring->rx_buffer_info = NULL;
  3969. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  3970. rx_ring->desc = NULL;
  3971. }
  3972. /**
  3973. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  3974. * @adapter: board private structure
  3975. *
  3976. * Free all receive software resources
  3977. **/
  3978. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  3979. {
  3980. int i;
  3981. for (i = 0; i < adapter->num_rx_queues; i++)
  3982. if (adapter->rx_ring[i]->desc)
  3983. ixgbe_free_rx_resources(adapter, adapter->rx_ring[i]);
  3984. }
  3985. /**
  3986. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  3987. * @netdev: network interface device structure
  3988. * @new_mtu: new value for maximum frame size
  3989. *
  3990. * Returns 0 on success, negative on failure
  3991. **/
  3992. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  3993. {
  3994. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3995. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  3996. /* MTU < 68 is an error and causes problems on some kernels */
  3997. if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
  3998. return -EINVAL;
  3999. DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
  4000. netdev->mtu, new_mtu);
  4001. /* must set new MTU before calling down or up */
  4002. netdev->mtu = new_mtu;
  4003. if (netif_running(netdev))
  4004. ixgbe_reinit_locked(adapter);
  4005. return 0;
  4006. }
  4007. /**
  4008. * ixgbe_open - Called when a network interface is made active
  4009. * @netdev: network interface device structure
  4010. *
  4011. * Returns 0 on success, negative value on failure
  4012. *
  4013. * The open entry point is called when a network interface is made
  4014. * active by the system (IFF_UP). At this point all resources needed
  4015. * for transmit and receive operations are allocated, the interrupt
  4016. * handler is registered with the OS, the watchdog timer is started,
  4017. * and the stack is notified that the interface is ready.
  4018. **/
  4019. static int ixgbe_open(struct net_device *netdev)
  4020. {
  4021. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4022. int err;
  4023. /* disallow open during test */
  4024. if (test_bit(__IXGBE_TESTING, &adapter->state))
  4025. return -EBUSY;
  4026. netif_carrier_off(netdev);
  4027. /* allocate transmit descriptors */
  4028. err = ixgbe_setup_all_tx_resources(adapter);
  4029. if (err)
  4030. goto err_setup_tx;
  4031. /* allocate receive descriptors */
  4032. err = ixgbe_setup_all_rx_resources(adapter);
  4033. if (err)
  4034. goto err_setup_rx;
  4035. ixgbe_configure(adapter);
  4036. err = ixgbe_request_irq(adapter);
  4037. if (err)
  4038. goto err_req_irq;
  4039. err = ixgbe_up_complete(adapter);
  4040. if (err)
  4041. goto err_up;
  4042. netif_tx_start_all_queues(netdev);
  4043. return 0;
  4044. err_up:
  4045. ixgbe_release_hw_control(adapter);
  4046. ixgbe_free_irq(adapter);
  4047. err_req_irq:
  4048. err_setup_rx:
  4049. ixgbe_free_all_rx_resources(adapter);
  4050. err_setup_tx:
  4051. ixgbe_free_all_tx_resources(adapter);
  4052. ixgbe_reset(adapter);
  4053. return err;
  4054. }
  4055. /**
  4056. * ixgbe_close - Disables a network interface
  4057. * @netdev: network interface device structure
  4058. *
  4059. * Returns 0, this is not allowed to fail
  4060. *
  4061. * The close entry point is called when an interface is de-activated
  4062. * by the OS. The hardware is still under the drivers control, but
  4063. * needs to be disabled. A global MAC reset is issued to stop the
  4064. * hardware, and all transmit and receive resources are freed.
  4065. **/
  4066. static int ixgbe_close(struct net_device *netdev)
  4067. {
  4068. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4069. ixgbe_down(adapter);
  4070. ixgbe_free_irq(adapter);
  4071. ixgbe_free_all_tx_resources(adapter);
  4072. ixgbe_free_all_rx_resources(adapter);
  4073. ixgbe_release_hw_control(adapter);
  4074. return 0;
  4075. }
  4076. #ifdef CONFIG_PM
  4077. static int ixgbe_resume(struct pci_dev *pdev)
  4078. {
  4079. struct net_device *netdev = pci_get_drvdata(pdev);
  4080. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4081. u32 err;
  4082. pci_set_power_state(pdev, PCI_D0);
  4083. pci_restore_state(pdev);
  4084. /*
  4085. * pci_restore_state clears dev->state_saved so call
  4086. * pci_save_state to restore it.
  4087. */
  4088. pci_save_state(pdev);
  4089. err = pci_enable_device_mem(pdev);
  4090. if (err) {
  4091. printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
  4092. "suspend\n");
  4093. return err;
  4094. }
  4095. pci_set_master(pdev);
  4096. pci_wake_from_d3(pdev, false);
  4097. err = ixgbe_init_interrupt_scheme(adapter);
  4098. if (err) {
  4099. printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
  4100. "device\n");
  4101. return err;
  4102. }
  4103. ixgbe_reset(adapter);
  4104. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  4105. if (netif_running(netdev)) {
  4106. err = ixgbe_open(adapter->netdev);
  4107. if (err)
  4108. return err;
  4109. }
  4110. netif_device_attach(netdev);
  4111. return 0;
  4112. }
  4113. #endif /* CONFIG_PM */
  4114. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  4115. {
  4116. struct net_device *netdev = pci_get_drvdata(pdev);
  4117. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4118. struct ixgbe_hw *hw = &adapter->hw;
  4119. u32 ctrl, fctrl;
  4120. u32 wufc = adapter->wol;
  4121. #ifdef CONFIG_PM
  4122. int retval = 0;
  4123. #endif
  4124. netif_device_detach(netdev);
  4125. if (netif_running(netdev)) {
  4126. ixgbe_down(adapter);
  4127. ixgbe_free_irq(adapter);
  4128. ixgbe_free_all_tx_resources(adapter);
  4129. ixgbe_free_all_rx_resources(adapter);
  4130. }
  4131. ixgbe_clear_interrupt_scheme(adapter);
  4132. #ifdef CONFIG_PM
  4133. retval = pci_save_state(pdev);
  4134. if (retval)
  4135. return retval;
  4136. #endif
  4137. if (wufc) {
  4138. ixgbe_set_rx_mode(netdev);
  4139. /* turn on all-multi mode if wake on multicast is enabled */
  4140. if (wufc & IXGBE_WUFC_MC) {
  4141. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4142. fctrl |= IXGBE_FCTRL_MPE;
  4143. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4144. }
  4145. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  4146. ctrl |= IXGBE_CTRL_GIO_DIS;
  4147. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  4148. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  4149. } else {
  4150. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  4151. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  4152. }
  4153. if (wufc && hw->mac.type == ixgbe_mac_82599EB)
  4154. pci_wake_from_d3(pdev, true);
  4155. else
  4156. pci_wake_from_d3(pdev, false);
  4157. *enable_wake = !!wufc;
  4158. ixgbe_release_hw_control(adapter);
  4159. pci_disable_device(pdev);
  4160. return 0;
  4161. }
  4162. #ifdef CONFIG_PM
  4163. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  4164. {
  4165. int retval;
  4166. bool wake;
  4167. retval = __ixgbe_shutdown(pdev, &wake);
  4168. if (retval)
  4169. return retval;
  4170. if (wake) {
  4171. pci_prepare_to_sleep(pdev);
  4172. } else {
  4173. pci_wake_from_d3(pdev, false);
  4174. pci_set_power_state(pdev, PCI_D3hot);
  4175. }
  4176. return 0;
  4177. }
  4178. #endif /* CONFIG_PM */
  4179. static void ixgbe_shutdown(struct pci_dev *pdev)
  4180. {
  4181. bool wake;
  4182. __ixgbe_shutdown(pdev, &wake);
  4183. if (system_state == SYSTEM_POWER_OFF) {
  4184. pci_wake_from_d3(pdev, wake);
  4185. pci_set_power_state(pdev, PCI_D3hot);
  4186. }
  4187. }
  4188. /**
  4189. * ixgbe_update_stats - Update the board statistics counters.
  4190. * @adapter: board private structure
  4191. **/
  4192. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  4193. {
  4194. struct net_device *netdev = adapter->netdev;
  4195. struct ixgbe_hw *hw = &adapter->hw;
  4196. u64 total_mpc = 0;
  4197. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  4198. u64 non_eop_descs = 0, restart_queue = 0;
  4199. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  4200. u64 rsc_count = 0;
  4201. u64 rsc_flush = 0;
  4202. for (i = 0; i < 16; i++)
  4203. adapter->hw_rx_no_dma_resources +=
  4204. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4205. for (i = 0; i < adapter->num_rx_queues; i++) {
  4206. rsc_count += adapter->rx_ring[i]->rsc_count;
  4207. rsc_flush += adapter->rx_ring[i]->rsc_flush;
  4208. }
  4209. adapter->rsc_total_count = rsc_count;
  4210. adapter->rsc_total_flush = rsc_flush;
  4211. }
  4212. /* gather some stats to the adapter struct that are per queue */
  4213. for (i = 0; i < adapter->num_tx_queues; i++)
  4214. restart_queue += adapter->tx_ring[i]->restart_queue;
  4215. adapter->restart_queue = restart_queue;
  4216. for (i = 0; i < adapter->num_rx_queues; i++)
  4217. non_eop_descs += adapter->rx_ring[i]->non_eop_descs;
  4218. adapter->non_eop_descs = non_eop_descs;
  4219. adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  4220. for (i = 0; i < 8; i++) {
  4221. /* for packet buffers not used, the register should read 0 */
  4222. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  4223. missed_rx += mpc;
  4224. adapter->stats.mpc[i] += mpc;
  4225. total_mpc += adapter->stats.mpc[i];
  4226. if (hw->mac.type == ixgbe_mac_82598EB)
  4227. adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  4228. adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  4229. adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  4230. adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  4231. adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  4232. if (hw->mac.type == ixgbe_mac_82599EB) {
  4233. adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
  4234. IXGBE_PXONRXCNT(i));
  4235. adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
  4236. IXGBE_PXOFFRXCNT(i));
  4237. adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4238. } else {
  4239. adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
  4240. IXGBE_PXONRXC(i));
  4241. adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
  4242. IXGBE_PXOFFRXC(i));
  4243. }
  4244. adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
  4245. IXGBE_PXONTXC(i));
  4246. adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
  4247. IXGBE_PXOFFTXC(i));
  4248. }
  4249. adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  4250. /* work around hardware counting issue */
  4251. adapter->stats.gprc -= missed_rx;
  4252. /* 82598 hardware only has a 32 bit counter in the high register */
  4253. if (hw->mac.type == ixgbe_mac_82599EB) {
  4254. u64 tmp;
  4255. adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  4256. tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
  4257. adapter->stats.gorc += (tmp << 32);
  4258. adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  4259. tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
  4260. adapter->stats.gotc += (tmp << 32);
  4261. adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  4262. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  4263. adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  4264. adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  4265. adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  4266. adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  4267. #ifdef IXGBE_FCOE
  4268. adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  4269. adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  4270. adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  4271. adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  4272. adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  4273. adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  4274. #endif /* IXGBE_FCOE */
  4275. } else {
  4276. adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  4277. adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  4278. adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  4279. adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  4280. adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  4281. }
  4282. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  4283. adapter->stats.bprc += bprc;
  4284. adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  4285. if (hw->mac.type == ixgbe_mac_82598EB)
  4286. adapter->stats.mprc -= bprc;
  4287. adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  4288. adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  4289. adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  4290. adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  4291. adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  4292. adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  4293. adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  4294. adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  4295. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  4296. adapter->stats.lxontxc += lxon;
  4297. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  4298. adapter->stats.lxofftxc += lxoff;
  4299. adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4300. adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  4301. adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  4302. /*
  4303. * 82598 errata - tx of flow control packets is included in tx counters
  4304. */
  4305. xon_off_tot = lxon + lxoff;
  4306. adapter->stats.gptc -= xon_off_tot;
  4307. adapter->stats.mptc -= xon_off_tot;
  4308. adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  4309. adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4310. adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  4311. adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  4312. adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  4313. adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  4314. adapter->stats.ptc64 -= xon_off_tot;
  4315. adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  4316. adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  4317. adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  4318. adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  4319. adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  4320. adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  4321. /* Fill out the OS statistics structure */
  4322. netdev->stats.multicast = adapter->stats.mprc;
  4323. /* Rx Errors */
  4324. netdev->stats.rx_errors = adapter->stats.crcerrs +
  4325. adapter->stats.rlec;
  4326. netdev->stats.rx_dropped = 0;
  4327. netdev->stats.rx_length_errors = adapter->stats.rlec;
  4328. netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
  4329. netdev->stats.rx_missed_errors = total_mpc;
  4330. }
  4331. /**
  4332. * ixgbe_watchdog - Timer Call-back
  4333. * @data: pointer to adapter cast into an unsigned long
  4334. **/
  4335. static void ixgbe_watchdog(unsigned long data)
  4336. {
  4337. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  4338. struct ixgbe_hw *hw = &adapter->hw;
  4339. u64 eics = 0;
  4340. int i;
  4341. /*
  4342. * Do the watchdog outside of interrupt context due to the lovely
  4343. * delays that some of the newer hardware requires
  4344. */
  4345. if (test_bit(__IXGBE_DOWN, &adapter->state))
  4346. goto watchdog_short_circuit;
  4347. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  4348. /*
  4349. * for legacy and MSI interrupts don't set any bits
  4350. * that are enabled for EIAM, because this operation
  4351. * would set *both* EIMS and EICS for any bit in EIAM
  4352. */
  4353. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  4354. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  4355. goto watchdog_reschedule;
  4356. }
  4357. /* get one bit for every active tx/rx interrupt vector */
  4358. for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
  4359. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  4360. if (qv->rxr_count || qv->txr_count)
  4361. eics |= ((u64)1 << i);
  4362. }
  4363. /* Cause software interrupt to ensure rx rings are cleaned */
  4364. ixgbe_irq_rearm_queues(adapter, eics);
  4365. watchdog_reschedule:
  4366. /* Reset the timer */
  4367. mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
  4368. watchdog_short_circuit:
  4369. schedule_work(&adapter->watchdog_task);
  4370. }
  4371. /**
  4372. * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
  4373. * @work: pointer to work_struct containing our data
  4374. **/
  4375. static void ixgbe_multispeed_fiber_task(struct work_struct *work)
  4376. {
  4377. struct ixgbe_adapter *adapter = container_of(work,
  4378. struct ixgbe_adapter,
  4379. multispeed_fiber_task);
  4380. struct ixgbe_hw *hw = &adapter->hw;
  4381. u32 autoneg;
  4382. bool negotiation;
  4383. adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
  4384. autoneg = hw->phy.autoneg_advertised;
  4385. if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
  4386. hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  4387. hw->mac.autotry_restart = false;
  4388. if (hw->mac.ops.setup_link)
  4389. hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
  4390. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4391. adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
  4392. }
  4393. /**
  4394. * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
  4395. * @work: pointer to work_struct containing our data
  4396. **/
  4397. static void ixgbe_sfp_config_module_task(struct work_struct *work)
  4398. {
  4399. struct ixgbe_adapter *adapter = container_of(work,
  4400. struct ixgbe_adapter,
  4401. sfp_config_module_task);
  4402. struct ixgbe_hw *hw = &adapter->hw;
  4403. u32 err;
  4404. adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
  4405. /* Time for electrical oscillations to settle down */
  4406. msleep(100);
  4407. err = hw->phy.ops.identify_sfp(hw);
  4408. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4409. dev_err(&adapter->pdev->dev, "failed to initialize because "
  4410. "an unsupported SFP+ module type was detected.\n"
  4411. "Reload the driver after installing a supported "
  4412. "module.\n");
  4413. unregister_netdev(adapter->netdev);
  4414. return;
  4415. }
  4416. hw->mac.ops.setup_sfp(hw);
  4417. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  4418. /* This will also work for DA Twinax connections */
  4419. schedule_work(&adapter->multispeed_fiber_task);
  4420. adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
  4421. }
  4422. /**
  4423. * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
  4424. * @work: pointer to work_struct containing our data
  4425. **/
  4426. static void ixgbe_fdir_reinit_task(struct work_struct *work)
  4427. {
  4428. struct ixgbe_adapter *adapter = container_of(work,
  4429. struct ixgbe_adapter,
  4430. fdir_reinit_task);
  4431. struct ixgbe_hw *hw = &adapter->hw;
  4432. int i;
  4433. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  4434. for (i = 0; i < adapter->num_tx_queues; i++)
  4435. set_bit(__IXGBE_FDIR_INIT_DONE,
  4436. &(adapter->tx_ring[i]->reinit_state));
  4437. } else {
  4438. DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
  4439. "ignored adding FDIR ATR filters \n");
  4440. }
  4441. /* Done FDIR Re-initialization, enable transmits */
  4442. netif_tx_start_all_queues(adapter->netdev);
  4443. }
  4444. static DEFINE_MUTEX(ixgbe_watchdog_lock);
  4445. /**
  4446. * ixgbe_watchdog_task - worker thread to bring link up
  4447. * @work: pointer to work_struct containing our data
  4448. **/
  4449. static void ixgbe_watchdog_task(struct work_struct *work)
  4450. {
  4451. struct ixgbe_adapter *adapter = container_of(work,
  4452. struct ixgbe_adapter,
  4453. watchdog_task);
  4454. struct net_device *netdev = adapter->netdev;
  4455. struct ixgbe_hw *hw = &adapter->hw;
  4456. u32 link_speed;
  4457. bool link_up;
  4458. int i;
  4459. struct ixgbe_ring *tx_ring;
  4460. int some_tx_pending = 0;
  4461. mutex_lock(&ixgbe_watchdog_lock);
  4462. link_up = adapter->link_up;
  4463. link_speed = adapter->link_speed;
  4464. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
  4465. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  4466. if (link_up) {
  4467. #ifdef CONFIG_DCB
  4468. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4469. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  4470. hw->mac.ops.fc_enable(hw, i);
  4471. } else {
  4472. hw->mac.ops.fc_enable(hw, 0);
  4473. }
  4474. #else
  4475. hw->mac.ops.fc_enable(hw, 0);
  4476. #endif
  4477. }
  4478. if (link_up ||
  4479. time_after(jiffies, (adapter->link_check_timeout +
  4480. IXGBE_TRY_LINK_TIMEOUT))) {
  4481. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4482. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  4483. }
  4484. adapter->link_up = link_up;
  4485. adapter->link_speed = link_speed;
  4486. }
  4487. if (link_up) {
  4488. if (!netif_carrier_ok(netdev)) {
  4489. bool flow_rx, flow_tx;
  4490. if (hw->mac.type == ixgbe_mac_82599EB) {
  4491. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  4492. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  4493. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  4494. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  4495. } else {
  4496. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4497. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  4498. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  4499. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  4500. }
  4501. printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
  4502. "Flow Control: %s\n",
  4503. netdev->name,
  4504. (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
  4505. "10 Gbps" :
  4506. (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
  4507. "1 Gbps" : "unknown speed")),
  4508. ((flow_rx && flow_tx) ? "RX/TX" :
  4509. (flow_rx ? "RX" :
  4510. (flow_tx ? "TX" : "None"))));
  4511. netif_carrier_on(netdev);
  4512. } else {
  4513. /* Force detection of hung controller */
  4514. adapter->detect_tx_hung = true;
  4515. }
  4516. } else {
  4517. adapter->link_up = false;
  4518. adapter->link_speed = 0;
  4519. if (netif_carrier_ok(netdev)) {
  4520. printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
  4521. netdev->name);
  4522. netif_carrier_off(netdev);
  4523. }
  4524. }
  4525. if (!netif_carrier_ok(netdev)) {
  4526. for (i = 0; i < adapter->num_tx_queues; i++) {
  4527. tx_ring = adapter->tx_ring[i];
  4528. if (tx_ring->next_to_use != tx_ring->next_to_clean) {
  4529. some_tx_pending = 1;
  4530. break;
  4531. }
  4532. }
  4533. if (some_tx_pending) {
  4534. /* We've lost link, so the controller stops DMA,
  4535. * but we've got queued Tx work that's never going
  4536. * to get done, so reset controller to flush Tx.
  4537. * (Do the reset outside of interrupt context).
  4538. */
  4539. schedule_work(&adapter->reset_task);
  4540. }
  4541. }
  4542. ixgbe_update_stats(adapter);
  4543. mutex_unlock(&ixgbe_watchdog_lock);
  4544. }
  4545. static int ixgbe_tso(struct ixgbe_adapter *adapter,
  4546. struct ixgbe_ring *tx_ring, struct sk_buff *skb,
  4547. u32 tx_flags, u8 *hdr_len)
  4548. {
  4549. struct ixgbe_adv_tx_context_desc *context_desc;
  4550. unsigned int i;
  4551. int err;
  4552. struct ixgbe_tx_buffer *tx_buffer_info;
  4553. u32 vlan_macip_lens = 0, type_tucmd_mlhl;
  4554. u32 mss_l4len_idx, l4len;
  4555. if (skb_is_gso(skb)) {
  4556. if (skb_header_cloned(skb)) {
  4557. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  4558. if (err)
  4559. return err;
  4560. }
  4561. l4len = tcp_hdrlen(skb);
  4562. *hdr_len += l4len;
  4563. if (skb->protocol == htons(ETH_P_IP)) {
  4564. struct iphdr *iph = ip_hdr(skb);
  4565. iph->tot_len = 0;
  4566. iph->check = 0;
  4567. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  4568. iph->daddr, 0,
  4569. IPPROTO_TCP,
  4570. 0);
  4571. } else if (skb_is_gso_v6(skb)) {
  4572. ipv6_hdr(skb)->payload_len = 0;
  4573. tcp_hdr(skb)->check =
  4574. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  4575. &ipv6_hdr(skb)->daddr,
  4576. 0, IPPROTO_TCP, 0);
  4577. }
  4578. i = tx_ring->next_to_use;
  4579. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4580. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  4581. /* VLAN MACLEN IPLEN */
  4582. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  4583. vlan_macip_lens |=
  4584. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  4585. vlan_macip_lens |= ((skb_network_offset(skb)) <<
  4586. IXGBE_ADVTXD_MACLEN_SHIFT);
  4587. *hdr_len += skb_network_offset(skb);
  4588. vlan_macip_lens |=
  4589. (skb_transport_header(skb) - skb_network_header(skb));
  4590. *hdr_len +=
  4591. (skb_transport_header(skb) - skb_network_header(skb));
  4592. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  4593. context_desc->seqnum_seed = 0;
  4594. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  4595. type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
  4596. IXGBE_ADVTXD_DTYP_CTXT);
  4597. if (skb->protocol == htons(ETH_P_IP))
  4598. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  4599. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  4600. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  4601. /* MSS L4LEN IDX */
  4602. mss_l4len_idx =
  4603. (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
  4604. mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
  4605. /* use index 1 for TSO */
  4606. mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  4607. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  4608. tx_buffer_info->time_stamp = jiffies;
  4609. tx_buffer_info->next_to_watch = i;
  4610. i++;
  4611. if (i == tx_ring->count)
  4612. i = 0;
  4613. tx_ring->next_to_use = i;
  4614. return true;
  4615. }
  4616. return false;
  4617. }
  4618. static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
  4619. struct ixgbe_ring *tx_ring,
  4620. struct sk_buff *skb, u32 tx_flags)
  4621. {
  4622. struct ixgbe_adv_tx_context_desc *context_desc;
  4623. unsigned int i;
  4624. struct ixgbe_tx_buffer *tx_buffer_info;
  4625. u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
  4626. if (skb->ip_summed == CHECKSUM_PARTIAL ||
  4627. (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
  4628. i = tx_ring->next_to_use;
  4629. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4630. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  4631. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  4632. vlan_macip_lens |=
  4633. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  4634. vlan_macip_lens |= (skb_network_offset(skb) <<
  4635. IXGBE_ADVTXD_MACLEN_SHIFT);
  4636. if (skb->ip_summed == CHECKSUM_PARTIAL)
  4637. vlan_macip_lens |= (skb_transport_header(skb) -
  4638. skb_network_header(skb));
  4639. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  4640. context_desc->seqnum_seed = 0;
  4641. type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
  4642. IXGBE_ADVTXD_DTYP_CTXT);
  4643. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  4644. __be16 protocol;
  4645. if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
  4646. const struct vlan_ethhdr *vhdr =
  4647. (const struct vlan_ethhdr *)skb->data;
  4648. protocol = vhdr->h_vlan_encapsulated_proto;
  4649. } else {
  4650. protocol = skb->protocol;
  4651. }
  4652. switch (protocol) {
  4653. case cpu_to_be16(ETH_P_IP):
  4654. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  4655. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  4656. type_tucmd_mlhl |=
  4657. IXGBE_ADVTXD_TUCMD_L4T_TCP;
  4658. else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
  4659. type_tucmd_mlhl |=
  4660. IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  4661. break;
  4662. case cpu_to_be16(ETH_P_IPV6):
  4663. /* XXX what about other V6 headers?? */
  4664. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  4665. type_tucmd_mlhl |=
  4666. IXGBE_ADVTXD_TUCMD_L4T_TCP;
  4667. else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
  4668. type_tucmd_mlhl |=
  4669. IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  4670. break;
  4671. default:
  4672. if (unlikely(net_ratelimit())) {
  4673. DPRINTK(PROBE, WARNING,
  4674. "partial checksum but proto=%x!\n",
  4675. skb->protocol);
  4676. }
  4677. break;
  4678. }
  4679. }
  4680. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  4681. /* use index zero for tx checksum offload */
  4682. context_desc->mss_l4len_idx = 0;
  4683. tx_buffer_info->time_stamp = jiffies;
  4684. tx_buffer_info->next_to_watch = i;
  4685. i++;
  4686. if (i == tx_ring->count)
  4687. i = 0;
  4688. tx_ring->next_to_use = i;
  4689. return true;
  4690. }
  4691. return false;
  4692. }
  4693. static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
  4694. struct ixgbe_ring *tx_ring,
  4695. struct sk_buff *skb, u32 tx_flags,
  4696. unsigned int first)
  4697. {
  4698. struct pci_dev *pdev = adapter->pdev;
  4699. struct ixgbe_tx_buffer *tx_buffer_info;
  4700. unsigned int len;
  4701. unsigned int total = skb->len;
  4702. unsigned int offset = 0, size, count = 0, i;
  4703. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  4704. unsigned int f;
  4705. i = tx_ring->next_to_use;
  4706. if (tx_flags & IXGBE_TX_FLAGS_FCOE)
  4707. /* excluding fcoe_crc_eof for FCoE */
  4708. total -= sizeof(struct fcoe_crc_eof);
  4709. len = min(skb_headlen(skb), total);
  4710. while (len) {
  4711. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4712. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  4713. tx_buffer_info->length = size;
  4714. tx_buffer_info->mapped_as_page = false;
  4715. tx_buffer_info->dma = pci_map_single(pdev,
  4716. skb->data + offset,
  4717. size, PCI_DMA_TODEVICE);
  4718. if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
  4719. goto dma_error;
  4720. tx_buffer_info->time_stamp = jiffies;
  4721. tx_buffer_info->next_to_watch = i;
  4722. len -= size;
  4723. total -= size;
  4724. offset += size;
  4725. count++;
  4726. if (len) {
  4727. i++;
  4728. if (i == tx_ring->count)
  4729. i = 0;
  4730. }
  4731. }
  4732. for (f = 0; f < nr_frags; f++) {
  4733. struct skb_frag_struct *frag;
  4734. frag = &skb_shinfo(skb)->frags[f];
  4735. len = min((unsigned int)frag->size, total);
  4736. offset = frag->page_offset;
  4737. while (len) {
  4738. i++;
  4739. if (i == tx_ring->count)
  4740. i = 0;
  4741. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4742. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  4743. tx_buffer_info->length = size;
  4744. tx_buffer_info->dma = pci_map_page(adapter->pdev,
  4745. frag->page,
  4746. offset, size,
  4747. PCI_DMA_TODEVICE);
  4748. tx_buffer_info->mapped_as_page = true;
  4749. if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
  4750. goto dma_error;
  4751. tx_buffer_info->time_stamp = jiffies;
  4752. tx_buffer_info->next_to_watch = i;
  4753. len -= size;
  4754. total -= size;
  4755. offset += size;
  4756. count++;
  4757. }
  4758. if (total == 0)
  4759. break;
  4760. }
  4761. tx_ring->tx_buffer_info[i].skb = skb;
  4762. tx_ring->tx_buffer_info[first].next_to_watch = i;
  4763. return count;
  4764. dma_error:
  4765. dev_err(&pdev->dev, "TX DMA map failed\n");
  4766. /* clear timestamp and dma mappings for failed tx_buffer_info map */
  4767. tx_buffer_info->dma = 0;
  4768. tx_buffer_info->time_stamp = 0;
  4769. tx_buffer_info->next_to_watch = 0;
  4770. if (count)
  4771. count--;
  4772. /* clear timestamp and dma mappings for remaining portion of packet */
  4773. while (count--) {
  4774. if (i==0)
  4775. i += tx_ring->count;
  4776. i--;
  4777. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4778. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  4779. }
  4780. return 0;
  4781. }
  4782. static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
  4783. struct ixgbe_ring *tx_ring,
  4784. int tx_flags, int count, u32 paylen, u8 hdr_len)
  4785. {
  4786. union ixgbe_adv_tx_desc *tx_desc = NULL;
  4787. struct ixgbe_tx_buffer *tx_buffer_info;
  4788. u32 olinfo_status = 0, cmd_type_len = 0;
  4789. unsigned int i;
  4790. u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
  4791. cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
  4792. cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
  4793. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  4794. cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
  4795. if (tx_flags & IXGBE_TX_FLAGS_TSO) {
  4796. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  4797. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  4798. IXGBE_ADVTXD_POPTS_SHIFT;
  4799. /* use index 1 context for tso */
  4800. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  4801. if (tx_flags & IXGBE_TX_FLAGS_IPV4)
  4802. olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
  4803. IXGBE_ADVTXD_POPTS_SHIFT;
  4804. } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
  4805. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  4806. IXGBE_ADVTXD_POPTS_SHIFT;
  4807. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  4808. olinfo_status |= IXGBE_ADVTXD_CC;
  4809. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  4810. if (tx_flags & IXGBE_TX_FLAGS_FSO)
  4811. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  4812. }
  4813. olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
  4814. i = tx_ring->next_to_use;
  4815. while (count--) {
  4816. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4817. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  4818. tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
  4819. tx_desc->read.cmd_type_len =
  4820. cpu_to_le32(cmd_type_len | tx_buffer_info->length);
  4821. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  4822. i++;
  4823. if (i == tx_ring->count)
  4824. i = 0;
  4825. }
  4826. tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
  4827. /*
  4828. * Force memory writes to complete before letting h/w
  4829. * know there are new descriptors to fetch. (Only
  4830. * applicable for weak-ordered memory model archs,
  4831. * such as IA-64).
  4832. */
  4833. wmb();
  4834. tx_ring->next_to_use = i;
  4835. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  4836. }
  4837. static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
  4838. int queue, u32 tx_flags)
  4839. {
  4840. /* Right now, we support IPv4 only */
  4841. struct ixgbe_atr_input atr_input;
  4842. struct tcphdr *th;
  4843. struct iphdr *iph = ip_hdr(skb);
  4844. struct ethhdr *eth = (struct ethhdr *)skb->data;
  4845. u16 vlan_id, src_port, dst_port, flex_bytes;
  4846. u32 src_ipv4_addr, dst_ipv4_addr;
  4847. u8 l4type = 0;
  4848. /* check if we're UDP or TCP */
  4849. if (iph->protocol == IPPROTO_TCP) {
  4850. th = tcp_hdr(skb);
  4851. src_port = th->source;
  4852. dst_port = th->dest;
  4853. l4type |= IXGBE_ATR_L4TYPE_TCP;
  4854. /* l4type IPv4 type is 0, no need to assign */
  4855. } else {
  4856. /* Unsupported L4 header, just bail here */
  4857. return;
  4858. }
  4859. memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
  4860. vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
  4861. IXGBE_TX_FLAGS_VLAN_SHIFT;
  4862. src_ipv4_addr = iph->saddr;
  4863. dst_ipv4_addr = iph->daddr;
  4864. flex_bytes = eth->h_proto;
  4865. ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
  4866. ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
  4867. ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
  4868. ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
  4869. ixgbe_atr_set_l4type_82599(&atr_input, l4type);
  4870. /* src and dst are inverted, think how the receiver sees them */
  4871. ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
  4872. ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
  4873. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  4874. ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
  4875. }
  4876. static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
  4877. struct ixgbe_ring *tx_ring, int size)
  4878. {
  4879. netif_stop_subqueue(netdev, tx_ring->queue_index);
  4880. /* Herbert's original patch had:
  4881. * smp_mb__after_netif_stop_queue();
  4882. * but since that doesn't exist yet, just open code it. */
  4883. smp_mb();
  4884. /* We need to check again in a case another CPU has just
  4885. * made room available. */
  4886. if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
  4887. return -EBUSY;
  4888. /* A reprieve! - use start_queue because it doesn't call schedule */
  4889. netif_start_subqueue(netdev, tx_ring->queue_index);
  4890. ++tx_ring->restart_queue;
  4891. return 0;
  4892. }
  4893. static int ixgbe_maybe_stop_tx(struct net_device *netdev,
  4894. struct ixgbe_ring *tx_ring, int size)
  4895. {
  4896. if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
  4897. return 0;
  4898. return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
  4899. }
  4900. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
  4901. {
  4902. struct ixgbe_adapter *adapter = netdev_priv(dev);
  4903. int txq = smp_processor_id();
  4904. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4905. while (unlikely(txq >= dev->real_num_tx_queues))
  4906. txq -= dev->real_num_tx_queues;
  4907. return txq;
  4908. }
  4909. #ifdef IXGBE_FCOE
  4910. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  4911. ((skb->protocol == htons(ETH_P_FCOE)) ||
  4912. (skb->protocol == htons(ETH_P_FIP)))) {
  4913. txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
  4914. txq += adapter->ring_feature[RING_F_FCOE].mask;
  4915. return txq;
  4916. }
  4917. #endif
  4918. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4919. if (skb->priority == TC_PRIO_CONTROL)
  4920. txq = adapter->ring_feature[RING_F_DCB].indices-1;
  4921. else
  4922. txq = (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK)
  4923. >> 13;
  4924. return txq;
  4925. }
  4926. return skb_tx_hash(dev, skb);
  4927. }
  4928. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  4929. struct net_device *netdev)
  4930. {
  4931. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4932. struct ixgbe_ring *tx_ring;
  4933. struct netdev_queue *txq;
  4934. unsigned int first;
  4935. unsigned int tx_flags = 0;
  4936. u8 hdr_len = 0;
  4937. int tso;
  4938. int count = 0;
  4939. unsigned int f;
  4940. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  4941. tx_flags |= vlan_tx_tag_get(skb);
  4942. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4943. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  4944. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  4945. }
  4946. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  4947. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  4948. } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4949. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  4950. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  4951. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  4952. }
  4953. tx_ring = adapter->tx_ring[skb->queue_mapping];
  4954. #ifdef IXGBE_FCOE
  4955. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  4956. #ifdef CONFIG_IXGBE_DCB
  4957. /* for FCoE with DCB, we force the priority to what
  4958. * was specified by the switch */
  4959. if ((skb->protocol == htons(ETH_P_FCOE)) ||
  4960. (skb->protocol == htons(ETH_P_FIP))) {
  4961. tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
  4962. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  4963. tx_flags |= ((adapter->fcoe.up << 13)
  4964. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  4965. }
  4966. #endif
  4967. /* flag for FCoE offloads */
  4968. if (skb->protocol == htons(ETH_P_FCOE))
  4969. tx_flags |= IXGBE_TX_FLAGS_FCOE;
  4970. }
  4971. #endif
  4972. /* four things can cause us to need a context descriptor */
  4973. if (skb_is_gso(skb) ||
  4974. (skb->ip_summed == CHECKSUM_PARTIAL) ||
  4975. (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
  4976. (tx_flags & IXGBE_TX_FLAGS_FCOE))
  4977. count++;
  4978. count += TXD_USE_COUNT(skb_headlen(skb));
  4979. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  4980. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  4981. if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
  4982. adapter->tx_busy++;
  4983. return NETDEV_TX_BUSY;
  4984. }
  4985. first = tx_ring->next_to_use;
  4986. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  4987. #ifdef IXGBE_FCOE
  4988. /* setup tx offload for FCoE */
  4989. tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  4990. if (tso < 0) {
  4991. dev_kfree_skb_any(skb);
  4992. return NETDEV_TX_OK;
  4993. }
  4994. if (tso)
  4995. tx_flags |= IXGBE_TX_FLAGS_FSO;
  4996. #endif /* IXGBE_FCOE */
  4997. } else {
  4998. if (skb->protocol == htons(ETH_P_IP))
  4999. tx_flags |= IXGBE_TX_FLAGS_IPV4;
  5000. tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  5001. if (tso < 0) {
  5002. dev_kfree_skb_any(skb);
  5003. return NETDEV_TX_OK;
  5004. }
  5005. if (tso)
  5006. tx_flags |= IXGBE_TX_FLAGS_TSO;
  5007. else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
  5008. (skb->ip_summed == CHECKSUM_PARTIAL))
  5009. tx_flags |= IXGBE_TX_FLAGS_CSUM;
  5010. }
  5011. count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
  5012. if (count) {
  5013. /* add the ATR filter if ATR is on */
  5014. if (tx_ring->atr_sample_rate) {
  5015. ++tx_ring->atr_count;
  5016. if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
  5017. test_bit(__IXGBE_FDIR_INIT_DONE,
  5018. &tx_ring->reinit_state)) {
  5019. ixgbe_atr(adapter, skb, tx_ring->queue_index,
  5020. tx_flags);
  5021. tx_ring->atr_count = 0;
  5022. }
  5023. }
  5024. txq = netdev_get_tx_queue(netdev, tx_ring->queue_index);
  5025. txq->tx_bytes += skb->len;
  5026. txq->tx_packets++;
  5027. ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
  5028. hdr_len);
  5029. ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
  5030. } else {
  5031. dev_kfree_skb_any(skb);
  5032. tx_ring->tx_buffer_info[first].time_stamp = 0;
  5033. tx_ring->next_to_use = first;
  5034. }
  5035. return NETDEV_TX_OK;
  5036. }
  5037. /**
  5038. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  5039. * @netdev: network interface device structure
  5040. * @p: pointer to an address structure
  5041. *
  5042. * Returns 0 on success, negative on failure
  5043. **/
  5044. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  5045. {
  5046. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5047. struct ixgbe_hw *hw = &adapter->hw;
  5048. struct sockaddr *addr = p;
  5049. if (!is_valid_ether_addr(addr->sa_data))
  5050. return -EADDRNOTAVAIL;
  5051. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  5052. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  5053. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
  5054. IXGBE_RAH_AV);
  5055. return 0;
  5056. }
  5057. static int
  5058. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  5059. {
  5060. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5061. struct ixgbe_hw *hw = &adapter->hw;
  5062. u16 value;
  5063. int rc;
  5064. if (prtad != hw->phy.mdio.prtad)
  5065. return -EINVAL;
  5066. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  5067. if (!rc)
  5068. rc = value;
  5069. return rc;
  5070. }
  5071. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  5072. u16 addr, u16 value)
  5073. {
  5074. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5075. struct ixgbe_hw *hw = &adapter->hw;
  5076. if (prtad != hw->phy.mdio.prtad)
  5077. return -EINVAL;
  5078. return hw->phy.ops.write_reg(hw, addr, devad, value);
  5079. }
  5080. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  5081. {
  5082. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5083. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  5084. }
  5085. /**
  5086. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  5087. * netdev->dev_addrs
  5088. * @netdev: network interface device structure
  5089. *
  5090. * Returns non-zero on failure
  5091. **/
  5092. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  5093. {
  5094. int err = 0;
  5095. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5096. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5097. if (is_valid_ether_addr(mac->san_addr)) {
  5098. rtnl_lock();
  5099. err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5100. rtnl_unlock();
  5101. }
  5102. return err;
  5103. }
  5104. /**
  5105. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  5106. * netdev->dev_addrs
  5107. * @netdev: network interface device structure
  5108. *
  5109. * Returns non-zero on failure
  5110. **/
  5111. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  5112. {
  5113. int err = 0;
  5114. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5115. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5116. if (is_valid_ether_addr(mac->san_addr)) {
  5117. rtnl_lock();
  5118. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5119. rtnl_unlock();
  5120. }
  5121. return err;
  5122. }
  5123. #ifdef CONFIG_NET_POLL_CONTROLLER
  5124. /*
  5125. * Polling 'interrupt' - used by things like netconsole to send skbs
  5126. * without having to re-enable interrupts. It's not called while
  5127. * the interrupt routine is executing.
  5128. */
  5129. static void ixgbe_netpoll(struct net_device *netdev)
  5130. {
  5131. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5132. int i;
  5133. /* if interface is down do nothing */
  5134. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5135. return;
  5136. adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
  5137. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  5138. int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  5139. for (i = 0; i < num_q_vectors; i++) {
  5140. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  5141. ixgbe_msix_clean_many(0, q_vector);
  5142. }
  5143. } else {
  5144. ixgbe_intr(adapter->pdev->irq, netdev);
  5145. }
  5146. adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
  5147. }
  5148. #endif
  5149. static const struct net_device_ops ixgbe_netdev_ops = {
  5150. .ndo_open = ixgbe_open,
  5151. .ndo_stop = ixgbe_close,
  5152. .ndo_start_xmit = ixgbe_xmit_frame,
  5153. .ndo_select_queue = ixgbe_select_queue,
  5154. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  5155. .ndo_set_multicast_list = ixgbe_set_rx_mode,
  5156. .ndo_validate_addr = eth_validate_addr,
  5157. .ndo_set_mac_address = ixgbe_set_mac,
  5158. .ndo_change_mtu = ixgbe_change_mtu,
  5159. .ndo_tx_timeout = ixgbe_tx_timeout,
  5160. .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
  5161. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  5162. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  5163. .ndo_do_ioctl = ixgbe_ioctl,
  5164. #ifdef CONFIG_NET_POLL_CONTROLLER
  5165. .ndo_poll_controller = ixgbe_netpoll,
  5166. #endif
  5167. #ifdef IXGBE_FCOE
  5168. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  5169. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  5170. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  5171. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  5172. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  5173. #endif /* IXGBE_FCOE */
  5174. };
  5175. static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
  5176. const struct ixgbe_info *ii)
  5177. {
  5178. #ifdef CONFIG_PCI_IOV
  5179. struct ixgbe_hw *hw = &adapter->hw;
  5180. int err;
  5181. if (hw->mac.type != ixgbe_mac_82599EB || !max_vfs)
  5182. return;
  5183. /* The 82599 supports up to 64 VFs per physical function
  5184. * but this implementation limits allocation to 63 so that
  5185. * basic networking resources are still available to the
  5186. * physical function
  5187. */
  5188. adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
  5189. adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
  5190. err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
  5191. if (err) {
  5192. DPRINTK(PROBE, ERR,
  5193. "Failed to enable PCI sriov: %d\n", err);
  5194. goto err_novfs;
  5195. }
  5196. /* If call to enable VFs succeeded then allocate memory
  5197. * for per VF control structures.
  5198. */
  5199. adapter->vfinfo =
  5200. kcalloc(adapter->num_vfs,
  5201. sizeof(struct vf_data_storage), GFP_KERNEL);
  5202. if (adapter->vfinfo) {
  5203. /* Now that we're sure SR-IOV is enabled
  5204. * and memory allocated set up the mailbox parameters
  5205. */
  5206. ixgbe_init_mbx_params_pf(hw);
  5207. memcpy(&hw->mbx.ops, ii->mbx_ops,
  5208. sizeof(hw->mbx.ops));
  5209. /* Disable RSC when in SR-IOV mode */
  5210. adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
  5211. IXGBE_FLAG2_RSC_ENABLED);
  5212. return;
  5213. }
  5214. /* Oh oh */
  5215. DPRINTK(PROBE, ERR,
  5216. "Unable to allocate memory for VF "
  5217. "Data Storage - SRIOV disabled\n");
  5218. pci_disable_sriov(adapter->pdev);
  5219. err_novfs:
  5220. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  5221. adapter->num_vfs = 0;
  5222. #endif /* CONFIG_PCI_IOV */
  5223. }
  5224. /**
  5225. * ixgbe_probe - Device Initialization Routine
  5226. * @pdev: PCI device information struct
  5227. * @ent: entry in ixgbe_pci_tbl
  5228. *
  5229. * Returns 0 on success, negative on failure
  5230. *
  5231. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  5232. * The OS initialization, configuring of the adapter private structure,
  5233. * and a hardware reset occur.
  5234. **/
  5235. static int __devinit ixgbe_probe(struct pci_dev *pdev,
  5236. const struct pci_device_id *ent)
  5237. {
  5238. struct net_device *netdev;
  5239. struct ixgbe_adapter *adapter = NULL;
  5240. struct ixgbe_hw *hw;
  5241. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  5242. static int cards_found;
  5243. int i, err, pci_using_dac;
  5244. unsigned int indices = num_possible_cpus();
  5245. #ifdef IXGBE_FCOE
  5246. u16 device_caps;
  5247. #endif
  5248. u32 part_num, eec;
  5249. err = pci_enable_device_mem(pdev);
  5250. if (err)
  5251. return err;
  5252. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
  5253. !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
  5254. pci_using_dac = 1;
  5255. } else {
  5256. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  5257. if (err) {
  5258. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  5259. if (err) {
  5260. dev_err(&pdev->dev, "No usable DMA "
  5261. "configuration, aborting\n");
  5262. goto err_dma;
  5263. }
  5264. }
  5265. pci_using_dac = 0;
  5266. }
  5267. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  5268. IORESOURCE_MEM), ixgbe_driver_name);
  5269. if (err) {
  5270. dev_err(&pdev->dev,
  5271. "pci_request_selected_regions failed 0x%x\n", err);
  5272. goto err_pci_reg;
  5273. }
  5274. pci_enable_pcie_error_reporting(pdev);
  5275. pci_set_master(pdev);
  5276. pci_save_state(pdev);
  5277. if (ii->mac == ixgbe_mac_82598EB)
  5278. indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
  5279. else
  5280. indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
  5281. indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
  5282. #ifdef IXGBE_FCOE
  5283. indices += min_t(unsigned int, num_possible_cpus(),
  5284. IXGBE_MAX_FCOE_INDICES);
  5285. #endif
  5286. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  5287. if (!netdev) {
  5288. err = -ENOMEM;
  5289. goto err_alloc_etherdev;
  5290. }
  5291. SET_NETDEV_DEV(netdev, &pdev->dev);
  5292. pci_set_drvdata(pdev, netdev);
  5293. adapter = netdev_priv(netdev);
  5294. adapter->netdev = netdev;
  5295. adapter->pdev = pdev;
  5296. hw = &adapter->hw;
  5297. hw->back = adapter;
  5298. adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  5299. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  5300. pci_resource_len(pdev, 0));
  5301. if (!hw->hw_addr) {
  5302. err = -EIO;
  5303. goto err_ioremap;
  5304. }
  5305. for (i = 1; i <= 5; i++) {
  5306. if (pci_resource_len(pdev, i) == 0)
  5307. continue;
  5308. }
  5309. netdev->netdev_ops = &ixgbe_netdev_ops;
  5310. ixgbe_set_ethtool_ops(netdev);
  5311. netdev->watchdog_timeo = 5 * HZ;
  5312. strcpy(netdev->name, pci_name(pdev));
  5313. adapter->bd_number = cards_found;
  5314. /* Setup hw api */
  5315. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  5316. hw->mac.type = ii->mac;
  5317. /* EEPROM */
  5318. memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
  5319. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  5320. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  5321. if (!(eec & (1 << 8)))
  5322. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  5323. /* PHY */
  5324. memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
  5325. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  5326. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  5327. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  5328. hw->phy.mdio.mmds = 0;
  5329. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  5330. hw->phy.mdio.dev = netdev;
  5331. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  5332. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  5333. /* set up this timer and work struct before calling get_invariants
  5334. * which might start the timer
  5335. */
  5336. init_timer(&adapter->sfp_timer);
  5337. adapter->sfp_timer.function = &ixgbe_sfp_timer;
  5338. adapter->sfp_timer.data = (unsigned long) adapter;
  5339. INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
  5340. /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
  5341. INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
  5342. /* a new SFP+ module arrival, called from GPI SDP2 context */
  5343. INIT_WORK(&adapter->sfp_config_module_task,
  5344. ixgbe_sfp_config_module_task);
  5345. ii->get_invariants(hw);
  5346. /* setup the private structure */
  5347. err = ixgbe_sw_init(adapter);
  5348. if (err)
  5349. goto err_sw_init;
  5350. /* Make it possible the adapter to be woken up via WOL */
  5351. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5352. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5353. /*
  5354. * If there is a fan on this device and it has failed log the
  5355. * failure.
  5356. */
  5357. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  5358. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  5359. if (esdp & IXGBE_ESDP_SDP1)
  5360. DPRINTK(PROBE, CRIT,
  5361. "Fan has stopped, replace the adapter\n");
  5362. }
  5363. /* reset_hw fills in the perm_addr as well */
  5364. err = hw->mac.ops.reset_hw(hw);
  5365. if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
  5366. hw->mac.type == ixgbe_mac_82598EB) {
  5367. /*
  5368. * Start a kernel thread to watch for a module to arrive.
  5369. * Only do this for 82598, since 82599 will generate
  5370. * interrupts on module arrival.
  5371. */
  5372. set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5373. mod_timer(&adapter->sfp_timer,
  5374. round_jiffies(jiffies + (2 * HZ)));
  5375. err = 0;
  5376. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  5377. dev_err(&adapter->pdev->dev, "failed to initialize because "
  5378. "an unsupported SFP+ module type was detected.\n"
  5379. "Reload the driver after installing a supported "
  5380. "module.\n");
  5381. goto err_sw_init;
  5382. } else if (err) {
  5383. dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
  5384. goto err_sw_init;
  5385. }
  5386. ixgbe_probe_vf(adapter, ii);
  5387. netdev->features = NETIF_F_SG |
  5388. NETIF_F_IP_CSUM |
  5389. NETIF_F_HW_VLAN_TX |
  5390. NETIF_F_HW_VLAN_RX |
  5391. NETIF_F_HW_VLAN_FILTER;
  5392. netdev->features |= NETIF_F_IPV6_CSUM;
  5393. netdev->features |= NETIF_F_TSO;
  5394. netdev->features |= NETIF_F_TSO6;
  5395. netdev->features |= NETIF_F_GRO;
  5396. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5397. netdev->features |= NETIF_F_SCTP_CSUM;
  5398. netdev->vlan_features |= NETIF_F_TSO;
  5399. netdev->vlan_features |= NETIF_F_TSO6;
  5400. netdev->vlan_features |= NETIF_F_IP_CSUM;
  5401. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  5402. netdev->vlan_features |= NETIF_F_SG;
  5403. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  5404. adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
  5405. IXGBE_FLAG_DCB_ENABLED);
  5406. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  5407. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  5408. #ifdef CONFIG_IXGBE_DCB
  5409. netdev->dcbnl_ops = &dcbnl_ops;
  5410. #endif
  5411. #ifdef IXGBE_FCOE
  5412. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  5413. if (hw->mac.ops.get_device_caps) {
  5414. hw->mac.ops.get_device_caps(hw, &device_caps);
  5415. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  5416. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5417. }
  5418. }
  5419. #endif /* IXGBE_FCOE */
  5420. if (pci_using_dac)
  5421. netdev->features |= NETIF_F_HIGHDMA;
  5422. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  5423. netdev->features |= NETIF_F_LRO;
  5424. /* make sure the EEPROM is good */
  5425. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  5426. dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
  5427. err = -EIO;
  5428. goto err_eeprom;
  5429. }
  5430. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  5431. memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
  5432. if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
  5433. dev_err(&pdev->dev, "invalid MAC address\n");
  5434. err = -EIO;
  5435. goto err_eeprom;
  5436. }
  5437. /* power down the optics */
  5438. if (hw->phy.multispeed_fiber)
  5439. hw->mac.ops.disable_tx_laser(hw);
  5440. init_timer(&adapter->watchdog_timer);
  5441. adapter->watchdog_timer.function = &ixgbe_watchdog;
  5442. adapter->watchdog_timer.data = (unsigned long)adapter;
  5443. INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
  5444. INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
  5445. err = ixgbe_init_interrupt_scheme(adapter);
  5446. if (err)
  5447. goto err_sw_init;
  5448. switch (pdev->device) {
  5449. case IXGBE_DEV_ID_82599_KX4:
  5450. adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
  5451. IXGBE_WUFC_MC | IXGBE_WUFC_BC);
  5452. break;
  5453. default:
  5454. adapter->wol = 0;
  5455. break;
  5456. }
  5457. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  5458. /* pick up the PCI bus settings for reporting later */
  5459. hw->mac.ops.get_bus_info(hw);
  5460. /* print bus type/speed/width info */
  5461. dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
  5462. ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
  5463. (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
  5464. ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
  5465. (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
  5466. (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
  5467. "Unknown"),
  5468. netdev->dev_addr);
  5469. ixgbe_read_pba_num_generic(hw, &part_num);
  5470. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  5471. dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
  5472. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  5473. (part_num >> 8), (part_num & 0xff));
  5474. else
  5475. dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
  5476. hw->mac.type, hw->phy.type,
  5477. (part_num >> 8), (part_num & 0xff));
  5478. if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
  5479. dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
  5480. "this card is not sufficient for optimal "
  5481. "performance.\n");
  5482. dev_warn(&pdev->dev, "For optimal performance a x8 "
  5483. "PCI-Express slot is required.\n");
  5484. }
  5485. /* save off EEPROM version number */
  5486. hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
  5487. /* reset the hardware with the new settings */
  5488. err = hw->mac.ops.start_hw(hw);
  5489. if (err == IXGBE_ERR_EEPROM_VERSION) {
  5490. /* We are running on a pre-production device, log a warning */
  5491. dev_warn(&pdev->dev, "This device is a pre-production "
  5492. "adapter/LOM. Please be aware there may be issues "
  5493. "associated with your hardware. If you are "
  5494. "experiencing problems please contact your Intel or "
  5495. "hardware representative who provided you with this "
  5496. "hardware.\n");
  5497. }
  5498. strcpy(netdev->name, "eth%d");
  5499. err = register_netdev(netdev);
  5500. if (err)
  5501. goto err_register;
  5502. /* carrier off reporting is important to ethtool even BEFORE open */
  5503. netif_carrier_off(netdev);
  5504. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  5505. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  5506. INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
  5507. #ifdef CONFIG_IXGBE_DCA
  5508. if (dca_add_requester(&pdev->dev) == 0) {
  5509. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  5510. ixgbe_setup_dca(adapter);
  5511. }
  5512. #endif
  5513. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  5514. DPRINTK(PROBE, INFO, "IOV is enabled with %d VFs\n",
  5515. adapter->num_vfs);
  5516. for (i = 0; i < adapter->num_vfs; i++)
  5517. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  5518. }
  5519. /* add san mac addr to netdev */
  5520. ixgbe_add_sanmac_netdev(netdev);
  5521. dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
  5522. cards_found++;
  5523. return 0;
  5524. err_register:
  5525. ixgbe_release_hw_control(adapter);
  5526. ixgbe_clear_interrupt_scheme(adapter);
  5527. err_sw_init:
  5528. err_eeprom:
  5529. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  5530. ixgbe_disable_sriov(adapter);
  5531. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5532. del_timer_sync(&adapter->sfp_timer);
  5533. cancel_work_sync(&adapter->sfp_task);
  5534. cancel_work_sync(&adapter->multispeed_fiber_task);
  5535. cancel_work_sync(&adapter->sfp_config_module_task);
  5536. iounmap(hw->hw_addr);
  5537. err_ioremap:
  5538. free_netdev(netdev);
  5539. err_alloc_etherdev:
  5540. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  5541. IORESOURCE_MEM));
  5542. err_pci_reg:
  5543. err_dma:
  5544. pci_disable_device(pdev);
  5545. return err;
  5546. }
  5547. /**
  5548. * ixgbe_remove - Device Removal Routine
  5549. * @pdev: PCI device information struct
  5550. *
  5551. * ixgbe_remove is called by the PCI subsystem to alert the driver
  5552. * that it should release a PCI device. The could be caused by a
  5553. * Hot-Plug event, or because the driver is going to be removed from
  5554. * memory.
  5555. **/
  5556. static void __devexit ixgbe_remove(struct pci_dev *pdev)
  5557. {
  5558. struct net_device *netdev = pci_get_drvdata(pdev);
  5559. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5560. set_bit(__IXGBE_DOWN, &adapter->state);
  5561. /* clear the module not found bit to make sure the worker won't
  5562. * reschedule
  5563. */
  5564. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5565. del_timer_sync(&adapter->watchdog_timer);
  5566. del_timer_sync(&adapter->sfp_timer);
  5567. cancel_work_sync(&adapter->watchdog_task);
  5568. cancel_work_sync(&adapter->sfp_task);
  5569. cancel_work_sync(&adapter->multispeed_fiber_task);
  5570. cancel_work_sync(&adapter->sfp_config_module_task);
  5571. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  5572. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  5573. cancel_work_sync(&adapter->fdir_reinit_task);
  5574. flush_scheduled_work();
  5575. #ifdef CONFIG_IXGBE_DCA
  5576. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  5577. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  5578. dca_remove_requester(&pdev->dev);
  5579. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  5580. }
  5581. #endif
  5582. #ifdef IXGBE_FCOE
  5583. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  5584. ixgbe_cleanup_fcoe(adapter);
  5585. #endif /* IXGBE_FCOE */
  5586. /* remove the added san mac */
  5587. ixgbe_del_sanmac_netdev(netdev);
  5588. if (netdev->reg_state == NETREG_REGISTERED)
  5589. unregister_netdev(netdev);
  5590. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  5591. ixgbe_disable_sriov(adapter);
  5592. ixgbe_clear_interrupt_scheme(adapter);
  5593. ixgbe_release_hw_control(adapter);
  5594. iounmap(adapter->hw.hw_addr);
  5595. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  5596. IORESOURCE_MEM));
  5597. DPRINTK(PROBE, INFO, "complete\n");
  5598. free_netdev(netdev);
  5599. pci_disable_pcie_error_reporting(pdev);
  5600. pci_disable_device(pdev);
  5601. }
  5602. /**
  5603. * ixgbe_io_error_detected - called when PCI error is detected
  5604. * @pdev: Pointer to PCI device
  5605. * @state: The current pci connection state
  5606. *
  5607. * This function is called after a PCI bus error affecting
  5608. * this device has been detected.
  5609. */
  5610. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  5611. pci_channel_state_t state)
  5612. {
  5613. struct net_device *netdev = pci_get_drvdata(pdev);
  5614. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5615. netif_device_detach(netdev);
  5616. if (state == pci_channel_io_perm_failure)
  5617. return PCI_ERS_RESULT_DISCONNECT;
  5618. if (netif_running(netdev))
  5619. ixgbe_down(adapter);
  5620. pci_disable_device(pdev);
  5621. /* Request a slot reset. */
  5622. return PCI_ERS_RESULT_NEED_RESET;
  5623. }
  5624. /**
  5625. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  5626. * @pdev: Pointer to PCI device
  5627. *
  5628. * Restart the card from scratch, as if from a cold-boot.
  5629. */
  5630. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  5631. {
  5632. struct net_device *netdev = pci_get_drvdata(pdev);
  5633. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5634. pci_ers_result_t result;
  5635. int err;
  5636. if (pci_enable_device_mem(pdev)) {
  5637. DPRINTK(PROBE, ERR,
  5638. "Cannot re-enable PCI device after reset.\n");
  5639. result = PCI_ERS_RESULT_DISCONNECT;
  5640. } else {
  5641. pci_set_master(pdev);
  5642. pci_restore_state(pdev);
  5643. pci_save_state(pdev);
  5644. pci_wake_from_d3(pdev, false);
  5645. ixgbe_reset(adapter);
  5646. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5647. result = PCI_ERS_RESULT_RECOVERED;
  5648. }
  5649. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  5650. if (err) {
  5651. dev_err(&pdev->dev,
  5652. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
  5653. /* non-fatal, continue */
  5654. }
  5655. return result;
  5656. }
  5657. /**
  5658. * ixgbe_io_resume - called when traffic can start flowing again.
  5659. * @pdev: Pointer to PCI device
  5660. *
  5661. * This callback is called when the error recovery driver tells us that
  5662. * its OK to resume normal operation.
  5663. */
  5664. static void ixgbe_io_resume(struct pci_dev *pdev)
  5665. {
  5666. struct net_device *netdev = pci_get_drvdata(pdev);
  5667. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5668. if (netif_running(netdev)) {
  5669. if (ixgbe_up(adapter)) {
  5670. DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
  5671. return;
  5672. }
  5673. }
  5674. netif_device_attach(netdev);
  5675. }
  5676. static struct pci_error_handlers ixgbe_err_handler = {
  5677. .error_detected = ixgbe_io_error_detected,
  5678. .slot_reset = ixgbe_io_slot_reset,
  5679. .resume = ixgbe_io_resume,
  5680. };
  5681. static struct pci_driver ixgbe_driver = {
  5682. .name = ixgbe_driver_name,
  5683. .id_table = ixgbe_pci_tbl,
  5684. .probe = ixgbe_probe,
  5685. .remove = __devexit_p(ixgbe_remove),
  5686. #ifdef CONFIG_PM
  5687. .suspend = ixgbe_suspend,
  5688. .resume = ixgbe_resume,
  5689. #endif
  5690. .shutdown = ixgbe_shutdown,
  5691. .err_handler = &ixgbe_err_handler
  5692. };
  5693. /**
  5694. * ixgbe_init_module - Driver Registration Routine
  5695. *
  5696. * ixgbe_init_module is the first routine called when the driver is
  5697. * loaded. All it does is register with the PCI subsystem.
  5698. **/
  5699. static int __init ixgbe_init_module(void)
  5700. {
  5701. int ret;
  5702. printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
  5703. ixgbe_driver_string, ixgbe_driver_version);
  5704. printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
  5705. #ifdef CONFIG_IXGBE_DCA
  5706. dca_register_notify(&dca_notifier);
  5707. #endif
  5708. ret = pci_register_driver(&ixgbe_driver);
  5709. return ret;
  5710. }
  5711. module_init(ixgbe_init_module);
  5712. /**
  5713. * ixgbe_exit_module - Driver Exit Cleanup Routine
  5714. *
  5715. * ixgbe_exit_module is called just before the driver is removed
  5716. * from memory.
  5717. **/
  5718. static void __exit ixgbe_exit_module(void)
  5719. {
  5720. #ifdef CONFIG_IXGBE_DCA
  5721. dca_unregister_notify(&dca_notifier);
  5722. #endif
  5723. pci_unregister_driver(&ixgbe_driver);
  5724. }
  5725. #ifdef CONFIG_IXGBE_DCA
  5726. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  5727. void *p)
  5728. {
  5729. int ret_val;
  5730. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  5731. __ixgbe_notify_dca);
  5732. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  5733. }
  5734. #endif /* CONFIG_IXGBE_DCA */
  5735. #ifdef DEBUG
  5736. /**
  5737. * ixgbe_get_hw_dev_name - return device name string
  5738. * used by hardware layer to print debugging information
  5739. **/
  5740. char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
  5741. {
  5742. struct ixgbe_adapter *adapter = hw->back;
  5743. return adapter->netdev->name;
  5744. }
  5745. #endif
  5746. module_exit(ixgbe_exit_module);
  5747. /* ixgbe_main.c */