igb_main.c 187 KB

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