ixgbe_main.c 172 KB

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