ixgbe_main.c 217 KB

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