ixgbe_main.c 173 KB

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