ixgbe_main.c 160 KB

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