ixgbe_main.c 172 KB

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