igb_main.c 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/module.h>
  22. #include <linux/types.h>
  23. #include <linux/init.h>
  24. #include <linux/bitops.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/pagemap.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/ipv6.h>
  29. #include <linux/slab.h>
  30. #include <net/checksum.h>
  31. #include <net/ip6_checksum.h>
  32. #include <linux/net_tstamp.h>
  33. #include <linux/mii.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if.h>
  36. #include <linux/if_vlan.h>
  37. #include <linux/pci.h>
  38. #include <linux/pci-aspm.h>
  39. #include <linux/delay.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/ip.h>
  42. #include <linux/tcp.h>
  43. #include <linux/sctp.h>
  44. #include <linux/if_ether.h>
  45. #include <linux/aer.h>
  46. #include <linux/prefetch.h>
  47. #include <linux/pm_runtime.h>
  48. #ifdef CONFIG_IGB_DCA
  49. #include <linux/dca.h>
  50. #endif
  51. #include "igb.h"
  52. #define MAJ 3
  53. #define MIN 2
  54. #define BUILD 10
  55. #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
  56. __stringify(BUILD) "-k"
  57. char igb_driver_name[] = "igb";
  58. char igb_driver_version[] = DRV_VERSION;
  59. static const char igb_driver_string[] =
  60. "Intel(R) Gigabit Ethernet Network Driver";
  61. static const char igb_copyright[] = "Copyright (c) 2007-2012 Intel Corporation.";
  62. static const struct e1000_info *igb_info_tbl[] = {
  63. [board_82575] = &e1000_82575_info,
  64. };
  65. static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = {
  66. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
  67. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
  68. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
  69. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
  70. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
  71. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
  72. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
  73. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
  74. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
  75. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
  76. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
  77. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
  78. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
  79. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
  80. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
  81. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
  82. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
  83. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
  84. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
  85. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
  86. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
  87. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
  88. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
  89. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
  90. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
  91. /* required last entry */
  92. {0, }
  93. };
  94. MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
  95. void igb_reset(struct igb_adapter *);
  96. static int igb_setup_all_tx_resources(struct igb_adapter *);
  97. static int igb_setup_all_rx_resources(struct igb_adapter *);
  98. static void igb_free_all_tx_resources(struct igb_adapter *);
  99. static void igb_free_all_rx_resources(struct igb_adapter *);
  100. static void igb_setup_mrqc(struct igb_adapter *);
  101. static int igb_probe(struct pci_dev *, const struct pci_device_id *);
  102. static void __devexit igb_remove(struct pci_dev *pdev);
  103. static void igb_init_hw_timer(struct igb_adapter *adapter);
  104. static int igb_sw_init(struct igb_adapter *);
  105. static int igb_open(struct net_device *);
  106. static int igb_close(struct net_device *);
  107. static void igb_configure_tx(struct igb_adapter *);
  108. static void igb_configure_rx(struct igb_adapter *);
  109. static void igb_clean_all_tx_rings(struct igb_adapter *);
  110. static void igb_clean_all_rx_rings(struct igb_adapter *);
  111. static void igb_clean_tx_ring(struct igb_ring *);
  112. static void igb_clean_rx_ring(struct igb_ring *);
  113. static void igb_set_rx_mode(struct net_device *);
  114. static void igb_update_phy_info(unsigned long);
  115. static void igb_watchdog(unsigned long);
  116. static void igb_watchdog_task(struct work_struct *);
  117. static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *);
  118. static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev,
  119. struct rtnl_link_stats64 *stats);
  120. static int igb_change_mtu(struct net_device *, int);
  121. static int igb_set_mac(struct net_device *, void *);
  122. static void igb_set_uta(struct igb_adapter *adapter);
  123. static irqreturn_t igb_intr(int irq, void *);
  124. static irqreturn_t igb_intr_msi(int irq, void *);
  125. static irqreturn_t igb_msix_other(int irq, void *);
  126. static irqreturn_t igb_msix_ring(int irq, void *);
  127. #ifdef CONFIG_IGB_DCA
  128. static void igb_update_dca(struct igb_q_vector *);
  129. static void igb_setup_dca(struct igb_adapter *);
  130. #endif /* CONFIG_IGB_DCA */
  131. static int igb_poll(struct napi_struct *, int);
  132. static bool igb_clean_tx_irq(struct igb_q_vector *);
  133. static bool igb_clean_rx_irq(struct igb_q_vector *, int);
  134. static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
  135. static void igb_tx_timeout(struct net_device *);
  136. static void igb_reset_task(struct work_struct *);
  137. static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features);
  138. static int igb_vlan_rx_add_vid(struct net_device *, u16);
  139. static int igb_vlan_rx_kill_vid(struct net_device *, u16);
  140. static void igb_restore_vlan(struct igb_adapter *);
  141. static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
  142. static void igb_ping_all_vfs(struct igb_adapter *);
  143. static void igb_msg_task(struct igb_adapter *);
  144. static void igb_vmm_control(struct igb_adapter *);
  145. static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
  146. static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
  147. static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
  148. static int igb_ndo_set_vf_vlan(struct net_device *netdev,
  149. int vf, u16 vlan, u8 qos);
  150. static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
  151. static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
  152. struct ifla_vf_info *ivi);
  153. static void igb_check_vf_rate_limit(struct igb_adapter *);
  154. #ifdef CONFIG_PCI_IOV
  155. static int igb_vf_configure(struct igb_adapter *adapter, int vf);
  156. static int igb_find_enabled_vfs(struct igb_adapter *adapter);
  157. static int igb_check_vf_assignment(struct igb_adapter *adapter);
  158. #endif
  159. #ifdef CONFIG_PM
  160. static int igb_suspend(struct device *);
  161. static int igb_resume(struct device *);
  162. #ifdef CONFIG_PM_RUNTIME
  163. static int igb_runtime_suspend(struct device *dev);
  164. static int igb_runtime_resume(struct device *dev);
  165. static int igb_runtime_idle(struct device *dev);
  166. #endif
  167. static const struct dev_pm_ops igb_pm_ops = {
  168. SET_SYSTEM_SLEEP_PM_OPS(igb_suspend, igb_resume)
  169. SET_RUNTIME_PM_OPS(igb_runtime_suspend, igb_runtime_resume,
  170. igb_runtime_idle)
  171. };
  172. #endif
  173. static void igb_shutdown(struct pci_dev *);
  174. #ifdef CONFIG_IGB_DCA
  175. static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
  176. static struct notifier_block dca_notifier = {
  177. .notifier_call = igb_notify_dca,
  178. .next = NULL,
  179. .priority = 0
  180. };
  181. #endif
  182. #ifdef CONFIG_NET_POLL_CONTROLLER
  183. /* for netdump / net console */
  184. static void igb_netpoll(struct net_device *);
  185. #endif
  186. #ifdef CONFIG_PCI_IOV
  187. static unsigned int max_vfs = 0;
  188. module_param(max_vfs, uint, 0);
  189. MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
  190. "per physical function");
  191. #endif /* CONFIG_PCI_IOV */
  192. static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
  193. pci_channel_state_t);
  194. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
  195. static void igb_io_resume(struct pci_dev *);
  196. static struct pci_error_handlers igb_err_handler = {
  197. .error_detected = igb_io_error_detected,
  198. .slot_reset = igb_io_slot_reset,
  199. .resume = igb_io_resume,
  200. };
  201. static void igb_init_dmac(struct igb_adapter *adapter, u32 pba);
  202. static struct pci_driver igb_driver = {
  203. .name = igb_driver_name,
  204. .id_table = igb_pci_tbl,
  205. .probe = igb_probe,
  206. .remove = __devexit_p(igb_remove),
  207. #ifdef CONFIG_PM
  208. .driver.pm = &igb_pm_ops,
  209. #endif
  210. .shutdown = igb_shutdown,
  211. .err_handler = &igb_err_handler
  212. };
  213. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  214. MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
  215. MODULE_LICENSE("GPL");
  216. MODULE_VERSION(DRV_VERSION);
  217. struct igb_reg_info {
  218. u32 ofs;
  219. char *name;
  220. };
  221. static const struct igb_reg_info igb_reg_info_tbl[] = {
  222. /* General Registers */
  223. {E1000_CTRL, "CTRL"},
  224. {E1000_STATUS, "STATUS"},
  225. {E1000_CTRL_EXT, "CTRL_EXT"},
  226. /* Interrupt Registers */
  227. {E1000_ICR, "ICR"},
  228. /* RX Registers */
  229. {E1000_RCTL, "RCTL"},
  230. {E1000_RDLEN(0), "RDLEN"},
  231. {E1000_RDH(0), "RDH"},
  232. {E1000_RDT(0), "RDT"},
  233. {E1000_RXDCTL(0), "RXDCTL"},
  234. {E1000_RDBAL(0), "RDBAL"},
  235. {E1000_RDBAH(0), "RDBAH"},
  236. /* TX Registers */
  237. {E1000_TCTL, "TCTL"},
  238. {E1000_TDBAL(0), "TDBAL"},
  239. {E1000_TDBAH(0), "TDBAH"},
  240. {E1000_TDLEN(0), "TDLEN"},
  241. {E1000_TDH(0), "TDH"},
  242. {E1000_TDT(0), "TDT"},
  243. {E1000_TXDCTL(0), "TXDCTL"},
  244. {E1000_TDFH, "TDFH"},
  245. {E1000_TDFT, "TDFT"},
  246. {E1000_TDFHS, "TDFHS"},
  247. {E1000_TDFPC, "TDFPC"},
  248. /* List Terminator */
  249. {}
  250. };
  251. /*
  252. * igb_regdump - register printout routine
  253. */
  254. static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
  255. {
  256. int n = 0;
  257. char rname[16];
  258. u32 regs[8];
  259. switch (reginfo->ofs) {
  260. case E1000_RDLEN(0):
  261. for (n = 0; n < 4; n++)
  262. regs[n] = rd32(E1000_RDLEN(n));
  263. break;
  264. case E1000_RDH(0):
  265. for (n = 0; n < 4; n++)
  266. regs[n] = rd32(E1000_RDH(n));
  267. break;
  268. case E1000_RDT(0):
  269. for (n = 0; n < 4; n++)
  270. regs[n] = rd32(E1000_RDT(n));
  271. break;
  272. case E1000_RXDCTL(0):
  273. for (n = 0; n < 4; n++)
  274. regs[n] = rd32(E1000_RXDCTL(n));
  275. break;
  276. case E1000_RDBAL(0):
  277. for (n = 0; n < 4; n++)
  278. regs[n] = rd32(E1000_RDBAL(n));
  279. break;
  280. case E1000_RDBAH(0):
  281. for (n = 0; n < 4; n++)
  282. regs[n] = rd32(E1000_RDBAH(n));
  283. break;
  284. case E1000_TDBAL(0):
  285. for (n = 0; n < 4; n++)
  286. regs[n] = rd32(E1000_RDBAL(n));
  287. break;
  288. case E1000_TDBAH(0):
  289. for (n = 0; n < 4; n++)
  290. regs[n] = rd32(E1000_TDBAH(n));
  291. break;
  292. case E1000_TDLEN(0):
  293. for (n = 0; n < 4; n++)
  294. regs[n] = rd32(E1000_TDLEN(n));
  295. break;
  296. case E1000_TDH(0):
  297. for (n = 0; n < 4; n++)
  298. regs[n] = rd32(E1000_TDH(n));
  299. break;
  300. case E1000_TDT(0):
  301. for (n = 0; n < 4; n++)
  302. regs[n] = rd32(E1000_TDT(n));
  303. break;
  304. case E1000_TXDCTL(0):
  305. for (n = 0; n < 4; n++)
  306. regs[n] = rd32(E1000_TXDCTL(n));
  307. break;
  308. default:
  309. pr_info("%-15s %08x\n", reginfo->name, rd32(reginfo->ofs));
  310. return;
  311. }
  312. snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
  313. pr_info("%-15s %08x %08x %08x %08x\n", rname, regs[0], regs[1],
  314. regs[2], regs[3]);
  315. }
  316. /*
  317. * igb_dump - Print registers, tx-rings and rx-rings
  318. */
  319. static void igb_dump(struct igb_adapter *adapter)
  320. {
  321. struct net_device *netdev = adapter->netdev;
  322. struct e1000_hw *hw = &adapter->hw;
  323. struct igb_reg_info *reginfo;
  324. struct igb_ring *tx_ring;
  325. union e1000_adv_tx_desc *tx_desc;
  326. struct my_u0 { u64 a; u64 b; } *u0;
  327. struct igb_ring *rx_ring;
  328. union e1000_adv_rx_desc *rx_desc;
  329. u32 staterr;
  330. u16 i, n;
  331. if (!netif_msg_hw(adapter))
  332. return;
  333. /* Print netdevice Info */
  334. if (netdev) {
  335. dev_info(&adapter->pdev->dev, "Net device Info\n");
  336. pr_info("Device Name state trans_start "
  337. "last_rx\n");
  338. pr_info("%-15s %016lX %016lX %016lX\n", netdev->name,
  339. netdev->state, netdev->trans_start, netdev->last_rx);
  340. }
  341. /* Print Registers */
  342. dev_info(&adapter->pdev->dev, "Register Dump\n");
  343. pr_info(" Register Name Value\n");
  344. for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
  345. reginfo->name; reginfo++) {
  346. igb_regdump(hw, reginfo);
  347. }
  348. /* Print TX Ring Summary */
  349. if (!netdev || !netif_running(netdev))
  350. goto exit;
  351. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  352. pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
  353. for (n = 0; n < adapter->num_tx_queues; n++) {
  354. struct igb_tx_buffer *buffer_info;
  355. tx_ring = adapter->tx_ring[n];
  356. buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  357. pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
  358. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  359. (u64)buffer_info->dma,
  360. buffer_info->length,
  361. buffer_info->next_to_watch,
  362. (u64)buffer_info->time_stamp);
  363. }
  364. /* Print TX Rings */
  365. if (!netif_msg_tx_done(adapter))
  366. goto rx_ring_summary;
  367. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  368. /* Transmit Descriptor Formats
  369. *
  370. * Advanced Transmit Descriptor
  371. * +--------------------------------------------------------------+
  372. * 0 | Buffer Address [63:0] |
  373. * +--------------------------------------------------------------+
  374. * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
  375. * +--------------------------------------------------------------+
  376. * 63 46 45 40 39 38 36 35 32 31 24 15 0
  377. */
  378. for (n = 0; n < adapter->num_tx_queues; n++) {
  379. tx_ring = adapter->tx_ring[n];
  380. pr_info("------------------------------------\n");
  381. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  382. pr_info("------------------------------------\n");
  383. pr_info("T [desc] [address 63:0 ] [PlPOCIStDDM Ln] "
  384. "[bi->dma ] leng ntw timestamp "
  385. "bi->skb\n");
  386. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  387. const char *next_desc;
  388. struct igb_tx_buffer *buffer_info;
  389. tx_desc = IGB_TX_DESC(tx_ring, i);
  390. buffer_info = &tx_ring->tx_buffer_info[i];
  391. u0 = (struct my_u0 *)tx_desc;
  392. if (i == tx_ring->next_to_use &&
  393. i == tx_ring->next_to_clean)
  394. next_desc = " NTC/U";
  395. else if (i == tx_ring->next_to_use)
  396. next_desc = " NTU";
  397. else if (i == tx_ring->next_to_clean)
  398. next_desc = " NTC";
  399. else
  400. next_desc = "";
  401. pr_info("T [0x%03X] %016llX %016llX %016llX"
  402. " %04X %p %016llX %p%s\n", i,
  403. le64_to_cpu(u0->a),
  404. le64_to_cpu(u0->b),
  405. (u64)buffer_info->dma,
  406. buffer_info->length,
  407. buffer_info->next_to_watch,
  408. (u64)buffer_info->time_stamp,
  409. buffer_info->skb, next_desc);
  410. if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
  411. print_hex_dump(KERN_INFO, "",
  412. DUMP_PREFIX_ADDRESS,
  413. 16, 1, phys_to_virt(buffer_info->dma),
  414. buffer_info->length, true);
  415. }
  416. }
  417. /* Print RX Rings Summary */
  418. rx_ring_summary:
  419. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  420. pr_info("Queue [NTU] [NTC]\n");
  421. for (n = 0; n < adapter->num_rx_queues; n++) {
  422. rx_ring = adapter->rx_ring[n];
  423. pr_info(" %5d %5X %5X\n",
  424. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  425. }
  426. /* Print RX Rings */
  427. if (!netif_msg_rx_status(adapter))
  428. goto exit;
  429. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  430. /* Advanced Receive Descriptor (Read) Format
  431. * 63 1 0
  432. * +-----------------------------------------------------+
  433. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  434. * +----------------------------------------------+------+
  435. * 8 | Header Buffer Address [63:1] | DD |
  436. * +-----------------------------------------------------+
  437. *
  438. *
  439. * Advanced Receive Descriptor (Write-Back) Format
  440. *
  441. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  442. * +------------------------------------------------------+
  443. * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
  444. * | Checksum Ident | | | | Type | Type |
  445. * +------------------------------------------------------+
  446. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  447. * +------------------------------------------------------+
  448. * 63 48 47 32 31 20 19 0
  449. */
  450. for (n = 0; n < adapter->num_rx_queues; n++) {
  451. rx_ring = adapter->rx_ring[n];
  452. pr_info("------------------------------------\n");
  453. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  454. pr_info("------------------------------------\n");
  455. pr_info("R [desc] [ PktBuf A0] [ HeadBuf DD] "
  456. "[bi->dma ] [bi->skb] <-- Adv Rx Read format\n");
  457. pr_info("RWB[desc] [PcsmIpSHl PtRs] [vl er S cks ln] -----"
  458. "----------- [bi->skb] <-- Adv Rx Write-Back format\n");
  459. for (i = 0; i < rx_ring->count; i++) {
  460. const char *next_desc;
  461. struct igb_rx_buffer *buffer_info;
  462. buffer_info = &rx_ring->rx_buffer_info[i];
  463. rx_desc = IGB_RX_DESC(rx_ring, i);
  464. u0 = (struct my_u0 *)rx_desc;
  465. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  466. if (i == rx_ring->next_to_use)
  467. next_desc = " NTU";
  468. else if (i == rx_ring->next_to_clean)
  469. next_desc = " NTC";
  470. else
  471. next_desc = "";
  472. if (staterr & E1000_RXD_STAT_DD) {
  473. /* Descriptor Done */
  474. pr_info("%s[0x%03X] %016llX %016llX -------"
  475. "--------- %p%s\n", "RWB", i,
  476. le64_to_cpu(u0->a),
  477. le64_to_cpu(u0->b),
  478. buffer_info->skb, next_desc);
  479. } else {
  480. pr_info("%s[0x%03X] %016llX %016llX %016llX"
  481. " %p%s\n", "R ", i,
  482. le64_to_cpu(u0->a),
  483. le64_to_cpu(u0->b),
  484. (u64)buffer_info->dma,
  485. buffer_info->skb, next_desc);
  486. if (netif_msg_pktdata(adapter)) {
  487. print_hex_dump(KERN_INFO, "",
  488. DUMP_PREFIX_ADDRESS,
  489. 16, 1,
  490. phys_to_virt(buffer_info->dma),
  491. IGB_RX_HDR_LEN, true);
  492. print_hex_dump(KERN_INFO, "",
  493. DUMP_PREFIX_ADDRESS,
  494. 16, 1,
  495. phys_to_virt(
  496. buffer_info->page_dma +
  497. buffer_info->page_offset),
  498. PAGE_SIZE/2, true);
  499. }
  500. }
  501. }
  502. }
  503. exit:
  504. return;
  505. }
  506. /**
  507. * igb_read_clock - read raw cycle counter (to be used by time counter)
  508. */
  509. static cycle_t igb_read_clock(const struct cyclecounter *tc)
  510. {
  511. struct igb_adapter *adapter =
  512. container_of(tc, struct igb_adapter, cycles);
  513. struct e1000_hw *hw = &adapter->hw;
  514. u64 stamp = 0;
  515. int shift = 0;
  516. /*
  517. * The timestamp latches on lowest register read. For the 82580
  518. * the lowest register is SYSTIMR instead of SYSTIML. However we never
  519. * adjusted TIMINCA so SYSTIMR will just read as all 0s so ignore it.
  520. */
  521. if (hw->mac.type >= e1000_82580) {
  522. stamp = rd32(E1000_SYSTIMR) >> 8;
  523. shift = IGB_82580_TSYNC_SHIFT;
  524. }
  525. stamp |= (u64)rd32(E1000_SYSTIML) << shift;
  526. stamp |= (u64)rd32(E1000_SYSTIMH) << (shift + 32);
  527. return stamp;
  528. }
  529. /**
  530. * igb_get_hw_dev - return device
  531. * used by hardware layer to print debugging information
  532. **/
  533. struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
  534. {
  535. struct igb_adapter *adapter = hw->back;
  536. return adapter->netdev;
  537. }
  538. /**
  539. * igb_init_module - Driver Registration Routine
  540. *
  541. * igb_init_module is the first routine called when the driver is
  542. * loaded. All it does is register with the PCI subsystem.
  543. **/
  544. static int __init igb_init_module(void)
  545. {
  546. int ret;
  547. pr_info("%s - version %s\n",
  548. igb_driver_string, igb_driver_version);
  549. pr_info("%s\n", igb_copyright);
  550. #ifdef CONFIG_IGB_DCA
  551. dca_register_notify(&dca_notifier);
  552. #endif
  553. ret = pci_register_driver(&igb_driver);
  554. return ret;
  555. }
  556. module_init(igb_init_module);
  557. /**
  558. * igb_exit_module - Driver Exit Cleanup Routine
  559. *
  560. * igb_exit_module is called just before the driver is removed
  561. * from memory.
  562. **/
  563. static void __exit igb_exit_module(void)
  564. {
  565. #ifdef CONFIG_IGB_DCA
  566. dca_unregister_notify(&dca_notifier);
  567. #endif
  568. pci_unregister_driver(&igb_driver);
  569. }
  570. module_exit(igb_exit_module);
  571. #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
  572. /**
  573. * igb_cache_ring_register - Descriptor ring to register mapping
  574. * @adapter: board private structure to initialize
  575. *
  576. * Once we know the feature-set enabled for the device, we'll cache
  577. * the register offset the descriptor ring is assigned to.
  578. **/
  579. static void igb_cache_ring_register(struct igb_adapter *adapter)
  580. {
  581. int i = 0, j = 0;
  582. u32 rbase_offset = adapter->vfs_allocated_count;
  583. switch (adapter->hw.mac.type) {
  584. case e1000_82576:
  585. /* The queues are allocated for virtualization such that VF 0
  586. * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
  587. * In order to avoid collision we start at the first free queue
  588. * and continue consuming queues in the same sequence
  589. */
  590. if (adapter->vfs_allocated_count) {
  591. for (; i < adapter->rss_queues; i++)
  592. adapter->rx_ring[i]->reg_idx = rbase_offset +
  593. Q_IDX_82576(i);
  594. }
  595. case e1000_82575:
  596. case e1000_82580:
  597. case e1000_i350:
  598. default:
  599. for (; i < adapter->num_rx_queues; i++)
  600. adapter->rx_ring[i]->reg_idx = rbase_offset + i;
  601. for (; j < adapter->num_tx_queues; j++)
  602. adapter->tx_ring[j]->reg_idx = rbase_offset + j;
  603. break;
  604. }
  605. }
  606. static void igb_free_queues(struct igb_adapter *adapter)
  607. {
  608. int i;
  609. for (i = 0; i < adapter->num_tx_queues; i++) {
  610. kfree(adapter->tx_ring[i]);
  611. adapter->tx_ring[i] = NULL;
  612. }
  613. for (i = 0; i < adapter->num_rx_queues; i++) {
  614. kfree(adapter->rx_ring[i]);
  615. adapter->rx_ring[i] = NULL;
  616. }
  617. adapter->num_rx_queues = 0;
  618. adapter->num_tx_queues = 0;
  619. }
  620. /**
  621. * igb_alloc_queues - Allocate memory for all rings
  622. * @adapter: board private structure to initialize
  623. *
  624. * We allocate one ring per queue at run-time since we don't know the
  625. * number of queues at compile-time.
  626. **/
  627. static int igb_alloc_queues(struct igb_adapter *adapter)
  628. {
  629. struct igb_ring *ring;
  630. int i;
  631. int orig_node = adapter->node;
  632. for (i = 0; i < adapter->num_tx_queues; i++) {
  633. if (orig_node == -1) {
  634. int cur_node = next_online_node(adapter->node);
  635. if (cur_node == MAX_NUMNODES)
  636. cur_node = first_online_node;
  637. adapter->node = cur_node;
  638. }
  639. ring = kzalloc_node(sizeof(struct igb_ring), GFP_KERNEL,
  640. adapter->node);
  641. if (!ring)
  642. ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
  643. if (!ring)
  644. goto err;
  645. ring->count = adapter->tx_ring_count;
  646. ring->queue_index = i;
  647. ring->dev = &adapter->pdev->dev;
  648. ring->netdev = adapter->netdev;
  649. ring->numa_node = adapter->node;
  650. /* For 82575, context index must be unique per ring. */
  651. if (adapter->hw.mac.type == e1000_82575)
  652. set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);
  653. adapter->tx_ring[i] = ring;
  654. }
  655. /* Restore the adapter's original node */
  656. adapter->node = orig_node;
  657. for (i = 0; i < adapter->num_rx_queues; i++) {
  658. if (orig_node == -1) {
  659. int cur_node = next_online_node(adapter->node);
  660. if (cur_node == MAX_NUMNODES)
  661. cur_node = first_online_node;
  662. adapter->node = cur_node;
  663. }
  664. ring = kzalloc_node(sizeof(struct igb_ring), GFP_KERNEL,
  665. adapter->node);
  666. if (!ring)
  667. ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
  668. if (!ring)
  669. goto err;
  670. ring->count = adapter->rx_ring_count;
  671. ring->queue_index = i;
  672. ring->dev = &adapter->pdev->dev;
  673. ring->netdev = adapter->netdev;
  674. ring->numa_node = adapter->node;
  675. /* set flag indicating ring supports SCTP checksum offload */
  676. if (adapter->hw.mac.type >= e1000_82576)
  677. set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags);
  678. /* On i350, loopback VLAN packets have the tag byte-swapped. */
  679. if (adapter->hw.mac.type == e1000_i350)
  680. set_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags);
  681. adapter->rx_ring[i] = ring;
  682. }
  683. /* Restore the adapter's original node */
  684. adapter->node = orig_node;
  685. igb_cache_ring_register(adapter);
  686. return 0;
  687. err:
  688. /* Restore the adapter's original node */
  689. adapter->node = orig_node;
  690. igb_free_queues(adapter);
  691. return -ENOMEM;
  692. }
  693. /**
  694. * igb_write_ivar - configure ivar for given MSI-X vector
  695. * @hw: pointer to the HW structure
  696. * @msix_vector: vector number we are allocating to a given ring
  697. * @index: row index of IVAR register to write within IVAR table
  698. * @offset: column offset of in IVAR, should be multiple of 8
  699. *
  700. * This function is intended to handle the writing of the IVAR register
  701. * for adapters 82576 and newer. The IVAR table consists of 2 columns,
  702. * each containing an cause allocation for an Rx and Tx ring, and a
  703. * variable number of rows depending on the number of queues supported.
  704. **/
  705. static void igb_write_ivar(struct e1000_hw *hw, int msix_vector,
  706. int index, int offset)
  707. {
  708. u32 ivar = array_rd32(E1000_IVAR0, index);
  709. /* clear any bits that are currently set */
  710. ivar &= ~((u32)0xFF << offset);
  711. /* write vector and valid bit */
  712. ivar |= (msix_vector | E1000_IVAR_VALID) << offset;
  713. array_wr32(E1000_IVAR0, index, ivar);
  714. }
  715. #define IGB_N0_QUEUE -1
  716. static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
  717. {
  718. struct igb_adapter *adapter = q_vector->adapter;
  719. struct e1000_hw *hw = &adapter->hw;
  720. int rx_queue = IGB_N0_QUEUE;
  721. int tx_queue = IGB_N0_QUEUE;
  722. u32 msixbm = 0;
  723. if (q_vector->rx.ring)
  724. rx_queue = q_vector->rx.ring->reg_idx;
  725. if (q_vector->tx.ring)
  726. tx_queue = q_vector->tx.ring->reg_idx;
  727. switch (hw->mac.type) {
  728. case e1000_82575:
  729. /* The 82575 assigns vectors using a bitmask, which matches the
  730. bitmask for the EICR/EIMS/EIMC registers. To assign one
  731. or more queues to a vector, we write the appropriate bits
  732. into the MSIXBM register for that vector. */
  733. if (rx_queue > IGB_N0_QUEUE)
  734. msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
  735. if (tx_queue > IGB_N0_QUEUE)
  736. msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
  737. if (!adapter->msix_entries && msix_vector == 0)
  738. msixbm |= E1000_EIMS_OTHER;
  739. array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
  740. q_vector->eims_value = msixbm;
  741. break;
  742. case e1000_82576:
  743. /*
  744. * 82576 uses a table that essentially consists of 2 columns
  745. * with 8 rows. The ordering is column-major so we use the
  746. * lower 3 bits as the row index, and the 4th bit as the
  747. * column offset.
  748. */
  749. if (rx_queue > IGB_N0_QUEUE)
  750. igb_write_ivar(hw, msix_vector,
  751. rx_queue & 0x7,
  752. (rx_queue & 0x8) << 1);
  753. if (tx_queue > IGB_N0_QUEUE)
  754. igb_write_ivar(hw, msix_vector,
  755. tx_queue & 0x7,
  756. ((tx_queue & 0x8) << 1) + 8);
  757. q_vector->eims_value = 1 << msix_vector;
  758. break;
  759. case e1000_82580:
  760. case e1000_i350:
  761. /*
  762. * On 82580 and newer adapters the scheme is similar to 82576
  763. * however instead of ordering column-major we have things
  764. * ordered row-major. So we traverse the table by using
  765. * bit 0 as the column offset, and the remaining bits as the
  766. * row index.
  767. */
  768. if (rx_queue > IGB_N0_QUEUE)
  769. igb_write_ivar(hw, msix_vector,
  770. rx_queue >> 1,
  771. (rx_queue & 0x1) << 4);
  772. if (tx_queue > IGB_N0_QUEUE)
  773. igb_write_ivar(hw, msix_vector,
  774. tx_queue >> 1,
  775. ((tx_queue & 0x1) << 4) + 8);
  776. q_vector->eims_value = 1 << msix_vector;
  777. break;
  778. default:
  779. BUG();
  780. break;
  781. }
  782. /* add q_vector eims value to global eims_enable_mask */
  783. adapter->eims_enable_mask |= q_vector->eims_value;
  784. /* configure q_vector to set itr on first interrupt */
  785. q_vector->set_itr = 1;
  786. }
  787. /**
  788. * igb_configure_msix - Configure MSI-X hardware
  789. *
  790. * igb_configure_msix sets up the hardware to properly
  791. * generate MSI-X interrupts.
  792. **/
  793. static void igb_configure_msix(struct igb_adapter *adapter)
  794. {
  795. u32 tmp;
  796. int i, vector = 0;
  797. struct e1000_hw *hw = &adapter->hw;
  798. adapter->eims_enable_mask = 0;
  799. /* set vector for other causes, i.e. link changes */
  800. switch (hw->mac.type) {
  801. case e1000_82575:
  802. tmp = rd32(E1000_CTRL_EXT);
  803. /* enable MSI-X PBA support*/
  804. tmp |= E1000_CTRL_EXT_PBA_CLR;
  805. /* Auto-Mask interrupts upon ICR read. */
  806. tmp |= E1000_CTRL_EXT_EIAME;
  807. tmp |= E1000_CTRL_EXT_IRCA;
  808. wr32(E1000_CTRL_EXT, tmp);
  809. /* enable msix_other interrupt */
  810. array_wr32(E1000_MSIXBM(0), vector++,
  811. E1000_EIMS_OTHER);
  812. adapter->eims_other = E1000_EIMS_OTHER;
  813. break;
  814. case e1000_82576:
  815. case e1000_82580:
  816. case e1000_i350:
  817. /* Turn on MSI-X capability first, or our settings
  818. * won't stick. And it will take days to debug. */
  819. wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
  820. E1000_GPIE_PBA | E1000_GPIE_EIAME |
  821. E1000_GPIE_NSICR);
  822. /* enable msix_other interrupt */
  823. adapter->eims_other = 1 << vector;
  824. tmp = (vector++ | E1000_IVAR_VALID) << 8;
  825. wr32(E1000_IVAR_MISC, tmp);
  826. break;
  827. default:
  828. /* do nothing, since nothing else supports MSI-X */
  829. break;
  830. } /* switch (hw->mac.type) */
  831. adapter->eims_enable_mask |= adapter->eims_other;
  832. for (i = 0; i < adapter->num_q_vectors; i++)
  833. igb_assign_vector(adapter->q_vector[i], vector++);
  834. wrfl();
  835. }
  836. /**
  837. * igb_request_msix - Initialize MSI-X interrupts
  838. *
  839. * igb_request_msix allocates MSI-X vectors and requests interrupts from the
  840. * kernel.
  841. **/
  842. static int igb_request_msix(struct igb_adapter *adapter)
  843. {
  844. struct net_device *netdev = adapter->netdev;
  845. struct e1000_hw *hw = &adapter->hw;
  846. int i, err = 0, vector = 0;
  847. err = request_irq(adapter->msix_entries[vector].vector,
  848. igb_msix_other, 0, netdev->name, adapter);
  849. if (err)
  850. goto out;
  851. vector++;
  852. for (i = 0; i < adapter->num_q_vectors; i++) {
  853. struct igb_q_vector *q_vector = adapter->q_vector[i];
  854. q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
  855. if (q_vector->rx.ring && q_vector->tx.ring)
  856. sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
  857. q_vector->rx.ring->queue_index);
  858. else if (q_vector->tx.ring)
  859. sprintf(q_vector->name, "%s-tx-%u", netdev->name,
  860. q_vector->tx.ring->queue_index);
  861. else if (q_vector->rx.ring)
  862. sprintf(q_vector->name, "%s-rx-%u", netdev->name,
  863. q_vector->rx.ring->queue_index);
  864. else
  865. sprintf(q_vector->name, "%s-unused", netdev->name);
  866. err = request_irq(adapter->msix_entries[vector].vector,
  867. igb_msix_ring, 0, q_vector->name,
  868. q_vector);
  869. if (err)
  870. goto out;
  871. vector++;
  872. }
  873. igb_configure_msix(adapter);
  874. return 0;
  875. out:
  876. return err;
  877. }
  878. static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
  879. {
  880. if (adapter->msix_entries) {
  881. pci_disable_msix(adapter->pdev);
  882. kfree(adapter->msix_entries);
  883. adapter->msix_entries = NULL;
  884. } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
  885. pci_disable_msi(adapter->pdev);
  886. }
  887. }
  888. /**
  889. * igb_free_q_vectors - Free memory allocated for interrupt vectors
  890. * @adapter: board private structure to initialize
  891. *
  892. * This function frees the memory allocated to the q_vectors. In addition if
  893. * NAPI is enabled it will delete any references to the NAPI struct prior
  894. * to freeing the q_vector.
  895. **/
  896. static void igb_free_q_vectors(struct igb_adapter *adapter)
  897. {
  898. int v_idx;
  899. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  900. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  901. adapter->q_vector[v_idx] = NULL;
  902. if (!q_vector)
  903. continue;
  904. netif_napi_del(&q_vector->napi);
  905. kfree(q_vector);
  906. }
  907. adapter->num_q_vectors = 0;
  908. }
  909. /**
  910. * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
  911. *
  912. * This function resets the device so that it has 0 rx queues, tx queues, and
  913. * MSI-X interrupts allocated.
  914. */
  915. static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
  916. {
  917. igb_free_queues(adapter);
  918. igb_free_q_vectors(adapter);
  919. igb_reset_interrupt_capability(adapter);
  920. }
  921. /**
  922. * igb_set_interrupt_capability - set MSI or MSI-X if supported
  923. *
  924. * Attempt to configure interrupts using the best available
  925. * capabilities of the hardware and kernel.
  926. **/
  927. static int igb_set_interrupt_capability(struct igb_adapter *adapter)
  928. {
  929. int err;
  930. int numvecs, i;
  931. /* Number of supported queues. */
  932. adapter->num_rx_queues = adapter->rss_queues;
  933. if (adapter->vfs_allocated_count)
  934. adapter->num_tx_queues = 1;
  935. else
  936. adapter->num_tx_queues = adapter->rss_queues;
  937. /* start with one vector for every rx queue */
  938. numvecs = adapter->num_rx_queues;
  939. /* if tx handler is separate add 1 for every tx queue */
  940. if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
  941. numvecs += adapter->num_tx_queues;
  942. /* store the number of vectors reserved for queues */
  943. adapter->num_q_vectors = numvecs;
  944. /* add 1 vector for link status interrupts */
  945. numvecs++;
  946. adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
  947. GFP_KERNEL);
  948. if (!adapter->msix_entries)
  949. goto msi_only;
  950. for (i = 0; i < numvecs; i++)
  951. adapter->msix_entries[i].entry = i;
  952. err = pci_enable_msix(adapter->pdev,
  953. adapter->msix_entries,
  954. numvecs);
  955. if (err == 0)
  956. goto out;
  957. igb_reset_interrupt_capability(adapter);
  958. /* If we can't do MSI-X, try MSI */
  959. msi_only:
  960. #ifdef CONFIG_PCI_IOV
  961. /* disable SR-IOV for non MSI-X configurations */
  962. if (adapter->vf_data) {
  963. struct e1000_hw *hw = &adapter->hw;
  964. /* disable iov and allow time for transactions to clear */
  965. pci_disable_sriov(adapter->pdev);
  966. msleep(500);
  967. kfree(adapter->vf_data);
  968. adapter->vf_data = NULL;
  969. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  970. wrfl();
  971. msleep(100);
  972. dev_info(&adapter->pdev->dev, "IOV Disabled\n");
  973. }
  974. #endif
  975. adapter->vfs_allocated_count = 0;
  976. adapter->rss_queues = 1;
  977. adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
  978. adapter->num_rx_queues = 1;
  979. adapter->num_tx_queues = 1;
  980. adapter->num_q_vectors = 1;
  981. if (!pci_enable_msi(adapter->pdev))
  982. adapter->flags |= IGB_FLAG_HAS_MSI;
  983. out:
  984. /* Notify the stack of the (possibly) reduced queue counts. */
  985. netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
  986. return netif_set_real_num_rx_queues(adapter->netdev,
  987. adapter->num_rx_queues);
  988. }
  989. /**
  990. * igb_alloc_q_vectors - Allocate memory for interrupt vectors
  991. * @adapter: board private structure to initialize
  992. *
  993. * We allocate one q_vector per queue interrupt. If allocation fails we
  994. * return -ENOMEM.
  995. **/
  996. static int igb_alloc_q_vectors(struct igb_adapter *adapter)
  997. {
  998. struct igb_q_vector *q_vector;
  999. struct e1000_hw *hw = &adapter->hw;
  1000. int v_idx;
  1001. int orig_node = adapter->node;
  1002. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  1003. if ((adapter->num_q_vectors == (adapter->num_rx_queues +
  1004. adapter->num_tx_queues)) &&
  1005. (adapter->num_rx_queues == v_idx))
  1006. adapter->node = orig_node;
  1007. if (orig_node == -1) {
  1008. int cur_node = next_online_node(adapter->node);
  1009. if (cur_node == MAX_NUMNODES)
  1010. cur_node = first_online_node;
  1011. adapter->node = cur_node;
  1012. }
  1013. q_vector = kzalloc_node(sizeof(struct igb_q_vector), GFP_KERNEL,
  1014. adapter->node);
  1015. if (!q_vector)
  1016. q_vector = kzalloc(sizeof(struct igb_q_vector),
  1017. GFP_KERNEL);
  1018. if (!q_vector)
  1019. goto err_out;
  1020. q_vector->adapter = adapter;
  1021. q_vector->itr_register = hw->hw_addr + E1000_EITR(0);
  1022. q_vector->itr_val = IGB_START_ITR;
  1023. netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64);
  1024. adapter->q_vector[v_idx] = q_vector;
  1025. }
  1026. /* Restore the adapter's original node */
  1027. adapter->node = orig_node;
  1028. return 0;
  1029. err_out:
  1030. /* Restore the adapter's original node */
  1031. adapter->node = orig_node;
  1032. igb_free_q_vectors(adapter);
  1033. return -ENOMEM;
  1034. }
  1035. static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter,
  1036. int ring_idx, int v_idx)
  1037. {
  1038. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  1039. q_vector->rx.ring = adapter->rx_ring[ring_idx];
  1040. q_vector->rx.ring->q_vector = q_vector;
  1041. q_vector->rx.count++;
  1042. q_vector->itr_val = adapter->rx_itr_setting;
  1043. if (q_vector->itr_val && q_vector->itr_val <= 3)
  1044. q_vector->itr_val = IGB_START_ITR;
  1045. }
  1046. static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter,
  1047. int ring_idx, int v_idx)
  1048. {
  1049. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  1050. q_vector->tx.ring = adapter->tx_ring[ring_idx];
  1051. q_vector->tx.ring->q_vector = q_vector;
  1052. q_vector->tx.count++;
  1053. q_vector->itr_val = adapter->tx_itr_setting;
  1054. q_vector->tx.work_limit = adapter->tx_work_limit;
  1055. if (q_vector->itr_val && q_vector->itr_val <= 3)
  1056. q_vector->itr_val = IGB_START_ITR;
  1057. }
  1058. /**
  1059. * igb_map_ring_to_vector - maps allocated queues to vectors
  1060. *
  1061. * This function maps the recently allocated queues to vectors.
  1062. **/
  1063. static int igb_map_ring_to_vector(struct igb_adapter *adapter)
  1064. {
  1065. int i;
  1066. int v_idx = 0;
  1067. if ((adapter->num_q_vectors < adapter->num_rx_queues) ||
  1068. (adapter->num_q_vectors < adapter->num_tx_queues))
  1069. return -ENOMEM;
  1070. if (adapter->num_q_vectors >=
  1071. (adapter->num_rx_queues + adapter->num_tx_queues)) {
  1072. for (i = 0; i < adapter->num_rx_queues; i++)
  1073. igb_map_rx_ring_to_vector(adapter, i, v_idx++);
  1074. for (i = 0; i < adapter->num_tx_queues; i++)
  1075. igb_map_tx_ring_to_vector(adapter, i, v_idx++);
  1076. } else {
  1077. for (i = 0; i < adapter->num_rx_queues; i++) {
  1078. if (i < adapter->num_tx_queues)
  1079. igb_map_tx_ring_to_vector(adapter, i, v_idx);
  1080. igb_map_rx_ring_to_vector(adapter, i, v_idx++);
  1081. }
  1082. for (; i < adapter->num_tx_queues; i++)
  1083. igb_map_tx_ring_to_vector(adapter, i, v_idx++);
  1084. }
  1085. return 0;
  1086. }
  1087. /**
  1088. * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
  1089. *
  1090. * This function initializes the interrupts and allocates all of the queues.
  1091. **/
  1092. static int igb_init_interrupt_scheme(struct igb_adapter *adapter)
  1093. {
  1094. struct pci_dev *pdev = adapter->pdev;
  1095. int err;
  1096. err = igb_set_interrupt_capability(adapter);
  1097. if (err)
  1098. return err;
  1099. err = igb_alloc_q_vectors(adapter);
  1100. if (err) {
  1101. dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
  1102. goto err_alloc_q_vectors;
  1103. }
  1104. err = igb_alloc_queues(adapter);
  1105. if (err) {
  1106. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  1107. goto err_alloc_queues;
  1108. }
  1109. err = igb_map_ring_to_vector(adapter);
  1110. if (err) {
  1111. dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n");
  1112. goto err_map_queues;
  1113. }
  1114. return 0;
  1115. err_map_queues:
  1116. igb_free_queues(adapter);
  1117. err_alloc_queues:
  1118. igb_free_q_vectors(adapter);
  1119. err_alloc_q_vectors:
  1120. igb_reset_interrupt_capability(adapter);
  1121. return err;
  1122. }
  1123. /**
  1124. * igb_request_irq - initialize interrupts
  1125. *
  1126. * Attempts to configure interrupts using the best available
  1127. * capabilities of the hardware and kernel.
  1128. **/
  1129. static int igb_request_irq(struct igb_adapter *adapter)
  1130. {
  1131. struct net_device *netdev = adapter->netdev;
  1132. struct pci_dev *pdev = adapter->pdev;
  1133. int err = 0;
  1134. if (adapter->msix_entries) {
  1135. err = igb_request_msix(adapter);
  1136. if (!err)
  1137. goto request_done;
  1138. /* fall back to MSI */
  1139. igb_clear_interrupt_scheme(adapter);
  1140. if (!pci_enable_msi(pdev))
  1141. adapter->flags |= IGB_FLAG_HAS_MSI;
  1142. igb_free_all_tx_resources(adapter);
  1143. igb_free_all_rx_resources(adapter);
  1144. adapter->num_tx_queues = 1;
  1145. adapter->num_rx_queues = 1;
  1146. adapter->num_q_vectors = 1;
  1147. err = igb_alloc_q_vectors(adapter);
  1148. if (err) {
  1149. dev_err(&pdev->dev,
  1150. "Unable to allocate memory for vectors\n");
  1151. goto request_done;
  1152. }
  1153. err = igb_alloc_queues(adapter);
  1154. if (err) {
  1155. dev_err(&pdev->dev,
  1156. "Unable to allocate memory for queues\n");
  1157. igb_free_q_vectors(adapter);
  1158. goto request_done;
  1159. }
  1160. igb_setup_all_tx_resources(adapter);
  1161. igb_setup_all_rx_resources(adapter);
  1162. }
  1163. igb_assign_vector(adapter->q_vector[0], 0);
  1164. if (adapter->flags & IGB_FLAG_HAS_MSI) {
  1165. err = request_irq(pdev->irq, igb_intr_msi, 0,
  1166. netdev->name, adapter);
  1167. if (!err)
  1168. goto request_done;
  1169. /* fall back to legacy interrupts */
  1170. igb_reset_interrupt_capability(adapter);
  1171. adapter->flags &= ~IGB_FLAG_HAS_MSI;
  1172. }
  1173. err = request_irq(pdev->irq, igb_intr, IRQF_SHARED,
  1174. netdev->name, adapter);
  1175. if (err)
  1176. dev_err(&pdev->dev, "Error %d getting interrupt\n",
  1177. err);
  1178. request_done:
  1179. return err;
  1180. }
  1181. static void igb_free_irq(struct igb_adapter *adapter)
  1182. {
  1183. if (adapter->msix_entries) {
  1184. int vector = 0, i;
  1185. free_irq(adapter->msix_entries[vector++].vector, adapter);
  1186. for (i = 0; i < adapter->num_q_vectors; i++)
  1187. free_irq(adapter->msix_entries[vector++].vector,
  1188. adapter->q_vector[i]);
  1189. } else {
  1190. free_irq(adapter->pdev->irq, adapter);
  1191. }
  1192. }
  1193. /**
  1194. * igb_irq_disable - Mask off interrupt generation on the NIC
  1195. * @adapter: board private structure
  1196. **/
  1197. static void igb_irq_disable(struct igb_adapter *adapter)
  1198. {
  1199. struct e1000_hw *hw = &adapter->hw;
  1200. /*
  1201. * we need to be careful when disabling interrupts. The VFs are also
  1202. * mapped into these registers and so clearing the bits can cause
  1203. * issues on the VF drivers so we only need to clear what we set
  1204. */
  1205. if (adapter->msix_entries) {
  1206. u32 regval = rd32(E1000_EIAM);
  1207. wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
  1208. wr32(E1000_EIMC, adapter->eims_enable_mask);
  1209. regval = rd32(E1000_EIAC);
  1210. wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
  1211. }
  1212. wr32(E1000_IAM, 0);
  1213. wr32(E1000_IMC, ~0);
  1214. wrfl();
  1215. if (adapter->msix_entries) {
  1216. int i;
  1217. for (i = 0; i < adapter->num_q_vectors; i++)
  1218. synchronize_irq(adapter->msix_entries[i].vector);
  1219. } else {
  1220. synchronize_irq(adapter->pdev->irq);
  1221. }
  1222. }
  1223. /**
  1224. * igb_irq_enable - Enable default interrupt generation settings
  1225. * @adapter: board private structure
  1226. **/
  1227. static void igb_irq_enable(struct igb_adapter *adapter)
  1228. {
  1229. struct e1000_hw *hw = &adapter->hw;
  1230. if (adapter->msix_entries) {
  1231. u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_DRSTA;
  1232. u32 regval = rd32(E1000_EIAC);
  1233. wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
  1234. regval = rd32(E1000_EIAM);
  1235. wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
  1236. wr32(E1000_EIMS, adapter->eims_enable_mask);
  1237. if (adapter->vfs_allocated_count) {
  1238. wr32(E1000_MBVFIMR, 0xFF);
  1239. ims |= E1000_IMS_VMMB;
  1240. }
  1241. wr32(E1000_IMS, ims);
  1242. } else {
  1243. wr32(E1000_IMS, IMS_ENABLE_MASK |
  1244. E1000_IMS_DRSTA);
  1245. wr32(E1000_IAM, IMS_ENABLE_MASK |
  1246. E1000_IMS_DRSTA);
  1247. }
  1248. }
  1249. static void igb_update_mng_vlan(struct igb_adapter *adapter)
  1250. {
  1251. struct e1000_hw *hw = &adapter->hw;
  1252. u16 vid = adapter->hw.mng_cookie.vlan_id;
  1253. u16 old_vid = adapter->mng_vlan_id;
  1254. if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  1255. /* add VID to filter table */
  1256. igb_vfta_set(hw, vid, true);
  1257. adapter->mng_vlan_id = vid;
  1258. } else {
  1259. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  1260. }
  1261. if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
  1262. (vid != old_vid) &&
  1263. !test_bit(old_vid, adapter->active_vlans)) {
  1264. /* remove VID from filter table */
  1265. igb_vfta_set(hw, old_vid, false);
  1266. }
  1267. }
  1268. /**
  1269. * igb_release_hw_control - release control of the h/w to f/w
  1270. * @adapter: address of board private structure
  1271. *
  1272. * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
  1273. * For ASF and Pass Through versions of f/w this means that the
  1274. * driver is no longer loaded.
  1275. *
  1276. **/
  1277. static void igb_release_hw_control(struct igb_adapter *adapter)
  1278. {
  1279. struct e1000_hw *hw = &adapter->hw;
  1280. u32 ctrl_ext;
  1281. /* Let firmware take over control of h/w */
  1282. ctrl_ext = rd32(E1000_CTRL_EXT);
  1283. wr32(E1000_CTRL_EXT,
  1284. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  1285. }
  1286. /**
  1287. * igb_get_hw_control - get control of the h/w from f/w
  1288. * @adapter: address of board private structure
  1289. *
  1290. * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
  1291. * For ASF and Pass Through versions of f/w this means that
  1292. * the driver is loaded.
  1293. *
  1294. **/
  1295. static void igb_get_hw_control(struct igb_adapter *adapter)
  1296. {
  1297. struct e1000_hw *hw = &adapter->hw;
  1298. u32 ctrl_ext;
  1299. /* Let firmware know the driver has taken over */
  1300. ctrl_ext = rd32(E1000_CTRL_EXT);
  1301. wr32(E1000_CTRL_EXT,
  1302. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  1303. }
  1304. /**
  1305. * igb_configure - configure the hardware for RX and TX
  1306. * @adapter: private board structure
  1307. **/
  1308. static void igb_configure(struct igb_adapter *adapter)
  1309. {
  1310. struct net_device *netdev = adapter->netdev;
  1311. int i;
  1312. igb_get_hw_control(adapter);
  1313. igb_set_rx_mode(netdev);
  1314. igb_restore_vlan(adapter);
  1315. igb_setup_tctl(adapter);
  1316. igb_setup_mrqc(adapter);
  1317. igb_setup_rctl(adapter);
  1318. igb_configure_tx(adapter);
  1319. igb_configure_rx(adapter);
  1320. igb_rx_fifo_flush_82575(&adapter->hw);
  1321. /* call igb_desc_unused which always leaves
  1322. * at least 1 descriptor unused to make sure
  1323. * next_to_use != next_to_clean */
  1324. for (i = 0; i < adapter->num_rx_queues; i++) {
  1325. struct igb_ring *ring = adapter->rx_ring[i];
  1326. igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
  1327. }
  1328. }
  1329. /**
  1330. * igb_power_up_link - Power up the phy/serdes link
  1331. * @adapter: address of board private structure
  1332. **/
  1333. void igb_power_up_link(struct igb_adapter *adapter)
  1334. {
  1335. if (adapter->hw.phy.media_type == e1000_media_type_copper)
  1336. igb_power_up_phy_copper(&adapter->hw);
  1337. else
  1338. igb_power_up_serdes_link_82575(&adapter->hw);
  1339. igb_reset_phy(&adapter->hw);
  1340. }
  1341. /**
  1342. * igb_power_down_link - Power down the phy/serdes link
  1343. * @adapter: address of board private structure
  1344. */
  1345. static void igb_power_down_link(struct igb_adapter *adapter)
  1346. {
  1347. if (adapter->hw.phy.media_type == e1000_media_type_copper)
  1348. igb_power_down_phy_copper_82575(&adapter->hw);
  1349. else
  1350. igb_shutdown_serdes_link_82575(&adapter->hw);
  1351. }
  1352. /**
  1353. * igb_up - Open the interface and prepare it to handle traffic
  1354. * @adapter: board private structure
  1355. **/
  1356. int igb_up(struct igb_adapter *adapter)
  1357. {
  1358. struct e1000_hw *hw = &adapter->hw;
  1359. int i;
  1360. /* hardware has been reset, we need to reload some things */
  1361. igb_configure(adapter);
  1362. clear_bit(__IGB_DOWN, &adapter->state);
  1363. for (i = 0; i < adapter->num_q_vectors; i++)
  1364. napi_enable(&(adapter->q_vector[i]->napi));
  1365. if (adapter->msix_entries)
  1366. igb_configure_msix(adapter);
  1367. else
  1368. igb_assign_vector(adapter->q_vector[0], 0);
  1369. /* Clear any pending interrupts. */
  1370. rd32(E1000_ICR);
  1371. igb_irq_enable(adapter);
  1372. /* notify VFs that reset has been completed */
  1373. if (adapter->vfs_allocated_count) {
  1374. u32 reg_data = rd32(E1000_CTRL_EXT);
  1375. reg_data |= E1000_CTRL_EXT_PFRSTD;
  1376. wr32(E1000_CTRL_EXT, reg_data);
  1377. }
  1378. netif_tx_start_all_queues(adapter->netdev);
  1379. /* start the watchdog. */
  1380. hw->mac.get_link_status = 1;
  1381. schedule_work(&adapter->watchdog_task);
  1382. return 0;
  1383. }
  1384. void igb_down(struct igb_adapter *adapter)
  1385. {
  1386. struct net_device *netdev = adapter->netdev;
  1387. struct e1000_hw *hw = &adapter->hw;
  1388. u32 tctl, rctl;
  1389. int i;
  1390. /* signal that we're down so the interrupt handler does not
  1391. * reschedule our watchdog timer */
  1392. set_bit(__IGB_DOWN, &adapter->state);
  1393. /* disable receives in the hardware */
  1394. rctl = rd32(E1000_RCTL);
  1395. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  1396. /* flush and sleep below */
  1397. netif_tx_stop_all_queues(netdev);
  1398. /* disable transmits in the hardware */
  1399. tctl = rd32(E1000_TCTL);
  1400. tctl &= ~E1000_TCTL_EN;
  1401. wr32(E1000_TCTL, tctl);
  1402. /* flush both disables and wait for them to finish */
  1403. wrfl();
  1404. msleep(10);
  1405. for (i = 0; i < adapter->num_q_vectors; i++)
  1406. napi_disable(&(adapter->q_vector[i]->napi));
  1407. igb_irq_disable(adapter);
  1408. del_timer_sync(&adapter->watchdog_timer);
  1409. del_timer_sync(&adapter->phy_info_timer);
  1410. netif_carrier_off(netdev);
  1411. /* record the stats before reset*/
  1412. spin_lock(&adapter->stats64_lock);
  1413. igb_update_stats(adapter, &adapter->stats64);
  1414. spin_unlock(&adapter->stats64_lock);
  1415. adapter->link_speed = 0;
  1416. adapter->link_duplex = 0;
  1417. if (!pci_channel_offline(adapter->pdev))
  1418. igb_reset(adapter);
  1419. igb_clean_all_tx_rings(adapter);
  1420. igb_clean_all_rx_rings(adapter);
  1421. #ifdef CONFIG_IGB_DCA
  1422. /* since we reset the hardware DCA settings were cleared */
  1423. igb_setup_dca(adapter);
  1424. #endif
  1425. }
  1426. void igb_reinit_locked(struct igb_adapter *adapter)
  1427. {
  1428. WARN_ON(in_interrupt());
  1429. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  1430. msleep(1);
  1431. igb_down(adapter);
  1432. igb_up(adapter);
  1433. clear_bit(__IGB_RESETTING, &adapter->state);
  1434. }
  1435. void igb_reset(struct igb_adapter *adapter)
  1436. {
  1437. struct pci_dev *pdev = adapter->pdev;
  1438. struct e1000_hw *hw = &adapter->hw;
  1439. struct e1000_mac_info *mac = &hw->mac;
  1440. struct e1000_fc_info *fc = &hw->fc;
  1441. u32 pba = 0, tx_space, min_tx_space, min_rx_space;
  1442. u16 hwm;
  1443. /* Repartition Pba for greater than 9k mtu
  1444. * To take effect CTRL.RST is required.
  1445. */
  1446. switch (mac->type) {
  1447. case e1000_i350:
  1448. case e1000_82580:
  1449. pba = rd32(E1000_RXPBS);
  1450. pba = igb_rxpbs_adjust_82580(pba);
  1451. break;
  1452. case e1000_82576:
  1453. pba = rd32(E1000_RXPBS);
  1454. pba &= E1000_RXPBS_SIZE_MASK_82576;
  1455. break;
  1456. case e1000_82575:
  1457. default:
  1458. pba = E1000_PBA_34K;
  1459. break;
  1460. }
  1461. if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  1462. (mac->type < e1000_82576)) {
  1463. /* adjust PBA for jumbo frames */
  1464. wr32(E1000_PBA, pba);
  1465. /* To maintain wire speed transmits, the Tx FIFO should be
  1466. * large enough to accommodate two full transmit packets,
  1467. * rounded up to the next 1KB and expressed in KB. Likewise,
  1468. * the Rx FIFO should be large enough to accommodate at least
  1469. * one full receive packet and is similarly rounded up and
  1470. * expressed in KB. */
  1471. pba = rd32(E1000_PBA);
  1472. /* upper 16 bits has Tx packet buffer allocation size in KB */
  1473. tx_space = pba >> 16;
  1474. /* lower 16 bits has Rx packet buffer allocation size in KB */
  1475. pba &= 0xffff;
  1476. /* the tx fifo also stores 16 bytes of information about the tx
  1477. * but don't include ethernet FCS because hardware appends it */
  1478. min_tx_space = (adapter->max_frame_size +
  1479. sizeof(union e1000_adv_tx_desc) -
  1480. ETH_FCS_LEN) * 2;
  1481. min_tx_space = ALIGN(min_tx_space, 1024);
  1482. min_tx_space >>= 10;
  1483. /* software strips receive CRC, so leave room for it */
  1484. min_rx_space = adapter->max_frame_size;
  1485. min_rx_space = ALIGN(min_rx_space, 1024);
  1486. min_rx_space >>= 10;
  1487. /* If current Tx allocation is less than the min Tx FIFO size,
  1488. * and the min Tx FIFO size is less than the current Rx FIFO
  1489. * allocation, take space away from current Rx allocation */
  1490. if (tx_space < min_tx_space &&
  1491. ((min_tx_space - tx_space) < pba)) {
  1492. pba = pba - (min_tx_space - tx_space);
  1493. /* if short on rx space, rx wins and must trump tx
  1494. * adjustment */
  1495. if (pba < min_rx_space)
  1496. pba = min_rx_space;
  1497. }
  1498. wr32(E1000_PBA, pba);
  1499. }
  1500. /* flow control settings */
  1501. /* The high water mark must be low enough to fit one full frame
  1502. * (or the size used for early receive) above it in the Rx FIFO.
  1503. * Set it to the lower of:
  1504. * - 90% of the Rx FIFO size, or
  1505. * - the full Rx FIFO size minus one full frame */
  1506. hwm = min(((pba << 10) * 9 / 10),
  1507. ((pba << 10) - 2 * adapter->max_frame_size));
  1508. fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
  1509. fc->low_water = fc->high_water - 16;
  1510. fc->pause_time = 0xFFFF;
  1511. fc->send_xon = 1;
  1512. fc->current_mode = fc->requested_mode;
  1513. /* disable receive for all VFs and wait one second */
  1514. if (adapter->vfs_allocated_count) {
  1515. int i;
  1516. for (i = 0 ; i < adapter->vfs_allocated_count; i++)
  1517. adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
  1518. /* ping all the active vfs to let them know we are going down */
  1519. igb_ping_all_vfs(adapter);
  1520. /* disable transmits and receives */
  1521. wr32(E1000_VFRE, 0);
  1522. wr32(E1000_VFTE, 0);
  1523. }
  1524. /* Allow time for pending master requests to run */
  1525. hw->mac.ops.reset_hw(hw);
  1526. wr32(E1000_WUC, 0);
  1527. if (hw->mac.ops.init_hw(hw))
  1528. dev_err(&pdev->dev, "Hardware Error\n");
  1529. igb_init_dmac(adapter, pba);
  1530. if (!netif_running(adapter->netdev))
  1531. igb_power_down_link(adapter);
  1532. igb_update_mng_vlan(adapter);
  1533. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  1534. wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
  1535. igb_get_phy_info(hw);
  1536. }
  1537. static netdev_features_t igb_fix_features(struct net_device *netdev,
  1538. netdev_features_t features)
  1539. {
  1540. /*
  1541. * Since there is no support for separate rx/tx vlan accel
  1542. * enable/disable make sure tx flag is always in same state as rx.
  1543. */
  1544. if (features & NETIF_F_HW_VLAN_RX)
  1545. features |= NETIF_F_HW_VLAN_TX;
  1546. else
  1547. features &= ~NETIF_F_HW_VLAN_TX;
  1548. return features;
  1549. }
  1550. static int igb_set_features(struct net_device *netdev,
  1551. netdev_features_t features)
  1552. {
  1553. netdev_features_t changed = netdev->features ^ features;
  1554. if (changed & NETIF_F_HW_VLAN_RX)
  1555. igb_vlan_mode(netdev, features);
  1556. return 0;
  1557. }
  1558. static const struct net_device_ops igb_netdev_ops = {
  1559. .ndo_open = igb_open,
  1560. .ndo_stop = igb_close,
  1561. .ndo_start_xmit = igb_xmit_frame,
  1562. .ndo_get_stats64 = igb_get_stats64,
  1563. .ndo_set_rx_mode = igb_set_rx_mode,
  1564. .ndo_set_mac_address = igb_set_mac,
  1565. .ndo_change_mtu = igb_change_mtu,
  1566. .ndo_do_ioctl = igb_ioctl,
  1567. .ndo_tx_timeout = igb_tx_timeout,
  1568. .ndo_validate_addr = eth_validate_addr,
  1569. .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
  1570. .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
  1571. .ndo_set_vf_mac = igb_ndo_set_vf_mac,
  1572. .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
  1573. .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
  1574. .ndo_get_vf_config = igb_ndo_get_vf_config,
  1575. #ifdef CONFIG_NET_POLL_CONTROLLER
  1576. .ndo_poll_controller = igb_netpoll,
  1577. #endif
  1578. .ndo_fix_features = igb_fix_features,
  1579. .ndo_set_features = igb_set_features,
  1580. };
  1581. /**
  1582. * igb_probe - Device Initialization Routine
  1583. * @pdev: PCI device information struct
  1584. * @ent: entry in igb_pci_tbl
  1585. *
  1586. * Returns 0 on success, negative on failure
  1587. *
  1588. * igb_probe initializes an adapter identified by a pci_dev structure.
  1589. * The OS initialization, configuring of the adapter private structure,
  1590. * and a hardware reset occur.
  1591. **/
  1592. static int __devinit igb_probe(struct pci_dev *pdev,
  1593. const struct pci_device_id *ent)
  1594. {
  1595. struct net_device *netdev;
  1596. struct igb_adapter *adapter;
  1597. struct e1000_hw *hw;
  1598. u16 eeprom_data = 0;
  1599. s32 ret_val;
  1600. static int global_quad_port_a; /* global quad port a indication */
  1601. const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
  1602. unsigned long mmio_start, mmio_len;
  1603. int err, pci_using_dac;
  1604. u16 eeprom_apme_mask = IGB_EEPROM_APME;
  1605. u8 part_str[E1000_PBANUM_LENGTH];
  1606. /* Catch broken hardware that put the wrong VF device ID in
  1607. * the PCIe SR-IOV capability.
  1608. */
  1609. if (pdev->is_virtfn) {
  1610. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  1611. pci_name(pdev), pdev->vendor, pdev->device);
  1612. return -EINVAL;
  1613. }
  1614. err = pci_enable_device_mem(pdev);
  1615. if (err)
  1616. return err;
  1617. pci_using_dac = 0;
  1618. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
  1619. if (!err) {
  1620. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
  1621. if (!err)
  1622. pci_using_dac = 1;
  1623. } else {
  1624. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  1625. if (err) {
  1626. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  1627. if (err) {
  1628. dev_err(&pdev->dev, "No usable DMA "
  1629. "configuration, aborting\n");
  1630. goto err_dma;
  1631. }
  1632. }
  1633. }
  1634. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  1635. IORESOURCE_MEM),
  1636. igb_driver_name);
  1637. if (err)
  1638. goto err_pci_reg;
  1639. pci_enable_pcie_error_reporting(pdev);
  1640. pci_set_master(pdev);
  1641. pci_save_state(pdev);
  1642. err = -ENOMEM;
  1643. netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
  1644. IGB_MAX_TX_QUEUES);
  1645. if (!netdev)
  1646. goto err_alloc_etherdev;
  1647. SET_NETDEV_DEV(netdev, &pdev->dev);
  1648. pci_set_drvdata(pdev, netdev);
  1649. adapter = netdev_priv(netdev);
  1650. adapter->netdev = netdev;
  1651. adapter->pdev = pdev;
  1652. hw = &adapter->hw;
  1653. hw->back = adapter;
  1654. adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  1655. mmio_start = pci_resource_start(pdev, 0);
  1656. mmio_len = pci_resource_len(pdev, 0);
  1657. err = -EIO;
  1658. hw->hw_addr = ioremap(mmio_start, mmio_len);
  1659. if (!hw->hw_addr)
  1660. goto err_ioremap;
  1661. netdev->netdev_ops = &igb_netdev_ops;
  1662. igb_set_ethtool_ops(netdev);
  1663. netdev->watchdog_timeo = 5 * HZ;
  1664. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  1665. netdev->mem_start = mmio_start;
  1666. netdev->mem_end = mmio_start + mmio_len;
  1667. /* PCI config space info */
  1668. hw->vendor_id = pdev->vendor;
  1669. hw->device_id = pdev->device;
  1670. hw->revision_id = pdev->revision;
  1671. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1672. hw->subsystem_device_id = pdev->subsystem_device;
  1673. /* Copy the default MAC, PHY and NVM function pointers */
  1674. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  1675. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  1676. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  1677. /* Initialize skew-specific constants */
  1678. err = ei->get_invariants(hw);
  1679. if (err)
  1680. goto err_sw_init;
  1681. /* setup the private structure */
  1682. err = igb_sw_init(adapter);
  1683. if (err)
  1684. goto err_sw_init;
  1685. igb_get_bus_info_pcie(hw);
  1686. hw->phy.autoneg_wait_to_complete = false;
  1687. /* Copper options */
  1688. if (hw->phy.media_type == e1000_media_type_copper) {
  1689. hw->phy.mdix = AUTO_ALL_MODES;
  1690. hw->phy.disable_polarity_correction = false;
  1691. hw->phy.ms_type = e1000_ms_hw_default;
  1692. }
  1693. if (igb_check_reset_block(hw))
  1694. dev_info(&pdev->dev,
  1695. "PHY reset is blocked due to SOL/IDER session.\n");
  1696. /*
  1697. * features is initialized to 0 in allocation, it might have bits
  1698. * set by igb_sw_init so we should use an or instead of an
  1699. * assignment.
  1700. */
  1701. netdev->features |= NETIF_F_SG |
  1702. NETIF_F_IP_CSUM |
  1703. NETIF_F_IPV6_CSUM |
  1704. NETIF_F_TSO |
  1705. NETIF_F_TSO6 |
  1706. NETIF_F_RXHASH |
  1707. NETIF_F_RXCSUM |
  1708. NETIF_F_HW_VLAN_RX |
  1709. NETIF_F_HW_VLAN_TX;
  1710. /* copy netdev features into list of user selectable features */
  1711. netdev->hw_features |= netdev->features;
  1712. /* set this bit last since it cannot be part of hw_features */
  1713. netdev->features |= NETIF_F_HW_VLAN_FILTER;
  1714. netdev->vlan_features |= NETIF_F_TSO |
  1715. NETIF_F_TSO6 |
  1716. NETIF_F_IP_CSUM |
  1717. NETIF_F_IPV6_CSUM |
  1718. NETIF_F_SG;
  1719. if (pci_using_dac) {
  1720. netdev->features |= NETIF_F_HIGHDMA;
  1721. netdev->vlan_features |= NETIF_F_HIGHDMA;
  1722. }
  1723. if (hw->mac.type >= e1000_82576) {
  1724. netdev->hw_features |= NETIF_F_SCTP_CSUM;
  1725. netdev->features |= NETIF_F_SCTP_CSUM;
  1726. }
  1727. netdev->priv_flags |= IFF_UNICAST_FLT;
  1728. adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
  1729. /* before reading the NVM, reset the controller to put the device in a
  1730. * known good starting state */
  1731. hw->mac.ops.reset_hw(hw);
  1732. /* make sure the NVM is good */
  1733. if (hw->nvm.ops.validate(hw) < 0) {
  1734. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  1735. err = -EIO;
  1736. goto err_eeprom;
  1737. }
  1738. /* copy the MAC address out of the NVM */
  1739. if (hw->mac.ops.read_mac_addr(hw))
  1740. dev_err(&pdev->dev, "NVM Read Error\n");
  1741. memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
  1742. memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
  1743. if (!is_valid_ether_addr(netdev->perm_addr)) {
  1744. dev_err(&pdev->dev, "Invalid MAC Address\n");
  1745. err = -EIO;
  1746. goto err_eeprom;
  1747. }
  1748. setup_timer(&adapter->watchdog_timer, igb_watchdog,
  1749. (unsigned long) adapter);
  1750. setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
  1751. (unsigned long) adapter);
  1752. INIT_WORK(&adapter->reset_task, igb_reset_task);
  1753. INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
  1754. /* Initialize link properties that are user-changeable */
  1755. adapter->fc_autoneg = true;
  1756. hw->mac.autoneg = true;
  1757. hw->phy.autoneg_advertised = 0x2f;
  1758. hw->fc.requested_mode = e1000_fc_default;
  1759. hw->fc.current_mode = e1000_fc_default;
  1760. igb_validate_mdi_setting(hw);
  1761. /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
  1762. * enable the ACPI Magic Packet filter
  1763. */
  1764. if (hw->bus.func == 0)
  1765. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  1766. else if (hw->mac.type >= e1000_82580)
  1767. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1768. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1769. &eeprom_data);
  1770. else if (hw->bus.func == 1)
  1771. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  1772. if (eeprom_data & eeprom_apme_mask)
  1773. adapter->eeprom_wol |= E1000_WUFC_MAG;
  1774. /* now that we have the eeprom settings, apply the special cases where
  1775. * the eeprom may be wrong or the board simply won't support wake on
  1776. * lan on a particular port */
  1777. switch (pdev->device) {
  1778. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  1779. adapter->eeprom_wol = 0;
  1780. break;
  1781. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  1782. case E1000_DEV_ID_82576_FIBER:
  1783. case E1000_DEV_ID_82576_SERDES:
  1784. /* Wake events only supported on port A for dual fiber
  1785. * regardless of eeprom setting */
  1786. if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
  1787. adapter->eeprom_wol = 0;
  1788. break;
  1789. case E1000_DEV_ID_82576_QUAD_COPPER:
  1790. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  1791. /* if quad port adapter, disable WoL on all but port A */
  1792. if (global_quad_port_a != 0)
  1793. adapter->eeprom_wol = 0;
  1794. else
  1795. adapter->flags |= IGB_FLAG_QUAD_PORT_A;
  1796. /* Reset for multiple quad port adapters */
  1797. if (++global_quad_port_a == 4)
  1798. global_quad_port_a = 0;
  1799. break;
  1800. }
  1801. /* initialize the wol settings based on the eeprom settings */
  1802. adapter->wol = adapter->eeprom_wol;
  1803. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1804. /* reset the hardware with the new settings */
  1805. igb_reset(adapter);
  1806. /* let the f/w know that the h/w is now under the control of the
  1807. * driver. */
  1808. igb_get_hw_control(adapter);
  1809. strcpy(netdev->name, "eth%d");
  1810. err = register_netdev(netdev);
  1811. if (err)
  1812. goto err_register;
  1813. /* carrier off reporting is important to ethtool even BEFORE open */
  1814. netif_carrier_off(netdev);
  1815. #ifdef CONFIG_IGB_DCA
  1816. if (dca_add_requester(&pdev->dev) == 0) {
  1817. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  1818. dev_info(&pdev->dev, "DCA enabled\n");
  1819. igb_setup_dca(adapter);
  1820. }
  1821. #endif
  1822. /* do hw tstamp init after resetting */
  1823. igb_init_hw_timer(adapter);
  1824. dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
  1825. /* print bus type/speed/width info */
  1826. dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
  1827. netdev->name,
  1828. ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
  1829. (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
  1830. "unknown"),
  1831. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  1832. (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
  1833. (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
  1834. "unknown"),
  1835. netdev->dev_addr);
  1836. ret_val = igb_read_part_string(hw, part_str, E1000_PBANUM_LENGTH);
  1837. if (ret_val)
  1838. strcpy(part_str, "Unknown");
  1839. dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
  1840. dev_info(&pdev->dev,
  1841. "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
  1842. adapter->msix_entries ? "MSI-X" :
  1843. (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
  1844. adapter->num_rx_queues, adapter->num_tx_queues);
  1845. switch (hw->mac.type) {
  1846. case e1000_i350:
  1847. igb_set_eee_i350(hw);
  1848. break;
  1849. default:
  1850. break;
  1851. }
  1852. pm_runtime_put_noidle(&pdev->dev);
  1853. return 0;
  1854. err_register:
  1855. igb_release_hw_control(adapter);
  1856. err_eeprom:
  1857. if (!igb_check_reset_block(hw))
  1858. igb_reset_phy(hw);
  1859. if (hw->flash_address)
  1860. iounmap(hw->flash_address);
  1861. err_sw_init:
  1862. igb_clear_interrupt_scheme(adapter);
  1863. iounmap(hw->hw_addr);
  1864. err_ioremap:
  1865. free_netdev(netdev);
  1866. err_alloc_etherdev:
  1867. pci_release_selected_regions(pdev,
  1868. pci_select_bars(pdev, IORESOURCE_MEM));
  1869. err_pci_reg:
  1870. err_dma:
  1871. pci_disable_device(pdev);
  1872. return err;
  1873. }
  1874. /**
  1875. * igb_remove - Device Removal Routine
  1876. * @pdev: PCI device information struct
  1877. *
  1878. * igb_remove is called by the PCI subsystem to alert the driver
  1879. * that it should release a PCI device. The could be caused by a
  1880. * Hot-Plug event, or because the driver is going to be removed from
  1881. * memory.
  1882. **/
  1883. static void __devexit igb_remove(struct pci_dev *pdev)
  1884. {
  1885. struct net_device *netdev = pci_get_drvdata(pdev);
  1886. struct igb_adapter *adapter = netdev_priv(netdev);
  1887. struct e1000_hw *hw = &adapter->hw;
  1888. pm_runtime_get_noresume(&pdev->dev);
  1889. /*
  1890. * The watchdog timer may be rescheduled, so explicitly
  1891. * disable watchdog from being rescheduled.
  1892. */
  1893. set_bit(__IGB_DOWN, &adapter->state);
  1894. del_timer_sync(&adapter->watchdog_timer);
  1895. del_timer_sync(&adapter->phy_info_timer);
  1896. cancel_work_sync(&adapter->reset_task);
  1897. cancel_work_sync(&adapter->watchdog_task);
  1898. #ifdef CONFIG_IGB_DCA
  1899. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  1900. dev_info(&pdev->dev, "DCA disabled\n");
  1901. dca_remove_requester(&pdev->dev);
  1902. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  1903. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  1904. }
  1905. #endif
  1906. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  1907. * would have already happened in close and is redundant. */
  1908. igb_release_hw_control(adapter);
  1909. unregister_netdev(netdev);
  1910. igb_clear_interrupt_scheme(adapter);
  1911. #ifdef CONFIG_PCI_IOV
  1912. /* reclaim resources allocated to VFs */
  1913. if (adapter->vf_data) {
  1914. /* disable iov and allow time for transactions to clear */
  1915. if (!igb_check_vf_assignment(adapter)) {
  1916. pci_disable_sriov(pdev);
  1917. msleep(500);
  1918. } else {
  1919. dev_info(&pdev->dev, "VF(s) assigned to guests!\n");
  1920. }
  1921. kfree(adapter->vf_data);
  1922. adapter->vf_data = NULL;
  1923. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  1924. wrfl();
  1925. msleep(100);
  1926. dev_info(&pdev->dev, "IOV Disabled\n");
  1927. }
  1928. #endif
  1929. iounmap(hw->hw_addr);
  1930. if (hw->flash_address)
  1931. iounmap(hw->flash_address);
  1932. pci_release_selected_regions(pdev,
  1933. pci_select_bars(pdev, IORESOURCE_MEM));
  1934. kfree(adapter->shadow_vfta);
  1935. free_netdev(netdev);
  1936. pci_disable_pcie_error_reporting(pdev);
  1937. pci_disable_device(pdev);
  1938. }
  1939. /**
  1940. * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
  1941. * @adapter: board private structure to initialize
  1942. *
  1943. * This function initializes the vf specific data storage and then attempts to
  1944. * allocate the VFs. The reason for ordering it this way is because it is much
  1945. * mor expensive time wise to disable SR-IOV than it is to allocate and free
  1946. * the memory for the VFs.
  1947. **/
  1948. static void __devinit igb_probe_vfs(struct igb_adapter * adapter)
  1949. {
  1950. #ifdef CONFIG_PCI_IOV
  1951. struct pci_dev *pdev = adapter->pdev;
  1952. int old_vfs = igb_find_enabled_vfs(adapter);
  1953. int i;
  1954. if (old_vfs) {
  1955. dev_info(&pdev->dev, "%d pre-allocated VFs found - override "
  1956. "max_vfs setting of %d\n", old_vfs, max_vfs);
  1957. adapter->vfs_allocated_count = old_vfs;
  1958. }
  1959. if (!adapter->vfs_allocated_count)
  1960. return;
  1961. adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
  1962. sizeof(struct vf_data_storage), GFP_KERNEL);
  1963. /* if allocation failed then we do not support SR-IOV */
  1964. if (!adapter->vf_data) {
  1965. adapter->vfs_allocated_count = 0;
  1966. dev_err(&pdev->dev, "Unable to allocate memory for VF "
  1967. "Data Storage\n");
  1968. goto out;
  1969. }
  1970. if (!old_vfs) {
  1971. if (pci_enable_sriov(pdev, adapter->vfs_allocated_count))
  1972. goto err_out;
  1973. }
  1974. dev_info(&pdev->dev, "%d VFs allocated\n",
  1975. adapter->vfs_allocated_count);
  1976. for (i = 0; i < adapter->vfs_allocated_count; i++)
  1977. igb_vf_configure(adapter, i);
  1978. /* DMA Coalescing is not supported in IOV mode. */
  1979. adapter->flags &= ~IGB_FLAG_DMAC;
  1980. goto out;
  1981. err_out:
  1982. kfree(adapter->vf_data);
  1983. adapter->vf_data = NULL;
  1984. adapter->vfs_allocated_count = 0;
  1985. out:
  1986. return;
  1987. #endif /* CONFIG_PCI_IOV */
  1988. }
  1989. /**
  1990. * igb_init_hw_timer - Initialize hardware timer used with IEEE 1588 timestamp
  1991. * @adapter: board private structure to initialize
  1992. *
  1993. * igb_init_hw_timer initializes the function pointer and values for the hw
  1994. * timer found in hardware.
  1995. **/
  1996. static void igb_init_hw_timer(struct igb_adapter *adapter)
  1997. {
  1998. struct e1000_hw *hw = &adapter->hw;
  1999. switch (hw->mac.type) {
  2000. case e1000_i350:
  2001. case e1000_82580:
  2002. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  2003. adapter->cycles.read = igb_read_clock;
  2004. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  2005. adapter->cycles.mult = 1;
  2006. /*
  2007. * The 82580 timesync updates the system timer every 8ns by 8ns
  2008. * and the value cannot be shifted. Instead we need to shift
  2009. * the registers to generate a 64bit timer value. As a result
  2010. * SYSTIMR/L/H, TXSTMPL/H, RXSTMPL/H all have to be shifted by
  2011. * 24 in order to generate a larger value for synchronization.
  2012. */
  2013. adapter->cycles.shift = IGB_82580_TSYNC_SHIFT;
  2014. /* disable system timer temporarily by setting bit 31 */
  2015. wr32(E1000_TSAUXC, 0x80000000);
  2016. wrfl();
  2017. /* Set registers so that rollover occurs soon to test this. */
  2018. wr32(E1000_SYSTIMR, 0x00000000);
  2019. wr32(E1000_SYSTIML, 0x80000000);
  2020. wr32(E1000_SYSTIMH, 0x000000FF);
  2021. wrfl();
  2022. /* enable system timer by clearing bit 31 */
  2023. wr32(E1000_TSAUXC, 0x0);
  2024. wrfl();
  2025. timecounter_init(&adapter->clock,
  2026. &adapter->cycles,
  2027. ktime_to_ns(ktime_get_real()));
  2028. /*
  2029. * Synchronize our NIC clock against system wall clock. NIC
  2030. * time stamp reading requires ~3us per sample, each sample
  2031. * was pretty stable even under load => only require 10
  2032. * samples for each offset comparison.
  2033. */
  2034. memset(&adapter->compare, 0, sizeof(adapter->compare));
  2035. adapter->compare.source = &adapter->clock;
  2036. adapter->compare.target = ktime_get_real;
  2037. adapter->compare.num_samples = 10;
  2038. timecompare_update(&adapter->compare, 0);
  2039. break;
  2040. case e1000_82576:
  2041. /*
  2042. * Initialize hardware timer: we keep it running just in case
  2043. * that some program needs it later on.
  2044. */
  2045. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  2046. adapter->cycles.read = igb_read_clock;
  2047. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  2048. adapter->cycles.mult = 1;
  2049. /**
  2050. * Scale the NIC clock cycle by a large factor so that
  2051. * relatively small clock corrections can be added or
  2052. * subtracted at each clock tick. The drawbacks of a large
  2053. * factor are a) that the clock register overflows more quickly
  2054. * (not such a big deal) and b) that the increment per tick has
  2055. * to fit into 24 bits. As a result we need to use a shift of
  2056. * 19 so we can fit a value of 16 into the TIMINCA register.
  2057. */
  2058. adapter->cycles.shift = IGB_82576_TSYNC_SHIFT;
  2059. wr32(E1000_TIMINCA,
  2060. (1 << E1000_TIMINCA_16NS_SHIFT) |
  2061. (16 << IGB_82576_TSYNC_SHIFT));
  2062. /* Set registers so that rollover occurs soon to test this. */
  2063. wr32(E1000_SYSTIML, 0x00000000);
  2064. wr32(E1000_SYSTIMH, 0xFF800000);
  2065. wrfl();
  2066. timecounter_init(&adapter->clock,
  2067. &adapter->cycles,
  2068. ktime_to_ns(ktime_get_real()));
  2069. /*
  2070. * Synchronize our NIC clock against system wall clock. NIC
  2071. * time stamp reading requires ~3us per sample, each sample
  2072. * was pretty stable even under load => only require 10
  2073. * samples for each offset comparison.
  2074. */
  2075. memset(&adapter->compare, 0, sizeof(adapter->compare));
  2076. adapter->compare.source = &adapter->clock;
  2077. adapter->compare.target = ktime_get_real;
  2078. adapter->compare.num_samples = 10;
  2079. timecompare_update(&adapter->compare, 0);
  2080. break;
  2081. case e1000_82575:
  2082. /* 82575 does not support timesync */
  2083. default:
  2084. break;
  2085. }
  2086. }
  2087. /**
  2088. * igb_sw_init - Initialize general software structures (struct igb_adapter)
  2089. * @adapter: board private structure to initialize
  2090. *
  2091. * igb_sw_init initializes the Adapter private data structure.
  2092. * Fields are initialized based on PCI device information and
  2093. * OS network device settings (MTU size).
  2094. **/
  2095. static int __devinit igb_sw_init(struct igb_adapter *adapter)
  2096. {
  2097. struct e1000_hw *hw = &adapter->hw;
  2098. struct net_device *netdev = adapter->netdev;
  2099. struct pci_dev *pdev = adapter->pdev;
  2100. pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
  2101. /* set default ring sizes */
  2102. adapter->tx_ring_count = IGB_DEFAULT_TXD;
  2103. adapter->rx_ring_count = IGB_DEFAULT_RXD;
  2104. /* set default ITR values */
  2105. adapter->rx_itr_setting = IGB_DEFAULT_ITR;
  2106. adapter->tx_itr_setting = IGB_DEFAULT_ITR;
  2107. /* set default work limits */
  2108. adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
  2109. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
  2110. VLAN_HLEN;
  2111. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  2112. adapter->node = -1;
  2113. spin_lock_init(&adapter->stats64_lock);
  2114. #ifdef CONFIG_PCI_IOV
  2115. switch (hw->mac.type) {
  2116. case e1000_82576:
  2117. case e1000_i350:
  2118. if (max_vfs > 7) {
  2119. dev_warn(&pdev->dev,
  2120. "Maximum of 7 VFs per PF, using max\n");
  2121. adapter->vfs_allocated_count = 7;
  2122. } else
  2123. adapter->vfs_allocated_count = max_vfs;
  2124. break;
  2125. default:
  2126. break;
  2127. }
  2128. #endif /* CONFIG_PCI_IOV */
  2129. adapter->rss_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
  2130. /* i350 cannot do RSS and SR-IOV at the same time */
  2131. if (hw->mac.type == e1000_i350 && adapter->vfs_allocated_count)
  2132. adapter->rss_queues = 1;
  2133. /*
  2134. * if rss_queues > 4 or vfs are going to be allocated with rss_queues
  2135. * then we should combine the queues into a queue pair in order to
  2136. * conserve interrupts due to limited supply
  2137. */
  2138. if ((adapter->rss_queues > 4) ||
  2139. ((adapter->rss_queues > 1) && (adapter->vfs_allocated_count > 6)))
  2140. adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
  2141. /* Setup and initialize a copy of the hw vlan table array */
  2142. adapter->shadow_vfta = kzalloc(sizeof(u32) *
  2143. E1000_VLAN_FILTER_TBL_SIZE,
  2144. GFP_ATOMIC);
  2145. /* This call may decrease the number of queues */
  2146. if (igb_init_interrupt_scheme(adapter)) {
  2147. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  2148. return -ENOMEM;
  2149. }
  2150. igb_probe_vfs(adapter);
  2151. /* Explicitly disable IRQ since the NIC can be in any state. */
  2152. igb_irq_disable(adapter);
  2153. if (hw->mac.type == e1000_i350)
  2154. adapter->flags &= ~IGB_FLAG_DMAC;
  2155. set_bit(__IGB_DOWN, &adapter->state);
  2156. return 0;
  2157. }
  2158. /**
  2159. * igb_open - Called when a network interface is made active
  2160. * @netdev: network interface device structure
  2161. *
  2162. * Returns 0 on success, negative value on failure
  2163. *
  2164. * The open entry point is called when a network interface is made
  2165. * active by the system (IFF_UP). At this point all resources needed
  2166. * for transmit and receive operations are allocated, the interrupt
  2167. * handler is registered with the OS, the watchdog timer is started,
  2168. * and the stack is notified that the interface is ready.
  2169. **/
  2170. static int __igb_open(struct net_device *netdev, bool resuming)
  2171. {
  2172. struct igb_adapter *adapter = netdev_priv(netdev);
  2173. struct e1000_hw *hw = &adapter->hw;
  2174. struct pci_dev *pdev = adapter->pdev;
  2175. int err;
  2176. int i;
  2177. /* disallow open during test */
  2178. if (test_bit(__IGB_TESTING, &adapter->state)) {
  2179. WARN_ON(resuming);
  2180. return -EBUSY;
  2181. }
  2182. if (!resuming)
  2183. pm_runtime_get_sync(&pdev->dev);
  2184. netif_carrier_off(netdev);
  2185. /* allocate transmit descriptors */
  2186. err = igb_setup_all_tx_resources(adapter);
  2187. if (err)
  2188. goto err_setup_tx;
  2189. /* allocate receive descriptors */
  2190. err = igb_setup_all_rx_resources(adapter);
  2191. if (err)
  2192. goto err_setup_rx;
  2193. igb_power_up_link(adapter);
  2194. /* before we allocate an interrupt, we must be ready to handle it.
  2195. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  2196. * as soon as we call pci_request_irq, so we have to setup our
  2197. * clean_rx handler before we do so. */
  2198. igb_configure(adapter);
  2199. err = igb_request_irq(adapter);
  2200. if (err)
  2201. goto err_req_irq;
  2202. /* From here on the code is the same as igb_up() */
  2203. clear_bit(__IGB_DOWN, &adapter->state);
  2204. for (i = 0; i < adapter->num_q_vectors; i++)
  2205. napi_enable(&(adapter->q_vector[i]->napi));
  2206. /* Clear any pending interrupts. */
  2207. rd32(E1000_ICR);
  2208. igb_irq_enable(adapter);
  2209. /* notify VFs that reset has been completed */
  2210. if (adapter->vfs_allocated_count) {
  2211. u32 reg_data = rd32(E1000_CTRL_EXT);
  2212. reg_data |= E1000_CTRL_EXT_PFRSTD;
  2213. wr32(E1000_CTRL_EXT, reg_data);
  2214. }
  2215. netif_tx_start_all_queues(netdev);
  2216. if (!resuming)
  2217. pm_runtime_put(&pdev->dev);
  2218. /* start the watchdog. */
  2219. hw->mac.get_link_status = 1;
  2220. schedule_work(&adapter->watchdog_task);
  2221. return 0;
  2222. err_req_irq:
  2223. igb_release_hw_control(adapter);
  2224. igb_power_down_link(adapter);
  2225. igb_free_all_rx_resources(adapter);
  2226. err_setup_rx:
  2227. igb_free_all_tx_resources(adapter);
  2228. err_setup_tx:
  2229. igb_reset(adapter);
  2230. if (!resuming)
  2231. pm_runtime_put(&pdev->dev);
  2232. return err;
  2233. }
  2234. static int igb_open(struct net_device *netdev)
  2235. {
  2236. return __igb_open(netdev, false);
  2237. }
  2238. /**
  2239. * igb_close - Disables a network interface
  2240. * @netdev: network interface device structure
  2241. *
  2242. * Returns 0, this is not allowed to fail
  2243. *
  2244. * The close entry point is called when an interface is de-activated
  2245. * by the OS. The hardware is still under the driver's control, but
  2246. * needs to be disabled. A global MAC reset is issued to stop the
  2247. * hardware, and all transmit and receive resources are freed.
  2248. **/
  2249. static int __igb_close(struct net_device *netdev, bool suspending)
  2250. {
  2251. struct igb_adapter *adapter = netdev_priv(netdev);
  2252. struct pci_dev *pdev = adapter->pdev;
  2253. WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
  2254. if (!suspending)
  2255. pm_runtime_get_sync(&pdev->dev);
  2256. igb_down(adapter);
  2257. igb_free_irq(adapter);
  2258. igb_free_all_tx_resources(adapter);
  2259. igb_free_all_rx_resources(adapter);
  2260. if (!suspending)
  2261. pm_runtime_put_sync(&pdev->dev);
  2262. return 0;
  2263. }
  2264. static int igb_close(struct net_device *netdev)
  2265. {
  2266. return __igb_close(netdev, false);
  2267. }
  2268. /**
  2269. * igb_setup_tx_resources - allocate Tx resources (Descriptors)
  2270. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  2271. *
  2272. * Return 0 on success, negative on failure
  2273. **/
  2274. int igb_setup_tx_resources(struct igb_ring *tx_ring)
  2275. {
  2276. struct device *dev = tx_ring->dev;
  2277. int orig_node = dev_to_node(dev);
  2278. int size;
  2279. size = sizeof(struct igb_tx_buffer) * tx_ring->count;
  2280. tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
  2281. if (!tx_ring->tx_buffer_info)
  2282. tx_ring->tx_buffer_info = vzalloc(size);
  2283. if (!tx_ring->tx_buffer_info)
  2284. goto err;
  2285. /* round up to nearest 4K */
  2286. tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
  2287. tx_ring->size = ALIGN(tx_ring->size, 4096);
  2288. set_dev_node(dev, tx_ring->numa_node);
  2289. tx_ring->desc = dma_alloc_coherent(dev,
  2290. tx_ring->size,
  2291. &tx_ring->dma,
  2292. GFP_KERNEL);
  2293. set_dev_node(dev, orig_node);
  2294. if (!tx_ring->desc)
  2295. tx_ring->desc = dma_alloc_coherent(dev,
  2296. tx_ring->size,
  2297. &tx_ring->dma,
  2298. GFP_KERNEL);
  2299. if (!tx_ring->desc)
  2300. goto err;
  2301. tx_ring->next_to_use = 0;
  2302. tx_ring->next_to_clean = 0;
  2303. return 0;
  2304. err:
  2305. vfree(tx_ring->tx_buffer_info);
  2306. dev_err(dev,
  2307. "Unable to allocate memory for the transmit descriptor ring\n");
  2308. return -ENOMEM;
  2309. }
  2310. /**
  2311. * igb_setup_all_tx_resources - wrapper to allocate Tx resources
  2312. * (Descriptors) for all queues
  2313. * @adapter: board private structure
  2314. *
  2315. * Return 0 on success, negative on failure
  2316. **/
  2317. static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
  2318. {
  2319. struct pci_dev *pdev = adapter->pdev;
  2320. int i, err = 0;
  2321. for (i = 0; i < adapter->num_tx_queues; i++) {
  2322. err = igb_setup_tx_resources(adapter->tx_ring[i]);
  2323. if (err) {
  2324. dev_err(&pdev->dev,
  2325. "Allocation for Tx Queue %u failed\n", i);
  2326. for (i--; i >= 0; i--)
  2327. igb_free_tx_resources(adapter->tx_ring[i]);
  2328. break;
  2329. }
  2330. }
  2331. return err;
  2332. }
  2333. /**
  2334. * igb_setup_tctl - configure the transmit control registers
  2335. * @adapter: Board private structure
  2336. **/
  2337. void igb_setup_tctl(struct igb_adapter *adapter)
  2338. {
  2339. struct e1000_hw *hw = &adapter->hw;
  2340. u32 tctl;
  2341. /* disable queue 0 which is enabled by default on 82575 and 82576 */
  2342. wr32(E1000_TXDCTL(0), 0);
  2343. /* Program the Transmit Control Register */
  2344. tctl = rd32(E1000_TCTL);
  2345. tctl &= ~E1000_TCTL_CT;
  2346. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  2347. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  2348. igb_config_collision_dist(hw);
  2349. /* Enable transmits */
  2350. tctl |= E1000_TCTL_EN;
  2351. wr32(E1000_TCTL, tctl);
  2352. }
  2353. /**
  2354. * igb_configure_tx_ring - Configure transmit ring after Reset
  2355. * @adapter: board private structure
  2356. * @ring: tx ring to configure
  2357. *
  2358. * Configure a transmit ring after a reset.
  2359. **/
  2360. void igb_configure_tx_ring(struct igb_adapter *adapter,
  2361. struct igb_ring *ring)
  2362. {
  2363. struct e1000_hw *hw = &adapter->hw;
  2364. u32 txdctl = 0;
  2365. u64 tdba = ring->dma;
  2366. int reg_idx = ring->reg_idx;
  2367. /* disable the queue */
  2368. wr32(E1000_TXDCTL(reg_idx), 0);
  2369. wrfl();
  2370. mdelay(10);
  2371. wr32(E1000_TDLEN(reg_idx),
  2372. ring->count * sizeof(union e1000_adv_tx_desc));
  2373. wr32(E1000_TDBAL(reg_idx),
  2374. tdba & 0x00000000ffffffffULL);
  2375. wr32(E1000_TDBAH(reg_idx), tdba >> 32);
  2376. ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
  2377. wr32(E1000_TDH(reg_idx), 0);
  2378. writel(0, ring->tail);
  2379. txdctl |= IGB_TX_PTHRESH;
  2380. txdctl |= IGB_TX_HTHRESH << 8;
  2381. txdctl |= IGB_TX_WTHRESH << 16;
  2382. txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
  2383. wr32(E1000_TXDCTL(reg_idx), txdctl);
  2384. }
  2385. /**
  2386. * igb_configure_tx - Configure transmit Unit after Reset
  2387. * @adapter: board private structure
  2388. *
  2389. * Configure the Tx unit of the MAC after a reset.
  2390. **/
  2391. static void igb_configure_tx(struct igb_adapter *adapter)
  2392. {
  2393. int i;
  2394. for (i = 0; i < adapter->num_tx_queues; i++)
  2395. igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2396. }
  2397. /**
  2398. * igb_setup_rx_resources - allocate Rx resources (Descriptors)
  2399. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  2400. *
  2401. * Returns 0 on success, negative on failure
  2402. **/
  2403. int igb_setup_rx_resources(struct igb_ring *rx_ring)
  2404. {
  2405. struct device *dev = rx_ring->dev;
  2406. int orig_node = dev_to_node(dev);
  2407. int size, desc_len;
  2408. size = sizeof(struct igb_rx_buffer) * rx_ring->count;
  2409. rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
  2410. if (!rx_ring->rx_buffer_info)
  2411. rx_ring->rx_buffer_info = vzalloc(size);
  2412. if (!rx_ring->rx_buffer_info)
  2413. goto err;
  2414. desc_len = sizeof(union e1000_adv_rx_desc);
  2415. /* Round up to nearest 4K */
  2416. rx_ring->size = rx_ring->count * desc_len;
  2417. rx_ring->size = ALIGN(rx_ring->size, 4096);
  2418. set_dev_node(dev, rx_ring->numa_node);
  2419. rx_ring->desc = dma_alloc_coherent(dev,
  2420. rx_ring->size,
  2421. &rx_ring->dma,
  2422. GFP_KERNEL);
  2423. set_dev_node(dev, orig_node);
  2424. if (!rx_ring->desc)
  2425. rx_ring->desc = dma_alloc_coherent(dev,
  2426. rx_ring->size,
  2427. &rx_ring->dma,
  2428. GFP_KERNEL);
  2429. if (!rx_ring->desc)
  2430. goto err;
  2431. rx_ring->next_to_clean = 0;
  2432. rx_ring->next_to_use = 0;
  2433. return 0;
  2434. err:
  2435. vfree(rx_ring->rx_buffer_info);
  2436. rx_ring->rx_buffer_info = NULL;
  2437. dev_err(dev, "Unable to allocate memory for the receive descriptor"
  2438. " ring\n");
  2439. return -ENOMEM;
  2440. }
  2441. /**
  2442. * igb_setup_all_rx_resources - wrapper to allocate Rx resources
  2443. * (Descriptors) for all queues
  2444. * @adapter: board private structure
  2445. *
  2446. * Return 0 on success, negative on failure
  2447. **/
  2448. static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
  2449. {
  2450. struct pci_dev *pdev = adapter->pdev;
  2451. int i, err = 0;
  2452. for (i = 0; i < adapter->num_rx_queues; i++) {
  2453. err = igb_setup_rx_resources(adapter->rx_ring[i]);
  2454. if (err) {
  2455. dev_err(&pdev->dev,
  2456. "Allocation for Rx Queue %u failed\n", i);
  2457. for (i--; i >= 0; i--)
  2458. igb_free_rx_resources(adapter->rx_ring[i]);
  2459. break;
  2460. }
  2461. }
  2462. return err;
  2463. }
  2464. /**
  2465. * igb_setup_mrqc - configure the multiple receive queue control registers
  2466. * @adapter: Board private structure
  2467. **/
  2468. static void igb_setup_mrqc(struct igb_adapter *adapter)
  2469. {
  2470. struct e1000_hw *hw = &adapter->hw;
  2471. u32 mrqc, rxcsum;
  2472. u32 j, num_rx_queues, shift = 0, shift2 = 0;
  2473. union e1000_reta {
  2474. u32 dword;
  2475. u8 bytes[4];
  2476. } reta;
  2477. static const u8 rsshash[40] = {
  2478. 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67,
  2479. 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb,
  2480. 0xae, 0x7b, 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30,
  2481. 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa };
  2482. /* Fill out hash function seeds */
  2483. for (j = 0; j < 10; j++) {
  2484. u32 rsskey = rsshash[(j * 4)];
  2485. rsskey |= rsshash[(j * 4) + 1] << 8;
  2486. rsskey |= rsshash[(j * 4) + 2] << 16;
  2487. rsskey |= rsshash[(j * 4) + 3] << 24;
  2488. array_wr32(E1000_RSSRK(0), j, rsskey);
  2489. }
  2490. num_rx_queues = adapter->rss_queues;
  2491. if (adapter->vfs_allocated_count) {
  2492. /* 82575 and 82576 supports 2 RSS queues for VMDq */
  2493. switch (hw->mac.type) {
  2494. case e1000_i350:
  2495. case e1000_82580:
  2496. num_rx_queues = 1;
  2497. shift = 0;
  2498. break;
  2499. case e1000_82576:
  2500. shift = 3;
  2501. num_rx_queues = 2;
  2502. break;
  2503. case e1000_82575:
  2504. shift = 2;
  2505. shift2 = 6;
  2506. default:
  2507. break;
  2508. }
  2509. } else {
  2510. if (hw->mac.type == e1000_82575)
  2511. shift = 6;
  2512. }
  2513. for (j = 0; j < (32 * 4); j++) {
  2514. reta.bytes[j & 3] = (j % num_rx_queues) << shift;
  2515. if (shift2)
  2516. reta.bytes[j & 3] |= num_rx_queues << shift2;
  2517. if ((j & 3) == 3)
  2518. wr32(E1000_RETA(j >> 2), reta.dword);
  2519. }
  2520. /*
  2521. * Disable raw packet checksumming so that RSS hash is placed in
  2522. * descriptor on writeback. No need to enable TCP/UDP/IP checksum
  2523. * offloads as they are enabled by default
  2524. */
  2525. rxcsum = rd32(E1000_RXCSUM);
  2526. rxcsum |= E1000_RXCSUM_PCSD;
  2527. if (adapter->hw.mac.type >= e1000_82576)
  2528. /* Enable Receive Checksum Offload for SCTP */
  2529. rxcsum |= E1000_RXCSUM_CRCOFL;
  2530. /* Don't need to set TUOFL or IPOFL, they default to 1 */
  2531. wr32(E1000_RXCSUM, rxcsum);
  2532. /* If VMDq is enabled then we set the appropriate mode for that, else
  2533. * we default to RSS so that an RSS hash is calculated per packet even
  2534. * if we are only using one queue */
  2535. if (adapter->vfs_allocated_count) {
  2536. if (hw->mac.type > e1000_82575) {
  2537. /* Set the default pool for the PF's first queue */
  2538. u32 vtctl = rd32(E1000_VT_CTL);
  2539. vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
  2540. E1000_VT_CTL_DISABLE_DEF_POOL);
  2541. vtctl |= adapter->vfs_allocated_count <<
  2542. E1000_VT_CTL_DEFAULT_POOL_SHIFT;
  2543. wr32(E1000_VT_CTL, vtctl);
  2544. }
  2545. if (adapter->rss_queues > 1)
  2546. mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
  2547. else
  2548. mrqc = E1000_MRQC_ENABLE_VMDQ;
  2549. } else {
  2550. mrqc = E1000_MRQC_ENABLE_RSS_4Q;
  2551. }
  2552. igb_vmm_control(adapter);
  2553. /*
  2554. * Generate RSS hash based on TCP port numbers and/or
  2555. * IPv4/v6 src and dst addresses since UDP cannot be
  2556. * hashed reliably due to IP fragmentation
  2557. */
  2558. mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
  2559. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  2560. E1000_MRQC_RSS_FIELD_IPV6 |
  2561. E1000_MRQC_RSS_FIELD_IPV6_TCP |
  2562. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
  2563. wr32(E1000_MRQC, mrqc);
  2564. }
  2565. /**
  2566. * igb_setup_rctl - configure the receive control registers
  2567. * @adapter: Board private structure
  2568. **/
  2569. void igb_setup_rctl(struct igb_adapter *adapter)
  2570. {
  2571. struct e1000_hw *hw = &adapter->hw;
  2572. u32 rctl;
  2573. rctl = rd32(E1000_RCTL);
  2574. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  2575. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  2576. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
  2577. (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  2578. /*
  2579. * enable stripping of CRC. It's unlikely this will break BMC
  2580. * redirection as it did with e1000. Newer features require
  2581. * that the HW strips the CRC.
  2582. */
  2583. rctl |= E1000_RCTL_SECRC;
  2584. /* disable store bad packets and clear size bits. */
  2585. rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
  2586. /* enable LPE to prevent packets larger than max_frame_size */
  2587. rctl |= E1000_RCTL_LPE;
  2588. /* disable queue 0 to prevent tail write w/o re-config */
  2589. wr32(E1000_RXDCTL(0), 0);
  2590. /* Attention!!! For SR-IOV PF driver operations you must enable
  2591. * queue drop for all VF and PF queues to prevent head of line blocking
  2592. * if an un-trusted VF does not provide descriptors to hardware.
  2593. */
  2594. if (adapter->vfs_allocated_count) {
  2595. /* set all queue drop enable bits */
  2596. wr32(E1000_QDE, ALL_QUEUES);
  2597. }
  2598. wr32(E1000_RCTL, rctl);
  2599. }
  2600. static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
  2601. int vfn)
  2602. {
  2603. struct e1000_hw *hw = &adapter->hw;
  2604. u32 vmolr;
  2605. /* if it isn't the PF check to see if VFs are enabled and
  2606. * increase the size to support vlan tags */
  2607. if (vfn < adapter->vfs_allocated_count &&
  2608. adapter->vf_data[vfn].vlans_enabled)
  2609. size += VLAN_TAG_SIZE;
  2610. vmolr = rd32(E1000_VMOLR(vfn));
  2611. vmolr &= ~E1000_VMOLR_RLPML_MASK;
  2612. vmolr |= size | E1000_VMOLR_LPE;
  2613. wr32(E1000_VMOLR(vfn), vmolr);
  2614. return 0;
  2615. }
  2616. /**
  2617. * igb_rlpml_set - set maximum receive packet size
  2618. * @adapter: board private structure
  2619. *
  2620. * Configure maximum receivable packet size.
  2621. **/
  2622. static void igb_rlpml_set(struct igb_adapter *adapter)
  2623. {
  2624. u32 max_frame_size = adapter->max_frame_size;
  2625. struct e1000_hw *hw = &adapter->hw;
  2626. u16 pf_id = adapter->vfs_allocated_count;
  2627. if (pf_id) {
  2628. igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
  2629. /*
  2630. * If we're in VMDQ or SR-IOV mode, then set global RLPML
  2631. * to our max jumbo frame size, in case we need to enable
  2632. * jumbo frames on one of the rings later.
  2633. * This will not pass over-length frames into the default
  2634. * queue because it's gated by the VMOLR.RLPML.
  2635. */
  2636. max_frame_size = MAX_JUMBO_FRAME_SIZE;
  2637. }
  2638. wr32(E1000_RLPML, max_frame_size);
  2639. }
  2640. static inline void igb_set_vmolr(struct igb_adapter *adapter,
  2641. int vfn, bool aupe)
  2642. {
  2643. struct e1000_hw *hw = &adapter->hw;
  2644. u32 vmolr;
  2645. /*
  2646. * This register exists only on 82576 and newer so if we are older then
  2647. * we should exit and do nothing
  2648. */
  2649. if (hw->mac.type < e1000_82576)
  2650. return;
  2651. vmolr = rd32(E1000_VMOLR(vfn));
  2652. vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */
  2653. if (aupe)
  2654. vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
  2655. else
  2656. vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
  2657. /* clear all bits that might not be set */
  2658. vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
  2659. if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
  2660. vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
  2661. /*
  2662. * for VMDq only allow the VFs and pool 0 to accept broadcast and
  2663. * multicast packets
  2664. */
  2665. if (vfn <= adapter->vfs_allocated_count)
  2666. vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
  2667. wr32(E1000_VMOLR(vfn), vmolr);
  2668. }
  2669. /**
  2670. * igb_configure_rx_ring - Configure a receive ring after Reset
  2671. * @adapter: board private structure
  2672. * @ring: receive ring to be configured
  2673. *
  2674. * Configure the Rx unit of the MAC after a reset.
  2675. **/
  2676. void igb_configure_rx_ring(struct igb_adapter *adapter,
  2677. struct igb_ring *ring)
  2678. {
  2679. struct e1000_hw *hw = &adapter->hw;
  2680. u64 rdba = ring->dma;
  2681. int reg_idx = ring->reg_idx;
  2682. u32 srrctl = 0, rxdctl = 0;
  2683. /* disable the queue */
  2684. wr32(E1000_RXDCTL(reg_idx), 0);
  2685. /* Set DMA base address registers */
  2686. wr32(E1000_RDBAL(reg_idx),
  2687. rdba & 0x00000000ffffffffULL);
  2688. wr32(E1000_RDBAH(reg_idx), rdba >> 32);
  2689. wr32(E1000_RDLEN(reg_idx),
  2690. ring->count * sizeof(union e1000_adv_rx_desc));
  2691. /* initialize head and tail */
  2692. ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
  2693. wr32(E1000_RDH(reg_idx), 0);
  2694. writel(0, ring->tail);
  2695. /* set descriptor configuration */
  2696. srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2697. #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
  2698. srrctl |= IGB_RXBUFFER_16384 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
  2699. #else
  2700. srrctl |= (PAGE_SIZE / 2) >> E1000_SRRCTL_BSIZEPKT_SHIFT;
  2701. #endif
  2702. srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  2703. if (hw->mac.type >= e1000_82580)
  2704. srrctl |= E1000_SRRCTL_TIMESTAMP;
  2705. /* Only set Drop Enable if we are supporting multiple queues */
  2706. if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
  2707. srrctl |= E1000_SRRCTL_DROP_EN;
  2708. wr32(E1000_SRRCTL(reg_idx), srrctl);
  2709. /* set filtering for VMDQ pools */
  2710. igb_set_vmolr(adapter, reg_idx & 0x7, true);
  2711. rxdctl |= IGB_RX_PTHRESH;
  2712. rxdctl |= IGB_RX_HTHRESH << 8;
  2713. rxdctl |= IGB_RX_WTHRESH << 16;
  2714. /* enable receive descriptor fetching */
  2715. rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
  2716. wr32(E1000_RXDCTL(reg_idx), rxdctl);
  2717. }
  2718. /**
  2719. * igb_configure_rx - Configure receive Unit after Reset
  2720. * @adapter: board private structure
  2721. *
  2722. * Configure the Rx unit of the MAC after a reset.
  2723. **/
  2724. static void igb_configure_rx(struct igb_adapter *adapter)
  2725. {
  2726. int i;
  2727. /* set UTA to appropriate mode */
  2728. igb_set_uta(adapter);
  2729. /* set the correct pool for the PF default MAC address in entry 0 */
  2730. igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
  2731. adapter->vfs_allocated_count);
  2732. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  2733. * the Base and Length of the Rx Descriptor Ring */
  2734. for (i = 0; i < adapter->num_rx_queues; i++)
  2735. igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
  2736. }
  2737. /**
  2738. * igb_free_tx_resources - Free Tx Resources per Queue
  2739. * @tx_ring: Tx descriptor ring for a specific queue
  2740. *
  2741. * Free all transmit software resources
  2742. **/
  2743. void igb_free_tx_resources(struct igb_ring *tx_ring)
  2744. {
  2745. igb_clean_tx_ring(tx_ring);
  2746. vfree(tx_ring->tx_buffer_info);
  2747. tx_ring->tx_buffer_info = NULL;
  2748. /* if not set, then don't free */
  2749. if (!tx_ring->desc)
  2750. return;
  2751. dma_free_coherent(tx_ring->dev, tx_ring->size,
  2752. tx_ring->desc, tx_ring->dma);
  2753. tx_ring->desc = NULL;
  2754. }
  2755. /**
  2756. * igb_free_all_tx_resources - Free Tx Resources for All Queues
  2757. * @adapter: board private structure
  2758. *
  2759. * Free all transmit software resources
  2760. **/
  2761. static void igb_free_all_tx_resources(struct igb_adapter *adapter)
  2762. {
  2763. int i;
  2764. for (i = 0; i < adapter->num_tx_queues; i++)
  2765. igb_free_tx_resources(adapter->tx_ring[i]);
  2766. }
  2767. void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
  2768. struct igb_tx_buffer *tx_buffer)
  2769. {
  2770. if (tx_buffer->skb) {
  2771. dev_kfree_skb_any(tx_buffer->skb);
  2772. if (tx_buffer->dma)
  2773. dma_unmap_single(ring->dev,
  2774. tx_buffer->dma,
  2775. tx_buffer->length,
  2776. DMA_TO_DEVICE);
  2777. } else if (tx_buffer->dma) {
  2778. dma_unmap_page(ring->dev,
  2779. tx_buffer->dma,
  2780. tx_buffer->length,
  2781. DMA_TO_DEVICE);
  2782. }
  2783. tx_buffer->next_to_watch = NULL;
  2784. tx_buffer->skb = NULL;
  2785. tx_buffer->dma = 0;
  2786. /* buffer_info must be completely set up in the transmit path */
  2787. }
  2788. /**
  2789. * igb_clean_tx_ring - Free Tx Buffers
  2790. * @tx_ring: ring to be cleaned
  2791. **/
  2792. static void igb_clean_tx_ring(struct igb_ring *tx_ring)
  2793. {
  2794. struct igb_tx_buffer *buffer_info;
  2795. unsigned long size;
  2796. u16 i;
  2797. if (!tx_ring->tx_buffer_info)
  2798. return;
  2799. /* Free all the Tx ring sk_buffs */
  2800. for (i = 0; i < tx_ring->count; i++) {
  2801. buffer_info = &tx_ring->tx_buffer_info[i];
  2802. igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
  2803. }
  2804. netdev_tx_reset_queue(txring_txq(tx_ring));
  2805. size = sizeof(struct igb_tx_buffer) * tx_ring->count;
  2806. memset(tx_ring->tx_buffer_info, 0, size);
  2807. /* Zero out the descriptor ring */
  2808. memset(tx_ring->desc, 0, tx_ring->size);
  2809. tx_ring->next_to_use = 0;
  2810. tx_ring->next_to_clean = 0;
  2811. }
  2812. /**
  2813. * igb_clean_all_tx_rings - Free Tx Buffers for all queues
  2814. * @adapter: board private structure
  2815. **/
  2816. static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
  2817. {
  2818. int i;
  2819. for (i = 0; i < adapter->num_tx_queues; i++)
  2820. igb_clean_tx_ring(adapter->tx_ring[i]);
  2821. }
  2822. /**
  2823. * igb_free_rx_resources - Free Rx Resources
  2824. * @rx_ring: ring to clean the resources from
  2825. *
  2826. * Free all receive software resources
  2827. **/
  2828. void igb_free_rx_resources(struct igb_ring *rx_ring)
  2829. {
  2830. igb_clean_rx_ring(rx_ring);
  2831. vfree(rx_ring->rx_buffer_info);
  2832. rx_ring->rx_buffer_info = NULL;
  2833. /* if not set, then don't free */
  2834. if (!rx_ring->desc)
  2835. return;
  2836. dma_free_coherent(rx_ring->dev, rx_ring->size,
  2837. rx_ring->desc, rx_ring->dma);
  2838. rx_ring->desc = NULL;
  2839. }
  2840. /**
  2841. * igb_free_all_rx_resources - Free Rx Resources for All Queues
  2842. * @adapter: board private structure
  2843. *
  2844. * Free all receive software resources
  2845. **/
  2846. static void igb_free_all_rx_resources(struct igb_adapter *adapter)
  2847. {
  2848. int i;
  2849. for (i = 0; i < adapter->num_rx_queues; i++)
  2850. igb_free_rx_resources(adapter->rx_ring[i]);
  2851. }
  2852. /**
  2853. * igb_clean_rx_ring - Free Rx Buffers per Queue
  2854. * @rx_ring: ring to free buffers from
  2855. **/
  2856. static void igb_clean_rx_ring(struct igb_ring *rx_ring)
  2857. {
  2858. unsigned long size;
  2859. u16 i;
  2860. if (!rx_ring->rx_buffer_info)
  2861. return;
  2862. /* Free all the Rx ring sk_buffs */
  2863. for (i = 0; i < rx_ring->count; i++) {
  2864. struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
  2865. if (buffer_info->dma) {
  2866. dma_unmap_single(rx_ring->dev,
  2867. buffer_info->dma,
  2868. IGB_RX_HDR_LEN,
  2869. DMA_FROM_DEVICE);
  2870. buffer_info->dma = 0;
  2871. }
  2872. if (buffer_info->skb) {
  2873. dev_kfree_skb(buffer_info->skb);
  2874. buffer_info->skb = NULL;
  2875. }
  2876. if (buffer_info->page_dma) {
  2877. dma_unmap_page(rx_ring->dev,
  2878. buffer_info->page_dma,
  2879. PAGE_SIZE / 2,
  2880. DMA_FROM_DEVICE);
  2881. buffer_info->page_dma = 0;
  2882. }
  2883. if (buffer_info->page) {
  2884. put_page(buffer_info->page);
  2885. buffer_info->page = NULL;
  2886. buffer_info->page_offset = 0;
  2887. }
  2888. }
  2889. size = sizeof(struct igb_rx_buffer) * rx_ring->count;
  2890. memset(rx_ring->rx_buffer_info, 0, size);
  2891. /* Zero out the descriptor ring */
  2892. memset(rx_ring->desc, 0, rx_ring->size);
  2893. rx_ring->next_to_clean = 0;
  2894. rx_ring->next_to_use = 0;
  2895. }
  2896. /**
  2897. * igb_clean_all_rx_rings - Free Rx Buffers for all queues
  2898. * @adapter: board private structure
  2899. **/
  2900. static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
  2901. {
  2902. int i;
  2903. for (i = 0; i < adapter->num_rx_queues; i++)
  2904. igb_clean_rx_ring(adapter->rx_ring[i]);
  2905. }
  2906. /**
  2907. * igb_set_mac - Change the Ethernet Address of the NIC
  2908. * @netdev: network interface device structure
  2909. * @p: pointer to an address structure
  2910. *
  2911. * Returns 0 on success, negative on failure
  2912. **/
  2913. static int igb_set_mac(struct net_device *netdev, void *p)
  2914. {
  2915. struct igb_adapter *adapter = netdev_priv(netdev);
  2916. struct e1000_hw *hw = &adapter->hw;
  2917. struct sockaddr *addr = p;
  2918. if (!is_valid_ether_addr(addr->sa_data))
  2919. return -EADDRNOTAVAIL;
  2920. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2921. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  2922. /* set the correct pool for the new PF MAC address in entry 0 */
  2923. igb_rar_set_qsel(adapter, hw->mac.addr, 0,
  2924. adapter->vfs_allocated_count);
  2925. return 0;
  2926. }
  2927. /**
  2928. * igb_write_mc_addr_list - write multicast addresses to MTA
  2929. * @netdev: network interface device structure
  2930. *
  2931. * Writes multicast address list to the MTA hash table.
  2932. * Returns: -ENOMEM on failure
  2933. * 0 on no addresses written
  2934. * X on writing X addresses to MTA
  2935. **/
  2936. static int igb_write_mc_addr_list(struct net_device *netdev)
  2937. {
  2938. struct igb_adapter *adapter = netdev_priv(netdev);
  2939. struct e1000_hw *hw = &adapter->hw;
  2940. struct netdev_hw_addr *ha;
  2941. u8 *mta_list;
  2942. int i;
  2943. if (netdev_mc_empty(netdev)) {
  2944. /* nothing to program, so clear mc list */
  2945. igb_update_mc_addr_list(hw, NULL, 0);
  2946. igb_restore_vf_multicasts(adapter);
  2947. return 0;
  2948. }
  2949. mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
  2950. if (!mta_list)
  2951. return -ENOMEM;
  2952. /* The shared function expects a packed array of only addresses. */
  2953. i = 0;
  2954. netdev_for_each_mc_addr(ha, netdev)
  2955. memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
  2956. igb_update_mc_addr_list(hw, mta_list, i);
  2957. kfree(mta_list);
  2958. return netdev_mc_count(netdev);
  2959. }
  2960. /**
  2961. * igb_write_uc_addr_list - write unicast addresses to RAR table
  2962. * @netdev: network interface device structure
  2963. *
  2964. * Writes unicast address list to the RAR table.
  2965. * Returns: -ENOMEM on failure/insufficient address space
  2966. * 0 on no addresses written
  2967. * X on writing X addresses to the RAR table
  2968. **/
  2969. static int igb_write_uc_addr_list(struct net_device *netdev)
  2970. {
  2971. struct igb_adapter *adapter = netdev_priv(netdev);
  2972. struct e1000_hw *hw = &adapter->hw;
  2973. unsigned int vfn = adapter->vfs_allocated_count;
  2974. unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
  2975. int count = 0;
  2976. /* return ENOMEM indicating insufficient memory for addresses */
  2977. if (netdev_uc_count(netdev) > rar_entries)
  2978. return -ENOMEM;
  2979. if (!netdev_uc_empty(netdev) && rar_entries) {
  2980. struct netdev_hw_addr *ha;
  2981. netdev_for_each_uc_addr(ha, netdev) {
  2982. if (!rar_entries)
  2983. break;
  2984. igb_rar_set_qsel(adapter, ha->addr,
  2985. rar_entries--,
  2986. vfn);
  2987. count++;
  2988. }
  2989. }
  2990. /* write the addresses in reverse order to avoid write combining */
  2991. for (; rar_entries > 0 ; rar_entries--) {
  2992. wr32(E1000_RAH(rar_entries), 0);
  2993. wr32(E1000_RAL(rar_entries), 0);
  2994. }
  2995. wrfl();
  2996. return count;
  2997. }
  2998. /**
  2999. * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
  3000. * @netdev: network interface device structure
  3001. *
  3002. * The set_rx_mode entry point is called whenever the unicast or multicast
  3003. * address lists or the network interface flags are updated. This routine is
  3004. * responsible for configuring the hardware for proper unicast, multicast,
  3005. * promiscuous mode, and all-multi behavior.
  3006. **/
  3007. static void igb_set_rx_mode(struct net_device *netdev)
  3008. {
  3009. struct igb_adapter *adapter = netdev_priv(netdev);
  3010. struct e1000_hw *hw = &adapter->hw;
  3011. unsigned int vfn = adapter->vfs_allocated_count;
  3012. u32 rctl, vmolr = 0;
  3013. int count;
  3014. /* Check for Promiscuous and All Multicast modes */
  3015. rctl = rd32(E1000_RCTL);
  3016. /* clear the effected bits */
  3017. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
  3018. if (netdev->flags & IFF_PROMISC) {
  3019. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  3020. vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
  3021. } else {
  3022. if (netdev->flags & IFF_ALLMULTI) {
  3023. rctl |= E1000_RCTL_MPE;
  3024. vmolr |= E1000_VMOLR_MPME;
  3025. } else {
  3026. /*
  3027. * Write addresses to the MTA, if the attempt fails
  3028. * then we should just turn on promiscuous mode so
  3029. * that we can at least receive multicast traffic
  3030. */
  3031. count = igb_write_mc_addr_list(netdev);
  3032. if (count < 0) {
  3033. rctl |= E1000_RCTL_MPE;
  3034. vmolr |= E1000_VMOLR_MPME;
  3035. } else if (count) {
  3036. vmolr |= E1000_VMOLR_ROMPE;
  3037. }
  3038. }
  3039. /*
  3040. * Write addresses to available RAR registers, if there is not
  3041. * sufficient space to store all the addresses then enable
  3042. * unicast promiscuous mode
  3043. */
  3044. count = igb_write_uc_addr_list(netdev);
  3045. if (count < 0) {
  3046. rctl |= E1000_RCTL_UPE;
  3047. vmolr |= E1000_VMOLR_ROPE;
  3048. }
  3049. rctl |= E1000_RCTL_VFE;
  3050. }
  3051. wr32(E1000_RCTL, rctl);
  3052. /*
  3053. * In order to support SR-IOV and eventually VMDq it is necessary to set
  3054. * the VMOLR to enable the appropriate modes. Without this workaround
  3055. * we will have issues with VLAN tag stripping not being done for frames
  3056. * that are only arriving because we are the default pool
  3057. */
  3058. if (hw->mac.type < e1000_82576)
  3059. return;
  3060. vmolr |= rd32(E1000_VMOLR(vfn)) &
  3061. ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
  3062. wr32(E1000_VMOLR(vfn), vmolr);
  3063. igb_restore_vf_multicasts(adapter);
  3064. }
  3065. static void igb_check_wvbr(struct igb_adapter *adapter)
  3066. {
  3067. struct e1000_hw *hw = &adapter->hw;
  3068. u32 wvbr = 0;
  3069. switch (hw->mac.type) {
  3070. case e1000_82576:
  3071. case e1000_i350:
  3072. if (!(wvbr = rd32(E1000_WVBR)))
  3073. return;
  3074. break;
  3075. default:
  3076. break;
  3077. }
  3078. adapter->wvbr |= wvbr;
  3079. }
  3080. #define IGB_STAGGERED_QUEUE_OFFSET 8
  3081. static void igb_spoof_check(struct igb_adapter *adapter)
  3082. {
  3083. int j;
  3084. if (!adapter->wvbr)
  3085. return;
  3086. for(j = 0; j < adapter->vfs_allocated_count; j++) {
  3087. if (adapter->wvbr & (1 << j) ||
  3088. adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
  3089. dev_warn(&adapter->pdev->dev,
  3090. "Spoof event(s) detected on VF %d\n", j);
  3091. adapter->wvbr &=
  3092. ~((1 << j) |
  3093. (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
  3094. }
  3095. }
  3096. }
  3097. /* Need to wait a few seconds after link up to get diagnostic information from
  3098. * the phy */
  3099. static void igb_update_phy_info(unsigned long data)
  3100. {
  3101. struct igb_adapter *adapter = (struct igb_adapter *) data;
  3102. igb_get_phy_info(&adapter->hw);
  3103. }
  3104. /**
  3105. * igb_has_link - check shared code for link and determine up/down
  3106. * @adapter: pointer to driver private info
  3107. **/
  3108. bool igb_has_link(struct igb_adapter *adapter)
  3109. {
  3110. struct e1000_hw *hw = &adapter->hw;
  3111. bool link_active = false;
  3112. s32 ret_val = 0;
  3113. /* get_link_status is set on LSC (link status) interrupt or
  3114. * rx sequence error interrupt. get_link_status will stay
  3115. * false until the e1000_check_for_link establishes link
  3116. * for copper adapters ONLY
  3117. */
  3118. switch (hw->phy.media_type) {
  3119. case e1000_media_type_copper:
  3120. if (hw->mac.get_link_status) {
  3121. ret_val = hw->mac.ops.check_for_link(hw);
  3122. link_active = !hw->mac.get_link_status;
  3123. } else {
  3124. link_active = true;
  3125. }
  3126. break;
  3127. case e1000_media_type_internal_serdes:
  3128. ret_val = hw->mac.ops.check_for_link(hw);
  3129. link_active = hw->mac.serdes_has_link;
  3130. break;
  3131. default:
  3132. case e1000_media_type_unknown:
  3133. break;
  3134. }
  3135. return link_active;
  3136. }
  3137. static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
  3138. {
  3139. bool ret = false;
  3140. u32 ctrl_ext, thstat;
  3141. /* check for thermal sensor event on i350, copper only */
  3142. if (hw->mac.type == e1000_i350) {
  3143. thstat = rd32(E1000_THSTAT);
  3144. ctrl_ext = rd32(E1000_CTRL_EXT);
  3145. if ((hw->phy.media_type == e1000_media_type_copper) &&
  3146. !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) {
  3147. ret = !!(thstat & event);
  3148. }
  3149. }
  3150. return ret;
  3151. }
  3152. /**
  3153. * igb_watchdog - Timer Call-back
  3154. * @data: pointer to adapter cast into an unsigned long
  3155. **/
  3156. static void igb_watchdog(unsigned long data)
  3157. {
  3158. struct igb_adapter *adapter = (struct igb_adapter *)data;
  3159. /* Do the rest outside of interrupt context */
  3160. schedule_work(&adapter->watchdog_task);
  3161. }
  3162. static void igb_watchdog_task(struct work_struct *work)
  3163. {
  3164. struct igb_adapter *adapter = container_of(work,
  3165. struct igb_adapter,
  3166. watchdog_task);
  3167. struct e1000_hw *hw = &adapter->hw;
  3168. struct net_device *netdev = adapter->netdev;
  3169. u32 link;
  3170. int i;
  3171. link = igb_has_link(adapter);
  3172. if (link) {
  3173. /* Cancel scheduled suspend requests. */
  3174. pm_runtime_resume(netdev->dev.parent);
  3175. if (!netif_carrier_ok(netdev)) {
  3176. u32 ctrl;
  3177. hw->mac.ops.get_speed_and_duplex(hw,
  3178. &adapter->link_speed,
  3179. &adapter->link_duplex);
  3180. ctrl = rd32(E1000_CTRL);
  3181. /* Links status message must follow this format */
  3182. printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s "
  3183. "Duplex, Flow Control: %s\n",
  3184. netdev->name,
  3185. adapter->link_speed,
  3186. adapter->link_duplex == FULL_DUPLEX ?
  3187. "Full" : "Half",
  3188. (ctrl & E1000_CTRL_TFCE) &&
  3189. (ctrl & E1000_CTRL_RFCE) ? "RX/TX" :
  3190. (ctrl & E1000_CTRL_RFCE) ? "RX" :
  3191. (ctrl & E1000_CTRL_TFCE) ? "TX" : "None");
  3192. /* check for thermal sensor event */
  3193. if (igb_thermal_sensor_event(hw,
  3194. E1000_THSTAT_LINK_THROTTLE)) {
  3195. netdev_info(netdev, "The network adapter link "
  3196. "speed was downshifted because it "
  3197. "overheated\n");
  3198. }
  3199. /* adjust timeout factor according to speed/duplex */
  3200. adapter->tx_timeout_factor = 1;
  3201. switch (adapter->link_speed) {
  3202. case SPEED_10:
  3203. adapter->tx_timeout_factor = 14;
  3204. break;
  3205. case SPEED_100:
  3206. /* maybe add some timeout factor ? */
  3207. break;
  3208. }
  3209. netif_carrier_on(netdev);
  3210. igb_ping_all_vfs(adapter);
  3211. igb_check_vf_rate_limit(adapter);
  3212. /* link state has changed, schedule phy info update */
  3213. if (!test_bit(__IGB_DOWN, &adapter->state))
  3214. mod_timer(&adapter->phy_info_timer,
  3215. round_jiffies(jiffies + 2 * HZ));
  3216. }
  3217. } else {
  3218. if (netif_carrier_ok(netdev)) {
  3219. adapter->link_speed = 0;
  3220. adapter->link_duplex = 0;
  3221. /* check for thermal sensor event */
  3222. if (igb_thermal_sensor_event(hw,
  3223. E1000_THSTAT_PWR_DOWN)) {
  3224. netdev_err(netdev, "The network adapter was "
  3225. "stopped because it overheated\n");
  3226. }
  3227. /* Links status message must follow this format */
  3228. printk(KERN_INFO "igb: %s NIC Link is Down\n",
  3229. netdev->name);
  3230. netif_carrier_off(netdev);
  3231. igb_ping_all_vfs(adapter);
  3232. /* link state has changed, schedule phy info update */
  3233. if (!test_bit(__IGB_DOWN, &adapter->state))
  3234. mod_timer(&adapter->phy_info_timer,
  3235. round_jiffies(jiffies + 2 * HZ));
  3236. pm_schedule_suspend(netdev->dev.parent,
  3237. MSEC_PER_SEC * 5);
  3238. }
  3239. }
  3240. spin_lock(&adapter->stats64_lock);
  3241. igb_update_stats(adapter, &adapter->stats64);
  3242. spin_unlock(&adapter->stats64_lock);
  3243. for (i = 0; i < adapter->num_tx_queues; i++) {
  3244. struct igb_ring *tx_ring = adapter->tx_ring[i];
  3245. if (!netif_carrier_ok(netdev)) {
  3246. /* We've lost link, so the controller stops DMA,
  3247. * but we've got queued Tx work that's never going
  3248. * to get done, so reset controller to flush Tx.
  3249. * (Do the reset outside of interrupt context). */
  3250. if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
  3251. adapter->tx_timeout_count++;
  3252. schedule_work(&adapter->reset_task);
  3253. /* return immediately since reset is imminent */
  3254. return;
  3255. }
  3256. }
  3257. /* Force detection of hung controller every watchdog period */
  3258. set_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
  3259. }
  3260. /* Cause software interrupt to ensure rx ring is cleaned */
  3261. if (adapter->msix_entries) {
  3262. u32 eics = 0;
  3263. for (i = 0; i < adapter->num_q_vectors; i++)
  3264. eics |= adapter->q_vector[i]->eims_value;
  3265. wr32(E1000_EICS, eics);
  3266. } else {
  3267. wr32(E1000_ICS, E1000_ICS_RXDMT0);
  3268. }
  3269. igb_spoof_check(adapter);
  3270. /* Reset the timer */
  3271. if (!test_bit(__IGB_DOWN, &adapter->state))
  3272. mod_timer(&adapter->watchdog_timer,
  3273. round_jiffies(jiffies + 2 * HZ));
  3274. }
  3275. enum latency_range {
  3276. lowest_latency = 0,
  3277. low_latency = 1,
  3278. bulk_latency = 2,
  3279. latency_invalid = 255
  3280. };
  3281. /**
  3282. * igb_update_ring_itr - update the dynamic ITR value based on packet size
  3283. *
  3284. * Stores a new ITR value based on strictly on packet size. This
  3285. * algorithm is less sophisticated than that used in igb_update_itr,
  3286. * due to the difficulty of synchronizing statistics across multiple
  3287. * receive rings. The divisors and thresholds used by this function
  3288. * were determined based on theoretical maximum wire speed and testing
  3289. * data, in order to minimize response time while increasing bulk
  3290. * throughput.
  3291. * This functionality is controlled by the InterruptThrottleRate module
  3292. * parameter (see igb_param.c)
  3293. * NOTE: This function is called only when operating in a multiqueue
  3294. * receive environment.
  3295. * @q_vector: pointer to q_vector
  3296. **/
  3297. static void igb_update_ring_itr(struct igb_q_vector *q_vector)
  3298. {
  3299. int new_val = q_vector->itr_val;
  3300. int avg_wire_size = 0;
  3301. struct igb_adapter *adapter = q_vector->adapter;
  3302. unsigned int packets;
  3303. /* For non-gigabit speeds, just fix the interrupt rate at 4000
  3304. * ints/sec - ITR timer value of 120 ticks.
  3305. */
  3306. if (adapter->link_speed != SPEED_1000) {
  3307. new_val = IGB_4K_ITR;
  3308. goto set_itr_val;
  3309. }
  3310. packets = q_vector->rx.total_packets;
  3311. if (packets)
  3312. avg_wire_size = q_vector->rx.total_bytes / packets;
  3313. packets = q_vector->tx.total_packets;
  3314. if (packets)
  3315. avg_wire_size = max_t(u32, avg_wire_size,
  3316. q_vector->tx.total_bytes / packets);
  3317. /* if avg_wire_size isn't set no work was done */
  3318. if (!avg_wire_size)
  3319. goto clear_counts;
  3320. /* Add 24 bytes to size to account for CRC, preamble, and gap */
  3321. avg_wire_size += 24;
  3322. /* Don't starve jumbo frames */
  3323. avg_wire_size = min(avg_wire_size, 3000);
  3324. /* Give a little boost to mid-size frames */
  3325. if ((avg_wire_size > 300) && (avg_wire_size < 1200))
  3326. new_val = avg_wire_size / 3;
  3327. else
  3328. new_val = avg_wire_size / 2;
  3329. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  3330. if (new_val < IGB_20K_ITR &&
  3331. ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
  3332. (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
  3333. new_val = IGB_20K_ITR;
  3334. set_itr_val:
  3335. if (new_val != q_vector->itr_val) {
  3336. q_vector->itr_val = new_val;
  3337. q_vector->set_itr = 1;
  3338. }
  3339. clear_counts:
  3340. q_vector->rx.total_bytes = 0;
  3341. q_vector->rx.total_packets = 0;
  3342. q_vector->tx.total_bytes = 0;
  3343. q_vector->tx.total_packets = 0;
  3344. }
  3345. /**
  3346. * igb_update_itr - update the dynamic ITR value based on statistics
  3347. * Stores a new ITR value based on packets and byte
  3348. * counts during the last interrupt. The advantage of per interrupt
  3349. * computation is faster updates and more accurate ITR for the current
  3350. * traffic pattern. Constants in this function were computed
  3351. * based on theoretical maximum wire speed and thresholds were set based
  3352. * on testing data as well as attempting to minimize response time
  3353. * while increasing bulk throughput.
  3354. * this functionality is controlled by the InterruptThrottleRate module
  3355. * parameter (see igb_param.c)
  3356. * NOTE: These calculations are only valid when operating in a single-
  3357. * queue environment.
  3358. * @q_vector: pointer to q_vector
  3359. * @ring_container: ring info to update the itr for
  3360. **/
  3361. static void igb_update_itr(struct igb_q_vector *q_vector,
  3362. struct igb_ring_container *ring_container)
  3363. {
  3364. unsigned int packets = ring_container->total_packets;
  3365. unsigned int bytes = ring_container->total_bytes;
  3366. u8 itrval = ring_container->itr;
  3367. /* no packets, exit with status unchanged */
  3368. if (packets == 0)
  3369. return;
  3370. switch (itrval) {
  3371. case lowest_latency:
  3372. /* handle TSO and jumbo frames */
  3373. if (bytes/packets > 8000)
  3374. itrval = bulk_latency;
  3375. else if ((packets < 5) && (bytes > 512))
  3376. itrval = low_latency;
  3377. break;
  3378. case low_latency: /* 50 usec aka 20000 ints/s */
  3379. if (bytes > 10000) {
  3380. /* this if handles the TSO accounting */
  3381. if (bytes/packets > 8000) {
  3382. itrval = bulk_latency;
  3383. } else if ((packets < 10) || ((bytes/packets) > 1200)) {
  3384. itrval = bulk_latency;
  3385. } else if ((packets > 35)) {
  3386. itrval = lowest_latency;
  3387. }
  3388. } else if (bytes/packets > 2000) {
  3389. itrval = bulk_latency;
  3390. } else if (packets <= 2 && bytes < 512) {
  3391. itrval = lowest_latency;
  3392. }
  3393. break;
  3394. case bulk_latency: /* 250 usec aka 4000 ints/s */
  3395. if (bytes > 25000) {
  3396. if (packets > 35)
  3397. itrval = low_latency;
  3398. } else if (bytes < 1500) {
  3399. itrval = low_latency;
  3400. }
  3401. break;
  3402. }
  3403. /* clear work counters since we have the values we need */
  3404. ring_container->total_bytes = 0;
  3405. ring_container->total_packets = 0;
  3406. /* write updated itr to ring container */
  3407. ring_container->itr = itrval;
  3408. }
  3409. static void igb_set_itr(struct igb_q_vector *q_vector)
  3410. {
  3411. struct igb_adapter *adapter = q_vector->adapter;
  3412. u32 new_itr = q_vector->itr_val;
  3413. u8 current_itr = 0;
  3414. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  3415. if (adapter->link_speed != SPEED_1000) {
  3416. current_itr = 0;
  3417. new_itr = IGB_4K_ITR;
  3418. goto set_itr_now;
  3419. }
  3420. igb_update_itr(q_vector, &q_vector->tx);
  3421. igb_update_itr(q_vector, &q_vector->rx);
  3422. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  3423. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  3424. if (current_itr == lowest_latency &&
  3425. ((q_vector->rx.ring && adapter->rx_itr_setting == 3) ||
  3426. (!q_vector->rx.ring && adapter->tx_itr_setting == 3)))
  3427. current_itr = low_latency;
  3428. switch (current_itr) {
  3429. /* counts and packets in update_itr are dependent on these numbers */
  3430. case lowest_latency:
  3431. new_itr = IGB_70K_ITR; /* 70,000 ints/sec */
  3432. break;
  3433. case low_latency:
  3434. new_itr = IGB_20K_ITR; /* 20,000 ints/sec */
  3435. break;
  3436. case bulk_latency:
  3437. new_itr = IGB_4K_ITR; /* 4,000 ints/sec */
  3438. break;
  3439. default:
  3440. break;
  3441. }
  3442. set_itr_now:
  3443. if (new_itr != q_vector->itr_val) {
  3444. /* this attempts to bias the interrupt rate towards Bulk
  3445. * by adding intermediate steps when interrupt rate is
  3446. * increasing */
  3447. new_itr = new_itr > q_vector->itr_val ?
  3448. max((new_itr * q_vector->itr_val) /
  3449. (new_itr + (q_vector->itr_val >> 2)),
  3450. new_itr) :
  3451. new_itr;
  3452. /* Don't write the value here; it resets the adapter's
  3453. * internal timer, and causes us to delay far longer than
  3454. * we should between interrupts. Instead, we write the ITR
  3455. * value at the beginning of the next interrupt so the timing
  3456. * ends up being correct.
  3457. */
  3458. q_vector->itr_val = new_itr;
  3459. q_vector->set_itr = 1;
  3460. }
  3461. }
  3462. static void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens,
  3463. u32 type_tucmd, u32 mss_l4len_idx)
  3464. {
  3465. struct e1000_adv_tx_context_desc *context_desc;
  3466. u16 i = tx_ring->next_to_use;
  3467. context_desc = IGB_TX_CTXTDESC(tx_ring, i);
  3468. i++;
  3469. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  3470. /* set bits to identify this as an advanced context descriptor */
  3471. type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
  3472. /* For 82575, context index must be unique per ring. */
  3473. if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
  3474. mss_l4len_idx |= tx_ring->reg_idx << 4;
  3475. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  3476. context_desc->seqnum_seed = 0;
  3477. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  3478. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  3479. }
  3480. static int igb_tso(struct igb_ring *tx_ring,
  3481. struct igb_tx_buffer *first,
  3482. u8 *hdr_len)
  3483. {
  3484. struct sk_buff *skb = first->skb;
  3485. u32 vlan_macip_lens, type_tucmd;
  3486. u32 mss_l4len_idx, l4len;
  3487. if (!skb_is_gso(skb))
  3488. return 0;
  3489. if (skb_header_cloned(skb)) {
  3490. int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  3491. if (err)
  3492. return err;
  3493. }
  3494. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  3495. type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
  3496. if (first->protocol == __constant_htons(ETH_P_IP)) {
  3497. struct iphdr *iph = ip_hdr(skb);
  3498. iph->tot_len = 0;
  3499. iph->check = 0;
  3500. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3501. iph->daddr, 0,
  3502. IPPROTO_TCP,
  3503. 0);
  3504. type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
  3505. first->tx_flags |= IGB_TX_FLAGS_TSO |
  3506. IGB_TX_FLAGS_CSUM |
  3507. IGB_TX_FLAGS_IPV4;
  3508. } else if (skb_is_gso_v6(skb)) {
  3509. ipv6_hdr(skb)->payload_len = 0;
  3510. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  3511. &ipv6_hdr(skb)->daddr,
  3512. 0, IPPROTO_TCP, 0);
  3513. first->tx_flags |= IGB_TX_FLAGS_TSO |
  3514. IGB_TX_FLAGS_CSUM;
  3515. }
  3516. /* compute header lengths */
  3517. l4len = tcp_hdrlen(skb);
  3518. *hdr_len = skb_transport_offset(skb) + l4len;
  3519. /* update gso size and bytecount with header size */
  3520. first->gso_segs = skb_shinfo(skb)->gso_segs;
  3521. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  3522. /* MSS L4LEN IDX */
  3523. mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT;
  3524. mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT;
  3525. /* VLAN MACLEN IPLEN */
  3526. vlan_macip_lens = skb_network_header_len(skb);
  3527. vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
  3528. vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
  3529. igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
  3530. return 1;
  3531. }
  3532. static void igb_tx_csum(struct igb_ring *tx_ring, struct igb_tx_buffer *first)
  3533. {
  3534. struct sk_buff *skb = first->skb;
  3535. u32 vlan_macip_lens = 0;
  3536. u32 mss_l4len_idx = 0;
  3537. u32 type_tucmd = 0;
  3538. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  3539. if (!(first->tx_flags & IGB_TX_FLAGS_VLAN))
  3540. return;
  3541. } else {
  3542. u8 l4_hdr = 0;
  3543. switch (first->protocol) {
  3544. case __constant_htons(ETH_P_IP):
  3545. vlan_macip_lens |= skb_network_header_len(skb);
  3546. type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
  3547. l4_hdr = ip_hdr(skb)->protocol;
  3548. break;
  3549. case __constant_htons(ETH_P_IPV6):
  3550. vlan_macip_lens |= skb_network_header_len(skb);
  3551. l4_hdr = ipv6_hdr(skb)->nexthdr;
  3552. break;
  3553. default:
  3554. if (unlikely(net_ratelimit())) {
  3555. dev_warn(tx_ring->dev,
  3556. "partial checksum but proto=%x!\n",
  3557. first->protocol);
  3558. }
  3559. break;
  3560. }
  3561. switch (l4_hdr) {
  3562. case IPPROTO_TCP:
  3563. type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  3564. mss_l4len_idx = tcp_hdrlen(skb) <<
  3565. E1000_ADVTXD_L4LEN_SHIFT;
  3566. break;
  3567. case IPPROTO_SCTP:
  3568. type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
  3569. mss_l4len_idx = sizeof(struct sctphdr) <<
  3570. E1000_ADVTXD_L4LEN_SHIFT;
  3571. break;
  3572. case IPPROTO_UDP:
  3573. mss_l4len_idx = sizeof(struct udphdr) <<
  3574. E1000_ADVTXD_L4LEN_SHIFT;
  3575. break;
  3576. default:
  3577. if (unlikely(net_ratelimit())) {
  3578. dev_warn(tx_ring->dev,
  3579. "partial checksum but l4 proto=%x!\n",
  3580. l4_hdr);
  3581. }
  3582. break;
  3583. }
  3584. /* update TX checksum flag */
  3585. first->tx_flags |= IGB_TX_FLAGS_CSUM;
  3586. }
  3587. vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT;
  3588. vlan_macip_lens |= first->tx_flags & IGB_TX_FLAGS_VLAN_MASK;
  3589. igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx);
  3590. }
  3591. static __le32 igb_tx_cmd_type(u32 tx_flags)
  3592. {
  3593. /* set type for advanced descriptor with frame checksum insertion */
  3594. __le32 cmd_type = cpu_to_le32(E1000_ADVTXD_DTYP_DATA |
  3595. E1000_ADVTXD_DCMD_IFCS |
  3596. E1000_ADVTXD_DCMD_DEXT);
  3597. /* set HW vlan bit if vlan is present */
  3598. if (tx_flags & IGB_TX_FLAGS_VLAN)
  3599. cmd_type |= cpu_to_le32(E1000_ADVTXD_DCMD_VLE);
  3600. /* set timestamp bit if present */
  3601. if (tx_flags & IGB_TX_FLAGS_TSTAMP)
  3602. cmd_type |= cpu_to_le32(E1000_ADVTXD_MAC_TSTAMP);
  3603. /* set segmentation bits for TSO */
  3604. if (tx_flags & IGB_TX_FLAGS_TSO)
  3605. cmd_type |= cpu_to_le32(E1000_ADVTXD_DCMD_TSE);
  3606. return cmd_type;
  3607. }
  3608. static void igb_tx_olinfo_status(struct igb_ring *tx_ring,
  3609. union e1000_adv_tx_desc *tx_desc,
  3610. u32 tx_flags, unsigned int paylen)
  3611. {
  3612. u32 olinfo_status = paylen << E1000_ADVTXD_PAYLEN_SHIFT;
  3613. /* 82575 requires a unique index per ring if any offload is enabled */
  3614. if ((tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_VLAN)) &&
  3615. test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
  3616. olinfo_status |= tx_ring->reg_idx << 4;
  3617. /* insert L4 checksum */
  3618. if (tx_flags & IGB_TX_FLAGS_CSUM) {
  3619. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  3620. /* insert IPv4 checksum */
  3621. if (tx_flags & IGB_TX_FLAGS_IPV4)
  3622. olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
  3623. }
  3624. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  3625. }
  3626. /*
  3627. * The largest size we can write to the descriptor is 65535. In order to
  3628. * maintain a power of two alignment we have to limit ourselves to 32K.
  3629. */
  3630. #define IGB_MAX_TXD_PWR 15
  3631. #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
  3632. static void igb_tx_map(struct igb_ring *tx_ring,
  3633. struct igb_tx_buffer *first,
  3634. const u8 hdr_len)
  3635. {
  3636. struct sk_buff *skb = first->skb;
  3637. struct igb_tx_buffer *tx_buffer_info;
  3638. union e1000_adv_tx_desc *tx_desc;
  3639. dma_addr_t dma;
  3640. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  3641. unsigned int data_len = skb->data_len;
  3642. unsigned int size = skb_headlen(skb);
  3643. unsigned int paylen = skb->len - hdr_len;
  3644. __le32 cmd_type;
  3645. u32 tx_flags = first->tx_flags;
  3646. u16 i = tx_ring->next_to_use;
  3647. tx_desc = IGB_TX_DESC(tx_ring, i);
  3648. igb_tx_olinfo_status(tx_ring, tx_desc, tx_flags, paylen);
  3649. cmd_type = igb_tx_cmd_type(tx_flags);
  3650. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  3651. if (dma_mapping_error(tx_ring->dev, dma))
  3652. goto dma_error;
  3653. /* record length, and DMA address */
  3654. first->length = size;
  3655. first->dma = dma;
  3656. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  3657. for (;;) {
  3658. while (unlikely(size > IGB_MAX_DATA_PER_TXD)) {
  3659. tx_desc->read.cmd_type_len =
  3660. cmd_type | cpu_to_le32(IGB_MAX_DATA_PER_TXD);
  3661. i++;
  3662. tx_desc++;
  3663. if (i == tx_ring->count) {
  3664. tx_desc = IGB_TX_DESC(tx_ring, 0);
  3665. i = 0;
  3666. }
  3667. dma += IGB_MAX_DATA_PER_TXD;
  3668. size -= IGB_MAX_DATA_PER_TXD;
  3669. tx_desc->read.olinfo_status = 0;
  3670. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  3671. }
  3672. if (likely(!data_len))
  3673. break;
  3674. tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
  3675. i++;
  3676. tx_desc++;
  3677. if (i == tx_ring->count) {
  3678. tx_desc = IGB_TX_DESC(tx_ring, 0);
  3679. i = 0;
  3680. }
  3681. size = skb_frag_size(frag);
  3682. data_len -= size;
  3683. dma = skb_frag_dma_map(tx_ring->dev, frag, 0,
  3684. size, DMA_TO_DEVICE);
  3685. if (dma_mapping_error(tx_ring->dev, dma))
  3686. goto dma_error;
  3687. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3688. tx_buffer_info->length = size;
  3689. tx_buffer_info->dma = dma;
  3690. tx_desc->read.olinfo_status = 0;
  3691. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  3692. frag++;
  3693. }
  3694. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  3695. /* write last descriptor with RS and EOP bits */
  3696. cmd_type |= cpu_to_le32(size) | cpu_to_le32(IGB_TXD_DCMD);
  3697. tx_desc->read.cmd_type_len = cmd_type;
  3698. /* set the timestamp */
  3699. first->time_stamp = jiffies;
  3700. /*
  3701. * Force memory writes to complete before letting h/w know there
  3702. * are new descriptors to fetch. (Only applicable for weak-ordered
  3703. * memory model archs, such as IA-64).
  3704. *
  3705. * We also need this memory barrier to make certain all of the
  3706. * status bits have been updated before next_to_watch is written.
  3707. */
  3708. wmb();
  3709. /* set next_to_watch value indicating a packet is present */
  3710. first->next_to_watch = tx_desc;
  3711. i++;
  3712. if (i == tx_ring->count)
  3713. i = 0;
  3714. tx_ring->next_to_use = i;
  3715. writel(i, tx_ring->tail);
  3716. /* we need this if more than one processor can write to our tail
  3717. * at a time, it syncronizes IO on IA64/Altix systems */
  3718. mmiowb();
  3719. return;
  3720. dma_error:
  3721. dev_err(tx_ring->dev, "TX DMA map failed\n");
  3722. /* clear dma mappings for failed tx_buffer_info map */
  3723. for (;;) {
  3724. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3725. igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  3726. if (tx_buffer_info == first)
  3727. break;
  3728. if (i == 0)
  3729. i = tx_ring->count;
  3730. i--;
  3731. }
  3732. tx_ring->next_to_use = i;
  3733. }
  3734. static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
  3735. {
  3736. struct net_device *netdev = tx_ring->netdev;
  3737. netif_stop_subqueue(netdev, tx_ring->queue_index);
  3738. /* Herbert's original patch had:
  3739. * smp_mb__after_netif_stop_queue();
  3740. * but since that doesn't exist yet, just open code it. */
  3741. smp_mb();
  3742. /* We need to check again in a case another CPU has just
  3743. * made room available. */
  3744. if (igb_desc_unused(tx_ring) < size)
  3745. return -EBUSY;
  3746. /* A reprieve! */
  3747. netif_wake_subqueue(netdev, tx_ring->queue_index);
  3748. u64_stats_update_begin(&tx_ring->tx_syncp2);
  3749. tx_ring->tx_stats.restart_queue2++;
  3750. u64_stats_update_end(&tx_ring->tx_syncp2);
  3751. return 0;
  3752. }
  3753. static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)
  3754. {
  3755. if (igb_desc_unused(tx_ring) >= size)
  3756. return 0;
  3757. return __igb_maybe_stop_tx(tx_ring, size);
  3758. }
  3759. netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
  3760. struct igb_ring *tx_ring)
  3761. {
  3762. struct igb_tx_buffer *first;
  3763. int tso;
  3764. u32 tx_flags = 0;
  3765. __be16 protocol = vlan_get_protocol(skb);
  3766. u8 hdr_len = 0;
  3767. /* need: 1 descriptor per page,
  3768. * + 2 desc gap to keep tail from touching head,
  3769. * + 1 desc for skb->data,
  3770. * + 1 desc for context descriptor,
  3771. * otherwise try next time */
  3772. if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
  3773. /* this is a hard error */
  3774. return NETDEV_TX_BUSY;
  3775. }
  3776. /* record the location of the first descriptor for this packet */
  3777. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  3778. first->skb = skb;
  3779. first->bytecount = skb->len;
  3780. first->gso_segs = 1;
  3781. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  3782. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  3783. tx_flags |= IGB_TX_FLAGS_TSTAMP;
  3784. }
  3785. if (vlan_tx_tag_present(skb)) {
  3786. tx_flags |= IGB_TX_FLAGS_VLAN;
  3787. tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
  3788. }
  3789. /* record initial flags and protocol */
  3790. first->tx_flags = tx_flags;
  3791. first->protocol = protocol;
  3792. tso = igb_tso(tx_ring, first, &hdr_len);
  3793. if (tso < 0)
  3794. goto out_drop;
  3795. else if (!tso)
  3796. igb_tx_csum(tx_ring, first);
  3797. igb_tx_map(tx_ring, first, hdr_len);
  3798. /* Make sure there is space in the ring for the next send. */
  3799. igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4);
  3800. return NETDEV_TX_OK;
  3801. out_drop:
  3802. igb_unmap_and_free_tx_resource(tx_ring, first);
  3803. return NETDEV_TX_OK;
  3804. }
  3805. static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter,
  3806. struct sk_buff *skb)
  3807. {
  3808. unsigned int r_idx = skb->queue_mapping;
  3809. if (r_idx >= adapter->num_tx_queues)
  3810. r_idx = r_idx % adapter->num_tx_queues;
  3811. return adapter->tx_ring[r_idx];
  3812. }
  3813. static netdev_tx_t igb_xmit_frame(struct sk_buff *skb,
  3814. struct net_device *netdev)
  3815. {
  3816. struct igb_adapter *adapter = netdev_priv(netdev);
  3817. if (test_bit(__IGB_DOWN, &adapter->state)) {
  3818. dev_kfree_skb_any(skb);
  3819. return NETDEV_TX_OK;
  3820. }
  3821. if (skb->len <= 0) {
  3822. dev_kfree_skb_any(skb);
  3823. return NETDEV_TX_OK;
  3824. }
  3825. /*
  3826. * The minimum packet size with TCTL.PSP set is 17 so pad the skb
  3827. * in order to meet this minimum size requirement.
  3828. */
  3829. if (skb->len < 17) {
  3830. if (skb_padto(skb, 17))
  3831. return NETDEV_TX_OK;
  3832. skb->len = 17;
  3833. }
  3834. return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb));
  3835. }
  3836. /**
  3837. * igb_tx_timeout - Respond to a Tx Hang
  3838. * @netdev: network interface device structure
  3839. **/
  3840. static void igb_tx_timeout(struct net_device *netdev)
  3841. {
  3842. struct igb_adapter *adapter = netdev_priv(netdev);
  3843. struct e1000_hw *hw = &adapter->hw;
  3844. /* Do the reset outside of interrupt context */
  3845. adapter->tx_timeout_count++;
  3846. if (hw->mac.type >= e1000_82580)
  3847. hw->dev_spec._82575.global_device_reset = true;
  3848. schedule_work(&adapter->reset_task);
  3849. wr32(E1000_EICS,
  3850. (adapter->eims_enable_mask & ~adapter->eims_other));
  3851. }
  3852. static void igb_reset_task(struct work_struct *work)
  3853. {
  3854. struct igb_adapter *adapter;
  3855. adapter = container_of(work, struct igb_adapter, reset_task);
  3856. igb_dump(adapter);
  3857. netdev_err(adapter->netdev, "Reset adapter\n");
  3858. igb_reinit_locked(adapter);
  3859. }
  3860. /**
  3861. * igb_get_stats64 - Get System Network Statistics
  3862. * @netdev: network interface device structure
  3863. * @stats: rtnl_link_stats64 pointer
  3864. *
  3865. **/
  3866. static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev,
  3867. struct rtnl_link_stats64 *stats)
  3868. {
  3869. struct igb_adapter *adapter = netdev_priv(netdev);
  3870. spin_lock(&adapter->stats64_lock);
  3871. igb_update_stats(adapter, &adapter->stats64);
  3872. memcpy(stats, &adapter->stats64, sizeof(*stats));
  3873. spin_unlock(&adapter->stats64_lock);
  3874. return stats;
  3875. }
  3876. /**
  3877. * igb_change_mtu - Change the Maximum Transfer Unit
  3878. * @netdev: network interface device structure
  3879. * @new_mtu: new value for maximum frame size
  3880. *
  3881. * Returns 0 on success, negative on failure
  3882. **/
  3883. static int igb_change_mtu(struct net_device *netdev, int new_mtu)
  3884. {
  3885. struct igb_adapter *adapter = netdev_priv(netdev);
  3886. struct pci_dev *pdev = adapter->pdev;
  3887. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  3888. if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  3889. dev_err(&pdev->dev, "Invalid MTU setting\n");
  3890. return -EINVAL;
  3891. }
  3892. #define MAX_STD_JUMBO_FRAME_SIZE 9238
  3893. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  3894. dev_err(&pdev->dev, "MTU > 9216 not supported.\n");
  3895. return -EINVAL;
  3896. }
  3897. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  3898. msleep(1);
  3899. /* igb_down has a dependency on max_frame_size */
  3900. adapter->max_frame_size = max_frame;
  3901. if (netif_running(netdev))
  3902. igb_down(adapter);
  3903. dev_info(&pdev->dev, "changing MTU from %d to %d\n",
  3904. netdev->mtu, new_mtu);
  3905. netdev->mtu = new_mtu;
  3906. if (netif_running(netdev))
  3907. igb_up(adapter);
  3908. else
  3909. igb_reset(adapter);
  3910. clear_bit(__IGB_RESETTING, &adapter->state);
  3911. return 0;
  3912. }
  3913. /**
  3914. * igb_update_stats - Update the board statistics counters
  3915. * @adapter: board private structure
  3916. **/
  3917. void igb_update_stats(struct igb_adapter *adapter,
  3918. struct rtnl_link_stats64 *net_stats)
  3919. {
  3920. struct e1000_hw *hw = &adapter->hw;
  3921. struct pci_dev *pdev = adapter->pdev;
  3922. u32 reg, mpc;
  3923. u16 phy_tmp;
  3924. int i;
  3925. u64 bytes, packets;
  3926. unsigned int start;
  3927. u64 _bytes, _packets;
  3928. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  3929. /*
  3930. * Prevent stats update while adapter is being reset, or if the pci
  3931. * connection is down.
  3932. */
  3933. if (adapter->link_speed == 0)
  3934. return;
  3935. if (pci_channel_offline(pdev))
  3936. return;
  3937. bytes = 0;
  3938. packets = 0;
  3939. for (i = 0; i < adapter->num_rx_queues; i++) {
  3940. u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF;
  3941. struct igb_ring *ring = adapter->rx_ring[i];
  3942. ring->rx_stats.drops += rqdpc_tmp;
  3943. net_stats->rx_fifo_errors += rqdpc_tmp;
  3944. do {
  3945. start = u64_stats_fetch_begin_bh(&ring->rx_syncp);
  3946. _bytes = ring->rx_stats.bytes;
  3947. _packets = ring->rx_stats.packets;
  3948. } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start));
  3949. bytes += _bytes;
  3950. packets += _packets;
  3951. }
  3952. net_stats->rx_bytes = bytes;
  3953. net_stats->rx_packets = packets;
  3954. bytes = 0;
  3955. packets = 0;
  3956. for (i = 0; i < adapter->num_tx_queues; i++) {
  3957. struct igb_ring *ring = adapter->tx_ring[i];
  3958. do {
  3959. start = u64_stats_fetch_begin_bh(&ring->tx_syncp);
  3960. _bytes = ring->tx_stats.bytes;
  3961. _packets = ring->tx_stats.packets;
  3962. } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start));
  3963. bytes += _bytes;
  3964. packets += _packets;
  3965. }
  3966. net_stats->tx_bytes = bytes;
  3967. net_stats->tx_packets = packets;
  3968. /* read stats registers */
  3969. adapter->stats.crcerrs += rd32(E1000_CRCERRS);
  3970. adapter->stats.gprc += rd32(E1000_GPRC);
  3971. adapter->stats.gorc += rd32(E1000_GORCL);
  3972. rd32(E1000_GORCH); /* clear GORCL */
  3973. adapter->stats.bprc += rd32(E1000_BPRC);
  3974. adapter->stats.mprc += rd32(E1000_MPRC);
  3975. adapter->stats.roc += rd32(E1000_ROC);
  3976. adapter->stats.prc64 += rd32(E1000_PRC64);
  3977. adapter->stats.prc127 += rd32(E1000_PRC127);
  3978. adapter->stats.prc255 += rd32(E1000_PRC255);
  3979. adapter->stats.prc511 += rd32(E1000_PRC511);
  3980. adapter->stats.prc1023 += rd32(E1000_PRC1023);
  3981. adapter->stats.prc1522 += rd32(E1000_PRC1522);
  3982. adapter->stats.symerrs += rd32(E1000_SYMERRS);
  3983. adapter->stats.sec += rd32(E1000_SEC);
  3984. mpc = rd32(E1000_MPC);
  3985. adapter->stats.mpc += mpc;
  3986. net_stats->rx_fifo_errors += mpc;
  3987. adapter->stats.scc += rd32(E1000_SCC);
  3988. adapter->stats.ecol += rd32(E1000_ECOL);
  3989. adapter->stats.mcc += rd32(E1000_MCC);
  3990. adapter->stats.latecol += rd32(E1000_LATECOL);
  3991. adapter->stats.dc += rd32(E1000_DC);
  3992. adapter->stats.rlec += rd32(E1000_RLEC);
  3993. adapter->stats.xonrxc += rd32(E1000_XONRXC);
  3994. adapter->stats.xontxc += rd32(E1000_XONTXC);
  3995. adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
  3996. adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
  3997. adapter->stats.fcruc += rd32(E1000_FCRUC);
  3998. adapter->stats.gptc += rd32(E1000_GPTC);
  3999. adapter->stats.gotc += rd32(E1000_GOTCL);
  4000. rd32(E1000_GOTCH); /* clear GOTCL */
  4001. adapter->stats.rnbc += rd32(E1000_RNBC);
  4002. adapter->stats.ruc += rd32(E1000_RUC);
  4003. adapter->stats.rfc += rd32(E1000_RFC);
  4004. adapter->stats.rjc += rd32(E1000_RJC);
  4005. adapter->stats.tor += rd32(E1000_TORH);
  4006. adapter->stats.tot += rd32(E1000_TOTH);
  4007. adapter->stats.tpr += rd32(E1000_TPR);
  4008. adapter->stats.ptc64 += rd32(E1000_PTC64);
  4009. adapter->stats.ptc127 += rd32(E1000_PTC127);
  4010. adapter->stats.ptc255 += rd32(E1000_PTC255);
  4011. adapter->stats.ptc511 += rd32(E1000_PTC511);
  4012. adapter->stats.ptc1023 += rd32(E1000_PTC1023);
  4013. adapter->stats.ptc1522 += rd32(E1000_PTC1522);
  4014. adapter->stats.mptc += rd32(E1000_MPTC);
  4015. adapter->stats.bptc += rd32(E1000_BPTC);
  4016. adapter->stats.tpt += rd32(E1000_TPT);
  4017. adapter->stats.colc += rd32(E1000_COLC);
  4018. adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
  4019. /* read internal phy specific stats */
  4020. reg = rd32(E1000_CTRL_EXT);
  4021. if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
  4022. adapter->stats.rxerrc += rd32(E1000_RXERRC);
  4023. adapter->stats.tncrs += rd32(E1000_TNCRS);
  4024. }
  4025. adapter->stats.tsctc += rd32(E1000_TSCTC);
  4026. adapter->stats.tsctfc += rd32(E1000_TSCTFC);
  4027. adapter->stats.iac += rd32(E1000_IAC);
  4028. adapter->stats.icrxoc += rd32(E1000_ICRXOC);
  4029. adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
  4030. adapter->stats.icrxatc += rd32(E1000_ICRXATC);
  4031. adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
  4032. adapter->stats.ictxatc += rd32(E1000_ICTXATC);
  4033. adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
  4034. adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
  4035. adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
  4036. /* Fill out the OS statistics structure */
  4037. net_stats->multicast = adapter->stats.mprc;
  4038. net_stats->collisions = adapter->stats.colc;
  4039. /* Rx Errors */
  4040. /* RLEC on some newer hardware can be incorrect so build
  4041. * our own version based on RUC and ROC */
  4042. net_stats->rx_errors = adapter->stats.rxerrc +
  4043. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4044. adapter->stats.ruc + adapter->stats.roc +
  4045. adapter->stats.cexterr;
  4046. net_stats->rx_length_errors = adapter->stats.ruc +
  4047. adapter->stats.roc;
  4048. net_stats->rx_crc_errors = adapter->stats.crcerrs;
  4049. net_stats->rx_frame_errors = adapter->stats.algnerrc;
  4050. net_stats->rx_missed_errors = adapter->stats.mpc;
  4051. /* Tx Errors */
  4052. net_stats->tx_errors = adapter->stats.ecol +
  4053. adapter->stats.latecol;
  4054. net_stats->tx_aborted_errors = adapter->stats.ecol;
  4055. net_stats->tx_window_errors = adapter->stats.latecol;
  4056. net_stats->tx_carrier_errors = adapter->stats.tncrs;
  4057. /* Tx Dropped needs to be maintained elsewhere */
  4058. /* Phy Stats */
  4059. if (hw->phy.media_type == e1000_media_type_copper) {
  4060. if ((adapter->link_speed == SPEED_1000) &&
  4061. (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  4062. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  4063. adapter->phy_stats.idle_errors += phy_tmp;
  4064. }
  4065. }
  4066. /* Management Stats */
  4067. adapter->stats.mgptc += rd32(E1000_MGTPTC);
  4068. adapter->stats.mgprc += rd32(E1000_MGTPRC);
  4069. adapter->stats.mgpdc += rd32(E1000_MGTPDC);
  4070. /* OS2BMC Stats */
  4071. reg = rd32(E1000_MANC);
  4072. if (reg & E1000_MANC_EN_BMC2OS) {
  4073. adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
  4074. adapter->stats.o2bspc += rd32(E1000_O2BSPC);
  4075. adapter->stats.b2ospc += rd32(E1000_B2OSPC);
  4076. adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
  4077. }
  4078. }
  4079. static irqreturn_t igb_msix_other(int irq, void *data)
  4080. {
  4081. struct igb_adapter *adapter = data;
  4082. struct e1000_hw *hw = &adapter->hw;
  4083. u32 icr = rd32(E1000_ICR);
  4084. /* reading ICR causes bit 31 of EICR to be cleared */
  4085. if (icr & E1000_ICR_DRSTA)
  4086. schedule_work(&adapter->reset_task);
  4087. if (icr & E1000_ICR_DOUTSYNC) {
  4088. /* HW is reporting DMA is out of sync */
  4089. adapter->stats.doosync++;
  4090. /* The DMA Out of Sync is also indication of a spoof event
  4091. * in IOV mode. Check the Wrong VM Behavior register to
  4092. * see if it is really a spoof event. */
  4093. igb_check_wvbr(adapter);
  4094. }
  4095. /* Check for a mailbox event */
  4096. if (icr & E1000_ICR_VMMB)
  4097. igb_msg_task(adapter);
  4098. if (icr & E1000_ICR_LSC) {
  4099. hw->mac.get_link_status = 1;
  4100. /* guard against interrupt when we're going down */
  4101. if (!test_bit(__IGB_DOWN, &adapter->state))
  4102. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4103. }
  4104. wr32(E1000_EIMS, adapter->eims_other);
  4105. return IRQ_HANDLED;
  4106. }
  4107. static void igb_write_itr(struct igb_q_vector *q_vector)
  4108. {
  4109. struct igb_adapter *adapter = q_vector->adapter;
  4110. u32 itr_val = q_vector->itr_val & 0x7FFC;
  4111. if (!q_vector->set_itr)
  4112. return;
  4113. if (!itr_val)
  4114. itr_val = 0x4;
  4115. if (adapter->hw.mac.type == e1000_82575)
  4116. itr_val |= itr_val << 16;
  4117. else
  4118. itr_val |= E1000_EITR_CNT_IGNR;
  4119. writel(itr_val, q_vector->itr_register);
  4120. q_vector->set_itr = 0;
  4121. }
  4122. static irqreturn_t igb_msix_ring(int irq, void *data)
  4123. {
  4124. struct igb_q_vector *q_vector = data;
  4125. /* Write the ITR value calculated from the previous interrupt. */
  4126. igb_write_itr(q_vector);
  4127. napi_schedule(&q_vector->napi);
  4128. return IRQ_HANDLED;
  4129. }
  4130. #ifdef CONFIG_IGB_DCA
  4131. static void igb_update_dca(struct igb_q_vector *q_vector)
  4132. {
  4133. struct igb_adapter *adapter = q_vector->adapter;
  4134. struct e1000_hw *hw = &adapter->hw;
  4135. int cpu = get_cpu();
  4136. if (q_vector->cpu == cpu)
  4137. goto out_no_update;
  4138. if (q_vector->tx.ring) {
  4139. int q = q_vector->tx.ring->reg_idx;
  4140. u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
  4141. if (hw->mac.type == e1000_82575) {
  4142. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
  4143. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  4144. } else {
  4145. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
  4146. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  4147. E1000_DCA_TXCTRL_CPUID_SHIFT;
  4148. }
  4149. dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
  4150. wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
  4151. }
  4152. if (q_vector->rx.ring) {
  4153. int q = q_vector->rx.ring->reg_idx;
  4154. u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
  4155. if (hw->mac.type == e1000_82575) {
  4156. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
  4157. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  4158. } else {
  4159. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
  4160. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  4161. E1000_DCA_RXCTRL_CPUID_SHIFT;
  4162. }
  4163. dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
  4164. dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
  4165. dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
  4166. wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
  4167. }
  4168. q_vector->cpu = cpu;
  4169. out_no_update:
  4170. put_cpu();
  4171. }
  4172. static void igb_setup_dca(struct igb_adapter *adapter)
  4173. {
  4174. struct e1000_hw *hw = &adapter->hw;
  4175. int i;
  4176. if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
  4177. return;
  4178. /* Always use CB2 mode, difference is masked in the CB driver. */
  4179. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
  4180. for (i = 0; i < adapter->num_q_vectors; i++) {
  4181. adapter->q_vector[i]->cpu = -1;
  4182. igb_update_dca(adapter->q_vector[i]);
  4183. }
  4184. }
  4185. static int __igb_notify_dca(struct device *dev, void *data)
  4186. {
  4187. struct net_device *netdev = dev_get_drvdata(dev);
  4188. struct igb_adapter *adapter = netdev_priv(netdev);
  4189. struct pci_dev *pdev = adapter->pdev;
  4190. struct e1000_hw *hw = &adapter->hw;
  4191. unsigned long event = *(unsigned long *)data;
  4192. switch (event) {
  4193. case DCA_PROVIDER_ADD:
  4194. /* if already enabled, don't do it again */
  4195. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  4196. break;
  4197. if (dca_add_requester(dev) == 0) {
  4198. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  4199. dev_info(&pdev->dev, "DCA enabled\n");
  4200. igb_setup_dca(adapter);
  4201. break;
  4202. }
  4203. /* Fall Through since DCA is disabled. */
  4204. case DCA_PROVIDER_REMOVE:
  4205. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  4206. /* without this a class_device is left
  4207. * hanging around in the sysfs model */
  4208. dca_remove_requester(dev);
  4209. dev_info(&pdev->dev, "DCA disabled\n");
  4210. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  4211. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  4212. }
  4213. break;
  4214. }
  4215. return 0;
  4216. }
  4217. static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
  4218. void *p)
  4219. {
  4220. int ret_val;
  4221. ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
  4222. __igb_notify_dca);
  4223. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  4224. }
  4225. #endif /* CONFIG_IGB_DCA */
  4226. #ifdef CONFIG_PCI_IOV
  4227. static int igb_vf_configure(struct igb_adapter *adapter, int vf)
  4228. {
  4229. unsigned char mac_addr[ETH_ALEN];
  4230. struct pci_dev *pdev = adapter->pdev;
  4231. struct e1000_hw *hw = &adapter->hw;
  4232. struct pci_dev *pvfdev;
  4233. unsigned int device_id;
  4234. u16 thisvf_devfn;
  4235. random_ether_addr(mac_addr);
  4236. igb_set_vf_mac(adapter, vf, mac_addr);
  4237. switch (adapter->hw.mac.type) {
  4238. case e1000_82576:
  4239. device_id = IGB_82576_VF_DEV_ID;
  4240. /* VF Stride for 82576 is 2 */
  4241. thisvf_devfn = (pdev->devfn + 0x80 + (vf << 1)) |
  4242. (pdev->devfn & 1);
  4243. break;
  4244. case e1000_i350:
  4245. device_id = IGB_I350_VF_DEV_ID;
  4246. /* VF Stride for I350 is 4 */
  4247. thisvf_devfn = (pdev->devfn + 0x80 + (vf << 2)) |
  4248. (pdev->devfn & 3);
  4249. break;
  4250. default:
  4251. device_id = 0;
  4252. thisvf_devfn = 0;
  4253. break;
  4254. }
  4255. pvfdev = pci_get_device(hw->vendor_id, device_id, NULL);
  4256. while (pvfdev) {
  4257. if (pvfdev->devfn == thisvf_devfn)
  4258. break;
  4259. pvfdev = pci_get_device(hw->vendor_id,
  4260. device_id, pvfdev);
  4261. }
  4262. if (pvfdev)
  4263. adapter->vf_data[vf].vfdev = pvfdev;
  4264. else
  4265. dev_err(&pdev->dev,
  4266. "Couldn't find pci dev ptr for VF %4.4x\n",
  4267. thisvf_devfn);
  4268. return pvfdev != NULL;
  4269. }
  4270. static int igb_find_enabled_vfs(struct igb_adapter *adapter)
  4271. {
  4272. struct e1000_hw *hw = &adapter->hw;
  4273. struct pci_dev *pdev = adapter->pdev;
  4274. struct pci_dev *pvfdev;
  4275. u16 vf_devfn = 0;
  4276. u16 vf_stride;
  4277. unsigned int device_id;
  4278. int vfs_found = 0;
  4279. switch (adapter->hw.mac.type) {
  4280. case e1000_82576:
  4281. device_id = IGB_82576_VF_DEV_ID;
  4282. /* VF Stride for 82576 is 2 */
  4283. vf_stride = 2;
  4284. break;
  4285. case e1000_i350:
  4286. device_id = IGB_I350_VF_DEV_ID;
  4287. /* VF Stride for I350 is 4 */
  4288. vf_stride = 4;
  4289. break;
  4290. default:
  4291. device_id = 0;
  4292. vf_stride = 0;
  4293. break;
  4294. }
  4295. vf_devfn = pdev->devfn + 0x80;
  4296. pvfdev = pci_get_device(hw->vendor_id, device_id, NULL);
  4297. while (pvfdev) {
  4298. if (pvfdev->devfn == vf_devfn &&
  4299. (pvfdev->bus->number >= pdev->bus->number))
  4300. vfs_found++;
  4301. vf_devfn += vf_stride;
  4302. pvfdev = pci_get_device(hw->vendor_id,
  4303. device_id, pvfdev);
  4304. }
  4305. return vfs_found;
  4306. }
  4307. static int igb_check_vf_assignment(struct igb_adapter *adapter)
  4308. {
  4309. int i;
  4310. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  4311. if (adapter->vf_data[i].vfdev) {
  4312. if (adapter->vf_data[i].vfdev->dev_flags &
  4313. PCI_DEV_FLAGS_ASSIGNED)
  4314. return true;
  4315. }
  4316. }
  4317. return false;
  4318. }
  4319. #endif
  4320. static void igb_ping_all_vfs(struct igb_adapter *adapter)
  4321. {
  4322. struct e1000_hw *hw = &adapter->hw;
  4323. u32 ping;
  4324. int i;
  4325. for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
  4326. ping = E1000_PF_CONTROL_MSG;
  4327. if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
  4328. ping |= E1000_VT_MSGTYPE_CTS;
  4329. igb_write_mbx(hw, &ping, 1, i);
  4330. }
  4331. }
  4332. static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  4333. {
  4334. struct e1000_hw *hw = &adapter->hw;
  4335. u32 vmolr = rd32(E1000_VMOLR(vf));
  4336. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4337. vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
  4338. IGB_VF_FLAG_MULTI_PROMISC);
  4339. vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
  4340. if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
  4341. vmolr |= E1000_VMOLR_MPME;
  4342. vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
  4343. *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
  4344. } else {
  4345. /*
  4346. * if we have hashes and we are clearing a multicast promisc
  4347. * flag we need to write the hashes to the MTA as this step
  4348. * was previously skipped
  4349. */
  4350. if (vf_data->num_vf_mc_hashes > 30) {
  4351. vmolr |= E1000_VMOLR_MPME;
  4352. } else if (vf_data->num_vf_mc_hashes) {
  4353. int j;
  4354. vmolr |= E1000_VMOLR_ROMPE;
  4355. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  4356. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  4357. }
  4358. }
  4359. wr32(E1000_VMOLR(vf), vmolr);
  4360. /* there are flags left unprocessed, likely not supported */
  4361. if (*msgbuf & E1000_VT_MSGINFO_MASK)
  4362. return -EINVAL;
  4363. return 0;
  4364. }
  4365. static int igb_set_vf_multicasts(struct igb_adapter *adapter,
  4366. u32 *msgbuf, u32 vf)
  4367. {
  4368. int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  4369. u16 *hash_list = (u16 *)&msgbuf[1];
  4370. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4371. int i;
  4372. /* salt away the number of multicast addresses assigned
  4373. * to this VF for later use to restore when the PF multi cast
  4374. * list changes
  4375. */
  4376. vf_data->num_vf_mc_hashes = n;
  4377. /* only up to 30 hash values supported */
  4378. if (n > 30)
  4379. n = 30;
  4380. /* store the hashes for later use */
  4381. for (i = 0; i < n; i++)
  4382. vf_data->vf_mc_hashes[i] = hash_list[i];
  4383. /* Flush and reset the mta with the new values */
  4384. igb_set_rx_mode(adapter->netdev);
  4385. return 0;
  4386. }
  4387. static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
  4388. {
  4389. struct e1000_hw *hw = &adapter->hw;
  4390. struct vf_data_storage *vf_data;
  4391. int i, j;
  4392. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  4393. u32 vmolr = rd32(E1000_VMOLR(i));
  4394. vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
  4395. vf_data = &adapter->vf_data[i];
  4396. if ((vf_data->num_vf_mc_hashes > 30) ||
  4397. (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
  4398. vmolr |= E1000_VMOLR_MPME;
  4399. } else if (vf_data->num_vf_mc_hashes) {
  4400. vmolr |= E1000_VMOLR_ROMPE;
  4401. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  4402. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  4403. }
  4404. wr32(E1000_VMOLR(i), vmolr);
  4405. }
  4406. }
  4407. static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
  4408. {
  4409. struct e1000_hw *hw = &adapter->hw;
  4410. u32 pool_mask, reg, vid;
  4411. int i;
  4412. pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  4413. /* Find the vlan filter for this id */
  4414. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4415. reg = rd32(E1000_VLVF(i));
  4416. /* remove the vf from the pool */
  4417. reg &= ~pool_mask;
  4418. /* if pool is empty then remove entry from vfta */
  4419. if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
  4420. (reg & E1000_VLVF_VLANID_ENABLE)) {
  4421. reg = 0;
  4422. vid = reg & E1000_VLVF_VLANID_MASK;
  4423. igb_vfta_set(hw, vid, false);
  4424. }
  4425. wr32(E1000_VLVF(i), reg);
  4426. }
  4427. adapter->vf_data[vf].vlans_enabled = 0;
  4428. }
  4429. static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
  4430. {
  4431. struct e1000_hw *hw = &adapter->hw;
  4432. u32 reg, i;
  4433. /* The vlvf table only exists on 82576 hardware and newer */
  4434. if (hw->mac.type < e1000_82576)
  4435. return -1;
  4436. /* we only need to do this if VMDq is enabled */
  4437. if (!adapter->vfs_allocated_count)
  4438. return -1;
  4439. /* Find the vlan filter for this id */
  4440. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4441. reg = rd32(E1000_VLVF(i));
  4442. if ((reg & E1000_VLVF_VLANID_ENABLE) &&
  4443. vid == (reg & E1000_VLVF_VLANID_MASK))
  4444. break;
  4445. }
  4446. if (add) {
  4447. if (i == E1000_VLVF_ARRAY_SIZE) {
  4448. /* Did not find a matching VLAN ID entry that was
  4449. * enabled. Search for a free filter entry, i.e.
  4450. * one without the enable bit set
  4451. */
  4452. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4453. reg = rd32(E1000_VLVF(i));
  4454. if (!(reg & E1000_VLVF_VLANID_ENABLE))
  4455. break;
  4456. }
  4457. }
  4458. if (i < E1000_VLVF_ARRAY_SIZE) {
  4459. /* Found an enabled/available entry */
  4460. reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  4461. /* if !enabled we need to set this up in vfta */
  4462. if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
  4463. /* add VID to filter table */
  4464. igb_vfta_set(hw, vid, true);
  4465. reg |= E1000_VLVF_VLANID_ENABLE;
  4466. }
  4467. reg &= ~E1000_VLVF_VLANID_MASK;
  4468. reg |= vid;
  4469. wr32(E1000_VLVF(i), reg);
  4470. /* do not modify RLPML for PF devices */
  4471. if (vf >= adapter->vfs_allocated_count)
  4472. return 0;
  4473. if (!adapter->vf_data[vf].vlans_enabled) {
  4474. u32 size;
  4475. reg = rd32(E1000_VMOLR(vf));
  4476. size = reg & E1000_VMOLR_RLPML_MASK;
  4477. size += 4;
  4478. reg &= ~E1000_VMOLR_RLPML_MASK;
  4479. reg |= size;
  4480. wr32(E1000_VMOLR(vf), reg);
  4481. }
  4482. adapter->vf_data[vf].vlans_enabled++;
  4483. }
  4484. } else {
  4485. if (i < E1000_VLVF_ARRAY_SIZE) {
  4486. /* remove vf from the pool */
  4487. reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
  4488. /* if pool is empty then remove entry from vfta */
  4489. if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
  4490. reg = 0;
  4491. igb_vfta_set(hw, vid, false);
  4492. }
  4493. wr32(E1000_VLVF(i), reg);
  4494. /* do not modify RLPML for PF devices */
  4495. if (vf >= adapter->vfs_allocated_count)
  4496. return 0;
  4497. adapter->vf_data[vf].vlans_enabled--;
  4498. if (!adapter->vf_data[vf].vlans_enabled) {
  4499. u32 size;
  4500. reg = rd32(E1000_VMOLR(vf));
  4501. size = reg & E1000_VMOLR_RLPML_MASK;
  4502. size -= 4;
  4503. reg &= ~E1000_VMOLR_RLPML_MASK;
  4504. reg |= size;
  4505. wr32(E1000_VMOLR(vf), reg);
  4506. }
  4507. }
  4508. }
  4509. return 0;
  4510. }
  4511. static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
  4512. {
  4513. struct e1000_hw *hw = &adapter->hw;
  4514. if (vid)
  4515. wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
  4516. else
  4517. wr32(E1000_VMVIR(vf), 0);
  4518. }
  4519. static int igb_ndo_set_vf_vlan(struct net_device *netdev,
  4520. int vf, u16 vlan, u8 qos)
  4521. {
  4522. int err = 0;
  4523. struct igb_adapter *adapter = netdev_priv(netdev);
  4524. if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
  4525. return -EINVAL;
  4526. if (vlan || qos) {
  4527. err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
  4528. if (err)
  4529. goto out;
  4530. igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
  4531. igb_set_vmolr(adapter, vf, !vlan);
  4532. adapter->vf_data[vf].pf_vlan = vlan;
  4533. adapter->vf_data[vf].pf_qos = qos;
  4534. dev_info(&adapter->pdev->dev,
  4535. "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
  4536. if (test_bit(__IGB_DOWN, &adapter->state)) {
  4537. dev_warn(&adapter->pdev->dev,
  4538. "The VF VLAN has been set,"
  4539. " but the PF device is not up.\n");
  4540. dev_warn(&adapter->pdev->dev,
  4541. "Bring the PF device up before"
  4542. " attempting to use the VF device.\n");
  4543. }
  4544. } else {
  4545. igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
  4546. false, vf);
  4547. igb_set_vmvir(adapter, vlan, vf);
  4548. igb_set_vmolr(adapter, vf, true);
  4549. adapter->vf_data[vf].pf_vlan = 0;
  4550. adapter->vf_data[vf].pf_qos = 0;
  4551. }
  4552. out:
  4553. return err;
  4554. }
  4555. static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  4556. {
  4557. int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  4558. int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
  4559. return igb_vlvf_set(adapter, vid, add, vf);
  4560. }
  4561. static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
  4562. {
  4563. /* clear flags - except flag that indicates PF has set the MAC */
  4564. adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
  4565. adapter->vf_data[vf].last_nack = jiffies;
  4566. /* reset offloads to defaults */
  4567. igb_set_vmolr(adapter, vf, true);
  4568. /* reset vlans for device */
  4569. igb_clear_vf_vfta(adapter, vf);
  4570. if (adapter->vf_data[vf].pf_vlan)
  4571. igb_ndo_set_vf_vlan(adapter->netdev, vf,
  4572. adapter->vf_data[vf].pf_vlan,
  4573. adapter->vf_data[vf].pf_qos);
  4574. else
  4575. igb_clear_vf_vfta(adapter, vf);
  4576. /* reset multicast table array for vf */
  4577. adapter->vf_data[vf].num_vf_mc_hashes = 0;
  4578. /* Flush and reset the mta with the new values */
  4579. igb_set_rx_mode(adapter->netdev);
  4580. }
  4581. static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
  4582. {
  4583. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  4584. /* generate a new mac address as we were hotplug removed/added */
  4585. if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
  4586. random_ether_addr(vf_mac);
  4587. /* process remaining reset events */
  4588. igb_vf_reset(adapter, vf);
  4589. }
  4590. static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
  4591. {
  4592. struct e1000_hw *hw = &adapter->hw;
  4593. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  4594. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  4595. u32 reg, msgbuf[3];
  4596. u8 *addr = (u8 *)(&msgbuf[1]);
  4597. /* process all the same items cleared in a function level reset */
  4598. igb_vf_reset(adapter, vf);
  4599. /* set vf mac address */
  4600. igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
  4601. /* enable transmit and receive for vf */
  4602. reg = rd32(E1000_VFTE);
  4603. wr32(E1000_VFTE, reg | (1 << vf));
  4604. reg = rd32(E1000_VFRE);
  4605. wr32(E1000_VFRE, reg | (1 << vf));
  4606. adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
  4607. /* reply to reset with ack and vf mac address */
  4608. msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
  4609. memcpy(addr, vf_mac, 6);
  4610. igb_write_mbx(hw, msgbuf, 3, vf);
  4611. }
  4612. static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
  4613. {
  4614. /*
  4615. * The VF MAC Address is stored in a packed array of bytes
  4616. * starting at the second 32 bit word of the msg array
  4617. */
  4618. unsigned char *addr = (char *)&msg[1];
  4619. int err = -1;
  4620. if (is_valid_ether_addr(addr))
  4621. err = igb_set_vf_mac(adapter, vf, addr);
  4622. return err;
  4623. }
  4624. static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
  4625. {
  4626. struct e1000_hw *hw = &adapter->hw;
  4627. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4628. u32 msg = E1000_VT_MSGTYPE_NACK;
  4629. /* if device isn't clear to send it shouldn't be reading either */
  4630. if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
  4631. time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
  4632. igb_write_mbx(hw, &msg, 1, vf);
  4633. vf_data->last_nack = jiffies;
  4634. }
  4635. }
  4636. static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
  4637. {
  4638. struct pci_dev *pdev = adapter->pdev;
  4639. u32 msgbuf[E1000_VFMAILBOX_SIZE];
  4640. struct e1000_hw *hw = &adapter->hw;
  4641. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4642. s32 retval;
  4643. retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
  4644. if (retval) {
  4645. /* if receive failed revoke VF CTS stats and restart init */
  4646. dev_err(&pdev->dev, "Error receiving message from VF\n");
  4647. vf_data->flags &= ~IGB_VF_FLAG_CTS;
  4648. if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
  4649. return;
  4650. goto out;
  4651. }
  4652. /* this is a message we already processed, do nothing */
  4653. if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
  4654. return;
  4655. /*
  4656. * until the vf completes a reset it should not be
  4657. * allowed to start any configuration.
  4658. */
  4659. if (msgbuf[0] == E1000_VF_RESET) {
  4660. igb_vf_reset_msg(adapter, vf);
  4661. return;
  4662. }
  4663. if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
  4664. if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
  4665. return;
  4666. retval = -1;
  4667. goto out;
  4668. }
  4669. switch ((msgbuf[0] & 0xFFFF)) {
  4670. case E1000_VF_SET_MAC_ADDR:
  4671. retval = -EINVAL;
  4672. if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
  4673. retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
  4674. else
  4675. dev_warn(&pdev->dev,
  4676. "VF %d attempted to override administratively "
  4677. "set MAC address\nReload the VF driver to "
  4678. "resume operations\n", vf);
  4679. break;
  4680. case E1000_VF_SET_PROMISC:
  4681. retval = igb_set_vf_promisc(adapter, msgbuf, vf);
  4682. break;
  4683. case E1000_VF_SET_MULTICAST:
  4684. retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
  4685. break;
  4686. case E1000_VF_SET_LPE:
  4687. retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
  4688. break;
  4689. case E1000_VF_SET_VLAN:
  4690. retval = -1;
  4691. if (vf_data->pf_vlan)
  4692. dev_warn(&pdev->dev,
  4693. "VF %d attempted to override administratively "
  4694. "set VLAN tag\nReload the VF driver to "
  4695. "resume operations\n", vf);
  4696. else
  4697. retval = igb_set_vf_vlan(adapter, msgbuf, vf);
  4698. break;
  4699. default:
  4700. dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
  4701. retval = -1;
  4702. break;
  4703. }
  4704. msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
  4705. out:
  4706. /* notify the VF of the results of what it sent us */
  4707. if (retval)
  4708. msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
  4709. else
  4710. msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
  4711. igb_write_mbx(hw, msgbuf, 1, vf);
  4712. }
  4713. static void igb_msg_task(struct igb_adapter *adapter)
  4714. {
  4715. struct e1000_hw *hw = &adapter->hw;
  4716. u32 vf;
  4717. for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
  4718. /* process any reset requests */
  4719. if (!igb_check_for_rst(hw, vf))
  4720. igb_vf_reset_event(adapter, vf);
  4721. /* process any messages pending */
  4722. if (!igb_check_for_msg(hw, vf))
  4723. igb_rcv_msg_from_vf(adapter, vf);
  4724. /* process any acks */
  4725. if (!igb_check_for_ack(hw, vf))
  4726. igb_rcv_ack_from_vf(adapter, vf);
  4727. }
  4728. }
  4729. /**
  4730. * igb_set_uta - Set unicast filter table address
  4731. * @adapter: board private structure
  4732. *
  4733. * The unicast table address is a register array of 32-bit registers.
  4734. * The table is meant to be used in a way similar to how the MTA is used
  4735. * however due to certain limitations in the hardware it is necessary to
  4736. * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
  4737. * enable bit to allow vlan tag stripping when promiscuous mode is enabled
  4738. **/
  4739. static void igb_set_uta(struct igb_adapter *adapter)
  4740. {
  4741. struct e1000_hw *hw = &adapter->hw;
  4742. int i;
  4743. /* The UTA table only exists on 82576 hardware and newer */
  4744. if (hw->mac.type < e1000_82576)
  4745. return;
  4746. /* we only need to do this if VMDq is enabled */
  4747. if (!adapter->vfs_allocated_count)
  4748. return;
  4749. for (i = 0; i < hw->mac.uta_reg_count; i++)
  4750. array_wr32(E1000_UTA, i, ~0);
  4751. }
  4752. /**
  4753. * igb_intr_msi - Interrupt Handler
  4754. * @irq: interrupt number
  4755. * @data: pointer to a network interface device structure
  4756. **/
  4757. static irqreturn_t igb_intr_msi(int irq, void *data)
  4758. {
  4759. struct igb_adapter *adapter = data;
  4760. struct igb_q_vector *q_vector = adapter->q_vector[0];
  4761. struct e1000_hw *hw = &adapter->hw;
  4762. /* read ICR disables interrupts using IAM */
  4763. u32 icr = rd32(E1000_ICR);
  4764. igb_write_itr(q_vector);
  4765. if (icr & E1000_ICR_DRSTA)
  4766. schedule_work(&adapter->reset_task);
  4767. if (icr & E1000_ICR_DOUTSYNC) {
  4768. /* HW is reporting DMA is out of sync */
  4769. adapter->stats.doosync++;
  4770. }
  4771. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  4772. hw->mac.get_link_status = 1;
  4773. if (!test_bit(__IGB_DOWN, &adapter->state))
  4774. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4775. }
  4776. napi_schedule(&q_vector->napi);
  4777. return IRQ_HANDLED;
  4778. }
  4779. /**
  4780. * igb_intr - Legacy Interrupt Handler
  4781. * @irq: interrupt number
  4782. * @data: pointer to a network interface device structure
  4783. **/
  4784. static irqreturn_t igb_intr(int irq, void *data)
  4785. {
  4786. struct igb_adapter *adapter = data;
  4787. struct igb_q_vector *q_vector = adapter->q_vector[0];
  4788. struct e1000_hw *hw = &adapter->hw;
  4789. /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
  4790. * need for the IMC write */
  4791. u32 icr = rd32(E1000_ICR);
  4792. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  4793. * not set, then the adapter didn't send an interrupt */
  4794. if (!(icr & E1000_ICR_INT_ASSERTED))
  4795. return IRQ_NONE;
  4796. igb_write_itr(q_vector);
  4797. if (icr & E1000_ICR_DRSTA)
  4798. schedule_work(&adapter->reset_task);
  4799. if (icr & E1000_ICR_DOUTSYNC) {
  4800. /* HW is reporting DMA is out of sync */
  4801. adapter->stats.doosync++;
  4802. }
  4803. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  4804. hw->mac.get_link_status = 1;
  4805. /* guard against interrupt when we're going down */
  4806. if (!test_bit(__IGB_DOWN, &adapter->state))
  4807. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4808. }
  4809. napi_schedule(&q_vector->napi);
  4810. return IRQ_HANDLED;
  4811. }
  4812. static void igb_ring_irq_enable(struct igb_q_vector *q_vector)
  4813. {
  4814. struct igb_adapter *adapter = q_vector->adapter;
  4815. struct e1000_hw *hw = &adapter->hw;
  4816. if ((q_vector->rx.ring && (adapter->rx_itr_setting & 3)) ||
  4817. (!q_vector->rx.ring && (adapter->tx_itr_setting & 3))) {
  4818. if ((adapter->num_q_vectors == 1) && !adapter->vf_data)
  4819. igb_set_itr(q_vector);
  4820. else
  4821. igb_update_ring_itr(q_vector);
  4822. }
  4823. if (!test_bit(__IGB_DOWN, &adapter->state)) {
  4824. if (adapter->msix_entries)
  4825. wr32(E1000_EIMS, q_vector->eims_value);
  4826. else
  4827. igb_irq_enable(adapter);
  4828. }
  4829. }
  4830. /**
  4831. * igb_poll - NAPI Rx polling callback
  4832. * @napi: napi polling structure
  4833. * @budget: count of how many packets we should handle
  4834. **/
  4835. static int igb_poll(struct napi_struct *napi, int budget)
  4836. {
  4837. struct igb_q_vector *q_vector = container_of(napi,
  4838. struct igb_q_vector,
  4839. napi);
  4840. bool clean_complete = true;
  4841. #ifdef CONFIG_IGB_DCA
  4842. if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
  4843. igb_update_dca(q_vector);
  4844. #endif
  4845. if (q_vector->tx.ring)
  4846. clean_complete = igb_clean_tx_irq(q_vector);
  4847. if (q_vector->rx.ring)
  4848. clean_complete &= igb_clean_rx_irq(q_vector, budget);
  4849. /* If all work not completed, return budget and keep polling */
  4850. if (!clean_complete)
  4851. return budget;
  4852. /* If not enough Rx work done, exit the polling mode */
  4853. napi_complete(napi);
  4854. igb_ring_irq_enable(q_vector);
  4855. return 0;
  4856. }
  4857. /**
  4858. * igb_systim_to_hwtstamp - convert system time value to hw timestamp
  4859. * @adapter: board private structure
  4860. * @shhwtstamps: timestamp structure to update
  4861. * @regval: unsigned 64bit system time value.
  4862. *
  4863. * We need to convert the system time value stored in the RX/TXSTMP registers
  4864. * into a hwtstamp which can be used by the upper level timestamping functions
  4865. */
  4866. static void igb_systim_to_hwtstamp(struct igb_adapter *adapter,
  4867. struct skb_shared_hwtstamps *shhwtstamps,
  4868. u64 regval)
  4869. {
  4870. u64 ns;
  4871. /*
  4872. * The 82580 starts with 1ns at bit 0 in RX/TXSTMPL, shift this up to
  4873. * 24 to match clock shift we setup earlier.
  4874. */
  4875. if (adapter->hw.mac.type >= e1000_82580)
  4876. regval <<= IGB_82580_TSYNC_SHIFT;
  4877. ns = timecounter_cyc2time(&adapter->clock, regval);
  4878. timecompare_update(&adapter->compare, ns);
  4879. memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
  4880. shhwtstamps->hwtstamp = ns_to_ktime(ns);
  4881. shhwtstamps->syststamp = timecompare_transform(&adapter->compare, ns);
  4882. }
  4883. /**
  4884. * igb_tx_hwtstamp - utility function which checks for TX time stamp
  4885. * @q_vector: pointer to q_vector containing needed info
  4886. * @buffer: pointer to igb_tx_buffer structure
  4887. *
  4888. * If we were asked to do hardware stamping and such a time stamp is
  4889. * available, then it must have been for this skb here because we only
  4890. * allow only one such packet into the queue.
  4891. */
  4892. static void igb_tx_hwtstamp(struct igb_q_vector *q_vector,
  4893. struct igb_tx_buffer *buffer_info)
  4894. {
  4895. struct igb_adapter *adapter = q_vector->adapter;
  4896. struct e1000_hw *hw = &adapter->hw;
  4897. struct skb_shared_hwtstamps shhwtstamps;
  4898. u64 regval;
  4899. /* if skb does not support hw timestamp or TX stamp not valid exit */
  4900. if (likely(!(buffer_info->tx_flags & IGB_TX_FLAGS_TSTAMP)) ||
  4901. !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID))
  4902. return;
  4903. regval = rd32(E1000_TXSTMPL);
  4904. regval |= (u64)rd32(E1000_TXSTMPH) << 32;
  4905. igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
  4906. skb_tstamp_tx(buffer_info->skb, &shhwtstamps);
  4907. }
  4908. /**
  4909. * igb_clean_tx_irq - Reclaim resources after transmit completes
  4910. * @q_vector: pointer to q_vector containing needed info
  4911. * returns true if ring is completely cleaned
  4912. **/
  4913. static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
  4914. {
  4915. struct igb_adapter *adapter = q_vector->adapter;
  4916. struct igb_ring *tx_ring = q_vector->tx.ring;
  4917. struct igb_tx_buffer *tx_buffer;
  4918. union e1000_adv_tx_desc *tx_desc, *eop_desc;
  4919. unsigned int total_bytes = 0, total_packets = 0;
  4920. unsigned int budget = q_vector->tx.work_limit;
  4921. unsigned int i = tx_ring->next_to_clean;
  4922. if (test_bit(__IGB_DOWN, &adapter->state))
  4923. return true;
  4924. tx_buffer = &tx_ring->tx_buffer_info[i];
  4925. tx_desc = IGB_TX_DESC(tx_ring, i);
  4926. i -= tx_ring->count;
  4927. for (; budget; budget--) {
  4928. eop_desc = tx_buffer->next_to_watch;
  4929. /* prevent any other reads prior to eop_desc */
  4930. rmb();
  4931. /* if next_to_watch is not set then there is no work pending */
  4932. if (!eop_desc)
  4933. break;
  4934. /* if DD is not set pending work has not been completed */
  4935. if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))
  4936. break;
  4937. /* clear next_to_watch to prevent false hangs */
  4938. tx_buffer->next_to_watch = NULL;
  4939. /* update the statistics for this packet */
  4940. total_bytes += tx_buffer->bytecount;
  4941. total_packets += tx_buffer->gso_segs;
  4942. /* retrieve hardware timestamp */
  4943. igb_tx_hwtstamp(q_vector, tx_buffer);
  4944. /* free the skb */
  4945. dev_kfree_skb_any(tx_buffer->skb);
  4946. tx_buffer->skb = NULL;
  4947. /* unmap skb header data */
  4948. dma_unmap_single(tx_ring->dev,
  4949. tx_buffer->dma,
  4950. tx_buffer->length,
  4951. DMA_TO_DEVICE);
  4952. /* clear last DMA location and unmap remaining buffers */
  4953. while (tx_desc != eop_desc) {
  4954. tx_buffer->dma = 0;
  4955. tx_buffer++;
  4956. tx_desc++;
  4957. i++;
  4958. if (unlikely(!i)) {
  4959. i -= tx_ring->count;
  4960. tx_buffer = tx_ring->tx_buffer_info;
  4961. tx_desc = IGB_TX_DESC(tx_ring, 0);
  4962. }
  4963. /* unmap any remaining paged data */
  4964. if (tx_buffer->dma) {
  4965. dma_unmap_page(tx_ring->dev,
  4966. tx_buffer->dma,
  4967. tx_buffer->length,
  4968. DMA_TO_DEVICE);
  4969. }
  4970. }
  4971. /* clear last DMA location */
  4972. tx_buffer->dma = 0;
  4973. /* move us one more past the eop_desc for start of next pkt */
  4974. tx_buffer++;
  4975. tx_desc++;
  4976. i++;
  4977. if (unlikely(!i)) {
  4978. i -= tx_ring->count;
  4979. tx_buffer = tx_ring->tx_buffer_info;
  4980. tx_desc = IGB_TX_DESC(tx_ring, 0);
  4981. }
  4982. }
  4983. netdev_tx_completed_queue(txring_txq(tx_ring),
  4984. total_packets, total_bytes);
  4985. i += tx_ring->count;
  4986. tx_ring->next_to_clean = i;
  4987. u64_stats_update_begin(&tx_ring->tx_syncp);
  4988. tx_ring->tx_stats.bytes += total_bytes;
  4989. tx_ring->tx_stats.packets += total_packets;
  4990. u64_stats_update_end(&tx_ring->tx_syncp);
  4991. q_vector->tx.total_bytes += total_bytes;
  4992. q_vector->tx.total_packets += total_packets;
  4993. if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {
  4994. struct e1000_hw *hw = &adapter->hw;
  4995. eop_desc = tx_buffer->next_to_watch;
  4996. /* Detect a transmit hang in hardware, this serializes the
  4997. * check with the clearing of time_stamp and movement of i */
  4998. clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags);
  4999. if (eop_desc &&
  5000. time_after(jiffies, tx_buffer->time_stamp +
  5001. (adapter->tx_timeout_factor * HZ)) &&
  5002. !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
  5003. /* detected Tx unit hang */
  5004. dev_err(tx_ring->dev,
  5005. "Detected Tx Unit Hang\n"
  5006. " Tx Queue <%d>\n"
  5007. " TDH <%x>\n"
  5008. " TDT <%x>\n"
  5009. " next_to_use <%x>\n"
  5010. " next_to_clean <%x>\n"
  5011. "buffer_info[next_to_clean]\n"
  5012. " time_stamp <%lx>\n"
  5013. " next_to_watch <%p>\n"
  5014. " jiffies <%lx>\n"
  5015. " desc.status <%x>\n",
  5016. tx_ring->queue_index,
  5017. rd32(E1000_TDH(tx_ring->reg_idx)),
  5018. readl(tx_ring->tail),
  5019. tx_ring->next_to_use,
  5020. tx_ring->next_to_clean,
  5021. tx_buffer->time_stamp,
  5022. eop_desc,
  5023. jiffies,
  5024. eop_desc->wb.status);
  5025. netif_stop_subqueue(tx_ring->netdev,
  5026. tx_ring->queue_index);
  5027. /* we are about to reset, no point in enabling stuff */
  5028. return true;
  5029. }
  5030. }
  5031. if (unlikely(total_packets &&
  5032. netif_carrier_ok(tx_ring->netdev) &&
  5033. igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
  5034. /* Make sure that anybody stopping the queue after this
  5035. * sees the new next_to_clean.
  5036. */
  5037. smp_mb();
  5038. if (__netif_subqueue_stopped(tx_ring->netdev,
  5039. tx_ring->queue_index) &&
  5040. !(test_bit(__IGB_DOWN, &adapter->state))) {
  5041. netif_wake_subqueue(tx_ring->netdev,
  5042. tx_ring->queue_index);
  5043. u64_stats_update_begin(&tx_ring->tx_syncp);
  5044. tx_ring->tx_stats.restart_queue++;
  5045. u64_stats_update_end(&tx_ring->tx_syncp);
  5046. }
  5047. }
  5048. return !!budget;
  5049. }
  5050. static inline void igb_rx_checksum(struct igb_ring *ring,
  5051. union e1000_adv_rx_desc *rx_desc,
  5052. struct sk_buff *skb)
  5053. {
  5054. skb_checksum_none_assert(skb);
  5055. /* Ignore Checksum bit is set */
  5056. if (igb_test_staterr(rx_desc, E1000_RXD_STAT_IXSM))
  5057. return;
  5058. /* Rx checksum disabled via ethtool */
  5059. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  5060. return;
  5061. /* TCP/UDP checksum error bit is set */
  5062. if (igb_test_staterr(rx_desc,
  5063. E1000_RXDEXT_STATERR_TCPE |
  5064. E1000_RXDEXT_STATERR_IPE)) {
  5065. /*
  5066. * work around errata with sctp packets where the TCPE aka
  5067. * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
  5068. * packets, (aka let the stack check the crc32c)
  5069. */
  5070. if (!((skb->len == 60) &&
  5071. test_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags))) {
  5072. u64_stats_update_begin(&ring->rx_syncp);
  5073. ring->rx_stats.csum_err++;
  5074. u64_stats_update_end(&ring->rx_syncp);
  5075. }
  5076. /* let the stack verify checksum errors */
  5077. return;
  5078. }
  5079. /* It must be a TCP or UDP packet with a valid checksum */
  5080. if (igb_test_staterr(rx_desc, E1000_RXD_STAT_TCPCS |
  5081. E1000_RXD_STAT_UDPCS))
  5082. skb->ip_summed = CHECKSUM_UNNECESSARY;
  5083. dev_dbg(ring->dev, "cksum success: bits %08X\n",
  5084. le32_to_cpu(rx_desc->wb.upper.status_error));
  5085. }
  5086. static inline void igb_rx_hash(struct igb_ring *ring,
  5087. union e1000_adv_rx_desc *rx_desc,
  5088. struct sk_buff *skb)
  5089. {
  5090. if (ring->netdev->features & NETIF_F_RXHASH)
  5091. skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
  5092. }
  5093. static void igb_rx_hwtstamp(struct igb_q_vector *q_vector,
  5094. union e1000_adv_rx_desc *rx_desc,
  5095. struct sk_buff *skb)
  5096. {
  5097. struct igb_adapter *adapter = q_vector->adapter;
  5098. struct e1000_hw *hw = &adapter->hw;
  5099. u64 regval;
  5100. if (!igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP |
  5101. E1000_RXDADV_STAT_TS))
  5102. return;
  5103. /*
  5104. * If this bit is set, then the RX registers contain the time stamp. No
  5105. * other packet will be time stamped until we read these registers, so
  5106. * read the registers to make them available again. Because only one
  5107. * packet can be time stamped at a time, we know that the register
  5108. * values must belong to this one here and therefore we don't need to
  5109. * compare any of the additional attributes stored for it.
  5110. *
  5111. * If nothing went wrong, then it should have a shared tx_flags that we
  5112. * can turn into a skb_shared_hwtstamps.
  5113. */
  5114. if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
  5115. u32 *stamp = (u32 *)skb->data;
  5116. regval = le32_to_cpu(*(stamp + 2));
  5117. regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32;
  5118. skb_pull(skb, IGB_TS_HDR_LEN);
  5119. } else {
  5120. if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
  5121. return;
  5122. regval = rd32(E1000_RXSTMPL);
  5123. regval |= (u64)rd32(E1000_RXSTMPH) << 32;
  5124. }
  5125. igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
  5126. }
  5127. static void igb_rx_vlan(struct igb_ring *ring,
  5128. union e1000_adv_rx_desc *rx_desc,
  5129. struct sk_buff *skb)
  5130. {
  5131. if (igb_test_staterr(rx_desc, E1000_RXD_STAT_VP)) {
  5132. u16 vid;
  5133. if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
  5134. test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &ring->flags))
  5135. vid = be16_to_cpu(rx_desc->wb.upper.vlan);
  5136. else
  5137. vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  5138. __vlan_hwaccel_put_tag(skb, vid);
  5139. }
  5140. }
  5141. static inline u16 igb_get_hlen(union e1000_adv_rx_desc *rx_desc)
  5142. {
  5143. /* HW will not DMA in data larger than the given buffer, even if it
  5144. * parses the (NFS, of course) header to be larger. In that case, it
  5145. * fills the header buffer and spills the rest into the page.
  5146. */
  5147. u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
  5148. E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
  5149. if (hlen > IGB_RX_HDR_LEN)
  5150. hlen = IGB_RX_HDR_LEN;
  5151. return hlen;
  5152. }
  5153. static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
  5154. {
  5155. struct igb_ring *rx_ring = q_vector->rx.ring;
  5156. union e1000_adv_rx_desc *rx_desc;
  5157. const int current_node = numa_node_id();
  5158. unsigned int total_bytes = 0, total_packets = 0;
  5159. u16 cleaned_count = igb_desc_unused(rx_ring);
  5160. u16 i = rx_ring->next_to_clean;
  5161. rx_desc = IGB_RX_DESC(rx_ring, i);
  5162. while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) {
  5163. struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
  5164. struct sk_buff *skb = buffer_info->skb;
  5165. union e1000_adv_rx_desc *next_rxd;
  5166. buffer_info->skb = NULL;
  5167. prefetch(skb->data);
  5168. i++;
  5169. if (i == rx_ring->count)
  5170. i = 0;
  5171. next_rxd = IGB_RX_DESC(rx_ring, i);
  5172. prefetch(next_rxd);
  5173. /*
  5174. * This memory barrier is needed to keep us from reading
  5175. * any other fields out of the rx_desc until we know the
  5176. * RXD_STAT_DD bit is set
  5177. */
  5178. rmb();
  5179. if (!skb_is_nonlinear(skb)) {
  5180. __skb_put(skb, igb_get_hlen(rx_desc));
  5181. dma_unmap_single(rx_ring->dev, buffer_info->dma,
  5182. IGB_RX_HDR_LEN,
  5183. DMA_FROM_DEVICE);
  5184. buffer_info->dma = 0;
  5185. }
  5186. if (rx_desc->wb.upper.length) {
  5187. u16 length = le16_to_cpu(rx_desc->wb.upper.length);
  5188. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  5189. buffer_info->page,
  5190. buffer_info->page_offset,
  5191. length);
  5192. skb->len += length;
  5193. skb->data_len += length;
  5194. skb->truesize += PAGE_SIZE / 2;
  5195. if ((page_count(buffer_info->page) != 1) ||
  5196. (page_to_nid(buffer_info->page) != current_node))
  5197. buffer_info->page = NULL;
  5198. else
  5199. get_page(buffer_info->page);
  5200. dma_unmap_page(rx_ring->dev, buffer_info->page_dma,
  5201. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  5202. buffer_info->page_dma = 0;
  5203. }
  5204. if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)) {
  5205. struct igb_rx_buffer *next_buffer;
  5206. next_buffer = &rx_ring->rx_buffer_info[i];
  5207. buffer_info->skb = next_buffer->skb;
  5208. buffer_info->dma = next_buffer->dma;
  5209. next_buffer->skb = skb;
  5210. next_buffer->dma = 0;
  5211. goto next_desc;
  5212. }
  5213. if (igb_test_staterr(rx_desc,
  5214. E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
  5215. dev_kfree_skb_any(skb);
  5216. goto next_desc;
  5217. }
  5218. igb_rx_hwtstamp(q_vector, rx_desc, skb);
  5219. igb_rx_hash(rx_ring, rx_desc, skb);
  5220. igb_rx_checksum(rx_ring, rx_desc, skb);
  5221. igb_rx_vlan(rx_ring, rx_desc, skb);
  5222. total_bytes += skb->len;
  5223. total_packets++;
  5224. skb->protocol = eth_type_trans(skb, rx_ring->netdev);
  5225. napi_gro_receive(&q_vector->napi, skb);
  5226. budget--;
  5227. next_desc:
  5228. if (!budget)
  5229. break;
  5230. cleaned_count++;
  5231. /* return some buffers to hardware, one at a time is too slow */
  5232. if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
  5233. igb_alloc_rx_buffers(rx_ring, cleaned_count);
  5234. cleaned_count = 0;
  5235. }
  5236. /* use prefetched values */
  5237. rx_desc = next_rxd;
  5238. }
  5239. rx_ring->next_to_clean = i;
  5240. u64_stats_update_begin(&rx_ring->rx_syncp);
  5241. rx_ring->rx_stats.packets += total_packets;
  5242. rx_ring->rx_stats.bytes += total_bytes;
  5243. u64_stats_update_end(&rx_ring->rx_syncp);
  5244. q_vector->rx.total_packets += total_packets;
  5245. q_vector->rx.total_bytes += total_bytes;
  5246. if (cleaned_count)
  5247. igb_alloc_rx_buffers(rx_ring, cleaned_count);
  5248. return !!budget;
  5249. }
  5250. static bool igb_alloc_mapped_skb(struct igb_ring *rx_ring,
  5251. struct igb_rx_buffer *bi)
  5252. {
  5253. struct sk_buff *skb = bi->skb;
  5254. dma_addr_t dma = bi->dma;
  5255. if (dma)
  5256. return true;
  5257. if (likely(!skb)) {
  5258. skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
  5259. IGB_RX_HDR_LEN);
  5260. bi->skb = skb;
  5261. if (!skb) {
  5262. rx_ring->rx_stats.alloc_failed++;
  5263. return false;
  5264. }
  5265. /* initialize skb for ring */
  5266. skb_record_rx_queue(skb, rx_ring->queue_index);
  5267. }
  5268. dma = dma_map_single(rx_ring->dev, skb->data,
  5269. IGB_RX_HDR_LEN, DMA_FROM_DEVICE);
  5270. if (dma_mapping_error(rx_ring->dev, dma)) {
  5271. rx_ring->rx_stats.alloc_failed++;
  5272. return false;
  5273. }
  5274. bi->dma = dma;
  5275. return true;
  5276. }
  5277. static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
  5278. struct igb_rx_buffer *bi)
  5279. {
  5280. struct page *page = bi->page;
  5281. dma_addr_t page_dma = bi->page_dma;
  5282. unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
  5283. if (page_dma)
  5284. return true;
  5285. if (!page) {
  5286. page = alloc_page(GFP_ATOMIC | __GFP_COLD);
  5287. bi->page = page;
  5288. if (unlikely(!page)) {
  5289. rx_ring->rx_stats.alloc_failed++;
  5290. return false;
  5291. }
  5292. }
  5293. page_dma = dma_map_page(rx_ring->dev, page,
  5294. page_offset, PAGE_SIZE / 2,
  5295. DMA_FROM_DEVICE);
  5296. if (dma_mapping_error(rx_ring->dev, page_dma)) {
  5297. rx_ring->rx_stats.alloc_failed++;
  5298. return false;
  5299. }
  5300. bi->page_dma = page_dma;
  5301. bi->page_offset = page_offset;
  5302. return true;
  5303. }
  5304. /**
  5305. * igb_alloc_rx_buffers - Replace used receive buffers; packet split
  5306. * @adapter: address of board private structure
  5307. **/
  5308. void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
  5309. {
  5310. union e1000_adv_rx_desc *rx_desc;
  5311. struct igb_rx_buffer *bi;
  5312. u16 i = rx_ring->next_to_use;
  5313. rx_desc = IGB_RX_DESC(rx_ring, i);
  5314. bi = &rx_ring->rx_buffer_info[i];
  5315. i -= rx_ring->count;
  5316. while (cleaned_count--) {
  5317. if (!igb_alloc_mapped_skb(rx_ring, bi))
  5318. break;
  5319. /* Refresh the desc even if buffer_addrs didn't change
  5320. * because each write-back erases this info. */
  5321. rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
  5322. if (!igb_alloc_mapped_page(rx_ring, bi))
  5323. break;
  5324. rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
  5325. rx_desc++;
  5326. bi++;
  5327. i++;
  5328. if (unlikely(!i)) {
  5329. rx_desc = IGB_RX_DESC(rx_ring, 0);
  5330. bi = rx_ring->rx_buffer_info;
  5331. i -= rx_ring->count;
  5332. }
  5333. /* clear the hdr_addr for the next_to_use descriptor */
  5334. rx_desc->read.hdr_addr = 0;
  5335. }
  5336. i += rx_ring->count;
  5337. if (rx_ring->next_to_use != i) {
  5338. rx_ring->next_to_use = i;
  5339. /* Force memory writes to complete before letting h/w
  5340. * know there are new descriptors to fetch. (Only
  5341. * applicable for weak-ordered memory model archs,
  5342. * such as IA-64). */
  5343. wmb();
  5344. writel(i, rx_ring->tail);
  5345. }
  5346. }
  5347. /**
  5348. * igb_mii_ioctl -
  5349. * @netdev:
  5350. * @ifreq:
  5351. * @cmd:
  5352. **/
  5353. static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5354. {
  5355. struct igb_adapter *adapter = netdev_priv(netdev);
  5356. struct mii_ioctl_data *data = if_mii(ifr);
  5357. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  5358. return -EOPNOTSUPP;
  5359. switch (cmd) {
  5360. case SIOCGMIIPHY:
  5361. data->phy_id = adapter->hw.phy.addr;
  5362. break;
  5363. case SIOCGMIIREG:
  5364. if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  5365. &data->val_out))
  5366. return -EIO;
  5367. break;
  5368. case SIOCSMIIREG:
  5369. default:
  5370. return -EOPNOTSUPP;
  5371. }
  5372. return 0;
  5373. }
  5374. /**
  5375. * igb_hwtstamp_ioctl - control hardware time stamping
  5376. * @netdev:
  5377. * @ifreq:
  5378. * @cmd:
  5379. *
  5380. * Outgoing time stamping can be enabled and disabled. Play nice and
  5381. * disable it when requested, although it shouldn't case any overhead
  5382. * when no packet needs it. At most one packet in the queue may be
  5383. * marked for time stamping, otherwise it would be impossible to tell
  5384. * for sure to which packet the hardware time stamp belongs.
  5385. *
  5386. * Incoming time stamping has to be configured via the hardware
  5387. * filters. Not all combinations are supported, in particular event
  5388. * type has to be specified. Matching the kind of event packet is
  5389. * not supported, with the exception of "all V2 events regardless of
  5390. * level 2 or 4".
  5391. *
  5392. **/
  5393. static int igb_hwtstamp_ioctl(struct net_device *netdev,
  5394. struct ifreq *ifr, int cmd)
  5395. {
  5396. struct igb_adapter *adapter = netdev_priv(netdev);
  5397. struct e1000_hw *hw = &adapter->hw;
  5398. struct hwtstamp_config config;
  5399. u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
  5400. u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  5401. u32 tsync_rx_cfg = 0;
  5402. bool is_l4 = false;
  5403. bool is_l2 = false;
  5404. u32 regval;
  5405. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  5406. return -EFAULT;
  5407. /* reserved for future extensions */
  5408. if (config.flags)
  5409. return -EINVAL;
  5410. switch (config.tx_type) {
  5411. case HWTSTAMP_TX_OFF:
  5412. tsync_tx_ctl = 0;
  5413. case HWTSTAMP_TX_ON:
  5414. break;
  5415. default:
  5416. return -ERANGE;
  5417. }
  5418. switch (config.rx_filter) {
  5419. case HWTSTAMP_FILTER_NONE:
  5420. tsync_rx_ctl = 0;
  5421. break;
  5422. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  5423. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  5424. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  5425. case HWTSTAMP_FILTER_ALL:
  5426. /*
  5427. * register TSYNCRXCFG must be set, therefore it is not
  5428. * possible to time stamp both Sync and Delay_Req messages
  5429. * => fall back to time stamping all packets
  5430. */
  5431. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  5432. config.rx_filter = HWTSTAMP_FILTER_ALL;
  5433. break;
  5434. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  5435. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  5436. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
  5437. is_l4 = true;
  5438. break;
  5439. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  5440. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  5441. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
  5442. is_l4 = true;
  5443. break;
  5444. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5445. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5446. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  5447. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
  5448. is_l2 = true;
  5449. is_l4 = true;
  5450. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5451. break;
  5452. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5453. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5454. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  5455. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
  5456. is_l2 = true;
  5457. is_l4 = true;
  5458. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5459. break;
  5460. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  5461. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5462. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5463. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  5464. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  5465. is_l2 = true;
  5466. is_l4 = true;
  5467. break;
  5468. default:
  5469. return -ERANGE;
  5470. }
  5471. if (hw->mac.type == e1000_82575) {
  5472. if (tsync_rx_ctl | tsync_tx_ctl)
  5473. return -EINVAL;
  5474. return 0;
  5475. }
  5476. /*
  5477. * Per-packet timestamping only works if all packets are
  5478. * timestamped, so enable timestamping in all packets as
  5479. * long as one rx filter was configured.
  5480. */
  5481. if ((hw->mac.type >= e1000_82580) && tsync_rx_ctl) {
  5482. tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  5483. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  5484. }
  5485. /* enable/disable TX */
  5486. regval = rd32(E1000_TSYNCTXCTL);
  5487. regval &= ~E1000_TSYNCTXCTL_ENABLED;
  5488. regval |= tsync_tx_ctl;
  5489. wr32(E1000_TSYNCTXCTL, regval);
  5490. /* enable/disable RX */
  5491. regval = rd32(E1000_TSYNCRXCTL);
  5492. regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
  5493. regval |= tsync_rx_ctl;
  5494. wr32(E1000_TSYNCRXCTL, regval);
  5495. /* define which PTP packets are time stamped */
  5496. wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
  5497. /* define ethertype filter for timestamped packets */
  5498. if (is_l2)
  5499. wr32(E1000_ETQF(3),
  5500. (E1000_ETQF_FILTER_ENABLE | /* enable filter */
  5501. E1000_ETQF_1588 | /* enable timestamping */
  5502. ETH_P_1588)); /* 1588 eth protocol type */
  5503. else
  5504. wr32(E1000_ETQF(3), 0);
  5505. #define PTP_PORT 319
  5506. /* L4 Queue Filter[3]: filter by destination port and protocol */
  5507. if (is_l4) {
  5508. u32 ftqf = (IPPROTO_UDP /* UDP */
  5509. | E1000_FTQF_VF_BP /* VF not compared */
  5510. | E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */
  5511. | E1000_FTQF_MASK); /* mask all inputs */
  5512. ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */
  5513. wr32(E1000_IMIR(3), htons(PTP_PORT));
  5514. wr32(E1000_IMIREXT(3),
  5515. (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
  5516. if (hw->mac.type == e1000_82576) {
  5517. /* enable source port check */
  5518. wr32(E1000_SPQF(3), htons(PTP_PORT));
  5519. ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
  5520. }
  5521. wr32(E1000_FTQF(3), ftqf);
  5522. } else {
  5523. wr32(E1000_FTQF(3), E1000_FTQF_MASK);
  5524. }
  5525. wrfl();
  5526. adapter->hwtstamp_config = config;
  5527. /* clear TX/RX time stamp registers, just to be sure */
  5528. regval = rd32(E1000_TXSTMPH);
  5529. regval = rd32(E1000_RXSTMPH);
  5530. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  5531. -EFAULT : 0;
  5532. }
  5533. /**
  5534. * igb_ioctl -
  5535. * @netdev:
  5536. * @ifreq:
  5537. * @cmd:
  5538. **/
  5539. static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5540. {
  5541. switch (cmd) {
  5542. case SIOCGMIIPHY:
  5543. case SIOCGMIIREG:
  5544. case SIOCSMIIREG:
  5545. return igb_mii_ioctl(netdev, ifr, cmd);
  5546. case SIOCSHWTSTAMP:
  5547. return igb_hwtstamp_ioctl(netdev, ifr, cmd);
  5548. default:
  5549. return -EOPNOTSUPP;
  5550. }
  5551. }
  5552. s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  5553. {
  5554. struct igb_adapter *adapter = hw->back;
  5555. u16 cap_offset;
  5556. cap_offset = adapter->pdev->pcie_cap;
  5557. if (!cap_offset)
  5558. return -E1000_ERR_CONFIG;
  5559. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  5560. return 0;
  5561. }
  5562. s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  5563. {
  5564. struct igb_adapter *adapter = hw->back;
  5565. u16 cap_offset;
  5566. cap_offset = adapter->pdev->pcie_cap;
  5567. if (!cap_offset)
  5568. return -E1000_ERR_CONFIG;
  5569. pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
  5570. return 0;
  5571. }
  5572. static void igb_vlan_mode(struct net_device *netdev, netdev_features_t features)
  5573. {
  5574. struct igb_adapter *adapter = netdev_priv(netdev);
  5575. struct e1000_hw *hw = &adapter->hw;
  5576. u32 ctrl, rctl;
  5577. bool enable = !!(features & NETIF_F_HW_VLAN_RX);
  5578. if (enable) {
  5579. /* enable VLAN tag insert/strip */
  5580. ctrl = rd32(E1000_CTRL);
  5581. ctrl |= E1000_CTRL_VME;
  5582. wr32(E1000_CTRL, ctrl);
  5583. /* Disable CFI check */
  5584. rctl = rd32(E1000_RCTL);
  5585. rctl &= ~E1000_RCTL_CFIEN;
  5586. wr32(E1000_RCTL, rctl);
  5587. } else {
  5588. /* disable VLAN tag insert/strip */
  5589. ctrl = rd32(E1000_CTRL);
  5590. ctrl &= ~E1000_CTRL_VME;
  5591. wr32(E1000_CTRL, ctrl);
  5592. }
  5593. igb_rlpml_set(adapter);
  5594. }
  5595. static int igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  5596. {
  5597. struct igb_adapter *adapter = netdev_priv(netdev);
  5598. struct e1000_hw *hw = &adapter->hw;
  5599. int pf_id = adapter->vfs_allocated_count;
  5600. /* attempt to add filter to vlvf array */
  5601. igb_vlvf_set(adapter, vid, true, pf_id);
  5602. /* add the filter since PF can receive vlans w/o entry in vlvf */
  5603. igb_vfta_set(hw, vid, true);
  5604. set_bit(vid, adapter->active_vlans);
  5605. return 0;
  5606. }
  5607. static int igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  5608. {
  5609. struct igb_adapter *adapter = netdev_priv(netdev);
  5610. struct e1000_hw *hw = &adapter->hw;
  5611. int pf_id = adapter->vfs_allocated_count;
  5612. s32 err;
  5613. /* remove vlan from VLVF table array */
  5614. err = igb_vlvf_set(adapter, vid, false, pf_id);
  5615. /* if vid was not present in VLVF just remove it from table */
  5616. if (err)
  5617. igb_vfta_set(hw, vid, false);
  5618. clear_bit(vid, adapter->active_vlans);
  5619. return 0;
  5620. }
  5621. static void igb_restore_vlan(struct igb_adapter *adapter)
  5622. {
  5623. u16 vid;
  5624. igb_vlan_mode(adapter->netdev, adapter->netdev->features);
  5625. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  5626. igb_vlan_rx_add_vid(adapter->netdev, vid);
  5627. }
  5628. int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
  5629. {
  5630. struct pci_dev *pdev = adapter->pdev;
  5631. struct e1000_mac_info *mac = &adapter->hw.mac;
  5632. mac->autoneg = 0;
  5633. /* Make sure dplx is at most 1 bit and lsb of speed is not set
  5634. * for the switch() below to work */
  5635. if ((spd & 1) || (dplx & ~1))
  5636. goto err_inval;
  5637. /* Fiber NIC's only allow 1000 Gbps Full duplex */
  5638. if ((adapter->hw.phy.media_type == e1000_media_type_internal_serdes) &&
  5639. spd != SPEED_1000 &&
  5640. dplx != DUPLEX_FULL)
  5641. goto err_inval;
  5642. switch (spd + dplx) {
  5643. case SPEED_10 + DUPLEX_HALF:
  5644. mac->forced_speed_duplex = ADVERTISE_10_HALF;
  5645. break;
  5646. case SPEED_10 + DUPLEX_FULL:
  5647. mac->forced_speed_duplex = ADVERTISE_10_FULL;
  5648. break;
  5649. case SPEED_100 + DUPLEX_HALF:
  5650. mac->forced_speed_duplex = ADVERTISE_100_HALF;
  5651. break;
  5652. case SPEED_100 + DUPLEX_FULL:
  5653. mac->forced_speed_duplex = ADVERTISE_100_FULL;
  5654. break;
  5655. case SPEED_1000 + DUPLEX_FULL:
  5656. mac->autoneg = 1;
  5657. adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
  5658. break;
  5659. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  5660. default:
  5661. goto err_inval;
  5662. }
  5663. return 0;
  5664. err_inval:
  5665. dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
  5666. return -EINVAL;
  5667. }
  5668. static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake,
  5669. bool runtime)
  5670. {
  5671. struct net_device *netdev = pci_get_drvdata(pdev);
  5672. struct igb_adapter *adapter = netdev_priv(netdev);
  5673. struct e1000_hw *hw = &adapter->hw;
  5674. u32 ctrl, rctl, status;
  5675. u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
  5676. #ifdef CONFIG_PM
  5677. int retval = 0;
  5678. #endif
  5679. netif_device_detach(netdev);
  5680. if (netif_running(netdev))
  5681. __igb_close(netdev, true);
  5682. igb_clear_interrupt_scheme(adapter);
  5683. #ifdef CONFIG_PM
  5684. retval = pci_save_state(pdev);
  5685. if (retval)
  5686. return retval;
  5687. #endif
  5688. status = rd32(E1000_STATUS);
  5689. if (status & E1000_STATUS_LU)
  5690. wufc &= ~E1000_WUFC_LNKC;
  5691. if (wufc) {
  5692. igb_setup_rctl(adapter);
  5693. igb_set_rx_mode(netdev);
  5694. /* turn on all-multi mode if wake on multicast is enabled */
  5695. if (wufc & E1000_WUFC_MC) {
  5696. rctl = rd32(E1000_RCTL);
  5697. rctl |= E1000_RCTL_MPE;
  5698. wr32(E1000_RCTL, rctl);
  5699. }
  5700. ctrl = rd32(E1000_CTRL);
  5701. /* advertise wake from D3Cold */
  5702. #define E1000_CTRL_ADVD3WUC 0x00100000
  5703. /* phy power management enable */
  5704. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  5705. ctrl |= E1000_CTRL_ADVD3WUC;
  5706. wr32(E1000_CTRL, ctrl);
  5707. /* Allow time for pending master requests to run */
  5708. igb_disable_pcie_master(hw);
  5709. wr32(E1000_WUC, E1000_WUC_PME_EN);
  5710. wr32(E1000_WUFC, wufc);
  5711. } else {
  5712. wr32(E1000_WUC, 0);
  5713. wr32(E1000_WUFC, 0);
  5714. }
  5715. *enable_wake = wufc || adapter->en_mng_pt;
  5716. if (!*enable_wake)
  5717. igb_power_down_link(adapter);
  5718. else
  5719. igb_power_up_link(adapter);
  5720. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  5721. * would have already happened in close and is redundant. */
  5722. igb_release_hw_control(adapter);
  5723. pci_disable_device(pdev);
  5724. return 0;
  5725. }
  5726. #ifdef CONFIG_PM
  5727. static int igb_suspend(struct device *dev)
  5728. {
  5729. int retval;
  5730. bool wake;
  5731. struct pci_dev *pdev = to_pci_dev(dev);
  5732. retval = __igb_shutdown(pdev, &wake, 0);
  5733. if (retval)
  5734. return retval;
  5735. if (wake) {
  5736. pci_prepare_to_sleep(pdev);
  5737. } else {
  5738. pci_wake_from_d3(pdev, false);
  5739. pci_set_power_state(pdev, PCI_D3hot);
  5740. }
  5741. return 0;
  5742. }
  5743. static int igb_resume(struct device *dev)
  5744. {
  5745. struct pci_dev *pdev = to_pci_dev(dev);
  5746. struct net_device *netdev = pci_get_drvdata(pdev);
  5747. struct igb_adapter *adapter = netdev_priv(netdev);
  5748. struct e1000_hw *hw = &adapter->hw;
  5749. u32 err;
  5750. pci_set_power_state(pdev, PCI_D0);
  5751. pci_restore_state(pdev);
  5752. pci_save_state(pdev);
  5753. err = pci_enable_device_mem(pdev);
  5754. if (err) {
  5755. dev_err(&pdev->dev,
  5756. "igb: Cannot enable PCI device from suspend\n");
  5757. return err;
  5758. }
  5759. pci_set_master(pdev);
  5760. pci_enable_wake(pdev, PCI_D3hot, 0);
  5761. pci_enable_wake(pdev, PCI_D3cold, 0);
  5762. if (!rtnl_is_locked()) {
  5763. /*
  5764. * shut up ASSERT_RTNL() warning in
  5765. * netif_set_real_num_tx/rx_queues.
  5766. */
  5767. rtnl_lock();
  5768. err = igb_init_interrupt_scheme(adapter);
  5769. rtnl_unlock();
  5770. } else {
  5771. err = igb_init_interrupt_scheme(adapter);
  5772. }
  5773. if (err) {
  5774. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  5775. return -ENOMEM;
  5776. }
  5777. igb_reset(adapter);
  5778. /* let the f/w know that the h/w is now under the control of the
  5779. * driver. */
  5780. igb_get_hw_control(adapter);
  5781. wr32(E1000_WUS, ~0);
  5782. if (netdev->flags & IFF_UP) {
  5783. err = __igb_open(netdev, true);
  5784. if (err)
  5785. return err;
  5786. }
  5787. netif_device_attach(netdev);
  5788. return 0;
  5789. }
  5790. #ifdef CONFIG_PM_RUNTIME
  5791. static int igb_runtime_idle(struct device *dev)
  5792. {
  5793. struct pci_dev *pdev = to_pci_dev(dev);
  5794. struct net_device *netdev = pci_get_drvdata(pdev);
  5795. struct igb_adapter *adapter = netdev_priv(netdev);
  5796. if (!igb_has_link(adapter))
  5797. pm_schedule_suspend(dev, MSEC_PER_SEC * 5);
  5798. return -EBUSY;
  5799. }
  5800. static int igb_runtime_suspend(struct device *dev)
  5801. {
  5802. struct pci_dev *pdev = to_pci_dev(dev);
  5803. int retval;
  5804. bool wake;
  5805. retval = __igb_shutdown(pdev, &wake, 1);
  5806. if (retval)
  5807. return retval;
  5808. if (wake) {
  5809. pci_prepare_to_sleep(pdev);
  5810. } else {
  5811. pci_wake_from_d3(pdev, false);
  5812. pci_set_power_state(pdev, PCI_D3hot);
  5813. }
  5814. return 0;
  5815. }
  5816. static int igb_runtime_resume(struct device *dev)
  5817. {
  5818. return igb_resume(dev);
  5819. }
  5820. #endif /* CONFIG_PM_RUNTIME */
  5821. #endif
  5822. static void igb_shutdown(struct pci_dev *pdev)
  5823. {
  5824. bool wake;
  5825. __igb_shutdown(pdev, &wake, 0);
  5826. if (system_state == SYSTEM_POWER_OFF) {
  5827. pci_wake_from_d3(pdev, wake);
  5828. pci_set_power_state(pdev, PCI_D3hot);
  5829. }
  5830. }
  5831. #ifdef CONFIG_NET_POLL_CONTROLLER
  5832. /*
  5833. * Polling 'interrupt' - used by things like netconsole to send skbs
  5834. * without having to re-enable interrupts. It's not called while
  5835. * the interrupt routine is executing.
  5836. */
  5837. static void igb_netpoll(struct net_device *netdev)
  5838. {
  5839. struct igb_adapter *adapter = netdev_priv(netdev);
  5840. struct e1000_hw *hw = &adapter->hw;
  5841. struct igb_q_vector *q_vector;
  5842. int i;
  5843. for (i = 0; i < adapter->num_q_vectors; i++) {
  5844. q_vector = adapter->q_vector[i];
  5845. if (adapter->msix_entries)
  5846. wr32(E1000_EIMC, q_vector->eims_value);
  5847. else
  5848. igb_irq_disable(adapter);
  5849. napi_schedule(&q_vector->napi);
  5850. }
  5851. }
  5852. #endif /* CONFIG_NET_POLL_CONTROLLER */
  5853. /**
  5854. * igb_io_error_detected - called when PCI error is detected
  5855. * @pdev: Pointer to PCI device
  5856. * @state: The current pci connection state
  5857. *
  5858. * This function is called after a PCI bus error affecting
  5859. * this device has been detected.
  5860. */
  5861. static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
  5862. pci_channel_state_t state)
  5863. {
  5864. struct net_device *netdev = pci_get_drvdata(pdev);
  5865. struct igb_adapter *adapter = netdev_priv(netdev);
  5866. netif_device_detach(netdev);
  5867. if (state == pci_channel_io_perm_failure)
  5868. return PCI_ERS_RESULT_DISCONNECT;
  5869. if (netif_running(netdev))
  5870. igb_down(adapter);
  5871. pci_disable_device(pdev);
  5872. /* Request a slot slot reset. */
  5873. return PCI_ERS_RESULT_NEED_RESET;
  5874. }
  5875. /**
  5876. * igb_io_slot_reset - called after the pci bus has been reset.
  5877. * @pdev: Pointer to PCI device
  5878. *
  5879. * Restart the card from scratch, as if from a cold-boot. Implementation
  5880. * resembles the first-half of the igb_resume routine.
  5881. */
  5882. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
  5883. {
  5884. struct net_device *netdev = pci_get_drvdata(pdev);
  5885. struct igb_adapter *adapter = netdev_priv(netdev);
  5886. struct e1000_hw *hw = &adapter->hw;
  5887. pci_ers_result_t result;
  5888. int err;
  5889. if (pci_enable_device_mem(pdev)) {
  5890. dev_err(&pdev->dev,
  5891. "Cannot re-enable PCI device after reset.\n");
  5892. result = PCI_ERS_RESULT_DISCONNECT;
  5893. } else {
  5894. pci_set_master(pdev);
  5895. pci_restore_state(pdev);
  5896. pci_save_state(pdev);
  5897. pci_enable_wake(pdev, PCI_D3hot, 0);
  5898. pci_enable_wake(pdev, PCI_D3cold, 0);
  5899. igb_reset(adapter);
  5900. wr32(E1000_WUS, ~0);
  5901. result = PCI_ERS_RESULT_RECOVERED;
  5902. }
  5903. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  5904. if (err) {
  5905. dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
  5906. "failed 0x%0x\n", err);
  5907. /* non-fatal, continue */
  5908. }
  5909. return result;
  5910. }
  5911. /**
  5912. * igb_io_resume - called when traffic can start flowing again.
  5913. * @pdev: Pointer to PCI device
  5914. *
  5915. * This callback is called when the error recovery driver tells us that
  5916. * its OK to resume normal operation. Implementation resembles the
  5917. * second-half of the igb_resume routine.
  5918. */
  5919. static void igb_io_resume(struct pci_dev *pdev)
  5920. {
  5921. struct net_device *netdev = pci_get_drvdata(pdev);
  5922. struct igb_adapter *adapter = netdev_priv(netdev);
  5923. if (netif_running(netdev)) {
  5924. if (igb_up(adapter)) {
  5925. dev_err(&pdev->dev, "igb_up failed after reset\n");
  5926. return;
  5927. }
  5928. }
  5929. netif_device_attach(netdev);
  5930. /* let the f/w know that the h/w is now under the control of the
  5931. * driver. */
  5932. igb_get_hw_control(adapter);
  5933. }
  5934. static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
  5935. u8 qsel)
  5936. {
  5937. u32 rar_low, rar_high;
  5938. struct e1000_hw *hw = &adapter->hw;
  5939. /* HW expects these in little endian so we reverse the byte order
  5940. * from network order (big endian) to little endian
  5941. */
  5942. rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
  5943. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  5944. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  5945. /* Indicate to hardware the Address is Valid. */
  5946. rar_high |= E1000_RAH_AV;
  5947. if (hw->mac.type == e1000_82575)
  5948. rar_high |= E1000_RAH_POOL_1 * qsel;
  5949. else
  5950. rar_high |= E1000_RAH_POOL_1 << qsel;
  5951. wr32(E1000_RAL(index), rar_low);
  5952. wrfl();
  5953. wr32(E1000_RAH(index), rar_high);
  5954. wrfl();
  5955. }
  5956. static int igb_set_vf_mac(struct igb_adapter *adapter,
  5957. int vf, unsigned char *mac_addr)
  5958. {
  5959. struct e1000_hw *hw = &adapter->hw;
  5960. /* VF MAC addresses start at end of receive addresses and moves
  5961. * torwards the first, as a result a collision should not be possible */
  5962. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  5963. memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
  5964. igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
  5965. return 0;
  5966. }
  5967. static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
  5968. {
  5969. struct igb_adapter *adapter = netdev_priv(netdev);
  5970. if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
  5971. return -EINVAL;
  5972. adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
  5973. dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
  5974. dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
  5975. " change effective.");
  5976. if (test_bit(__IGB_DOWN, &adapter->state)) {
  5977. dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
  5978. " but the PF device is not up.\n");
  5979. dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
  5980. " attempting to use the VF device.\n");
  5981. }
  5982. return igb_set_vf_mac(adapter, vf, mac);
  5983. }
  5984. static int igb_link_mbps(int internal_link_speed)
  5985. {
  5986. switch (internal_link_speed) {
  5987. case SPEED_100:
  5988. return 100;
  5989. case SPEED_1000:
  5990. return 1000;
  5991. default:
  5992. return 0;
  5993. }
  5994. }
  5995. static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
  5996. int link_speed)
  5997. {
  5998. int rf_dec, rf_int;
  5999. u32 bcnrc_val;
  6000. if (tx_rate != 0) {
  6001. /* Calculate the rate factor values to set */
  6002. rf_int = link_speed / tx_rate;
  6003. rf_dec = (link_speed - (rf_int * tx_rate));
  6004. rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
  6005. bcnrc_val = E1000_RTTBCNRC_RS_ENA;
  6006. bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
  6007. E1000_RTTBCNRC_RF_INT_MASK);
  6008. bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
  6009. } else {
  6010. bcnrc_val = 0;
  6011. }
  6012. wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
  6013. wr32(E1000_RTTBCNRC, bcnrc_val);
  6014. }
  6015. static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
  6016. {
  6017. int actual_link_speed, i;
  6018. bool reset_rate = false;
  6019. /* VF TX rate limit was not set or not supported */
  6020. if ((adapter->vf_rate_link_speed == 0) ||
  6021. (adapter->hw.mac.type != e1000_82576))
  6022. return;
  6023. actual_link_speed = igb_link_mbps(adapter->link_speed);
  6024. if (actual_link_speed != adapter->vf_rate_link_speed) {
  6025. reset_rate = true;
  6026. adapter->vf_rate_link_speed = 0;
  6027. dev_info(&adapter->pdev->dev,
  6028. "Link speed has been changed. VF Transmit "
  6029. "rate is disabled\n");
  6030. }
  6031. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  6032. if (reset_rate)
  6033. adapter->vf_data[i].tx_rate = 0;
  6034. igb_set_vf_rate_limit(&adapter->hw, i,
  6035. adapter->vf_data[i].tx_rate,
  6036. actual_link_speed);
  6037. }
  6038. }
  6039. static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
  6040. {
  6041. struct igb_adapter *adapter = netdev_priv(netdev);
  6042. struct e1000_hw *hw = &adapter->hw;
  6043. int actual_link_speed;
  6044. if (hw->mac.type != e1000_82576)
  6045. return -EOPNOTSUPP;
  6046. actual_link_speed = igb_link_mbps(adapter->link_speed);
  6047. if ((vf >= adapter->vfs_allocated_count) ||
  6048. (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
  6049. (tx_rate < 0) || (tx_rate > actual_link_speed))
  6050. return -EINVAL;
  6051. adapter->vf_rate_link_speed = actual_link_speed;
  6052. adapter->vf_data[vf].tx_rate = (u16)tx_rate;
  6053. igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
  6054. return 0;
  6055. }
  6056. static int igb_ndo_get_vf_config(struct net_device *netdev,
  6057. int vf, struct ifla_vf_info *ivi)
  6058. {
  6059. struct igb_adapter *adapter = netdev_priv(netdev);
  6060. if (vf >= adapter->vfs_allocated_count)
  6061. return -EINVAL;
  6062. ivi->vf = vf;
  6063. memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
  6064. ivi->tx_rate = adapter->vf_data[vf].tx_rate;
  6065. ivi->vlan = adapter->vf_data[vf].pf_vlan;
  6066. ivi->qos = adapter->vf_data[vf].pf_qos;
  6067. return 0;
  6068. }
  6069. static void igb_vmm_control(struct igb_adapter *adapter)
  6070. {
  6071. struct e1000_hw *hw = &adapter->hw;
  6072. u32 reg;
  6073. switch (hw->mac.type) {
  6074. case e1000_82575:
  6075. default:
  6076. /* replication is not supported for 82575 */
  6077. return;
  6078. case e1000_82576:
  6079. /* notify HW that the MAC is adding vlan tags */
  6080. reg = rd32(E1000_DTXCTL);
  6081. reg |= E1000_DTXCTL_VLAN_ADDED;
  6082. wr32(E1000_DTXCTL, reg);
  6083. case e1000_82580:
  6084. /* enable replication vlan tag stripping */
  6085. reg = rd32(E1000_RPLOLR);
  6086. reg |= E1000_RPLOLR_STRVLAN;
  6087. wr32(E1000_RPLOLR, reg);
  6088. case e1000_i350:
  6089. /* none of the above registers are supported by i350 */
  6090. break;
  6091. }
  6092. if (adapter->vfs_allocated_count) {
  6093. igb_vmdq_set_loopback_pf(hw, true);
  6094. igb_vmdq_set_replication_pf(hw, true);
  6095. igb_vmdq_set_anti_spoofing_pf(hw, true,
  6096. adapter->vfs_allocated_count);
  6097. } else {
  6098. igb_vmdq_set_loopback_pf(hw, false);
  6099. igb_vmdq_set_replication_pf(hw, false);
  6100. }
  6101. }
  6102. static void igb_init_dmac(struct igb_adapter *adapter, u32 pba)
  6103. {
  6104. struct e1000_hw *hw = &adapter->hw;
  6105. u32 dmac_thr;
  6106. u16 hwm;
  6107. if (hw->mac.type > e1000_82580) {
  6108. if (adapter->flags & IGB_FLAG_DMAC) {
  6109. u32 reg;
  6110. /* force threshold to 0. */
  6111. wr32(E1000_DMCTXTH, 0);
  6112. /*
  6113. * DMA Coalescing high water mark needs to be greater
  6114. * than the Rx threshold. Set hwm to PBA - max frame
  6115. * size in 16B units, capping it at PBA - 6KB.
  6116. */
  6117. hwm = 64 * pba - adapter->max_frame_size / 16;
  6118. if (hwm < 64 * (pba - 6))
  6119. hwm = 64 * (pba - 6);
  6120. reg = rd32(E1000_FCRTC);
  6121. reg &= ~E1000_FCRTC_RTH_COAL_MASK;
  6122. reg |= ((hwm << E1000_FCRTC_RTH_COAL_SHIFT)
  6123. & E1000_FCRTC_RTH_COAL_MASK);
  6124. wr32(E1000_FCRTC, reg);
  6125. /*
  6126. * Set the DMA Coalescing Rx threshold to PBA - 2 * max
  6127. * frame size, capping it at PBA - 10KB.
  6128. */
  6129. dmac_thr = pba - adapter->max_frame_size / 512;
  6130. if (dmac_thr < pba - 10)
  6131. dmac_thr = pba - 10;
  6132. reg = rd32(E1000_DMACR);
  6133. reg &= ~E1000_DMACR_DMACTHR_MASK;
  6134. reg |= ((dmac_thr << E1000_DMACR_DMACTHR_SHIFT)
  6135. & E1000_DMACR_DMACTHR_MASK);
  6136. /* transition to L0x or L1 if available..*/
  6137. reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
  6138. /* watchdog timer= +-1000 usec in 32usec intervals */
  6139. reg |= (1000 >> 5);
  6140. wr32(E1000_DMACR, reg);
  6141. /*
  6142. * no lower threshold to disable
  6143. * coalescing(smart fifb)-UTRESH=0
  6144. */
  6145. wr32(E1000_DMCRTRH, 0);
  6146. reg = (IGB_DMCTLX_DCFLUSH_DIS | 0x4);
  6147. wr32(E1000_DMCTLX, reg);
  6148. /*
  6149. * free space in tx packet buffer to wake from
  6150. * DMA coal
  6151. */
  6152. wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
  6153. (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
  6154. /*
  6155. * make low power state decision controlled
  6156. * by DMA coal
  6157. */
  6158. reg = rd32(E1000_PCIEMISC);
  6159. reg &= ~E1000_PCIEMISC_LX_DECISION;
  6160. wr32(E1000_PCIEMISC, reg);
  6161. } /* endif adapter->dmac is not disabled */
  6162. } else if (hw->mac.type == e1000_82580) {
  6163. u32 reg = rd32(E1000_PCIEMISC);
  6164. wr32(E1000_PCIEMISC, reg & ~E1000_PCIEMISC_LX_DECISION);
  6165. wr32(E1000_DMACR, 0);
  6166. }
  6167. }
  6168. /* igb_main.c */