ixgbe_main.c 205 KB

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