ixgbe_main.c 224 KB

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