igb_main.c 188 KB

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