ixgbe_main.c 217 KB

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