ixgbe_main.c 185 KB

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