ixgbe_main.c 172 KB

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