ixgbe_main.c 155 KB

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