ixgbe_main.c 160 KB

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