ixgbe_main.c 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/types.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/string.h>
  26. #include <linux/in.h>
  27. #include <linux/ip.h>
  28. #include <linux/tcp.h>
  29. #include <linux/pkt_sched.h>
  30. #include <linux/ipv6.h>
  31. #include <net/checksum.h>
  32. #include <net/ip6_checksum.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/if_vlan.h>
  35. #include <scsi/fc/fc_fcoe.h>
  36. #include "ixgbe.h"
  37. #include "ixgbe_common.h"
  38. #include "ixgbe_dcb_82599.h"
  39. char ixgbe_driver_name[] = "ixgbe";
  40. static const char ixgbe_driver_string[] =
  41. "Intel(R) 10 Gigabit PCI Express Network Driver";
  42. #define DRV_VERSION "2.0.44-k2"
  43. const char ixgbe_driver_version[] = DRV_VERSION;
  44. static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
  45. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  46. [board_82598] = &ixgbe_82598_info,
  47. [board_82599] = &ixgbe_82599_info,
  48. };
  49. /* ixgbe_pci_tbl - PCI Device ID Table
  50. *
  51. * Wildcard entries (PCI_ANY_ID) should come last
  52. * Last entry must be all 0s
  53. *
  54. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  55. * Class, Class Mask, private data (not used) }
  56. */
  57. static struct pci_device_id ixgbe_pci_tbl[] = {
  58. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
  59. board_82598 },
  60. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
  61. board_82598 },
  62. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
  63. board_82598 },
  64. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
  65. board_82598 },
  66. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
  67. board_82598 },
  68. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
  69. board_82598 },
  70. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
  71. board_82598 },
  72. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
  73. board_82598 },
  74. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
  75. board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
  77. board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
  79. board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
  81. board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
  83. board_82599 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
  85. board_82599 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
  87. board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
  89. board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
  91. board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
  93. board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
  95. board_82599 },
  96. /* required last entry */
  97. {0, }
  98. };
  99. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  100. #ifdef CONFIG_IXGBE_DCA
  101. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  102. void *p);
  103. static struct notifier_block dca_notifier = {
  104. .notifier_call = ixgbe_notify_dca,
  105. .next = NULL,
  106. .priority = 0
  107. };
  108. #endif
  109. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  110. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  111. MODULE_LICENSE("GPL");
  112. MODULE_VERSION(DRV_VERSION);
  113. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  114. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  115. {
  116. u32 ctrl_ext;
  117. /* Let firmware take over control of h/w */
  118. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  119. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  120. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  121. }
  122. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  123. {
  124. u32 ctrl_ext;
  125. /* Let firmware know the driver has taken over */
  126. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  127. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  128. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  129. }
  130. /*
  131. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  132. * @adapter: pointer to adapter struct
  133. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  134. * @queue: queue to map the corresponding interrupt to
  135. * @msix_vector: the vector to map to the corresponding queue
  136. *
  137. */
  138. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  139. u8 queue, u8 msix_vector)
  140. {
  141. u32 ivar, index;
  142. struct ixgbe_hw *hw = &adapter->hw;
  143. switch (hw->mac.type) {
  144. case ixgbe_mac_82598EB:
  145. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  146. if (direction == -1)
  147. direction = 0;
  148. index = (((direction * 64) + queue) >> 2) & 0x1F;
  149. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  150. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  151. ivar |= (msix_vector << (8 * (queue & 0x3)));
  152. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  153. break;
  154. case ixgbe_mac_82599EB:
  155. if (direction == -1) {
  156. /* other causes */
  157. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  158. index = ((queue & 1) * 8);
  159. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  160. ivar &= ~(0xFF << index);
  161. ivar |= (msix_vector << index);
  162. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  163. break;
  164. } else {
  165. /* tx or rx causes */
  166. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  167. index = ((16 * (queue & 1)) + (8 * direction));
  168. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  169. ivar &= ~(0xFF << index);
  170. ivar |= (msix_vector << index);
  171. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  172. break;
  173. }
  174. default:
  175. break;
  176. }
  177. }
  178. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  179. u64 qmask)
  180. {
  181. u32 mask;
  182. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  183. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  184. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  185. } else {
  186. mask = (qmask & 0xFFFFFFFF);
  187. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  188. mask = (qmask >> 32);
  189. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  190. }
  191. }
  192. static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
  193. struct ixgbe_tx_buffer
  194. *tx_buffer_info)
  195. {
  196. if (tx_buffer_info->dma) {
  197. if (tx_buffer_info->mapped_as_page)
  198. pci_unmap_page(adapter->pdev,
  199. tx_buffer_info->dma,
  200. tx_buffer_info->length,
  201. PCI_DMA_TODEVICE);
  202. else
  203. pci_unmap_single(adapter->pdev,
  204. tx_buffer_info->dma,
  205. tx_buffer_info->length,
  206. PCI_DMA_TODEVICE);
  207. tx_buffer_info->dma = 0;
  208. }
  209. if (tx_buffer_info->skb) {
  210. dev_kfree_skb_any(tx_buffer_info->skb);
  211. tx_buffer_info->skb = NULL;
  212. }
  213. tx_buffer_info->time_stamp = 0;
  214. /* tx_buffer_info must be completely set up in the transmit path */
  215. }
  216. /**
  217. * ixgbe_tx_is_paused - check if the tx ring is paused
  218. * @adapter: the ixgbe adapter
  219. * @tx_ring: the corresponding tx_ring
  220. *
  221. * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
  222. * corresponding TC of this tx_ring when checking TFCS.
  223. *
  224. * Returns : true if paused
  225. */
  226. static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter,
  227. struct ixgbe_ring *tx_ring)
  228. {
  229. u32 txoff = IXGBE_TFCS_TXOFF;
  230. #ifdef CONFIG_IXGBE_DCB
  231. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  232. int tc;
  233. int reg_idx = tx_ring->reg_idx;
  234. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  235. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  236. tc = reg_idx >> 2;
  237. txoff = IXGBE_TFCS_TXOFF0;
  238. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  239. tc = 0;
  240. txoff = IXGBE_TFCS_TXOFF;
  241. if (dcb_i == 8) {
  242. /* TC0, TC1 */
  243. tc = reg_idx >> 5;
  244. if (tc == 2) /* TC2, TC3 */
  245. tc += (reg_idx - 64) >> 4;
  246. else if (tc == 3) /* TC4, TC5, TC6, TC7 */
  247. tc += 1 + ((reg_idx - 96) >> 3);
  248. } else if (dcb_i == 4) {
  249. /* TC0, TC1 */
  250. tc = reg_idx >> 6;
  251. if (tc == 1) {
  252. tc += (reg_idx - 64) >> 5;
  253. if (tc == 2) /* TC2, TC3 */
  254. tc += (reg_idx - 96) >> 4;
  255. }
  256. }
  257. }
  258. txoff <<= tc;
  259. }
  260. #endif
  261. return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff;
  262. }
  263. static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
  264. struct ixgbe_ring *tx_ring,
  265. unsigned int eop)
  266. {
  267. struct ixgbe_hw *hw = &adapter->hw;
  268. /* Detect a transmit hang in hardware, this serializes the
  269. * check with the clearing of time_stamp and movement of eop */
  270. adapter->detect_tx_hung = false;
  271. if (tx_ring->tx_buffer_info[eop].time_stamp &&
  272. time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
  273. !ixgbe_tx_is_paused(adapter, tx_ring)) {
  274. /* detected Tx unit hang */
  275. union ixgbe_adv_tx_desc *tx_desc;
  276. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  277. DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
  278. " Tx Queue <%d>\n"
  279. " TDH, TDT <%x>, <%x>\n"
  280. " next_to_use <%x>\n"
  281. " next_to_clean <%x>\n"
  282. "tx_buffer_info[next_to_clean]\n"
  283. " time_stamp <%lx>\n"
  284. " jiffies <%lx>\n",
  285. tx_ring->queue_index,
  286. IXGBE_READ_REG(hw, tx_ring->head),
  287. IXGBE_READ_REG(hw, tx_ring->tail),
  288. tx_ring->next_to_use, eop,
  289. tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
  290. return true;
  291. }
  292. return false;
  293. }
  294. #define IXGBE_MAX_TXD_PWR 14
  295. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  296. /* Tx Descriptors needed, worst case */
  297. #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
  298. (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
  299. #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
  300. MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
  301. static void ixgbe_tx_timeout(struct net_device *netdev);
  302. /**
  303. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  304. * @q_vector: structure containing interrupt and ring information
  305. * @tx_ring: tx ring to clean
  306. **/
  307. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  308. struct ixgbe_ring *tx_ring)
  309. {
  310. struct ixgbe_adapter *adapter = q_vector->adapter;
  311. struct net_device *netdev = adapter->netdev;
  312. union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
  313. struct ixgbe_tx_buffer *tx_buffer_info;
  314. unsigned int i, eop, count = 0;
  315. unsigned int total_bytes = 0, total_packets = 0;
  316. i = tx_ring->next_to_clean;
  317. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  318. eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  319. while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
  320. (count < tx_ring->work_limit)) {
  321. bool cleaned = false;
  322. for ( ; !cleaned; count++) {
  323. struct sk_buff *skb;
  324. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  325. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  326. cleaned = (i == eop);
  327. skb = tx_buffer_info->skb;
  328. if (cleaned && skb) {
  329. unsigned int segs, bytecount;
  330. unsigned int hlen = skb_headlen(skb);
  331. /* gso_segs is currently only valid for tcp */
  332. segs = skb_shinfo(skb)->gso_segs ?: 1;
  333. #ifdef IXGBE_FCOE
  334. /* adjust for FCoE Sequence Offload */
  335. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  336. && (skb->protocol == htons(ETH_P_FCOE)) &&
  337. skb_is_gso(skb)) {
  338. hlen = skb_transport_offset(skb) +
  339. sizeof(struct fc_frame_header) +
  340. sizeof(struct fcoe_crc_eof);
  341. segs = DIV_ROUND_UP(skb->len - hlen,
  342. skb_shinfo(skb)->gso_size);
  343. }
  344. #endif /* IXGBE_FCOE */
  345. /* multiply data chunks by size of headers */
  346. bytecount = ((segs - 1) * hlen) + skb->len;
  347. total_packets += segs;
  348. total_bytes += bytecount;
  349. }
  350. ixgbe_unmap_and_free_tx_resource(adapter,
  351. tx_buffer_info);
  352. tx_desc->wb.status = 0;
  353. i++;
  354. if (i == tx_ring->count)
  355. i = 0;
  356. }
  357. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  358. eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
  359. }
  360. tx_ring->next_to_clean = i;
  361. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  362. if (unlikely(count && netif_carrier_ok(netdev) &&
  363. (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
  364. /* Make sure that anybody stopping the queue after this
  365. * sees the new next_to_clean.
  366. */
  367. smp_mb();
  368. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  369. !test_bit(__IXGBE_DOWN, &adapter->state)) {
  370. netif_wake_subqueue(netdev, tx_ring->queue_index);
  371. ++tx_ring->restart_queue;
  372. }
  373. }
  374. if (adapter->detect_tx_hung) {
  375. if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
  376. /* schedule immediate reset if we believe we hung */
  377. DPRINTK(PROBE, INFO,
  378. "tx hang %d detected, resetting adapter\n",
  379. adapter->tx_timeout_count + 1);
  380. ixgbe_tx_timeout(adapter->netdev);
  381. }
  382. }
  383. /* re-arm the interrupt */
  384. if (count >= tx_ring->work_limit)
  385. ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
  386. tx_ring->total_bytes += total_bytes;
  387. tx_ring->total_packets += total_packets;
  388. tx_ring->stats.packets += total_packets;
  389. tx_ring->stats.bytes += total_bytes;
  390. return (count < tx_ring->work_limit);
  391. }
  392. #ifdef CONFIG_IXGBE_DCA
  393. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  394. struct ixgbe_ring *rx_ring)
  395. {
  396. u32 rxctrl;
  397. int cpu = get_cpu();
  398. int q = rx_ring - adapter->rx_ring;
  399. if (rx_ring->cpu != cpu) {
  400. rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
  401. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  402. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
  403. rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  404. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  405. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
  406. rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  407. IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
  408. }
  409. rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  410. rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
  411. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
  412. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
  413. IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
  414. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
  415. rx_ring->cpu = cpu;
  416. }
  417. put_cpu();
  418. }
  419. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  420. struct ixgbe_ring *tx_ring)
  421. {
  422. u32 txctrl;
  423. int cpu = get_cpu();
  424. int q = tx_ring - adapter->tx_ring;
  425. struct ixgbe_hw *hw = &adapter->hw;
  426. if (tx_ring->cpu != cpu) {
  427. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  428. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
  429. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
  430. txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  431. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  432. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
  433. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  434. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
  435. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
  436. txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  437. IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
  438. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  439. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
  440. }
  441. tx_ring->cpu = cpu;
  442. }
  443. put_cpu();
  444. }
  445. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  446. {
  447. int i;
  448. if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
  449. return;
  450. /* always use CB2 mode, difference is masked in the CB driver */
  451. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
  452. for (i = 0; i < adapter->num_tx_queues; i++) {
  453. adapter->tx_ring[i].cpu = -1;
  454. ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
  455. }
  456. for (i = 0; i < adapter->num_rx_queues; i++) {
  457. adapter->rx_ring[i].cpu = -1;
  458. ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
  459. }
  460. }
  461. static int __ixgbe_notify_dca(struct device *dev, void *data)
  462. {
  463. struct net_device *netdev = dev_get_drvdata(dev);
  464. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  465. unsigned long event = *(unsigned long *)data;
  466. switch (event) {
  467. case DCA_PROVIDER_ADD:
  468. /* if we're already enabled, don't do it again */
  469. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  470. break;
  471. if (dca_add_requester(dev) == 0) {
  472. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  473. ixgbe_setup_dca(adapter);
  474. break;
  475. }
  476. /* Fall Through since DCA is disabled. */
  477. case DCA_PROVIDER_REMOVE:
  478. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  479. dca_remove_requester(dev);
  480. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  481. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  482. }
  483. break;
  484. }
  485. return 0;
  486. }
  487. #endif /* CONFIG_IXGBE_DCA */
  488. /**
  489. * ixgbe_receive_skb - Send a completed packet up the stack
  490. * @adapter: board private structure
  491. * @skb: packet to send up
  492. * @status: hardware indication of status of receive
  493. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  494. * @rx_desc: rx descriptor
  495. **/
  496. static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
  497. struct sk_buff *skb, u8 status,
  498. struct ixgbe_ring *ring,
  499. union ixgbe_adv_rx_desc *rx_desc)
  500. {
  501. struct ixgbe_adapter *adapter = q_vector->adapter;
  502. struct napi_struct *napi = &q_vector->napi;
  503. bool is_vlan = (status & IXGBE_RXD_STAT_VP);
  504. u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
  505. skb_record_rx_queue(skb, ring->queue_index);
  506. if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
  507. if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
  508. vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
  509. else
  510. napi_gro_receive(napi, skb);
  511. } else {
  512. if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
  513. vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
  514. else
  515. netif_rx(skb);
  516. }
  517. }
  518. /**
  519. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  520. * @adapter: address of board private structure
  521. * @status_err: hardware indication of status of receive
  522. * @skb: skb currently being received and modified
  523. **/
  524. static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
  525. union ixgbe_adv_rx_desc *rx_desc,
  526. struct sk_buff *skb)
  527. {
  528. u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
  529. skb->ip_summed = CHECKSUM_NONE;
  530. /* Rx csum disabled */
  531. if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
  532. return;
  533. /* if IP and error */
  534. if ((status_err & IXGBE_RXD_STAT_IPCS) &&
  535. (status_err & IXGBE_RXDADV_ERR_IPE)) {
  536. adapter->hw_csum_rx_error++;
  537. return;
  538. }
  539. if (!(status_err & IXGBE_RXD_STAT_L4CS))
  540. return;
  541. if (status_err & IXGBE_RXDADV_ERR_TCPE) {
  542. u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  543. /*
  544. * 82599 errata, UDP frames with a 0 checksum can be marked as
  545. * checksum errors.
  546. */
  547. if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
  548. (adapter->hw.mac.type == ixgbe_mac_82599EB))
  549. return;
  550. adapter->hw_csum_rx_error++;
  551. return;
  552. }
  553. /* It must be a TCP or UDP packet with a valid checksum */
  554. skb->ip_summed = CHECKSUM_UNNECESSARY;
  555. }
  556. static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
  557. struct ixgbe_ring *rx_ring, u32 val)
  558. {
  559. /*
  560. * Force memory writes to complete before letting h/w
  561. * know there are new descriptors to fetch. (Only
  562. * applicable for weak-ordered memory model archs,
  563. * such as IA-64).
  564. */
  565. wmb();
  566. IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
  567. }
  568. /**
  569. * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
  570. * @adapter: address of board private structure
  571. **/
  572. static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
  573. struct ixgbe_ring *rx_ring,
  574. int cleaned_count)
  575. {
  576. struct pci_dev *pdev = adapter->pdev;
  577. union ixgbe_adv_rx_desc *rx_desc;
  578. struct ixgbe_rx_buffer *bi;
  579. unsigned int i;
  580. i = rx_ring->next_to_use;
  581. bi = &rx_ring->rx_buffer_info[i];
  582. while (cleaned_count--) {
  583. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  584. if (!bi->page_dma &&
  585. (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
  586. if (!bi->page) {
  587. bi->page = alloc_page(GFP_ATOMIC);
  588. if (!bi->page) {
  589. adapter->alloc_rx_page_failed++;
  590. goto no_buffers;
  591. }
  592. bi->page_offset = 0;
  593. } else {
  594. /* use a half page if we're re-using */
  595. bi->page_offset ^= (PAGE_SIZE / 2);
  596. }
  597. bi->page_dma = pci_map_page(pdev, bi->page,
  598. bi->page_offset,
  599. (PAGE_SIZE / 2),
  600. PCI_DMA_FROMDEVICE);
  601. }
  602. if (!bi->skb) {
  603. struct sk_buff *skb;
  604. /* netdev_alloc_skb reserves 32 bytes up front!! */
  605. uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES;
  606. skb = netdev_alloc_skb(adapter->netdev, bufsz);
  607. if (!skb) {
  608. adapter->alloc_rx_buff_failed++;
  609. goto no_buffers;
  610. }
  611. /* advance the data pointer to the next cache line */
  612. skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES)
  613. - skb->data));
  614. bi->skb = skb;
  615. bi->dma = pci_map_single(pdev, skb->data,
  616. rx_ring->rx_buf_len,
  617. PCI_DMA_FROMDEVICE);
  618. }
  619. /* Refresh the desc even if buffer_addrs didn't change because
  620. * each write-back erases this info. */
  621. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  622. rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
  623. rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
  624. } else {
  625. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
  626. }
  627. i++;
  628. if (i == rx_ring->count)
  629. i = 0;
  630. bi = &rx_ring->rx_buffer_info[i];
  631. }
  632. no_buffers:
  633. if (rx_ring->next_to_use != i) {
  634. rx_ring->next_to_use = i;
  635. if (i-- == 0)
  636. i = (rx_ring->count - 1);
  637. ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
  638. }
  639. }
  640. static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
  641. {
  642. return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
  643. }
  644. static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
  645. {
  646. return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  647. }
  648. static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
  649. {
  650. return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
  651. IXGBE_RXDADV_RSCCNT_MASK) >>
  652. IXGBE_RXDADV_RSCCNT_SHIFT;
  653. }
  654. /**
  655. * ixgbe_transform_rsc_queue - change rsc queue into a full packet
  656. * @skb: pointer to the last skb in the rsc queue
  657. * @count: pointer to number of packets coalesced in this context
  658. *
  659. * This function changes a queue full of hw rsc buffers into a completed
  660. * packet. It uses the ->prev pointers to find the first packet and then
  661. * turns it into the frag list owner.
  662. **/
  663. static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
  664. u64 *count)
  665. {
  666. unsigned int frag_list_size = 0;
  667. while (skb->prev) {
  668. struct sk_buff *prev = skb->prev;
  669. frag_list_size += skb->len;
  670. skb->prev = NULL;
  671. skb = prev;
  672. *count += 1;
  673. }
  674. skb_shinfo(skb)->frag_list = skb->next;
  675. skb->next = NULL;
  676. skb->len += frag_list_size;
  677. skb->data_len += frag_list_size;
  678. skb->truesize += frag_list_size;
  679. return skb;
  680. }
  681. static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  682. struct ixgbe_ring *rx_ring,
  683. int *work_done, int work_to_do)
  684. {
  685. struct ixgbe_adapter *adapter = q_vector->adapter;
  686. struct net_device *netdev = adapter->netdev;
  687. struct pci_dev *pdev = adapter->pdev;
  688. union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
  689. struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
  690. struct sk_buff *skb;
  691. unsigned int i, rsc_count = 0;
  692. u32 len, staterr;
  693. u16 hdr_info;
  694. bool cleaned = false;
  695. int cleaned_count = 0;
  696. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  697. #ifdef IXGBE_FCOE
  698. int ddp_bytes = 0;
  699. #endif /* IXGBE_FCOE */
  700. i = rx_ring->next_to_clean;
  701. rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
  702. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  703. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  704. while (staterr & IXGBE_RXD_STAT_DD) {
  705. u32 upper_len = 0;
  706. if (*work_done >= work_to_do)
  707. break;
  708. (*work_done)++;
  709. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  710. hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
  711. len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
  712. IXGBE_RXDADV_HDRBUFLEN_SHIFT;
  713. if (len > IXGBE_RX_HDR_SIZE)
  714. len = IXGBE_RX_HDR_SIZE;
  715. upper_len = le16_to_cpu(rx_desc->wb.upper.length);
  716. } else {
  717. len = le16_to_cpu(rx_desc->wb.upper.length);
  718. }
  719. cleaned = true;
  720. skb = rx_buffer_info->skb;
  721. prefetch(skb->data);
  722. rx_buffer_info->skb = NULL;
  723. if (rx_buffer_info->dma) {
  724. pci_unmap_single(pdev, rx_buffer_info->dma,
  725. rx_ring->rx_buf_len,
  726. PCI_DMA_FROMDEVICE);
  727. rx_buffer_info->dma = 0;
  728. skb_put(skb, len);
  729. }
  730. if (upper_len) {
  731. pci_unmap_page(pdev, rx_buffer_info->page_dma,
  732. PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
  733. rx_buffer_info->page_dma = 0;
  734. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  735. rx_buffer_info->page,
  736. rx_buffer_info->page_offset,
  737. upper_len);
  738. if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
  739. (page_count(rx_buffer_info->page) != 1))
  740. rx_buffer_info->page = NULL;
  741. else
  742. get_page(rx_buffer_info->page);
  743. skb->len += upper_len;
  744. skb->data_len += upper_len;
  745. skb->truesize += upper_len;
  746. }
  747. i++;
  748. if (i == rx_ring->count)
  749. i = 0;
  750. next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
  751. prefetch(next_rxd);
  752. cleaned_count++;
  753. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  754. rsc_count = ixgbe_get_rsc_count(rx_desc);
  755. if (rsc_count) {
  756. u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
  757. IXGBE_RXDADV_NEXTP_SHIFT;
  758. next_buffer = &rx_ring->rx_buffer_info[nextp];
  759. } else {
  760. next_buffer = &rx_ring->rx_buffer_info[i];
  761. }
  762. if (staterr & IXGBE_RXD_STAT_EOP) {
  763. if (skb->prev)
  764. skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
  765. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  766. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
  767. rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
  768. else
  769. rx_ring->rsc_count++;
  770. rx_ring->rsc_flush++;
  771. }
  772. rx_ring->stats.packets++;
  773. rx_ring->stats.bytes += skb->len;
  774. } else {
  775. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  776. rx_buffer_info->skb = next_buffer->skb;
  777. rx_buffer_info->dma = next_buffer->dma;
  778. next_buffer->skb = skb;
  779. next_buffer->dma = 0;
  780. } else {
  781. skb->next = next_buffer->skb;
  782. skb->next->prev = skb;
  783. }
  784. rx_ring->non_eop_descs++;
  785. goto next_desc;
  786. }
  787. if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
  788. dev_kfree_skb_irq(skb);
  789. goto next_desc;
  790. }
  791. ixgbe_rx_checksum(adapter, rx_desc, skb);
  792. /* probably a little skewed due to removing CRC */
  793. total_rx_bytes += skb->len;
  794. total_rx_packets++;
  795. skb->protocol = eth_type_trans(skb, adapter->netdev);
  796. #ifdef IXGBE_FCOE
  797. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  798. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  799. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  800. if (!ddp_bytes)
  801. goto next_desc;
  802. }
  803. #endif /* IXGBE_FCOE */
  804. ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
  805. next_desc:
  806. rx_desc->wb.upper.status_error = 0;
  807. /* return some buffers to hardware, one at a time is too slow */
  808. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  809. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  810. cleaned_count = 0;
  811. }
  812. /* use prefetched values */
  813. rx_desc = next_rxd;
  814. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  815. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  816. }
  817. rx_ring->next_to_clean = i;
  818. cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
  819. if (cleaned_count)
  820. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  821. #ifdef IXGBE_FCOE
  822. /* include DDPed FCoE data */
  823. if (ddp_bytes > 0) {
  824. unsigned int mss;
  825. mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
  826. sizeof(struct fc_frame_header) -
  827. sizeof(struct fcoe_crc_eof);
  828. if (mss > 512)
  829. mss &= ~511;
  830. total_rx_bytes += ddp_bytes;
  831. total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
  832. }
  833. #endif /* IXGBE_FCOE */
  834. rx_ring->total_packets += total_rx_packets;
  835. rx_ring->total_bytes += total_rx_bytes;
  836. netdev->stats.rx_bytes += total_rx_bytes;
  837. netdev->stats.rx_packets += total_rx_packets;
  838. return cleaned;
  839. }
  840. static int ixgbe_clean_rxonly(struct napi_struct *, int);
  841. /**
  842. * ixgbe_configure_msix - Configure MSI-X hardware
  843. * @adapter: board private structure
  844. *
  845. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  846. * interrupts.
  847. **/
  848. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  849. {
  850. struct ixgbe_q_vector *q_vector;
  851. int i, j, q_vectors, v_idx, r_idx;
  852. u32 mask;
  853. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  854. /*
  855. * Populate the IVAR table and set the ITR values to the
  856. * corresponding register.
  857. */
  858. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  859. q_vector = adapter->q_vector[v_idx];
  860. /* XXX for_each_bit(...) */
  861. r_idx = find_first_bit(q_vector->rxr_idx,
  862. adapter->num_rx_queues);
  863. for (i = 0; i < q_vector->rxr_count; i++) {
  864. j = adapter->rx_ring[r_idx].reg_idx;
  865. ixgbe_set_ivar(adapter, 0, j, v_idx);
  866. r_idx = find_next_bit(q_vector->rxr_idx,
  867. adapter->num_rx_queues,
  868. r_idx + 1);
  869. }
  870. r_idx = find_first_bit(q_vector->txr_idx,
  871. adapter->num_tx_queues);
  872. for (i = 0; i < q_vector->txr_count; i++) {
  873. j = adapter->tx_ring[r_idx].reg_idx;
  874. ixgbe_set_ivar(adapter, 1, j, v_idx);
  875. r_idx = find_next_bit(q_vector->txr_idx,
  876. adapter->num_tx_queues,
  877. r_idx + 1);
  878. }
  879. if (q_vector->txr_count && !q_vector->rxr_count)
  880. /* tx only */
  881. q_vector->eitr = adapter->tx_eitr_param;
  882. else if (q_vector->rxr_count)
  883. /* rx or mixed */
  884. q_vector->eitr = adapter->rx_eitr_param;
  885. ixgbe_write_eitr(q_vector);
  886. }
  887. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  888. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  889. v_idx);
  890. else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  891. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  892. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  893. /* set up to autoclear timer, and the vectors */
  894. mask = IXGBE_EIMS_ENABLE_MASK;
  895. mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
  896. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  897. }
  898. enum latency_range {
  899. lowest_latency = 0,
  900. low_latency = 1,
  901. bulk_latency = 2,
  902. latency_invalid = 255
  903. };
  904. /**
  905. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  906. * @adapter: pointer to adapter
  907. * @eitr: eitr setting (ints per sec) to give last timeslice
  908. * @itr_setting: current throttle rate in ints/second
  909. * @packets: the number of packets during this measurement interval
  910. * @bytes: the number of bytes during this measurement interval
  911. *
  912. * Stores a new ITR value based on packets and byte
  913. * counts during the last interrupt. The advantage of per interrupt
  914. * computation is faster updates and more accurate ITR for the current
  915. * traffic pattern. Constants in this function were computed
  916. * based on theoretical maximum wire speed and thresholds were set based
  917. * on testing data as well as attempting to minimize response time
  918. * while increasing bulk throughput.
  919. * this functionality is controlled by the InterruptThrottleRate module
  920. * parameter (see ixgbe_param.c)
  921. **/
  922. static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
  923. u32 eitr, u8 itr_setting,
  924. int packets, int bytes)
  925. {
  926. unsigned int retval = itr_setting;
  927. u32 timepassed_us;
  928. u64 bytes_perint;
  929. if (packets == 0)
  930. goto update_itr_done;
  931. /* simple throttlerate management
  932. * 0-20MB/s lowest (100000 ints/s)
  933. * 20-100MB/s low (20000 ints/s)
  934. * 100-1249MB/s bulk (8000 ints/s)
  935. */
  936. /* what was last interrupt timeslice? */
  937. timepassed_us = 1000000/eitr;
  938. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  939. switch (itr_setting) {
  940. case lowest_latency:
  941. if (bytes_perint > adapter->eitr_low)
  942. retval = low_latency;
  943. break;
  944. case low_latency:
  945. if (bytes_perint > adapter->eitr_high)
  946. retval = bulk_latency;
  947. else if (bytes_perint <= adapter->eitr_low)
  948. retval = lowest_latency;
  949. break;
  950. case bulk_latency:
  951. if (bytes_perint <= adapter->eitr_high)
  952. retval = low_latency;
  953. break;
  954. }
  955. update_itr_done:
  956. return retval;
  957. }
  958. /**
  959. * ixgbe_write_eitr - write EITR register in hardware specific way
  960. * @q_vector: structure containing interrupt and ring information
  961. *
  962. * This function is made to be called by ethtool and by the driver
  963. * when it needs to update EITR registers at runtime. Hardware
  964. * specific quirks/differences are taken care of here.
  965. */
  966. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  967. {
  968. struct ixgbe_adapter *adapter = q_vector->adapter;
  969. struct ixgbe_hw *hw = &adapter->hw;
  970. int v_idx = q_vector->v_idx;
  971. u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
  972. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  973. /* must write high and low 16 bits to reset counter */
  974. itr_reg |= (itr_reg << 16);
  975. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  976. /*
  977. * set the WDIS bit to not clear the timer bits and cause an
  978. * immediate assertion of the interrupt
  979. */
  980. itr_reg |= IXGBE_EITR_CNT_WDIS;
  981. }
  982. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  983. }
  984. static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
  985. {
  986. struct ixgbe_adapter *adapter = q_vector->adapter;
  987. u32 new_itr;
  988. u8 current_itr, ret_itr;
  989. int i, r_idx;
  990. struct ixgbe_ring *rx_ring, *tx_ring;
  991. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  992. for (i = 0; i < q_vector->txr_count; i++) {
  993. tx_ring = &(adapter->tx_ring[r_idx]);
  994. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  995. q_vector->tx_itr,
  996. tx_ring->total_packets,
  997. tx_ring->total_bytes);
  998. /* if the result for this queue would decrease interrupt
  999. * rate for this vector then use that result */
  1000. q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
  1001. q_vector->tx_itr - 1 : ret_itr);
  1002. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1003. r_idx + 1);
  1004. }
  1005. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1006. for (i = 0; i < q_vector->rxr_count; i++) {
  1007. rx_ring = &(adapter->rx_ring[r_idx]);
  1008. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1009. q_vector->rx_itr,
  1010. rx_ring->total_packets,
  1011. rx_ring->total_bytes);
  1012. /* if the result for this queue would decrease interrupt
  1013. * rate for this vector then use that result */
  1014. q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
  1015. q_vector->rx_itr - 1 : ret_itr);
  1016. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1017. r_idx + 1);
  1018. }
  1019. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1020. switch (current_itr) {
  1021. /* counts and packets in update_itr are dependent on these numbers */
  1022. case lowest_latency:
  1023. new_itr = 100000;
  1024. break;
  1025. case low_latency:
  1026. new_itr = 20000; /* aka hwitr = ~200 */
  1027. break;
  1028. case bulk_latency:
  1029. default:
  1030. new_itr = 8000;
  1031. break;
  1032. }
  1033. if (new_itr != q_vector->eitr) {
  1034. /* do an exponential smoothing */
  1035. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1036. /* save the algorithm value here, not the smoothed one */
  1037. q_vector->eitr = new_itr;
  1038. ixgbe_write_eitr(q_vector);
  1039. }
  1040. return;
  1041. }
  1042. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  1043. {
  1044. struct ixgbe_hw *hw = &adapter->hw;
  1045. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  1046. (eicr & IXGBE_EICR_GPI_SDP1)) {
  1047. DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
  1048. /* write to clear the interrupt */
  1049. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1050. }
  1051. }
  1052. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  1053. {
  1054. struct ixgbe_hw *hw = &adapter->hw;
  1055. if (eicr & IXGBE_EICR_GPI_SDP1) {
  1056. /* Clear the interrupt */
  1057. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1058. schedule_work(&adapter->multispeed_fiber_task);
  1059. } else if (eicr & IXGBE_EICR_GPI_SDP2) {
  1060. /* Clear the interrupt */
  1061. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
  1062. schedule_work(&adapter->sfp_config_module_task);
  1063. } else {
  1064. /* Interrupt isn't for us... */
  1065. return;
  1066. }
  1067. }
  1068. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  1069. {
  1070. struct ixgbe_hw *hw = &adapter->hw;
  1071. adapter->lsc_int++;
  1072. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  1073. adapter->link_check_timeout = jiffies;
  1074. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  1075. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  1076. IXGBE_WRITE_FLUSH(hw);
  1077. schedule_work(&adapter->watchdog_task);
  1078. }
  1079. }
  1080. static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
  1081. {
  1082. struct net_device *netdev = data;
  1083. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1084. struct ixgbe_hw *hw = &adapter->hw;
  1085. u32 eicr;
  1086. /*
  1087. * Workaround for Silicon errata. Use clear-by-write instead
  1088. * of clear-by-read. Reading with EICS will return the
  1089. * interrupt causes without clearing, which later be done
  1090. * with the write to EICR.
  1091. */
  1092. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  1093. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  1094. if (eicr & IXGBE_EICR_LSC)
  1095. ixgbe_check_lsc(adapter);
  1096. if (hw->mac.type == ixgbe_mac_82598EB)
  1097. ixgbe_check_fan_failure(adapter, eicr);
  1098. if (hw->mac.type == ixgbe_mac_82599EB) {
  1099. ixgbe_check_sfp_event(adapter, eicr);
  1100. /* Handle Flow Director Full threshold interrupt */
  1101. if (eicr & IXGBE_EICR_FLOW_DIR) {
  1102. int i;
  1103. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
  1104. /* Disable transmits before FDIR Re-initialization */
  1105. netif_tx_stop_all_queues(netdev);
  1106. for (i = 0; i < adapter->num_tx_queues; i++) {
  1107. struct ixgbe_ring *tx_ring =
  1108. &adapter->tx_ring[i];
  1109. if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
  1110. &tx_ring->reinit_state))
  1111. schedule_work(&adapter->fdir_reinit_task);
  1112. }
  1113. }
  1114. }
  1115. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1116. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
  1117. return IRQ_HANDLED;
  1118. }
  1119. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  1120. u64 qmask)
  1121. {
  1122. u32 mask;
  1123. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1124. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1125. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1126. } else {
  1127. mask = (qmask & 0xFFFFFFFF);
  1128. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
  1129. mask = (qmask >> 32);
  1130. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
  1131. }
  1132. /* skip the flush */
  1133. }
  1134. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  1135. u64 qmask)
  1136. {
  1137. u32 mask;
  1138. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1139. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1140. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
  1141. } else {
  1142. mask = (qmask & 0xFFFFFFFF);
  1143. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
  1144. mask = (qmask >> 32);
  1145. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
  1146. }
  1147. /* skip the flush */
  1148. }
  1149. static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
  1150. {
  1151. struct ixgbe_q_vector *q_vector = data;
  1152. struct ixgbe_adapter *adapter = q_vector->adapter;
  1153. struct ixgbe_ring *tx_ring;
  1154. int i, r_idx;
  1155. if (!q_vector->txr_count)
  1156. return IRQ_HANDLED;
  1157. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1158. for (i = 0; i < q_vector->txr_count; i++) {
  1159. tx_ring = &(adapter->tx_ring[r_idx]);
  1160. tx_ring->total_bytes = 0;
  1161. tx_ring->total_packets = 0;
  1162. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1163. r_idx + 1);
  1164. }
  1165. /* EIAM disabled interrupts (on this vector) for us */
  1166. napi_schedule(&q_vector->napi);
  1167. return IRQ_HANDLED;
  1168. }
  1169. /**
  1170. * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
  1171. * @irq: unused
  1172. * @data: pointer to our q_vector struct for this interrupt vector
  1173. **/
  1174. static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
  1175. {
  1176. struct ixgbe_q_vector *q_vector = data;
  1177. struct ixgbe_adapter *adapter = q_vector->adapter;
  1178. struct ixgbe_ring *rx_ring;
  1179. int r_idx;
  1180. int i;
  1181. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1182. for (i = 0; i < q_vector->rxr_count; i++) {
  1183. rx_ring = &(adapter->rx_ring[r_idx]);
  1184. rx_ring->total_bytes = 0;
  1185. rx_ring->total_packets = 0;
  1186. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1187. r_idx + 1);
  1188. }
  1189. if (!q_vector->rxr_count)
  1190. return IRQ_HANDLED;
  1191. /* disable interrupts on this vector only */
  1192. /* EIAM disabled interrupts (on this vector) for us */
  1193. napi_schedule(&q_vector->napi);
  1194. return IRQ_HANDLED;
  1195. }
  1196. static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
  1197. {
  1198. struct ixgbe_q_vector *q_vector = data;
  1199. struct ixgbe_adapter *adapter = q_vector->adapter;
  1200. struct ixgbe_ring *ring;
  1201. int r_idx;
  1202. int i;
  1203. if (!q_vector->txr_count && !q_vector->rxr_count)
  1204. return IRQ_HANDLED;
  1205. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1206. for (i = 0; i < q_vector->txr_count; i++) {
  1207. ring = &(adapter->tx_ring[r_idx]);
  1208. ring->total_bytes = 0;
  1209. ring->total_packets = 0;
  1210. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1211. r_idx + 1);
  1212. }
  1213. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1214. for (i = 0; i < q_vector->rxr_count; i++) {
  1215. ring = &(adapter->rx_ring[r_idx]);
  1216. ring->total_bytes = 0;
  1217. ring->total_packets = 0;
  1218. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1219. r_idx + 1);
  1220. }
  1221. /* EIAM disabled interrupts (on this vector) for us */
  1222. napi_schedule(&q_vector->napi);
  1223. return IRQ_HANDLED;
  1224. }
  1225. /**
  1226. * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
  1227. * @napi: napi struct with our devices info in it
  1228. * @budget: amount of work driver is allowed to do this pass, in packets
  1229. *
  1230. * This function is optimized for cleaning one queue only on a single
  1231. * q_vector!!!
  1232. **/
  1233. static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
  1234. {
  1235. struct ixgbe_q_vector *q_vector =
  1236. container_of(napi, struct ixgbe_q_vector, napi);
  1237. struct ixgbe_adapter *adapter = q_vector->adapter;
  1238. struct ixgbe_ring *rx_ring = NULL;
  1239. int work_done = 0;
  1240. long r_idx;
  1241. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1242. rx_ring = &(adapter->rx_ring[r_idx]);
  1243. #ifdef CONFIG_IXGBE_DCA
  1244. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1245. ixgbe_update_rx_dca(adapter, rx_ring);
  1246. #endif
  1247. ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
  1248. /* If all Rx work done, exit the polling mode */
  1249. if (work_done < budget) {
  1250. napi_complete(napi);
  1251. if (adapter->rx_itr_setting & 1)
  1252. ixgbe_set_itr_msix(q_vector);
  1253. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1254. ixgbe_irq_enable_queues(adapter,
  1255. ((u64)1 << q_vector->v_idx));
  1256. }
  1257. return work_done;
  1258. }
  1259. /**
  1260. * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
  1261. * @napi: napi struct with our devices info in it
  1262. * @budget: amount of work driver is allowed to do this pass, in packets
  1263. *
  1264. * This function will clean more than one rx queue associated with a
  1265. * q_vector.
  1266. **/
  1267. static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
  1268. {
  1269. struct ixgbe_q_vector *q_vector =
  1270. container_of(napi, struct ixgbe_q_vector, napi);
  1271. struct ixgbe_adapter *adapter = q_vector->adapter;
  1272. struct ixgbe_ring *ring = NULL;
  1273. int work_done = 0, i;
  1274. long r_idx;
  1275. bool tx_clean_complete = true;
  1276. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1277. for (i = 0; i < q_vector->txr_count; i++) {
  1278. ring = &(adapter->tx_ring[r_idx]);
  1279. #ifdef CONFIG_IXGBE_DCA
  1280. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1281. ixgbe_update_tx_dca(adapter, ring);
  1282. #endif
  1283. tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
  1284. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1285. r_idx + 1);
  1286. }
  1287. /* attempt to distribute budget to each queue fairly, but don't allow
  1288. * the budget to go below 1 because we'll exit polling */
  1289. budget /= (q_vector->rxr_count ?: 1);
  1290. budget = max(budget, 1);
  1291. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1292. for (i = 0; i < q_vector->rxr_count; i++) {
  1293. ring = &(adapter->rx_ring[r_idx]);
  1294. #ifdef CONFIG_IXGBE_DCA
  1295. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1296. ixgbe_update_rx_dca(adapter, ring);
  1297. #endif
  1298. ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
  1299. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1300. r_idx + 1);
  1301. }
  1302. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1303. ring = &(adapter->rx_ring[r_idx]);
  1304. /* If all Rx work done, exit the polling mode */
  1305. if (work_done < budget) {
  1306. napi_complete(napi);
  1307. if (adapter->rx_itr_setting & 1)
  1308. ixgbe_set_itr_msix(q_vector);
  1309. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1310. ixgbe_irq_enable_queues(adapter,
  1311. ((u64)1 << q_vector->v_idx));
  1312. return 0;
  1313. }
  1314. return work_done;
  1315. }
  1316. /**
  1317. * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
  1318. * @napi: napi struct with our devices info in it
  1319. * @budget: amount of work driver is allowed to do this pass, in packets
  1320. *
  1321. * This function is optimized for cleaning one queue only on a single
  1322. * q_vector!!!
  1323. **/
  1324. static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
  1325. {
  1326. struct ixgbe_q_vector *q_vector =
  1327. container_of(napi, struct ixgbe_q_vector, napi);
  1328. struct ixgbe_adapter *adapter = q_vector->adapter;
  1329. struct ixgbe_ring *tx_ring = NULL;
  1330. int work_done = 0;
  1331. long r_idx;
  1332. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1333. tx_ring = &(adapter->tx_ring[r_idx]);
  1334. #ifdef CONFIG_IXGBE_DCA
  1335. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1336. ixgbe_update_tx_dca(adapter, tx_ring);
  1337. #endif
  1338. if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
  1339. work_done = budget;
  1340. /* If all Tx work done, exit the polling mode */
  1341. if (work_done < budget) {
  1342. napi_complete(napi);
  1343. if (adapter->tx_itr_setting & 1)
  1344. ixgbe_set_itr_msix(q_vector);
  1345. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1346. ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
  1347. }
  1348. return work_done;
  1349. }
  1350. static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
  1351. int r_idx)
  1352. {
  1353. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1354. set_bit(r_idx, q_vector->rxr_idx);
  1355. q_vector->rxr_count++;
  1356. }
  1357. static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
  1358. int t_idx)
  1359. {
  1360. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1361. set_bit(t_idx, q_vector->txr_idx);
  1362. q_vector->txr_count++;
  1363. }
  1364. /**
  1365. * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
  1366. * @adapter: board private structure to initialize
  1367. * @vectors: allotted vector count for descriptor rings
  1368. *
  1369. * This function maps descriptor rings to the queue-specific vectors
  1370. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  1371. * one vector per ring/queue, but on a constrained vector budget, we
  1372. * group the rings as "efficiently" as possible. You would add new
  1373. * mapping configurations in here.
  1374. **/
  1375. static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
  1376. int vectors)
  1377. {
  1378. int v_start = 0;
  1379. int rxr_idx = 0, txr_idx = 0;
  1380. int rxr_remaining = adapter->num_rx_queues;
  1381. int txr_remaining = adapter->num_tx_queues;
  1382. int i, j;
  1383. int rqpv, tqpv;
  1384. int err = 0;
  1385. /* No mapping required if MSI-X is disabled. */
  1386. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  1387. goto out;
  1388. /*
  1389. * The ideal configuration...
  1390. * We have enough vectors to map one per queue.
  1391. */
  1392. if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
  1393. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  1394. map_vector_to_rxq(adapter, v_start, rxr_idx);
  1395. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  1396. map_vector_to_txq(adapter, v_start, txr_idx);
  1397. goto out;
  1398. }
  1399. /*
  1400. * If we don't have enough vectors for a 1-to-1
  1401. * mapping, we'll have to group them so there are
  1402. * multiple queues per vector.
  1403. */
  1404. /* Re-adjusting *qpv takes care of the remainder. */
  1405. for (i = v_start; i < vectors; i++) {
  1406. rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
  1407. for (j = 0; j < rqpv; j++) {
  1408. map_vector_to_rxq(adapter, i, rxr_idx);
  1409. rxr_idx++;
  1410. rxr_remaining--;
  1411. }
  1412. }
  1413. for (i = v_start; i < vectors; i++) {
  1414. tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
  1415. for (j = 0; j < tqpv; j++) {
  1416. map_vector_to_txq(adapter, i, txr_idx);
  1417. txr_idx++;
  1418. txr_remaining--;
  1419. }
  1420. }
  1421. out:
  1422. return err;
  1423. }
  1424. /**
  1425. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  1426. * @adapter: board private structure
  1427. *
  1428. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  1429. * interrupts from the kernel.
  1430. **/
  1431. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  1432. {
  1433. struct net_device *netdev = adapter->netdev;
  1434. irqreturn_t (*handler)(int, void *);
  1435. int i, vector, q_vectors, err;
  1436. int ri=0, ti=0;
  1437. /* Decrement for Other and TCP Timer vectors */
  1438. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1439. /* Map the Tx/Rx rings to the vectors we were allotted. */
  1440. err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
  1441. if (err)
  1442. goto out;
  1443. #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
  1444. (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
  1445. &ixgbe_msix_clean_many)
  1446. for (vector = 0; vector < q_vectors; vector++) {
  1447. handler = SET_HANDLER(adapter->q_vector[vector]);
  1448. if(handler == &ixgbe_msix_clean_rx) {
  1449. sprintf(adapter->name[vector], "%s-%s-%d",
  1450. netdev->name, "rx", ri++);
  1451. }
  1452. else if(handler == &ixgbe_msix_clean_tx) {
  1453. sprintf(adapter->name[vector], "%s-%s-%d",
  1454. netdev->name, "tx", ti++);
  1455. }
  1456. else
  1457. sprintf(adapter->name[vector], "%s-%s-%d",
  1458. netdev->name, "TxRx", vector);
  1459. err = request_irq(adapter->msix_entries[vector].vector,
  1460. handler, 0, adapter->name[vector],
  1461. adapter->q_vector[vector]);
  1462. if (err) {
  1463. DPRINTK(PROBE, ERR,
  1464. "request_irq failed for MSIX interrupt "
  1465. "Error: %d\n", err);
  1466. goto free_queue_irqs;
  1467. }
  1468. }
  1469. sprintf(adapter->name[vector], "%s:lsc", netdev->name);
  1470. err = request_irq(adapter->msix_entries[vector].vector,
  1471. ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
  1472. if (err) {
  1473. DPRINTK(PROBE, ERR,
  1474. "request_irq for msix_lsc failed: %d\n", err);
  1475. goto free_queue_irqs;
  1476. }
  1477. return 0;
  1478. free_queue_irqs:
  1479. for (i = vector - 1; i >= 0; i--)
  1480. free_irq(adapter->msix_entries[--vector].vector,
  1481. adapter->q_vector[i]);
  1482. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  1483. pci_disable_msix(adapter->pdev);
  1484. kfree(adapter->msix_entries);
  1485. adapter->msix_entries = NULL;
  1486. out:
  1487. return err;
  1488. }
  1489. static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
  1490. {
  1491. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  1492. u8 current_itr;
  1493. u32 new_itr = q_vector->eitr;
  1494. struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
  1495. struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
  1496. q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
  1497. q_vector->tx_itr,
  1498. tx_ring->total_packets,
  1499. tx_ring->total_bytes);
  1500. q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
  1501. q_vector->rx_itr,
  1502. rx_ring->total_packets,
  1503. rx_ring->total_bytes);
  1504. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1505. switch (current_itr) {
  1506. /* counts and packets in update_itr are dependent on these numbers */
  1507. case lowest_latency:
  1508. new_itr = 100000;
  1509. break;
  1510. case low_latency:
  1511. new_itr = 20000; /* aka hwitr = ~200 */
  1512. break;
  1513. case bulk_latency:
  1514. new_itr = 8000;
  1515. break;
  1516. default:
  1517. break;
  1518. }
  1519. if (new_itr != q_vector->eitr) {
  1520. /* do an exponential smoothing */
  1521. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1522. /* save the algorithm value here, not the smoothed one */
  1523. q_vector->eitr = new_itr;
  1524. ixgbe_write_eitr(q_vector);
  1525. }
  1526. return;
  1527. }
  1528. /**
  1529. * ixgbe_irq_enable - Enable default interrupt generation settings
  1530. * @adapter: board private structure
  1531. **/
  1532. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
  1533. {
  1534. u32 mask;
  1535. mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  1536. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  1537. mask |= IXGBE_EIMS_GPI_SDP1;
  1538. if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1539. mask |= IXGBE_EIMS_ECC;
  1540. mask |= IXGBE_EIMS_GPI_SDP1;
  1541. mask |= IXGBE_EIMS_GPI_SDP2;
  1542. }
  1543. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  1544. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  1545. mask |= IXGBE_EIMS_FLOW_DIR;
  1546. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1547. ixgbe_irq_enable_queues(adapter, ~0);
  1548. IXGBE_WRITE_FLUSH(&adapter->hw);
  1549. }
  1550. /**
  1551. * ixgbe_intr - legacy mode Interrupt Handler
  1552. * @irq: interrupt number
  1553. * @data: pointer to a network interface device structure
  1554. **/
  1555. static irqreturn_t ixgbe_intr(int irq, void *data)
  1556. {
  1557. struct net_device *netdev = data;
  1558. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1559. struct ixgbe_hw *hw = &adapter->hw;
  1560. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  1561. u32 eicr;
  1562. /*
  1563. * Workaround for silicon errata. Mask the interrupts
  1564. * before the read of EICR.
  1565. */
  1566. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  1567. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  1568. * therefore no explict interrupt disable is necessary */
  1569. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  1570. if (!eicr) {
  1571. /* shared interrupt alert!
  1572. * make sure interrupts are enabled because the read will
  1573. * have disabled interrupts due to EIAM */
  1574. ixgbe_irq_enable(adapter);
  1575. return IRQ_NONE; /* Not our interrupt */
  1576. }
  1577. if (eicr & IXGBE_EICR_LSC)
  1578. ixgbe_check_lsc(adapter);
  1579. if (hw->mac.type == ixgbe_mac_82599EB)
  1580. ixgbe_check_sfp_event(adapter, eicr);
  1581. ixgbe_check_fan_failure(adapter, eicr);
  1582. if (napi_schedule_prep(&(q_vector->napi))) {
  1583. adapter->tx_ring[0].total_packets = 0;
  1584. adapter->tx_ring[0].total_bytes = 0;
  1585. adapter->rx_ring[0].total_packets = 0;
  1586. adapter->rx_ring[0].total_bytes = 0;
  1587. /* would disable interrupts here but EIAM disabled it */
  1588. __napi_schedule(&(q_vector->napi));
  1589. }
  1590. return IRQ_HANDLED;
  1591. }
  1592. static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
  1593. {
  1594. int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1595. for (i = 0; i < q_vectors; i++) {
  1596. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  1597. bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
  1598. bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
  1599. q_vector->rxr_count = 0;
  1600. q_vector->txr_count = 0;
  1601. }
  1602. }
  1603. /**
  1604. * ixgbe_request_irq - initialize interrupts
  1605. * @adapter: board private structure
  1606. *
  1607. * Attempts to configure interrupts using the best available
  1608. * capabilities of the hardware and kernel.
  1609. **/
  1610. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  1611. {
  1612. struct net_device *netdev = adapter->netdev;
  1613. int err;
  1614. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  1615. err = ixgbe_request_msix_irqs(adapter);
  1616. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  1617. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  1618. netdev->name, netdev);
  1619. } else {
  1620. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  1621. netdev->name, netdev);
  1622. }
  1623. if (err)
  1624. DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
  1625. return err;
  1626. }
  1627. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  1628. {
  1629. struct net_device *netdev = adapter->netdev;
  1630. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  1631. int i, q_vectors;
  1632. q_vectors = adapter->num_msix_vectors;
  1633. i = q_vectors - 1;
  1634. free_irq(adapter->msix_entries[i].vector, netdev);
  1635. i--;
  1636. for (; i >= 0; i--) {
  1637. free_irq(adapter->msix_entries[i].vector,
  1638. adapter->q_vector[i]);
  1639. }
  1640. ixgbe_reset_q_vectors(adapter);
  1641. } else {
  1642. free_irq(adapter->pdev->irq, netdev);
  1643. }
  1644. }
  1645. /**
  1646. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  1647. * @adapter: board private structure
  1648. **/
  1649. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  1650. {
  1651. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1652. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  1653. } else {
  1654. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  1655. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  1656. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  1657. }
  1658. IXGBE_WRITE_FLUSH(&adapter->hw);
  1659. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  1660. int i;
  1661. for (i = 0; i < adapter->num_msix_vectors; i++)
  1662. synchronize_irq(adapter->msix_entries[i].vector);
  1663. } else {
  1664. synchronize_irq(adapter->pdev->irq);
  1665. }
  1666. }
  1667. /**
  1668. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  1669. *
  1670. **/
  1671. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  1672. {
  1673. struct ixgbe_hw *hw = &adapter->hw;
  1674. IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
  1675. EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
  1676. ixgbe_set_ivar(adapter, 0, 0, 0);
  1677. ixgbe_set_ivar(adapter, 1, 0, 0);
  1678. map_vector_to_rxq(adapter, 0, 0);
  1679. map_vector_to_txq(adapter, 0, 0);
  1680. DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
  1681. }
  1682. /**
  1683. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  1684. * @adapter: board private structure
  1685. *
  1686. * Configure the Tx unit of the MAC after a reset.
  1687. **/
  1688. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  1689. {
  1690. u64 tdba;
  1691. struct ixgbe_hw *hw = &adapter->hw;
  1692. u32 i, j, tdlen, txctrl;
  1693. /* Setup the HW Tx Head and Tail descriptor pointers */
  1694. for (i = 0; i < adapter->num_tx_queues; i++) {
  1695. struct ixgbe_ring *ring = &adapter->tx_ring[i];
  1696. j = ring->reg_idx;
  1697. tdba = ring->dma;
  1698. tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
  1699. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
  1700. (tdba & DMA_BIT_MASK(32)));
  1701. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
  1702. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
  1703. IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
  1704. IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
  1705. adapter->tx_ring[i].head = IXGBE_TDH(j);
  1706. adapter->tx_ring[i].tail = IXGBE_TDT(j);
  1707. /*
  1708. * Disable Tx Head Writeback RO bit, since this hoses
  1709. * bookkeeping if things aren't delivered in order.
  1710. */
  1711. switch (hw->mac.type) {
  1712. case ixgbe_mac_82598EB:
  1713. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
  1714. break;
  1715. case ixgbe_mac_82599EB:
  1716. default:
  1717. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j));
  1718. break;
  1719. }
  1720. txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
  1721. switch (hw->mac.type) {
  1722. case ixgbe_mac_82598EB:
  1723. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
  1724. break;
  1725. case ixgbe_mac_82599EB:
  1726. default:
  1727. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl);
  1728. break;
  1729. }
  1730. }
  1731. if (hw->mac.type == ixgbe_mac_82599EB) {
  1732. u32 rttdcs;
  1733. /* disable the arbiter while setting MTQC */
  1734. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  1735. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  1736. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  1737. /* We enable 8 traffic classes, DCB only */
  1738. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  1739. IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
  1740. IXGBE_MTQC_8TC_8TQ));
  1741. else
  1742. IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
  1743. /* re-eable the arbiter */
  1744. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  1745. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  1746. }
  1747. }
  1748. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  1749. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  1750. struct ixgbe_ring *rx_ring)
  1751. {
  1752. u32 srrctl;
  1753. int index;
  1754. struct ixgbe_ring_feature *feature = adapter->ring_feature;
  1755. index = rx_ring->reg_idx;
  1756. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1757. unsigned long mask;
  1758. mask = (unsigned long) feature[RING_F_RSS].mask;
  1759. index = index & mask;
  1760. }
  1761. srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
  1762. srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
  1763. srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
  1764. srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
  1765. IXGBE_SRRCTL_BSIZEHDR_MASK;
  1766. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1767. #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
  1768. srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  1769. #else
  1770. srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  1771. #endif
  1772. srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  1773. } else {
  1774. srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
  1775. IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  1776. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  1777. }
  1778. IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
  1779. }
  1780. static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  1781. {
  1782. u32 mrqc = 0;
  1783. int mask;
  1784. if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
  1785. return mrqc;
  1786. mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
  1787. #ifdef CONFIG_IXGBE_DCB
  1788. | IXGBE_FLAG_DCB_ENABLED
  1789. #endif
  1790. );
  1791. switch (mask) {
  1792. case (IXGBE_FLAG_RSS_ENABLED):
  1793. mrqc = IXGBE_MRQC_RSSEN;
  1794. break;
  1795. #ifdef CONFIG_IXGBE_DCB
  1796. case (IXGBE_FLAG_DCB_ENABLED):
  1797. mrqc = IXGBE_MRQC_RT8TCEN;
  1798. break;
  1799. #endif /* CONFIG_IXGBE_DCB */
  1800. default:
  1801. break;
  1802. }
  1803. return mrqc;
  1804. }
  1805. /**
  1806. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  1807. * @adapter: address of board private structure
  1808. * @index: index of ring to set
  1809. **/
  1810. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index)
  1811. {
  1812. struct ixgbe_ring *rx_ring;
  1813. struct ixgbe_hw *hw = &adapter->hw;
  1814. int j;
  1815. u32 rscctrl;
  1816. int rx_buf_len;
  1817. rx_ring = &adapter->rx_ring[index];
  1818. j = rx_ring->reg_idx;
  1819. rx_buf_len = rx_ring->rx_buf_len;
  1820. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
  1821. rscctrl |= IXGBE_RSCCTL_RSCEN;
  1822. /*
  1823. * we must limit the number of descriptors so that the
  1824. * total size of max desc * buf_len is not greater
  1825. * than 65535
  1826. */
  1827. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1828. #if (MAX_SKB_FRAGS > 16)
  1829. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  1830. #elif (MAX_SKB_FRAGS > 8)
  1831. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  1832. #elif (MAX_SKB_FRAGS > 4)
  1833. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  1834. #else
  1835. rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
  1836. #endif
  1837. } else {
  1838. if (rx_buf_len < IXGBE_RXBUFFER_4096)
  1839. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  1840. else if (rx_buf_len < IXGBE_RXBUFFER_8192)
  1841. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  1842. else
  1843. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  1844. }
  1845. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
  1846. }
  1847. /**
  1848. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  1849. * @adapter: board private structure
  1850. *
  1851. * Configure the Rx unit of the MAC after a reset.
  1852. **/
  1853. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  1854. {
  1855. u64 rdba;
  1856. struct ixgbe_hw *hw = &adapter->hw;
  1857. struct ixgbe_ring *rx_ring;
  1858. struct net_device *netdev = adapter->netdev;
  1859. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  1860. int i, j;
  1861. u32 rdlen, rxctrl, rxcsum;
  1862. static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
  1863. 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
  1864. 0x6A3E67EA, 0x14364D17, 0x3BED200D};
  1865. u32 fctrl, hlreg0;
  1866. u32 reta = 0, mrqc = 0;
  1867. u32 rdrxctl;
  1868. int rx_buf_len;
  1869. /* Decide whether to use packet split mode or not */
  1870. adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
  1871. /* Set the RX buffer length according to the mode */
  1872. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
  1873. rx_buf_len = IXGBE_RX_HDR_SIZE;
  1874. if (hw->mac.type == ixgbe_mac_82599EB) {
  1875. /* PSRTYPE must be initialized in 82599 */
  1876. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  1877. IXGBE_PSRTYPE_UDPHDR |
  1878. IXGBE_PSRTYPE_IPV4HDR |
  1879. IXGBE_PSRTYPE_IPV6HDR |
  1880. IXGBE_PSRTYPE_L2HDR;
  1881. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
  1882. }
  1883. } else {
  1884. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  1885. (netdev->mtu <= ETH_DATA_LEN))
  1886. rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  1887. else
  1888. rx_buf_len = ALIGN(max_frame, 1024);
  1889. }
  1890. fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
  1891. fctrl |= IXGBE_FCTRL_BAM;
  1892. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  1893. fctrl |= IXGBE_FCTRL_PMCF;
  1894. IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
  1895. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  1896. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1897. hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
  1898. else
  1899. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  1900. #ifdef IXGBE_FCOE
  1901. if (netdev->features & NETIF_F_FCOE_MTU)
  1902. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  1903. #endif
  1904. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  1905. rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
  1906. /* disable receives while setting up the descriptors */
  1907. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  1908. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  1909. /*
  1910. * Setup the HW Rx Head and Tail Descriptor Pointers and
  1911. * the Base and Length of the Rx Descriptor Ring
  1912. */
  1913. for (i = 0; i < adapter->num_rx_queues; i++) {
  1914. rx_ring = &adapter->rx_ring[i];
  1915. rdba = rx_ring->dma;
  1916. j = rx_ring->reg_idx;
  1917. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
  1918. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
  1919. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
  1920. IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
  1921. IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
  1922. rx_ring->head = IXGBE_RDH(j);
  1923. rx_ring->tail = IXGBE_RDT(j);
  1924. rx_ring->rx_buf_len = rx_buf_len;
  1925. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
  1926. rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
  1927. else
  1928. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  1929. #ifdef IXGBE_FCOE
  1930. if (netdev->features & NETIF_F_FCOE_MTU) {
  1931. struct ixgbe_ring_feature *f;
  1932. f = &adapter->ring_feature[RING_F_FCOE];
  1933. if ((i >= f->mask) && (i < f->mask + f->indices)) {
  1934. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  1935. if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
  1936. rx_ring->rx_buf_len =
  1937. IXGBE_FCOE_JUMBO_FRAME_SIZE;
  1938. }
  1939. }
  1940. #endif /* IXGBE_FCOE */
  1941. ixgbe_configure_srrctl(adapter, rx_ring);
  1942. }
  1943. if (hw->mac.type == ixgbe_mac_82598EB) {
  1944. /*
  1945. * For VMDq support of different descriptor types or
  1946. * buffer sizes through the use of multiple SRRCTL
  1947. * registers, RDRXCTL.MVMEN must be set to 1
  1948. *
  1949. * also, the manual doesn't mention it clearly but DCA hints
  1950. * will only use queue 0's tags unless this bit is set. Side
  1951. * effects of setting this bit are only that SRRCTL must be
  1952. * fully programmed [0..15]
  1953. */
  1954. rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  1955. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  1956. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  1957. }
  1958. /* Program MRQC for the distribution of queues */
  1959. mrqc = ixgbe_setup_mrqc(adapter);
  1960. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  1961. /* Fill out redirection table */
  1962. for (i = 0, j = 0; i < 128; i++, j++) {
  1963. if (j == adapter->ring_feature[RING_F_RSS].indices)
  1964. j = 0;
  1965. /* reta = 4-byte sliding window of
  1966. * 0x00..(indices-1)(indices-1)00..etc. */
  1967. reta = (reta << 8) | (j * 0x11);
  1968. if ((i & 3) == 3)
  1969. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  1970. }
  1971. /* Fill out hash function seeds */
  1972. for (i = 0; i < 10; i++)
  1973. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
  1974. if (hw->mac.type == ixgbe_mac_82598EB)
  1975. mrqc |= IXGBE_MRQC_RSSEN;
  1976. /* Perform hash on these packet types */
  1977. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
  1978. | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
  1979. | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
  1980. | IXGBE_MRQC_RSS_FIELD_IPV6
  1981. | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
  1982. | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  1983. }
  1984. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  1985. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  1986. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
  1987. adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
  1988. /* Disable indicating checksum in descriptor, enables
  1989. * RSS hash */
  1990. rxcsum |= IXGBE_RXCSUM_PCSD;
  1991. }
  1992. if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
  1993. /* Enable IPv4 payload checksum for UDP fragments
  1994. * if PCSD is not set */
  1995. rxcsum |= IXGBE_RXCSUM_IPPCSE;
  1996. }
  1997. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  1998. if (hw->mac.type == ixgbe_mac_82599EB) {
  1999. rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  2000. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  2001. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  2002. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  2003. }
  2004. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  2005. /* Enable 82599 HW-RSC */
  2006. for (i = 0; i < adapter->num_rx_queues; i++)
  2007. ixgbe_configure_rscctl(adapter, i);
  2008. /* Disable RSC for ACK packets */
  2009. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  2010. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  2011. }
  2012. }
  2013. static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  2014. {
  2015. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2016. struct ixgbe_hw *hw = &adapter->hw;
  2017. /* add VID to filter table */
  2018. hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
  2019. }
  2020. static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  2021. {
  2022. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2023. struct ixgbe_hw *hw = &adapter->hw;
  2024. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2025. ixgbe_irq_disable(adapter);
  2026. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  2027. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2028. ixgbe_irq_enable(adapter);
  2029. /* remove VID from filter table */
  2030. hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
  2031. }
  2032. static void ixgbe_vlan_rx_register(struct net_device *netdev,
  2033. struct vlan_group *grp)
  2034. {
  2035. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2036. u32 ctrl;
  2037. int i, j;
  2038. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2039. ixgbe_irq_disable(adapter);
  2040. adapter->vlgrp = grp;
  2041. /*
  2042. * For a DCB driver, always enable VLAN tag stripping so we can
  2043. * still receive traffic from a DCB-enabled host even if we're
  2044. * not in DCB mode.
  2045. */
  2046. ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
  2047. /* Disable CFI check */
  2048. ctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2049. /* enable VLAN tag stripping */
  2050. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2051. ctrl |= IXGBE_VLNCTRL_VME;
  2052. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  2053. for (i = 0; i < adapter->num_rx_queues; i++) {
  2054. u32 ctrl;
  2055. j = adapter->rx_ring[i].reg_idx;
  2056. ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
  2057. ctrl |= IXGBE_RXDCTL_VME;
  2058. IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
  2059. }
  2060. }
  2061. IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
  2062. ixgbe_vlan_rx_add_vid(netdev, 0);
  2063. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2064. ixgbe_irq_enable(adapter);
  2065. }
  2066. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  2067. {
  2068. ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  2069. if (adapter->vlgrp) {
  2070. u16 vid;
  2071. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  2072. if (!vlan_group_get_device(adapter->vlgrp, vid))
  2073. continue;
  2074. ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
  2075. }
  2076. }
  2077. }
  2078. static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
  2079. {
  2080. struct dev_mc_list *mc_ptr;
  2081. u8 *addr = *mc_addr_ptr;
  2082. *vmdq = 0;
  2083. mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
  2084. if (mc_ptr->next)
  2085. *mc_addr_ptr = mc_ptr->next->dmi_addr;
  2086. else
  2087. *mc_addr_ptr = NULL;
  2088. return addr;
  2089. }
  2090. /**
  2091. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  2092. * @netdev: network interface device structure
  2093. *
  2094. * The set_rx_method entry point is called whenever the unicast/multicast
  2095. * address list or the network interface flags are updated. This routine is
  2096. * responsible for configuring the hardware for proper unicast, multicast and
  2097. * promiscuous mode.
  2098. **/
  2099. static void ixgbe_set_rx_mode(struct net_device *netdev)
  2100. {
  2101. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2102. struct ixgbe_hw *hw = &adapter->hw;
  2103. u32 fctrl, vlnctrl;
  2104. u8 *addr_list = NULL;
  2105. int addr_count = 0;
  2106. /* Check for Promiscuous and All Multicast modes */
  2107. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  2108. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2109. if (netdev->flags & IFF_PROMISC) {
  2110. hw->addr_ctrl.user_set_promisc = 1;
  2111. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2112. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  2113. } else {
  2114. if (netdev->flags & IFF_ALLMULTI) {
  2115. fctrl |= IXGBE_FCTRL_MPE;
  2116. fctrl &= ~IXGBE_FCTRL_UPE;
  2117. } else {
  2118. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2119. }
  2120. vlnctrl |= IXGBE_VLNCTRL_VFE;
  2121. hw->addr_ctrl.user_set_promisc = 0;
  2122. }
  2123. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  2124. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2125. /* reprogram secondary unicast list */
  2126. hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
  2127. /* reprogram multicast list */
  2128. addr_count = netdev->mc_count;
  2129. if (addr_count)
  2130. addr_list = netdev->mc_list->dmi_addr;
  2131. hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
  2132. ixgbe_addr_list_itr);
  2133. }
  2134. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  2135. {
  2136. int q_idx;
  2137. struct ixgbe_q_vector *q_vector;
  2138. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2139. /* legacy and MSI only use one vector */
  2140. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2141. q_vectors = 1;
  2142. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2143. struct napi_struct *napi;
  2144. q_vector = adapter->q_vector[q_idx];
  2145. napi = &q_vector->napi;
  2146. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2147. if (!q_vector->rxr_count || !q_vector->txr_count) {
  2148. if (q_vector->txr_count == 1)
  2149. napi->poll = &ixgbe_clean_txonly;
  2150. else if (q_vector->rxr_count == 1)
  2151. napi->poll = &ixgbe_clean_rxonly;
  2152. }
  2153. }
  2154. napi_enable(napi);
  2155. }
  2156. }
  2157. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  2158. {
  2159. int q_idx;
  2160. struct ixgbe_q_vector *q_vector;
  2161. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2162. /* legacy and MSI only use one vector */
  2163. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2164. q_vectors = 1;
  2165. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2166. q_vector = adapter->q_vector[q_idx];
  2167. napi_disable(&q_vector->napi);
  2168. }
  2169. }
  2170. #ifdef CONFIG_IXGBE_DCB
  2171. /*
  2172. * ixgbe_configure_dcb - Configure DCB hardware
  2173. * @adapter: ixgbe adapter struct
  2174. *
  2175. * This is called by the driver on open to configure the DCB hardware.
  2176. * This is also called by the gennetlink interface when reconfiguring
  2177. * the DCB state.
  2178. */
  2179. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  2180. {
  2181. struct ixgbe_hw *hw = &adapter->hw;
  2182. u32 txdctl, vlnctrl;
  2183. int i, j;
  2184. ixgbe_dcb_check_config(&adapter->dcb_cfg);
  2185. ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
  2186. ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
  2187. /* reconfigure the hardware */
  2188. ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
  2189. for (i = 0; i < adapter->num_tx_queues; i++) {
  2190. j = adapter->tx_ring[i].reg_idx;
  2191. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2192. /* PThresh workaround for Tx hang with DFP enabled. */
  2193. txdctl |= 32;
  2194. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2195. }
  2196. /* Enable VLAN tag insert/strip */
  2197. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2198. if (hw->mac.type == ixgbe_mac_82598EB) {
  2199. vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
  2200. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2201. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2202. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  2203. vlnctrl |= IXGBE_VLNCTRL_VFE;
  2204. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2205. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2206. for (i = 0; i < adapter->num_rx_queues; i++) {
  2207. j = adapter->rx_ring[i].reg_idx;
  2208. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2209. vlnctrl |= IXGBE_RXDCTL_VME;
  2210. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  2211. }
  2212. }
  2213. hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
  2214. }
  2215. #endif
  2216. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  2217. {
  2218. struct net_device *netdev = adapter->netdev;
  2219. struct ixgbe_hw *hw = &adapter->hw;
  2220. int i;
  2221. ixgbe_set_rx_mode(netdev);
  2222. ixgbe_restore_vlan(adapter);
  2223. #ifdef CONFIG_IXGBE_DCB
  2224. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  2225. if (hw->mac.type == ixgbe_mac_82598EB)
  2226. netif_set_gso_max_size(netdev, 32768);
  2227. else
  2228. netif_set_gso_max_size(netdev, 65536);
  2229. ixgbe_configure_dcb(adapter);
  2230. } else {
  2231. netif_set_gso_max_size(netdev, 65536);
  2232. }
  2233. #else
  2234. netif_set_gso_max_size(netdev, 65536);
  2235. #endif
  2236. #ifdef IXGBE_FCOE
  2237. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  2238. ixgbe_configure_fcoe(adapter);
  2239. #endif /* IXGBE_FCOE */
  2240. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2241. for (i = 0; i < adapter->num_tx_queues; i++)
  2242. adapter->tx_ring[i].atr_sample_rate =
  2243. adapter->atr_sample_rate;
  2244. ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
  2245. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  2246. ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
  2247. }
  2248. ixgbe_configure_tx(adapter);
  2249. ixgbe_configure_rx(adapter);
  2250. for (i = 0; i < adapter->num_rx_queues; i++)
  2251. ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
  2252. (adapter->rx_ring[i].count - 1));
  2253. }
  2254. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2255. {
  2256. switch (hw->phy.type) {
  2257. case ixgbe_phy_sfp_avago:
  2258. case ixgbe_phy_sfp_ftl:
  2259. case ixgbe_phy_sfp_intel:
  2260. case ixgbe_phy_sfp_unknown:
  2261. case ixgbe_phy_tw_tyco:
  2262. case ixgbe_phy_tw_unknown:
  2263. return true;
  2264. default:
  2265. return false;
  2266. }
  2267. }
  2268. /**
  2269. * ixgbe_sfp_link_config - set up SFP+ link
  2270. * @adapter: pointer to private adapter struct
  2271. **/
  2272. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  2273. {
  2274. struct ixgbe_hw *hw = &adapter->hw;
  2275. if (hw->phy.multispeed_fiber) {
  2276. /*
  2277. * In multispeed fiber setups, the device may not have
  2278. * had a physical connection when the driver loaded.
  2279. * If that's the case, the initial link configuration
  2280. * couldn't get the MAC into 10G or 1G mode, so we'll
  2281. * never have a link status change interrupt fire.
  2282. * We need to try and force an autonegotiation
  2283. * session, then bring up link.
  2284. */
  2285. hw->mac.ops.setup_sfp(hw);
  2286. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  2287. schedule_work(&adapter->multispeed_fiber_task);
  2288. } else {
  2289. /*
  2290. * Direct Attach Cu and non-multispeed fiber modules
  2291. * still need to be configured properly prior to
  2292. * attempting link.
  2293. */
  2294. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
  2295. schedule_work(&adapter->sfp_config_module_task);
  2296. }
  2297. }
  2298. /**
  2299. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  2300. * @hw: pointer to private hardware struct
  2301. *
  2302. * Returns 0 on success, negative on failure
  2303. **/
  2304. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  2305. {
  2306. u32 autoneg;
  2307. bool negotiation, link_up = false;
  2308. u32 ret = IXGBE_ERR_LINK_SETUP;
  2309. if (hw->mac.ops.check_link)
  2310. ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
  2311. if (ret)
  2312. goto link_cfg_out;
  2313. if (hw->mac.ops.get_link_capabilities)
  2314. ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  2315. if (ret)
  2316. goto link_cfg_out;
  2317. if (hw->mac.ops.setup_link)
  2318. ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
  2319. link_cfg_out:
  2320. return ret;
  2321. }
  2322. #define IXGBE_MAX_RX_DESC_POLL 10
  2323. static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  2324. int rxr)
  2325. {
  2326. int j = adapter->rx_ring[rxr].reg_idx;
  2327. int k;
  2328. for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
  2329. if (IXGBE_READ_REG(&adapter->hw,
  2330. IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
  2331. break;
  2332. else
  2333. msleep(1);
  2334. }
  2335. if (k >= IXGBE_MAX_RX_DESC_POLL) {
  2336. DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
  2337. "not set within the polling period\n", rxr);
  2338. }
  2339. ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
  2340. (adapter->rx_ring[rxr].count - 1));
  2341. }
  2342. static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
  2343. {
  2344. struct net_device *netdev = adapter->netdev;
  2345. struct ixgbe_hw *hw = &adapter->hw;
  2346. int i, j = 0;
  2347. int num_rx_rings = adapter->num_rx_queues;
  2348. int err;
  2349. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2350. u32 txdctl, rxdctl, mhadd;
  2351. u32 dmatxctl;
  2352. u32 gpie;
  2353. ixgbe_get_hw_control(adapter);
  2354. if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
  2355. (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
  2356. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2357. gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
  2358. IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
  2359. } else {
  2360. /* MSI only */
  2361. gpie = 0;
  2362. }
  2363. /* XXX: to interrupt immediately for EICS writes, enable this */
  2364. /* gpie |= IXGBE_GPIE_EIMEN; */
  2365. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2366. }
  2367. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2368. /*
  2369. * use EIAM to auto-mask when MSI-X interrupt is asserted
  2370. * this saves a register write for every interrupt
  2371. */
  2372. switch (hw->mac.type) {
  2373. case ixgbe_mac_82598EB:
  2374. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  2375. break;
  2376. default:
  2377. case ixgbe_mac_82599EB:
  2378. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  2379. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  2380. break;
  2381. }
  2382. } else {
  2383. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  2384. * specifically only auto mask tx and rx interrupts */
  2385. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  2386. }
  2387. /* Enable fan failure interrupt if media type is copper */
  2388. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  2389. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  2390. gpie |= IXGBE_SDP1_GPIEN;
  2391. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2392. }
  2393. if (hw->mac.type == ixgbe_mac_82599EB) {
  2394. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  2395. gpie |= IXGBE_SDP1_GPIEN;
  2396. gpie |= IXGBE_SDP2_GPIEN;
  2397. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  2398. }
  2399. #ifdef IXGBE_FCOE
  2400. /* adjust max frame to be able to do baby jumbo for FCoE */
  2401. if ((netdev->features & NETIF_F_FCOE_MTU) &&
  2402. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  2403. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2404. #endif /* IXGBE_FCOE */
  2405. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  2406. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  2407. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  2408. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  2409. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  2410. }
  2411. for (i = 0; i < adapter->num_tx_queues; i++) {
  2412. j = adapter->tx_ring[i].reg_idx;
  2413. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2414. /* enable WTHRESH=8 descriptors, to encourage burst writeback */
  2415. txdctl |= (8 << 16);
  2416. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2417. }
  2418. if (hw->mac.type == ixgbe_mac_82599EB) {
  2419. /* DMATXCTL.EN must be set after all Tx queue config is done */
  2420. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2421. dmatxctl |= IXGBE_DMATXCTL_TE;
  2422. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2423. }
  2424. for (i = 0; i < adapter->num_tx_queues; i++) {
  2425. j = adapter->tx_ring[i].reg_idx;
  2426. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2427. txdctl |= IXGBE_TXDCTL_ENABLE;
  2428. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2429. }
  2430. for (i = 0; i < num_rx_rings; i++) {
  2431. j = adapter->rx_ring[i].reg_idx;
  2432. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2433. /* enable PTHRESH=32 descriptors (half the internal cache)
  2434. * and HTHRESH=0 descriptors (to minimize latency on fetch),
  2435. * this also removes a pesky rx_no_buffer_count increment */
  2436. rxdctl |= 0x0020;
  2437. rxdctl |= IXGBE_RXDCTL_ENABLE;
  2438. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
  2439. if (hw->mac.type == ixgbe_mac_82599EB)
  2440. ixgbe_rx_desc_queue_enable(adapter, i);
  2441. }
  2442. /* enable all receives */
  2443. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2444. if (hw->mac.type == ixgbe_mac_82598EB)
  2445. rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
  2446. else
  2447. rxdctl |= IXGBE_RXCTRL_RXEN;
  2448. hw->mac.ops.enable_rx_dma(hw, rxdctl);
  2449. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2450. ixgbe_configure_msix(adapter);
  2451. else
  2452. ixgbe_configure_msi_and_legacy(adapter);
  2453. clear_bit(__IXGBE_DOWN, &adapter->state);
  2454. ixgbe_napi_enable_all(adapter);
  2455. /* clear any pending interrupts, may auto mask */
  2456. IXGBE_READ_REG(hw, IXGBE_EICR);
  2457. ixgbe_irq_enable(adapter);
  2458. /*
  2459. * If this adapter has a fan, check to see if we had a failure
  2460. * before we enabled the interrupt.
  2461. */
  2462. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  2463. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  2464. if (esdp & IXGBE_ESDP_SDP1)
  2465. DPRINTK(DRV, CRIT,
  2466. "Fan has stopped, replace the adapter\n");
  2467. }
  2468. /*
  2469. * For hot-pluggable SFP+ devices, a new SFP+ module may have
  2470. * arrived before interrupts were enabled but after probe. Such
  2471. * devices wouldn't have their type identified yet. We need to
  2472. * kick off the SFP+ module setup first, then try to bring up link.
  2473. * If we're not hot-pluggable SFP+, we just need to configure link
  2474. * and bring it up.
  2475. */
  2476. if (hw->phy.type == ixgbe_phy_unknown) {
  2477. err = hw->phy.ops.identify(hw);
  2478. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  2479. /*
  2480. * Take the device down and schedule the sfp tasklet
  2481. * which will unregister_netdev and log it.
  2482. */
  2483. ixgbe_down(adapter);
  2484. schedule_work(&adapter->sfp_config_module_task);
  2485. return err;
  2486. }
  2487. }
  2488. if (ixgbe_is_sfp(hw)) {
  2489. ixgbe_sfp_link_config(adapter);
  2490. } else {
  2491. err = ixgbe_non_sfp_link_config(hw);
  2492. if (err)
  2493. DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
  2494. }
  2495. for (i = 0; i < adapter->num_tx_queues; i++)
  2496. set_bit(__IXGBE_FDIR_INIT_DONE,
  2497. &(adapter->tx_ring[i].reinit_state));
  2498. /* enable transmits */
  2499. netif_tx_start_all_queues(netdev);
  2500. /* bring the link up in the watchdog, this could race with our first
  2501. * link up interrupt but shouldn't be a problem */
  2502. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2503. adapter->link_check_timeout = jiffies;
  2504. mod_timer(&adapter->watchdog_timer, jiffies);
  2505. return 0;
  2506. }
  2507. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  2508. {
  2509. WARN_ON(in_interrupt());
  2510. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  2511. msleep(1);
  2512. ixgbe_down(adapter);
  2513. ixgbe_up(adapter);
  2514. clear_bit(__IXGBE_RESETTING, &adapter->state);
  2515. }
  2516. int ixgbe_up(struct ixgbe_adapter *adapter)
  2517. {
  2518. /* hardware has been reset, we need to reload some things */
  2519. ixgbe_configure(adapter);
  2520. return ixgbe_up_complete(adapter);
  2521. }
  2522. void ixgbe_reset(struct ixgbe_adapter *adapter)
  2523. {
  2524. struct ixgbe_hw *hw = &adapter->hw;
  2525. int err;
  2526. err = hw->mac.ops.init_hw(hw);
  2527. switch (err) {
  2528. case 0:
  2529. case IXGBE_ERR_SFP_NOT_PRESENT:
  2530. break;
  2531. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  2532. dev_err(&adapter->pdev->dev, "master disable timed out\n");
  2533. break;
  2534. case IXGBE_ERR_EEPROM_VERSION:
  2535. /* We are running on a pre-production device, log a warning */
  2536. dev_warn(&adapter->pdev->dev, "This device is a pre-production "
  2537. "adapter/LOM. Please be aware there may be issues "
  2538. "associated with your hardware. If you are "
  2539. "experiencing problems please contact your Intel or "
  2540. "hardware representative who provided you with this "
  2541. "hardware.\n");
  2542. break;
  2543. default:
  2544. dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
  2545. }
  2546. /* reprogram the RAR[0] in case user changed it. */
  2547. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  2548. }
  2549. /**
  2550. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  2551. * @adapter: board private structure
  2552. * @rx_ring: ring to free buffers from
  2553. **/
  2554. static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
  2555. struct ixgbe_ring *rx_ring)
  2556. {
  2557. struct pci_dev *pdev = adapter->pdev;
  2558. unsigned long size;
  2559. unsigned int i;
  2560. /* Free all the Rx ring sk_buffs */
  2561. for (i = 0; i < rx_ring->count; i++) {
  2562. struct ixgbe_rx_buffer *rx_buffer_info;
  2563. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  2564. if (rx_buffer_info->dma) {
  2565. pci_unmap_single(pdev, rx_buffer_info->dma,
  2566. rx_ring->rx_buf_len,
  2567. PCI_DMA_FROMDEVICE);
  2568. rx_buffer_info->dma = 0;
  2569. }
  2570. if (rx_buffer_info->skb) {
  2571. struct sk_buff *skb = rx_buffer_info->skb;
  2572. rx_buffer_info->skb = NULL;
  2573. do {
  2574. struct sk_buff *this = skb;
  2575. skb = skb->prev;
  2576. dev_kfree_skb(this);
  2577. } while (skb);
  2578. }
  2579. if (!rx_buffer_info->page)
  2580. continue;
  2581. if (rx_buffer_info->page_dma) {
  2582. pci_unmap_page(pdev, rx_buffer_info->page_dma,
  2583. PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
  2584. rx_buffer_info->page_dma = 0;
  2585. }
  2586. put_page(rx_buffer_info->page);
  2587. rx_buffer_info->page = NULL;
  2588. rx_buffer_info->page_offset = 0;
  2589. }
  2590. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  2591. memset(rx_ring->rx_buffer_info, 0, size);
  2592. /* Zero out the descriptor ring */
  2593. memset(rx_ring->desc, 0, rx_ring->size);
  2594. rx_ring->next_to_clean = 0;
  2595. rx_ring->next_to_use = 0;
  2596. if (rx_ring->head)
  2597. writel(0, adapter->hw.hw_addr + rx_ring->head);
  2598. if (rx_ring->tail)
  2599. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  2600. }
  2601. /**
  2602. * ixgbe_clean_tx_ring - Free Tx Buffers
  2603. * @adapter: board private structure
  2604. * @tx_ring: ring to be cleaned
  2605. **/
  2606. static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
  2607. struct ixgbe_ring *tx_ring)
  2608. {
  2609. struct ixgbe_tx_buffer *tx_buffer_info;
  2610. unsigned long size;
  2611. unsigned int i;
  2612. /* Free all the Tx ring sk_buffs */
  2613. for (i = 0; i < tx_ring->count; i++) {
  2614. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  2615. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  2616. }
  2617. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  2618. memset(tx_ring->tx_buffer_info, 0, size);
  2619. /* Zero out the descriptor ring */
  2620. memset(tx_ring->desc, 0, tx_ring->size);
  2621. tx_ring->next_to_use = 0;
  2622. tx_ring->next_to_clean = 0;
  2623. if (tx_ring->head)
  2624. writel(0, adapter->hw.hw_addr + tx_ring->head);
  2625. if (tx_ring->tail)
  2626. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  2627. }
  2628. /**
  2629. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  2630. * @adapter: board private structure
  2631. **/
  2632. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  2633. {
  2634. int i;
  2635. for (i = 0; i < adapter->num_rx_queues; i++)
  2636. ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
  2637. }
  2638. /**
  2639. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  2640. * @adapter: board private structure
  2641. **/
  2642. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  2643. {
  2644. int i;
  2645. for (i = 0; i < adapter->num_tx_queues; i++)
  2646. ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
  2647. }
  2648. void ixgbe_down(struct ixgbe_adapter *adapter)
  2649. {
  2650. struct net_device *netdev = adapter->netdev;
  2651. struct ixgbe_hw *hw = &adapter->hw;
  2652. u32 rxctrl;
  2653. u32 txdctl;
  2654. int i, j;
  2655. /* signal that we are down to the interrupt handler */
  2656. set_bit(__IXGBE_DOWN, &adapter->state);
  2657. /* disable receives */
  2658. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2659. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  2660. netif_tx_disable(netdev);
  2661. IXGBE_WRITE_FLUSH(hw);
  2662. msleep(10);
  2663. netif_tx_stop_all_queues(netdev);
  2664. ixgbe_irq_disable(adapter);
  2665. ixgbe_napi_disable_all(adapter);
  2666. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  2667. del_timer_sync(&adapter->sfp_timer);
  2668. del_timer_sync(&adapter->watchdog_timer);
  2669. cancel_work_sync(&adapter->watchdog_task);
  2670. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  2671. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  2672. cancel_work_sync(&adapter->fdir_reinit_task);
  2673. /* disable transmits in the hardware now that interrupts are off */
  2674. for (i = 0; i < adapter->num_tx_queues; i++) {
  2675. j = adapter->tx_ring[i].reg_idx;
  2676. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2677. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
  2678. (txdctl & ~IXGBE_TXDCTL_ENABLE));
  2679. }
  2680. /* Disable the Tx DMA engine on 82599 */
  2681. if (hw->mac.type == ixgbe_mac_82599EB)
  2682. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  2683. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  2684. ~IXGBE_DMATXCTL_TE));
  2685. netif_carrier_off(netdev);
  2686. if (!pci_channel_offline(adapter->pdev))
  2687. ixgbe_reset(adapter);
  2688. ixgbe_clean_all_tx_rings(adapter);
  2689. ixgbe_clean_all_rx_rings(adapter);
  2690. #ifdef CONFIG_IXGBE_DCA
  2691. /* since we reset the hardware DCA settings were cleared */
  2692. ixgbe_setup_dca(adapter);
  2693. #endif
  2694. }
  2695. /**
  2696. * ixgbe_poll - NAPI Rx polling callback
  2697. * @napi: structure for representing this polling device
  2698. * @budget: how many packets driver is allowed to clean
  2699. *
  2700. * This function is used for legacy and MSI, NAPI mode
  2701. **/
  2702. static int ixgbe_poll(struct napi_struct *napi, int budget)
  2703. {
  2704. struct ixgbe_q_vector *q_vector =
  2705. container_of(napi, struct ixgbe_q_vector, napi);
  2706. struct ixgbe_adapter *adapter = q_vector->adapter;
  2707. int tx_clean_complete, work_done = 0;
  2708. #ifdef CONFIG_IXGBE_DCA
  2709. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  2710. ixgbe_update_tx_dca(adapter, adapter->tx_ring);
  2711. ixgbe_update_rx_dca(adapter, adapter->rx_ring);
  2712. }
  2713. #endif
  2714. tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
  2715. ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
  2716. if (!tx_clean_complete)
  2717. work_done = budget;
  2718. /* If budget not fully consumed, exit the polling mode */
  2719. if (work_done < budget) {
  2720. napi_complete(napi);
  2721. if (adapter->rx_itr_setting & 1)
  2722. ixgbe_set_itr(adapter);
  2723. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2724. ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
  2725. }
  2726. return work_done;
  2727. }
  2728. /**
  2729. * ixgbe_tx_timeout - Respond to a Tx Hang
  2730. * @netdev: network interface device structure
  2731. **/
  2732. static void ixgbe_tx_timeout(struct net_device *netdev)
  2733. {
  2734. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2735. /* Do the reset outside of interrupt context */
  2736. schedule_work(&adapter->reset_task);
  2737. }
  2738. static void ixgbe_reset_task(struct work_struct *work)
  2739. {
  2740. struct ixgbe_adapter *adapter;
  2741. adapter = container_of(work, struct ixgbe_adapter, reset_task);
  2742. /* If we're already down or resetting, just bail */
  2743. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  2744. test_bit(__IXGBE_RESETTING, &adapter->state))
  2745. return;
  2746. adapter->tx_timeout_count++;
  2747. ixgbe_reinit_locked(adapter);
  2748. }
  2749. #ifdef CONFIG_IXGBE_DCB
  2750. static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
  2751. {
  2752. bool ret = false;
  2753. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
  2754. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
  2755. return ret;
  2756. f->mask = 0x7 << 3;
  2757. adapter->num_rx_queues = f->indices;
  2758. adapter->num_tx_queues = f->indices;
  2759. ret = true;
  2760. return ret;
  2761. }
  2762. #endif
  2763. /**
  2764. * ixgbe_set_rss_queues: Allocate queues for RSS
  2765. * @adapter: board private structure to initialize
  2766. *
  2767. * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
  2768. * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
  2769. *
  2770. **/
  2771. static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
  2772. {
  2773. bool ret = false;
  2774. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
  2775. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  2776. f->mask = 0xF;
  2777. adapter->num_rx_queues = f->indices;
  2778. adapter->num_tx_queues = f->indices;
  2779. ret = true;
  2780. } else {
  2781. ret = false;
  2782. }
  2783. return ret;
  2784. }
  2785. /**
  2786. * ixgbe_set_fdir_queues: Allocate queues for Flow Director
  2787. * @adapter: board private structure to initialize
  2788. *
  2789. * Flow Director is an advanced Rx filter, attempting to get Rx flows back
  2790. * to the original CPU that initiated the Tx session. This runs in addition
  2791. * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
  2792. * Rx load across CPUs using RSS.
  2793. *
  2794. **/
  2795. static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
  2796. {
  2797. bool ret = false;
  2798. struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
  2799. f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
  2800. f_fdir->mask = 0;
  2801. /* Flow Director must have RSS enabled */
  2802. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  2803. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  2804. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
  2805. adapter->num_tx_queues = f_fdir->indices;
  2806. adapter->num_rx_queues = f_fdir->indices;
  2807. ret = true;
  2808. } else {
  2809. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  2810. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  2811. }
  2812. return ret;
  2813. }
  2814. #ifdef IXGBE_FCOE
  2815. /**
  2816. * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
  2817. * @adapter: board private structure to initialize
  2818. *
  2819. * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
  2820. * The ring feature mask is not used as a mask for FCoE, as it can take any 8
  2821. * rx queues out of the max number of rx queues, instead, it is used as the
  2822. * index of the first rx queue used by FCoE.
  2823. *
  2824. **/
  2825. static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
  2826. {
  2827. bool ret = false;
  2828. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  2829. f->indices = min((int)num_online_cpus(), f->indices);
  2830. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  2831. adapter->num_rx_queues = 1;
  2832. adapter->num_tx_queues = 1;
  2833. #ifdef CONFIG_IXGBE_DCB
  2834. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  2835. DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
  2836. ixgbe_set_dcb_queues(adapter);
  2837. }
  2838. #endif
  2839. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  2840. DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
  2841. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  2842. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  2843. ixgbe_set_fdir_queues(adapter);
  2844. else
  2845. ixgbe_set_rss_queues(adapter);
  2846. }
  2847. /* adding FCoE rx rings to the end */
  2848. f->mask = adapter->num_rx_queues;
  2849. adapter->num_rx_queues += f->indices;
  2850. adapter->num_tx_queues += f->indices;
  2851. ret = true;
  2852. }
  2853. return ret;
  2854. }
  2855. #endif /* IXGBE_FCOE */
  2856. /*
  2857. * ixgbe_set_num_queues: Allocate queues for device, feature dependant
  2858. * @adapter: board private structure to initialize
  2859. *
  2860. * This is the top level queue allocation routine. The order here is very
  2861. * important, starting with the "most" number of features turned on at once,
  2862. * and ending with the smallest set of features. This way large combinations
  2863. * can be allocated if they're turned on, and smaller combinations are the
  2864. * fallthrough conditions.
  2865. *
  2866. **/
  2867. static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
  2868. {
  2869. #ifdef IXGBE_FCOE
  2870. if (ixgbe_set_fcoe_queues(adapter))
  2871. goto done;
  2872. #endif /* IXGBE_FCOE */
  2873. #ifdef CONFIG_IXGBE_DCB
  2874. if (ixgbe_set_dcb_queues(adapter))
  2875. goto done;
  2876. #endif
  2877. if (ixgbe_set_fdir_queues(adapter))
  2878. goto done;
  2879. if (ixgbe_set_rss_queues(adapter))
  2880. goto done;
  2881. /* fallback to base case */
  2882. adapter->num_rx_queues = 1;
  2883. adapter->num_tx_queues = 1;
  2884. done:
  2885. /* Notify the stack of the (possibly) reduced Tx Queue count. */
  2886. adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
  2887. }
  2888. static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
  2889. int vectors)
  2890. {
  2891. int err, vector_threshold;
  2892. /* We'll want at least 3 (vector_threshold):
  2893. * 1) TxQ[0] Cleanup
  2894. * 2) RxQ[0] Cleanup
  2895. * 3) Other (Link Status Change, etc.)
  2896. * 4) TCP Timer (optional)
  2897. */
  2898. vector_threshold = MIN_MSIX_COUNT;
  2899. /* The more we get, the more we will assign to Tx/Rx Cleanup
  2900. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  2901. * Right now, we simply care about how many we'll get; we'll
  2902. * set them up later while requesting irq's.
  2903. */
  2904. while (vectors >= vector_threshold) {
  2905. err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
  2906. vectors);
  2907. if (!err) /* Success in acquiring all requested vectors. */
  2908. break;
  2909. else if (err < 0)
  2910. vectors = 0; /* Nasty failure, quit now */
  2911. else /* err == number of vectors we should try again with */
  2912. vectors = err;
  2913. }
  2914. if (vectors < vector_threshold) {
  2915. /* Can't allocate enough MSI-X interrupts? Oh well.
  2916. * This just means we'll go with either a single MSI
  2917. * vector or fall back to legacy interrupts.
  2918. */
  2919. DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
  2920. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2921. kfree(adapter->msix_entries);
  2922. adapter->msix_entries = NULL;
  2923. } else {
  2924. adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
  2925. /*
  2926. * Adjust for only the vectors we'll use, which is minimum
  2927. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  2928. * vectors we were allocated.
  2929. */
  2930. adapter->num_msix_vectors = min(vectors,
  2931. adapter->max_msix_q_vectors + NON_Q_VECTORS);
  2932. }
  2933. }
  2934. /**
  2935. * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
  2936. * @adapter: board private structure to initialize
  2937. *
  2938. * Cache the descriptor ring offsets for RSS to the assigned rings.
  2939. *
  2940. **/
  2941. static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
  2942. {
  2943. int i;
  2944. bool ret = false;
  2945. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  2946. for (i = 0; i < adapter->num_rx_queues; i++)
  2947. adapter->rx_ring[i].reg_idx = i;
  2948. for (i = 0; i < adapter->num_tx_queues; i++)
  2949. adapter->tx_ring[i].reg_idx = i;
  2950. ret = true;
  2951. } else {
  2952. ret = false;
  2953. }
  2954. return ret;
  2955. }
  2956. #ifdef CONFIG_IXGBE_DCB
  2957. /**
  2958. * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
  2959. * @adapter: board private structure to initialize
  2960. *
  2961. * Cache the descriptor ring offsets for DCB to the assigned rings.
  2962. *
  2963. **/
  2964. static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
  2965. {
  2966. int i;
  2967. bool ret = false;
  2968. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  2969. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  2970. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2971. /* the number of queues is assumed to be symmetric */
  2972. for (i = 0; i < dcb_i; i++) {
  2973. adapter->rx_ring[i].reg_idx = i << 3;
  2974. adapter->tx_ring[i].reg_idx = i << 2;
  2975. }
  2976. ret = true;
  2977. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  2978. if (dcb_i == 8) {
  2979. /*
  2980. * Tx TC0 starts at: descriptor queue 0
  2981. * Tx TC1 starts at: descriptor queue 32
  2982. * Tx TC2 starts at: descriptor queue 64
  2983. * Tx TC3 starts at: descriptor queue 80
  2984. * Tx TC4 starts at: descriptor queue 96
  2985. * Tx TC5 starts at: descriptor queue 104
  2986. * Tx TC6 starts at: descriptor queue 112
  2987. * Tx TC7 starts at: descriptor queue 120
  2988. *
  2989. * Rx TC0-TC7 are offset by 16 queues each
  2990. */
  2991. for (i = 0; i < 3; i++) {
  2992. adapter->tx_ring[i].reg_idx = i << 5;
  2993. adapter->rx_ring[i].reg_idx = i << 4;
  2994. }
  2995. for ( ; i < 5; i++) {
  2996. adapter->tx_ring[i].reg_idx =
  2997. ((i + 2) << 4);
  2998. adapter->rx_ring[i].reg_idx = i << 4;
  2999. }
  3000. for ( ; i < dcb_i; i++) {
  3001. adapter->tx_ring[i].reg_idx =
  3002. ((i + 8) << 3);
  3003. adapter->rx_ring[i].reg_idx = i << 4;
  3004. }
  3005. ret = true;
  3006. } else if (dcb_i == 4) {
  3007. /*
  3008. * Tx TC0 starts at: descriptor queue 0
  3009. * Tx TC1 starts at: descriptor queue 64
  3010. * Tx TC2 starts at: descriptor queue 96
  3011. * Tx TC3 starts at: descriptor queue 112
  3012. *
  3013. * Rx TC0-TC3 are offset by 32 queues each
  3014. */
  3015. adapter->tx_ring[0].reg_idx = 0;
  3016. adapter->tx_ring[1].reg_idx = 64;
  3017. adapter->tx_ring[2].reg_idx = 96;
  3018. adapter->tx_ring[3].reg_idx = 112;
  3019. for (i = 0 ; i < dcb_i; i++)
  3020. adapter->rx_ring[i].reg_idx = i << 5;
  3021. ret = true;
  3022. } else {
  3023. ret = false;
  3024. }
  3025. } else {
  3026. ret = false;
  3027. }
  3028. } else {
  3029. ret = false;
  3030. }
  3031. return ret;
  3032. }
  3033. #endif
  3034. /**
  3035. * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
  3036. * @adapter: board private structure to initialize
  3037. *
  3038. * Cache the descriptor ring offsets for Flow Director to the assigned rings.
  3039. *
  3040. **/
  3041. static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
  3042. {
  3043. int i;
  3044. bool ret = false;
  3045. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  3046. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3047. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
  3048. for (i = 0; i < adapter->num_rx_queues; i++)
  3049. adapter->rx_ring[i].reg_idx = i;
  3050. for (i = 0; i < adapter->num_tx_queues; i++)
  3051. adapter->tx_ring[i].reg_idx = i;
  3052. ret = true;
  3053. }
  3054. return ret;
  3055. }
  3056. #ifdef IXGBE_FCOE
  3057. /**
  3058. * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
  3059. * @adapter: board private structure to initialize
  3060. *
  3061. * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
  3062. *
  3063. */
  3064. static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
  3065. {
  3066. int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
  3067. bool ret = false;
  3068. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3069. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3070. #ifdef CONFIG_IXGBE_DCB
  3071. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3072. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  3073. ixgbe_cache_ring_dcb(adapter);
  3074. /* find out queues in TC for FCoE */
  3075. fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1;
  3076. fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1;
  3077. /*
  3078. * In 82599, the number of Tx queues for each traffic
  3079. * class for both 8-TC and 4-TC modes are:
  3080. * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
  3081. * 8 TCs: 32 32 16 16 8 8 8 8
  3082. * 4 TCs: 64 64 32 32
  3083. * We have max 8 queues for FCoE, where 8 the is
  3084. * FCoE redirection table size. If TC for FCoE is
  3085. * less than or equal to TC3, we have enough queues
  3086. * to add max of 8 queues for FCoE, so we start FCoE
  3087. * tx descriptor from the next one, i.e., reg_idx + 1.
  3088. * If TC for FCoE is above TC3, implying 8 TC mode,
  3089. * and we need 8 for FCoE, we have to take all queues
  3090. * in that traffic class for FCoE.
  3091. */
  3092. if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
  3093. fcoe_tx_i--;
  3094. }
  3095. #endif /* CONFIG_IXGBE_DCB */
  3096. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3097. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3098. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3099. ixgbe_cache_ring_fdir(adapter);
  3100. else
  3101. ixgbe_cache_ring_rss(adapter);
  3102. fcoe_rx_i = f->mask;
  3103. fcoe_tx_i = f->mask;
  3104. }
  3105. for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
  3106. adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i;
  3107. adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i;
  3108. }
  3109. ret = true;
  3110. }
  3111. return ret;
  3112. }
  3113. #endif /* IXGBE_FCOE */
  3114. /**
  3115. * ixgbe_cache_ring_register - Descriptor ring to register mapping
  3116. * @adapter: board private structure to initialize
  3117. *
  3118. * Once we know the feature-set enabled for the device, we'll cache
  3119. * the register offset the descriptor ring is assigned to.
  3120. *
  3121. * Note, the order the various feature calls is important. It must start with
  3122. * the "most" features enabled at the same time, then trickle down to the
  3123. * least amount of features turned on at once.
  3124. **/
  3125. static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
  3126. {
  3127. /* start with default case */
  3128. adapter->rx_ring[0].reg_idx = 0;
  3129. adapter->tx_ring[0].reg_idx = 0;
  3130. #ifdef IXGBE_FCOE
  3131. if (ixgbe_cache_ring_fcoe(adapter))
  3132. return;
  3133. #endif /* IXGBE_FCOE */
  3134. #ifdef CONFIG_IXGBE_DCB
  3135. if (ixgbe_cache_ring_dcb(adapter))
  3136. return;
  3137. #endif
  3138. if (ixgbe_cache_ring_fdir(adapter))
  3139. return;
  3140. if (ixgbe_cache_ring_rss(adapter))
  3141. return;
  3142. }
  3143. /**
  3144. * ixgbe_alloc_queues - Allocate memory for all rings
  3145. * @adapter: board private structure to initialize
  3146. *
  3147. * We allocate one ring per queue at run-time since we don't know the
  3148. * number of queues at compile-time. The polling_netdev array is
  3149. * intended for Multiqueue, but should work fine with a single queue.
  3150. **/
  3151. static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
  3152. {
  3153. int i;
  3154. adapter->tx_ring = kcalloc(adapter->num_tx_queues,
  3155. sizeof(struct ixgbe_ring), GFP_KERNEL);
  3156. if (!adapter->tx_ring)
  3157. goto err_tx_ring_allocation;
  3158. adapter->rx_ring = kcalloc(adapter->num_rx_queues,
  3159. sizeof(struct ixgbe_ring), GFP_KERNEL);
  3160. if (!adapter->rx_ring)
  3161. goto err_rx_ring_allocation;
  3162. for (i = 0; i < adapter->num_tx_queues; i++) {
  3163. adapter->tx_ring[i].count = adapter->tx_ring_count;
  3164. adapter->tx_ring[i].queue_index = i;
  3165. }
  3166. for (i = 0; i < adapter->num_rx_queues; i++) {
  3167. adapter->rx_ring[i].count = adapter->rx_ring_count;
  3168. adapter->rx_ring[i].queue_index = i;
  3169. }
  3170. ixgbe_cache_ring_register(adapter);
  3171. return 0;
  3172. err_rx_ring_allocation:
  3173. kfree(adapter->tx_ring);
  3174. err_tx_ring_allocation:
  3175. return -ENOMEM;
  3176. }
  3177. /**
  3178. * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
  3179. * @adapter: board private structure to initialize
  3180. *
  3181. * Attempt to configure the interrupts using the best available
  3182. * capabilities of the hardware and the kernel.
  3183. **/
  3184. static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
  3185. {
  3186. struct ixgbe_hw *hw = &adapter->hw;
  3187. int err = 0;
  3188. int vector, v_budget;
  3189. /*
  3190. * It's easy to be greedy for MSI-X vectors, but it really
  3191. * doesn't do us much good if we have a lot more vectors
  3192. * than CPU's. So let's be conservative and only ask for
  3193. * (roughly) the same number of vectors as there are CPU's.
  3194. */
  3195. v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
  3196. (int)num_online_cpus()) + NON_Q_VECTORS;
  3197. /*
  3198. * At the same time, hardware can only support a maximum of
  3199. * hw.mac->max_msix_vectors vectors. With features
  3200. * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
  3201. * descriptor queues supported by our device. Thus, we cap it off in
  3202. * those rare cases where the cpu count also exceeds our vector limit.
  3203. */
  3204. v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
  3205. /* A failure in MSI-X entry allocation isn't fatal, but it does
  3206. * mean we disable MSI-X capabilities of the adapter. */
  3207. adapter->msix_entries = kcalloc(v_budget,
  3208. sizeof(struct msix_entry), GFP_KERNEL);
  3209. if (adapter->msix_entries) {
  3210. for (vector = 0; vector < v_budget; vector++)
  3211. adapter->msix_entries[vector].entry = vector;
  3212. ixgbe_acquire_msix_vectors(adapter, v_budget);
  3213. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3214. goto out;
  3215. }
  3216. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  3217. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  3218. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3219. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3220. adapter->atr_sample_rate = 0;
  3221. ixgbe_set_num_queues(adapter);
  3222. err = pci_enable_msi(adapter->pdev);
  3223. if (!err) {
  3224. adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
  3225. } else {
  3226. DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
  3227. "falling back to legacy. Error: %d\n", err);
  3228. /* reset err */
  3229. err = 0;
  3230. }
  3231. out:
  3232. return err;
  3233. }
  3234. /**
  3235. * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
  3236. * @adapter: board private structure to initialize
  3237. *
  3238. * We allocate one q_vector per queue interrupt. If allocation fails we
  3239. * return -ENOMEM.
  3240. **/
  3241. static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
  3242. {
  3243. int q_idx, num_q_vectors;
  3244. struct ixgbe_q_vector *q_vector;
  3245. int napi_vectors;
  3246. int (*poll)(struct napi_struct *, int);
  3247. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3248. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  3249. napi_vectors = adapter->num_rx_queues;
  3250. poll = &ixgbe_clean_rxtx_many;
  3251. } else {
  3252. num_q_vectors = 1;
  3253. napi_vectors = 1;
  3254. poll = &ixgbe_poll;
  3255. }
  3256. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  3257. q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
  3258. if (!q_vector)
  3259. goto err_out;
  3260. q_vector->adapter = adapter;
  3261. if (q_vector->txr_count && !q_vector->rxr_count)
  3262. q_vector->eitr = adapter->tx_eitr_param;
  3263. else
  3264. q_vector->eitr = adapter->rx_eitr_param;
  3265. q_vector->v_idx = q_idx;
  3266. netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
  3267. adapter->q_vector[q_idx] = q_vector;
  3268. }
  3269. return 0;
  3270. err_out:
  3271. while (q_idx) {
  3272. q_idx--;
  3273. q_vector = adapter->q_vector[q_idx];
  3274. netif_napi_del(&q_vector->napi);
  3275. kfree(q_vector);
  3276. adapter->q_vector[q_idx] = NULL;
  3277. }
  3278. return -ENOMEM;
  3279. }
  3280. /**
  3281. * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
  3282. * @adapter: board private structure to initialize
  3283. *
  3284. * This function frees the memory allocated to the q_vectors. In addition if
  3285. * NAPI is enabled it will delete any references to the NAPI struct prior
  3286. * to freeing the q_vector.
  3287. **/
  3288. static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
  3289. {
  3290. int q_idx, num_q_vectors;
  3291. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3292. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  3293. else
  3294. num_q_vectors = 1;
  3295. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  3296. struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
  3297. adapter->q_vector[q_idx] = NULL;
  3298. netif_napi_del(&q_vector->napi);
  3299. kfree(q_vector);
  3300. }
  3301. }
  3302. static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
  3303. {
  3304. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3305. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  3306. pci_disable_msix(adapter->pdev);
  3307. kfree(adapter->msix_entries);
  3308. adapter->msix_entries = NULL;
  3309. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  3310. adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
  3311. pci_disable_msi(adapter->pdev);
  3312. }
  3313. return;
  3314. }
  3315. /**
  3316. * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
  3317. * @adapter: board private structure to initialize
  3318. *
  3319. * We determine which interrupt scheme to use based on...
  3320. * - Kernel support (MSI, MSI-X)
  3321. * - which can be user-defined (via MODULE_PARAM)
  3322. * - Hardware queue count (num_*_queues)
  3323. * - defined by miscellaneous hardware support/features (RSS, etc.)
  3324. **/
  3325. int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
  3326. {
  3327. int err;
  3328. /* Number of supported queues */
  3329. ixgbe_set_num_queues(adapter);
  3330. err = ixgbe_set_interrupt_capability(adapter);
  3331. if (err) {
  3332. DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
  3333. goto err_set_interrupt;
  3334. }
  3335. err = ixgbe_alloc_q_vectors(adapter);
  3336. if (err) {
  3337. DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
  3338. "vectors\n");
  3339. goto err_alloc_q_vectors;
  3340. }
  3341. err = ixgbe_alloc_queues(adapter);
  3342. if (err) {
  3343. DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
  3344. goto err_alloc_queues;
  3345. }
  3346. DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
  3347. "Tx Queue count = %u\n",
  3348. (adapter->num_rx_queues > 1) ? "Enabled" :
  3349. "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
  3350. set_bit(__IXGBE_DOWN, &adapter->state);
  3351. return 0;
  3352. err_alloc_queues:
  3353. ixgbe_free_q_vectors(adapter);
  3354. err_alloc_q_vectors:
  3355. ixgbe_reset_interrupt_capability(adapter);
  3356. err_set_interrupt:
  3357. return err;
  3358. }
  3359. /**
  3360. * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3361. * @adapter: board private structure to clear interrupt scheme on
  3362. *
  3363. * We go through and clear interrupt specific resources and reset the structure
  3364. * to pre-load conditions
  3365. **/
  3366. void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
  3367. {
  3368. kfree(adapter->tx_ring);
  3369. kfree(adapter->rx_ring);
  3370. adapter->tx_ring = NULL;
  3371. adapter->rx_ring = NULL;
  3372. ixgbe_free_q_vectors(adapter);
  3373. ixgbe_reset_interrupt_capability(adapter);
  3374. }
  3375. /**
  3376. * ixgbe_sfp_timer - worker thread to find a missing module
  3377. * @data: pointer to our adapter struct
  3378. **/
  3379. static void ixgbe_sfp_timer(unsigned long data)
  3380. {
  3381. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  3382. /*
  3383. * Do the sfp_timer outside of interrupt context due to the
  3384. * delays that sfp+ detection requires
  3385. */
  3386. schedule_work(&adapter->sfp_task);
  3387. }
  3388. /**
  3389. * ixgbe_sfp_task - worker thread to find a missing module
  3390. * @work: pointer to work_struct containing our data
  3391. **/
  3392. static void ixgbe_sfp_task(struct work_struct *work)
  3393. {
  3394. struct ixgbe_adapter *adapter = container_of(work,
  3395. struct ixgbe_adapter,
  3396. sfp_task);
  3397. struct ixgbe_hw *hw = &adapter->hw;
  3398. if ((hw->phy.type == ixgbe_phy_nl) &&
  3399. (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
  3400. s32 ret = hw->phy.ops.identify_sfp(hw);
  3401. if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
  3402. goto reschedule;
  3403. ret = hw->phy.ops.reset(hw);
  3404. if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  3405. dev_err(&adapter->pdev->dev, "failed to initialize "
  3406. "because an unsupported SFP+ module type "
  3407. "was detected.\n"
  3408. "Reload the driver after installing a "
  3409. "supported module.\n");
  3410. unregister_netdev(adapter->netdev);
  3411. } else {
  3412. DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
  3413. hw->phy.sfp_type);
  3414. }
  3415. /* don't need this routine any more */
  3416. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  3417. }
  3418. return;
  3419. reschedule:
  3420. if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
  3421. mod_timer(&adapter->sfp_timer,
  3422. round_jiffies(jiffies + (2 * HZ)));
  3423. }
  3424. /**
  3425. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  3426. * @adapter: board private structure to initialize
  3427. *
  3428. * ixgbe_sw_init initializes the Adapter private data structure.
  3429. * Fields are initialized based on PCI device information and
  3430. * OS network device settings (MTU size).
  3431. **/
  3432. static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
  3433. {
  3434. struct ixgbe_hw *hw = &adapter->hw;
  3435. struct pci_dev *pdev = adapter->pdev;
  3436. unsigned int rss;
  3437. #ifdef CONFIG_IXGBE_DCB
  3438. int j;
  3439. struct tc_configuration *tc;
  3440. #endif
  3441. /* PCI config space info */
  3442. hw->vendor_id = pdev->vendor;
  3443. hw->device_id = pdev->device;
  3444. hw->revision_id = pdev->revision;
  3445. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  3446. hw->subsystem_device_id = pdev->subsystem_device;
  3447. /* Set capability flags */
  3448. rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
  3449. adapter->ring_feature[RING_F_RSS].indices = rss;
  3450. adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
  3451. adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
  3452. if (hw->mac.type == ixgbe_mac_82598EB) {
  3453. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  3454. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  3455. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
  3456. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  3457. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
  3458. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  3459. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  3460. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3461. adapter->ring_feature[RING_F_FDIR].indices =
  3462. IXGBE_MAX_FDIR_INDICES;
  3463. adapter->atr_sample_rate = 20;
  3464. adapter->fdir_pballoc = 0;
  3465. #ifdef IXGBE_FCOE
  3466. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  3467. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  3468. adapter->ring_feature[RING_F_FCOE].indices = 0;
  3469. #ifdef CONFIG_IXGBE_DCB
  3470. /* Default traffic class to use for FCoE */
  3471. adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
  3472. #endif
  3473. #endif /* IXGBE_FCOE */
  3474. }
  3475. #ifdef CONFIG_IXGBE_DCB
  3476. /* Configure DCB traffic classes */
  3477. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  3478. tc = &adapter->dcb_cfg.tc_config[j];
  3479. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  3480. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  3481. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  3482. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  3483. tc->dcb_pfc = pfc_disabled;
  3484. }
  3485. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  3486. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  3487. adapter->dcb_cfg.rx_pba_cfg = pba_equal;
  3488. adapter->dcb_cfg.pfc_mode_enable = false;
  3489. adapter->dcb_cfg.round_robin_enable = false;
  3490. adapter->dcb_set_bitmap = 0x00;
  3491. ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
  3492. adapter->ring_feature[RING_F_DCB].indices);
  3493. #endif
  3494. /* default flow control settings */
  3495. hw->fc.requested_mode = ixgbe_fc_full;
  3496. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  3497. #ifdef CONFIG_DCB
  3498. adapter->last_lfc_mode = hw->fc.current_mode;
  3499. #endif
  3500. hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
  3501. hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
  3502. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  3503. hw->fc.send_xon = true;
  3504. hw->fc.disable_fc_autoneg = false;
  3505. /* enable itr by default in dynamic mode */
  3506. adapter->rx_itr_setting = 1;
  3507. adapter->rx_eitr_param = 20000;
  3508. adapter->tx_itr_setting = 1;
  3509. adapter->tx_eitr_param = 10000;
  3510. /* set defaults for eitr in MegaBytes */
  3511. adapter->eitr_low = 10;
  3512. adapter->eitr_high = 20;
  3513. /* set default ring sizes */
  3514. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  3515. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  3516. /* initialize eeprom parameters */
  3517. if (ixgbe_init_eeprom_params_generic(hw)) {
  3518. dev_err(&pdev->dev, "EEPROM initialization failed\n");
  3519. return -EIO;
  3520. }
  3521. /* enable rx csum by default */
  3522. adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
  3523. set_bit(__IXGBE_DOWN, &adapter->state);
  3524. return 0;
  3525. }
  3526. /**
  3527. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  3528. * @adapter: board private structure
  3529. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  3530. *
  3531. * Return 0 on success, negative on failure
  3532. **/
  3533. int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
  3534. struct ixgbe_ring *tx_ring)
  3535. {
  3536. struct pci_dev *pdev = adapter->pdev;
  3537. int size;
  3538. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  3539. tx_ring->tx_buffer_info = vmalloc(size);
  3540. if (!tx_ring->tx_buffer_info)
  3541. goto err;
  3542. memset(tx_ring->tx_buffer_info, 0, size);
  3543. /* round up to nearest 4K */
  3544. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  3545. tx_ring->size = ALIGN(tx_ring->size, 4096);
  3546. tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
  3547. &tx_ring->dma);
  3548. if (!tx_ring->desc)
  3549. goto err;
  3550. tx_ring->next_to_use = 0;
  3551. tx_ring->next_to_clean = 0;
  3552. tx_ring->work_limit = tx_ring->count;
  3553. return 0;
  3554. err:
  3555. vfree(tx_ring->tx_buffer_info);
  3556. tx_ring->tx_buffer_info = NULL;
  3557. DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
  3558. "descriptor ring\n");
  3559. return -ENOMEM;
  3560. }
  3561. /**
  3562. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  3563. * @adapter: board private structure
  3564. *
  3565. * If this function returns with an error, then it's possible one or
  3566. * more of the rings is populated (while the rest are not). It is the
  3567. * callers duty to clean those orphaned rings.
  3568. *
  3569. * Return 0 on success, negative on failure
  3570. **/
  3571. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  3572. {
  3573. int i, err = 0;
  3574. for (i = 0; i < adapter->num_tx_queues; i++) {
  3575. err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  3576. if (!err)
  3577. continue;
  3578. DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
  3579. break;
  3580. }
  3581. return err;
  3582. }
  3583. /**
  3584. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  3585. * @adapter: board private structure
  3586. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  3587. *
  3588. * Returns 0 on success, negative on failure
  3589. **/
  3590. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  3591. struct ixgbe_ring *rx_ring)
  3592. {
  3593. struct pci_dev *pdev = adapter->pdev;
  3594. int size;
  3595. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  3596. rx_ring->rx_buffer_info = vmalloc(size);
  3597. if (!rx_ring->rx_buffer_info) {
  3598. DPRINTK(PROBE, ERR,
  3599. "vmalloc allocation failed for the rx desc ring\n");
  3600. goto alloc_failed;
  3601. }
  3602. memset(rx_ring->rx_buffer_info, 0, size);
  3603. /* Round up to nearest 4K */
  3604. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  3605. rx_ring->size = ALIGN(rx_ring->size, 4096);
  3606. rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
  3607. if (!rx_ring->desc) {
  3608. DPRINTK(PROBE, ERR,
  3609. "Memory allocation failed for the rx desc ring\n");
  3610. vfree(rx_ring->rx_buffer_info);
  3611. goto alloc_failed;
  3612. }
  3613. rx_ring->next_to_clean = 0;
  3614. rx_ring->next_to_use = 0;
  3615. return 0;
  3616. alloc_failed:
  3617. return -ENOMEM;
  3618. }
  3619. /**
  3620. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  3621. * @adapter: board private structure
  3622. *
  3623. * If this function returns with an error, then it's possible one or
  3624. * more of the rings is populated (while the rest are not). It is the
  3625. * callers duty to clean those orphaned rings.
  3626. *
  3627. * Return 0 on success, negative on failure
  3628. **/
  3629. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  3630. {
  3631. int i, err = 0;
  3632. for (i = 0; i < adapter->num_rx_queues; i++) {
  3633. err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  3634. if (!err)
  3635. continue;
  3636. DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
  3637. break;
  3638. }
  3639. return err;
  3640. }
  3641. /**
  3642. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  3643. * @adapter: board private structure
  3644. * @tx_ring: Tx descriptor ring for a specific queue
  3645. *
  3646. * Free all transmit software resources
  3647. **/
  3648. void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
  3649. struct ixgbe_ring *tx_ring)
  3650. {
  3651. struct pci_dev *pdev = adapter->pdev;
  3652. ixgbe_clean_tx_ring(adapter, tx_ring);
  3653. vfree(tx_ring->tx_buffer_info);
  3654. tx_ring->tx_buffer_info = NULL;
  3655. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  3656. tx_ring->desc = NULL;
  3657. }
  3658. /**
  3659. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  3660. * @adapter: board private structure
  3661. *
  3662. * Free all transmit software resources
  3663. **/
  3664. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  3665. {
  3666. int i;
  3667. for (i = 0; i < adapter->num_tx_queues; i++)
  3668. if (adapter->tx_ring[i].desc)
  3669. ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
  3670. }
  3671. /**
  3672. * ixgbe_free_rx_resources - Free Rx Resources
  3673. * @adapter: board private structure
  3674. * @rx_ring: ring to clean the resources from
  3675. *
  3676. * Free all receive software resources
  3677. **/
  3678. void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
  3679. struct ixgbe_ring *rx_ring)
  3680. {
  3681. struct pci_dev *pdev = adapter->pdev;
  3682. ixgbe_clean_rx_ring(adapter, rx_ring);
  3683. vfree(rx_ring->rx_buffer_info);
  3684. rx_ring->rx_buffer_info = NULL;
  3685. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  3686. rx_ring->desc = NULL;
  3687. }
  3688. /**
  3689. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  3690. * @adapter: board private structure
  3691. *
  3692. * Free all receive software resources
  3693. **/
  3694. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  3695. {
  3696. int i;
  3697. for (i = 0; i < adapter->num_rx_queues; i++)
  3698. if (adapter->rx_ring[i].desc)
  3699. ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
  3700. }
  3701. /**
  3702. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  3703. * @netdev: network interface device structure
  3704. * @new_mtu: new value for maximum frame size
  3705. *
  3706. * Returns 0 on success, negative on failure
  3707. **/
  3708. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  3709. {
  3710. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3711. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  3712. /* MTU < 68 is an error and causes problems on some kernels */
  3713. if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
  3714. return -EINVAL;
  3715. DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
  3716. netdev->mtu, new_mtu);
  3717. /* must set new MTU before calling down or up */
  3718. netdev->mtu = new_mtu;
  3719. if (netif_running(netdev))
  3720. ixgbe_reinit_locked(adapter);
  3721. return 0;
  3722. }
  3723. /**
  3724. * ixgbe_open - Called when a network interface is made active
  3725. * @netdev: network interface device structure
  3726. *
  3727. * Returns 0 on success, negative value on failure
  3728. *
  3729. * The open entry point is called when a network interface is made
  3730. * active by the system (IFF_UP). At this point all resources needed
  3731. * for transmit and receive operations are allocated, the interrupt
  3732. * handler is registered with the OS, the watchdog timer is started,
  3733. * and the stack is notified that the interface is ready.
  3734. **/
  3735. static int ixgbe_open(struct net_device *netdev)
  3736. {
  3737. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3738. int err;
  3739. /* disallow open during test */
  3740. if (test_bit(__IXGBE_TESTING, &adapter->state))
  3741. return -EBUSY;
  3742. netif_carrier_off(netdev);
  3743. /* allocate transmit descriptors */
  3744. err = ixgbe_setup_all_tx_resources(adapter);
  3745. if (err)
  3746. goto err_setup_tx;
  3747. /* allocate receive descriptors */
  3748. err = ixgbe_setup_all_rx_resources(adapter);
  3749. if (err)
  3750. goto err_setup_rx;
  3751. ixgbe_configure(adapter);
  3752. err = ixgbe_request_irq(adapter);
  3753. if (err)
  3754. goto err_req_irq;
  3755. err = ixgbe_up_complete(adapter);
  3756. if (err)
  3757. goto err_up;
  3758. netif_tx_start_all_queues(netdev);
  3759. return 0;
  3760. err_up:
  3761. ixgbe_release_hw_control(adapter);
  3762. ixgbe_free_irq(adapter);
  3763. err_req_irq:
  3764. err_setup_rx:
  3765. ixgbe_free_all_rx_resources(adapter);
  3766. err_setup_tx:
  3767. ixgbe_free_all_tx_resources(adapter);
  3768. ixgbe_reset(adapter);
  3769. return err;
  3770. }
  3771. /**
  3772. * ixgbe_close - Disables a network interface
  3773. * @netdev: network interface device structure
  3774. *
  3775. * Returns 0, this is not allowed to fail
  3776. *
  3777. * The close entry point is called when an interface is de-activated
  3778. * by the OS. The hardware is still under the drivers control, but
  3779. * needs to be disabled. A global MAC reset is issued to stop the
  3780. * hardware, and all transmit and receive resources are freed.
  3781. **/
  3782. static int ixgbe_close(struct net_device *netdev)
  3783. {
  3784. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3785. ixgbe_down(adapter);
  3786. ixgbe_free_irq(adapter);
  3787. ixgbe_free_all_tx_resources(adapter);
  3788. ixgbe_free_all_rx_resources(adapter);
  3789. ixgbe_release_hw_control(adapter);
  3790. return 0;
  3791. }
  3792. #ifdef CONFIG_PM
  3793. static int ixgbe_resume(struct pci_dev *pdev)
  3794. {
  3795. struct net_device *netdev = pci_get_drvdata(pdev);
  3796. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3797. u32 err;
  3798. pci_set_power_state(pdev, PCI_D0);
  3799. pci_restore_state(pdev);
  3800. err = pci_enable_device_mem(pdev);
  3801. if (err) {
  3802. printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
  3803. "suspend\n");
  3804. return err;
  3805. }
  3806. pci_set_master(pdev);
  3807. pci_wake_from_d3(pdev, false);
  3808. err = ixgbe_init_interrupt_scheme(adapter);
  3809. if (err) {
  3810. printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
  3811. "device\n");
  3812. return err;
  3813. }
  3814. ixgbe_reset(adapter);
  3815. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  3816. if (netif_running(netdev)) {
  3817. err = ixgbe_open(adapter->netdev);
  3818. if (err)
  3819. return err;
  3820. }
  3821. netif_device_attach(netdev);
  3822. return 0;
  3823. }
  3824. #endif /* CONFIG_PM */
  3825. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  3826. {
  3827. struct net_device *netdev = pci_get_drvdata(pdev);
  3828. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3829. struct ixgbe_hw *hw = &adapter->hw;
  3830. u32 ctrl, fctrl;
  3831. u32 wufc = adapter->wol;
  3832. #ifdef CONFIG_PM
  3833. int retval = 0;
  3834. #endif
  3835. netif_device_detach(netdev);
  3836. if (netif_running(netdev)) {
  3837. ixgbe_down(adapter);
  3838. ixgbe_free_irq(adapter);
  3839. ixgbe_free_all_tx_resources(adapter);
  3840. ixgbe_free_all_rx_resources(adapter);
  3841. }
  3842. ixgbe_clear_interrupt_scheme(adapter);
  3843. #ifdef CONFIG_PM
  3844. retval = pci_save_state(pdev);
  3845. if (retval)
  3846. return retval;
  3847. #endif
  3848. if (wufc) {
  3849. ixgbe_set_rx_mode(netdev);
  3850. /* turn on all-multi mode if wake on multicast is enabled */
  3851. if (wufc & IXGBE_WUFC_MC) {
  3852. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  3853. fctrl |= IXGBE_FCTRL_MPE;
  3854. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  3855. }
  3856. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  3857. ctrl |= IXGBE_CTRL_GIO_DIS;
  3858. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  3859. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  3860. } else {
  3861. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  3862. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  3863. }
  3864. if (wufc && hw->mac.type == ixgbe_mac_82599EB)
  3865. pci_wake_from_d3(pdev, true);
  3866. else
  3867. pci_wake_from_d3(pdev, false);
  3868. *enable_wake = !!wufc;
  3869. ixgbe_release_hw_control(adapter);
  3870. pci_disable_device(pdev);
  3871. return 0;
  3872. }
  3873. #ifdef CONFIG_PM
  3874. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  3875. {
  3876. int retval;
  3877. bool wake;
  3878. retval = __ixgbe_shutdown(pdev, &wake);
  3879. if (retval)
  3880. return retval;
  3881. if (wake) {
  3882. pci_prepare_to_sleep(pdev);
  3883. } else {
  3884. pci_wake_from_d3(pdev, false);
  3885. pci_set_power_state(pdev, PCI_D3hot);
  3886. }
  3887. return 0;
  3888. }
  3889. #endif /* CONFIG_PM */
  3890. static void ixgbe_shutdown(struct pci_dev *pdev)
  3891. {
  3892. bool wake;
  3893. __ixgbe_shutdown(pdev, &wake);
  3894. if (system_state == SYSTEM_POWER_OFF) {
  3895. pci_wake_from_d3(pdev, wake);
  3896. pci_set_power_state(pdev, PCI_D3hot);
  3897. }
  3898. }
  3899. /**
  3900. * ixgbe_update_stats - Update the board statistics counters.
  3901. * @adapter: board private structure
  3902. **/
  3903. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  3904. {
  3905. struct net_device *netdev = adapter->netdev;
  3906. struct ixgbe_hw *hw = &adapter->hw;
  3907. u64 total_mpc = 0;
  3908. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  3909. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  3910. u64 rsc_count = 0;
  3911. u64 rsc_flush = 0;
  3912. for (i = 0; i < 16; i++)
  3913. adapter->hw_rx_no_dma_resources +=
  3914. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  3915. for (i = 0; i < adapter->num_rx_queues; i++) {
  3916. rsc_count += adapter->rx_ring[i].rsc_count;
  3917. rsc_flush += adapter->rx_ring[i].rsc_flush;
  3918. }
  3919. adapter->rsc_total_count = rsc_count;
  3920. adapter->rsc_total_flush = rsc_flush;
  3921. }
  3922. /* gather some stats to the adapter struct that are per queue */
  3923. for (i = 0; i < adapter->num_tx_queues; i++)
  3924. adapter->restart_queue += adapter->tx_ring[i].restart_queue;
  3925. for (i = 0; i < adapter->num_rx_queues; i++)
  3926. adapter->non_eop_descs += adapter->tx_ring[i].non_eop_descs;
  3927. adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  3928. for (i = 0; i < 8; i++) {
  3929. /* for packet buffers not used, the register should read 0 */
  3930. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  3931. missed_rx += mpc;
  3932. adapter->stats.mpc[i] += mpc;
  3933. total_mpc += adapter->stats.mpc[i];
  3934. if (hw->mac.type == ixgbe_mac_82598EB)
  3935. adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  3936. adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  3937. adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  3938. adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  3939. adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  3940. if (hw->mac.type == ixgbe_mac_82599EB) {
  3941. adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
  3942. IXGBE_PXONRXCNT(i));
  3943. adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
  3944. IXGBE_PXOFFRXCNT(i));
  3945. adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  3946. } else {
  3947. adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
  3948. IXGBE_PXONRXC(i));
  3949. adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
  3950. IXGBE_PXOFFRXC(i));
  3951. }
  3952. adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
  3953. IXGBE_PXONTXC(i));
  3954. adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
  3955. IXGBE_PXOFFTXC(i));
  3956. }
  3957. adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  3958. /* work around hardware counting issue */
  3959. adapter->stats.gprc -= missed_rx;
  3960. /* 82598 hardware only has a 32 bit counter in the high register */
  3961. if (hw->mac.type == ixgbe_mac_82599EB) {
  3962. u64 tmp;
  3963. adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  3964. tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
  3965. adapter->stats.gorc += (tmp << 32);
  3966. adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  3967. tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
  3968. adapter->stats.gotc += (tmp << 32);
  3969. adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  3970. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  3971. adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  3972. adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  3973. adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  3974. adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  3975. #ifdef IXGBE_FCOE
  3976. adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  3977. adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  3978. adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  3979. adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  3980. adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  3981. adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  3982. #endif /* IXGBE_FCOE */
  3983. } else {
  3984. adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  3985. adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  3986. adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  3987. adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  3988. adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  3989. }
  3990. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  3991. adapter->stats.bprc += bprc;
  3992. adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  3993. if (hw->mac.type == ixgbe_mac_82598EB)
  3994. adapter->stats.mprc -= bprc;
  3995. adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  3996. adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  3997. adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  3998. adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  3999. adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  4000. adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  4001. adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  4002. adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  4003. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  4004. adapter->stats.lxontxc += lxon;
  4005. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  4006. adapter->stats.lxofftxc += lxoff;
  4007. adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4008. adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  4009. adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  4010. /*
  4011. * 82598 errata - tx of flow control packets is included in tx counters
  4012. */
  4013. xon_off_tot = lxon + lxoff;
  4014. adapter->stats.gptc -= xon_off_tot;
  4015. adapter->stats.mptc -= xon_off_tot;
  4016. adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  4017. adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4018. adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  4019. adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  4020. adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  4021. adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  4022. adapter->stats.ptc64 -= xon_off_tot;
  4023. adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  4024. adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  4025. adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  4026. adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  4027. adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  4028. adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  4029. /* Fill out the OS statistics structure */
  4030. netdev->stats.multicast = adapter->stats.mprc;
  4031. /* Rx Errors */
  4032. netdev->stats.rx_errors = adapter->stats.crcerrs +
  4033. adapter->stats.rlec;
  4034. netdev->stats.rx_dropped = 0;
  4035. netdev->stats.rx_length_errors = adapter->stats.rlec;
  4036. netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
  4037. netdev->stats.rx_missed_errors = total_mpc;
  4038. }
  4039. /**
  4040. * ixgbe_watchdog - Timer Call-back
  4041. * @data: pointer to adapter cast into an unsigned long
  4042. **/
  4043. static void ixgbe_watchdog(unsigned long data)
  4044. {
  4045. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  4046. struct ixgbe_hw *hw = &adapter->hw;
  4047. u64 eics = 0;
  4048. int i;
  4049. /*
  4050. * Do the watchdog outside of interrupt context due to the lovely
  4051. * delays that some of the newer hardware requires
  4052. */
  4053. if (test_bit(__IXGBE_DOWN, &adapter->state))
  4054. goto watchdog_short_circuit;
  4055. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  4056. /*
  4057. * for legacy and MSI interrupts don't set any bits
  4058. * that are enabled for EIAM, because this operation
  4059. * would set *both* EIMS and EICS for any bit in EIAM
  4060. */
  4061. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  4062. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  4063. goto watchdog_reschedule;
  4064. }
  4065. /* get one bit for every active tx/rx interrupt vector */
  4066. for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
  4067. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  4068. if (qv->rxr_count || qv->txr_count)
  4069. eics |= ((u64)1 << i);
  4070. }
  4071. /* Cause software interrupt to ensure rx rings are cleaned */
  4072. ixgbe_irq_rearm_queues(adapter, eics);
  4073. watchdog_reschedule:
  4074. /* Reset the timer */
  4075. mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
  4076. watchdog_short_circuit:
  4077. schedule_work(&adapter->watchdog_task);
  4078. }
  4079. /**
  4080. * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
  4081. * @work: pointer to work_struct containing our data
  4082. **/
  4083. static void ixgbe_multispeed_fiber_task(struct work_struct *work)
  4084. {
  4085. struct ixgbe_adapter *adapter = container_of(work,
  4086. struct ixgbe_adapter,
  4087. multispeed_fiber_task);
  4088. struct ixgbe_hw *hw = &adapter->hw;
  4089. u32 autoneg;
  4090. bool negotiation;
  4091. adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
  4092. autoneg = hw->phy.autoneg_advertised;
  4093. if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
  4094. hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  4095. if (hw->mac.ops.setup_link)
  4096. hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
  4097. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4098. adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
  4099. }
  4100. /**
  4101. * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
  4102. * @work: pointer to work_struct containing our data
  4103. **/
  4104. static void ixgbe_sfp_config_module_task(struct work_struct *work)
  4105. {
  4106. struct ixgbe_adapter *adapter = container_of(work,
  4107. struct ixgbe_adapter,
  4108. sfp_config_module_task);
  4109. struct ixgbe_hw *hw = &adapter->hw;
  4110. u32 err;
  4111. adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
  4112. /* Time for electrical oscillations to settle down */
  4113. msleep(100);
  4114. err = hw->phy.ops.identify_sfp(hw);
  4115. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4116. dev_err(&adapter->pdev->dev, "failed to initialize because "
  4117. "an unsupported SFP+ module type was detected.\n"
  4118. "Reload the driver after installing a supported "
  4119. "module.\n");
  4120. unregister_netdev(adapter->netdev);
  4121. return;
  4122. }
  4123. hw->mac.ops.setup_sfp(hw);
  4124. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  4125. /* This will also work for DA Twinax connections */
  4126. schedule_work(&adapter->multispeed_fiber_task);
  4127. adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
  4128. }
  4129. /**
  4130. * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
  4131. * @work: pointer to work_struct containing our data
  4132. **/
  4133. static void ixgbe_fdir_reinit_task(struct work_struct *work)
  4134. {
  4135. struct ixgbe_adapter *adapter = container_of(work,
  4136. struct ixgbe_adapter,
  4137. fdir_reinit_task);
  4138. struct ixgbe_hw *hw = &adapter->hw;
  4139. int i;
  4140. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  4141. for (i = 0; i < adapter->num_tx_queues; i++)
  4142. set_bit(__IXGBE_FDIR_INIT_DONE,
  4143. &(adapter->tx_ring[i].reinit_state));
  4144. } else {
  4145. DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
  4146. "ignored adding FDIR ATR filters \n");
  4147. }
  4148. /* Done FDIR Re-initialization, enable transmits */
  4149. netif_tx_start_all_queues(adapter->netdev);
  4150. }
  4151. /**
  4152. * ixgbe_watchdog_task - worker thread to bring link up
  4153. * @work: pointer to work_struct containing our data
  4154. **/
  4155. static void ixgbe_watchdog_task(struct work_struct *work)
  4156. {
  4157. struct ixgbe_adapter *adapter = container_of(work,
  4158. struct ixgbe_adapter,
  4159. watchdog_task);
  4160. struct net_device *netdev = adapter->netdev;
  4161. struct ixgbe_hw *hw = &adapter->hw;
  4162. u32 link_speed = adapter->link_speed;
  4163. bool link_up = adapter->link_up;
  4164. int i;
  4165. struct ixgbe_ring *tx_ring;
  4166. int some_tx_pending = 0;
  4167. adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
  4168. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
  4169. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  4170. if (link_up) {
  4171. #ifdef CONFIG_DCB
  4172. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4173. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  4174. hw->mac.ops.fc_enable(hw, i);
  4175. } else {
  4176. hw->mac.ops.fc_enable(hw, 0);
  4177. }
  4178. #else
  4179. hw->mac.ops.fc_enable(hw, 0);
  4180. #endif
  4181. }
  4182. if (link_up ||
  4183. time_after(jiffies, (adapter->link_check_timeout +
  4184. IXGBE_TRY_LINK_TIMEOUT))) {
  4185. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4186. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  4187. }
  4188. adapter->link_up = link_up;
  4189. adapter->link_speed = link_speed;
  4190. }
  4191. if (link_up) {
  4192. if (!netif_carrier_ok(netdev)) {
  4193. bool flow_rx, flow_tx;
  4194. if (hw->mac.type == ixgbe_mac_82599EB) {
  4195. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  4196. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  4197. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  4198. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  4199. } else {
  4200. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4201. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  4202. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  4203. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  4204. }
  4205. printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
  4206. "Flow Control: %s\n",
  4207. netdev->name,
  4208. (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
  4209. "10 Gbps" :
  4210. (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
  4211. "1 Gbps" : "unknown speed")),
  4212. ((flow_rx && flow_tx) ? "RX/TX" :
  4213. (flow_rx ? "RX" :
  4214. (flow_tx ? "TX" : "None"))));
  4215. netif_carrier_on(netdev);
  4216. } else {
  4217. /* Force detection of hung controller */
  4218. adapter->detect_tx_hung = true;
  4219. }
  4220. } else {
  4221. adapter->link_up = false;
  4222. adapter->link_speed = 0;
  4223. if (netif_carrier_ok(netdev)) {
  4224. printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
  4225. netdev->name);
  4226. netif_carrier_off(netdev);
  4227. }
  4228. }
  4229. if (!netif_carrier_ok(netdev)) {
  4230. for (i = 0; i < adapter->num_tx_queues; i++) {
  4231. tx_ring = &adapter->tx_ring[i];
  4232. if (tx_ring->next_to_use != tx_ring->next_to_clean) {
  4233. some_tx_pending = 1;
  4234. break;
  4235. }
  4236. }
  4237. if (some_tx_pending) {
  4238. /* We've lost link, so the controller stops DMA,
  4239. * but we've got queued Tx work that's never going
  4240. * to get done, so reset controller to flush Tx.
  4241. * (Do the reset outside of interrupt context).
  4242. */
  4243. schedule_work(&adapter->reset_task);
  4244. }
  4245. }
  4246. ixgbe_update_stats(adapter);
  4247. adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
  4248. }
  4249. static int ixgbe_tso(struct ixgbe_adapter *adapter,
  4250. struct ixgbe_ring *tx_ring, struct sk_buff *skb,
  4251. u32 tx_flags, u8 *hdr_len)
  4252. {
  4253. struct ixgbe_adv_tx_context_desc *context_desc;
  4254. unsigned int i;
  4255. int err;
  4256. struct ixgbe_tx_buffer *tx_buffer_info;
  4257. u32 vlan_macip_lens = 0, type_tucmd_mlhl;
  4258. u32 mss_l4len_idx, l4len;
  4259. if (skb_is_gso(skb)) {
  4260. if (skb_header_cloned(skb)) {
  4261. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  4262. if (err)
  4263. return err;
  4264. }
  4265. l4len = tcp_hdrlen(skb);
  4266. *hdr_len += l4len;
  4267. if (skb->protocol == htons(ETH_P_IP)) {
  4268. struct iphdr *iph = ip_hdr(skb);
  4269. iph->tot_len = 0;
  4270. iph->check = 0;
  4271. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  4272. iph->daddr, 0,
  4273. IPPROTO_TCP,
  4274. 0);
  4275. } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
  4276. ipv6_hdr(skb)->payload_len = 0;
  4277. tcp_hdr(skb)->check =
  4278. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  4279. &ipv6_hdr(skb)->daddr,
  4280. 0, IPPROTO_TCP, 0);
  4281. }
  4282. i = tx_ring->next_to_use;
  4283. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4284. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  4285. /* VLAN MACLEN IPLEN */
  4286. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  4287. vlan_macip_lens |=
  4288. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  4289. vlan_macip_lens |= ((skb_network_offset(skb)) <<
  4290. IXGBE_ADVTXD_MACLEN_SHIFT);
  4291. *hdr_len += skb_network_offset(skb);
  4292. vlan_macip_lens |=
  4293. (skb_transport_header(skb) - skb_network_header(skb));
  4294. *hdr_len +=
  4295. (skb_transport_header(skb) - skb_network_header(skb));
  4296. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  4297. context_desc->seqnum_seed = 0;
  4298. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  4299. type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
  4300. IXGBE_ADVTXD_DTYP_CTXT);
  4301. if (skb->protocol == htons(ETH_P_IP))
  4302. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  4303. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  4304. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  4305. /* MSS L4LEN IDX */
  4306. mss_l4len_idx =
  4307. (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
  4308. mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
  4309. /* use index 1 for TSO */
  4310. mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  4311. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  4312. tx_buffer_info->time_stamp = jiffies;
  4313. tx_buffer_info->next_to_watch = i;
  4314. i++;
  4315. if (i == tx_ring->count)
  4316. i = 0;
  4317. tx_ring->next_to_use = i;
  4318. return true;
  4319. }
  4320. return false;
  4321. }
  4322. static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
  4323. struct ixgbe_ring *tx_ring,
  4324. struct sk_buff *skb, u32 tx_flags)
  4325. {
  4326. struct ixgbe_adv_tx_context_desc *context_desc;
  4327. unsigned int i;
  4328. struct ixgbe_tx_buffer *tx_buffer_info;
  4329. u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
  4330. if (skb->ip_summed == CHECKSUM_PARTIAL ||
  4331. (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
  4332. i = tx_ring->next_to_use;
  4333. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4334. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  4335. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  4336. vlan_macip_lens |=
  4337. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  4338. vlan_macip_lens |= (skb_network_offset(skb) <<
  4339. IXGBE_ADVTXD_MACLEN_SHIFT);
  4340. if (skb->ip_summed == CHECKSUM_PARTIAL)
  4341. vlan_macip_lens |= (skb_transport_header(skb) -
  4342. skb_network_header(skb));
  4343. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  4344. context_desc->seqnum_seed = 0;
  4345. type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
  4346. IXGBE_ADVTXD_DTYP_CTXT);
  4347. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  4348. switch (skb->protocol) {
  4349. case cpu_to_be16(ETH_P_IP):
  4350. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  4351. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  4352. type_tucmd_mlhl |=
  4353. IXGBE_ADVTXD_TUCMD_L4T_TCP;
  4354. else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
  4355. type_tucmd_mlhl |=
  4356. IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  4357. break;
  4358. case cpu_to_be16(ETH_P_IPV6):
  4359. /* XXX what about other V6 headers?? */
  4360. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  4361. type_tucmd_mlhl |=
  4362. IXGBE_ADVTXD_TUCMD_L4T_TCP;
  4363. else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
  4364. type_tucmd_mlhl |=
  4365. IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  4366. break;
  4367. default:
  4368. if (unlikely(net_ratelimit())) {
  4369. DPRINTK(PROBE, WARNING,
  4370. "partial checksum but proto=%x!\n",
  4371. skb->protocol);
  4372. }
  4373. break;
  4374. }
  4375. }
  4376. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  4377. /* use index zero for tx checksum offload */
  4378. context_desc->mss_l4len_idx = 0;
  4379. tx_buffer_info->time_stamp = jiffies;
  4380. tx_buffer_info->next_to_watch = i;
  4381. i++;
  4382. if (i == tx_ring->count)
  4383. i = 0;
  4384. tx_ring->next_to_use = i;
  4385. return true;
  4386. }
  4387. return false;
  4388. }
  4389. static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
  4390. struct ixgbe_ring *tx_ring,
  4391. struct sk_buff *skb, u32 tx_flags,
  4392. unsigned int first)
  4393. {
  4394. struct pci_dev *pdev = adapter->pdev;
  4395. struct ixgbe_tx_buffer *tx_buffer_info;
  4396. unsigned int len;
  4397. unsigned int total = skb->len;
  4398. unsigned int offset = 0, size, count = 0, i;
  4399. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  4400. unsigned int f;
  4401. i = tx_ring->next_to_use;
  4402. if (tx_flags & IXGBE_TX_FLAGS_FCOE)
  4403. /* excluding fcoe_crc_eof for FCoE */
  4404. total -= sizeof(struct fcoe_crc_eof);
  4405. len = min(skb_headlen(skb), total);
  4406. while (len) {
  4407. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4408. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  4409. tx_buffer_info->length = size;
  4410. tx_buffer_info->mapped_as_page = false;
  4411. tx_buffer_info->dma = pci_map_single(pdev,
  4412. skb->data + offset,
  4413. size, PCI_DMA_TODEVICE);
  4414. if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
  4415. goto dma_error;
  4416. tx_buffer_info->time_stamp = jiffies;
  4417. tx_buffer_info->next_to_watch = i;
  4418. len -= size;
  4419. total -= size;
  4420. offset += size;
  4421. count++;
  4422. if (len) {
  4423. i++;
  4424. if (i == tx_ring->count)
  4425. i = 0;
  4426. }
  4427. }
  4428. for (f = 0; f < nr_frags; f++) {
  4429. struct skb_frag_struct *frag;
  4430. frag = &skb_shinfo(skb)->frags[f];
  4431. len = min((unsigned int)frag->size, total);
  4432. offset = frag->page_offset;
  4433. while (len) {
  4434. i++;
  4435. if (i == tx_ring->count)
  4436. i = 0;
  4437. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4438. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  4439. tx_buffer_info->length = size;
  4440. tx_buffer_info->dma = pci_map_page(adapter->pdev,
  4441. frag->page,
  4442. offset, size,
  4443. PCI_DMA_TODEVICE);
  4444. tx_buffer_info->mapped_as_page = true;
  4445. if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
  4446. goto dma_error;
  4447. tx_buffer_info->time_stamp = jiffies;
  4448. tx_buffer_info->next_to_watch = i;
  4449. len -= size;
  4450. total -= size;
  4451. offset += size;
  4452. count++;
  4453. }
  4454. if (total == 0)
  4455. break;
  4456. }
  4457. tx_ring->tx_buffer_info[i].skb = skb;
  4458. tx_ring->tx_buffer_info[first].next_to_watch = i;
  4459. return count;
  4460. dma_error:
  4461. dev_err(&pdev->dev, "TX DMA map failed\n");
  4462. /* clear timestamp and dma mappings for failed tx_buffer_info map */
  4463. tx_buffer_info->dma = 0;
  4464. tx_buffer_info->time_stamp = 0;
  4465. tx_buffer_info->next_to_watch = 0;
  4466. count--;
  4467. /* clear timestamp and dma mappings for remaining portion of packet */
  4468. while (count >= 0) {
  4469. count--;
  4470. i--;
  4471. if (i < 0)
  4472. i += tx_ring->count;
  4473. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4474. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  4475. }
  4476. return count;
  4477. }
  4478. static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
  4479. struct ixgbe_ring *tx_ring,
  4480. int tx_flags, int count, u32 paylen, u8 hdr_len)
  4481. {
  4482. union ixgbe_adv_tx_desc *tx_desc = NULL;
  4483. struct ixgbe_tx_buffer *tx_buffer_info;
  4484. u32 olinfo_status = 0, cmd_type_len = 0;
  4485. unsigned int i;
  4486. u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
  4487. cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
  4488. cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
  4489. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  4490. cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
  4491. if (tx_flags & IXGBE_TX_FLAGS_TSO) {
  4492. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  4493. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  4494. IXGBE_ADVTXD_POPTS_SHIFT;
  4495. /* use index 1 context for tso */
  4496. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  4497. if (tx_flags & IXGBE_TX_FLAGS_IPV4)
  4498. olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
  4499. IXGBE_ADVTXD_POPTS_SHIFT;
  4500. } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
  4501. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  4502. IXGBE_ADVTXD_POPTS_SHIFT;
  4503. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  4504. olinfo_status |= IXGBE_ADVTXD_CC;
  4505. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  4506. if (tx_flags & IXGBE_TX_FLAGS_FSO)
  4507. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  4508. }
  4509. olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
  4510. i = tx_ring->next_to_use;
  4511. while (count--) {
  4512. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  4513. tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
  4514. tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
  4515. tx_desc->read.cmd_type_len =
  4516. cpu_to_le32(cmd_type_len | tx_buffer_info->length);
  4517. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  4518. i++;
  4519. if (i == tx_ring->count)
  4520. i = 0;
  4521. }
  4522. tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
  4523. /*
  4524. * Force memory writes to complete before letting h/w
  4525. * know there are new descriptors to fetch. (Only
  4526. * applicable for weak-ordered memory model archs,
  4527. * such as IA-64).
  4528. */
  4529. wmb();
  4530. tx_ring->next_to_use = i;
  4531. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  4532. }
  4533. static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
  4534. int queue, u32 tx_flags)
  4535. {
  4536. /* Right now, we support IPv4 only */
  4537. struct ixgbe_atr_input atr_input;
  4538. struct tcphdr *th;
  4539. struct iphdr *iph = ip_hdr(skb);
  4540. struct ethhdr *eth = (struct ethhdr *)skb->data;
  4541. u16 vlan_id, src_port, dst_port, flex_bytes;
  4542. u32 src_ipv4_addr, dst_ipv4_addr;
  4543. u8 l4type = 0;
  4544. /* check if we're UDP or TCP */
  4545. if (iph->protocol == IPPROTO_TCP) {
  4546. th = tcp_hdr(skb);
  4547. src_port = th->source;
  4548. dst_port = th->dest;
  4549. l4type |= IXGBE_ATR_L4TYPE_TCP;
  4550. /* l4type IPv4 type is 0, no need to assign */
  4551. } else {
  4552. /* Unsupported L4 header, just bail here */
  4553. return;
  4554. }
  4555. memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
  4556. vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
  4557. IXGBE_TX_FLAGS_VLAN_SHIFT;
  4558. src_ipv4_addr = iph->saddr;
  4559. dst_ipv4_addr = iph->daddr;
  4560. flex_bytes = eth->h_proto;
  4561. ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
  4562. ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
  4563. ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
  4564. ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
  4565. ixgbe_atr_set_l4type_82599(&atr_input, l4type);
  4566. /* src and dst are inverted, think how the receiver sees them */
  4567. ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
  4568. ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
  4569. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  4570. ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
  4571. }
  4572. static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
  4573. struct ixgbe_ring *tx_ring, int size)
  4574. {
  4575. netif_stop_subqueue(netdev, tx_ring->queue_index);
  4576. /* Herbert's original patch had:
  4577. * smp_mb__after_netif_stop_queue();
  4578. * but since that doesn't exist yet, just open code it. */
  4579. smp_mb();
  4580. /* We need to check again in a case another CPU has just
  4581. * made room available. */
  4582. if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
  4583. return -EBUSY;
  4584. /* A reprieve! - use start_queue because it doesn't call schedule */
  4585. netif_start_subqueue(netdev, tx_ring->queue_index);
  4586. ++tx_ring->restart_queue;
  4587. return 0;
  4588. }
  4589. static int ixgbe_maybe_stop_tx(struct net_device *netdev,
  4590. struct ixgbe_ring *tx_ring, int size)
  4591. {
  4592. if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
  4593. return 0;
  4594. return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
  4595. }
  4596. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
  4597. {
  4598. struct ixgbe_adapter *adapter = netdev_priv(dev);
  4599. int txq = smp_processor_id();
  4600. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
  4601. return txq;
  4602. #ifdef IXGBE_FCOE
  4603. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  4604. (skb->protocol == htons(ETH_P_FCOE))) {
  4605. txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
  4606. txq += adapter->ring_feature[RING_F_FCOE].mask;
  4607. return txq;
  4608. }
  4609. #endif
  4610. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  4611. return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13;
  4612. return skb_tx_hash(dev, skb);
  4613. }
  4614. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  4615. struct net_device *netdev)
  4616. {
  4617. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4618. struct ixgbe_ring *tx_ring;
  4619. struct netdev_queue *txq;
  4620. unsigned int first;
  4621. unsigned int tx_flags = 0;
  4622. u8 hdr_len = 0;
  4623. int tso;
  4624. int count = 0;
  4625. unsigned int f;
  4626. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  4627. tx_flags |= vlan_tx_tag_get(skb);
  4628. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4629. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  4630. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  4631. }
  4632. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  4633. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  4634. } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  4635. if (skb->priority != TC_PRIO_CONTROL) {
  4636. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  4637. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  4638. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  4639. } else {
  4640. skb->queue_mapping =
  4641. adapter->ring_feature[RING_F_DCB].indices-1;
  4642. }
  4643. }
  4644. tx_ring = &adapter->tx_ring[skb->queue_mapping];
  4645. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  4646. (skb->protocol == htons(ETH_P_FCOE))) {
  4647. tx_flags |= IXGBE_TX_FLAGS_FCOE;
  4648. #ifdef IXGBE_FCOE
  4649. #ifdef CONFIG_IXGBE_DCB
  4650. tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
  4651. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  4652. tx_flags |= ((adapter->fcoe.up << 13)
  4653. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  4654. #endif
  4655. #endif
  4656. }
  4657. /* four things can cause us to need a context descriptor */
  4658. if (skb_is_gso(skb) ||
  4659. (skb->ip_summed == CHECKSUM_PARTIAL) ||
  4660. (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
  4661. (tx_flags & IXGBE_TX_FLAGS_FCOE))
  4662. count++;
  4663. count += TXD_USE_COUNT(skb_headlen(skb));
  4664. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  4665. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  4666. if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
  4667. adapter->tx_busy++;
  4668. return NETDEV_TX_BUSY;
  4669. }
  4670. first = tx_ring->next_to_use;
  4671. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  4672. #ifdef IXGBE_FCOE
  4673. /* setup tx offload for FCoE */
  4674. tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  4675. if (tso < 0) {
  4676. dev_kfree_skb_any(skb);
  4677. return NETDEV_TX_OK;
  4678. }
  4679. if (tso)
  4680. tx_flags |= IXGBE_TX_FLAGS_FSO;
  4681. #endif /* IXGBE_FCOE */
  4682. } else {
  4683. if (skb->protocol == htons(ETH_P_IP))
  4684. tx_flags |= IXGBE_TX_FLAGS_IPV4;
  4685. tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  4686. if (tso < 0) {
  4687. dev_kfree_skb_any(skb);
  4688. return NETDEV_TX_OK;
  4689. }
  4690. if (tso)
  4691. tx_flags |= IXGBE_TX_FLAGS_TSO;
  4692. else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
  4693. (skb->ip_summed == CHECKSUM_PARTIAL))
  4694. tx_flags |= IXGBE_TX_FLAGS_CSUM;
  4695. }
  4696. count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
  4697. if (count) {
  4698. /* add the ATR filter if ATR is on */
  4699. if (tx_ring->atr_sample_rate) {
  4700. ++tx_ring->atr_count;
  4701. if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
  4702. test_bit(__IXGBE_FDIR_INIT_DONE,
  4703. &tx_ring->reinit_state)) {
  4704. ixgbe_atr(adapter, skb, tx_ring->queue_index,
  4705. tx_flags);
  4706. tx_ring->atr_count = 0;
  4707. }
  4708. }
  4709. txq = netdev_get_tx_queue(netdev, tx_ring->queue_index);
  4710. txq->tx_bytes += skb->len;
  4711. txq->tx_packets++;
  4712. ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
  4713. hdr_len);
  4714. ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
  4715. } else {
  4716. dev_kfree_skb_any(skb);
  4717. tx_ring->tx_buffer_info[first].time_stamp = 0;
  4718. tx_ring->next_to_use = first;
  4719. }
  4720. return NETDEV_TX_OK;
  4721. }
  4722. /**
  4723. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  4724. * @netdev: network interface device structure
  4725. * @p: pointer to an address structure
  4726. *
  4727. * Returns 0 on success, negative on failure
  4728. **/
  4729. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  4730. {
  4731. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4732. struct ixgbe_hw *hw = &adapter->hw;
  4733. struct sockaddr *addr = p;
  4734. if (!is_valid_ether_addr(addr->sa_data))
  4735. return -EADDRNOTAVAIL;
  4736. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  4737. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  4738. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
  4739. return 0;
  4740. }
  4741. static int
  4742. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  4743. {
  4744. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4745. struct ixgbe_hw *hw = &adapter->hw;
  4746. u16 value;
  4747. int rc;
  4748. if (prtad != hw->phy.mdio.prtad)
  4749. return -EINVAL;
  4750. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  4751. if (!rc)
  4752. rc = value;
  4753. return rc;
  4754. }
  4755. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  4756. u16 addr, u16 value)
  4757. {
  4758. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4759. struct ixgbe_hw *hw = &adapter->hw;
  4760. if (prtad != hw->phy.mdio.prtad)
  4761. return -EINVAL;
  4762. return hw->phy.ops.write_reg(hw, addr, devad, value);
  4763. }
  4764. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  4765. {
  4766. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4767. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  4768. }
  4769. /**
  4770. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  4771. * netdev->dev_addrs
  4772. * @netdev: network interface device structure
  4773. *
  4774. * Returns non-zero on failure
  4775. **/
  4776. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  4777. {
  4778. int err = 0;
  4779. struct ixgbe_adapter *adapter = netdev_priv(dev);
  4780. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  4781. if (is_valid_ether_addr(mac->san_addr)) {
  4782. rtnl_lock();
  4783. err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  4784. rtnl_unlock();
  4785. }
  4786. return err;
  4787. }
  4788. /**
  4789. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  4790. * netdev->dev_addrs
  4791. * @netdev: network interface device structure
  4792. *
  4793. * Returns non-zero on failure
  4794. **/
  4795. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  4796. {
  4797. int err = 0;
  4798. struct ixgbe_adapter *adapter = netdev_priv(dev);
  4799. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  4800. if (is_valid_ether_addr(mac->san_addr)) {
  4801. rtnl_lock();
  4802. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  4803. rtnl_unlock();
  4804. }
  4805. return err;
  4806. }
  4807. #ifdef CONFIG_NET_POLL_CONTROLLER
  4808. /*
  4809. * Polling 'interrupt' - used by things like netconsole to send skbs
  4810. * without having to re-enable interrupts. It's not called while
  4811. * the interrupt routine is executing.
  4812. */
  4813. static void ixgbe_netpoll(struct net_device *netdev)
  4814. {
  4815. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4816. int i;
  4817. adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
  4818. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4819. int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  4820. for (i = 0; i < num_q_vectors; i++) {
  4821. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  4822. ixgbe_msix_clean_many(0, q_vector);
  4823. }
  4824. } else {
  4825. ixgbe_intr(adapter->pdev->irq, netdev);
  4826. }
  4827. adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
  4828. }
  4829. #endif
  4830. static const struct net_device_ops ixgbe_netdev_ops = {
  4831. .ndo_open = ixgbe_open,
  4832. .ndo_stop = ixgbe_close,
  4833. .ndo_start_xmit = ixgbe_xmit_frame,
  4834. .ndo_select_queue = ixgbe_select_queue,
  4835. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  4836. .ndo_set_multicast_list = ixgbe_set_rx_mode,
  4837. .ndo_validate_addr = eth_validate_addr,
  4838. .ndo_set_mac_address = ixgbe_set_mac,
  4839. .ndo_change_mtu = ixgbe_change_mtu,
  4840. .ndo_tx_timeout = ixgbe_tx_timeout,
  4841. .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
  4842. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  4843. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  4844. .ndo_do_ioctl = ixgbe_ioctl,
  4845. #ifdef CONFIG_NET_POLL_CONTROLLER
  4846. .ndo_poll_controller = ixgbe_netpoll,
  4847. #endif
  4848. #ifdef IXGBE_FCOE
  4849. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  4850. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  4851. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  4852. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  4853. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  4854. #endif /* IXGBE_FCOE */
  4855. };
  4856. /**
  4857. * ixgbe_probe - Device Initialization Routine
  4858. * @pdev: PCI device information struct
  4859. * @ent: entry in ixgbe_pci_tbl
  4860. *
  4861. * Returns 0 on success, negative on failure
  4862. *
  4863. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  4864. * The OS initialization, configuring of the adapter private structure,
  4865. * and a hardware reset occur.
  4866. **/
  4867. static int __devinit ixgbe_probe(struct pci_dev *pdev,
  4868. const struct pci_device_id *ent)
  4869. {
  4870. struct net_device *netdev;
  4871. struct ixgbe_adapter *adapter = NULL;
  4872. struct ixgbe_hw *hw;
  4873. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  4874. static int cards_found;
  4875. int i, err, pci_using_dac;
  4876. #ifdef IXGBE_FCOE
  4877. u16 device_caps;
  4878. #endif
  4879. u32 part_num, eec;
  4880. err = pci_enable_device_mem(pdev);
  4881. if (err)
  4882. return err;
  4883. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
  4884. !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
  4885. pci_using_dac = 1;
  4886. } else {
  4887. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4888. if (err) {
  4889. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  4890. if (err) {
  4891. dev_err(&pdev->dev, "No usable DMA "
  4892. "configuration, aborting\n");
  4893. goto err_dma;
  4894. }
  4895. }
  4896. pci_using_dac = 0;
  4897. }
  4898. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  4899. IORESOURCE_MEM), ixgbe_driver_name);
  4900. if (err) {
  4901. dev_err(&pdev->dev,
  4902. "pci_request_selected_regions failed 0x%x\n", err);
  4903. goto err_pci_reg;
  4904. }
  4905. pci_enable_pcie_error_reporting(pdev);
  4906. pci_set_master(pdev);
  4907. pci_save_state(pdev);
  4908. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
  4909. if (!netdev) {
  4910. err = -ENOMEM;
  4911. goto err_alloc_etherdev;
  4912. }
  4913. SET_NETDEV_DEV(netdev, &pdev->dev);
  4914. pci_set_drvdata(pdev, netdev);
  4915. adapter = netdev_priv(netdev);
  4916. adapter->netdev = netdev;
  4917. adapter->pdev = pdev;
  4918. hw = &adapter->hw;
  4919. hw->back = adapter;
  4920. adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  4921. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  4922. pci_resource_len(pdev, 0));
  4923. if (!hw->hw_addr) {
  4924. err = -EIO;
  4925. goto err_ioremap;
  4926. }
  4927. for (i = 1; i <= 5; i++) {
  4928. if (pci_resource_len(pdev, i) == 0)
  4929. continue;
  4930. }
  4931. netdev->netdev_ops = &ixgbe_netdev_ops;
  4932. ixgbe_set_ethtool_ops(netdev);
  4933. netdev->watchdog_timeo = 5 * HZ;
  4934. strcpy(netdev->name, pci_name(pdev));
  4935. adapter->bd_number = cards_found;
  4936. /* Setup hw api */
  4937. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  4938. hw->mac.type = ii->mac;
  4939. /* EEPROM */
  4940. memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
  4941. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  4942. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  4943. if (!(eec & (1 << 8)))
  4944. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  4945. /* PHY */
  4946. memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
  4947. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  4948. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  4949. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  4950. hw->phy.mdio.mmds = 0;
  4951. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  4952. hw->phy.mdio.dev = netdev;
  4953. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  4954. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  4955. /* set up this timer and work struct before calling get_invariants
  4956. * which might start the timer
  4957. */
  4958. init_timer(&adapter->sfp_timer);
  4959. adapter->sfp_timer.function = &ixgbe_sfp_timer;
  4960. adapter->sfp_timer.data = (unsigned long) adapter;
  4961. INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
  4962. /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
  4963. INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
  4964. /* a new SFP+ module arrival, called from GPI SDP2 context */
  4965. INIT_WORK(&adapter->sfp_config_module_task,
  4966. ixgbe_sfp_config_module_task);
  4967. ii->get_invariants(hw);
  4968. /* setup the private structure */
  4969. err = ixgbe_sw_init(adapter);
  4970. if (err)
  4971. goto err_sw_init;
  4972. /*
  4973. * If there is a fan on this device and it has failed log the
  4974. * failure.
  4975. */
  4976. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4977. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4978. if (esdp & IXGBE_ESDP_SDP1)
  4979. DPRINTK(PROBE, CRIT,
  4980. "Fan has stopped, replace the adapter\n");
  4981. }
  4982. /* reset_hw fills in the perm_addr as well */
  4983. err = hw->mac.ops.reset_hw(hw);
  4984. if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
  4985. hw->mac.type == ixgbe_mac_82598EB) {
  4986. /*
  4987. * Start a kernel thread to watch for a module to arrive.
  4988. * Only do this for 82598, since 82599 will generate
  4989. * interrupts on module arrival.
  4990. */
  4991. set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  4992. mod_timer(&adapter->sfp_timer,
  4993. round_jiffies(jiffies + (2 * HZ)));
  4994. err = 0;
  4995. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4996. dev_err(&adapter->pdev->dev, "failed to initialize because "
  4997. "an unsupported SFP+ module type was detected.\n"
  4998. "Reload the driver after installing a supported "
  4999. "module.\n");
  5000. goto err_sw_init;
  5001. } else if (err) {
  5002. dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
  5003. goto err_sw_init;
  5004. }
  5005. netdev->features = NETIF_F_SG |
  5006. NETIF_F_IP_CSUM |
  5007. NETIF_F_HW_VLAN_TX |
  5008. NETIF_F_HW_VLAN_RX |
  5009. NETIF_F_HW_VLAN_FILTER;
  5010. netdev->features |= NETIF_F_IPV6_CSUM;
  5011. netdev->features |= NETIF_F_TSO;
  5012. netdev->features |= NETIF_F_TSO6;
  5013. netdev->features |= NETIF_F_GRO;
  5014. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5015. netdev->features |= NETIF_F_SCTP_CSUM;
  5016. netdev->vlan_features |= NETIF_F_TSO;
  5017. netdev->vlan_features |= NETIF_F_TSO6;
  5018. netdev->vlan_features |= NETIF_F_IP_CSUM;
  5019. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  5020. netdev->vlan_features |= NETIF_F_SG;
  5021. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  5022. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  5023. #ifdef CONFIG_IXGBE_DCB
  5024. netdev->dcbnl_ops = &dcbnl_ops;
  5025. #endif
  5026. #ifdef IXGBE_FCOE
  5027. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  5028. if (hw->mac.ops.get_device_caps) {
  5029. hw->mac.ops.get_device_caps(hw, &device_caps);
  5030. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  5031. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5032. }
  5033. }
  5034. #endif /* IXGBE_FCOE */
  5035. if (pci_using_dac)
  5036. netdev->features |= NETIF_F_HIGHDMA;
  5037. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  5038. netdev->features |= NETIF_F_LRO;
  5039. /* make sure the EEPROM is good */
  5040. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  5041. dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
  5042. err = -EIO;
  5043. goto err_eeprom;
  5044. }
  5045. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  5046. memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
  5047. if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
  5048. dev_err(&pdev->dev, "invalid MAC address\n");
  5049. err = -EIO;
  5050. goto err_eeprom;
  5051. }
  5052. init_timer(&adapter->watchdog_timer);
  5053. adapter->watchdog_timer.function = &ixgbe_watchdog;
  5054. adapter->watchdog_timer.data = (unsigned long)adapter;
  5055. INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
  5056. INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
  5057. err = ixgbe_init_interrupt_scheme(adapter);
  5058. if (err)
  5059. goto err_sw_init;
  5060. switch (pdev->device) {
  5061. case IXGBE_DEV_ID_82599_KX4:
  5062. adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
  5063. IXGBE_WUFC_MC | IXGBE_WUFC_BC);
  5064. /* Enable ACPI wakeup in GRC */
  5065. IXGBE_WRITE_REG(hw, IXGBE_GRC,
  5066. (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
  5067. break;
  5068. default:
  5069. adapter->wol = 0;
  5070. break;
  5071. }
  5072. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  5073. /* pick up the PCI bus settings for reporting later */
  5074. hw->mac.ops.get_bus_info(hw);
  5075. /* print bus type/speed/width info */
  5076. dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
  5077. ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
  5078. (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
  5079. ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
  5080. (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
  5081. (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
  5082. "Unknown"),
  5083. netdev->dev_addr);
  5084. ixgbe_read_pba_num_generic(hw, &part_num);
  5085. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  5086. dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
  5087. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  5088. (part_num >> 8), (part_num & 0xff));
  5089. else
  5090. dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
  5091. hw->mac.type, hw->phy.type,
  5092. (part_num >> 8), (part_num & 0xff));
  5093. if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
  5094. dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
  5095. "this card is not sufficient for optimal "
  5096. "performance.\n");
  5097. dev_warn(&pdev->dev, "For optimal performance a x8 "
  5098. "PCI-Express slot is required.\n");
  5099. }
  5100. /* save off EEPROM version number */
  5101. hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
  5102. /* reset the hardware with the new settings */
  5103. err = hw->mac.ops.start_hw(hw);
  5104. if (err == IXGBE_ERR_EEPROM_VERSION) {
  5105. /* We are running on a pre-production device, log a warning */
  5106. dev_warn(&pdev->dev, "This device is a pre-production "
  5107. "adapter/LOM. Please be aware there may be issues "
  5108. "associated with your hardware. If you are "
  5109. "experiencing problems please contact your Intel or "
  5110. "hardware representative who provided you with this "
  5111. "hardware.\n");
  5112. }
  5113. strcpy(netdev->name, "eth%d");
  5114. err = register_netdev(netdev);
  5115. if (err)
  5116. goto err_register;
  5117. /* carrier off reporting is important to ethtool even BEFORE open */
  5118. netif_carrier_off(netdev);
  5119. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  5120. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  5121. INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
  5122. #ifdef CONFIG_IXGBE_DCA
  5123. if (dca_add_requester(&pdev->dev) == 0) {
  5124. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  5125. ixgbe_setup_dca(adapter);
  5126. }
  5127. #endif
  5128. /* add san mac addr to netdev */
  5129. ixgbe_add_sanmac_netdev(netdev);
  5130. dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
  5131. cards_found++;
  5132. return 0;
  5133. err_register:
  5134. ixgbe_release_hw_control(adapter);
  5135. ixgbe_clear_interrupt_scheme(adapter);
  5136. err_sw_init:
  5137. err_eeprom:
  5138. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5139. del_timer_sync(&adapter->sfp_timer);
  5140. cancel_work_sync(&adapter->sfp_task);
  5141. cancel_work_sync(&adapter->multispeed_fiber_task);
  5142. cancel_work_sync(&adapter->sfp_config_module_task);
  5143. iounmap(hw->hw_addr);
  5144. err_ioremap:
  5145. free_netdev(netdev);
  5146. err_alloc_etherdev:
  5147. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  5148. IORESOURCE_MEM));
  5149. err_pci_reg:
  5150. err_dma:
  5151. pci_disable_device(pdev);
  5152. return err;
  5153. }
  5154. /**
  5155. * ixgbe_remove - Device Removal Routine
  5156. * @pdev: PCI device information struct
  5157. *
  5158. * ixgbe_remove is called by the PCI subsystem to alert the driver
  5159. * that it should release a PCI device. The could be caused by a
  5160. * Hot-Plug event, or because the driver is going to be removed from
  5161. * memory.
  5162. **/
  5163. static void __devexit ixgbe_remove(struct pci_dev *pdev)
  5164. {
  5165. struct net_device *netdev = pci_get_drvdata(pdev);
  5166. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5167. set_bit(__IXGBE_DOWN, &adapter->state);
  5168. /* clear the module not found bit to make sure the worker won't
  5169. * reschedule
  5170. */
  5171. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5172. del_timer_sync(&adapter->watchdog_timer);
  5173. del_timer_sync(&adapter->sfp_timer);
  5174. cancel_work_sync(&adapter->watchdog_task);
  5175. cancel_work_sync(&adapter->sfp_task);
  5176. cancel_work_sync(&adapter->multispeed_fiber_task);
  5177. cancel_work_sync(&adapter->sfp_config_module_task);
  5178. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  5179. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  5180. cancel_work_sync(&adapter->fdir_reinit_task);
  5181. flush_scheduled_work();
  5182. #ifdef CONFIG_IXGBE_DCA
  5183. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  5184. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  5185. dca_remove_requester(&pdev->dev);
  5186. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  5187. }
  5188. #endif
  5189. #ifdef IXGBE_FCOE
  5190. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  5191. ixgbe_cleanup_fcoe(adapter);
  5192. #endif /* IXGBE_FCOE */
  5193. /* remove the added san mac */
  5194. ixgbe_del_sanmac_netdev(netdev);
  5195. if (netdev->reg_state == NETREG_REGISTERED)
  5196. unregister_netdev(netdev);
  5197. ixgbe_clear_interrupt_scheme(adapter);
  5198. ixgbe_release_hw_control(adapter);
  5199. iounmap(adapter->hw.hw_addr);
  5200. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  5201. IORESOURCE_MEM));
  5202. DPRINTK(PROBE, INFO, "complete\n");
  5203. free_netdev(netdev);
  5204. pci_disable_pcie_error_reporting(pdev);
  5205. pci_disable_device(pdev);
  5206. }
  5207. /**
  5208. * ixgbe_io_error_detected - called when PCI error is detected
  5209. * @pdev: Pointer to PCI device
  5210. * @state: The current pci connection state
  5211. *
  5212. * This function is called after a PCI bus error affecting
  5213. * this device has been detected.
  5214. */
  5215. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  5216. pci_channel_state_t state)
  5217. {
  5218. struct net_device *netdev = pci_get_drvdata(pdev);
  5219. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5220. netif_device_detach(netdev);
  5221. if (state == pci_channel_io_perm_failure)
  5222. return PCI_ERS_RESULT_DISCONNECT;
  5223. if (netif_running(netdev))
  5224. ixgbe_down(adapter);
  5225. pci_disable_device(pdev);
  5226. /* Request a slot reset. */
  5227. return PCI_ERS_RESULT_NEED_RESET;
  5228. }
  5229. /**
  5230. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  5231. * @pdev: Pointer to PCI device
  5232. *
  5233. * Restart the card from scratch, as if from a cold-boot.
  5234. */
  5235. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  5236. {
  5237. struct net_device *netdev = pci_get_drvdata(pdev);
  5238. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5239. pci_ers_result_t result;
  5240. int err;
  5241. if (pci_enable_device_mem(pdev)) {
  5242. DPRINTK(PROBE, ERR,
  5243. "Cannot re-enable PCI device after reset.\n");
  5244. result = PCI_ERS_RESULT_DISCONNECT;
  5245. } else {
  5246. pci_set_master(pdev);
  5247. pci_restore_state(pdev);
  5248. pci_save_state(pdev);
  5249. pci_wake_from_d3(pdev, false);
  5250. ixgbe_reset(adapter);
  5251. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5252. result = PCI_ERS_RESULT_RECOVERED;
  5253. }
  5254. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  5255. if (err) {
  5256. dev_err(&pdev->dev,
  5257. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
  5258. /* non-fatal, continue */
  5259. }
  5260. return result;
  5261. }
  5262. /**
  5263. * ixgbe_io_resume - called when traffic can start flowing again.
  5264. * @pdev: Pointer to PCI device
  5265. *
  5266. * This callback is called when the error recovery driver tells us that
  5267. * its OK to resume normal operation.
  5268. */
  5269. static void ixgbe_io_resume(struct pci_dev *pdev)
  5270. {
  5271. struct net_device *netdev = pci_get_drvdata(pdev);
  5272. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5273. if (netif_running(netdev)) {
  5274. if (ixgbe_up(adapter)) {
  5275. DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
  5276. return;
  5277. }
  5278. }
  5279. netif_device_attach(netdev);
  5280. }
  5281. static struct pci_error_handlers ixgbe_err_handler = {
  5282. .error_detected = ixgbe_io_error_detected,
  5283. .slot_reset = ixgbe_io_slot_reset,
  5284. .resume = ixgbe_io_resume,
  5285. };
  5286. static struct pci_driver ixgbe_driver = {
  5287. .name = ixgbe_driver_name,
  5288. .id_table = ixgbe_pci_tbl,
  5289. .probe = ixgbe_probe,
  5290. .remove = __devexit_p(ixgbe_remove),
  5291. #ifdef CONFIG_PM
  5292. .suspend = ixgbe_suspend,
  5293. .resume = ixgbe_resume,
  5294. #endif
  5295. .shutdown = ixgbe_shutdown,
  5296. .err_handler = &ixgbe_err_handler
  5297. };
  5298. /**
  5299. * ixgbe_init_module - Driver Registration Routine
  5300. *
  5301. * ixgbe_init_module is the first routine called when the driver is
  5302. * loaded. All it does is register with the PCI subsystem.
  5303. **/
  5304. static int __init ixgbe_init_module(void)
  5305. {
  5306. int ret;
  5307. printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
  5308. ixgbe_driver_string, ixgbe_driver_version);
  5309. printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
  5310. #ifdef CONFIG_IXGBE_DCA
  5311. dca_register_notify(&dca_notifier);
  5312. #endif
  5313. ret = pci_register_driver(&ixgbe_driver);
  5314. return ret;
  5315. }
  5316. module_init(ixgbe_init_module);
  5317. /**
  5318. * ixgbe_exit_module - Driver Exit Cleanup Routine
  5319. *
  5320. * ixgbe_exit_module is called just before the driver is removed
  5321. * from memory.
  5322. **/
  5323. static void __exit ixgbe_exit_module(void)
  5324. {
  5325. #ifdef CONFIG_IXGBE_DCA
  5326. dca_unregister_notify(&dca_notifier);
  5327. #endif
  5328. pci_unregister_driver(&ixgbe_driver);
  5329. }
  5330. #ifdef CONFIG_IXGBE_DCA
  5331. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  5332. void *p)
  5333. {
  5334. int ret_val;
  5335. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  5336. __ixgbe_notify_dca);
  5337. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  5338. }
  5339. #endif /* CONFIG_IXGBE_DCA */
  5340. #ifdef DEBUG
  5341. /**
  5342. * ixgbe_get_hw_dev_name - return device name string
  5343. * used by hardware layer to print debugging information
  5344. **/
  5345. char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
  5346. {
  5347. struct ixgbe_adapter *adapter = hw->back;
  5348. return adapter->netdev->name;
  5349. }
  5350. #endif
  5351. module_exit(ixgbe_exit_module);
  5352. /* ixgbe_main.c */