igb_main.c 189 KB

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